summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-08-12 17:24:42 +0100
committerJohn Glover <j@johnglover.net>2012-08-12 17:24:42 +0100
commitc8b25884550c66ea00f32b9ab9ee75b4f158742f (patch)
treecde898f04ad1c00db921154b29939790f185fd13 /src
parent773e21b80a38de52ed59738a152ef34d001e4cee (diff)
downloadsimpl-c8b25884550c66ea00f32b9ab9ee75b4f158742f.tar.gz
simpl-c8b25884550c66ea00f32b9ab9ee75b4f158742f.tar.bz2
simpl-c8b25884550c66ea00f32b9ab9ee75b4f158742f.zip
[synthesis] Add C++ implementation of SndObjSynthesis.
Diffstat (limited to 'src')
-rw-r--r--src/simpl/synthesis.cpp115
-rw-r--r--src/simpl/synthesis.h34
2 files changed, 149 insertions, 0 deletions
diff --git a/src/simpl/synthesis.cpp b/src/simpl/synthesis.cpp
index 221e60e..43c30b2 100644
--- a/src/simpl/synthesis.cpp
+++ b/src/simpl/synthesis.cpp
@@ -138,3 +138,118 @@ void SMSSynthesis::synth_frame(Frame* frame) {
sms_synthesize(&_data, frame->synth(), &_synth_params);
}
+
+
+// ---------------------------------------------------------------------------
+// SndObjSynthesis
+// ---------------------------------------------------------------------------
+SimplSndObjAnalysisWrapper::SimplSndObjAnalysisWrapper(int max_partials) {
+ partials.resize(max_partials);
+}
+
+SimplSndObjAnalysisWrapper::~SimplSndObjAnalysisWrapper() {
+ partials.clear();
+}
+
+int SimplSndObjAnalysisWrapper::GetTrackID(int track) {
+ if(track < partials.size()) {
+ return track;
+ }
+ return 0;
+}
+
+int SimplSndObjAnalysisWrapper::GetTracks() {
+ return partials.size();
+}
+
+double SimplSndObjAnalysisWrapper::Output(int pos) {
+ int peak = pos / 3;
+
+ if(peak > partials.size()) {
+ return 0.0;
+ }
+
+ int data_field = pos % 3;
+
+ if(partials[peak]) {
+ if(data_field == 0) {
+ return partials[peak]->amplitude;
+ }
+ else if(data_field == 1) {
+ return partials[peak]->frequency;
+ }
+ return partials[peak]->phase;
+ }
+
+ return 0.0;
+}
+
+SndObjSynthesis::SndObjSynthesis() {
+ _analysis = NULL;
+ _table = NULL;
+ _synth = NULL;
+ reset();
+}
+
+SndObjSynthesis::~SndObjSynthesis() {
+ if(_analysis) {
+ delete _analysis;
+ }
+ if(_table) {
+ delete _table;
+ }
+ if(_synth) {
+ delete _synth;
+ }
+
+ _analysis = NULL;
+ _table = NULL;
+ _synth = NULL;
+}
+
+void SndObjSynthesis::reset() {
+ if(_analysis) {
+ delete _analysis;
+ }
+ if(_table) {
+ delete _table;
+ }
+ if(_synth) {
+ delete _synth;
+ }
+
+ _analysis = new SimplSndObjAnalysisWrapper(_max_partials);
+ _table = new HarmTable(10000, 1, 1, 0.25);
+ _synth = new AdSyn(_analysis, _max_partials, _table, 1, 1, _hop_size);
+}
+
+void SndObjSynthesis::hop_size(int new_hop_size) {
+ _hop_size = new_hop_size;
+ reset();
+}
+
+void SndObjSynthesis::max_partials(int new_max_partials) {
+ _max_partials = new_max_partials;
+ reset();
+}
+
+
+void SndObjSynthesis::synth_frame(Frame* frame) {
+ int num_partials = _max_partials;
+ if(frame->num_partials() < _max_partials) {
+ num_partials = frame->num_partials();
+ }
+
+ for(int i = 0; i < num_partials; i++) {
+ _analysis->partials[i] = frame->partial(i);
+ }
+ for(int i = num_partials; i < _max_partials; i++) {
+ _analysis->partials[i] = NULL;
+ }
+
+ _synth->DoProcess();
+
+ for(int i = 0; i < _hop_size; i++) {
+ frame->synth()[i] = _synth->Output(i);
+ }
+}
diff --git a/src/simpl/synthesis.h b/src/simpl/synthesis.h
index b3efd9c..85dd959 100644
--- a/src/simpl/synthesis.h
+++ b/src/simpl/synthesis.h
@@ -7,6 +7,11 @@ extern "C" {
#include "sms.h"
}
+#include "SndObj.h"
+#include "HarmTable.h"
+#include "SinAnal.h"
+#include "AdSyn.h"
+
using namespace std;
namespace simpl
@@ -63,6 +68,35 @@ class SMSSynthesis : public Synthesis {
};
+// ---------------------------------------------------------------------------
+// SndObjSynthesis
+// ---------------------------------------------------------------------------
+class SimplSndObjAnalysisWrapper : public SinAnal {
+ public:
+ SimplSndObjAnalysisWrapper(int max_partials);
+ ~SimplSndObjAnalysisWrapper();
+ Peaks partials;
+ int GetTrackID(int track);
+ int GetTracks();
+ double Output(int pos);
+};
+
+
+class SndObjSynthesis : public Synthesis {
+ private:
+ SimplSndObjAnalysisWrapper* _analysis;
+ HarmTable* _table;
+ AdSyn* _synth;
+ void reset();
+
+ public:
+ SndObjSynthesis();
+ ~SndObjSynthesis();
+ void hop_size(int new_hop_size);
+ void max_partials(int new_max_partials);
+ void synth_frame(Frame* frame);
+};
+
} // end of namespace Simpl
#endif