|
From: Lasse Kärkkäi. <tr...@us...> - 2011-01-13 17:23:01
|
Module: editor Branch: master Commit: a94754771b85d5fb8830ccc2565b57e4b5bda1ee Author: Lasse Kärkkäinen <tronic+ndrm at trn.iki.fi> Date: Thu Jan 13 18:19:48 2011 +0100 Improve filtering stability; revert semitone rounding --- pitch.cc | 2 +- pitch.hh | 2 +- pitchvis.cc | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pitch.cc b/pitch.cc index 2c4bfb8..b3da8a1 100644 --- a/pitch.cc +++ b/pitch.cc @@ -197,7 +197,7 @@ void Analyzer::mergeWithOld(Tones& tones) const { // Merge the old tone into the new tone it->age = oldit->age + 1; it->stabledb = 0.8 * oldit->stabledb + 0.2 * it->db; - //it->freq = 0.5 * oldit->freq + 0.5 * it->freq; + it->freq = 0.5 * oldit->freq + 0.5 * it->freq; } else if (oldit->db > -80.0) { // Insert a decayed version of the old tone into new tones Tone& t = *tones.insert(it, *oldit); diff --git a/pitch.hh b/pitch.hh index cff9b22..cff8cf3 100644 --- a/pitch.hh +++ b/pitch.hh @@ -12,7 +12,7 @@ static inline double dB2magn(double db) { return std::pow(10.0, db / 20.0); } /// A tone is a collection of a base frequency (freq) and all its harmonics struct Tone { - static const std::size_t MAXHARM = 8; ///< The maximum number of harmonics tracked + static const std::size_t MAXHARM = 16; ///< The maximum number of harmonics tracked static const std::size_t MINAGE = 6; ///< The minimum age required for a tone to be output double freq; ///< Frequency (Hz) double db; ///< Level (dB) diff --git a/pitchvis.cc b/pitchvis.cc index bc97bca..e4b29f9 100644 --- a/pitchvis.cc +++ b/pitchvis.cc @@ -38,7 +38,6 @@ PitchVis::PitchVis(std::string const& filename): height(1024) { analyzer.input(data.begin() + x * step, data.begin() + (x + 1) * step); analyzer.process(); - /* Analyzer::Peaks peaks = analyzer.getPeaks(); for (unsigned i = 0; i < peaks.size(); ++i) { unsigned y = height - static_cast<unsigned>(16.0 * scale.getNote(peaks[i].freq)); @@ -53,11 +52,11 @@ PitchVis::PitchVis(std::string const& filename): height(1024) { (*this)(x, y + 1) += p; (*this)(x, y - 1) += p; } - */ Analyzer::Tones tones = analyzer.getTones(); unsigned int i = 0; for (Analyzer::Tones::const_iterator it = tones.begin(), itend = tones.end(); it != itend && i < 3; ++it) { - unsigned y = height - static_cast<unsigned>(16.0 * scale.getNoteId(it->freq)); + if (it->age < Tone::MINAGE) continue; + unsigned y = height - static_cast<unsigned>(16.0 * scale.getNote(it->freq)); if (y == 0 || y >= height - 1) continue; float value = 0.003 * (it->db + 80.0); if (value <= 0.0) continue; |