Mercurial > hg > silvet
comparison src/Silvet.cpp @ 104:62b7be1226d5 openmp
OpenMP support in main EM iteration
author | Chris Cannam |
---|---|
date | Tue, 06 May 2014 16:28:04 +0100 |
parents | 9c7e6086192d |
children | ac750e222ad3 |
comparison
equal
deleted
inserted
replaced
82:4937f276b446 | 104:62b7be1226d5 |
---|---|
373 { | 373 { |
374 Grid filtered = preProcess(cqout); | 374 Grid filtered = preProcess(cqout); |
375 | 375 |
376 FeatureSet fs; | 376 FeatureSet fs; |
377 | 377 |
378 if (filtered.empty()) return fs; | |
379 | |
378 for (int i = 0; i < (int)filtered.size(); ++i) { | 380 for (int i = 0; i < (int)filtered.size(); ++i) { |
379 Feature f; | 381 Feature f; |
380 for (int j = 0; j < processingHeight; ++j) { | 382 for (int j = 0; j < processingHeight; ++j) { |
381 f.values.push_back(float(filtered[i][j])); | 383 f.values.push_back(float(filtered[i][j])); |
382 } | 384 } |
385 | 387 |
386 int width = filtered.size(); | 388 int width = filtered.size(); |
387 | 389 |
388 int iterations = 12; | 390 int iterations = 12; |
389 | 391 |
390 for (int i = 0; i < width; ++i) { | 392 int stride = 8; |
391 | 393 |
392 double sum = 0.0; | 394 for (int i = 0; i < width; i += stride) { |
393 for (int j = 0; j < processingHeight; ++j) { | 395 |
394 sum += filtered[i][j]; | 396 int chunk = stride; |
395 } | 397 if (i + chunk > width) { |
396 | 398 chunk = width - i; |
397 if (sum < 1e-5) continue; | 399 } |
398 | 400 |
399 EM em; | 401 vector<vector<double> > pitchSubMatrix |
400 for (int j = 0; j < iterations; ++j) { | 402 (chunk, vector<double>(processingNotes)); |
401 em.iterate(filtered[i]); | 403 |
402 } | 404 #pragma omp parallel for |
403 | 405 for (int k = 0; k < chunk; ++k) { |
404 vector<double> pitches = em.getPitchDistribution(); | 406 |
407 double sum = 0.0; | |
408 for (int j = 0; j < processingHeight; ++j) { | |
409 sum += filtered[i + k][j]; | |
410 } | |
411 | |
412 if (sum < 1e-5) continue; | |
413 | |
414 EM em; | |
415 for (int j = 0; j < iterations; ++j) { | |
416 em.iterate(filtered[i + k]); | |
417 } | |
418 | |
419 vector<double> pitches = em.getPitchDistribution(); | |
405 | 420 |
406 for (int j = 0; j < processingNotes; ++j) { | 421 for (int j = 0; j < processingNotes; ++j) { |
407 pitches[j] *= sum; | 422 pitchSubMatrix[k][j] = pitches[j] * sum; |
408 } | 423 } |
409 | 424 } |
410 Feature f; | 425 |
411 for (int j = 0; j < processingNotes; ++j) { | 426 for (int k = 0; k < chunk; ++k) { |
412 f.values.push_back(float(pitches[j])); | 427 |
413 } | 428 const vector<double> &pitches = pitchSubMatrix[k]; |
414 fs[m_pitchOutputNo].push_back(f); | 429 |
415 | 430 Feature f; |
416 FeatureList noteFeatures = postProcess(pitches); | 431 for (int j = 0; j < processingNotes; ++j) { |
417 | 432 f.values.push_back(float(pitches[j])); |
418 for (FeatureList::const_iterator fi = noteFeatures.begin(); | 433 } |
419 fi != noteFeatures.end(); ++fi) { | 434 fs[m_pitchOutputNo].push_back(f); |
420 fs[m_notesOutputNo].push_back(*fi); | 435 |
436 FeatureList noteFeatures = postProcess(pitches); | |
437 | |
438 for (FeatureList::const_iterator fi = noteFeatures.begin(); | |
439 fi != noteFeatures.end(); ++fi) { | |
440 fs[m_notesOutputNo].push_back(*fi); | |
441 } | |
421 } | 442 } |
422 } | 443 } |
423 | 444 |
424 return fs; | 445 return fs; |
425 } | 446 } |