|
From: Lasse Kärkkäi. <tr...@us...> - 2011-02-07 13:27:26
|
Module: editor
Branch: master
Commit: 57f5cbee7a846575c6b30e840c3e0a04f608db0a
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Feb 7 14:23:40 2011 +0100
Missing fundamental handling.
---
pitch.cc | 28 +++++++++++++++-------------
1 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/pitch.cc b/pitch.cc
index e5dab9e..3d742cf 100644
--- a/pitch.cc
+++ b/pitch.cc
@@ -105,21 +105,23 @@ void Analyzer::calcTones() {
Tones tones;
for (Combos::const_iterator it = combos.begin(), itend = combos.end(); it != itend; ++it) {
Tone tone;
- for (Combos::const_iterator harm = it + 1; harm != itend; ++harm) {
- double ratio = harm->freq / it->freq;
- unsigned n = round(ratio);
- if (n == 0) {
- continue;
+ for (int div = 1; div <= 3; ++div) { // Missing fundamental processing
+ double basefreq = it->freq / div;
+ if (basefreq < FFT_MINFREQ) break; // Do not try any lower frequencies
+ for (Combos::const_iterator harm = it; harm != itend; ++harm) {
+ double ratio = harm->freq / basefreq;
+ unsigned n = round(ratio);
+ if (n == 0) throw std::logic_error("combos not correctly sorted");
+ if (n > Tone::MAXHARM) break; // No more harmonics can be found
+ if (std::abs(ratio - n) > 0.03) continue; // Frequency doesn't match
+ double l = harm->level;
+ tone.harmonics[n - 1] += l;
+ tone.level += l;
+ tone.freq += l * harm->freq / n; // The sum of all harmonics' fundies (weighted by l)
}
- if (n > Tone::MAXHARM) break; // No more harmonics can be found
- if (std::abs(ratio - n) > 0.03) continue; // Frequency doesn't match
- double l = harm->level;
- tone.harmonics[n - 1] += l;
- tone.level += l;
- tone.freq += l * harm->freq / n; // The sum of all harmonics' fundies (weighted by l)
+ tone.freq /= tone.level; // Average instead of sum
+ tones.push_back(tone);
}
- tone.freq /= tone.level; // Average instead of sum
- tones.push_back(tone);
}
// Clean harmonics misdetected as fundamental
tones.sort();
|