From: Paul Brossier Date: Thu, 8 Oct 2009 18:20:19 +0000 (+0200) Subject: src/pitch/pitchschmitt.c: remove unneeded samplerate parameter, update prototypes... X-Git-Tag: bzr2git~156 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f162cf9b6087f77398c97b7b16b3079460f06a14;p=aubio.git src/pitch/pitchschmitt.c: remove unneeded samplerate parameter, update prototypes, make multichannel --- diff --git a/src/pitch/pitchschmitt.c b/src/pitch/pitchschmitt.c index b1c0eded..46c63528 100644 --- a/src/pitch/pitchschmitt.c +++ b/src/pitch/pitchschmitt.c @@ -31,24 +31,27 @@ struct _aubio_pitchschmitt_t { signed short int *buf; }; -aubio_pitchschmitt_t * new_aubio_pitchschmitt (uint_t size, uint_t samplerate) +aubio_pitchschmitt_t * new_aubio_pitchschmitt (uint_t size) { aubio_pitchschmitt_t * p = AUBIO_NEW(aubio_pitchschmitt_t); p->blockSize = size; p->schmittBuffer = AUBIO_ARRAY(signed short int,p->blockSize); p->buf = AUBIO_ARRAY(signed short int,p->blockSize); p->schmittPointer = p->schmittBuffer; - p->rate = samplerate; return p; } -smpl_t aubio_pitchschmitt_do (aubio_pitchschmitt_t *p, fvec_t * input) +void +aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, fvec_t * input, + fvec_t * output) { - uint_t i; - for (i=0; ilength; i++) { - p->buf[i] = input->data[0][i]*32768.; + uint_t i, j; + for (i = 0; i < input->channels; i++) { + for (j = 0; j < input->length; j++) { + p->buf[j] = input->data[i][j] * 32768.; + } + output->data[i][0] = aubio_schmittS16LE (p, input->length, p->buf); } - return aubio_schmittS16LE(p, input->length, p->buf); } smpl_t aubio_schmittS16LE (aubio_pitchschmitt_t *p, uint_t nframes, signed short int *indata) @@ -58,7 +61,7 @@ smpl_t aubio_schmittS16LE (aubio_pitchschmitt_t *p, uint_t nframes, signed short signed short int *schmittBuffer = p->schmittBuffer; signed short int *schmittPointer = p->schmittPointer; - smpl_t freq = 0., trigfact = 0.6; + smpl_t period = 0., trigfact = 0.6; for (i=0; i startpoint) { - freq = ((smpl_t)p->rate*(tc/(smpl_t)(endpoint-startpoint))); + if ((endpoint > startpoint) && (tc > 0)) { + period = (smpl_t)(endpoint-startpoint)/tc; } } } p->schmittBuffer = schmittBuffer; p->schmittPointer = schmittPointer; - return freq; + return period; } void del_aubio_pitchschmitt (aubio_pitchschmitt_t *p) diff --git a/src/pitch/pitchschmitt.h b/src/pitch/pitchschmitt.h index d1348880..198ad7ee 100644 --- a/src/pitch/pitchschmitt.h +++ b/src/pitch/pitchschmitt.h @@ -45,16 +45,16 @@ typedef struct _aubio_pitchschmitt_t aubio_pitchschmitt_t; \param p pitch detection object as returned by new_aubio_pitchschmitt \param input input signal window (length as specified at creation time) + \param output pitch period estimates, in samples */ -smpl_t aubio_pitchschmitt_do (aubio_pitchschmitt_t *p, fvec_t * input); +void aubio_pitchschmitt_do (aubio_pitchschmitt_t *p, fvec_t * input, fvec_t * output); /** creation of the pitch detection object \param size size of the input buffer to analyse - \param samplerate sampling rate of the signal */ -aubio_pitchschmitt_t * new_aubio_pitchschmitt (uint_t size, uint_t samplerate); +aubio_pitchschmitt_t * new_aubio_pitchschmitt (uint_t size); /** deletion of the pitch detection object \param p pitch detection object as returned by new_aubio_pitchschmitt diff --git a/tests/src/test-pitchschmitt.c b/tests/src/test-pitchschmitt.c index 1fd1b6a1..75edc6bd 100644 --- a/tests/src/test-pitchschmitt.c +++ b/tests/src/test-pitchschmitt.c @@ -3,19 +3,19 @@ int main(){ /* allocate some memory */ uint_t win_s = 1024; /* window size */ - uint_t samplerate = 44100; /* number of channel */ fvec_t * in = new_fvec (win_s, 1); /* input buffer */ - aubio_pitchschmitt_t * o = new_aubio_pitchschmitt( - win_s, samplerate ); + fvec_t * out = new_fvec (1, 1); /* input buffer */ + aubio_pitchschmitt_t * o = new_aubio_pitchschmitt(win_s); uint_t i = 0; while (i < 1000) { - aubio_pitchschmitt_do (o,in); + aubio_pitchschmitt_do (o,in, out); i++; }; del_aubio_pitchschmitt(o); del_fvec(in); + del_fvec(out); aubio_cleanup(); return 0;