From c0783367e9142a6f2525430d0ecb143e960ae0b2 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 3 Jun 2005 00:57:52 +0000 Subject: [PATCH] completed pitchdetection wrapper, moved to function pointers --- src/pitchdetection.c | 124 +++++++++++++++++++++++++++---------------- src/pitchdetection.h | 8 ++- 2 files changed, 84 insertions(+), 48 deletions(-) diff --git a/src/pitchdetection.c b/src/pitchdetection.c index 4e5d7009..f4347041 100644 --- a/src/pitchdetection.c +++ b/src/pitchdetection.c @@ -20,11 +20,16 @@ #include "sample.h" #include "phasevoc.h" #include "mathutils.h" -#include "filter.h" -#include "pitchyin.h" +//#include "filter.h" #include "pitchmcomb.h" +#include "pitchyin.h" +#include "pitchfcomb.h" +#include "pitchschmitt.h" #include "pitchdetection.h" +typedef smpl_t (*aubio_pitchdetection_func_t)(aubio_pitchdetection_t *p, + fvec_t * ibuf); + struct _aubio_pitchdetection_t { aubio_pitchdetection_type type; aubio_pitchdetection_mode mode; @@ -34,10 +39,13 @@ struct _aubio_pitchdetection_t { aubio_pvoc_t * pv; cvec_t * fftgrain; aubio_pitchmcomb_t * mcomb; - aubio_filter_t * filter; + aubio_pitchfcomb_t * fcomb; + aubio_pitchschmitt_t * schmitt; + //aubio_filter_t * filter; /* for yin */ fvec_t * buf; fvec_t * yin; + aubio_pitchdetection_func_t callback; }; aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize, @@ -55,15 +63,24 @@ aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize, case aubio_yin: p->buf = new_fvec(bufsize,channels); p->yin = new_fvec(bufsize/2,channels); + p->callback = aubio_pitchdetection_yin; break; case aubio_mcomb: p->pv = new_aubio_pvoc(bufsize, hopsize, channels); p->fftgrain = new_cvec(bufsize, channels); - p->filter = new_aubio_adsgn_filter((smpl_t)samplerate); p->mcomb = new_aubio_pitchmcomb(bufsize,channels); + p->callback = aubio_pitchdetection_mcomb; break; - default: - break; + case aubio_fcomb: + p->fcomb = new_aubio_pitchfcomb(bufsize,samplerate); + p->callback = aubio_pitchdetection_fcomb; + break; + case aubio_schmitt: + p->schmitt = new_aubio_pitchschmitt(bufsize,samplerate); + p->callback = aubio_pitchdetection_mcomb; + break; + default: + break; } return p; } @@ -77,55 +94,68 @@ void del_aubio_pitchdetection(aubio_pitchdetection_t * p) { case aubio_mcomb: del_aubio_pvoc(p->pv); del_cvec(p->fftgrain); - //del_aubio_adsgn_filter(p->filter); - //del_aubio_pitchmcomb(p->mcomb); + del_aubio_pitchmcomb(p->mcomb); break; + case aubio_schmitt: + del_aubio_pitchschmitt(p->schmitt); + break; + case aubio_fcomb: + del_aubio_pitchfcomb(p->fcomb); + break; default: break; } AUBIO_FREE(p); } -/** \bug ugly, should replace with function pointers or so */ smpl_t aubio_pitchdetection(aubio_pitchdetection_t *p, fvec_t * ibuf) { + return p->callback(p,ibuf); +} + +smpl_t aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t *ibuf) { + smpl_t pitch = 0.; + aubio_pvoc_do(p->pv,ibuf,p->fftgrain); + pitch = aubio_pitchmcomb_detect(p->mcomb,p->fftgrain); + /** \bug should move the >0 check within bintofreq */ + if (pitch>0.) { + pitch = bintofreq(pitch,p->srate,p->bufsize); + } else { + pitch = 0.; + } + return pitch; +} + +smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf) { smpl_t pitch = 0.; uint_t i,j = 0, overlap_size = 0; - switch(p->type) { - case aubio_yin: - overlap_size = p->buf->length-ibuf->length; - /* do sliding window blocking */ - for (i=0;ibuf->channels;i++){ - for (j=0;jbuf->data[i][j] = - p->buf->data[i][j+ibuf->length]; - } - } - for (i=0;ichannels;i++){ - for (j=0;jlength;j++){ - p->buf->data[i][j+overlap_size] = - ibuf->data[i][j]; - } - } - pitch = aubio_pitchyin_getpitchfast(p->buf,p->yin, 0.5); - if (pitch>0) { - pitch = p->srate/(pitch+0.); - } else { - pitch = 0.; - } - break; - case aubio_mcomb: - aubio_filter_do(p->filter,ibuf); - aubio_filter_do(p->filter,ibuf); - aubio_pvoc_do(p->pv,ibuf,p->fftgrain); - pitch = aubio_pitchmcomb_detect(p->mcomb,p->fftgrain); - if (pitch>0.) { - pitch = bintofreq(pitch,p->srate,p->bufsize); - } else { - pitch = 0.; - } - break; - default: - break; - } - return pitch; + overlap_size = p->buf->length-ibuf->length; + /* do sliding window blocking */ + for (i=0;ibuf->channels;i++){ + for (j=0;jbuf->data[i][j] = + p->buf->data[i][j+ibuf->length]; + } + } + for (i=0;ichannels;i++){ + for (j=0;jlength;j++){ + p->buf->data[i][j+overlap_size] = + ibuf->data[i][j]; + } + } + pitch = aubio_pitchyin_getpitchfast(p->buf,p->yin, 0.5); + if (pitch>0) { + pitch = p->srate/(pitch+0.); + } else { + pitch = 0.; + } + return pitch; +} + + +smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf){ + return aubio_pitchfcomb_detect(p->fcomb,ibuf); +} + +smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf){ + return aubio_pitchschmitt_detect(p->schmitt,ibuf); } diff --git a/src/pitchdetection.h b/src/pitchdetection.h index 220a6bbc..50129d9c 100644 --- a/src/pitchdetection.h +++ b/src/pitchdetection.h @@ -25,7 +25,9 @@ extern "C" { typedef enum { aubio_yin, - aubio_mcomb + aubio_mcomb, + aubio_schmitt, + aubio_fcomb } aubio_pitchdetection_type; typedef enum { @@ -38,6 +40,10 @@ typedef enum { typedef struct _aubio_pitchdetection_t aubio_pitchdetection_t; smpl_t aubio_pitchdetection(aubio_pitchdetection_t * p, fvec_t * ibuf); +smpl_t aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t * ibuf); +smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf); +smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf); +smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf); void del_aubio_pitchdetection(aubio_pitchdetection_t * p); -- 2.26.2