-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix for fixed point overflow in synthio #10288
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
Conversation
I updated the tests as this change breaks most of them. I looked and as far as I could tell it is small rounding differences due to how I fixed this issue. I also listened but would appreciate it if someone else can confirm that things sound right. The rounding changes were about 1 (for ints) or less then 0.0001 for floats so not large for audio. |
Not that it's necessary for this PR, but would |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks clean so far. I haven't yet tested it, but I will extensively soon.
Just finished running tests. No more distortion across the board! Now that we can push Q up to much higher values, I'm a bit disappointed that it doesn't appear to want to self-oscillate like you'd expect from an analog filter. After a bit of research, I was able to find some anecdotes about biquads not being able to self-oscillate without the help of additional processing (using an envelope follower controlling gain). For our purposes, I think we can live without it. |
Todbot has tested this (comment on #10200) and it fixes the issue he was having as well. |
@@ -250,7 +270,7 @@ static bool synth_note_into_buffer(synthio_synth_t *synth, int chan, int32_t *ou | |||
accum = accum - lim + offset; | |||
} | |||
int16_t idx = accum >> SYNTHIO_FREQUENCY_SHIFT; | |||
int16_t wi = (ring_waveform[idx] * out_buffer32[i]) / 32768; | |||
int16_t wi = (ring_waveform[idx] * out_buffer32[i]) / 32768; // consider for synthio_sat16 but had a weird artificat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int16_t wi = (ring_waveform[idx] * out_buffer32[i]) / 32768; // consider for synthio_sat16 but had a weird artificat | |
int16_t wi = (ring_waveform[idx] * out_buffer32[i]) / 32768; // consider for synthio_sat16 but had a weird artifact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I'll catch it my next time. It mostly is a note to remind myself to look at it more in the future anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One typo you may want to fix first. I don't really care so I approved.
thank you! |
Fix for #10286 and #10200.
There may still be more locations where fixed point could be handled better in
synthio
but this fix hits two big ones that I discovered so worth fixing those now.Also refactored
sat16
that will shift a fixed point result back into 16 bits out ofaudiofreeverb
and intosynthio
to be used by any audio module that needs it. Potentially worth moving this to a generic "audiohelper" type module in the future in case someone builds without synthio but still wants audio effects.