Skip to content

MP3Decoder: Switching tracks can play part of the previous track #9705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jepler opened this issue Oct 9, 2024 · 2 comments · Fixed by #9866
Closed

MP3Decoder: Switching tracks can play part of the previous track #9705

jepler opened this issue Oct 9, 2024 · 2 comments · Fixed by #9866
Assignees
Milestone

Comments

@jepler
Copy link

jepler commented Oct 9, 2024

CircuitPython version

Adafruit CircuitPython 9.2.0-beta.0-3-g3a189e75d9-dirty on 2024-09-23; Raspberry Pi Pico 2 with rp2350a

Code/REPL

# https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/circuitpython-audio-fx/polyphonic/code.py

Behavior

Install the project and hook up a button to GP4. When pressed and held, this says "track 4 hold loop".

Repeatedly press and release the button. Press for about 1 second at a time, trying to release when the voice is speaking.

Description

At the beginning of a subsequent play, you'll hear a snippet of the file playing at an earlier position. Then, it correctly plays from the beginning.

Additional information

It's not clear why this is happening, but it could relate to the fact that most of the MP3 player state is not cleared when a file is assigned; instead just a minimum amount of work is done.

@jepler jepler added the bug label Oct 9, 2024
@jepler
Copy link
Author

jepler commented Oct 9, 2024

You can also hear this if you use GP4 to trigger "track 4 hold loop", release mid-sample, and then press GP3 to trigger "track 3". However, you don't hear anything when going from GP3 to GP4, i.e., it's either only affecting looping samples OR samples that are stopped mid-playback. This also shows it's likely not a special case error of playing the same sample twice in a row.

@tannewt tannewt added the audio label Oct 10, 2024
@tannewt tannewt added this to the 9.x.x milestone Oct 10, 2024
@jepler jepler self-assigned this Nov 27, 2024
@jepler
Copy link
Author

jepler commented Dec 4, 2024

Here's a standalone test to run on the unix port. Each time the first buffer's RMS should be zero. but instead in the reopen case it's nonzero:

import audiomp3, audiocore
import ulab.numpy as np

TEST_FILE ="tests/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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants