Skip to content

Audio stopping during playback when using audiofreeverb.Freeverb #10295

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

Open
relic-se opened this issue Apr 25, 2025 · 5 comments
Open

Audio stopping during playback when using audiofreeverb.Freeverb #10295

relic-se opened this issue Apr 25, 2025 · 5 comments
Milestone

Comments

@relic-se
Copy link

CircuitPython version and board name

Adafruit CircuitPython 10.0.0-alpha.2-38-g8a28033587 on 2025-04-25; Pimoroni Pico Plus 2 with rp2350b

Code/REPL

import time
import board
import busio
import audiobusio, audiocore, audiomixer, synthio
import audiofreeverb, audiofilters

CHANNELS = 2
SRATE = 48000

i2s_bclk, i2s_lclk, i2s_data = board.GP2, board.GP3, board.GP4
audio = audiobusio.I2SOut(bit_clock=i2s_bclk, word_select=i2s_lclk, data=i2s_data)

mixer = audiomixer.Mixer(voice_count=1, channel_count=CHANNELS, sample_rate=SRATE, buffer_size=2048)
audio.play(mixer)

synth = synthio.Synthesizer(channel_count=CHANNELS, sample_rate=SRATE)

effect = audiofreeverb.Freeverb(channel_count=CHANNELS, sample_rate=SRATE)
effect.play(synth)

lpf = audiofilters.Filter(channel_count=CHANNELS, sample_rate=SRATE, mix=1.0)
lpf.filter = synthio.Biquad(synthio.FilterMode.LOW_PASS, frequency=1000, Q=1.0)

lpf.play(effect)
mixer.voice[0].play(lpf)

for i in range(24):
    print(i + 1)
    synth.press(synthio.Note(synthio.midi_to_hz(36 + i * 3), amplitude=0.5))
    time.sleep(0.5)

Behavior

Program continues running, but audio ceases altogether when the 10th note is pressed. If the filter and its module is removed, the audio cuts off at the 18th note.

Description

If I add in a print(gc.mem_free()) statement to the for loop, I get 8258240 bytes available at the note that cuts off (the board has 8MB of PSRAM).

Additional information

I initially thought the error was due to internal memory being filled up, but I'm unable to recreate the issue in versions of CircuitPython prior to the latest dev build without audiofreeverb.Freeverb. I think the error may lie somewhere within that effect.

@relic-se relic-se added the bug label Apr 25, 2025
@gamblor21
Copy link
Member

I have to look more but if you aren't releasing the notes synthio can only play so many at once. Does this occur with any other effects?

@relic-se
Copy link
Author

The limit on RP2350 is 24 notes. Under normal circumstances, the notes are either ignored or the oldest notes are dropped. In this situation, audio stops altogether.

@relic-se
Copy link
Author

I've tested it with audiodelays.Echo, but was unable to recreate the issue.

@dhalbert dhalbert added the audio label Apr 26, 2025
@dhalbert dhalbert added this to the 10.0.0 milestone Apr 26, 2025
@gamblor21
Copy link
Member

I tried this on the latest nightly build (Adafruit CircuitPython 10.0.0-alpha.2-40-gfa9b9746f9 on 2025-04-26; Raspberry Pi Pico 2 with rp2350a) and it worked normal for me. All notes played.

As I typed this I tried it a couple more times and had inconsistent results. This may be related to the issue being worked on when audio DMAs are not working. I cannot think of any part of Freeverb that would cause audio to stop in this manner as it does not base any functionality on Notes just the audio information it takes in.

@tannewt
Copy link
Member

tannewt commented Apr 28, 2025

I'm working to fix an issue where the audio buffers stop ping ponging to each other. This can happen if the second buffer completes while the first is being filled.

I suspect that the time it takes to compute the audio buffer may influence whether this happens. The longer it takes to fill the buffer, the more likely it is to happen.

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

No branches or pull requests

4 participants