annotate CepstrumPitchTracker.h @ 21:df41333abbc9 track

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