To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / CepstrumPitchTracker.h @ 18:131b1c40be1a
History | View | Annotate | Download (3.89 KB)
| 1 |
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
|---|---|
| 2 |
/*
|
| 3 |
Permission is hereby granted, free of charge, to any person
|
| 4 |
obtaining a copy of this software and associated documentation
|
| 5 |
files (the "Software"), to deal in the Software without
|
| 6 |
restriction, including without limitation the rights to use, copy,
|
| 7 |
modify, merge, publish, distribute, sublicense, and/or sell copies
|
| 8 |
of the Software, and to permit persons to whom the Software is
|
| 9 |
furnished to do so, subject to the following conditions:
|
| 10 |
|
| 11 |
The above copyright notice and this permission notice shall be
|
| 12 |
included in all copies or substantial portions of the Software.
|
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 15 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 16 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 17 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
| 18 |
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
| 19 |
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
| 20 |
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 21 |
*/
|
| 22 |
|
| 23 |
#ifndef _CEPSTRUM_PITCH_H_
|
| 24 |
#define _CEPSTRUM_PITCH_H_
|
| 25 |
|
| 26 |
#include <vamp-sdk/Plugin.h> |
| 27 |
|
| 28 |
class CepstrumPitchTracker : public Vamp::Plugin |
| 29 |
{
|
| 30 |
public:
|
| 31 |
CepstrumPitchTracker(float inputSampleRate);
|
| 32 |
virtual ~CepstrumPitchTracker(); |
| 33 |
|
| 34 |
std::string getIdentifier() const;
|
| 35 |
std::string getName() const;
|
| 36 |
std::string getDescription() const;
|
| 37 |
std::string getMaker() const;
|
| 38 |
int getPluginVersion() const; |
| 39 |
std::string getCopyright() const;
|
| 40 |
|
| 41 |
InputDomain getInputDomain() const;
|
| 42 |
size_t getPreferredBlockSize() const;
|
| 43 |
size_t getPreferredStepSize() const;
|
| 44 |
size_t getMinChannelCount() const;
|
| 45 |
size_t getMaxChannelCount() const;
|
| 46 |
|
| 47 |
ParameterList getParameterDescriptors() const;
|
| 48 |
float getParameter(std::string identifier) const; |
| 49 |
void setParameter(std::string identifier, float value); |
| 50 |
|
| 51 |
ProgramList getPrograms() const;
|
| 52 |
std::string getCurrentProgram() const;
|
| 53 |
void selectProgram(std::string name);
|
| 54 |
|
| 55 |
OutputList getOutputDescriptors() const;
|
| 56 |
|
| 57 |
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
|
| 58 |
void reset();
|
| 59 |
|
| 60 |
FeatureSet process(const float *const *inputBuffers, |
| 61 |
Vamp::RealTime timestamp); |
| 62 |
|
| 63 |
FeatureSet getRemainingFeatures(); |
| 64 |
|
| 65 |
protected:
|
| 66 |
size_t m_channels; |
| 67 |
size_t m_stepSize; |
| 68 |
size_t m_blockSize; |
| 69 |
float m_fmin;
|
| 70 |
float m_fmax;
|
| 71 |
int m_vflen;
|
| 72 |
|
| 73 |
int m_binFrom;
|
| 74 |
int m_binTo;
|
| 75 |
int m_bins; // count of "interesting" bins, those returned in m_cepOutput |
| 76 |
|
| 77 |
class Hypothesis {
|
| 78 |
|
| 79 |
public:
|
| 80 |
struct Estimate {
|
| 81 |
double freq;
|
| 82 |
Vamp::RealTime time; |
| 83 |
double confidence;
|
| 84 |
}; |
| 85 |
typedef std::vector<Estimate> Estimates;
|
| 86 |
|
| 87 |
struct Note {
|
| 88 |
double freq;
|
| 89 |
Vamp::RealTime time; |
| 90 |
Vamp::RealTime duration; |
| 91 |
}; |
| 92 |
|
| 93 |
Hypothesis(); |
| 94 |
~Hypothesis(); |
| 95 |
|
| 96 |
enum State {
|
| 97 |
New, |
| 98 |
Provisional, |
| 99 |
Satisfied, |
| 100 |
Rejected, |
| 101 |
Expired |
| 102 |
}; |
| 103 |
|
| 104 |
bool test(Estimate);
|
| 105 |
|
| 106 |
void advanceTime();
|
| 107 |
|
| 108 |
State getState(); |
| 109 |
|
| 110 |
int getPendingLength();
|
| 111 |
Estimates getAcceptedEstimates(); |
| 112 |
Note getAveragedNote(); |
| 113 |
|
| 114 |
void addFeatures(FeatureSet &fs);
|
| 115 |
|
| 116 |
private:
|
| 117 |
bool isWithinTolerance(Estimate);
|
| 118 |
bool isSatisfied();
|
| 119 |
double getMeanFrequency();
|
| 120 |
|
| 121 |
State m_state; |
| 122 |
Estimates m_pending; |
| 123 |
int m_age;
|
| 124 |
}; |
| 125 |
|
| 126 |
typedef std::vector<Hypothesis> Hypotheses;
|
| 127 |
Hypotheses m_possible; |
| 128 |
Hypothesis m_accepted; |
| 129 |
|
| 130 |
void filter(const double *in, double *out); |
| 131 |
double cubicInterpolate(const double[4], double); |
| 132 |
double findInterpolatedPeak(const double *in, int maxbin); |
| 133 |
void fft(unsigned int n, bool inverse, |
| 134 |
double *ri, double *ii, double *ro, double *io); |
| 135 |
}; |
| 136 |
|
| 137 |
#endif
|