To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / CepstrumPitchTracker.h @ 9:83603936e4d2

History | View | Annotate | Download (3.75 KB)

1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
/*
3
    Permission is hereby granted, free of charge, to any person
4
    obtaining a copy of this software and associated documentation
5
    files (the "Software"), to deal in the Software without
6
    restriction, including without limitation the rights to use, copy,
7
    modify, merge, publish, distribute, sublicense, and/or sell copies
8
    of the Software, and to permit persons to whom the Software is
9
    furnished to do so, subject to the following conditions:
10

11
    The above copyright notice and this permission notice shall be
12
    included in all copies or substantial portions of the Software.
13

14
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
18
    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19
    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
*/
22

    
23
#ifndef _CEPSTRUM_PITCH_H_
24
#define _CEPSTRUM_PITCH_H_
25

    
26
#include <vamp-sdk/Plugin.h>
27

    
28
class CepstrumPitchTracker : public Vamp::Plugin
29
{
30
public:
31
    CepstrumPitchTracker(float inputSampleRate);
32
    virtual ~CepstrumPitchTracker();
33

    
34
    std::string getIdentifier() const;
35
    std::string getName() const;
36
    std::string getDescription() const;
37
    std::string getMaker() const;
38
    int getPluginVersion() const;
39
    std::string getCopyright() const;
40

    
41
    InputDomain getInputDomain() const;
42
    size_t getPreferredBlockSize() const;
43
    size_t getPreferredStepSize() const;
44
    size_t getMinChannelCount() const;
45
    size_t getMaxChannelCount() const;
46

    
47
    ParameterList getParameterDescriptors() const;
48
    float getParameter(std::string identifier) const;
49
    void setParameter(std::string identifier, float value);
50

    
51
    ProgramList getPrograms() const;
52
    std::string getCurrentProgram() const;
53
    void selectProgram(std::string name);
54

    
55
    OutputList getOutputDescriptors() const;
56

    
57
    bool initialise(size_t channels, size_t stepSize, size_t blockSize);
58
    void reset();
59

    
60
    FeatureSet process(const float *const *inputBuffers,
61
                       Vamp::RealTime timestamp);
62

    
63
    FeatureSet getRemainingFeatures();
64

    
65
protected:
66
    size_t m_channels;
67
    size_t m_stepSize;
68
    size_t m_blockSize;
69
    float m_fmin;
70
    float m_fmax;
71
    int m_histlen;
72
    int m_vflen;
73
    int m_ppflen;
74

    
75
    int m_binFrom;
76
    int m_binTo;
77
    int m_bins; // count of "interesting" bins, those returned in m_cepOutput
78

    
79
    class Hypothesis {
80

    
81
    public:
82
        struct Estimate {
83
            double freq;
84
            Vamp::RealTime time;
85
        };
86
        typedef std::vector<Estimate> Estimates;
87
        
88
        Hypothesis(Estimate s);
89
        ~Hypothesis();
90

    
91
        enum State {
92
            Provisional,
93
            Satisfied,
94
            Rejected,
95
            Expired
96
        };
97

    
98
        bool test(Estimate);
99
        State getState();
100

    
101
        Estimates getAcceptedEstimates();
102

    
103
    private:
104
        bool isWithinTolerance(Estimate);
105
        bool isSatisfied();
106

    
107
        State m_state;
108
        Estimates m_pending;
109
        int m_age;
110
    };
111

    
112
    typedef std::vector<Hypothesis> Hypotheses;
113
    Hypotheses m_possible;
114
    Hypothesis *m_accepted;
115

    
116
    double **m_history;
117
    double *m_ppfilter;
118
    
119
    int m_prevpeak;
120
    double m_prevprop;
121

    
122
    double calculatePeakProportion(const double *data, double abstot, int n);
123
    void updatePropFilter(double peakProportion);
124
    bool acceptPeak(int n, double peakProportion);
125

    
126
    void filter(const double *in, double *out);
127
    void fft(unsigned int n, bool inverse,
128
             double *ri, double *ii, double *ro, double *io);
129
};
130

    
131
#endif