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 @ 12:1daaf43a5459

History | View | Annotate | Download (3.77 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

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

    
78
    class Hypothesis {
79

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

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

    
98
        bool test(Estimate);
99

    
100
        void advanceTime();
101

    
102
        State getState();
103

    
104
        int getPendingLength();
105
        Estimates getAcceptedEstimates();
106

    
107
        void addFeatures(FeatureList &fl);
108

    
109
    private:
110
        bool isWithinTolerance(Estimate);
111
        bool isSatisfied();
112

    
113
        State m_state;
114
        Estimates m_pending;
115
        int m_age;
116
    };
117

    
118
    typedef std::vector<Hypothesis> Hypotheses;
119
    Hypotheses m_possible;
120
    Hypothesis m_accepted;
121

    
122
    double **m_history;
123
    
124
    int m_prevpeak;
125
    double m_prevprop;
126

    
127
    double calculatePeakProportion(const double *data, double abstot, int n);
128
    bool acceptPeak(int n, double peakProportion);
129

    
130
    void filter(const double *in, double *out);
131
    void fft(unsigned int n, bool inverse,
132
             double *ri, double *ii, double *ro, double *io);
133
};
134

    
135
#endif