ref: 651b97eb39b1ac6e05830882ba7c44e2b942e27d
parent: f841b8165c5cecc0242e2c6e3015d8d5217ef93b
author: Paul Brossier <piem@altern.org>
date: Mon Aug 8 16:08:21 EDT 2005
fix schmitt and fcomb, factorise slideblock code
--- a/src/pitchdetection.c
+++ b/src/pitchdetection.c
@@ -29,6 +29,7 @@
typedef smpl_t (*aubio_pitchdetection_func_t)(aubio_pitchdetection_t *p,
fvec_t * ibuf);
+void aubio_pitchdetection_slideblock(aubio_pitchdetection_t *p, fvec_t *ibuf);
struct _aubio_pitchdetection_t {
aubio_pitchdetection_type type;
@@ -72,12 +73,14 @@
p->callback = aubio_pitchdetection_mcomb;
break;
case aubio_fcomb:
+ p->buf = new_fvec(bufsize,channels);
p->fcomb = new_aubio_pitchfcomb(bufsize,samplerate);
p->callback = aubio_pitchdetection_fcomb;
break;
case aubio_schmitt:
+ p->buf = new_fvec(bufsize,channels);
p->schmitt = new_aubio_pitchschmitt(bufsize,samplerate);
- p->callback = aubio_pitchdetection_mcomb;
+ p->callback = aubio_pitchdetection_schmitt;
break;
default:
break;
@@ -97,9 +100,11 @@
del_aubio_pitchmcomb(p->mcomb);
break;
case aubio_schmitt:
+ del_fvec(p->buf);
del_aubio_pitchschmitt(p->schmitt);
break;
case aubio_fcomb:
+ del_fvec(p->buf);
del_aubio_pitchfcomb(p->fcomb);
break;
default:
@@ -108,6 +113,23 @@
AUBIO_FREE(p);
}
+void aubio_pitchdetection_slideblock(aubio_pitchdetection_t *p, fvec_t *ibuf){
+ uint_t i,j = 0, overlap_size = 0;
+ overlap_size = p->buf->length-ibuf->length;
+ for (i=0;i<p->buf->channels;i++){
+ for (j=0;j<overlap_size;j++){
+ p->buf->data[i][j] =
+ p->buf->data[i][j+ibuf->length];
+ }
+ }
+ for (i=0;i<ibuf->channels;i++){
+ for (j=0;j<ibuf->length;j++){
+ p->buf->data[i][j+overlap_size] =
+ ibuf->data[i][j];
+ }
+ }
+}
+
smpl_t aubio_pitchdetection(aubio_pitchdetection_t *p, fvec_t * ibuf) {
return p->callback(p,ibuf);
}
@@ -127,21 +149,7 @@
smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf) {
smpl_t pitch = 0.;
- uint_t i,j = 0, overlap_size = 0;
- overlap_size = p->buf->length-ibuf->length;
- /* do sliding window blocking */
- for (i=0;i<p->buf->channels;i++){
- for (j=0;j<overlap_size;j++){
- p->buf->data[i][j] =
- p->buf->data[i][j+ibuf->length];
- }
- }
- for (i=0;i<ibuf->channels;i++){
- for (j=0;j<ibuf->length;j++){
- p->buf->data[i][j+overlap_size] =
- ibuf->data[i][j];
- }
- }
+ aubio_pitchdetection_slideblock(p,ibuf);
pitch = aubio_pitchyin_getpitchfast(p->buf,p->yin, 0.5);
if (pitch>0) {
pitch = p->srate/(pitch+0.);
@@ -153,9 +161,11 @@
smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf){
- return aubio_pitchfcomb_detect(p->fcomb,ibuf);
+ aubio_pitchdetection_slideblock(p,ibuf);
+ return aubio_pitchfcomb_detect(p->fcomb,p->buf);
}
smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf){
- return aubio_pitchschmitt_detect(p->schmitt,ibuf);
+ aubio_pitchdetection_slideblock(p,ibuf);
+ return aubio_pitchschmitt_detect(p->schmitt,p->buf);
}