perf(onset): skip atan2 phase computation for norm-only ODFs (~2x spe…#437
Open
cemkod wants to merge 1 commit intoaubio:masterfrom
Open
perf(onset): skip atan2 phase computation for norm-only ODFs (~2x spe…#437cemkod wants to merge 1 commit intoaubio:masterfrom
cemkod wants to merge 1 commit intoaubio:masterfrom
Conversation
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.
aubio_fft_do always calls aubio_fft_get_spectrum, which computes both magnitude and phase for every frequency bin. The phase computation is dominated by atan2 which is an expensive transcendental function that is called once per bin per frame.
6 of aubio's 9 onset detection functions (energy, hfc, kl, mkl, specflux, specdiff) only ever read fftgrain->norm. The phase array gets populated and silently thrown away every single frame. For a 1024-point FFT that's ~513 wasted atan2 calls per hop.
The Fix
Three layers, following aubio's existing idiom of parallel _do variants:
aubio_fft_do_norm_only() (fft.c/h): runs the FFT but calls aubio_fft_get_norm instead of aubio_fft_get_spectrum, skipping the atan2 loop entirely.
aubio_pvoc_do_norm() (phasevoc.c/h): identical to aubio_pvoc_do (swap buffers -> window -> shift -> FFT) but calls aubio_fft_do_norm_only at the end.
onset.c — adds a skip_phas flag to _aubio_onset_t. In aubio_onset_do it branches on the flag to call either aubio_pvoc_do_norm or aubio_pvoc_do. In aubio_onset_set_default_parameters the flag is set to 1 for the 6 norm-only ODFs, and left 0 for complex, phase, and wphase.
No public API changes — everything is internal to the onset object.
Test Results
pvoc_do (full): 1592.5 ms for 100000 frames (15.93 us/frame)
pvoc_do_norm (no phase): 732.1 ms for 100000 frames ( 7.32 us/frame)
speedup: 2.18x