source: src/pitch/pitch.c @ 4edba9d

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since 4edba9d was c268bf2, checked in by Paul Brossier <piem@piem.org>, 7 years ago

src/pitch/pitch.c: add yinfast

  • Property mode set to 100644
File size: 15.9 KB
RevLine 
[96fb8ad]1/*
[e6a78ea]2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
3
4  This file is part of aubio.
5
6  aubio is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10
11  aubio is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15
16  You should have received a copy of the GNU General Public License
17  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
18
19*/
[96fb8ad]20
21#include "aubio_priv.h"
[6c7d49b]22#include "fvec.h"
23#include "cvec.h"
[a4364b8]24#include "lvec.h"
[96fb8ad]25#include "mathutils.h"
[83963b3]26#include "musicutils.h"
27#include "spectral/phasevoc.h"
[a695854]28#include "temporal/filter.h"
[c159aeb]29#include "temporal/c_weighting.h"
[2d8cffa]30#include "pitch/pitchmcomb.h"
31#include "pitch/pitchyin.h"
32#include "pitch/pitchfcomb.h"
33#include "pitch/pitchschmitt.h"
34#include "pitch/pitchyinfft.h"
[c268bf2]35#include "pitch/pitchyinfast.h"
[95dc7f2]36#include "pitch/pitchspecacf.h"
[ca1abdd]37#include "pitch/pitch.h"
[96fb8ad]38
[8c3f717]39#define DEFAULT_PITCH_SILENCE -50.
40
[a64ef1d]41/** pitch detection algorithms */
[fddfa64]42typedef enum
43{
[a64ef1d]44  aubio_pitcht_yin,        /**< `yin`, YIN algorithm */
45  aubio_pitcht_mcomb,      /**< `mcomb`, Multi-comb filter */
46  aubio_pitcht_schmitt,    /**< `schmitt`, Schmitt trigger */
47  aubio_pitcht_fcomb,      /**< `fcomb`, Fast comb filter */
48  aubio_pitcht_yinfft,     /**< `yinfft`, Spectral YIN */
[c268bf2]49  aubio_pitcht_yinfast,    /**< `yinfast`, YIN fast */
[95dc7f2]50  aubio_pitcht_specacf,    /**< `specacf`, Spectral autocorrelation */
[a64ef1d]51  aubio_pitcht_default
52    = aubio_pitcht_yinfft, /**< `default` */
[ca1abdd]53} aubio_pitch_type;
[fe163ad]54
[a64ef1d]55/** pitch detection output modes */
[fddfa64]56typedef enum
57{
[fe163ad]58  aubio_pitchm_freq,   /**< Frequency (Hz) */
59  aubio_pitchm_midi,   /**< MIDI note (0.,127) */
60  aubio_pitchm_cent,   /**< Cent */
61  aubio_pitchm_bin,    /**< Frequency bin (0,bufsize) */
62  aubio_pitchm_default = aubio_pitchm_freq, /**< the one used when "default" is asked */
[ca1abdd]63} aubio_pitch_mode;
[fe163ad]64
[b130600]65/** callback to get pitch candidate, defined below */
[ce3ff2b]66typedef void (*aubio_pitch_detect_t) (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
[6d4ec49]67
[b130600]68/** callback to convert pitch from one unit to another, defined below */
69typedef smpl_t(*aubio_pitch_convert_t) (smpl_t value, uint_t samplerate, uint_t bufsize);
[5284e0d]70
[b130600]71/** callback to fetch the confidence of the algorithm */
72typedef smpl_t (*aubio_pitch_get_conf_t) (void * p);
[f44b111]73
[475da2f]74/** generic pitch detection structure */
[fddfa64]75struct _aubio_pitch_t
76{
[b130600]77  aubio_pitch_type type;          /**< pitch detection mode */
78  aubio_pitch_mode mode;          /**< pitch detection output mode */
79  uint_t samplerate;              /**< samplerate */
[475da2f]80  uint_t bufsize;                 /**< buffer size */
[b130600]81  void *p_object;                 /**< pointer to pitch object */
[fddfa64]82  aubio_filter_t *filter;         /**< filter */
[ce3ff2b]83  fvec_t *filtered;               /**< filtered input */
[fddfa64]84  aubio_pvoc_t *pv;               /**< phase vocoder for mcomb */
85  cvec_t *fftgrain;               /**< spectral frame for mcomb */
86  fvec_t *buf;                    /**< temporary buffer for yin */
[b130600]87  aubio_pitch_detect_t detect_cb; /**< callback to get the pitch candidates */
88  aubio_pitch_convert_t conv_cb;  /**< callback to convert it to the desired unit */
89  aubio_pitch_get_conf_t conf_cb; /**< pointer to the current confidence callback */
[8c3f717]90  smpl_t silence;                 /**< silence threshold */
[96fb8ad]91};
92
[b130600]93/* callback functions for pitch detection */
[ce3ff2b]94static void aubio_pitch_do_mcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
95static void aubio_pitch_do_yin (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
96static void aubio_pitch_do_schmitt (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
97static void aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
98static void aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
[c268bf2]99static void aubio_pitch_do_yinfast (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
[ce3ff2b]100static void aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
[3ec9d9c]101
[6388c37]102/* internal functions for frequency conversion */
103static smpl_t freqconvbin (smpl_t f, uint_t samplerate, uint_t bufsize);
104static smpl_t freqconvmidi (smpl_t f, uint_t samplerate, uint_t bufsize);
105static smpl_t freqconvpass (smpl_t f, uint_t samplerate, uint_t bufsize);
[b130600]106
107/* adapter to stack ibuf new samples at the end of buf, and trim `buf` to `bufsize` */
[ce3ff2b]108void aubio_pitch_slideblock (aubio_pitch_t * p, const fvec_t * ibuf);
[3ec9d9c]109
110
[ca1abdd]111aubio_pitch_t *
[ce3ff2b]112new_aubio_pitch (const char_t * pitch_mode,
[168337e]113    uint_t bufsize, uint_t hopsize, uint_t samplerate)
[96fb8ad]114{
[fddfa64]115  aubio_pitch_t *p = AUBIO_NEW (aubio_pitch_t);
[ca1abdd]116  aubio_pitch_type pitch_type;
[3f512b8]117  if (pitch_mode == NULL) {
118    AUBIO_ERR ("pitch: can not use ‘NULL‘ for pitch detection method\n");
119    goto beach;
120  }
[fe163ad]121  if (strcmp (pitch_mode, "mcomb") == 0)
[fddfa64]122    pitch_type = aubio_pitcht_mcomb;
[c268bf2]123  else if (strcmp (pitch_mode, "yinfast") == 0)
124    pitch_type = aubio_pitcht_yinfast;
[fe163ad]125  else if (strcmp (pitch_mode, "yinfft") == 0)
[97a5878b]126    pitch_type = aubio_pitcht_yinfft;
[fe163ad]127  else if (strcmp (pitch_mode, "yin") == 0)
[fddfa64]128    pitch_type = aubio_pitcht_yin;
[fe163ad]129  else if (strcmp (pitch_mode, "schmitt") == 0)
[fddfa64]130    pitch_type = aubio_pitcht_schmitt;
[fe163ad]131  else if (strcmp (pitch_mode, "fcomb") == 0)
[fddfa64]132    pitch_type = aubio_pitcht_fcomb;
[95dc7f2]133  else if (strcmp (pitch_mode, "specacf") == 0)
134    pitch_type = aubio_pitcht_specacf;
[fe163ad]135  else if (strcmp (pitch_mode, "default") == 0)
[fddfa64]136    pitch_type = aubio_pitcht_default;
[fe163ad]137  else {
[afa21cdc]138    AUBIO_ERR ("pitch: unknown pitch detection method ‘%s’\n", pitch_mode);
139    goto beach;
[fe163ad]140  }
[2abe563]141
142  // check parameters are valid
143  if ((sint_t)hopsize < 1) {
[d04875c]144    AUBIO_ERR("pitch: got hopsize %d, but can not be < 1\n", hopsize);
[2abe563]145    goto beach;
146  } else if ((sint_t)bufsize < 1) {
[d04875c]147    AUBIO_ERR("pitch: got buffer_size %d, but can not be < 1\n", bufsize);
[2abe563]148    goto beach;
149  } else if (bufsize < hopsize) {
[724922c]150    AUBIO_ERR("pitch: hop size (%d) is larger than win size (%d)\n", hopsize, bufsize);
[2abe563]151    goto beach;
152  } else if ((sint_t)samplerate < 1) {
[d04875c]153    AUBIO_ERR("pitch: samplerate (%d) can not be < 1\n", samplerate);
[2abe563]154    goto beach;
155  }
156
[b130600]157  p->samplerate = samplerate;
[fe163ad]158  p->type = pitch_type;
[ca1abdd]159  aubio_pitch_set_unit (p, "default");
[6d4ec49]160  p->bufsize = bufsize;
[8c3f717]161  p->silence = DEFAULT_PITCH_SILENCE;
[b130600]162  p->conf_cb = NULL;
[fddfa64]163  switch (p->type) {
[ca1abdd]164    case aubio_pitcht_yin:
[168337e]165      p->buf = new_fvec (bufsize);
[b130600]166      p->p_object = new_aubio_pitchyin (bufsize);
[4cb7a0a]167      if (!p->p_object) goto beach;
[b130600]168      p->detect_cb = aubio_pitch_do_yin;
169      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyin_get_confidence;
170      aubio_pitchyin_set_tolerance (p->p_object, 0.15);
[6d4ec49]171      break;
[ca1abdd]172    case aubio_pitcht_mcomb:
[ce3ff2b]173      p->filtered = new_fvec (hopsize);
[168337e]174      p->pv = new_aubio_pvoc (bufsize, hopsize);
[4cb7a0a]175      if (!p->pv) goto beach;
[168337e]176      p->fftgrain = new_cvec (bufsize);
[b130600]177      p->p_object = new_aubio_pitchmcomb (bufsize, hopsize);
[168337e]178      p->filter = new_aubio_filter_c_weighting (samplerate);
[b130600]179      p->detect_cb = aubio_pitch_do_mcomb;
[6d4ec49]180      break;
[ca1abdd]181    case aubio_pitcht_fcomb:
[168337e]182      p->buf = new_fvec (bufsize);
[b130600]183      p->p_object = new_aubio_pitchfcomb (bufsize, hopsize);
[4cb7a0a]184      if (!p->p_object) goto beach;
[b130600]185      p->detect_cb = aubio_pitch_do_fcomb;
[6d4ec49]186      break;
[ca1abdd]187    case aubio_pitcht_schmitt:
[168337e]188      p->buf = new_fvec (bufsize);
[b130600]189      p->p_object = new_aubio_pitchschmitt (bufsize);
190      p->detect_cb = aubio_pitch_do_schmitt;
[6d4ec49]191      break;
[ca1abdd]192    case aubio_pitcht_yinfft:
[168337e]193      p->buf = new_fvec (bufsize);
[9c9202f]194      p->p_object = new_aubio_pitchyinfft (samplerate, bufsize);
[4cb7a0a]195      if (!p->p_object) goto beach;
[b130600]196      p->detect_cb = aubio_pitch_do_yinfft;
197      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfft_get_confidence;
198      aubio_pitchyinfft_set_tolerance (p->p_object, 0.85);
[6d4ec49]199      break;
[c268bf2]200    case aubio_pitcht_yinfast:
201      p->buf = new_fvec (bufsize);
202      p->p_object = new_aubio_pitchyinfast (bufsize);
203      if (!p->p_object) goto beach;
204      p->detect_cb = aubio_pitch_do_yinfast;
205      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfast_get_confidence;
206      aubio_pitchyinfast_set_tolerance (p->p_object, 0.15);
207      break;
[95dc7f2]208    case aubio_pitcht_specacf:
209      p->buf = new_fvec (bufsize);
210      p->p_object = new_aubio_pitchspecacf (bufsize);
[4cb7a0a]211      if (!p->p_object) goto beach;
[95dc7f2]212      p->detect_cb = aubio_pitch_do_specacf;
213      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchspecacf_get_tolerance;
214      aubio_pitchspecacf_set_tolerance (p->p_object, 0.85);
215      break;
[6d4ec49]216    default:
217      break;
218  }
219  return p;
[2abe563]220
221beach:
[4cb7a0a]222  if (p->filtered) del_fvec(p->filtered);
223  if (p->buf) del_fvec(p->buf);
[2abe563]224  AUBIO_FREE(p);
225  return NULL;
[96fb8ad]226}
227
[fddfa64]228void
229del_aubio_pitch (aubio_pitch_t * p)
230{
231  switch (p->type) {
[ca1abdd]232    case aubio_pitcht_yin:
[fddfa64]233      del_fvec (p->buf);
[b130600]234      del_aubio_pitchyin (p->p_object);
[6d4ec49]235      break;
[ca1abdd]236    case aubio_pitcht_mcomb:
[ce3ff2b]237      del_fvec (p->filtered);
[fddfa64]238      del_aubio_pvoc (p->pv);
239      del_cvec (p->fftgrain);
240      del_aubio_filter (p->filter);
[b130600]241      del_aubio_pitchmcomb (p->p_object);
[6d4ec49]242      break;
[ca1abdd]243    case aubio_pitcht_schmitt:
[fddfa64]244      del_fvec (p->buf);
[b130600]245      del_aubio_pitchschmitt (p->p_object);
[6d4ec49]246      break;
[ca1abdd]247    case aubio_pitcht_fcomb:
[fddfa64]248      del_fvec (p->buf);
[b130600]249      del_aubio_pitchfcomb (p->p_object);
[6d4ec49]250      break;
[ca1abdd]251    case aubio_pitcht_yinfft:
[fddfa64]252      del_fvec (p->buf);
[b130600]253      del_aubio_pitchyinfft (p->p_object);
[6d4ec49]254      break;
[c268bf2]255    case aubio_pitcht_yinfast:
256      del_fvec (p->buf);
257      del_aubio_pitchyinfast (p->p_object);
258      break;
[95dc7f2]259    case aubio_pitcht_specacf:
260      del_fvec (p->buf);
261      del_aubio_pitchspecacf (p->p_object);
262      break;
[6d4ec49]263    default:
264      break;
265  }
[fddfa64]266  AUBIO_FREE (p);
[96fb8ad]267}
268
[fddfa64]269void
[ce3ff2b]270aubio_pitch_slideblock (aubio_pitch_t * p, const fvec_t * ibuf)
[fddfa64]271{
[6c8ef58]272  uint_t overlap_size = p->buf->length - ibuf->length;
[094a8be]273#if 1 //!HAVE_MEMCPY_HACKS
[6c8ef58]274  uint_t j;
[168337e]275  for (j = 0; j < overlap_size; j++) {
276    p->buf->data[j] = p->buf->data[j + ibuf->length];
[6d4ec49]277  }
[168337e]278  for (j = 0; j < ibuf->length; j++) {
279    p->buf->data[j + overlap_size] = ibuf->data[j];
[6d4ec49]280  }
[6c8ef58]281#else
282  smpl_t *data = p->buf->data;
283  smpl_t *newdata = ibuf->data;
284  memmove(data, data + ibuf->length, overlap_size);
285  memcpy(data + overlap_size, newdata, ibuf->length);
286#endif
[651b97e]287}
288
[fddfa64]289uint_t
[ce3ff2b]290aubio_pitch_set_unit (aubio_pitch_t * p, const char_t * pitch_unit)
[fddfa64]291{
[21e2e6db]292  uint_t err = AUBIO_OK;
[ca1abdd]293  aubio_pitch_mode pitch_mode;
[fe163ad]294  if (strcmp (pitch_unit, "freq") == 0)
[fddfa64]295    pitch_mode = aubio_pitchm_freq;
[53d1497]296  else if (strcmp (pitch_unit, "hertz") == 0)
297    pitch_mode = aubio_pitchm_freq;
[5a2a6c6]298  else if (strcmp (pitch_unit, "Hertz") == 0)
299    pitch_mode = aubio_pitchm_freq;
[53d1497]300  else if (strcmp (pitch_unit, "Hz") == 0)
301    pitch_mode = aubio_pitchm_freq;
302  else if (strcmp (pitch_unit, "f0") == 0)
303    pitch_mode = aubio_pitchm_freq;
[fe163ad]304  else if (strcmp (pitch_unit, "midi") == 0)
[fddfa64]305    pitch_mode = aubio_pitchm_midi;
[fe163ad]306  else if (strcmp (pitch_unit, "cent") == 0)
[fddfa64]307    pitch_mode = aubio_pitchm_cent;
[fe163ad]308  else if (strcmp (pitch_unit, "bin") == 0)
[fddfa64]309    pitch_mode = aubio_pitchm_bin;
[fe163ad]310  else if (strcmp (pitch_unit, "default") == 0)
[fddfa64]311    pitch_mode = aubio_pitchm_default;
[fe163ad]312  else {
[afa21cdc]313    AUBIO_WRN("pitch: unknown pitch detection unit ‘%s’, using default\n",
314        pitch_unit);
[fddfa64]315    pitch_mode = aubio_pitchm_default;
[21e2e6db]316    err = AUBIO_FAIL;
[fe163ad]317  }
318  p->mode = pitch_mode;
[fddfa64]319  switch (p->mode) {
[fe163ad]320    case aubio_pitchm_freq:
[b130600]321      p->conv_cb = freqconvpass;
[fe163ad]322      break;
323    case aubio_pitchm_midi:
[b130600]324      p->conv_cb = freqconvmidi;
[fe163ad]325      break;
326    case aubio_pitchm_cent:
327      /* bug: not implemented */
[b130600]328      p->conv_cb = freqconvmidi;
[fe163ad]329      break;
330    case aubio_pitchm_bin:
[b130600]331      p->conv_cb = freqconvbin;
[fe163ad]332      break;
333    default:
334      break;
335  }
[21e2e6db]336  return err;
[fe163ad]337}
338
[fddfa64]339uint_t
340aubio_pitch_set_tolerance (aubio_pitch_t * p, smpl_t tol)
341{
342  switch (p->type) {
[ca1abdd]343    case aubio_pitcht_yin:
[b130600]344      aubio_pitchyin_set_tolerance (p->p_object, tol);
[7a6cbbe]345      break;
[ca1abdd]346    case aubio_pitcht_yinfft:
[b130600]347      aubio_pitchyinfft_set_tolerance (p->p_object, tol);
[7a6cbbe]348      break;
[c268bf2]349    case aubio_pitcht_yinfast:
350      aubio_pitchyinfast_set_tolerance (p->p_object, tol);
351      break;
[7a6cbbe]352    default:
353      break;
354  }
[93177fa]355  return AUBIO_OK;
[f8a38c5]356}
357
[0cf2b44]358smpl_t
359aubio_pitch_get_tolerance (aubio_pitch_t * p)
360{
361  smpl_t tolerance = 1.;
362  switch (p->type) {
363    case aubio_pitcht_yin:
364      tolerance = aubio_pitchyin_get_tolerance (p->p_object);
365      break;
366    case aubio_pitcht_yinfft:
367      tolerance = aubio_pitchyinfft_get_tolerance (p->p_object);
368      break;
[c268bf2]369    case aubio_pitcht_yinfast:
370      tolerance = aubio_pitchyinfast_get_tolerance (p->p_object);
371      break;
[0cf2b44]372    default:
373      break;
374  }
375  return tolerance;
376}
377
[8c3f717]378uint_t
379aubio_pitch_set_silence (aubio_pitch_t * p, smpl_t silence)
380{
[973eb75]381  if (silence <= 0 && silence >= -200) {
[8c3f717]382    p->silence = silence;
383    return AUBIO_OK;
384  } else {
[afa21cdc]385    AUBIO_WRN("pitch: could not set silence to %.2f\n", silence);
[8c3f717]386    return AUBIO_FAIL;
387  }
388}
389
390smpl_t
391aubio_pitch_get_silence (aubio_pitch_t * p)
392{
393  return p->silence;
394}
395
[b130600]396
397/* do method, calling the detection callback, then the conversion callback */
[fddfa64]398void
[ce3ff2b]399aubio_pitch_do (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
[fddfa64]400{
[b130600]401  p->detect_cb (p, ibuf, obuf);
[8c3f717]402  if (aubio_silence_detection(ibuf, p->silence) == 1) {
403    obuf->data[0] = 0.;
404  }
[b130600]405  obuf->data[0] = p->conv_cb (obuf->data[0], p->samplerate, p->bufsize);
[c078336]406}
407
[b130600]408/* do method for each algorithm */
[fddfa64]409void
[ce3ff2b]410aubio_pitch_do_mcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
[fddfa64]411{
[ce3ff2b]412  aubio_filter_do_outplace (p->filter, ibuf, p->filtered);
[fddfa64]413  aubio_pvoc_do (p->pv, ibuf, p->fftgrain);
[b130600]414  aubio_pitchmcomb_do (p->p_object, p->fftgrain, obuf);
415  obuf->data[0] = aubio_bintofreq (obuf->data[0], p->samplerate, p->bufsize);
[c078336]416}
417
[fddfa64]418void
[ce3ff2b]419aubio_pitch_do_yin (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
[fddfa64]420{
[6d4ec49]421  smpl_t pitch = 0.;
[fddfa64]422  aubio_pitch_slideblock (p, ibuf);
[b130600]423  aubio_pitchyin_do (p->p_object, p->buf, obuf);
[168337e]424  pitch = obuf->data[0];
425  if (pitch > 0) {
[b130600]426    pitch = p->samplerate / (pitch + 0.);
[168337e]427  } else {
428    pitch = 0.;
[6d4ec49]429  }
[168337e]430  obuf->data[0] = pitch;
[c078336]431}
432
433
[fddfa64]434void
[ce3ff2b]435aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
[fddfa64]436{
[6d4ec49]437  smpl_t pitch = 0.;
[fddfa64]438  aubio_pitch_slideblock (p, ibuf);
[b130600]439  aubio_pitchyinfft_do (p->p_object, p->buf, obuf);
[168337e]440  pitch = obuf->data[0];
441  if (pitch > 0) {
[b130600]442    pitch = p->samplerate / (pitch + 0.);
[168337e]443  } else {
444    pitch = 0.;
[6d4ec49]445  }
[168337e]446  obuf->data[0] = pitch;
[650e39b]447}
448
[fddfa64]449void
[c268bf2]450aubio_pitch_do_yinfast (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
451{
452  smpl_t pitch = 0.;
453  aubio_pitch_slideblock (p, ibuf);
454  aubio_pitchyinfast_do (p->p_object, p->buf, obuf);
455  pitch = obuf->data[0];
456  if (pitch > 0) {
457    pitch = p->samplerate / (pitch + 0.);
458  } else {
459    pitch = 0.;
460  }
461  obuf->data[0] = pitch;
462}
463
464void
[ce3ff2b]465aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
[95dc7f2]466{
[c21acb9]467  smpl_t pitch = 0., period;
[95dc7f2]468  aubio_pitch_slideblock (p, ibuf);
469  aubio_pitchspecacf_do (p->p_object, p->buf, out);
470  //out->data[0] = aubio_bintofreq (out->data[0], p->samplerate, p->bufsize);
[c21acb9]471  period = out->data[0];
[95dc7f2]472  if (period > 0) {
473    pitch = p->samplerate / period;
474  } else {
475    pitch = 0.;
476  }
477  out->data[0] = pitch;
478}
479
480void
[ce3ff2b]481aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
[fddfa64]482{
483  aubio_pitch_slideblock (p, ibuf);
[b130600]484  aubio_pitchfcomb_do (p->p_object, p->buf, out);
485  out->data[0] = aubio_bintofreq (out->data[0], p->samplerate, p->bufsize);
[c078336]486}
487
[fddfa64]488void
[ce3ff2b]489aubio_pitch_do_schmitt (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
[fddfa64]490{
[7a6cbbe]491  smpl_t period, pitch = 0.;
[fddfa64]492  aubio_pitch_slideblock (p, ibuf);
[b130600]493  aubio_pitchschmitt_do (p->p_object, p->buf, out);
[168337e]494  period = out->data[0];
495  if (period > 0) {
[b130600]496    pitch = p->samplerate / period;
[168337e]497  } else {
498    pitch = 0.;
[7a6cbbe]499  }
[168337e]500  out->data[0] = pitch;
[96fb8ad]501}
[5284e0d]502
[b130600]503/* conversion callbacks */
504smpl_t
505freqconvbin(smpl_t f, uint_t samplerate, uint_t bufsize)
506{
507  return aubio_freqtobin(f, samplerate, bufsize);
508}
509
510smpl_t
511freqconvmidi (smpl_t f, uint_t samplerate UNUSED, uint_t bufsize UNUSED)
512{
513  return aubio_freqtomidi (f);
514}
515
516smpl_t
517freqconvpass (smpl_t f, uint_t samplerate UNUSED, uint_t bufsize UNUSED)
518{
519  return f;
520}
521
[5284e0d]522/* confidence callbacks */
523smpl_t
524aubio_pitch_get_confidence (aubio_pitch_t * p)
525{
[b130600]526  if (p->conf_cb) {
527    return p->conf_cb(p->p_object);
[5284e0d]528  }
529  return 0.;
530}
Note: See TracBrowser for help on using the repository browser.