Skip to content
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

Fix handling of stereo audio within audiodelays when freq_shift=True #9876

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

relic-se
Copy link

@relic-se relic-se commented Dec 6, 2024

@gamblor21 @jepler for interest.

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.

@jepler
Copy link
Member

jepler commented Dec 6, 2024

I feel your pain about single_channel_output. As far as I can tell from source code searches this was needed by samd51 analog AudioOut but not any other audio output, and we should restructure things so that not every audio source has to bear a code size and complication cost for it.

@gamblor21
Copy link
Member

From what I recall audio is either stored for mono in SSSS where each S is a n-bit sample or for stereo as LRLR (also n-bit samples).

I2SOut does handle taking mono samples and making them stereo by sending each sample out twice. How it does that depends on the underlying platform. For RP devices the way the PIO works it does this automatically (it is documented in the code). For SAMD I believe it does this via code.

In the code I wrote (and some of the other audio code I have seen) I just checked the channels for 1 or 2 and as long as the main buffer and echo buffer both used the same the Left/Right channels matched. But you have to make sure your total # of samples matches as well (44.1Khz would be 88.2K samples for stereo).

I have wondered if simplifying how mono/stereo and bit depth is handled would make things both easier to right and smaller, though potentially at a cost of useability on smaller / older controllers.

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 looks fine, but want to try it on the hardware. I know you wanted to review / work on #9876 first so can wait until that is done if you want.

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.

audiodelays.Echo.freq_shift panning issues with stereo sources
3 participants