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

Improve Oscillator performance by avoiding fmodf #188

Merged
merged 1 commit into from
Dec 11, 2023

Conversation

ndonald2
Copy link
Contributor

Summary

Adds a fastmod1f method to the dsp utils header which is significantly faster than fmodf(x, 1.0f), and use this in Oscillator for nontrivial performance gains.

Details

This optimization really adds up when processing multiple oscillators in more complex applications and when using block-based DSP instead of sample-by-sample, but even with DaisySP defaults the savings are obvious.

I neglected to add this optimization to BlOsc because:

  1. The measured performance gains are negligible (the cost of the rest of the DSP outweighs the optimization gain)
  2. The sawtooth fmodf invocation has a variable second argument (not just 1.0f)

Performance Metrics

Measured using CpuLoadMeter and the basic seed oscillator example from DaisyExamples at Sample Rate 48kHz and Block Size 4, with the POLYBLEP_TRI waveform.

Before:

Load min:  2.196%    Max:  3.372%    Average:  2.602%

After:

Load min:  1.500%    Max:  2.316%    Average:  1.607%

@stephenhensley
Copy link
Collaborator

Nice!
This is a great idea, and a nice little optimization. That type of performance improvement definitely adds up.

Thanks for the PR!

We'll review this and do some light testing, but I think it looks good as is.
I'll let you know if there's anything to do before we merge it.

@beserge
Copy link
Contributor

beserge commented Dec 11, 2023

Looks great! Thank you for the thorough PR. 🎸

@beserge beserge merged commit 37f4f8b into electro-smith:master Dec 11, 2023
2 checks passed
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.

None yet

3 participants