summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/simpl/synthesis.cpp78
-rw-r--r--src/simpl/synthesis.h31
-rw-r--r--src/sms/sms.h2
3 files changed, 107 insertions, 4 deletions
diff --git a/src/simpl/synthesis.cpp b/src/simpl/synthesis.cpp
index 168749b..9dd1131 100644
--- a/src/simpl/synthesis.cpp
+++ b/src/simpl/synthesis.cpp
@@ -51,7 +51,85 @@ void Synthesis::synth_frame(Frame* frame) {
Frames Synthesis::synth(Frames frames) {
for(int i = 0; i < frames.size(); i++) {
+ sample* synth_audio = new sample[_hop_size];
+ memset(synth_audio, 0.0, sizeof(sample) * _hop_size);
+ frames[i]->synth(synth_audio);
synth_frame(frames[i]);
}
return frames;
}
+
+
+// ---------------------------------------------------------------------------
+// SMSSynthesis
+// ---------------------------------------------------------------------------
+
+SMSSynthesis::SMSSynthesis() {
+ sms_init();
+
+ sms_initSynthParams(&_synth_params);
+ _synth_params.iSamplingRate = _sampling_rate;
+ _synth_params.iDetSynthType = SMS_DET_SIN;
+ _synth_params.iSynthesisType = SMS_STYPE_DET;
+ _synth_params.iStochasticType = SMS_STOC_NONE;
+ _synth_params.sizeHop = _hop_size;
+ _synth_params.nTracks = _max_partials;
+ _synth_params.deEmphasis = 0;
+ sms_initSynth(&_synth_params);
+
+ sms_allocFrame(&_data, _max_partials,
+ num_stochastic_coeffs(), 1,
+ stochastic_type(), 0);
+}
+
+SMSSynthesis::~SMSSynthesis() {
+ sms_freeSynth(&_synth_params);
+ sms_freeFrame(&_data);
+ sms_free();
+}
+
+void SMSSynthesis::hop_size(int new_hop_size) {
+ _hop_size = new_hop_size;
+
+ sms_freeSynth(&_synth_params);
+ _synth_params.sizeHop = _hop_size;
+ sms_initSynth(&_synth_params);
+}
+
+void SMSSynthesis::max_partials(int new_max_partials) {
+ _max_partials = new_max_partials;
+
+ sms_freeSynth(&_synth_params);
+ sms_freeFrame(&_data);
+ _synth_params.nTracks = _max_partials;
+ sms_initSynth(&_synth_params);
+ sms_allocFrame(&_data, _max_partials,
+ num_stochastic_coeffs(), 1,
+ stochastic_type(), 0);
+}
+
+int SMSSynthesis::num_stochastic_coeffs() {
+ return _synth_params.nStochasticCoeff;
+}
+
+int SMSSynthesis::stochastic_type() {
+ return _synth_params.iStochasticType;
+}
+
+int SMSSynthesis::det_synthesis_type() {
+ return _synth_params.iDetSynthType;
+}
+
+void SMSSynthesis::det_synthesis_type(int new_det_synthesis_type) {
+ _synth_params.iDetSynthType = new_det_synthesis_type;
+}
+
+void SMSSynthesis::synth_frame(Frame* frame) {
+ for(int i = 0; i < _data.nTracks; i++) {
+ _data.pFSinAmp[i] = frame->peak(i)->amplitude;
+ _data.pFSinFreq[i] = frame->peak(i)->frequency;
+ _data.pFSinPha[i] = frame->peak(i)->phase;
+ }
+
+ sms_synthesize(&_data, frame->synth(), &_synth_params);
+}
diff --git a/src/simpl/synthesis.h b/src/simpl/synthesis.h
index 43b45d0..b3efd9c 100644
--- a/src/simpl/synthesis.h
+++ b/src/simpl/synthesis.h
@@ -3,6 +3,10 @@
#include "base.h"
+extern "C" {
+ #include "sms.h"
+}
+
using namespace std;
namespace simpl
@@ -16,7 +20,7 @@ namespace simpl
// ---------------------------------------------------------------------------
class Synthesis {
- private:
+ protected:
int _frame_size;
int _hop_size;
int _max_partials;
@@ -27,9 +31,9 @@ class Synthesis {
int frame_size();
void frame_size(int new_frame_size);
int hop_size();
- void hop_size(int new_hop_size);
+ virtual void hop_size(int new_hop_size);
int max_partials();
- void max_partials(int new_max_partials);
+ virtual void max_partials(int new_max_partials);
int sampling_rate();
void sampling_rate(int new_sampling_rate);
@@ -38,6 +42,27 @@ class Synthesis {
};
+// ---------------------------------------------------------------------------
+// SMSSynthesis
+// ---------------------------------------------------------------------------
+class SMSSynthesis : public Synthesis {
+ private:
+ SMSSynthParams _synth_params;
+ SMSData _data;
+
+ public:
+ SMSSynthesis();
+ ~SMSSynthesis();
+ void hop_size(int new_hop_size);
+ void max_partials(int new_max_partials);
+ int num_stochastic_coeffs();
+ int stochastic_type();
+ int det_synthesis_type();
+ void det_synthesis_type(int new_det_synthesis_type);
+ void synth_frame(Frame* frame);
+};
+
+
} // end of namespace Simpl
#endif
diff --git a/src/sms/sms.h b/src/sms/sms.h
index 14399fc..7372a8a 100644
--- a/src/sms/sms.h
+++ b/src/sms/sms.h
@@ -320,7 +320,7 @@ typedef struct
* synthesized frame.
*
*/
-typedef struct
+typedef struct SMSSynthParams
{
int iStochasticType; /*!< type of stochastic model defined by SMS_StocSynthType
\see SMS_StocSynthType */