Repository navigation
Fix audiomixer phase inversion and use DSP on Cortex-M33 - #11617
Merged
Merged
Conversation
On cores with DSP instructions, a level of 1.0 (1 << 15) shifted left by 16 overflowed into the sign bit, so the mixed sample came out negated: mono output was inverted and the right channel of a centered stereo voice was out of phase with the left. Shift by 15 instead. A centered pan now scales both channels by 1.0 instead of the left one by 32767/32768.
The SIMD helpers were limited to ARMv7E-M, so the Cortex-M33 in the RP2350 fell back to a float divide per sample. Check __ARM_FEATURE_DSP instead, and mix with integers where there is no DSP, which matches the DSP result bit for bit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On boards with DSP instructions (SAMD51, nRF52840, i.MX RT, STM32F4), a voice at level 1.0 came out negated. The level is 1 << 15, and the code shifted it left by 16, which overflowed into the sign bit. Mono output was inverted. With centered stereo the right channel was out of phase with the left, so it cancelled out when the two channels were summed to mono.
Speed: The DSP code ran only on ARMv7E-M. The RP2350 has the same DSP instructions, so it now uses them too. Chips without DSP, like the RP2040, now mix with integers instead of float. The output is the same on every chip.
Time to mix 4 voices, 1024 samples:
Flash is 1.1 KB smaller on RP2040 and 1.8 KB smaller on RP2350.
Testing: I read the mixer output with audiocore.get_buffer() on all four boards.
The code was written with AI help.