ref: ca1abdd5271f95cfc6949637f31d9347358b246e
parent: 9f07d52148a0c25c53eabc3521e29464013107b4
author: Paul Brossier <[email protected]>
date: Mon Oct 19 06:51:59 EDT 2009
rename aubio_pitchdetection to aubio_pitch
--- a/plugins/puredata/aubiopitch~.c
+++ b/plugins/puredata/aubiopitch~.c
@@ -25,7 +25,7 @@
t_int pos; /*frames%dspblocksize*/
t_int bufsize;
t_int hopsize;
- aubio_pitchdetection_t *o;
+ aubio_pitch_t *o;
fvec_t *vec;
fvec_t *pitchvec;
t_outlet *pitch;
@@ -43,7 +43,7 @@
/*time for fft*/
if (x->pos == x->hopsize-1) {
/* block loop */
- aubio_pitchdetection_do(x->o,x->vec, x->pitchvec);
+ aubio_pitch_do(x->o,x->vec, x->pitchvec);
outlet_float(x->pitch, x->pitchvec->data[0][0]);
/* end of block loop */
x->pos = -1; /* so it will be zero next j loop */
@@ -76,9 +76,9 @@
x->hopsize = x->bufsize / 2;
//FIXME: get the real samplerate
- x->o = new_aubio_pitchdetection(s->s_name, x->bufsize,
+ x->o = new_aubio_pitch(s->s_name, x->bufsize,
x->hopsize, 1, 44100.);
- aubio_pitchdetection_set_tolerance (x->o, 0.7);
+ aubio_pitch_set_tolerance (x->o, 0.7);
x->vec = (fvec_t *)new_fvec(x->hopsize,1);
x->pitchvec = (fvec_t *)new_fvec(1,1);
@@ -91,7 +91,7 @@
static void *aubiopitch_tilde_del(t_aubiopitch_tilde *x)
{
- del_aubio_pitchdetection(x->o);
+ del_aubio_pitch(x->o);
del_fvec(x->vec);
del_fvec(x->pitchvec);
return 0;
--- a/python/aubio/aubioclass.py
+++ b/python/aubio/aubioclass.py
@@ -126,19 +126,19 @@
if dval < self.dcthreshold: isonset = 0
return isonset, dval
-class pitchdetection:
+class pitch:
def __init__(self,mode="mcomb",bufsize=2048,hopsize=1024,
channels=1,samplerate=44100.,omode="freq",tolerance=0.1):
- self.pitchp = new_aubio_pitchdetection(mode,bufsize,hopsize,channels,
+ self.pitchp = new_aubio_pitch(mode,bufsize,hopsize,channels,
samplerate)
self.mypitch = fvec(1, channels)
- aubio_pitchdetection_set_unit(self.pitchp,omode)
- aubio_pitchdetection_set_tolerance(self.pitchp,tolerance)
+ aubio_pitch_set_unit(self.pitchp,omode)
+ aubio_pitch_set_tolerance(self.pitchp,tolerance)
#self.filt = filter(srate,"adsgn")
def __del__(self):
- del_aubio_pitchdetection(self.pitchp)
+ del_aubio_pitch(self.pitchp)
def __call__(self,myvec):
- aubio_pitchdetection_do(self.pitchp,myvec(), self.mypitch())
+ aubio_pitch_do(self.pitchp,myvec(), self.mypitch())
return self.mypitch.get(0,0)
class filter:
--- a/python/aubio/task/notes.py
+++ b/python/aubio/task/notes.py
@@ -13,7 +13,7 @@
mode=self.params.onsetmode,
dcthreshold=self.params.dcthreshold,
derivate=self.params.derivate)
- self.pitchdet = pitchdetection(mode=self.params.pitchmode,
+ self.pitchdet = pitch(mode=self.params.pitchmode,
bufsize=self.params.pbufsize,
hopsize=self.params.phopsize,
channels=self.channels,
--- a/python/aubio/task/pitch.py
+++ b/python/aubio/task/pitch.py
@@ -12,7 +12,7 @@
tolerance = self.params.yinfftthresh
else:
tolerance = 0.
- self.pitchdet = pitchdetection(mode=self.params.pitchmode,
+ self.pitchdet = pitch(mode=self.params.pitchmode,
bufsize=self.params.bufsize,
hopsize=self.params.hopsize,
channels=self.channels,
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,7 +23,7 @@
spectral/fft.h \
spectral/tss.h \
spectral/spectral_centroid.h \
- pitch/pitchdetection.h \
+ pitch/pitch.h \
pitch/pitchmcomb.h \
pitch/pitchyin.h \
pitch/pitchschmitt.h \
@@ -58,7 +58,7 @@
spectral/fft.c \
spectral/tss.c \
spectral/spectral_centroid.c \
- pitch/pitchdetection.c \
+ pitch/pitch.c \
pitch/pitchmcomb.c \
pitch/pitchyin.c \
pitch/pitchschmitt.c \
--- a/src/aubio.h
+++ b/src/aubio.h
@@ -81,7 +81,7 @@
#include "spectral/fft.h"
#include "spectral/phasevoc.h"
#include "spectral/spectral_centroid.h"
-#include "pitch/pitchdetection.h"
+#include "pitch/pitch.h"
#include "pitch/pitchmcomb.h"
#include "pitch/pitchyin.h"
#include "pitch/pitchyinfft.h"
--- /dev/null
+++ b/src/pitch/pitch.c
@@ -1,0 +1,335 @@
+/*
+ Copyright (C) 2003 Paul Brossier
+
+ This program 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 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "aubio_priv.h"
+#include "fvec.h"
+#include "cvec.h"
+#include "lvec.h"
+#include "spectral/phasevoc.h"
+#include "mathutils.h"
+#include "temporal/filter.h"
+#include "temporal/c_weighting.h"
+#include "pitch/pitchmcomb.h"
+#include "pitch/pitchyin.h"
+#include "pitch/pitchfcomb.h"
+#include "pitch/pitchschmitt.h"
+#include "pitch/pitchyinfft.h"
+#include "pitch/pitch.h"
+
+/** pitch detection algorithm */
+typedef enum {
+ aubio_pitcht_yin, /**< YIN algorithm */
+ aubio_pitcht_mcomb, /**< Multi-comb filter */
+ aubio_pitcht_schmitt, /**< Schmitt trigger */
+ aubio_pitcht_fcomb, /**< Fast comb filter */
+ aubio_pitcht_yinfft, /**< Spectral YIN */
+ aubio_pitcht_default = aubio_pitcht_yinfft, /**< the one used when "default" is asked */
+} aubio_pitch_type;
+
+/** pitch detection output mode */
+typedef enum {
+ aubio_pitchm_freq, /**< Frequency (Hz) */
+ aubio_pitchm_midi, /**< MIDI note (0.,127) */
+ aubio_pitchm_cent, /**< Cent */
+ aubio_pitchm_bin, /**< Frequency bin (0,bufsize) */
+ aubio_pitchm_default = aubio_pitchm_freq, /**< the one used when "default" is asked */
+} aubio_pitch_mode;
+
+typedef void (*aubio_pitch_func_t)
+ (aubio_pitch_t *p, fvec_t * ibuf, fvec_t *obuf);
+typedef smpl_t (*aubio_pitch_conv_t)
+ (smpl_t value, uint_t srate, uint_t bufsize);
+
+void aubio_pitch_slideblock(aubio_pitch_t *p, fvec_t *ibuf);
+
+void aubio_pitch_do_mcomb (aubio_pitch_t *p, fvec_t *ibuf, fvec_t *obuf);
+void aubio_pitch_do_yin (aubio_pitch_t *p, fvec_t *ibuf, fvec_t *obuf);
+void aubio_pitch_do_schmitt (aubio_pitch_t *p, fvec_t *ibuf, fvec_t *obuf);
+void aubio_pitch_do_fcomb (aubio_pitch_t *p, fvec_t *ibuf, fvec_t *obuf);
+void aubio_pitch_do_yinfft (aubio_pitch_t *p, fvec_t *ibuf, fvec_t *obuf);
+
+/** generic pitch detection structure */
+struct _aubio_pitch_t {
+ aubio_pitch_type type; /**< pitch detection mode */
+ aubio_pitch_mode mode; /**< pitch detection output mode */
+ uint_t srate; /**< samplerate */
+ uint_t bufsize; /**< buffer size */
+ aubio_pitchmcomb_t * mcomb; /**< mcomb object */
+ aubio_pitchfcomb_t * fcomb; /**< fcomb object */
+ aubio_pitchschmitt_t * schmitt; /**< schmitt object */
+ aubio_pitchyinfft_t * yinfft; /**< yinfft object */
+ aubio_pitchyin_t * yin; /**< yinfft object */
+ aubio_filter_t * filter; /**< filter */
+ aubio_pvoc_t * pv; /**< phase vocoder for mcomb */
+ cvec_t * fftgrain; /**< spectral frame for mcomb */
+ fvec_t * buf; /**< temporary buffer for yin */
+ aubio_pitch_func_t callback; /**< pointer to current pitch detection method */
+ aubio_pitch_conv_t freqconv; /**< pointer to current pitch conversion method */
+};
+
+/* convenience wrapper function for frequency unit conversions
+ * should probably be rewritten with #defines */
+smpl_t freqconvbin(smpl_t f,uint_t srate,uint_t bufsize);
+smpl_t freqconvbin(smpl_t f,uint_t srate,uint_t bufsize){
+ return aubio_freqtobin(f,srate,bufsize);
+}
+
+smpl_t freqconvmidi(smpl_t f,uint_t srate,uint_t bufsize);
+smpl_t freqconvmidi(smpl_t f,uint_t srate UNUSED,uint_t bufsize UNUSED){
+ return aubio_freqtomidi(f);
+}
+
+smpl_t freqconvpass(smpl_t f,uint_t srate,uint_t bufsize);
+smpl_t freqconvpass(smpl_t f,uint_t srate UNUSED,uint_t bufsize UNUSED){
+ return f;
+}
+
+aubio_pitch_t *
+new_aubio_pitch (char_t * pitch_mode,
+ uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate)
+{
+ aubio_pitch_t *p = AUBIO_NEW(aubio_pitch_t);
+ aubio_pitch_type pitch_type;
+ if (strcmp (pitch_mode, "mcomb") == 0)
+ pitch_type = aubio_pitcht_mcomb;
+ else if (strcmp (pitch_mode, "yinfft") == 0)
+ pitch_type = aubio_pitcht_yin;
+ else if (strcmp (pitch_mode, "yin") == 0)
+ pitch_type = aubio_pitcht_yin;
+ else if (strcmp (pitch_mode, "schmitt") == 0)
+ pitch_type = aubio_pitcht_schmitt;
+ else if (strcmp (pitch_mode, "fcomb") == 0)
+ pitch_type = aubio_pitcht_fcomb;
+ else if (strcmp (pitch_mode, "default") == 0)
+ pitch_type = aubio_pitcht_default;
+ else {
+ AUBIO_ERR ("unknown pitch detection method %s, using default.\n", pitch_mode);
+ pitch_type = aubio_pitcht_default;
+ return NULL;
+ }
+ p->srate = samplerate;
+ p->type = pitch_type;
+ aubio_pitch_set_unit (p, "default");
+ p->bufsize = bufsize;
+ switch(p->type) {
+ case aubio_pitcht_yin:
+ p->buf = new_fvec(bufsize,channels);
+ p->yin = new_aubio_pitchyin(bufsize);
+ p->callback = aubio_pitch_do_yin;
+ aubio_pitchyin_set_tolerance (p->yin, 0.15);
+ break;
+ case aubio_pitcht_mcomb:
+ p->pv = new_aubio_pvoc(bufsize, hopsize, channels);
+ p->fftgrain = new_cvec(bufsize, channels);
+ p->mcomb = new_aubio_pitchmcomb(bufsize,hopsize,channels);
+ p->filter = new_aubio_filter_c_weighting (samplerate, channels);
+ p->callback = aubio_pitch_do_mcomb;
+ break;
+ case aubio_pitcht_fcomb:
+ p->buf = new_fvec(bufsize,channels);
+ p->fcomb = new_aubio_pitchfcomb(bufsize,hopsize,channels);
+ p->callback = aubio_pitch_do_fcomb;
+ break;
+ case aubio_pitcht_schmitt:
+ p->buf = new_fvec(bufsize,channels);
+ p->schmitt = new_aubio_pitchschmitt(bufsize);
+ p->callback = aubio_pitch_do_schmitt;
+ break;
+ case aubio_pitcht_yinfft:
+ p->buf = new_fvec(bufsize,channels);
+ p->yinfft = new_aubio_pitchyinfft(bufsize);
+ p->callback = aubio_pitch_do_yinfft;
+ aubio_pitchyinfft_set_tolerance (p->yinfft, 0.85);
+ break;
+ default:
+ break;
+ }
+ return p;
+}
+
+void del_aubio_pitch(aubio_pitch_t * p) {
+ switch(p->type) {
+ case aubio_pitcht_yin:
+ del_fvec(p->buf);
+ del_aubio_pitchyin(p->yin);
+ break;
+ case aubio_pitcht_mcomb:
+ del_aubio_pvoc(p->pv);
+ del_cvec(p->fftgrain);
+ del_aubio_filter(p->filter);
+ del_aubio_pitchmcomb(p->mcomb);
+ break;
+ case aubio_pitcht_schmitt:
+ del_fvec(p->buf);
+ del_aubio_pitchschmitt(p->schmitt);
+ break;
+ case aubio_pitcht_fcomb:
+ del_fvec(p->buf);
+ del_aubio_pitchfcomb(p->fcomb);
+ break;
+ case aubio_pitcht_yinfft:
+ del_fvec(p->buf);
+ del_aubio_pitchyinfft(p->yinfft);
+ break;
+ default:
+ break;
+ }
+ AUBIO_FREE(p);
+}
+
+void aubio_pitch_slideblock(aubio_pitch_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];
+ }
+ }
+}
+
+uint_t aubio_pitch_set_unit (aubio_pitch_t *p, char_t * pitch_unit) {
+ aubio_pitch_mode pitch_mode;
+ if (strcmp (pitch_unit, "freq") == 0)
+ pitch_mode = aubio_pitchm_freq;
+ else if (strcmp (pitch_unit, "midi") == 0)
+ pitch_mode = aubio_pitchm_midi;
+ else if (strcmp (pitch_unit, "cent") == 0)
+ pitch_mode = aubio_pitchm_cent;
+ else if (strcmp (pitch_unit, "bin") == 0)
+ pitch_mode = aubio_pitchm_bin;
+ else if (strcmp (pitch_unit, "default") == 0)
+ pitch_mode = aubio_pitchm_default;
+ else {
+ AUBIO_ERR ("unknown pitch detection unit %s, using default\n", pitch_unit);
+ pitch_mode = aubio_pitchm_default;
+ }
+ p->mode = pitch_mode;
+ switch(p->mode) {
+ case aubio_pitchm_freq:
+ p->freqconv = freqconvpass;
+ break;
+ case aubio_pitchm_midi:
+ p->freqconv = freqconvmidi;
+ break;
+ case aubio_pitchm_cent:
+ /* bug: not implemented */
+ p->freqconv = freqconvmidi;
+ break;
+ case aubio_pitchm_bin:
+ p->freqconv = freqconvbin;
+ break;
+ default:
+ break;
+ }
+ return AUBIO_OK;
+}
+
+uint_t aubio_pitch_set_tolerance(aubio_pitch_t *p, smpl_t tol) {
+ switch(p->type) {
+ case aubio_pitcht_yin:
+ aubio_pitchyin_set_tolerance (p->yin, tol);
+ break;
+ case aubio_pitcht_yinfft:
+ aubio_pitchyinfft_set_tolerance (p->yinfft, tol);
+ break;
+ default:
+ break;
+ }
+ return AUBIO_OK;
+}
+
+void aubio_pitch_do (aubio_pitch_t *p, fvec_t * ibuf, fvec_t *obuf) {
+ uint_t i;
+ p->callback(p, ibuf, obuf);
+ for (i = 0; i < obuf->channels; i++) {
+ p->freqconv(obuf->data[i][0],p->srate,p->bufsize);
+ }
+}
+
+void aubio_pitch_do_mcomb(aubio_pitch_t *p, fvec_t *ibuf, fvec_t * obuf) {
+ uint_t i;
+ aubio_filter_do(p->filter,ibuf);
+ aubio_pvoc_do(p->pv,ibuf,p->fftgrain);
+ aubio_pitchmcomb_do(p->mcomb,p->fftgrain, obuf);
+ for (i = 0; i < obuf->channels; i++) {
+ obuf->data[i][0] = aubio_bintofreq (obuf->data[i][0], p->srate, p->bufsize);
+ }
+}
+
+void aubio_pitch_do_yin(aubio_pitch_t *p, fvec_t *ibuf, fvec_t * obuf) {
+ smpl_t pitch = 0.;
+ uint_t i;
+ aubio_pitch_slideblock(p,ibuf);
+ aubio_pitchyin_do(p->yin,p->buf, obuf);
+ for (i = 0; i < obuf->channels; i++) {
+ pitch = obuf->data[i][0];
+ if (pitch>0) {
+ pitch = p->srate/(pitch+0.);
+ } else {
+ pitch = 0.;
+ }
+ obuf->data[i][0] = pitch;
+ }
+}
+
+
+void aubio_pitch_do_yinfft(aubio_pitch_t *p, fvec_t *ibuf, fvec_t * obuf){
+ smpl_t pitch = 0.;
+ uint_t i;
+ aubio_pitch_slideblock(p,ibuf);
+ aubio_pitchyinfft_do(p->yinfft,p->buf,obuf);
+ for (i = 0; i < obuf->channels; i++) {
+ pitch = obuf->data[i][0];
+ if (pitch>0) {
+ pitch = p->srate/(pitch+0.);
+ } else {
+ pitch = 0.;
+ }
+ obuf->data[i][0] = pitch;
+ }
+}
+
+void aubio_pitch_do_fcomb(aubio_pitch_t *p, fvec_t *ibuf, fvec_t * out){
+ uint_t i;
+ aubio_pitch_slideblock(p,ibuf);
+ aubio_pitchfcomb_do(p->fcomb,p->buf, out);
+ for (i = 0; i < out->channels; i++) {
+ out->data[i][0] = aubio_bintofreq (out->data[i][0], p->srate, p->bufsize);
+ }
+}
+
+void aubio_pitch_do_schmitt(aubio_pitch_t *p, fvec_t *ibuf, fvec_t *out){
+ smpl_t period, pitch = 0.;
+ uint_t i;
+ aubio_pitch_slideblock(p,ibuf);
+ aubio_pitchschmitt_do(p->schmitt,p->buf, out);
+ for (i = 0; i < out->channels; i++) {
+ period = out->data[i][0];
+ if (period>0) {
+ pitch = p->srate/period;
+ } else {
+ pitch = 0.;
+ }
+ out->data[i][0] = pitch;
+ }
+}
--- /dev/null
+++ b/src/pitch/pitch.h
@@ -1,0 +1,89 @@
+/*
+ Copyright (C) 2003 Paul Brossier
+
+ This program 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 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef PITCH_H
+#define PITCH_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** \file
+
+ Generic method for pitch detection
+
+ This file creates the objects required for the computation of the selected
+ pitch detection algorithm and output the results, in midi note or Hz.
+
+*/
+
+/** pitch detection object */
+typedef struct _aubio_pitch_t aubio_pitch_t;
+
+/** execute pitch detection on an input signal frame
+
+ \param o pitch detection object as returned by new_aubio_pitch()
+ \param in input signal of size [hopsize x channels]
+ \param out output pitch candidates of size [1 x channes]
+
+*/
+void aubio_pitch_do (aubio_pitch_t * o, fvec_t * in,
+ fvec_t * out);
+
+/** change yin or yinfft tolerance threshold
+
+ \param o pitch detection object as returned by new_aubio_pitch()
+ \param tol tolerance default is 0.15 for yin and 0.85 for yinfft
+
+*/
+uint_t aubio_pitch_set_tolerance (aubio_pitch_t * o,
+ smpl_t tol);
+
+/** deletion of the pitch detection object
+
+ \param o pitch detection object as returned by new_aubio_pitch()
+
+*/
+void del_aubio_pitch (aubio_pitch_t * o);
+
+/** creation of the pitch detection object
+
+ \param mode set pitch detection algorithm
+ \param bufsize size of the input buffer to analyse
+ \param hopsize step size between two consecutive analysis instant
+ \param channels number of channels to analyse
+ \param samplerate sampling rate of the signal
+
+*/
+aubio_pitch_t * new_aubio_pitch (char_t * mode,
+ uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate);
+
+/** set the output unit of the pitch detection object
+
+ \param o pitch detection object as returned by new_aubio_pitch()
+ \param mode set pitch units for output
+
+*/
+uint_t aubio_pitch_set_unit (aubio_pitch_t * o,
+ char_t * mode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*PITCH_H*/
--- a/src/pitch/pitchdetection.c
+++ /dev/null
@@ -1,335 +1,0 @@
-/*
- Copyright (C) 2003 Paul Brossier
-
- This program 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 2 of the License, or
- (at your option) any later version.
-
- This program 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 this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include "aubio_priv.h"
-#include "fvec.h"
-#include "cvec.h"
-#include "lvec.h"
-#include "spectral/phasevoc.h"
-#include "mathutils.h"
-#include "temporal/filter.h"
-#include "temporal/c_weighting.h"
-#include "pitch/pitchmcomb.h"
-#include "pitch/pitchyin.h"
-#include "pitch/pitchfcomb.h"
-#include "pitch/pitchschmitt.h"
-#include "pitch/pitchyinfft.h"
-#include "pitch/pitchdetection.h"
-
-/** pitch detection algorithm */
-typedef enum {
- aubio_pitch_yin, /**< YIN algorithm */
- aubio_pitch_mcomb, /**< Multi-comb filter */
- aubio_pitch_schmitt, /**< Schmitt trigger */
- aubio_pitch_fcomb, /**< Fast comb filter */
- aubio_pitch_yinfft, /**< Spectral YIN */
- aubio_pitch_default = aubio_pitch_yinfft, /**< the one used when "default" is asked */
-} aubio_pitchdetection_type;
-
-/** pitch detection output mode */
-typedef enum {
- aubio_pitchm_freq, /**< Frequency (Hz) */
- aubio_pitchm_midi, /**< MIDI note (0.,127) */
- aubio_pitchm_cent, /**< Cent */
- aubio_pitchm_bin, /**< Frequency bin (0,bufsize) */
- aubio_pitchm_default = aubio_pitchm_freq, /**< the one used when "default" is asked */
-} aubio_pitchdetection_mode;
-
-typedef void (*aubio_pitchdetection_func_t)
- (aubio_pitchdetection_t *p, fvec_t * ibuf, fvec_t *obuf);
-typedef smpl_t (*aubio_pitchdetection_conv_t)
- (smpl_t value, uint_t srate, uint_t bufsize);
-
-void aubio_pitchdetection_slideblock(aubio_pitchdetection_t *p, fvec_t *ibuf);
-
-void aubio_pitchdetection_mcomb (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf);
-void aubio_pitchdetection_yin (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf);
-void aubio_pitchdetection_schmitt (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf);
-void aubio_pitchdetection_fcomb (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf);
-void aubio_pitchdetection_yinfft (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf);
-
-/** generic pitch detection structure */
-struct _aubio_pitchdetection_t {
- aubio_pitchdetection_type type; /**< pitch detection mode */
- aubio_pitchdetection_mode mode; /**< pitch detection output mode */
- uint_t srate; /**< samplerate */
- uint_t bufsize; /**< buffer size */
- aubio_pitchmcomb_t * mcomb; /**< mcomb object */
- aubio_pitchfcomb_t * fcomb; /**< fcomb object */
- aubio_pitchschmitt_t * schmitt; /**< schmitt object */
- aubio_pitchyinfft_t * yinfft; /**< yinfft object */
- aubio_pitchyin_t * yin; /**< yinfft object */
- aubio_filter_t * filter; /**< filter */
- aubio_pvoc_t * pv; /**< phase vocoder for mcomb */
- cvec_t * fftgrain; /**< spectral frame for mcomb */
- fvec_t * buf; /**< temporary buffer for yin */
- aubio_pitchdetection_func_t callback; /**< pointer to current pitch detection method */
- aubio_pitchdetection_conv_t freqconv; /**< pointer to current pitch conversion method */
-};
-
-/* convenience wrapper function for frequency unit conversions
- * should probably be rewritten with #defines */
-smpl_t freqconvbin(smpl_t f,uint_t srate,uint_t bufsize);
-smpl_t freqconvbin(smpl_t f,uint_t srate,uint_t bufsize){
- return aubio_freqtobin(f,srate,bufsize);
-}
-
-smpl_t freqconvmidi(smpl_t f,uint_t srate,uint_t bufsize);
-smpl_t freqconvmidi(smpl_t f,uint_t srate UNUSED,uint_t bufsize UNUSED){
- return aubio_freqtomidi(f);
-}
-
-smpl_t freqconvpass(smpl_t f,uint_t srate,uint_t bufsize);
-smpl_t freqconvpass(smpl_t f,uint_t srate UNUSED,uint_t bufsize UNUSED){
- return f;
-}
-
-aubio_pitchdetection_t *
-new_aubio_pitchdetection (char_t * pitch_mode,
- uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate)
-{
- aubio_pitchdetection_t *p = AUBIO_NEW(aubio_pitchdetection_t);
- aubio_pitchdetection_type pitch_type;
- if (strcmp (pitch_mode, "mcomb") == 0)
- pitch_type = aubio_pitch_mcomb;
- else if (strcmp (pitch_mode, "yinfft") == 0)
- pitch_type = aubio_pitch_yin;
- else if (strcmp (pitch_mode, "yin") == 0)
- pitch_type = aubio_pitch_yin;
- else if (strcmp (pitch_mode, "schmitt") == 0)
- pitch_type = aubio_pitch_schmitt;
- else if (strcmp (pitch_mode, "fcomb") == 0)
- pitch_type = aubio_pitch_fcomb;
- else if (strcmp (pitch_mode, "default") == 0)
- pitch_type = aubio_pitch_default;
- else {
- AUBIO_ERR ("unknown pitch detection method %s, using default.\n", pitch_mode);
- pitch_type = aubio_pitch_default;
- return NULL;
- }
- p->srate = samplerate;
- p->type = pitch_type;
- aubio_pitchdetection_set_unit (p, "default");
- p->bufsize = bufsize;
- switch(p->type) {
- case aubio_pitch_yin:
- p->buf = new_fvec(bufsize,channels);
- p->yin = new_aubio_pitchyin(bufsize);
- p->callback = aubio_pitchdetection_yin;
- aubio_pitchyin_set_tolerance (p->yin, 0.15);
- break;
- case aubio_pitch_mcomb:
- p->pv = new_aubio_pvoc(bufsize, hopsize, channels);
- p->fftgrain = new_cvec(bufsize, channels);
- p->mcomb = new_aubio_pitchmcomb(bufsize,hopsize,channels);
- p->filter = new_aubio_filter_c_weighting (samplerate, channels);
- p->callback = aubio_pitchdetection_mcomb;
- break;
- case aubio_pitch_fcomb:
- p->buf = new_fvec(bufsize,channels);
- p->fcomb = new_aubio_pitchfcomb(bufsize,hopsize,channels);
- p->callback = aubio_pitchdetection_fcomb;
- break;
- case aubio_pitch_schmitt:
- p->buf = new_fvec(bufsize,channels);
- p->schmitt = new_aubio_pitchschmitt(bufsize);
- p->callback = aubio_pitchdetection_schmitt;
- break;
- case aubio_pitch_yinfft:
- p->buf = new_fvec(bufsize,channels);
- p->yinfft = new_aubio_pitchyinfft(bufsize);
- p->callback = aubio_pitchdetection_yinfft;
- aubio_pitchyinfft_set_tolerance (p->yinfft, 0.85);
- break;
- default:
- break;
- }
- return p;
-}
-
-void del_aubio_pitchdetection(aubio_pitchdetection_t * p) {
- switch(p->type) {
- case aubio_pitch_yin:
- del_fvec(p->buf);
- del_aubio_pitchyin(p->yin);
- break;
- case aubio_pitch_mcomb:
- del_aubio_pvoc(p->pv);
- del_cvec(p->fftgrain);
- del_aubio_filter(p->filter);
- del_aubio_pitchmcomb(p->mcomb);
- break;
- case aubio_pitch_schmitt:
- del_fvec(p->buf);
- del_aubio_pitchschmitt(p->schmitt);
- break;
- case aubio_pitch_fcomb:
- del_fvec(p->buf);
- del_aubio_pitchfcomb(p->fcomb);
- break;
- case aubio_pitch_yinfft:
- del_fvec(p->buf);
- del_aubio_pitchyinfft(p->yinfft);
- break;
- default:
- break;
- }
- 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];
- }
- }
-}
-
-uint_t aubio_pitchdetection_set_unit (aubio_pitchdetection_t *p, char_t * pitch_unit) {
- aubio_pitchdetection_mode pitch_mode;
- if (strcmp (pitch_unit, "freq") == 0)
- pitch_mode = aubio_pitchm_freq;
- else if (strcmp (pitch_unit, "midi") == 0)
- pitch_mode = aubio_pitchm_midi;
- else if (strcmp (pitch_unit, "cent") == 0)
- pitch_mode = aubio_pitchm_cent;
- else if (strcmp (pitch_unit, "bin") == 0)
- pitch_mode = aubio_pitchm_bin;
- else if (strcmp (pitch_unit, "default") == 0)
- pitch_mode = aubio_pitchm_default;
- else {
- AUBIO_ERR ("unknown pitch detection unit %s, using default\n", pitch_unit);
- pitch_mode = aubio_pitchm_default;
- }
- p->mode = pitch_mode;
- switch(p->mode) {
- case aubio_pitchm_freq:
- p->freqconv = freqconvpass;
- break;
- case aubio_pitchm_midi:
- p->freqconv = freqconvmidi;
- break;
- case aubio_pitchm_cent:
- /* bug: not implemented */
- p->freqconv = freqconvmidi;
- break;
- case aubio_pitchm_bin:
- p->freqconv = freqconvbin;
- break;
- default:
- break;
- }
- return AUBIO_OK;
-}
-
-uint_t aubio_pitchdetection_set_tolerance(aubio_pitchdetection_t *p, smpl_t tol) {
- switch(p->type) {
- case aubio_pitch_yin:
- aubio_pitchyin_set_tolerance (p->yin, tol);
- break;
- case aubio_pitch_yinfft:
- aubio_pitchyinfft_set_tolerance (p->yinfft, tol);
- break;
- default:
- break;
- }
- return AUBIO_OK;
-}
-
-void aubio_pitchdetection_do (aubio_pitchdetection_t *p, fvec_t * ibuf, fvec_t *obuf) {
- uint_t i;
- p->callback(p, ibuf, obuf);
- for (i = 0; i < obuf->channels; i++) {
- p->freqconv(obuf->data[i][0],p->srate,p->bufsize);
- }
-}
-
-void aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * obuf) {
- uint_t i;
- aubio_filter_do(p->filter,ibuf);
- aubio_pvoc_do(p->pv,ibuf,p->fftgrain);
- aubio_pitchmcomb_do(p->mcomb,p->fftgrain, obuf);
- for (i = 0; i < obuf->channels; i++) {
- obuf->data[i][0] = aubio_bintofreq (obuf->data[i][0], p->srate, p->bufsize);
- }
-}
-
-void aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * obuf) {
- smpl_t pitch = 0.;
- uint_t i;
- aubio_pitchdetection_slideblock(p,ibuf);
- aubio_pitchyin_do(p->yin,p->buf, obuf);
- for (i = 0; i < obuf->channels; i++) {
- pitch = obuf->data[i][0];
- if (pitch>0) {
- pitch = p->srate/(pitch+0.);
- } else {
- pitch = 0.;
- }
- obuf->data[i][0] = pitch;
- }
-}
-
-
-void aubio_pitchdetection_yinfft(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * obuf){
- smpl_t pitch = 0.;
- uint_t i;
- aubio_pitchdetection_slideblock(p,ibuf);
- aubio_pitchyinfft_do(p->yinfft,p->buf,obuf);
- for (i = 0; i < obuf->channels; i++) {
- pitch = obuf->data[i][0];
- if (pitch>0) {
- pitch = p->srate/(pitch+0.);
- } else {
- pitch = 0.;
- }
- obuf->data[i][0] = pitch;
- }
-}
-
-void aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * out){
- uint_t i;
- aubio_pitchdetection_slideblock(p,ibuf);
- aubio_pitchfcomb_do(p->fcomb,p->buf, out);
- for (i = 0; i < out->channels; i++) {
- out->data[i][0] = aubio_bintofreq (out->data[i][0], p->srate, p->bufsize);
- }
-}
-
-void aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *out){
- smpl_t period, pitch = 0.;
- uint_t i;
- aubio_pitchdetection_slideblock(p,ibuf);
- aubio_pitchschmitt_do(p->schmitt,p->buf, out);
- for (i = 0; i < out->channels; i++) {
- period = out->data[i][0];
- if (period>0) {
- pitch = p->srate/period;
- } else {
- pitch = 0.;
- }
- out->data[i][0] = pitch;
- }
-}
--- a/src/pitch/pitchdetection.h
+++ /dev/null
@@ -1,89 +1,0 @@
-/*
- Copyright (C) 2003 Paul Brossier
-
- This program 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 2 of the License, or
- (at your option) any later version.
-
- This program 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 this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef PITCHAUTOTCORR_H
-#define PITCHAUTOTCORR_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/** \file
-
- Generic method for pitch detection
-
- This file creates the objects required for the computation of the selected
- pitch detection algorithm and output the results, in midi note or Hz.
-
-*/
-
-/** pitch detection object */
-typedef struct _aubio_pitchdetection_t aubio_pitchdetection_t;
-
-/** execute pitch detection on an input signal frame
-
- \param o pitch detection object as returned by new_aubio_pitchdetection()
- \param in input signal of size [hopsize x channels]
- \param out output pitch candidates of size [1 x channes]
-
-*/
-void aubio_pitchdetection_do (aubio_pitchdetection_t * o, fvec_t * in,
- fvec_t * out);
-
-/** change yin or yinfft tolerance threshold
-
- \param o pitch detection object as returned by new_aubio_pitchdetection()
- \param tol tolerance default is 0.15 for yin and 0.85 for yinfft
-
-*/
-uint_t aubio_pitchdetection_set_tolerance (aubio_pitchdetection_t * o,
- smpl_t tol);
-
-/** deletion of the pitch detection object
-
- \param o pitch detection object as returned by new_aubio_pitchdetection()
-
-*/
-void del_aubio_pitchdetection (aubio_pitchdetection_t * o);
-
-/** creation of the pitch detection object
-
- \param mode set pitch detection algorithm
- \param bufsize size of the input buffer to analyse
- \param hopsize step size between two consecutive analysis instant
- \param channels number of channels to analyse
- \param samplerate sampling rate of the signal
-
-*/
-aubio_pitchdetection_t *new_aubio_pitchdetection (char_t * mode,
- uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate);
-
-/** set the output unit of the pitch detection object
-
- \param o pitch detection object as returned by new_aubio_pitchdetection()
- \param mode set pitch units for output
-
-*/
-uint_t aubio_pitchdetection_set_unit (aubio_pitchdetection_t * o,
- char_t * mode);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*PITCHDETECTION_H*/
--- a/swig/aubio.i
+++ b/swig/aubio.i
@@ -170,12 +170,12 @@
void aubio_pvoc_rdo(aubio_pvoc_t *pv, cvec_t * fftgrain, fvec_t *out);
/* pitch detection */
-aubio_pitchdetection_t *new_aubio_pitchdetection (char *pitch_mode,
+aubio_pitch_t *new_aubio_pitch (char *pitch_mode,
uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate);
-void aubio_pitchdetection_do (aubio_pitchdetection_t * p, fvec_t * ibuf, fvec_t * obuf);
-uint_t aubio_pitchdetection_set_tolerance(aubio_pitchdetection_t *p, smpl_t thres);
-uint_t aubio_pitchdetection_set_unit(aubio_pitchdetection_t *p, char * pitch_unit);
-void del_aubio_pitchdetection(aubio_pitchdetection_t * p);
+void aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
+uint_t aubio_pitch_set_tolerance(aubio_pitch_t *p, smpl_t thres);
+uint_t aubio_pitch_set_unit(aubio_pitch_t *p, char * pitch_unit);
+void del_aubio_pitch(aubio_pitch_t * p);
/* pitch mcomb */
aubio_pitchmcomb_t * new_aubio_pitchmcomb(uint_t bufsize, uint_t hopsize, uint_t channels);
--- a/tests/python/src/pitch/pitchdetection.py
+++ b/tests/python/src/pitch/pitchdetection.py
@@ -6,7 +6,7 @@
channels = 1
samplerate = 44100.
-class pitchdetection_test_case(unittest.TestCase):
+class pitch_test_case(unittest.TestCase):
def setUp(self, type = aubio_pitch_yinfft, mode = aubio_pitchm_freq):
self.create(type=type)
@@ -14,27 +14,27 @@
def create(self, type = aubio_pitch_yinfft,
mode = aubio_pitchm_freq):
self.type = type
- self.o = new_aubio_pitchdetection(buf_size, hop_size,
+ self.o = new_aubio_pitch(buf_size, hop_size,
channels, int(samplerate), type, mode)
def tearDown(self):
- del_aubio_pitchdetection(self.o)
+ del_aubio_pitch(self.o)
- def test_pitchdetection(self):
- """ create and delete pitchdetection """
+ def test_pitch(self):
+ """ create and delete pitch """
pass
- def test_pitchdetection_run_zeroes(self):
- """ run pitchdetection on an empty buffer """
+ def test_pitch_run_zeroes(self):
+ """ run pitch on an empty buffer """
vec = new_fvec(buf_size, channels)
out = new_fvec(1, channels)
for i in range(100):
- aubio_pitchdetection_do(self.o,vec, out)
+ aubio_pitch_do(self.o,vec, out)
self.assertEqual(fvec_read_sample(out, 0, 0),0.)
del vec
- def test_pitchdetection_run_4_impulses(self):
- """ run pitchdetection on a train of 4 impulses """
+ def test_pitch_run_4_impulses(self):
+ """ run pitch on a train of 4 impulses """
vec = new_fvec(buf_size, channels)
out = new_fvec(1, channels)
fvec_write_sample(vec,-1.,0, 0)
@@ -43,12 +43,12 @@
fvec_write_sample(vec, 1.,0,3*buf_size/4)
frequency = samplerate/2*4/buf_size
for i in range(100):
- aubio_pitchdetection_do(self.o,vec, out)
+ aubio_pitch_do(self.o,vec, out)
self.assertEqual(fvec_read_sample(out, 0, 0),frequency)
del vec
- def test_pitchdetection_run_4_positive_impulses(self):
- """ run pitchdetection on a train of 4 positive impulses of arbitrary size """
+ def test_pitch_run_4_positive_impulses(self):
+ """ run pitch on a train of 4 positive impulses of arbitrary size """
vec = new_fvec(buf_size, channels)
out = new_fvec(1, channels)
frequency = samplerate/2*8/buf_size
@@ -57,12 +57,12 @@
fvec_write_sample(vec, 2.-.01*i,0, buf_size/4)
fvec_write_sample(vec, 2.-.01*i,0, buf_size/2)
fvec_write_sample(vec, 2.-.01*i,0,3*buf_size/4)
- aubio_pitchdetection_do(self.o,vec, out)
+ aubio_pitch_do(self.o,vec, out)
self.assertAlmostEqual(fvec_read_sample(out, 0, 0),frequency,1)
del vec
- def test_pitchdetection_run_4_negative_impulses(self):
- """ run pitchdetection on a train of 4 negative impulses of arbitrary size """
+ def test_pitch_run_4_negative_impulses(self):
+ """ run pitch on a train of 4 negative impulses of arbitrary size """
vec = new_fvec(buf_size, channels)
out = new_fvec(1, channels)
frequency = samplerate/2*8/buf_size
@@ -71,12 +71,12 @@
fvec_write_sample(vec,-.01*i,0, buf_size/4)
fvec_write_sample(vec,-.01*i,0, buf_size/2)
fvec_write_sample(vec,-.01*i,0,3*buf_size/4)
- aubio_pitchdetection_do(self.o,vec, out)
+ aubio_pitch_do(self.o,vec, out)
self.assertAlmostEqual(fvec_read_sample(out, 0, 0),frequency,1)
del vec
- def test_pitchdetection_run_8_impulses(self):
- """ run pitchdetection on a train of 8 impulses """
+ def test_pitch_run_8_impulses(self):
+ """ run pitch on a train of 8 impulses """
vec = new_fvec(buf_size, channels)
out = new_fvec(1, channels)
fvec_write_sample(vec, 1.,0, 0)
@@ -88,25 +88,25 @@
fvec_write_sample(vec, 1.,0,3*buf_size/4)
fvec_write_sample(vec,-1.,0,7*buf_size/8)
for i in range(100):
- aubio_pitchdetection_do(self.o,vec, out)
+ aubio_pitch_do(self.o,vec, out)
self.assertAlmostEqual(fvec_read_sample(out, 0, 0),
samplerate/2/buf_size*8, 1)
del vec
"""
-class pitchdetection_yin_test_case(pitchdetection_test_case):
+class pitch_yin_test_case(pitchdetection_test_case):
def setUp(self, type = aubio_pitch_yin):
self.create(type=type)
-class pitchdetection_fcomb_test_case(pitchdetection_test_case):
+class pitch_fcomb_test_case(pitchdetection_test_case):
def setUp(self, type = aubio_pitch_fcomb):
self.create(type=type)
-class pitchdetection_mcomb_test_case(pitchdetection_test_case):
+class pitch_mcomb_test_case(pitchdetection_test_case):
def setUp(self, type = aubio_pitch_mcomb):
self.create(type=type)
-class pitchdetection_schmitt_test_case(pitchdetection_test_case):
+class pitch_schmitt_test_case(pitchdetection_test_case):
def setUp(self, type = aubio_pitch_schmitt):
self.create(type=type)
"""
--- a/tests/src/Makefile.am
+++ b/tests/src/Makefile.am
@@ -26,7 +26,7 @@
test-pitchschmitt \
test-pitchfcomb \
test-pitchmcomb \
- test-pitchdetection \
+ test-pitch \
test-beattracking \
test-onset \
test-tempo \
--- a/tests/src/test-pitchdetection.c
+++ b/tests/src/test-pitchdetection.c
@@ -10,16 +10,16 @@
uint_t channels = 1; /* number of channel */
fvec_t *in = new_fvec (hop_s, channels); /* input buffer */
fvec_t *out = new_fvec (1, channels); /* input buffer */
- aubio_pitchdetection_t *o =
- new_aubio_pitchdetection ("default", win_s, hop_s, channels, samplerate);
+ aubio_pitch_t *o =
+ new_aubio_pitch ("default", win_s, hop_s, channels, samplerate);
uint_t i = 0;
while (i < 100) {
- aubio_pitchdetection_do (o, in, out);
+ aubio_pitch_do (o, in, out);
i++;
};
- del_aubio_pitchdetection (o);
+ del_aubio_pitch (o);
del_fvec (in);
aubio_cleanup ();