Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/onset/onset.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ struct _aubio_onset_t {
smpl_t lambda_compression;
uint_t apply_awhitening; /**< apply adaptive spectral whitening */
aubio_spectral_whitening_t *spectral_whitening;
uint_t skip_phas; /**< skip phase computation for norm-only ODFs */
};

/* execute onset detection function on iput buffer */
void aubio_onset_do (aubio_onset_t *o, const fvec_t * input, fvec_t * onset)
{
smpl_t isonset = 0;
aubio_pvoc_do (o->pv,input, o->fftgrain);
if (o->skip_phas)
aubio_pvoc_do_norm(o->pv, input, o->fftgrain);
else
aubio_pvoc_do(o->pv, input, o->fftgrain);
/*
if (apply_filtering) {
}
Expand Down Expand Up @@ -295,9 +299,11 @@ uint_t aubio_onset_set_default_parameters (aubio_onset_t * o, const char_t * ons

/* method specific optimisations */
if (strcmp (onset_mode, "energy") == 0) {
o->skip_phas = 1;
} else if (strcmp (onset_mode, "hfc") == 0 || strcmp (onset_mode, "default") == 0) {
aubio_onset_set_threshold (o, 0.058);
aubio_onset_set_compression (o, 1.);
o->skip_phas = 1;
} else if (strcmp (onset_mode, "complexdomain") == 0
|| strcmp (onset_mode, "complex") == 0) {
aubio_onset_set_delay (o, 4.6 * o->hop_size);
Expand All @@ -313,17 +319,21 @@ uint_t aubio_onset_set_default_parameters (aubio_onset_t * o, const char_t * ons
aubio_onset_set_threshold (o, 0.05);
aubio_onset_set_awhitening(o, 1);
aubio_onset_set_compression (o, 0.02);
o->skip_phas = 1;
} else if (strcmp (onset_mode, "kl") == 0) {
aubio_onset_set_threshold (o, 0.35);
aubio_onset_set_awhitening(o, 1);
aubio_onset_set_compression (o, 0.02);
o->skip_phas = 1;
} else if (strcmp (onset_mode, "specflux") == 0) {
aubio_onset_set_threshold (o, 0.18);
aubio_onset_set_awhitening(o, 1);
aubio_spectral_whitening_set_relax_time(o->spectral_whitening, 100);
aubio_spectral_whitening_set_floor(o->spectral_whitening, 1.);
aubio_onset_set_compression (o, 10.);
o->skip_phas = 1;
} else if (strcmp (onset_mode, "specdiff") == 0) {
o->skip_phas = 1;
} else if (strcmp (onset_mode, "old_default") == 0) {
// used to reproduce results obtained with the previous version
aubio_onset_set_threshold (o, 0.3);
Expand Down
5 changes: 5 additions & 0 deletions src/spectral/fft.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ void aubio_fft_do(aubio_fft_t * s, const fvec_t * input, cvec_t * spectrum) {
aubio_fft_get_spectrum(s->compspec, spectrum);
}

void aubio_fft_do_norm_only(aubio_fft_t * s, const fvec_t * input, cvec_t * spectrum) {
aubio_fft_do_complex(s, input, s->compspec);
aubio_fft_get_norm(s->compspec, spectrum);
}

void aubio_fft_rdo(aubio_fft_t * s, const cvec_t * spectrum, fvec_t * output) {
aubio_fft_get_realimag(spectrum, s->compspec);
aubio_fft_rdo_complex(s, s->compspec, output);
Expand Down
8 changes: 8 additions & 0 deletions src/spectral/fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ void del_aubio_fft(aubio_fft_t * s);

*/
void aubio_fft_do (aubio_fft_t *s, const fvec_t * input, cvec_t * spectrum);
/** compute forward FFT, filling only the norm (magnitude) component

\param s fft object as returned by new_aubio_fft
\param input input signal
\param spectrum output spectrum (phas is left uninitialised)

*/
void aubio_fft_do_norm_only (aubio_fft_t *s, const fvec_t * input, cvec_t * spectrum);
/** compute backward (inverse) FFT

\param s fft object as returned by new_aubio_fft
Expand Down
7 changes: 7 additions & 0 deletions src/spectral/phasevoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ void aubio_pvoc_do(aubio_pvoc_t *pv, const fvec_t * datanew, cvec_t *fftgrain) {
aubio_fft_do (pv->fft,pv->data,fftgrain);
}

void aubio_pvoc_do_norm(aubio_pvoc_t *pv, const fvec_t * datanew, cvec_t *fftgrain) {
aubio_pvoc_swapbuffers(pv, datanew);
fvec_weight(pv->data, pv->w);
fvec_shift(pv->data);
aubio_fft_do_norm_only(pv->fft, pv->data, fftgrain);
}

void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) {
/* calculate rfft */
aubio_fft_rdo(pv->fft,fftgrain,pv->synth);
Expand Down
11 changes: 11 additions & 0 deletions src/spectral/phasevoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ void del_aubio_pvoc(aubio_pvoc_t *pv);

*/
void aubio_pvoc_do(aubio_pvoc_t *pv, const fvec_t *in, cvec_t * fftgrain);
/** compute spectral frame, filling only the norm (magnitude) component

Like aubio_pvoc_do() but skips phase computation (atan2), saving work for
onset detection functions that never read the phase array.

\param pv phase vocoder object as returned by new_aubio_pvoc
\param in new input signal (hop_s long)
\param fftgrain output spectral frame (phas is left uninitialised)

*/
void aubio_pvoc_do_norm(aubio_pvoc_t *pv, const fvec_t *in, cvec_t * fftgrain);
/** compute signal from spectral frame

This function takes an input spectral frame fftgrain of size
Expand Down
41 changes: 41 additions & 0 deletions tests/src/spectral/bench-pvoc-norm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <aubio.h>
#include "utils_tests.h"
#include <time.h>

#define N_FRAMES 100000
#define WIN_S 1024
#define HOP_S 256

int main (void)
{
uint_t i;
fvec_t *in = new_fvec(HOP_S);
cvec_t *fftgrain = new_cvec(WIN_S);
aubio_pvoc_t *pv = new_aubio_pvoc(WIN_S, HOP_S);
if (!in || !fftgrain || !pv) return 1;

/* fill with arbitrary non-zero data */
for (i = 0; i < HOP_S; i++) in->data[i] = (smpl_t)i / HOP_S;

clock_t t0 = clock();
for (i = 0; i < N_FRAMES; i++)
aubio_pvoc_do(pv, in, fftgrain);
double ms_full = (double)(clock() - t0) / CLOCKS_PER_SEC * 1000.0;

t0 = clock();
for (i = 0; i < N_FRAMES; i++)
aubio_pvoc_do_norm(pv, in, fftgrain);
double ms_norm = (double)(clock() - t0) / CLOCKS_PER_SEC * 1000.0;

PRINT_MSG("pvoc_do (full): %.1f ms for %d frames (%.2f us/frame)\n",
ms_full, N_FRAMES, ms_full * 1000.0 / N_FRAMES);
PRINT_MSG("pvoc_do_norm (no phase): %.1f ms for %d frames (%.2f us/frame)\n",
ms_norm, N_FRAMES, ms_norm * 1000.0 / N_FRAMES);
PRINT_MSG("speedup: %.2fx\n", ms_full / ms_norm);

del_aubio_pvoc(pv);
del_fvec(in);
del_cvec(fftgrain);
aubio_cleanup();
return 0;
}