Revision 56:d8eeba570d70
| CepstralPitchTracker.cpp | ||
|---|---|---|
| 26 | 26 |
#include "Cepstrum.h" |
| 27 | 27 |
#include "MeanFilter.h" |
| 28 | 28 |
#include "PeakInterpolator.h" |
| 29 |
#include "AgentFeeder.h" |
|
| 29 | 30 |
|
| 30 | 31 |
#include "vamp-sdk/FFT.h" |
| 31 | 32 |
|
| ... | ... | |
| 51 | 52 |
m_vflen(1), |
| 52 | 53 |
m_binFrom(0), |
| 53 | 54 |
m_binTo(0), |
| 54 |
m_bins(0) |
|
| 55 |
m_bins(0), |
|
| 56 |
m_feeder(0) |
|
| 55 | 57 |
{
|
| 56 | 58 |
} |
| 57 | 59 |
|
| 58 | 60 |
CepstralPitchTracker::~CepstralPitchTracker() |
| 59 | 61 |
{
|
| 62 |
delete m_feeder; |
|
| 60 | 63 |
} |
| 61 | 64 |
|
| 62 | 65 |
string |
| ... | ... | |
| 223 | 226 |
if (m_binTo >= (int)m_blockSize / 2) {
|
| 224 | 227 |
m_binTo = m_blockSize / 2 - 1; |
| 225 | 228 |
} |
| 229 |
if (m_binFrom >= m_binTo) {
|
|
| 230 |
// shouldn't happen except for degenerate samplerate / blocksize combos |
|
| 231 |
m_binFrom = m_binTo - 1; |
|
| 232 |
} |
|
| 226 | 233 |
|
| 227 | 234 |
m_bins = (m_binTo - m_binFrom) + 1; |
| 228 | 235 |
|
| ... | ... | |
| 234 | 241 |
void |
| 235 | 242 |
CepstralPitchTracker::reset() |
| 236 | 243 |
{
|
| 244 |
delete m_feeder; |
|
| 245 |
m_feeder = new AgentFeeder(); |
|
| 237 | 246 |
} |
| 238 | 247 |
|
| 239 | 248 |
void |
| ... | ... | |
| 317 | 326 |
e.time = timestamp; |
| 318 | 327 |
e.confidence = confidence; |
| 319 | 328 |
|
| 320 |
if (!m_good.accept(e)) {
|
|
| 321 |
|
|
| 322 |
int candidate = -1; |
|
| 323 |
bool accepted = false; |
|
| 324 |
|
|
| 325 |
for (int i = 0; i < (int)m_possible.size(); ++i) {
|
|
| 326 |
if (m_possible[i].accept(e)) {
|
|
| 327 |
if (m_possible[i].getState() == NoteHypothesis::Satisfied) {
|
|
| 328 |
accepted = true; |
|
| 329 |
candidate = i; |
|
| 330 |
} |
|
| 331 |
break; |
|
| 332 |
} |
|
| 333 |
} |
|
| 334 |
|
|
| 335 |
if (!accepted) {
|
|
| 336 |
NoteHypothesis h; |
|
| 337 |
h.accept(e); //!!! must succeed as h is new, so perhaps there should be a ctor for this |
|
| 338 |
m_possible.push_back(h); |
|
| 339 |
} |
|
| 340 |
|
|
| 341 |
if (m_good.getState() == NoteHypothesis::Expired) {
|
|
| 342 |
addFeaturesFrom(m_good, fs); |
|
| 343 |
} |
|
| 344 |
|
|
| 345 |
if (m_good.getState() == NoteHypothesis::Expired || |
|
| 346 |
m_good.getState() == NoteHypothesis::Rejected) {
|
|
| 347 |
if (candidate >= 0) {
|
|
| 348 |
m_good = m_possible[candidate]; |
|
| 349 |
} else {
|
|
| 350 |
m_good = NoteHypothesis(); |
|
| 351 |
} |
|
| 352 |
} |
|
| 353 |
|
|
| 354 |
// reap rejected/expired hypotheses from possible list |
|
| 355 |
Hypotheses toReap = m_possible; |
|
| 356 |
m_possible.clear(); |
|
| 357 |
for (int i = 0; i < (int)toReap.size(); ++i) {
|
|
| 358 |
NoteHypothesis h = toReap[i]; |
|
| 359 |
if (h.getState() != NoteHypothesis::Rejected && |
|
| 360 |
h.getState() != NoteHypothesis::Expired) {
|
|
| 361 |
m_possible.push_back(h); |
|
| 362 |
} |
|
| 363 |
} |
|
| 364 |
} |
|
| 329 |
m_feeder->feed(e); |
|
| 365 | 330 |
|
| 366 | 331 |
delete[] data; |
| 367 | 332 |
return fs; |
| ... | ... | |
| 370 | 335 |
CepstralPitchTracker::FeatureSet |
| 371 | 336 |
CepstralPitchTracker::getRemainingFeatures() |
| 372 | 337 |
{
|
| 338 |
m_feeder->finish(); |
|
| 339 |
|
|
| 340 |
AgentFeeder::Hypotheses accepted = m_feeder->getAcceptedHypotheses(); |
|
| 341 |
|
|
| 373 | 342 |
FeatureSet fs; |
| 374 |
if (m_good.getState() == NoteHypothesis::Satisfied) {
|
|
| 375 |
addFeaturesFrom(m_good, fs);
|
|
| 343 |
for (int i = 0; i < accepted.size(); ++i) {
|
|
| 344 |
addFeaturesFrom(accepted[i], fs);
|
|
| 376 | 345 |
} |
| 377 | 346 |
return fs; |
| 378 | 347 |
} |
Also available in: Unified diff