Revision 30:2554aab152a5

View differences:

CepstrumPitchTracker.cpp
45 45
}
46 46

  
47 47
bool
48
CepstrumPitchTracker::Hypothesis::isWithinTolerance(Estimate s)
48
CepstrumPitchTracker::Hypothesis::isWithinTolerance(Estimate s) const
49 49
{
50 50
    if (m_pending.empty()) {
51 51
        return true;
......
68 68
}
69 69

  
70 70
bool
71
CepstrumPitchTracker::Hypothesis::isOutOfDateFor(Estimate s)
71
CepstrumPitchTracker::Hypothesis::isOutOfDateFor(Estimate s) const
72 72
{
73 73
    if (m_pending.empty()) return false;
74 74

  
......
77 77
}
78 78

  
79 79
bool 
80
CepstrumPitchTracker::Hypothesis::isSatisfied()
80
CepstrumPitchTracker::Hypothesis::isSatisfied() const
81 81
{
82 82
    if (m_pending.empty()) return false;
83 83
    
......
91 91
    if (meanConfidence > 0.0) {
92 92
        lengthRequired = int(2.0 / meanConfidence + 0.5);
93 93
    }
94
    std::cerr << "meanConfidence = " << meanConfidence << ", lengthRequired = " << lengthRequired << ", length = " << m_pending.size() << std::endl;
95 94

  
96 95
    return (m_pending.size() > lengthRequired);
97 96
}
......
142 141
}        
143 142

  
144 143
CepstrumPitchTracker::Hypothesis::State
145
CepstrumPitchTracker::Hypothesis::getState()
144
CepstrumPitchTracker::Hypothesis::getState() const
146 145
{
147 146
    return m_state;
148 147
}
149 148

  
150 149
CepstrumPitchTracker::Hypothesis::Estimates
151
CepstrumPitchTracker::Hypothesis::getAcceptedEstimates()
150
CepstrumPitchTracker::Hypothesis::getAcceptedEstimates() const
152 151
{
153 152
    if (m_state == Satisfied || m_state == Expired) {
154 153
        return m_pending;
......
158 157
}
159 158

  
160 159
double
161
CepstrumPitchTracker::Hypothesis::getMeanFrequency()
160
CepstrumPitchTracker::Hypothesis::getMeanFrequency() const
162 161
{
163 162
    double acc = 0.0;
164 163
    for (int i = 0; i < m_pending.size(); ++i) {
......
169 168
}
170 169

  
171 170
CepstrumPitchTracker::Hypothesis::Note
172
CepstrumPitchTracker::Hypothesis::getAveragedNote()
171
CepstrumPitchTracker::Hypothesis::getAveragedNote() const
173 172
{
174 173
    Note n;
175 174

  
......
182 181

  
183 182
    n.time = m_pending.begin()->time;
184 183

  
185
    Estimates::iterator i = m_pending.end();
184
    Estimates::const_iterator i = m_pending.end();
186 185
    --i;
187 186
    n.duration = i->time - n.time;
188 187

  
......
192 191
    return n;
193 192
}
194 193

  
195
void
196
CepstrumPitchTracker::Hypothesis::addFeatures(FeatureSet &fs)
197
{
198
    for (int i = 0; i < m_pending.size(); ++i) {
199
	Feature f;
200
	f.hasTimestamp = true;
201
	f.timestamp = m_pending[i].time;
202
	f.values.push_back(m_pending[i].freq);
203
	fs[0].push_back(f);
204
    }
205

  
206
    Feature nf;
207
    nf.hasTimestamp = true;
208
    nf.hasDuration = true;
209
    Note n = getAveragedNote();
210
    nf.timestamp = n.time;
211
    nf.duration = n.duration;
212
    nf.values.push_back(n.freq);
213
    fs[1].push_back(nf);
214
}
215

  
216 194
CepstrumPitchTracker::CepstrumPitchTracker(float inputSampleRate) :
217 195
    Plugin(inputSampleRate),
218 196
    m_channels(0),
......
411 389
}
412 390

  
413 391
void
392
CepstrumPitchTracker::addFeaturesFrom(Hypothesis h, FeatureSet &fs)
393
{
394
    Hypothesis::Estimates es = h.getAcceptedEstimates();
395

  
396
    for (int i = 0; i < es.size(); ++i) {
397
	Feature f;
398
	f.hasTimestamp = true;
399
	f.timestamp = es[i].time;
400
	f.values.push_back(es[i].freq);
401
	fs[0].push_back(f);
402
    }
403

  
404
    Feature nf;
405
    nf.hasTimestamp = true;
406
    nf.hasDuration = true;
407
    Hypothesis::Note n = h.getAveragedNote();
408
    nf.timestamp = n.time;
409
    nf.duration = n.duration;
410
    nf.values.push_back(n.freq);
411
    fs[1].push_back(nf);
412
}
413

  
414
void
414 415
CepstrumPitchTracker::filter(const double *cep, double *data)
415 416
{
416 417
    for (int i = 0; i < m_bins; ++i) {
......
604 605
        }
605 606

  
606 607
        if (m_good.getState() == Hypothesis::Expired) {
607
            m_good.addFeatures(fs);
608
            addFeaturesFrom(m_good, fs);
608 609
        }
609 610
        
610 611
        if (m_good.getState() == Hypothesis::Expired ||
......
637 638
{
638 639
    FeatureSet fs;
639 640
    if (m_good.getState() == Hypothesis::Satisfied) {
640
        m_good.addFeatures(fs);
641
        addFeaturesFrom(m_good, fs);
641 642
    }
642 643
    return fs;
643 644
}
CepstrumPitchTracker.h
103 103

  
104 104
        bool accept(Estimate);
105 105

  
106
        State getState();
107

  
108
        Estimates getAcceptedEstimates();
109
        Note getAveragedNote();
110

  
111
        void addFeatures(FeatureSet &fs);
106
        State getState() const;
107
        Estimates getAcceptedEstimates() const;
108
        Note getAveragedNote() const;
112 109

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

  
119 116
        State m_state;
120 117
        Estimates m_pending;
......
124 121
    Hypotheses m_possible;
125 122
    Hypothesis m_good;
126 123

  
124
    void addFeaturesFrom(Hypothesis h, FeatureSet &fs);
125

  
127 126
    void filter(const double *in, double *out);
128 127
    double cubicInterpolate(const double[4], double);
129 128
    double findInterpolatedPeak(const double *in, int maxbin);

Also available in: Unified diff