forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9866 from jepler/mp3decoder-reopen-glitch
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import audiomp3, audiocore | ||
import ulab.numpy as np | ||
|
||
TEST_FILE = __file__.rsplit("/", 1)[0] + "/../circuitpython-manual/audiocore/jeplayer-splash-44100-stereo.mp3" | ||
|
||
def normalized_rms_ulab(values): | ||
values = np.frombuffer(values, dtype=np.int16) | ||
# this function works with ndarrays only | ||
minbuf = np.mean(values) | ||
values = values - minbuf | ||
samples_sum = np.sum(values * values) | ||
return (samples_sum / len(values))**.5 | ||
|
||
def print_frame_loudness(decoder, n): | ||
for i in range(n): | ||
result, buf = audiocore.get_buffer(decoder) | ||
print(f"{i} {result} {normalized_rms_ulab(buf):5.0f}") | ||
print() | ||
|
||
# First frames | ||
decoder = audiomp3.MP3Decoder(TEST_FILE) | ||
print_frame_loudness(decoder, 8) | ||
|
||
# First frames (fresh decoder) | ||
decoder = audiomp3.MP3Decoder(TEST_FILE) | ||
print_frame_loudness(decoder, 2) | ||
|
||
# First frames (reopen) | ||
decoder.open(TEST_FILE) | ||
print_frame_loudness(decoder, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
0 1 0 | ||
1 1 4730 | ||
2 1 27914 | ||
3 1 28737 | ||
4 1 29251 | ||
5 1 29219 | ||
6 1 28672 | ||
7 1 28213 | ||
|
||
0 1 0 | ||
1 1 4730 | ||
|
||
0 1 0 | ||
1 1 4730 | ||
2 1 27914 | ||
|