1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
// -----------------------------------------------------------------------
//
// Copyright (C) 2009-2011 Fons Adriaensen <fons@linuxaudio.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// -----------------------------------------------------------------------
#ifndef __RETUNER_H
#define __RETUNER_H
#include <fftw3.h>
#include <zita-resampler/resampler.h>
class Retuner
{
public:
Retuner (int fsamp);
~Retuner (void);
int process (int nfram, float *inp, float *out);
void set_refpitch (float v)
{
_refpitch = v;
}
void set_notebias (float v)
{
_notebias = v / 13.0f;
}
void set_corrfilt (float v)
{
_corrfilt = (4 * _frsize) / (v * _fsamp);
}
void set_corrgain (float v)
{
_corrgain = v;
}
void set_corroffs (float v)
{
_corroffs = v;
}
void set_notemask (int k)
{
_notemask = k;
}
int get_noteset (void)
{
int k;
k = _notebits;
_notebits = 0;
return k;
}
float get_error (void)
{
return 12.0f * _error;
}
private:
void findcycle (void);
void finderror (void);
float cubic (float *v, float a);
int _fsamp;
int _ifmin;
int _ifmax;
bool _upsamp;
int _fftlen;
int _ipsize;
int _frsize;
int _ipindex;
int _frindex;
int _frcount;
float _refpitch;
float _notebias;
float _corrfilt;
float _corrgain;
float _corroffs;
int _notemask;
int _notebits;
int _lastnote;
int _count;
float _cycle;
float _error;
float _ratio;
float _phase;
bool _xfade;
float _rindex1;
float _rindex2;
float *_ipbuff;
float *_xffunc;
float *_fftTwind;
float *_fftWcorr;
float *_fftTdata;
fftwf_complex *_fftFdata;
fftwf_plan _fwdplan;
fftwf_plan _invplan;
Resampler _resampler;
};
#endif
|