From: Paul Brossier Date: Thu, 5 Nov 2009 23:06:27 +0000 (+0100) Subject: src/: rename peakpick.h to peakpicker.h, make public again X-Git-Tag: 0.4.0-beta1~549 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=3e17aed37ad2b2c7b1d5b7e4e0900b183416e058;p=aubio.git src/: rename peakpick.h to peakpicker.h, make public again --- diff --git a/src/aubio.h b/src/aubio.h index 3079e75b..269e88be 100644 --- a/src/aubio.h +++ b/src/aubio.h @@ -169,6 +169,7 @@ extern "C" #include "spectral/specdesc.h" #include "pitch/pitch.h" #include "onset/onset.h" +#include "onset/peakpicker.h" #include "tempo/tempo.h" #if AUBIO_UNSTABLE @@ -184,7 +185,6 @@ extern "C" #include "pitch/pitchyinfft.h" #include "pitch/pitchschmitt.h" #include "pitch/pitchfcomb.h" -#include "onset/peakpick.h" #include "tempo/beattracking.h" #endif diff --git a/src/onset/onset.c b/src/onset/onset.c index e9c0a4cc..fee33747 100644 --- a/src/onset/onset.c +++ b/src/onset/onset.c @@ -23,7 +23,7 @@ #include "cvec.h" #include "spectral/specdesc.h" #include "spectral/phasevoc.h" -#include "onset/peakpick.h" +#include "onset/peakpicker.h" #include "mathutils.h" #include "onset/onset.h" diff --git a/src/onset/peakpick.c b/src/onset/peakpick.c deleted file mode 100644 index 43081b93..00000000 --- a/src/onset/peakpick.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - Copyright (C) 2003-2009 Paul Brossier - - This file is part of aubio. - - aubio is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - aubio is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with aubio. If not, see . - -*/ - -#include "aubio_priv.h" -#include "fvec.h" -#include "mathutils.h" -#include "lvec.h" -#include "temporal/filter.h" -#include "temporal/biquad.h" -#include "onset/peakpick.h" - -/** function pointer to thresholding function */ -typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input, uint_t channel); -/** function pointer to peak-picking function */ -typedef uint_t (*aubio_pickerfn_t)(fvec_t *input, uint_t pos); - -/** set peak picker thresholding function */ -uint_t aubio_peakpicker_set_thresholdfn(aubio_peakpicker_t * p, aubio_thresholdfn_t thresholdfn); -/** get peak picker thresholding function */ -aubio_thresholdfn_t aubio_peakpicker_get_thresholdfn(aubio_peakpicker_t * p); - -/* peak picking parameters, default values in brackets - * - * [<----post----|--pre-->] - * .................|............. - * time-> ^now - */ -struct _aubio_peakpicker_t -{ - /** thresh: offset threshold [0.033 or 0.01] */ - smpl_t threshold; - /** win_post: median filter window length (causal part) [8] */ - uint_t win_post; - /** pre: median filter window (anti-causal part) [post-1] */ - uint_t win_pre; - /** threshfn: name or handle of fn for computing adaptive threshold [median] */ - aubio_thresholdfn_t thresholdfn; - /** picker: name or handle of fn for picking event times [peakpick] */ - aubio_pickerfn_t pickerfn; - - /** biquad lowpass filter */ - aubio_filter_t *biquad; - /** original onsets */ - fvec_t *onset_keep; - /** modified onsets */ - fvec_t *onset_proc; - /** peak picked window [3] */ - fvec_t *onset_peek; - /** thresholded function */ - fvec_t *thresholded; - /** scratch pad for biquad and median */ - fvec_t *scratch; - - /** number of channels to analyse */ - uint_t channels; - - /** \bug should be used to calculate filter coefficients */ - /* cutoff: low-pass filter cutoff [0.34, 1] */ - /* smpl_t cutoff; */ - - /* not used anymore */ - /* time precision [512/44100 winlength/samplerate, fs/buffer_size */ - /* smpl_t tau; */ - /* alpha: normalisation exponent [9] */ - /* smpl_t alpha; */ -}; - - -/** modified version for real time, moving mean adaptive threshold this method - * is slightly more permissive than the offline one, and yelds to an increase - * of false positives. best */ -void -aubio_peakpicker_do (aubio_peakpicker_t * p, fvec_t * onset, fvec_t * out) -{ - fvec_t *onset_keep = p->onset_keep; - fvec_t *onset_proc = p->onset_proc; - fvec_t *onset_peek = p->onset_peek; - fvec_t *thresholded = p->thresholded; - fvec_t *scratch = p->scratch; - smpl_t mean = 0., median = 0.; - uint_t length = p->win_post + p->win_pre + 1; - uint_t i, j = 0; - - for (i = 0; i < p->channels; i++) { - /* store onset in onset_keep */ - /* shift all elements but last, then write last */ - for (j = 0; j < length - 1; j++) { - onset_keep->data[i][j] = onset_keep->data[i][j + 1]; - onset_proc->data[i][j] = onset_keep->data[i][j]; - } - onset_keep->data[i][length - 1] = onset->data[i][0]; - onset_proc->data[i][length - 1] = onset->data[i][0]; - } - - /* filter onset_proc */ - /** \bug filtfilt calculated post+pre times, should be only once !? */ - aubio_filter_do_filtfilt (p->biquad, onset_proc, scratch); - - for (i = 0; i < p->channels; i++) { - /* calculate mean and median for onset_proc */ - mean = fvec_mean_channel (onset_proc, i); - /* copy to scratch */ - for (j = 0; j < length; j++) - scratch->data[i][j] = onset_proc->data[i][j]; - median = p->thresholdfn (scratch, i); - - /* shift peek array */ - for (j = 0; j < 3 - 1; j++) - onset_peek->data[i][j] = onset_peek->data[i][j + 1]; - /* calculate new tresholded value */ - thresholded->data[i][0] = - onset_proc->data[i][p->win_post] - median - mean * p->threshold; - onset_peek->data[i][2] = thresholded->data[i][0]; - out->data[i][0] = (p->pickerfn) (onset_peek, 1); - if (out->data[i][0]) { - out->data[i][0] = fvec_quadint (onset_peek, 1, i); - } - } -} - -/** this method returns the current value in the pick peaking buffer - * after smoothing - */ -fvec_t * -aubio_peakpicker_get_thresholded_input (aubio_peakpicker_t * p) -{ - return p->thresholded; -} - -uint_t -aubio_peakpicker_set_threshold (aubio_peakpicker_t * p, smpl_t threshold) -{ - p->threshold = threshold; - return AUBIO_OK; -} - -smpl_t -aubio_peakpicker_get_threshold (aubio_peakpicker_t * p) -{ - return p->threshold; -} - -uint_t -aubio_peakpicker_set_thresholdfn (aubio_peakpicker_t * p, - aubio_thresholdfn_t thresholdfn) -{ - p->thresholdfn = thresholdfn; - return AUBIO_OK; -} - -aubio_thresholdfn_t -aubio_peakpicker_get_thresholdfn (aubio_peakpicker_t * p) -{ - return (aubio_thresholdfn_t) (p->thresholdfn); -} - -aubio_peakpicker_t * -new_aubio_peakpicker (uint_t channels) -{ - aubio_peakpicker_t *t = AUBIO_NEW (aubio_peakpicker_t); - t->threshold = 0.1; /* 0.0668; 0.33; 0.082; 0.033; */ - t->win_post = 5; - t->win_pre = 1; - //channels = 1; - t->channels = channels; - - t->thresholdfn = (aubio_thresholdfn_t) (fvec_median_channel); /* (fvec_mean); */ - t->pickerfn = (aubio_pickerfn_t) (fvec_peakpick); - - t->scratch = new_fvec (t->win_post + t->win_pre + 1, channels); - t->onset_keep = new_fvec (t->win_post + t->win_pre + 1, channels); - t->onset_proc = new_fvec (t->win_post + t->win_pre + 1, channels); - t->onset_peek = new_fvec (3, channels); - t->thresholded = new_fvec (1, channels); - - /* cutoff: low-pass filter with cutoff reduced frequency at 0.34 - generated with octave butter function: [b,a] = butter(2, 0.34); - */ - t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789, - -0.59488894, 0.23484048, channels); - - return t; -} - -void -del_aubio_peakpicker (aubio_peakpicker_t * p) -{ - del_aubio_filter (p->biquad); - del_fvec (p->onset_keep); - del_fvec (p->onset_proc); - del_fvec (p->onset_peek); - del_fvec (p->thresholded); - del_fvec (p->scratch); - AUBIO_FREE (p); -} diff --git a/src/onset/peakpick.h b/src/onset/peakpick.h deleted file mode 100644 index 3f46ce7f..00000000 --- a/src/onset/peakpick.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright (C) 2003-2009 Paul Brossier - - This file is part of aubio. - - aubio is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - aubio is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with aubio. If not, see . - -*/ - -/** \file - - Peak picking utilities function - -*/ - -#ifndef PEAKPICK_H -#define PEAKPICK_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** peak-picker structure */ -typedef struct _aubio_peakpicker_t aubio_peakpicker_t; - -/** peak-picker creation function */ -aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels); -/** real time peak picking function */ -void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out); -/** destroy peak picker structure */ -void del_aubio_peakpicker(aubio_peakpicker_t * p); - -/** get current peak value */ -fvec_t *aubio_peakpicker_get_thresholded_input (aubio_peakpicker_t * p); -/** set peak picking threshold */ -uint_t aubio_peakpicker_set_threshold(aubio_peakpicker_t * p, smpl_t threshold); -/** get peak picking threshold */ -smpl_t aubio_peakpicker_get_threshold(aubio_peakpicker_t * p); - -#ifdef __cplusplus -} -#endif - -#endif /* PEAKPICK_H */ diff --git a/src/onset/peakpicker.c b/src/onset/peakpicker.c new file mode 100644 index 00000000..71985de8 --- /dev/null +++ b/src/onset/peakpicker.c @@ -0,0 +1,212 @@ +/* + Copyright (C) 2003-2009 Paul Brossier + + This file is part of aubio. + + aubio is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + aubio is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with aubio. If not, see . + +*/ + +#include "aubio_priv.h" +#include "fvec.h" +#include "mathutils.h" +#include "lvec.h" +#include "temporal/filter.h" +#include "temporal/biquad.h" +#include "onset/peakpicker.h" + +/** function pointer to thresholding function */ +typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input, uint_t channel); +/** function pointer to peak-picking function */ +typedef uint_t (*aubio_pickerfn_t)(fvec_t *input, uint_t pos); + +/** set peak picker thresholding function */ +uint_t aubio_peakpicker_set_thresholdfn(aubio_peakpicker_t * p, aubio_thresholdfn_t thresholdfn); +/** get peak picker thresholding function */ +aubio_thresholdfn_t aubio_peakpicker_get_thresholdfn(aubio_peakpicker_t * p); + +/* peak picking parameters, default values in brackets + * + * [<----post----|--pre-->] + * .................|............. + * time-> ^now + */ +struct _aubio_peakpicker_t +{ + /** thresh: offset threshold [0.033 or 0.01] */ + smpl_t threshold; + /** win_post: median filter window length (causal part) [8] */ + uint_t win_post; + /** pre: median filter window (anti-causal part) [post-1] */ + uint_t win_pre; + /** threshfn: name or handle of fn for computing adaptive threshold [median] */ + aubio_thresholdfn_t thresholdfn; + /** picker: name or handle of fn for picking event times [peakpick] */ + aubio_pickerfn_t pickerfn; + + /** biquad lowpass filter */ + aubio_filter_t *biquad; + /** original onsets */ + fvec_t *onset_keep; + /** modified onsets */ + fvec_t *onset_proc; + /** peak picked window [3] */ + fvec_t *onset_peek; + /** thresholded function */ + fvec_t *thresholded; + /** scratch pad for biquad and median */ + fvec_t *scratch; + + /** number of channels to analyse */ + uint_t channels; + + /** \bug should be used to calculate filter coefficients */ + /* cutoff: low-pass filter cutoff [0.34, 1] */ + /* smpl_t cutoff; */ + + /* not used anymore */ + /* time precision [512/44100 winlength/samplerate, fs/buffer_size */ + /* smpl_t tau; */ + /* alpha: normalisation exponent [9] */ + /* smpl_t alpha; */ +}; + + +/** modified version for real time, moving mean adaptive threshold this method + * is slightly more permissive than the offline one, and yelds to an increase + * of false positives. best */ +void +aubio_peakpicker_do (aubio_peakpicker_t * p, fvec_t * onset, fvec_t * out) +{ + fvec_t *onset_keep = p->onset_keep; + fvec_t *onset_proc = p->onset_proc; + fvec_t *onset_peek = p->onset_peek; + fvec_t *thresholded = p->thresholded; + fvec_t *scratch = p->scratch; + smpl_t mean = 0., median = 0.; + uint_t length = p->win_post + p->win_pre + 1; + uint_t i, j = 0; + + for (i = 0; i < p->channels; i++) { + /* store onset in onset_keep */ + /* shift all elements but last, then write last */ + for (j = 0; j < length - 1; j++) { + onset_keep->data[i][j] = onset_keep->data[i][j + 1]; + onset_proc->data[i][j] = onset_keep->data[i][j]; + } + onset_keep->data[i][length - 1] = onset->data[i][0]; + onset_proc->data[i][length - 1] = onset->data[i][0]; + } + + /* filter onset_proc */ + /** \bug filtfilt calculated post+pre times, should be only once !? */ + aubio_filter_do_filtfilt (p->biquad, onset_proc, scratch); + + for (i = 0; i < p->channels; i++) { + /* calculate mean and median for onset_proc */ + mean = fvec_mean_channel (onset_proc, i); + /* copy to scratch */ + for (j = 0; j < length; j++) + scratch->data[i][j] = onset_proc->data[i][j]; + median = p->thresholdfn (scratch, i); + + /* shift peek array */ + for (j = 0; j < 3 - 1; j++) + onset_peek->data[i][j] = onset_peek->data[i][j + 1]; + /* calculate new tresholded value */ + thresholded->data[i][0] = + onset_proc->data[i][p->win_post] - median - mean * p->threshold; + onset_peek->data[i][2] = thresholded->data[i][0]; + out->data[i][0] = (p->pickerfn) (onset_peek, 1); + if (out->data[i][0]) { + out->data[i][0] = fvec_quadint (onset_peek, 1, i); + } + } +} + +/** this method returns the current value in the pick peaking buffer + * after smoothing + */ +fvec_t * +aubio_peakpicker_get_thresholded_input (aubio_peakpicker_t * p) +{ + return p->thresholded; +} + +uint_t +aubio_peakpicker_set_threshold (aubio_peakpicker_t * p, smpl_t threshold) +{ + p->threshold = threshold; + return AUBIO_OK; +} + +smpl_t +aubio_peakpicker_get_threshold (aubio_peakpicker_t * p) +{ + return p->threshold; +} + +uint_t +aubio_peakpicker_set_thresholdfn (aubio_peakpicker_t * p, + aubio_thresholdfn_t thresholdfn) +{ + p->thresholdfn = thresholdfn; + return AUBIO_OK; +} + +aubio_thresholdfn_t +aubio_peakpicker_get_thresholdfn (aubio_peakpicker_t * p) +{ + return (aubio_thresholdfn_t) (p->thresholdfn); +} + +aubio_peakpicker_t * +new_aubio_peakpicker (uint_t channels) +{ + aubio_peakpicker_t *t = AUBIO_NEW (aubio_peakpicker_t); + t->threshold = 0.1; /* 0.0668; 0.33; 0.082; 0.033; */ + t->win_post = 5; + t->win_pre = 1; + //channels = 1; + t->channels = channels; + + t->thresholdfn = (aubio_thresholdfn_t) (fvec_median_channel); /* (fvec_mean); */ + t->pickerfn = (aubio_pickerfn_t) (fvec_peakpick); + + t->scratch = new_fvec (t->win_post + t->win_pre + 1, channels); + t->onset_keep = new_fvec (t->win_post + t->win_pre + 1, channels); + t->onset_proc = new_fvec (t->win_post + t->win_pre + 1, channels); + t->onset_peek = new_fvec (3, channels); + t->thresholded = new_fvec (1, channels); + + /* cutoff: low-pass filter with cutoff reduced frequency at 0.34 + generated with octave butter function: [b,a] = butter(2, 0.34); + */ + t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789, + -0.59488894, 0.23484048, channels); + + return t; +} + +void +del_aubio_peakpicker (aubio_peakpicker_t * p) +{ + del_aubio_filter (p->biquad); + del_fvec (p->onset_keep); + del_fvec (p->onset_proc); + del_fvec (p->onset_peek); + del_fvec (p->thresholded); + del_fvec (p->scratch); + AUBIO_FREE (p); +} diff --git a/src/onset/peakpicker.h b/src/onset/peakpicker.h new file mode 100644 index 00000000..3f46ce7f --- /dev/null +++ b/src/onset/peakpicker.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2003-2009 Paul Brossier + + This file is part of aubio. + + aubio is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + aubio is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with aubio. If not, see . + +*/ + +/** \file + + Peak picking utilities function + +*/ + +#ifndef PEAKPICK_H +#define PEAKPICK_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** peak-picker structure */ +typedef struct _aubio_peakpicker_t aubio_peakpicker_t; + +/** peak-picker creation function */ +aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels); +/** real time peak picking function */ +void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out); +/** destroy peak picker structure */ +void del_aubio_peakpicker(aubio_peakpicker_t * p); + +/** get current peak value */ +fvec_t *aubio_peakpicker_get_thresholded_input (aubio_peakpicker_t * p); +/** set peak picking threshold */ +uint_t aubio_peakpicker_set_threshold(aubio_peakpicker_t * p, smpl_t threshold); +/** get peak picking threshold */ +smpl_t aubio_peakpicker_get_threshold(aubio_peakpicker_t * p); + +#ifdef __cplusplus +} +#endif + +#endif /* PEAKPICK_H */ diff --git a/src/tempo/tempo.c b/src/tempo/tempo.c index 469ff691..1bbe62c1 100644 --- a/src/tempo/tempo.c +++ b/src/tempo/tempo.c @@ -24,7 +24,7 @@ #include "spectral/specdesc.h" #include "tempo/beattracking.h" #include "spectral/phasevoc.h" -#include "onset/peakpick.h" +#include "onset/peakpicker.h" #include "mathutils.h" #include "tempo/tempo.h"