Include vamp-pyin
[ardour.git] / libs / vamp-pyin / Yin.h
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3 /*
4     pYIN - A fundamental frequency estimator for monophonic audio
5     Centre for Digital Music, Queen Mary, University of London.
6     
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License as
9     published by the Free Software Foundation; either version 2 of the
10     License, or (at your option) any later version.  See the file
11     COPYING included with this distribution for more information.
12 */
13
14 #ifndef _YIN_H_
15 #define _YIN_H_
16
17 #include "vamp-sdk/FFT.h"
18 #include "MeanFilter.h"
19
20 #include <cmath>
21
22 #include <iostream>
23 #include <vector>
24 #include <exception>
25
26 using std::vector;
27 using std::pair;
28
29
30
31 class Yin
32 {
33 public:
34     Yin(size_t frameSize, size_t inputSampleRate, double thresh = 0.2, bool fast = true);
35     virtual ~Yin();
36
37     struct YinOutput {
38         double f0;
39         double periodicity;
40         double rms;
41         vector<double> salience;
42         vector<pair<double, double> > freqProb;
43         YinOutput() :  f0(0), periodicity(0), rms(0), 
44             salience(vector<double>(0)), freqProb(vector<pair<double, double> >(0)) { }
45         YinOutput(double _f, double _p, double _r) :
46             f0(_f), periodicity(_p), rms(_r), 
47             salience(vector<double>(0)), freqProb(vector<pair<double, double> >(0)) { }
48         YinOutput(double _f, double _p, double _r, vector<double> _salience) :
49             f0(_f), periodicity(_p), rms(_r), salience(_salience), 
50             freqProb(vector<pair<double, double> >(0)) { }
51     };
52     
53     int setThreshold(double parameter);
54     int setThresholdDistr(float parameter);
55     int setFrameSize(size_t frameSize);
56     int setFast(bool fast);
57     // int setRemoveUnvoiced(bool frameSize);
58     YinOutput process(const double *in) const;
59     YinOutput processProbabilisticYin(const double *in) const;
60
61 private:
62     mutable size_t m_frameSize;
63     mutable size_t m_inputSampleRate;
64     mutable double m_thresh;
65     mutable size_t m_threshDistr;
66     mutable size_t m_yinBufferSize;
67     mutable bool   m_fast;
68     // mutable bool m_removeUnvoiced;
69 };
70
71 #endif