audiodelays.Echo.freq_shift
panning issues with stereo sources #9874
Open
Description
CircuitPython version
Adafruit CircuitPython 9.2.1-22-gb481f1fa8e on 2024-12-05; Pimoroni Pico Plus 2 with rp2350b
Code/REPL
import audiobusio
import audiodelays
import board, time
import synthio
audio = audiobusio.I2SOut(
bit_clock=board.GP0,
word_select=board.GP1,
data=board.GP3,
)
synth = synthio.Synthesizer(
sample_rate=22050,
channel_count=2,
)
effect = audiodelays.Echo(
max_delay_ms=200,
delay_ms=500,
decay=0.0,
mix=0.5,
sample_rate=22050,
channel_count=2,
freq_shift=True,
)
effect.play(synth)
audio.play(effect)
note = synthio.Note(
frequency=synthio.midi_to_hz(65),
panning=-1.0,
)
while True:
synth.press(note)
time.sleep(0.1)
synth.release(note)
time.sleep(0.9)
note.panning = note.panning * -1.0 # alternate panning
Behavior
Note plays for 0.1 second every second alternating between the left and right channels (hard panned). The delayed effect plays in the center channel with distorted abnormalities.
Description
Code works as intended if max_delay_ms
equals delay_ms
. Otherwise, panning errors in the audio occur. This is due to the poor handling of the buffer pointer when freq_shift
is enabled and multiple channels are present.
Additional information
The buffer pointers need to be limited to half the buffer size when channel_count=2
and freq_shift=True
and the right channel pointer needs to be offset to the second half of the buffer. This will allow the two channels to be separated appropriately.
This is my fault due to a lack of understanding of the audiosample API when adding this feature.