Don't choose impossible tones as undertones.
[pitch] / pitchdetector.h
1 #ifndef _PITCHDETECTOR_H
2 #define _PITCHDETECTOR_H 1
3
4 class PitchDetector {
5 public:
6         PitchDetector(unsigned sample_rate, unsigned fft_length, unsigned pad_factor, unsigned overlap);
7         ~PitchDetector();
8         std::pair<double, double> detect_pitch(short *buf);
9
10 private:
11         // parameters
12         unsigned sample_rate;
13         unsigned fft_length;
14         unsigned pad_factor;
15         unsigned overlap;
16
17         // buffers
18         double *in, *in_windowed;
19         std::complex<double> *out;
20         double *bins;
21         fftw_plan plan;
22         double *window_data;
23
24         // utility functions
25         void apply_window(double *in, double *out, unsigned num_samples);
26         void find_peak_magnitudes(std::complex<double> *in, double *out, unsigned num_samples);
27         std::pair<double, double> find_peak(double *in, unsigned num_samples);
28         std::pair<double, double> adjust_for_overtones(std::pair<double, double> base, double *in, unsigned num_samples);
29         double bin_to_freq(double bin, unsigned num_samples);
30         double freq_to_bin(double freq, unsigned num_samples);
31         std::pair<double, double> interpolate_peak(double ym1, double y0, double y1);
32 };
33
34 #endif /* !defined(_PITCHDETECTOR_H) */