2 Copyright (C) 2013 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
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.
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.
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/>.
21 #include "aubio_priv.h"
24 #include "mathutils.h"
25 #include "spectral/fft.h"
26 #include "pitch/pitchspecacf.h"
28 /** pitch specacf structure */
29 struct _aubio_pitchspecacf_t
31 fvec_t *win; /**< temporal weighting window */
32 fvec_t *winput; /**< windowed spectrum */
33 aubio_fft_t *fft; /**< fft object to compute*/
34 fvec_t *fftout; /**< Fourier transform output */
35 fvec_t *sqrmag; /**< square magnitudes */
36 fvec_t *acf; /**< auto correlation function */
37 smpl_t tol; /**< tolerance */
38 smpl_t confidence; /**< confidence */
41 aubio_pitchspecacf_t *
42 new_aubio_pitchspecacf (uint_t bufsize)
44 aubio_pitchspecacf_t *p = AUBIO_NEW (aubio_pitchspecacf_t);
45 p->win = new_aubio_window ("hanningz", bufsize);
46 p->winput = new_fvec (bufsize);
47 p->fft = new_aubio_fft (bufsize);
48 p->fftout = new_fvec (bufsize);
49 p->sqrmag = new_fvec (bufsize);
50 p->acf = new_fvec (bufsize / 2 + 1);
57 aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, fvec_t * input, fvec_t * output)
60 fvec_t *fftout = p->fftout;
62 for (l = 0; l < input->length; l++) {
63 p->winput->data[l] = p->win->data[l] * input->data[l];
65 // get the real / imag parts of its fft
66 aubio_fft_do_complex (p->fft, p->winput, fftout);
67 for (l = 0; l < input->length / 2 + 1; l++) {
68 p->sqrmag->data[l] = SQR(fftout->data[l]);
70 // get the real / imag parts of the fft of the squared magnitude
71 aubio_fft_do_complex (p->fft, p->sqrmag, fftout);
72 // copy real part to acf
73 for (l = 0; l < fftout->length / 2 + 1; l++) {
74 p->acf->data[l] = fftout->data[l];
77 tau = fvec_min_elem (p->acf);
78 // get the interpolated minimum
79 output->data[0] = fvec_quadratic_peak_pos (p->acf, tau) * 2.;
83 del_aubio_pitchspecacf (aubio_pitchspecacf_t * p)
87 del_aubio_fft (p->fft);
94 aubio_pitchspecacf_get_confidence (aubio_pitchspecacf_t * o) {
95 // no confidence for now
100 aubio_pitchspecacf_set_tolerance (aubio_pitchspecacf_t * p, smpl_t tol)
107 aubio_pitchspecacf_get_tolerance (aubio_pitchspecacf_t * p)