[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" |
---|
[95dc7f2] | 35 | #include "pitch/pitchspecacf.h" |
---|
[ca1abdd] | 36 | #include "pitch/pitch.h" |
---|
[96fb8ad] | 37 | |
---|
[8c3f717] | 38 | #define DEFAULT_PITCH_SILENCE -50. |
---|
| 39 | |
---|
[a64ef1d] | 40 | /** pitch detection algorithms */ |
---|
[fddfa64] | 41 | typedef enum |
---|
| 42 | { |
---|
[a64ef1d] | 43 | aubio_pitcht_yin, /**< `yin`, YIN algorithm */ |
---|
| 44 | aubio_pitcht_mcomb, /**< `mcomb`, Multi-comb filter */ |
---|
| 45 | aubio_pitcht_schmitt, /**< `schmitt`, Schmitt trigger */ |
---|
| 46 | aubio_pitcht_fcomb, /**< `fcomb`, Fast comb filter */ |
---|
| 47 | aubio_pitcht_yinfft, /**< `yinfft`, Spectral YIN */ |
---|
[95dc7f2] | 48 | aubio_pitcht_specacf, /**< `specacf`, Spectral autocorrelation */ |
---|
[a64ef1d] | 49 | aubio_pitcht_default |
---|
| 50 | = aubio_pitcht_yinfft, /**< `default` */ |
---|
[ca1abdd] | 51 | } aubio_pitch_type; |
---|
[fe163ad] | 52 | |
---|
[a64ef1d] | 53 | /** pitch detection output modes */ |
---|
[fddfa64] | 54 | typedef enum |
---|
| 55 | { |
---|
[fe163ad] | 56 | aubio_pitchm_freq, /**< Frequency (Hz) */ |
---|
| 57 | aubio_pitchm_midi, /**< MIDI note (0.,127) */ |
---|
| 58 | aubio_pitchm_cent, /**< Cent */ |
---|
| 59 | aubio_pitchm_bin, /**< Frequency bin (0,bufsize) */ |
---|
| 60 | aubio_pitchm_default = aubio_pitchm_freq, /**< the one used when "default" is asked */ |
---|
[ca1abdd] | 61 | } aubio_pitch_mode; |
---|
[fe163ad] | 62 | |
---|
[b130600] | 63 | /** callback to get pitch candidate, defined below */ |
---|
| 64 | typedef void (*aubio_pitch_detect_t) (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); |
---|
[6d4ec49] | 65 | |
---|
[b130600] | 66 | /** callback to convert pitch from one unit to another, defined below */ |
---|
| 67 | typedef smpl_t(*aubio_pitch_convert_t) (smpl_t value, uint_t samplerate, uint_t bufsize); |
---|
[5284e0d] | 68 | |
---|
[b130600] | 69 | /** callback to fetch the confidence of the algorithm */ |
---|
| 70 | typedef smpl_t (*aubio_pitch_get_conf_t) (void * p); |
---|
[f44b111] | 71 | |
---|
[475da2f] | 72 | /** generic pitch detection structure */ |
---|
[fddfa64] | 73 | struct _aubio_pitch_t |
---|
| 74 | { |
---|
[b130600] | 75 | aubio_pitch_type type; /**< pitch detection mode */ |
---|
| 76 | aubio_pitch_mode mode; /**< pitch detection output mode */ |
---|
| 77 | uint_t samplerate; /**< samplerate */ |
---|
[475da2f] | 78 | uint_t bufsize; /**< buffer size */ |
---|
[b130600] | 79 | void *p_object; /**< pointer to pitch object */ |
---|
[fddfa64] | 80 | aubio_filter_t *filter; /**< filter */ |
---|
| 81 | aubio_pvoc_t *pv; /**< phase vocoder for mcomb */ |
---|
| 82 | cvec_t *fftgrain; /**< spectral frame for mcomb */ |
---|
| 83 | fvec_t *buf; /**< temporary buffer for yin */ |
---|
[b130600] | 84 | aubio_pitch_detect_t detect_cb; /**< callback to get the pitch candidates */ |
---|
| 85 | aubio_pitch_convert_t conv_cb; /**< callback to convert it to the desired unit */ |
---|
| 86 | aubio_pitch_get_conf_t conf_cb; /**< pointer to the current confidence callback */ |
---|
[8c3f717] | 87 | smpl_t silence; /**< silence threshold */ |
---|
[96fb8ad] | 88 | }; |
---|
| 89 | |
---|
[b130600] | 90 | /* callback functions for pitch detection */ |
---|
| 91 | static void aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); |
---|
| 92 | static void aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); |
---|
| 93 | static void aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); |
---|
| 94 | static void aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); |
---|
| 95 | static void aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); |
---|
[95dc7f2] | 96 | static void aubio_pitch_do_specacf (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); |
---|
[3ec9d9c] | 97 | |
---|
[b130600] | 98 | /* conversion functions for frequency conversions */ |
---|
| 99 | smpl_t freqconvbin (smpl_t f, uint_t samplerate, uint_t bufsize); |
---|
| 100 | smpl_t freqconvmidi (smpl_t f, uint_t samplerate, uint_t bufsize); |
---|
| 101 | smpl_t freqconvpass (smpl_t f, uint_t samplerate, uint_t bufsize); |
---|
| 102 | |
---|
| 103 | /* adapter to stack ibuf new samples at the end of buf, and trim `buf` to `bufsize` */ |
---|
| 104 | void aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf); |
---|
[3ec9d9c] | 105 | |
---|
| 106 | |
---|
[ca1abdd] | 107 | aubio_pitch_t * |
---|
| 108 | new_aubio_pitch (char_t * pitch_mode, |
---|
[168337e] | 109 | uint_t bufsize, uint_t hopsize, uint_t samplerate) |
---|
[96fb8ad] | 110 | { |
---|
[fddfa64] | 111 | aubio_pitch_t *p = AUBIO_NEW (aubio_pitch_t); |
---|
[ca1abdd] | 112 | aubio_pitch_type pitch_type; |
---|
[fe163ad] | 113 | if (strcmp (pitch_mode, "mcomb") == 0) |
---|
[fddfa64] | 114 | pitch_type = aubio_pitcht_mcomb; |
---|
[fe163ad] | 115 | else if (strcmp (pitch_mode, "yinfft") == 0) |
---|
[97a5878b] | 116 | pitch_type = aubio_pitcht_yinfft; |
---|
[fe163ad] | 117 | else if (strcmp (pitch_mode, "yin") == 0) |
---|
[fddfa64] | 118 | pitch_type = aubio_pitcht_yin; |
---|
[fe163ad] | 119 | else if (strcmp (pitch_mode, "schmitt") == 0) |
---|
[fddfa64] | 120 | pitch_type = aubio_pitcht_schmitt; |
---|
[fe163ad] | 121 | else if (strcmp (pitch_mode, "fcomb") == 0) |
---|
[fddfa64] | 122 | pitch_type = aubio_pitcht_fcomb; |
---|
[95dc7f2] | 123 | else if (strcmp (pitch_mode, "specacf") == 0) |
---|
| 124 | pitch_type = aubio_pitcht_specacf; |
---|
[fe163ad] | 125 | else if (strcmp (pitch_mode, "default") == 0) |
---|
[fddfa64] | 126 | pitch_type = aubio_pitcht_default; |
---|
[fe163ad] | 127 | else { |
---|
[fddfa64] | 128 | AUBIO_ERR ("unknown pitch detection method %s, using default.\n", |
---|
| 129 | pitch_mode); |
---|
| 130 | pitch_type = aubio_pitcht_default; |
---|
[fe163ad] | 131 | } |
---|
[2abe563] | 132 | |
---|
| 133 | // check parameters are valid |
---|
| 134 | if ((sint_t)hopsize < 1) { |
---|
| 135 | AUBIO_ERR("onset: got hopsize %d, but can not be < 1\n", hopsize); |
---|
| 136 | goto beach; |
---|
| 137 | } else if ((sint_t)bufsize < 1) { |
---|
| 138 | AUBIO_ERR("onset: got buffer_size %d, but can not be < 1\n", bufsize); |
---|
| 139 | goto beach; |
---|
| 140 | } else if (bufsize < hopsize) { |
---|
| 141 | AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", bufsize, hopsize); |
---|
| 142 | goto beach; |
---|
| 143 | } else if ((sint_t)samplerate < 1) { |
---|
| 144 | AUBIO_ERR("onset: samplerate (%d) can not be < 1\n", samplerate); |
---|
| 145 | goto beach; |
---|
| 146 | } |
---|
| 147 | |
---|
[b130600] | 148 | p->samplerate = samplerate; |
---|
[fe163ad] | 149 | p->type = pitch_type; |
---|
[ca1abdd] | 150 | aubio_pitch_set_unit (p, "default"); |
---|
[6d4ec49] | 151 | p->bufsize = bufsize; |
---|
[8c3f717] | 152 | p->silence = DEFAULT_PITCH_SILENCE; |
---|
[b130600] | 153 | p->conf_cb = NULL; |
---|
[fddfa64] | 154 | switch (p->type) { |
---|
[ca1abdd] | 155 | case aubio_pitcht_yin: |
---|
[168337e] | 156 | p->buf = new_fvec (bufsize); |
---|
[b130600] | 157 | p->p_object = new_aubio_pitchyin (bufsize); |
---|
| 158 | p->detect_cb = aubio_pitch_do_yin; |
---|
| 159 | p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyin_get_confidence; |
---|
| 160 | aubio_pitchyin_set_tolerance (p->p_object, 0.15); |
---|
[6d4ec49] | 161 | break; |
---|
[ca1abdd] | 162 | case aubio_pitcht_mcomb: |
---|
[168337e] | 163 | p->pv = new_aubio_pvoc (bufsize, hopsize); |
---|
| 164 | p->fftgrain = new_cvec (bufsize); |
---|
[b130600] | 165 | p->p_object = new_aubio_pitchmcomb (bufsize, hopsize); |
---|
[168337e] | 166 | p->filter = new_aubio_filter_c_weighting (samplerate); |
---|
[b130600] | 167 | p->detect_cb = aubio_pitch_do_mcomb; |
---|
[6d4ec49] | 168 | break; |
---|
[ca1abdd] | 169 | case aubio_pitcht_fcomb: |
---|
[168337e] | 170 | p->buf = new_fvec (bufsize); |
---|
[b130600] | 171 | p->p_object = new_aubio_pitchfcomb (bufsize, hopsize); |
---|
| 172 | p->detect_cb = aubio_pitch_do_fcomb; |
---|
[6d4ec49] | 173 | break; |
---|
[ca1abdd] | 174 | case aubio_pitcht_schmitt: |
---|
[168337e] | 175 | p->buf = new_fvec (bufsize); |
---|
[b130600] | 176 | p->p_object = new_aubio_pitchschmitt (bufsize); |
---|
| 177 | p->detect_cb = aubio_pitch_do_schmitt; |
---|
[6d4ec49] | 178 | break; |
---|
[ca1abdd] | 179 | case aubio_pitcht_yinfft: |
---|
[168337e] | 180 | p->buf = new_fvec (bufsize); |
---|
[9c9202f] | 181 | p->p_object = new_aubio_pitchyinfft (samplerate, bufsize); |
---|
[b130600] | 182 | p->detect_cb = aubio_pitch_do_yinfft; |
---|
| 183 | p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfft_get_confidence; |
---|
| 184 | aubio_pitchyinfft_set_tolerance (p->p_object, 0.85); |
---|
[6d4ec49] | 185 | break; |
---|
[95dc7f2] | 186 | case aubio_pitcht_specacf: |
---|
| 187 | p->buf = new_fvec (bufsize); |
---|
| 188 | p->p_object = new_aubio_pitchspecacf (bufsize); |
---|
| 189 | p->detect_cb = aubio_pitch_do_specacf; |
---|
| 190 | p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchspecacf_get_tolerance; |
---|
| 191 | aubio_pitchspecacf_set_tolerance (p->p_object, 0.85); |
---|
| 192 | break; |
---|
[6d4ec49] | 193 | default: |
---|
| 194 | break; |
---|
| 195 | } |
---|
| 196 | return p; |
---|
[2abe563] | 197 | |
---|
| 198 | beach: |
---|
| 199 | AUBIO_FREE(p); |
---|
| 200 | return NULL; |
---|
[96fb8ad] | 201 | } |
---|
| 202 | |
---|
[fddfa64] | 203 | void |
---|
| 204 | del_aubio_pitch (aubio_pitch_t * p) |
---|
| 205 | { |
---|
| 206 | switch (p->type) { |
---|
[ca1abdd] | 207 | case aubio_pitcht_yin: |
---|
[fddfa64] | 208 | del_fvec (p->buf); |
---|
[b130600] | 209 | del_aubio_pitchyin (p->p_object); |
---|
[6d4ec49] | 210 | break; |
---|
[ca1abdd] | 211 | case aubio_pitcht_mcomb: |
---|
[fddfa64] | 212 | del_aubio_pvoc (p->pv); |
---|
| 213 | del_cvec (p->fftgrain); |
---|
| 214 | del_aubio_filter (p->filter); |
---|
[b130600] | 215 | del_aubio_pitchmcomb (p->p_object); |
---|
[6d4ec49] | 216 | break; |
---|
[ca1abdd] | 217 | case aubio_pitcht_schmitt: |
---|
[fddfa64] | 218 | del_fvec (p->buf); |
---|
[b130600] | 219 | del_aubio_pitchschmitt (p->p_object); |
---|
[6d4ec49] | 220 | break; |
---|
[ca1abdd] | 221 | case aubio_pitcht_fcomb: |
---|
[fddfa64] | 222 | del_fvec (p->buf); |
---|
[b130600] | 223 | del_aubio_pitchfcomb (p->p_object); |
---|
[6d4ec49] | 224 | break; |
---|
[ca1abdd] | 225 | case aubio_pitcht_yinfft: |
---|
[fddfa64] | 226 | del_fvec (p->buf); |
---|
[b130600] | 227 | del_aubio_pitchyinfft (p->p_object); |
---|
[6d4ec49] | 228 | break; |
---|
[95dc7f2] | 229 | case aubio_pitcht_specacf: |
---|
| 230 | del_fvec (p->buf); |
---|
| 231 | del_aubio_pitchspecacf (p->p_object); |
---|
| 232 | break; |
---|
[6d4ec49] | 233 | default: |
---|
| 234 | break; |
---|
| 235 | } |
---|
[fddfa64] | 236 | AUBIO_FREE (p); |
---|
[96fb8ad] | 237 | } |
---|
| 238 | |
---|
[fddfa64] | 239 | void |
---|
| 240 | aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf) |
---|
| 241 | { |
---|
[6c8ef58] | 242 | uint_t overlap_size = p->buf->length - ibuf->length; |
---|
[094a8be] | 243 | #if 1 //!HAVE_MEMCPY_HACKS |
---|
[6c8ef58] | 244 | uint_t j; |
---|
[168337e] | 245 | for (j = 0; j < overlap_size; j++) { |
---|
| 246 | p->buf->data[j] = p->buf->data[j + ibuf->length]; |
---|
[6d4ec49] | 247 | } |
---|
[168337e] | 248 | for (j = 0; j < ibuf->length; j++) { |
---|
| 249 | p->buf->data[j + overlap_size] = ibuf->data[j]; |
---|
[6d4ec49] | 250 | } |
---|
[6c8ef58] | 251 | #else |
---|
| 252 | smpl_t *data = p->buf->data; |
---|
| 253 | smpl_t *newdata = ibuf->data; |
---|
| 254 | memmove(data, data + ibuf->length, overlap_size); |
---|
| 255 | memcpy(data + overlap_size, newdata, ibuf->length); |
---|
| 256 | #endif |
---|
[651b97e] | 257 | } |
---|
| 258 | |
---|
[fddfa64] | 259 | uint_t |
---|
| 260 | aubio_pitch_set_unit (aubio_pitch_t * p, char_t * pitch_unit) |
---|
| 261 | { |
---|
[21e2e6db] | 262 | uint_t err = AUBIO_OK; |
---|
[ca1abdd] | 263 | aubio_pitch_mode pitch_mode; |
---|
[fe163ad] | 264 | if (strcmp (pitch_unit, "freq") == 0) |
---|
[fddfa64] | 265 | pitch_mode = aubio_pitchm_freq; |
---|
[53d1497] | 266 | else if (strcmp (pitch_unit, "hertz") == 0) |
---|
| 267 | pitch_mode = aubio_pitchm_freq; |
---|
[5a2a6c6] | 268 | else if (strcmp (pitch_unit, "Hertz") == 0) |
---|
| 269 | pitch_mode = aubio_pitchm_freq; |
---|
[53d1497] | 270 | else if (strcmp (pitch_unit, "Hz") == 0) |
---|
| 271 | pitch_mode = aubio_pitchm_freq; |
---|
| 272 | else if (strcmp (pitch_unit, "f0") == 0) |
---|
| 273 | pitch_mode = aubio_pitchm_freq; |
---|
[fe163ad] | 274 | else if (strcmp (pitch_unit, "midi") == 0) |
---|
[fddfa64] | 275 | pitch_mode = aubio_pitchm_midi; |
---|
[fe163ad] | 276 | else if (strcmp (pitch_unit, "cent") == 0) |
---|
[fddfa64] | 277 | pitch_mode = aubio_pitchm_cent; |
---|
[fe163ad] | 278 | else if (strcmp (pitch_unit, "bin") == 0) |
---|
[fddfa64] | 279 | pitch_mode = aubio_pitchm_bin; |
---|
[fe163ad] | 280 | else if (strcmp (pitch_unit, "default") == 0) |
---|
[fddfa64] | 281 | pitch_mode = aubio_pitchm_default; |
---|
[fe163ad] | 282 | else { |
---|
[fddfa64] | 283 | AUBIO_ERR ("unknown pitch detection unit %s, using default\n", pitch_unit); |
---|
| 284 | pitch_mode = aubio_pitchm_default; |
---|
[21e2e6db] | 285 | err = AUBIO_FAIL; |
---|
[fe163ad] | 286 | } |
---|
| 287 | p->mode = pitch_mode; |
---|
[fddfa64] | 288 | switch (p->mode) { |
---|
[fe163ad] | 289 | case aubio_pitchm_freq: |
---|
[b130600] | 290 | p->conv_cb = freqconvpass; |
---|
[fe163ad] | 291 | break; |
---|
| 292 | case aubio_pitchm_midi: |
---|
[b130600] | 293 | p->conv_cb = freqconvmidi; |
---|
[fe163ad] | 294 | break; |
---|
| 295 | case aubio_pitchm_cent: |
---|
| 296 | /* bug: not implemented */ |
---|
[b130600] | 297 | p->conv_cb = freqconvmidi; |
---|
[fe163ad] | 298 | break; |
---|
| 299 | case aubio_pitchm_bin: |
---|
[b130600] | 300 | p->conv_cb = freqconvbin; |
---|
[fe163ad] | 301 | break; |
---|
| 302 | default: |
---|
| 303 | break; |
---|
| 304 | } |
---|
[21e2e6db] | 305 | return err; |
---|
[fe163ad] | 306 | } |
---|
| 307 | |
---|
[fddfa64] | 308 | uint_t |
---|
| 309 | aubio_pitch_set_tolerance (aubio_pitch_t * p, smpl_t tol) |
---|
| 310 | { |
---|
| 311 | switch (p->type) { |
---|
[ca1abdd] | 312 | case aubio_pitcht_yin: |
---|
[b130600] | 313 | aubio_pitchyin_set_tolerance (p->p_object, tol); |
---|
[7a6cbbe] | 314 | break; |
---|
[ca1abdd] | 315 | case aubio_pitcht_yinfft: |
---|
[b130600] | 316 | aubio_pitchyinfft_set_tolerance (p->p_object, tol); |
---|
[7a6cbbe] | 317 | break; |
---|
| 318 | default: |
---|
| 319 | break; |
---|
| 320 | } |
---|
[93177fa] | 321 | return AUBIO_OK; |
---|
[f8a38c5] | 322 | } |
---|
| 323 | |
---|
[8c3f717] | 324 | uint_t |
---|
| 325 | aubio_pitch_set_silence (aubio_pitch_t * p, smpl_t silence) |
---|
| 326 | { |
---|
[973eb75] | 327 | if (silence <= 0 && silence >= -200) { |
---|
[8c3f717] | 328 | p->silence = silence; |
---|
| 329 | return AUBIO_OK; |
---|
| 330 | } else { |
---|
[973eb75] | 331 | AUBIO_ERR("pitch: could not set silence to %.2f", silence); |
---|
[8c3f717] | 332 | return AUBIO_FAIL; |
---|
| 333 | } |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | smpl_t |
---|
| 337 | aubio_pitch_get_silence (aubio_pitch_t * p) |
---|
| 338 | { |
---|
| 339 | return p->silence; |
---|
| 340 | } |
---|
| 341 | |
---|
[b130600] | 342 | |
---|
| 343 | /* do method, calling the detection callback, then the conversion callback */ |
---|
[fddfa64] | 344 | void |
---|
| 345 | aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf) |
---|
| 346 | { |
---|
[b130600] | 347 | p->detect_cb (p, ibuf, obuf); |
---|
[8c3f717] | 348 | if (aubio_silence_detection(ibuf, p->silence) == 1) { |
---|
| 349 | obuf->data[0] = 0.; |
---|
| 350 | } |
---|
[b130600] | 351 | obuf->data[0] = p->conv_cb (obuf->data[0], p->samplerate, p->bufsize); |
---|
[c078336] | 352 | } |
---|
| 353 | |
---|
[b130600] | 354 | /* do method for each algorithm */ |
---|
[fddfa64] | 355 | void |
---|
| 356 | aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf) |
---|
| 357 | { |
---|
| 358 | aubio_filter_do (p->filter, ibuf); |
---|
| 359 | aubio_pvoc_do (p->pv, ibuf, p->fftgrain); |
---|
[b130600] | 360 | aubio_pitchmcomb_do (p->p_object, p->fftgrain, obuf); |
---|
| 361 | obuf->data[0] = aubio_bintofreq (obuf->data[0], p->samplerate, p->bufsize); |
---|
[c078336] | 362 | } |
---|
| 363 | |
---|
[fddfa64] | 364 | void |
---|
| 365 | aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf) |
---|
| 366 | { |
---|
[6d4ec49] | 367 | smpl_t pitch = 0.; |
---|
[fddfa64] | 368 | aubio_pitch_slideblock (p, ibuf); |
---|
[b130600] | 369 | aubio_pitchyin_do (p->p_object, p->buf, obuf); |
---|
[168337e] | 370 | pitch = obuf->data[0]; |
---|
| 371 | if (pitch > 0) { |
---|
[b130600] | 372 | pitch = p->samplerate / (pitch + 0.); |
---|
[168337e] | 373 | } else { |
---|
| 374 | pitch = 0.; |
---|
[6d4ec49] | 375 | } |
---|
[168337e] | 376 | obuf->data[0] = pitch; |
---|
[c078336] | 377 | } |
---|
| 378 | |
---|
| 379 | |
---|
[fddfa64] | 380 | void |
---|
| 381 | aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf) |
---|
| 382 | { |
---|
[6d4ec49] | 383 | smpl_t pitch = 0.; |
---|
[fddfa64] | 384 | aubio_pitch_slideblock (p, ibuf); |
---|
[b130600] | 385 | aubio_pitchyinfft_do (p->p_object, p->buf, obuf); |
---|
[168337e] | 386 | pitch = obuf->data[0]; |
---|
| 387 | if (pitch > 0) { |
---|
[b130600] | 388 | pitch = p->samplerate / (pitch + 0.); |
---|
[168337e] | 389 | } else { |
---|
| 390 | pitch = 0.; |
---|
[6d4ec49] | 391 | } |
---|
[168337e] | 392 | obuf->data[0] = pitch; |
---|
[650e39b] | 393 | } |
---|
| 394 | |
---|
[fddfa64] | 395 | void |
---|
[95dc7f2] | 396 | aubio_pitch_do_specacf (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out) |
---|
| 397 | { |
---|
[c21acb9] | 398 | smpl_t pitch = 0., period; |
---|
[95dc7f2] | 399 | aubio_pitch_slideblock (p, ibuf); |
---|
| 400 | aubio_pitchspecacf_do (p->p_object, p->buf, out); |
---|
| 401 | //out->data[0] = aubio_bintofreq (out->data[0], p->samplerate, p->bufsize); |
---|
[c21acb9] | 402 | period = out->data[0]; |
---|
[95dc7f2] | 403 | if (period > 0) { |
---|
| 404 | pitch = p->samplerate / period; |
---|
| 405 | } else { |
---|
| 406 | pitch = 0.; |
---|
| 407 | } |
---|
| 408 | out->data[0] = pitch; |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | void |
---|
[fddfa64] | 412 | aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out) |
---|
| 413 | { |
---|
| 414 | aubio_pitch_slideblock (p, ibuf); |
---|
[b130600] | 415 | aubio_pitchfcomb_do (p->p_object, p->buf, out); |
---|
| 416 | out->data[0] = aubio_bintofreq (out->data[0], p->samplerate, p->bufsize); |
---|
[c078336] | 417 | } |
---|
| 418 | |
---|
[fddfa64] | 419 | void |
---|
| 420 | aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out) |
---|
| 421 | { |
---|
[7a6cbbe] | 422 | smpl_t period, pitch = 0.; |
---|
[fddfa64] | 423 | aubio_pitch_slideblock (p, ibuf); |
---|
[b130600] | 424 | aubio_pitchschmitt_do (p->p_object, p->buf, out); |
---|
[168337e] | 425 | period = out->data[0]; |
---|
| 426 | if (period > 0) { |
---|
[b130600] | 427 | pitch = p->samplerate / period; |
---|
[168337e] | 428 | } else { |
---|
| 429 | pitch = 0.; |
---|
[7a6cbbe] | 430 | } |
---|
[168337e] | 431 | out->data[0] = pitch; |
---|
[96fb8ad] | 432 | } |
---|
[5284e0d] | 433 | |
---|
[b130600] | 434 | /* conversion callbacks */ |
---|
| 435 | smpl_t |
---|
| 436 | freqconvbin(smpl_t f, uint_t samplerate, uint_t bufsize) |
---|
| 437 | { |
---|
| 438 | return aubio_freqtobin(f, samplerate, bufsize); |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | smpl_t |
---|
| 442 | freqconvmidi (smpl_t f, uint_t samplerate UNUSED, uint_t bufsize UNUSED) |
---|
| 443 | { |
---|
| 444 | return aubio_freqtomidi (f); |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | smpl_t |
---|
| 448 | freqconvpass (smpl_t f, uint_t samplerate UNUSED, uint_t bufsize UNUSED) |
---|
| 449 | { |
---|
| 450 | return f; |
---|
| 451 | } |
---|
| 452 | |
---|
[5284e0d] | 453 | /* confidence callbacks */ |
---|
| 454 | smpl_t |
---|
| 455 | aubio_pitch_get_confidence (aubio_pitch_t * p) |
---|
| 456 | { |
---|
[b130600] | 457 | if (p->conf_cb) { |
---|
| 458 | return p->conf_cb(p->p_object); |
---|
[5284e0d] | 459 | } |
---|
| 460 | return 0.; |
---|
| 461 | } |
---|