-
Notifications
You must be signed in to change notification settings - Fork 403
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
Std sin in sinosc and cpu with unison #1858
Comments
Hopefully the approximation won't be adding any harmonics? This should be checked, too. |
nah there's super good literature on how to do it. don't worry. not something i'm figuring out solo. |
std::sinf is indeed about 2x faster on mac and linux than std::sin - but if the argument is an explicit float gets automselected. On windows it makes no difference. Also windows implementation of sin is about 3x slower than the mac and linux one in my quick test. |
code i used to make that assertion btw. |
So did some research on this last night. The approximation I was considering has a better polynomial approximation (the pade approximation). Juce even has it in their lib https://github.com/juce-framework/JUCE/blob/02bbe31c0d2fb59ed32fb725b56ad25536c7ed75/modules/juce_dsp/maths/juce_FastMathApproximations.h#L159 so I'm going to try that one out as a sin approximation (with the appropriate phase bounds in place) |
yeah the max error of that pade approximation in the range -pi to pi on floats is 1e-5 and the average error is 1e-7 - basically float precision. On my mac it is twice as fast as std::sin and 30% faster than std::sinf. On linux is it more drastic, being about 10x faster than std::sin. On windows it is about 8x as fast as std::sin So that's definitely the approx to us. |
Taking the Pade approximation of sin from JUCE and Wikipedia (https://en.wikipedia.org/wiki/Padé_approximant and JUCE6 dsp fastmath classes), introduce a fast approximation of sin and cos which is valid in -PI,PI; Use it in the sin oscillator and ring modulator to reduce CPU in high unison counts. Closes surge-synthesizer#1858
Taking the Pade approximation of sin from JUCE and Wikipedia (https://en.wikipedia.org/wiki/Padé_approximant and JUCE6 dsp fastmath classes), introduce a fast approximation of sin and cos which is valid in -PI,PI; Use it in the sin oscillator and ring modulator to reduce CPU in high unison counts. Closes #1858
From slack: Pushing the introduction of a sin approximant for the sin osc and the ring modulator. |
Just tested this. It sounds fine on my end! The results for me when playing a 3 note chord on 16 voices unison on 1 SINE OSC are the following: Before: 11-12% CPU usage As a reference, 3 note chord on 1 16 voices SAW OSC takes around 1-2% on my machine. All in all, noticeable improvement! Setup: |
Thanks! |
nownwe added unison to sin you can run pretty cpu hot with 16 voices calling std::sin on every voice at every sample. This is a well solved problem so use one of those solutions .
The text was updated successfully, but these errors were encountered: