Skip to content

perf(onset): skip atan2 phase computation for norm-only ODFs (~2x spe…#437

Open
cemkod wants to merge 1 commit intoaubio:masterfrom
cemkod:feature/skip-phas-norm-only-odfs
Open

perf(onset): skip atan2 phase computation for norm-only ODFs (~2x spe…#437
cemkod wants to merge 1 commit intoaubio:masterfrom
cemkod:feature/skip-phas-norm-only-odfs

Conversation

@cemkod
Copy link
Copy Markdown

@cemkod cemkod commented Mar 17, 2026

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:

  1. 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.

  2. 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.

  3. 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

  • 2.18× faster phase vocoder step for the 6 norm-only ODFs
  • All 53 existing tests pass unchanged, ODFs that use phase data are unaffected

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.

1 participant