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 / CepstralPitchTracker.h @ 31:2c175adf8736

History | View | Annotate | Download (3.85 KB)

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

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

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

    
25
#ifndef _CEPSTRUM_PITCH_H_
26
#define _CEPSTRUM_PITCH_H_
27

    
28
#include <vamp-sdk/Plugin.h>
29

    
30
class CepstralPitchTracker : public Vamp::Plugin
31
{
32
public:
33
    CepstralPitchTracker(float inputSampleRate);
34
    virtual ~CepstralPitchTracker();
35

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

    
43
    InputDomain getInputDomain() const;
44
    size_t getPreferredBlockSize() const;
45
    size_t getPreferredStepSize() const;
46
    size_t getMinChannelCount() const;
47
    size_t getMaxChannelCount() const;
48

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

    
53
    ProgramList getPrograms() const;
54
    std::string getCurrentProgram() const;
55
    void selectProgram(std::string name);
56

    
57
    OutputList getOutputDescriptors() const;
58

    
59
    bool initialise(size_t channels, size_t stepSize, size_t blockSize);
60
    void reset();
61

    
62
    FeatureSet process(const float *const *inputBuffers,
63
                       Vamp::RealTime timestamp);
64

    
65
    FeatureSet getRemainingFeatures();
66

    
67
protected:
68
    size_t m_channels;
69
    size_t m_stepSize;
70
    size_t m_blockSize;
71
    float m_fmin;
72
    float m_fmax;
73
    int m_vflen;
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
            double confidence;
86
        };
87
        typedef std::vector<Estimate> Estimates;
88

    
89
        struct Note {
90
            double freq;
91
            Vamp::RealTime time;
92
            Vamp::RealTime duration;
93
        };
94
        
95
        Hypothesis();
96
        ~Hypothesis();
97

    
98
        enum State {
99
            New,
100
            Provisional,
101
            Satisfied,
102
            Rejected,
103
            Expired
104
        };
105

    
106
        bool accept(Estimate);
107

    
108
        State getState() const;
109
        Estimates getAcceptedEstimates() const;
110
        Note getAveragedNote() const;
111

    
112
    private:
113
        bool isWithinTolerance(Estimate) const;
114
        bool isOutOfDateFor(Estimate) const;
115
        bool isSatisfied() const;
116
        double getMeanFrequency() const;
117

    
118
        State m_state;
119
        Estimates m_pending;
120
    };
121

    
122
    typedef std::vector<Hypothesis> Hypotheses;
123
    Hypotheses m_possible;
124
    Hypothesis m_good;
125

    
126
    void addFeaturesFrom(Hypothesis h, FeatureSet &fs);
127

    
128
    void filter(const double *in, double *out);
129
    double cubicInterpolate(const double[4], double);
130
    double findInterpolatedPeak(const double *in, int maxbin);
131
};
132

    
133
#endif