source: src/pitch/pitchspecacf.c @ 95dc7f2

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 95dc7f2 was 95dc7f2, checked in by Paul Brossier <piem@piem.org>, 11 years ago

src/pitch/: add first draft for specacf

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2  Copyright (C) 2013 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*/
20
21#include "aubio_priv.h"
22#include "fvec.h"
23#include "cvec.h"
24#include "mathutils.h"
25#include "spectral/fft.h"
26#include "pitch/pitchspecacf.h"
27
28/** pitch specacf structure */
29struct _aubio_pitchspecacf_t
30{
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 */
39};
40
41aubio_pitchspecacf_t *
42new_aubio_pitchspecacf (uint_t bufsize)
43{
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);
51  p->tol = 1.;
52  return p;
53}
54
55void
56aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, fvec_t * input, fvec_t * output)
57{
58  uint_t l;
59  fvec_t *fftout = p->fftout;
60  // window the input
61  for (l = 0; l < input->length; l++) {
62    p->winput->data[l] = p->win->data[l] * input->data[l];
63  }
64  // get the real / imag parts of its fft
65  aubio_fft_do_complex (p->fft, p->winput, fftout);
66  for (l = 0; l < input->length / 2 + 1; l++) {
67    p->sqrmag->data[l] = SQR(fftout->data[l]);
68  }
69  // get the real / imag parts of the fft of the squared magnitude
70  aubio_fft_do_complex (p->fft, p->sqrmag, fftout);
71  // copy real part to acf
72  for (l = 0; l < fftout->length / 2 + 1; l++) {
73    p->acf->data[l] = fftout->data[l];
74  }
75  // get the minimum
76  uint_t tau = fvec_min_elem (p->acf);
77  // get the interpolated minimum
78  output->data[0] = fvec_quadratic_peak_pos (p->acf, tau) * 2.;
79}
80
81void
82del_aubio_pitchspecacf (aubio_pitchspecacf_t * p)
83{
84  del_fvec (p->win);
85  del_fvec (p->winput);
86  del_aubio_fft (p->fft);
87  del_fvec (p->sqrmag);
88  del_fvec (p->fftout);
89  AUBIO_FREE (p);
90}
91
92smpl_t
93aubio_pitchspecacf_get_confidence (aubio_pitchspecacf_t * o) {
94  return 0;
95}
96
97uint_t
98aubio_pitchspecacf_set_tolerance (aubio_pitchspecacf_t * p, smpl_t tol)
99{
100  p->tol = tol;
101  return 0;
102}
103
104smpl_t
105aubio_pitchspecacf_get_tolerance (aubio_pitchspecacf_t * p)
106{
107  return p->tol;
108}
Note: See TracBrowser for help on using the repository browser.