Guitarix
gx_pitch_tracker.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3  * Copyright (C) 2011 Pete Shorthose
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  * --------------------------------------------------------------------------
19  */
20 
21 /* ------- This is the guitarix Engine namespace ------- */
22 
23 #pragma once
24 
25 #ifndef SRC_HEADERS_GX_PITCH_TRACKER_H_
26 #define SRC_HEADERS_GX_PITCH_TRACKER_H_
27 
28 #include <fftw3.h>
29 
30 namespace gx_engine {
31 /* ------------- Pitch Tracker ------------- */
32 
33 class PitchTracker {
34  public:
35  PitchTracker();
36  ~PitchTracker();
37  void init(int priority, int policy, unsigned int samplerate);
38  void add(int count, float *input);
39  float get_estimated_freq() { return m_freq < 0 ? 0 : m_freq; }
40  float get_estimated_note();
41  void stop_thread();
42  void reset();
43  void set_fast_note_detection(bool v);
44  Glib::Dispatcher new_freq;
45  private:
46  bool setParameters(int priority, int policy, int sampleRate, int fftSize );
47  void run();
48  static void *static_run(void* p);
49  void start_thread(int policy, int priority);
50  void copy();
51  bool error;
52  volatile bool busy;
53  int tick;
54  sem_t m_trig;
55  pthread_t m_pthr;
56  Resampler resamp;
57  int m_sampleRate;
58  int fixed_sampleRate;
59  float m_freq;
60  // Value of the threshold above which
61  // the processing is activated.
62  float signal_threshold_on;
63  // Value of the threshold below which
64  // the input audio signal is deactivated.
65  float signal_threshold_off;
66  // Time between frequency estimates (in seconds)
67  float tracker_period;
68  // number of samples in input buffer
69  int m_buffersize;
70  // Size of the FFT window.
71  int m_fftSize;
72  // The audio buffer that stores the input signal.
73  float *m_buffer;
74  // Index of the first empty position in the buffer.
75  int m_bufferIndex;
76  // buffer for input signal
77  float *m_input;
78  // Whether or not the input level is high enough.
79  bool m_audioLevel;
80  // Support buffer used to store signals in the time domain.
81  float *m_fftwBufferTime;
82  // Support buffer used to store signals in the frequency domain.
83  float *m_fftwBufferFreq;
84  // Plan to compute the FFT of a given signal.
85  fftwf_plan m_fftwPlanFFT;
86  // Plan to compute the IFFT of a given signal (with additional zero-padding).
87  fftwf_plan m_fftwPlanIFFT;
88 };
89 
90 }
91 #endif // SRC_HEADERS_GX_PITCH_TRACKER_H_
void set_fast_note_detection(bool v)
void init(int priority, int policy, unsigned int samplerate)
void add(int count, float *input)
Glib::Dispatcher new_freq