diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/simpl/partial_tracking.cpp | 98 | ||||
-rw-r--r-- | src/simpl/partial_tracking.h | 41 | ||||
-rw-r--r-- | src/simpl/peak_detection.h | 6 |
3 files changed, 141 insertions, 4 deletions
diff --git a/src/simpl/partial_tracking.cpp b/src/simpl/partial_tracking.cpp index fdafb84..42df76b 100644 --- a/src/simpl/partial_tracking.cpp +++ b/src/simpl/partial_tracking.cpp @@ -304,3 +304,101 @@ Peaks SndObjPartialTracking::update_partials(Frame* frame) { return peaks; } + +// --------------------------------------------------------------------------- +// LorisPartialTracking +// --------------------------------------------------------------------------- +SimplLorisPTAnalyzer::SimplLorisPTAnalyzer() : + Loris::Analyzer(50, 100), + _env(1.0) { + buildFundamentalEnv(false); + _partial_builder = new Loris::PartialBuilder(m_freqDrift, _env); +} + +SimplLorisPTAnalyzer::~SimplLorisPTAnalyzer() { + delete _partial_builder; +} + +void SimplLorisPTAnalyzer::analyze() { + m_ampEnvBuilder->reset(); + m_f0Builder->reset(); + m_partials.clear(); + + // estimate the amplitude in this frame: + m_ampEnvBuilder->build(peaks, 0); + + // collect amplitudes and frequencies and try to + // estimate the fundamental + m_f0Builder->build(peaks, 0); + + // form Partials from the extracted Breakpoints: + _partial_builder->buildPartials(peaks, 0); + + // unwarp the Partial frequency envelopes: + _partial_builder->finishBuilding(m_partials); +} + +// --------------------------------------------------------------------------- + +LorisPartialTracking::LorisPartialTracking() { + _analyzer = NULL; + reset(); +} + +LorisPartialTracking::~LorisPartialTracking() { + if(_analyzer) { + delete _analyzer; + } +} + +void LorisPartialTracking::reset() { + if(_analyzer) { + delete _analyzer; + } + _analyzer = new SimplLorisPTAnalyzer(); +} + +void LorisPartialTracking::max_partials(int new_max_partials) { + _max_partials = new_max_partials; + reset(); +} + +Peaks LorisPartialTracking::update_partials(Frame* frame) { + int num_peaks = frame->num_peaks(); + if(num_peaks > _max_partials) { + num_peaks = _max_partials; + } + + Peaks peaks; + + _analyzer->peaks.clear(); + for(int i = 0; i < num_peaks; i++) { + Loris::Breakpoint bp = Loris::Breakpoint(frame->peak(i)->frequency, + frame->peak(i)->amplitude, + frame->peak(i)->bandwidth, + frame->peak(i)->phase); + _analyzer->peaks.push_back(Loris::SpectralPeak(1, bp)); + } + + _analyzer->analyze(); + _partials = _analyzer->partials(); + int num_partials = _partials.size(); + + for(Loris::PartialListIterator i = _partials.begin(); i != _partials.end(); ++i) { + Peak* p = new Peak(); + p->amplitude = i->amplitudeAt(1); + p->frequency = i->frequencyAt(1); + p->phase = i->phaseAt(1); + p->bandwidth = i->bandwidthAt(1); + peaks.push_back(p); + frame->add_partial(p); + } + + for(int i = num_partials; i < _max_partials; i++) { + Peak* p = new Peak(); + peaks.push_back(p); + frame->add_partial(p); + } + + return peaks; +} diff --git a/src/simpl/partial_tracking.h b/src/simpl/partial_tracking.h index 4491b42..b9f2d28 100644 --- a/src/simpl/partial_tracking.h +++ b/src/simpl/partial_tracking.h @@ -12,6 +12,15 @@ extern "C" { #include "IFGram.h" #include "SinAnal.h" +#include "Analyzer.h" +#include "AssociateBandwidth.h" +#include "BreakpointEnvelope.h" +#include "KaiserWindow.h" +#include "PartialBuilder.h" +#include "PartialList.h" +#include "ReassignedSpectrum.h" +#include "SpectralPeakSelector.h" + using namespace std; namespace simpl @@ -72,6 +81,7 @@ class SMSPartialTracking : public PartialTracking { Peaks update_partials(Frame* frame); }; + // --------------------------------------------------------------------------- // SndObjPartialTracking // --------------------------------------------------------------------------- @@ -93,7 +103,36 @@ class SndObjPartialTracking : public PartialTracking { Peaks update_partials(Frame* frame); }; +// --------------------------------------------------------------------------- +// LorisPartialTracking +// --------------------------------------------------------------------------- +class SimplLorisPTAnalyzer : public Loris::Analyzer { + protected: + Loris::BreakpointEnvelope _env; + Loris::PartialBuilder* _partial_builder; + + public: + SimplLorisPTAnalyzer(); + ~SimplLorisPTAnalyzer(); + Loris::Peaks peaks; + void analyze(); +}; + + +class LorisPartialTracking : public PartialTracking { + private: + SimplLorisPTAnalyzer* _analyzer; + Loris::PartialList _partials; + void reset(); + + public: + LorisPartialTracking(); + ~LorisPartialTracking(); + void max_partials(int new_max_partials); + Peaks update_partials(Frame* frame); +}; + -} // end of namespace Simpl +} // end of namespace simpl #endif diff --git a/src/simpl/peak_detection.h b/src/simpl/peak_detection.h index 30c9225..398c2bf 100644 --- a/src/simpl/peak_detection.h +++ b/src/simpl/peak_detection.h @@ -13,12 +13,12 @@ extern "C" { #include "SinAnal.h" #include "Analyzer.h" +#include "AssociateBandwidth.h" +#include "BreakpointEnvelope.h" #include "KaiserWindow.h" +#include "PartialBuilder.h" #include "ReassignedSpectrum.h" #include "SpectralPeakSelector.h" -#include "PartialBuilder.h" -#include "AssociateBandwidth.h" -#include "BreakpointEnvelope.h" using namespace std; |