Skip to content

Fix handling of stereo audio within audiodelays.Delay when freq_shift=True #10252

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

Merged
merged 4 commits into from
Apr 22, 2025

Conversation

relic-se
Copy link

@gamblor21 @dhalbert for interest.

This PR has been rewritten and resubmitted from its original state (#9876) for compatibility with 9.2.x and to fix conflicts with other recent changes to audiodelays.Delay.

This has been an issue that I've been aware of since the inclusion of audiodelays in 9.2.0. Echo buffer positions weren't being properly managed when handling stereo input/output. I've resolved this issue by separating the echo buffer into two halves (left + right) and offsetting the buffer where necessary. I've done my best to support single_channel_output as well, but I'm not exactly sure how to test that (I2SOut uses left/right pairs).

I've also found a minor bug when constructing audiodelays.Echo with delay_ms <= 0 || delay_ms > max_delay_ms where echo_buffer_length would not be set and remain as the default of 0. The effect of this issue wasn't too major, but I've resolved it by always setting echo_buffer_length during recalculate_delay and limiting it to the acceptable range.

Because each freq_shift mode handles the buffer differently now, I've added it so that the full echo_buffer and buffer positions are reset whenever the mode is changed to avoid potential audio abnormalities.

The example in #9874 now does not exhibit any issues. I've also tested this code with variable delay_ms values, and the frequency shifting works with full channel separation.

Fixes #9874.

…`echo_buffer_write_pos`, and split buffer for stereo output when `freq_shift=True`.
Copy link
Member

@gamblor21 gamblor21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looked good to me, but when I tried it and set the channels to one I lose the echo effect for freq_shift=True. It works for stereo.

@relic-se
Copy link
Author

Code looked good to me, but when I tried it and set the channels to one I lose the echo effect for freq_shift=True. It works for stereo.

I believe there's an issue with how the buffer index is updated in mono. I fixed it within the audiodelays.MultiTapDelay effect, but I haven't tackled it here. I'll take a swing at it soon.

@relic-se relic-se marked this pull request as draft April 21, 2025 21:39
@relic-se relic-se marked this pull request as ready for review April 21, 2025 22:43
@relic-se
Copy link
Author

@gamblor21 I began to encounter issues with buffer positions when using a synthio.LFO on delay_ms. In the process of working it out, I decided to implement the split buffer in stereo (1st half = left channel, 2nd half = right channel) on both delay modes (freq_shift=False/True) and always keep separate buffer positions for left and right channels. This fixes the single_channel_output problem, simplifies the code slightly, and fixes the issues I was having with the aforementioned delay_ms bug. Mono output is good from my testing as well.

Copy link
Member

@gamblor21 gamblor21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great now. Thanks so much!

@gamblor21 gamblor21 merged commit 7d8e41f into adafruit:9.2.x Apr 22, 2025
53 checks passed
@relic-se relic-se deleted the audiodelays_stereo branch April 22, 2025 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants