Unified · Split
| @@ -12,7 +12,7 @@ · 11 unmodified lines | |||
| 12 | 12 | ||
| 13 | char aubiopitch_version[] = "aubiopitch~ version 0.1"; | 13 | char aubiopitch_version[] = "aubiopitch~ version 0.1"; |
| 14 | 14 | ||
| 15 | aubio_pitchdetection_type type_pitch = aubio_pitch_mcomb; | 15 | aubio_pitchdetection_type type_pitch = aubio_pitch_yinfft; |
| 16 | aubio_pitchdetection_mode mode_pitch = aubio_pitchm_freq; | 16 | aubio_pitchdetection_mode mode_pitch = aubio_pitchm_freq; |
| 17 | 17 | ||
| 18 | static t_class *aubiopitch_tilde_class; | 18 | static t_class *aubiopitch_tilde_class; |
| @@ -80,6 +80,7 @@ static void *aubiopitch_tilde_new (void) · 61 unmodified lines | |||
| 80 | //FIXME: get the real samplerate | 80 | //FIXME: get the real samplerate |
| 81 | x->o = new_aubio_pitchdetection(x->bufsize*4, | 81 | x->o = new_aubio_pitchdetection(x->bufsize*4, |
| 82 | x->hopsize, 1, 44100., type_pitch, mode_pitch); | 82 | x->hopsize, 1, 44100., type_pitch, mode_pitch); |
| 83 | aubio_pitchdetection_set_yinthresh(x->o, 0.7); | ||
| 83 | x->vec = (fvec_t *)new_fvec(x->hopsize,1); | 84 | x->vec = (fvec_t *)new_fvec(x->hopsize,1); |
| 84 | 85 | ||
| 85 | //floatinlet_new (&x->x_obj, &x->threshold); | 86 | //floatinlet_new (&x->x_obj, &x->threshold); |
| @@ -7,13 +7,19 @@ class taskpitch(task): · 6 unmodified lines | |||
| 7 | def __init__(self,input,params=None): | 7 | def __init__(self,input,params=None): |
| 8 | task.__init__(self,input,params=params) | 8 | task.__init__(self,input,params=params) |
| 9 | self.shortlist = [0. for i in range(self.params.pitchsmooth)] | 9 | self.shortlist = [0. for i in range(self.params.pitchsmooth)] |
| 10 | if self.params.pitchmode == 'yinfft': | ||
| 11 | yinthresh = self.params.yinfftthresh | ||
| 12 | elif self.params.pitchmode == 'yin': | ||
| 13 | yinthresh = self.params.yinthresh | ||
| 14 | else: | ||
| 15 | yinthresh = 0. | ||
| 10 | self.pitchdet = pitchdetection(mode=get_pitch_mode(self.params.pitchmode), | 16 | self.pitchdet = pitchdetection(mode=get_pitch_mode(self.params.pitchmode), |
| 11 | bufsize=self.params.bufsize, | 17 | bufsize=self.params.bufsize, |
| 12 | hopsize=self.params.hopsize, | 18 | hopsize=self.params.hopsize, |
| 13 | channels=self.channels, | 19 | channels=self.channels, |
| 14 | samplerate=self.srate, | 20 | samplerate=self.srate, |
| 15 | omode=self.params.omode, | 21 | omode=self.params.omode, |
| 16 | yinthresh=self.params.yinthresh) | 22 | yinthresh=yinthresh) |
| 17 | 23 | ||
| 18 | def __call__(self): | 24 | def __call__(self): |
| 19 | from aubio.median import short_find | 25 | from aubio.median import short_find |
| @@ -67,7 +73,7 @@ class taskpitch(task): · 47 unmodified lines | |||
| 67 | time,pitch =[],[] | 73 | time,pitch =[],[] |
| 68 | while(tasksil.readsize==tasksil.params.hopsize): | 74 | while(tasksil.readsize==tasksil.params.hopsize): |
| 69 | tasksil() | 75 | tasksil() |
| 70 | time.append(tasksil.params.step*tasksil.frameread) | 76 | time.append(tasksil.params.step*(tasksil.frameread)) |
| 71 | if not tasksil.issilence: | 77 | if not tasksil.issilence: |
| 72 | pitch.append(self.truth) | 78 | pitch.append(self.truth) |
| 73 | else: | 79 | else: |
| @@ -155,7 +161,7 @@ class taskpitch(task): · 81 unmodified lines | |||
| 155 | title=self.params.pitchmode)) | 161 | title=self.params.pitchmode)) |
| 156 | 162 | ||
| 157 | 163 | ||
| 158 | def plotplot(self,wplot,oplots,outplot=None,multiplot = 1, midi = 1): | 164 | def plotplot(self,wplot,oplots,outplot=None,multiplot = 0, midi = 1): |
| 159 | from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot | 165 | from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot |
| 160 | import re | 166 | import re |
| 161 | import Gnuplot | 167 | import Gnuplot |
| @@ -197,7 +203,7 @@ class taskpitch(task): · 35 unmodified lines | |||
| 197 | g('set yrange [100:%f]' % self.params.pitchmax) | 203 | g('set yrange [100:%f]' % self.params.pitchmax) |
| 198 | else: | 204 | else: |
| 199 | g.ylabel('pitch (midi)') | 205 | g.ylabel('pitch (midi)') |
| 200 | g('set yrange [%f:%f]' % (40, aubio_freqtomidi(self.params.pitchmax))) | 206 | g('set yrange [%f:%f]' % (aubio_freqtomidi(self.params.pitchmin), aubio_freqtomidi(self.params.pitchmax))) |
| 201 | g('set key right top') | 207 | g('set key right top') |
| 202 | g('set noclip one') | 208 | g('set noclip one') |
| 203 | g('set format x ""') | 209 | g('set format x ""') |
| @@ -33,6 +33,8 @@ def get_pitch_mode(nvalue): · 32 unmodified lines | |||
| 33 | return aubio_pitch_fcomb | 33 | return aubio_pitch_fcomb |
| 34 | elif nvalue == 'schmitt': | 34 | elif nvalue == 'schmitt': |
| 35 | return aubio_pitch_schmitt | 35 | return aubio_pitch_schmitt |
| 36 | elif nvalue == 'yinfft': | ||
| 37 | return aubio_pitch_yinfft | ||
| 36 | else: | 38 | else: |
| 37 | import sys | 39 | import sys |
| 38 | print "error: unknown pitch detection function selected" | 40 | print "error: unknown pitch detection function selected" |
| @@ -89,7 +89,7 @@ params.samplerate = float(sndfile(filename).samplerate()) · 88 unmodified lines | |||
| 89 | params.hopsize = int(options.hopsize) | 89 | params.hopsize = int(options.hopsize) |
| 90 | params.bufsize = int(options.bufsize) | 90 | params.bufsize = int(options.bufsize) |
| 91 | params.step = params.samplerate/float(params.hopsize) | 91 | params.step = params.samplerate/float(params.hopsize) |
| 92 | params.threshold = float(options.threshold) | 92 | params.yinthresh = float(options.threshold) |
| 93 | params.silence = float(options.silence) | 93 | params.silence = float(options.silence) |
| 94 | params.verbose = options.verbose | 94 | params.verbose = options.verbose |
| 95 | #mintol = float(options.mintol)*step | 95 | #mintol = float(options.mintol)*step |
| @@ -100,7 +100,6 @@ else: delay = 2./params.step · 4 unmodified lines | |||
| 100 | if options.note: | 100 | if options.note: |
| 101 | exit("not implemented yet") | 101 | exit("not implemented yet") |
| 102 | 102 | ||
| 103 | |||
| 104 | wplot,oplots = [],[] | 103 | wplot,oplots = [],[] |
| 105 | modes = options.mode.split(',') | 104 | modes = options.mode.split(',') |
| 106 | for i in range(len(modes)): | 105 | for i in range(len(modes)): |
| @@ -17,6 +17,7 @@ pkginclude_HEADERS = aubio.h \ · 16 unmodified lines | |||
| 17 | pitchyin.h \ | 17 | pitchyin.h \ |
| 18 | pitchschmitt.h \ | 18 | pitchschmitt.h \ |
| 19 | pitchfcomb.h \ | 19 | pitchfcomb.h \ |
| 20 | pitchyinfft.h \ | ||
| 20 | beattracking.h \ | 21 | beattracking.h \ |
| 21 | filter.h | 22 | filter.h |
| 22 | nodist_pkginclude_HEADERS = config.h | 23 | nodist_pkginclude_HEADERS = config.h |
| @@ -56,6 +57,8 @@ libaubio_la_SOURCES = aubio.h \ · 33 unmodified lines | |||
| 56 | pitchschmitt.h \ | 57 | pitchschmitt.h \ |
| 57 | pitchfcomb.c \ | 58 | pitchfcomb.c \ |
| 58 | pitchfcomb.h \ | 59 | pitchfcomb.h \ |
| 60 | pitchyinfft.c \ | ||
| 61 | pitchyinfft.h \ | ||
| 59 | beattracking.c \ | 62 | beattracking.c \ |
| 60 | beattracking.h \ | 63 | beattracking.h \ |
| 61 | filter.c \ | 64 | filter.c \ |
| @@ -25,6 +25,7 @@ · 24 unmodified lines | |||
| 25 | #include "pitchyin.h" | 25 | #include "pitchyin.h" |
| 26 | #include "pitchfcomb.h" | 26 | #include "pitchfcomb.h" |
| 27 | #include "pitchschmitt.h" | 27 | #include "pitchschmitt.h" |
| 28 | #include "pitchyinfft.h" | ||
| 28 | #include "pitchdetection.h" | 29 | #include "pitchdetection.h" |
| 29 | 30 | ||
| 30 | typedef smpl_t (*aubio_pitchdetection_func_t)(aubio_pitchdetection_t *p, | 31 | typedef smpl_t (*aubio_pitchdetection_func_t)(aubio_pitchdetection_t *p, |
| @@ -43,6 +44,7 @@ struct _aubio_pitchdetection_t { · 12 unmodified lines | |||
| 43 | aubio_pitchmcomb_t * mcomb; | 44 | aubio_pitchmcomb_t * mcomb; |
| 44 | aubio_pitchfcomb_t * fcomb; | 45 | aubio_pitchfcomb_t * fcomb; |
| 45 | aubio_pitchschmitt_t * schmitt; | 46 | aubio_pitchschmitt_t * schmitt; |
| 47 | aubio_pitchyinfft_t * yinfft; | ||
| 46 | aubio_filter_t * filter; | 48 | aubio_filter_t * filter; |
| 47 | /* for yin */ | 49 | /* for yin */ |
| 48 | fvec_t * buf; | 50 | fvec_t * buf; |
| @@ -91,7 +93,7 @@ aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize, · 42 unmodified lines | |||
| 91 | case aubio_pitch_mcomb: | 93 | case aubio_pitch_mcomb: |
| 92 | p->pv = new_aubio_pvoc(bufsize, hopsize, channels); | 94 | p->pv = new_aubio_pvoc(bufsize, hopsize, channels); |
| 93 | p->fftgrain = new_cvec(bufsize, channels); | 95 | p->fftgrain = new_cvec(bufsize, channels); |
| 94 | p->mcomb = new_aubio_pitchmcomb(bufsize,channels,samplerate); | 96 | p->mcomb = new_aubio_pitchmcomb(bufsize,hopsize,channels,samplerate); |
| 95 | p->filter = new_aubio_cdsgn_filter(samplerate); | 97 | p->filter = new_aubio_cdsgn_filter(samplerate); |
| 96 | p->callback = aubio_pitchdetection_mcomb; | 98 | p->callback = aubio_pitchdetection_mcomb; |
| 97 | break; | 99 | break; |
| @@ -105,6 +107,12 @@ aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize, · 7 unmodified lines | |||
| 105 | p->schmitt = new_aubio_pitchschmitt(bufsize,samplerate); | 107 | p->schmitt = new_aubio_pitchschmitt(bufsize,samplerate); |
| 106 | p->callback = aubio_pitchdetection_schmitt; | 108 | p->callback = aubio_pitchdetection_schmitt; |
| 107 | break; | 109 | break; |
| 110 | case aubio_pitch_yinfft: | ||
| 111 | p->buf = new_fvec(bufsize,channels); | ||
| 112 | p->yinfft = new_aubio_pitchyinfft(bufsize); | ||
| 113 | p->callback = aubio_pitchdetection_yinfft; | ||
| 114 | p->yinthres = 0.2; | ||
| 115 | break; | ||
| 108 | default: | 116 | default: |
| 109 | break; | 117 | break; |
| 110 | } | 118 | } |
| @@ -147,6 +155,10 @@ void del_aubio_pitchdetection(aubio_pitchdetection_t * p) { · 36 unmodified lines | |||
| 147 | del_fvec(p->buf); | 155 | del_fvec(p->buf); |
| 148 | del_aubio_pitchfcomb(p->fcomb); | 156 | del_aubio_pitchfcomb(p->fcomb); |
| 149 | break; | 157 | break; |
| 158 | case aubio_pitch_yinfft: | ||
| 159 | del_fvec(p->buf); | ||
| 160 | del_aubio_pitchyinfft(p->yinfft); | ||
| 161 | break; | ||
| 150 | default: | 162 | default: |
| 151 | break; | 163 | break; |
| 152 | } | 164 | } |
| @@ -205,6 +217,18 @@ smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf) { · 52 unmodified lines | |||
| 205 | } | 217 | } |
| 206 | 218 | ||
| 207 | 219 | ||
| 220 | smpl_t aubio_pitchdetection_yinfft(aubio_pitchdetection_t *p, fvec_t *ibuf){ | ||
| 221 | smpl_t pitch = 0.; | ||
| 222 | aubio_pitchdetection_slideblock(p,ibuf); | ||
| 223 | pitch = aubio_pitchyinfft_detect(p->yinfft,p->buf,p->yinthres); | ||
| 224 | if (pitch>0) { | ||
| 225 | pitch = p->srate/(pitch+0.); | ||
| 226 | } else { | ||
| 227 | pitch = 0.; | ||
| 228 | } | ||
| 229 | return pitch; | ||
| 230 | } | ||
| 231 | |||
| 208 | smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf){ | 232 | smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf){ |
| 209 | aubio_pitchdetection_slideblock(p,ibuf); | 233 | aubio_pitchdetection_slideblock(p,ibuf); |
| 210 | return aubio_pitchfcomb_detect(p->fcomb,p->buf); | 234 | return aubio_pitchfcomb_detect(p->fcomb,p->buf); |
| @@ -27,7 +27,8 @@ typedef enum { · 26 unmodified lines | |||
| 27 | aubio_pitch_yin, | 27 | aubio_pitch_yin, |
| 28 | aubio_pitch_mcomb, | 28 | aubio_pitch_mcomb, |
| 29 | aubio_pitch_schmitt, | 29 | aubio_pitch_schmitt, |
| 30 | aubio_pitch_fcomb | 30 | aubio_pitch_fcomb, |
| 31 | aubio_pitch_yinfft | ||
| 31 | } aubio_pitchdetection_type; | 32 | } aubio_pitchdetection_type; |
| 32 | 33 | ||
| 33 | typedef enum { | 34 | typedef enum { |
| @@ -44,6 +45,7 @@ smpl_t aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t * ibuf); · 10 unmodified lines | |||
| 44 | smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf); | 45 | smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf); |
| 45 | smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf); | 46 | smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf); |
| 46 | smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf); | 47 | smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf); |
| 48 | smpl_t aubio_pitchdetection_yinfft(aubio_pitchdetection_t *p, fvec_t *ibuf); | ||
| 47 | 49 | ||
| 48 | void aubio_pitchdetection_set_yinthresh(aubio_pitchdetection_t *p, smpl_t thres); | 50 | void aubio_pitchdetection_set_yinthresh(aubio_pitchdetection_t *p, smpl_t thres); |
| 49 | void del_aubio_pitchdetection(aubio_pitchdetection_t * p); | 51 | void del_aubio_pitchdetection(aubio_pitchdetection_t * p); |
| @@ -0,0 +1,163 @@ | |||
| 1 | /* | ||
| 2 | Copyright (C) 2003 Paul Brossier | ||
| 3 | |||
| 4 | This program is free software; you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation; either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program; if not, write to the Free Software | ||
| 16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 17 | */ | ||
| 18 | |||
| 19 | /* This algorithm was developped by A. de Cheveigne and H. Kawahara and | ||
| 20 | * published in: | ||
| 21 | * | ||
| 22 | * de Cheveigné, A., Kawahara, H. (2002) "YIN, a fundamental frequency | ||
| 23 | * estimator for speech and music", J. Acoust. Soc. Am. 111, 1917-1930. | ||
| 24 | * | ||
| 25 | * see http://recherche.ircam.fr/equipes/pcm/pub/people/cheveign.html | ||
| 26 | * | ||
| 27 | * This implementation is using an FFT to compute the square difference | ||
| 28 | * function, which allows spectral weighting | ||
| 29 | * | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include "aubio_priv.h" | ||
| 33 | #include "sample.h" | ||
| 34 | #include "mathutils.h" | ||
| 35 | #include "fft.h" | ||
| 36 | #include "pitchyinfft.h" | ||
| 37 | |||
| 38 | struct _aubio_pitchyinfft_t { | ||
| 39 | uint_t bufsize; | ||
| 40 | uint_t rate; | ||
| 41 | fvec_t * win; | ||
| 42 | fvec_t * winput; | ||
| 43 | cvec_t * res; | ||
| 44 | fvec_t * sqrmag; | ||
| 45 | fvec_t * weight; | ||
| 46 | cvec_t * fftout; | ||
| 47 | aubio_mfft_t * fft; | ||
| 48 | fvec_t * yinfft; | ||
| 49 | }; | ||
| 50 | |||
| 51 | static const smpl_t freqs[] = {0., 20., 25., 31.5, 40., 50., 63., 80., 100., | ||
| 52 | 125., 160., 200., 250., 315., 400., 500., 630., 800., 1000., 1250., | ||
| 53 | 1600., 2000., 2500., 3150., 4000., 5000., 6300., 8000., 9000., 10000., | ||
| 54 | 12500., 15000., 20000., 25100}; | ||
| 55 | |||
| 56 | static const smpl_t weight[] = {-75.8, -70.1, -60.8, -52.1, -44.2, -37.5, | ||
| 57 | -31.3, -25.6, -20.9, -16.5, -12.6, -9.6, -7.0, -4.7, -3.0, -1.8, -0.8, | ||
| 58 | -0.2, -0.0, 0.5, 1.6, 3.2, 5.4, 7.8, 8.1, 5.3, -2.4, -11.1, -12.8, | ||
| 59 | -12.2, -7.4, -17.8, -17.8, -17.8}; | ||
| 60 | |||
| 61 | aubio_pitchyinfft_t * new_aubio_pitchyinfft (uint_t bufsize) | ||
| 62 | { | ||
| 63 | aubio_pitchyinfft_t * p = AUBIO_NEW(aubio_pitchyinfft_t); | ||
| 64 | p->bufsize = bufsize; | ||
| 65 | p->winput = new_fvec(bufsize,1); | ||
| 66 | p->fft = new_aubio_mfft(bufsize, 1); | ||
| 67 | p->fftout = new_cvec(bufsize,1); | ||
| 68 | p->sqrmag = new_fvec(bufsize,1); | ||
| 69 | p->res = new_cvec(bufsize,1); | ||
| 70 | p->yinfft = new_fvec(bufsize/2+1,1); | ||
| 71 | p->win = new_fvec(bufsize,1); | ||
| 72 | aubio_window(p->win->data[0], bufsize, aubio_win_hanningz); | ||
| 73 | p->weight = new_fvec(bufsize/2+1,1); | ||
| 74 | { | ||
| 75 | uint_t i = 0, j = 1; | ||
| 76 | smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0; | ||
| 77 | for (i=0; i<p->weight->length; i++) { | ||
| 78 | freq = (smpl_t)i/(smpl_t)bufsize*(smpl_t)44100.; | ||
| 79 | while (freq > freqs[j]) { | ||
| 80 | j +=1; | ||
| 81 | } | ||
| 82 | a0 = weight[j-1]; | ||
| 83 | f0 = freqs[j-1]; | ||
| 84 | a1 = weight[j]; | ||
| 85 | f1 = freqs[j]; | ||
| 86 | if (f0 == f1) { // just in case | ||
| 87 | p->weight->data[0][i] = a0; | ||
| 88 | } else if (f0 == 0) { // y = ax+b | ||
| 89 | p->weight->data[0][i] = (a1-a0)/f1*freq + a0; | ||
| 90 | } else { | ||
| 91 | p->weight->data[0][i] = (a1-a0)/(f1-f0)*freq + | ||
| 92 | (a0 - (a1 - a0)/(f1/f0 - 1.)); | ||
| 93 | } | ||
| 94 | while (freq > freqs[j]) { | ||
| 95 | j +=1; | ||
| 96 | } | ||
| 97 | //AUBIO_DBG("%f\n",p->weight->data[0][i]); | ||
| 98 | p->weight->data[0][i] = DB2LIN(p->weight->data[0][i]); | ||
| 99 | //p->weight->data[0][i] = SQRT(DB2LIN(p->weight->data[0][i])); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | return p; | ||
| 103 | } | ||
| 104 | |||
| 105 | smpl_t aubio_pitchyinfft_detect(aubio_pitchyinfft_t * p, fvec_t * input, smpl_t tol) { | ||
| 106 | uint_t tau, l = 0; | ||
| 107 | uint_t halfperiod; | ||
| 108 | smpl_t tmp = 0, sum = 0; | ||
| 109 | cvec_t * res = (cvec_t *)p->res; | ||
| 110 | fvec_t * yin = (fvec_t *)p->yinfft; | ||
| 111 | for (l=0; l < input->length; l++){ | ||
| 112 | p->winput->data[0][l] = p->win->data[0][l] * input->data[0][l]; | ||
| 113 | } | ||
| 114 | aubio_mfft_do(p->fft,p->winput,p->fftout); | ||
| 115 | for (l=0; l < p->fftout->length; l++){ | ||
| 116 | p->sqrmag->data[0][l] = SQR(p->fftout->norm[0][l]); | ||
| 117 | p->sqrmag->data[0][(p->fftout->length-1)*2-l] = | ||
| 118 | SQR(p->fftout->norm[0][l]); | ||
| 119 | p->sqrmag->data[0][l] *= p->weight->data[0][l]; | ||
| 120 | p->sqrmag->data[0][(p->fftout->length-1)*2-l] *= | ||
| 121 | p->weight->data[0][l]; | ||
| 122 | } | ||
| 123 | for (l=0; l < p->sqrmag->length/2+1; l++) { | ||
| 124 | sum += p->sqrmag->data[0][l]; | ||
| 125 | } | ||
| 126 | sum *= 2.; | ||
| 127 | aubio_mfft_do(p->fft,p->sqrmag,res); | ||
| 128 | yin->data[0][0] = 1.; | ||
| 129 | for (tau=1; tau < yin->length; tau++) { | ||
| 130 | yin->data[0][tau] = sum - | ||
| 131 | res->norm[0][tau+1]*COS(res->phas[0][tau+1]); | ||
| 132 | tmp += yin->data[0][tau]; | ||
| 133 | yin->data[0][tau] *= tau/tmp; | ||
| 134 | } | ||
| 135 | tau = vec_min_elem(yin); | ||
| 136 | if (yin->data[0][tau] < tol) { | ||
| 137 | /* no interpolation */ | ||
| 138 | //return tau+2; | ||
| 139 | /* 3 point quadratic interpolation */ | ||
| 140 | //return vec_quadint_min(yin,tau,1); | ||
| 141 | /* additional check nlikely octave doubling in higher frequencies */ | ||
| 142 | if (tau>35) { | ||
| 143 | return vec_quadint_min(yin,tau,1)+1; | ||
| 144 | } else { | ||
| 145 | /* should compare the minimum value of each interpolated peaks */ | ||
| 146 | halfperiod = FLOOR(tau/2+.5); | ||
| 147 | if (yin->data[0][halfperiod] < tol) | ||
| 148 | return vec_quadint_min(yin,halfperiod,1)+1; | ||
| 149 | else | ||
| 150 | return vec_quadint_min(yin,tau,1)+1; | ||
| 151 | } | ||
| 152 | } else | ||
| 153 | return 0; | ||
| 154 | } | ||
| 155 | |||
| 156 | void del_aubio_pitchyinfft(aubio_pitchyinfft_t *p){ | ||
| 157 | del_fvec(p->win); | ||
| 158 | del_aubio_mfft(p->fft); | ||
| 159 | del_fvec(p->yinfft); | ||
| 160 | del_fvec(p->sqrmag); | ||
| 161 | del_cvec(p->res); | ||
| 162 | del_cvec(p->fftout); | ||
| 163 | } | ||
| @@ -0,0 +1,45 @@ | |||
| 1 | /* | ||
| 2 | Copyright (C) 2003 Paul Brossier | ||
| 3 | |||
| 4 | This program is free software; you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation; either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program; if not, write to the Free Software | ||
| 16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 17 | */ | ||
| 18 | |||
| 19 | /* This algorithm was developped by A. de Cheveigne and H. Kawahara and | ||
| 20 | * published in: | ||
| 21 | * | ||
| 22 | * de Cheveigné, A., Kawahara, H. (2002) "YIN, a fundamental frequency | ||
| 23 | * estimator for speech and music", J. Acoust. Soc. Am. 111, 1917-1930. | ||
| 24 | * | ||
| 25 | * see http://recherche.ircam.fr/equipes/pcm/pub/people/cheveign.html | ||
| 26 | */ | ||
| 27 | |||
| 28 | #ifndef PITCHYINFFT_H | ||
| 29 | #define PITCHYINFFT_H | ||
| 30 | |||
| 31 | #ifdef __cplusplus | ||
| 32 | extern "C" { | ||
| 33 | #endif | ||
| 34 | |||
| 35 | typedef struct _aubio_pitchyinfft_t aubio_pitchyinfft_t; | ||
| 36 | |||
| 37 | smpl_t aubio_pitchyinfft_detect (aubio_pitchyinfft_t *p, fvec_t * input, smpl_t tol); | ||
| 38 | aubio_pitchyinfft_t * new_aubio_pitchyinfft (uint_t bufsize); | ||
| 39 | void del_aubio_pitchyinfft (aubio_pitchyinfft_t *p); | ||
| 40 | |||
| 41 | #ifdef __cplusplus | ||
| 42 | } | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #endif /*PITCHYINFFT_H*/ | ||
| @@ -190,7 +190,8 @@ typedef enum { · 189 unmodified lines | |||
| 190 | aubio_pitch_yin, | 190 | aubio_pitch_yin, |
| 191 | aubio_pitch_mcomb, | 191 | aubio_pitch_mcomb, |
| 192 | aubio_pitch_schmitt, | 192 | aubio_pitch_schmitt, |
| 193 | aubio_pitch_fcomb | 193 | aubio_pitch_fcomb, |
| 194 | aubio_pitch_yinfft | ||
| 194 | } aubio_pitchdetection_type; | 195 | } aubio_pitchdetection_type; |
| 195 | 196 | ||
| 196 | typedef enum { | 197 | typedef enum { |
| @@ -217,7 +218,7 @@ aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize, · 20 unmodified lines | |||
| 217 | 218 | ||
| 218 | 219 | ||
| 219 | /* pitch mcomb */ | 220 | /* pitch mcomb */ |
| 220 | aubio_pitchmcomb_t * new_aubio_pitchmcomb(uint_t size, uint_t channels, uint_t samplerate); | 221 | aubio_pitchmcomb_t * new_aubio_pitchmcomb(uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate); |
| 221 | smpl_t aubio_pitchmcomb_detect(aubio_pitchmcomb_t * p, cvec_t * fftgrain); | 222 | smpl_t aubio_pitchmcomb_detect(aubio_pitchmcomb_t * p, cvec_t * fftgrain); |
| 222 | uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands); | 223 | uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands); |
| 223 | void del_aubio_pitchmcomb (aubio_pitchmcomb_t *p); | 224 | void del_aubio_pitchmcomb (aubio_pitchmcomb_t *p); |
| @@ -226,7 +227,7 @@ void del_aubio_pitchmcomb (aubio_pitchmcomb_t *p); · 2 unmodified lines | |||
| 226 | void aubio_pitchyin_diff(fvec_t *input, fvec_t *yin); | 227 | void aubio_pitchyin_diff(fvec_t *input, fvec_t *yin); |
| 227 | void aubio_pitchyin_getcum(fvec_t *yin); | 228 | void aubio_pitchyin_getcum(fvec_t *yin); |
| 228 | uint_t aubio_pitchyin_getpitch(fvec_t *yin); | 229 | uint_t aubio_pitchyin_getpitch(fvec_t *yin); |
| 229 | uint_t aubio_pitchyin_getpitchfast(fvec_t * input, fvec_t *yin, smpl_t tol); | 230 | smpl_t aubio_pitchyin_getpitchfast(fvec_t * input, fvec_t *yin, smpl_t tol); |
| 230 | 231 | ||
| 231 | /* pitch schmitt */ | 232 | /* pitch schmitt */ |
| 232 | aubio_pitchschmitt_t * new_aubio_pitchschmitt (uint_t size, uint_t samplerate); | 233 | aubio_pitchschmitt_t * new_aubio_pitchschmitt (uint_t size, uint_t samplerate); |