matthiasm@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ matthiasm@0: /* matthiasm@0: This file is Copyright (c) 2012 Chris Cannam matthiasm@0: matthiasm@0: Permission is hereby granted, free of charge, to any person matthiasm@0: obtaining a copy of this software and associated documentation matthiasm@0: files (the "Software"), to deal in the Software without matthiasm@0: restriction, including without limitation the rights to use, copy, matthiasm@0: modify, merge, publish, distribute, sublicense, and/or sell copies matthiasm@0: of the Software, and to permit persons to whom the Software is matthiasm@0: furnished to do so, subject to the following conditions: matthiasm@0: matthiasm@0: The above copyright notice and this permission notice shall be matthiasm@0: included in all copies or substantial portions of the Software. matthiasm@0: matthiasm@0: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, matthiasm@0: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF matthiasm@0: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND matthiasm@0: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR matthiasm@0: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF matthiasm@0: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION matthiasm@0: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. matthiasm@0: */ matthiasm@0: matthiasm@0: #ifndef _YIN_H_ matthiasm@0: #define _YIN_H_ matthiasm@0: matthiasm@0: #include "vamp-sdk/FFT.h" matthiasm@0: #include "MeanFilter.h" matthiasm@0: matthiasm@0: #include matthiasm@0: matthiasm@0: #include matthiasm@0: #include matthiasm@0: #include matthiasm@0: matthiasm@0: using std::vector; matthiasm@0: using std::pair; matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: class Yin matthiasm@0: { matthiasm@0: public: matthiasm@0: Yin(size_t frameSize, size_t inputSampleRate, double thresh = 0.2); matthiasm@0: virtual ~Yin(); matthiasm@0: matthiasm@0: struct YinOutput { matthiasm@0: double f0; matthiasm@0: double periodicity; matthiasm@0: double rms; matthiasm@0: vector salience; matthiasm@0: vector > freqProb; matthiasm@0: YinOutput() : f0(0), periodicity(0), rms(0), matthiasm@0: salience(vector(0)), freqProb(vector >(0)) { } matthiasm@0: YinOutput(double _f, double _p, double _r) : matthiasm@0: f0(_f), periodicity(_p), rms(_r), matthiasm@0: salience(vector(0)), freqProb(vector >(0)) { } matthiasm@0: YinOutput(double _f, double _p, double _r, vector _salience) : matthiasm@0: f0(_f), periodicity(_p), rms(_r), salience(_salience), matthiasm@0: freqProb(vector >(0)) { } matthiasm@0: }; matthiasm@0: matthiasm@0: int setThreshold(double parameter); matthiasm@0: int setThresholdDistr(float parameter); matthiasm@0: int setFrameSize(size_t frameSize); matthiasm@0: // int setRemoveUnvoiced(bool frameSize); matthiasm@0: YinOutput process(const double *in) const; matthiasm@0: YinOutput processProbabilisticYin(const double *in) const; matthiasm@0: matthiasm@0: private: matthiasm@0: mutable size_t m_frameSize; matthiasm@0: mutable size_t m_inputSampleRate; matthiasm@0: mutable double m_thresh; matthiasm@0: mutable size_t m_threshDistr; matthiasm@0: mutable size_t m_yinBufferSize; matthiasm@0: // mutable bool m_removeUnvoiced; matthiasm@0: }; matthiasm@0: matthiasm@0: #endif