Skip to content

Commit 81d96ac

Browse files
authored
Merge pull request #10185 from jepler/issue10175
mp3 samples are signed
2 parents c27e0da + 17497e4 commit 81d96ac

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

shared-module/audiomp3/MP3Decoder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ void common_hal_audiomp3_mp3file_set_file(audiomp3_mp3file_obj_t *self, mp_obj_t
385385
self->base.channel_count = fi.nChans;
386386
self->base.single_buffer = false;
387387
self->base.bits_per_sample = 16;
388-
self->base.samples_signed = false;
388+
self->base.samples_signed = true;
389389
self->base.max_buffer_length = fi.outputSamps * sizeof(int16_t);
390390
self->len = 2 * self->base.max_buffer_length;
391391
self->samples_decoded = 0;

tests/circuitpython/issue9705.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
import audiomp3, audiocore
2-
import ulab.numpy as np
32

43
TEST_FILE = (
54
__file__.rsplit("/", 1)[0]
65
+ "/../circuitpython-manual/audiocore/jeplayer-splash-44100-stereo.mp3"
76
)
87

98

10-
def normalized_rms_ulab(values):
11-
values = np.frombuffer(values, dtype=np.int16)
12-
# this function works with ndarrays only
13-
minbuf = np.mean(values)
14-
values = values - minbuf
15-
samples_sum = np.sum(values * values)
16-
return (samples_sum / len(values)) ** 0.5
9+
def loudness(values):
10+
return sum(abs(a) for a in values)
1711

1812

1913
def print_frame_loudness(decoder, n):
2014
for i in range(n):
2115
result, buf = audiocore.get_buffer(decoder)
22-
print(f"{i} {result} {normalized_rms_ulab(buf):5.0f}")
16+
print(f"{i} {result} {loudness(buf):5.0f}")
2317
print()
2418

2519

tests/circuitpython/issue9705.py.exp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
0 1 0
2-
1 1 4730
3-
2 1 27914
4-
3 1 28737
5-
4 1 29251
6-
5 1 29219
7-
6 1 28672
8-
7 1 28213
2+
1 1 25
3+
2 1 830
4+
3 1 880
5+
4 1 932
6+
5 1 892
7+
6 1 869
8+
7 1 839
99

1010
0 1 0
11-
1 1 4730
11+
1 1 25
1212

1313
0 1 0
14-
1 1 4730
15-
2 1 27914
14+
1 1 25
15+
2 1 830
1616

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy