Chris@8: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@8: /* Chris@8: Permission is hereby granted, free of charge, to any person Chris@8: obtaining a copy of this software and associated documentation Chris@8: files (the "Software"), to deal in the Software without Chris@8: restriction, including without limitation the rights to use, copy, Chris@8: modify, merge, publish, distribute, sublicense, and/or sell copies Chris@8: of the Software, and to permit persons to whom the Software is Chris@8: furnished to do so, subject to the following conditions: Chris@8: Chris@8: The above copyright notice and this permission notice shall be Chris@8: included in all copies or substantial portions of the Software. Chris@8: Chris@8: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@8: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@8: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@8: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@8: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@8: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@8: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@8: */ Chris@8: Chris@8: #ifndef _CEPSTRUM_PITCH_H_ Chris@8: #define _CEPSTRUM_PITCH_H_ Chris@8: Chris@8: #include Chris@8: Chris@8: class CepstrumPitchTracker : public Vamp::Plugin Chris@8: { Chris@8: public: Chris@8: CepstrumPitchTracker(float inputSampleRate); Chris@8: virtual ~CepstrumPitchTracker(); Chris@8: Chris@8: std::string getIdentifier() const; Chris@8: std::string getName() const; Chris@8: std::string getDescription() const; Chris@8: std::string getMaker() const; Chris@8: int getPluginVersion() const; Chris@8: std::string getCopyright() const; Chris@8: Chris@8: InputDomain getInputDomain() const; Chris@8: size_t getPreferredBlockSize() const; Chris@8: size_t getPreferredStepSize() const; Chris@8: size_t getMinChannelCount() const; Chris@8: size_t getMaxChannelCount() const; Chris@8: Chris@8: ParameterList getParameterDescriptors() const; Chris@8: float getParameter(std::string identifier) const; Chris@8: void setParameter(std::string identifier, float value); Chris@8: Chris@8: ProgramList getPrograms() const; Chris@8: std::string getCurrentProgram() const; Chris@8: void selectProgram(std::string name); Chris@8: Chris@8: OutputList getOutputDescriptors() const; Chris@8: Chris@8: bool initialise(size_t channels, size_t stepSize, size_t blockSize); Chris@8: void reset(); Chris@8: Chris@8: FeatureSet process(const float *const *inputBuffers, Chris@8: Vamp::RealTime timestamp); Chris@8: Chris@8: FeatureSet getRemainingFeatures(); Chris@8: Chris@8: protected: Chris@8: size_t m_channels; Chris@8: size_t m_stepSize; Chris@8: size_t m_blockSize; Chris@8: float m_fmin; Chris@8: float m_fmax; Chris@10: int m_vflen; Chris@8: Chris@8: int m_binFrom; Chris@8: int m_binTo; Chris@8: int m_bins; // count of "interesting" bins, those returned in m_cepOutput Chris@8: Chris@12: class Hypothesis { Chris@12: Chris@12: public: Chris@12: struct Estimate { Chris@12: double freq; Chris@12: Vamp::RealTime time; Chris@20: double confidence; Chris@12: }; Chris@12: typedef std::vector Estimates; Chris@21: Chris@21: struct Note { Chris@21: double freq; Chris@21: Vamp::RealTime time; Chris@21: Vamp::RealTime duration; Chris@21: }; Chris@12: Chris@13: Hypothesis(); Chris@12: ~Hypothesis(); Chris@12: Chris@12: enum State { Chris@13: New, Chris@12: Provisional, Chris@12: Satisfied, Chris@12: Rejected, Chris@12: Expired Chris@12: }; Chris@12: Chris@12: bool test(Estimate); Chris@13: Chris@13: void advanceTime(); Chris@13: Chris@12: State getState(); Chris@12: Chris@17: int getPendingLength(); Chris@12: Estimates getAcceptedEstimates(); Chris@21: Note getAveragedNote(); Chris@12: Chris@21: void addFeatures(FeatureSet &fs); Chris@16: Chris@12: private: Chris@12: bool isWithinTolerance(Estimate); Chris@12: bool isSatisfied(); Chris@22: double getMeanFrequency(); Chris@12: Chris@12: State m_state; Chris@12: Estimates m_pending; Chris@12: int m_age; Chris@12: }; Chris@12: Chris@12: typedef std::vector Hypotheses; Chris@12: Hypotheses m_possible; Chris@13: Hypothesis m_accepted; Chris@12: Chris@8: void filter(const double *in, double *out); Chris@25: double cubicInterpolate(const double[4], double); Chris@25: double findInterpolatedPeak(const double *in, int maxbin); Chris@8: void fft(unsigned int n, bool inverse, Chris@8: double *ri, double *ii, double *ro, double *io); Chris@8: }; Chris@8: Chris@8: #endif