matthiasm@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
matthiasm@0
|
2 /*
|
matthiasm@0
|
3 This file is Copyright (c) 2012 Chris Cannam
|
matthiasm@0
|
4
|
matthiasm@0
|
5 Permission is hereby granted, free of charge, to any person
|
matthiasm@0
|
6 obtaining a copy of this software and associated documentation
|
matthiasm@0
|
7 files (the "Software"), to deal in the Software without
|
matthiasm@0
|
8 restriction, including without limitation the rights to use, copy,
|
matthiasm@0
|
9 modify, merge, publish, distribute, sublicense, and/or sell copies
|
matthiasm@0
|
10 of the Software, and to permit persons to whom the Software is
|
matthiasm@0
|
11 furnished to do so, subject to the following conditions:
|
matthiasm@0
|
12
|
matthiasm@0
|
13 The above copyright notice and this permission notice shall be
|
matthiasm@0
|
14 included in all copies or substantial portions of the Software.
|
matthiasm@0
|
15
|
matthiasm@0
|
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
matthiasm@0
|
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
matthiasm@0
|
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
matthiasm@0
|
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
matthiasm@0
|
20 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
matthiasm@0
|
21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
matthiasm@0
|
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
matthiasm@0
|
23 */
|
matthiasm@0
|
24
|
matthiasm@0
|
25 #ifndef _YIN_H_
|
matthiasm@0
|
26 #define _YIN_H_
|
matthiasm@0
|
27
|
matthiasm@0
|
28 #include "vamp-sdk/FFT.h"
|
matthiasm@0
|
29 #include "MeanFilter.h"
|
matthiasm@0
|
30
|
matthiasm@0
|
31 #include <cmath>
|
matthiasm@0
|
32
|
matthiasm@0
|
33 #include <iostream>
|
matthiasm@0
|
34 #include <vector>
|
matthiasm@0
|
35 #include <exception>
|
matthiasm@0
|
36
|
matthiasm@0
|
37 using std::vector;
|
matthiasm@0
|
38 using std::pair;
|
matthiasm@0
|
39
|
matthiasm@0
|
40
|
matthiasm@0
|
41
|
matthiasm@0
|
42 class Yin
|
matthiasm@0
|
43 {
|
matthiasm@0
|
44 public:
|
matthiasm@0
|
45 Yin(size_t frameSize, size_t inputSampleRate, double thresh = 0.2);
|
matthiasm@0
|
46 virtual ~Yin();
|
matthiasm@0
|
47
|
matthiasm@0
|
48 struct YinOutput {
|
matthiasm@0
|
49 double f0;
|
matthiasm@0
|
50 double periodicity;
|
matthiasm@0
|
51 double rms;
|
matthiasm@0
|
52 vector<double> salience;
|
matthiasm@0
|
53 vector<pair<double, double> > freqProb;
|
matthiasm@0
|
54 YinOutput() : f0(0), periodicity(0), rms(0),
|
matthiasm@0
|
55 salience(vector<double>(0)), freqProb(vector<pair<double, double> >(0)) { }
|
matthiasm@0
|
56 YinOutput(double _f, double _p, double _r) :
|
matthiasm@0
|
57 f0(_f), periodicity(_p), rms(_r),
|
matthiasm@0
|
58 salience(vector<double>(0)), freqProb(vector<pair<double, double> >(0)) { }
|
matthiasm@0
|
59 YinOutput(double _f, double _p, double _r, vector<double> _salience) :
|
matthiasm@0
|
60 f0(_f), periodicity(_p), rms(_r), salience(_salience),
|
matthiasm@0
|
61 freqProb(vector<pair<double, double> >(0)) { }
|
matthiasm@0
|
62 };
|
matthiasm@0
|
63
|
matthiasm@0
|
64 int setThreshold(double parameter);
|
matthiasm@0
|
65 int setThresholdDistr(float parameter);
|
matthiasm@0
|
66 int setFrameSize(size_t frameSize);
|
matthiasm@0
|
67 // int setRemoveUnvoiced(bool frameSize);
|
matthiasm@0
|
68 YinOutput process(const double *in) const;
|
matthiasm@0
|
69 YinOutput processProbabilisticYin(const double *in) const;
|
matthiasm@0
|
70
|
matthiasm@0
|
71 private:
|
matthiasm@0
|
72 mutable size_t m_frameSize;
|
matthiasm@0
|
73 mutable size_t m_inputSampleRate;
|
matthiasm@0
|
74 mutable double m_thresh;
|
matthiasm@0
|
75 mutable size_t m_threshDistr;
|
matthiasm@0
|
76 mutable size_t m_yinBufferSize;
|
matthiasm@0
|
77 // mutable bool m_removeUnvoiced;
|
matthiasm@0
|
78 };
|
matthiasm@0
|
79
|
matthiasm@0
|
80 #endif
|