|
From: Lasse Kärkkäi. <tr...@us...> - 2011-01-20 10:34:57
|
Module: editor
Branch: master
Commit: 9ec8b1a1c4cda67e5e9829491836a09132a4940c
Author: Lasse Karkkainen <tro...@tr...>
Date: Thu Jan 20 11:27:37 2011 +0100
It compiles, ship i-- No, wait, it still segfaults :(
---
pitch.cc | 42 +++++++++++++++++-------------------------
pitch.hh | 11 ++++++-----
pitchvis.cc | 5 ++---
3 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/pitch.cc b/pitch.cc
index a5a6c3b..0cd9e19 100644
--- a/pitch.cc
+++ b/pitch.cc
@@ -2,8 +2,6 @@
#include "libda/fft.hpp"
#include <cmath>
-#include <iostream>
-#include <iomanip>
#include <numeric>
static const unsigned FFT_P = 11; // FFT size setting, will use 2^FFT_P sample FFT
@@ -14,23 +12,10 @@ static const std::size_t FFT_STEP = 512; // Step size in samples, should be <=
static const double FFT_MINFREQ = 45.0;
static const double FFT_MAXFREQ = 3000.0;
-Tone::Tone():
- freq(),
- freqSlow(),
- level(),
- levelSlow(),
- age()
-{
+Tone::Tone(): freq(), level() {
for (std::size_t i = 0; i < MAXHARM; ++i) harmonics[i] = 0.0;
}
-void Tone::print() const {
- if (age < Tone::MINAGE) return;
- std::cout << std::fixed << std::setprecision(1) << freq << " Hz, age " << age << ", " << level2dB(level) << " dB:";
- for (std::size_t i = 0; i < 8; ++i) std::cout << " " << harmonics[i];
- std::cout << std::endl;
-}
-
bool Tone::operator==(double f) const {
return std::abs(freq / f - 1.0) < 0.03; // Half semitone
}
@@ -161,7 +146,7 @@ void Analyzer::calcTones() {
}
if (miss) ++misses;
}
- t.freqSlow = t.freq /= t.level; // Average instead of sum
+ t.freq /= t.level; // Average instead of sum
if (score > bestScore) {
bestScore = score;
bestTone = t;
@@ -179,15 +164,17 @@ void Analyzer::calcTones() {
else ++it2;
}
}
-// std::cerr << std::endl;
- mergeWithOld(tones);
- m_tones.swap(tones);
+ temporalMerge(tones);
}
-void Analyzer::mergeWithOld(Tones& tones) const {
- Tones::iterator it = tones.begin();
+void Analyzer::temporalMerge(Tones& tones) {
+ /*Tones::iterator oldit;
+ for (Tones::const_iterator it = tones.begin(), itend = tones.end(); it != itend; ++it) {
+ if () oldit = std::find(
+ }
// Iterate over old tones
- for (Tones::const_iterator oldit = m_tones.begin(); oldit != m_tones.end(); ++oldit) {
+ for (ToneSeries::reverse_iterator oldit = m_toneSeries.rbegin(); oldit != m_toneSeries.rend(); ++oldit) {
+ if (
// Try to find a matching new tone
while (it != tones.end() && *it < *oldit) ++it;
// If match found
@@ -202,7 +189,8 @@ void Analyzer::mergeWithOld(Tones& tones) const {
t.level = 0.0;
t.levelSlow *= 0.01;
}
- }
+ }*/
+ m_moments.push_back(Moment(0.0, tones));
}
void Analyzer::process() {
@@ -210,7 +198,7 @@ void Analyzer::process() {
while (calcFFT()) calcTones();
}
-Tone const* Analyzer::findTone(double minfreq, double maxfreq) const {
+/*Tone const* Analyzer::findTone(double minfreq, double maxfreq) const {
Tone const* best = NULL;
double bestscore = -getInf();
for (Tones::const_iterator it = m_tones.begin(); it != m_tones.end(); ++it) {
@@ -226,5 +214,9 @@ Tone const* Analyzer::findTone(double minfreq, double maxfreq) const {
}
m_oldfreq = (best ? best->freq : 0.0);
return best;
+}*/
+
+Moment::Moment(double t, Tones& tones): m_time(t) {
+ m_tones.swap(tones);
}
diff --git a/pitch.hh b/pitch.hh
index 402f73d..eb1327e 100644
--- a/pitch.hh
+++ b/pitch.hh
@@ -23,8 +23,9 @@ struct Tone {
struct Moment {
typedef std::list<Tone> Tones;
- Tones tones;
- double time;
+ Tones m_tones;
+ double m_time;
+ Moment(double t, Tones& tones);
};
/// A peak contains information about a single frequency
@@ -83,9 +84,9 @@ public:
/** Get the peak level in dB (negative value, 0.0 means clipping, sometimes clipping may occur at lower levels too). **/
double getLevel() const { return 10.0 * log10(m_level); }
/** Get a list of all tones detected. **/
- Tones const& getTones() const;
+ Tones const& getTones() const { return m_moments.back().m_tones; /* FIXME */ }
/** Find a tone within the singing range; prefers strong tones around 200-400 Hz. **/
- Tone const* findTone(double minfreq = 70.0, double maxfreq = 700.0) const;
+ //Tone const* findTone(double minfreq = 70.0, double maxfreq = 700.0) const;
std::string const& getId() const { return m_id; }
private:
@@ -102,6 +103,6 @@ private:
mutable double m_oldfreq;
bool calcFFT();
void calcTones();
- void mergeWithSeries(Tones const& tones);
+ void temporalMerge(Tones& tones);
};
diff --git a/pitchvis.cc b/pitchvis.cc
index 5bcca18..1fd4da7 100644
--- a/pitchvis.cc
+++ b/pitchvis.cc
@@ -69,10 +69,9 @@ PitchVis::PitchVis(std::string const& filename, QWidget *parent): QWidget(parent
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) {
- if (it->age < Tone::MINAGE) continue;
- unsigned y = freq2px(it->freqSlow);
+ unsigned y = freq2px(it->freq);
if (y == 0 || y >= height - 1) continue;
- float value = 0.003 * (level2dB(it->levelSlow) + 80.0);
+ float value = 0.003 * (level2dB(it->level) + 80.0);
if (value <= 0.0) continue;
Pixel p(0.0f, value, 0.0f);
for (int j = int(y) - 2; j <= int(y) + 2; ++j) pixel(x, j) += p;
|