Mercurial > hg > silvet
comparison src/Silvet.cpp @ 46:d7f1c10f4e1d
Fix noise-reduction filtering (it was going the wrong way)
author | Chris Cannam |
---|---|
date | Mon, 07 Apr 2014 14:18:22 +0100 |
parents | b49597c93132 |
children | ccb1a437a828 9b17bbd16a5f |
comparison
equal
deleted
inserted
replaced
43:7de9fe5e9fab | 46:d7f1c10f4e1d |
---|---|
44 | 44 |
45 Silvet::~Silvet() | 45 Silvet::~Silvet() |
46 { | 46 { |
47 delete m_resampler; | 47 delete m_resampler; |
48 delete m_cq; | 48 delete m_cq; |
49 for (int i = 0; i < (int)m_filterA.size(); ++i) { | |
50 delete m_filterA[i]; | |
51 delete m_filterB[i]; | |
52 } | |
53 for (int i = 0; i < (int)m_postFilter.size(); ++i) { | 49 for (int i = 0; i < (int)m_postFilter.size(); ++i) { |
54 delete m_postFilter[i]; | 50 delete m_postFilter[i]; |
55 } | 51 } |
56 } | 52 } |
57 | 53 |
285 | 281 |
286 m_cq = new CQInterpolated | 282 m_cq = new CQInterpolated |
287 (processingSampleRate, 27.5, processingSampleRate / 3, processingBPO, | 283 (processingSampleRate, 27.5, processingSampleRate / 3, processingBPO, |
288 CQInterpolated::Linear); | 284 CQInterpolated::Linear); |
289 | 285 |
290 for (int i = 0; i < (int)m_filterA.size(); ++i) { | |
291 delete m_filterA[i]; | |
292 delete m_filterB[i]; | |
293 } | |
294 for (int i = 0; i < (int)m_postFilter.size(); ++i) { | 286 for (int i = 0; i < (int)m_postFilter.size(); ++i) { |
295 delete m_postFilter[i]; | 287 delete m_postFilter[i]; |
296 } | 288 } |
297 m_filterA.clear(); | |
298 m_filterB.clear(); | |
299 m_postFilter.clear(); | 289 m_postFilter.clear(); |
300 for (int i = 0; i < processingHeight; ++i) { | |
301 m_filterA.push_back(new MedianFilter<double>(40)); | |
302 m_filterB.push_back(new MedianFilter<double>(40)); | |
303 } | |
304 for (int i = 0; i < processingNotes; ++i) { | 290 for (int i = 0; i < processingNotes; ++i) { |
305 m_postFilter.push_back(new MedianFilter<double>(3)); | 291 m_postFilter.push_back(new MedianFilter<double>(3)); |
306 } | 292 } |
307 m_pianoRoll.clear(); | 293 m_pianoRoll.clear(); |
308 m_columnCount = 0; | 294 m_columnCount = 0; |
430 // each column, and we want it the other way around) and | 416 // each column, and we want it the other way around) and |
431 // then ignore the first 55 (lowest-frequency) bins, | 417 // then ignore the first 55 (lowest-frequency) bins, |
432 // giving us 545 bins instead of 600 | 418 // giving us 545 bins instead of 600 |
433 | 419 |
434 for (int j = 0; j < processingHeight; ++j) { | 420 for (int j = 0; j < processingHeight; ++j) { |
435 | |
436 int ix = inCol.size() - j - 55; | 421 int ix = inCol.size() - j - 55; |
437 | 422 outCol[j] = inCol[ix]; |
438 double val = inCol[ix]; | 423 } |
439 m_filterA[j]->push(val); | 424 |
440 | 425 vector<double> noiseLevel1 = |
441 double a = m_filterA[j]->get(); | 426 MedianFilter<double>::filter(40, outCol); |
442 m_filterB[j]->push(std::min(a, val)); | 427 for (int j = 0; j < processingHeight; ++j) { |
443 | 428 noiseLevel1[j] = std::min(outCol[j], noiseLevel1[j]); |
444 double filtered = m_filterB[j]->get(); | 429 } |
445 outCol[j] = filtered; | 430 |
431 vector<double> noiseLevel2 = | |
432 MedianFilter<double>::filter(40, noiseLevel1); | |
433 for (int j = 0; j < processingHeight; ++j) { | |
434 outCol[j] = std::max(outCol[j] - noiseLevel2[j], 0.0); | |
446 } | 435 } |
447 | 436 |
448 // then we only use every fourth filtered column, for 25 | 437 // then we only use every fourth filtered column, for 25 |
449 // columns per second in the eventual grid | 438 // columns per second in the eventual grid |
439 //!!! why, if we're filtering the time columns, don't we just | |
440 // reduce to this frame rate before filtering at all? | |
450 | 441 |
451 if (m_reducedColumnCount % 4 == 0) { | 442 if (m_reducedColumnCount % 4 == 0) { |
452 out.push_back(outCol); | 443 out.push_back(outCol); |
453 } | 444 } |
454 | 445 |