diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/simpl/base.cpp | 22 | ||||
-rw-r--r-- | src/simpl/base.h | 4 | ||||
-rw-r--r-- | src/simpl/synthesis.cpp | 13 | ||||
-rw-r--r-- | src/simpl/synthesis.h | 4 | ||||
-rw-r--r-- | src/sndobj/AdSyn.cpp | 95 | ||||
-rw-r--r-- | src/sndobj/AdSyn.h | 13 | ||||
-rw-r--r-- | src/sndobj/SinSyn.cpp | 37 |
7 files changed, 131 insertions, 57 deletions
diff --git a/src/simpl/base.cpp b/src/simpl/base.cpp index 2377c01..8086143 100644 --- a/src/simpl/base.cpp +++ b/src/simpl/base.cpp @@ -139,6 +139,21 @@ void Frame::destroy_arrays() { delete [] _synth_residual; } +void Frame::clear() { + clear_peaks(); + clear_partials(); +} + +void Frame::clear_peaks() { + _peaks.clear(); + _num_peaks = 0; +} + +void Frame::clear_partials() { + _partials.clear(); + _num_partials = 0; +} + // Frame - peaks // ------------- @@ -177,13 +192,6 @@ void Frame::peak(int peak_number, Peak* peak) { _peaks[peak_number] = peak; } -void Frame::clear() { - _peaks.clear(); - _partials.clear(); - _num_peaks = 0; - _num_partials = 0; -} - // Frame - partials // ---------------- diff --git a/src/simpl/base.h b/src/simpl/base.h index 040e199..8d7138c 100644 --- a/src/simpl/base.h +++ b/src/simpl/base.h @@ -100,6 +100,9 @@ class Frame { Frame(); Frame(int frame_size, bool alloc_memory=false); ~Frame(); + void clear(); + void clear_peaks(); + void clear_partials(); // peaks int num_peaks(); @@ -109,7 +112,6 @@ class Frame { void add_peak(Peak* peak); Peak* peak(int peak_number); void peak(int peak_number, Peak* peak); - void clear(); // partials int num_partials(); diff --git a/src/simpl/synthesis.cpp b/src/simpl/synthesis.cpp index 43c30b2..25312cc 100644 --- a/src/simpl/synthesis.cpp +++ b/src/simpl/synthesis.cpp @@ -51,9 +51,10 @@ 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); + sample* synth_audio = new sample[_frame_size]; + memset(synth_audio, 0.0, sizeof(sample) * _frame_size); frames[i]->synth(synth_audio); + frames[i]->synth_size(_frame_size); synth_frame(frames[i]); } return frames; @@ -220,7 +221,12 @@ void SndObjSynthesis::reset() { _analysis = new SimplSndObjAnalysisWrapper(_max_partials); _table = new HarmTable(10000, 1, 1, 0.25); - _synth = new AdSyn(_analysis, _max_partials, _table, 1, 1, _hop_size); + _synth = new SimplAdSyn(_analysis, _max_partials, _table, 1, 1, _frame_size); +} + +void SndObjSynthesis::frame_size(int new_frame_size) { + _frame_size = new_frame_size; + reset(); } void SndObjSynthesis::hop_size(int new_hop_size) { @@ -233,7 +239,6 @@ void SndObjSynthesis::max_partials(int new_max_partials) { reset(); } - void SndObjSynthesis::synth_frame(Frame* frame) { int num_partials = _max_partials; if(frame->num_partials() < _max_partials) { diff --git a/src/simpl/synthesis.h b/src/simpl/synthesis.h index 85dd959..456b4e4 100644 --- a/src/simpl/synthesis.h +++ b/src/simpl/synthesis.h @@ -34,7 +34,7 @@ class Synthesis { public: Synthesis(); int frame_size(); - void frame_size(int new_frame_size); + virtual void frame_size(int new_frame_size); int hop_size(); virtual void hop_size(int new_hop_size); int max_partials(); @@ -86,7 +86,7 @@ class SndObjSynthesis : public Synthesis { private: SimplSndObjAnalysisWrapper* _analysis; HarmTable* _table; - AdSyn* _synth; + SimplAdSyn* _synth; void reset(); public: diff --git a/src/sndobj/AdSyn.cpp b/src/sndobj/AdSyn.cpp index 5b1a514..412a350 100644 --- a/src/sndobj/AdSyn.cpp +++ b/src/sndobj/AdSyn.cpp @@ -14,7 +14,7 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // Copyright (c)Victor Lazzarini, 1997-2004 // See License.txt for a disclaimer of all warranties @@ -26,7 +26,7 @@ AdSyn::AdSyn(){ } AdSyn::AdSyn(SinAnal* input, int maxtracks, Table* table, - double pitch, double scale, int vecsize, double sr) + double pitch, double scale, int vecsize, double sr) :ReSyn(input, maxtracks, table, pitch, scale, 1.f, vecsize, sr){ } @@ -41,7 +41,7 @@ AdSyn::DoProcess(){ int notcontin = 0; bool contin = false; int oldtracks = m_tracks; - double* tab = m_ptable->GetTable(); + double* tab = m_ptable->GetTable(); if((m_tracks = ((SinAnal *)m_input)->GetTracks()) > m_maxtracks){ m_tracks = m_maxtracks; } @@ -52,16 +52,16 @@ AdSyn::DoProcess(){ while(i < m_tracks*3){ i3 = i/3; ampnext = m_input->Output(i)*m_scale; - freqnext = m_input->Output(i+1)*m_pitch; + freqnext = m_input->Output(i+1)*m_pitch; ID = ((SinAnal *)m_input)->GetTrackID(i3); - j = i3+notcontin; + j = i3+notcontin; if(i3 < oldtracks-notcontin){ - if(m_trackID[j]==ID){ - // if this is a continuing track + if(m_trackID[j]==ID){ + // if this is a continuing track track = j; - contin = true; + contin = true; freq = m_freqs[track]; phase = m_phases[track]; amp = m_amps[track]; @@ -72,11 +72,11 @@ AdSyn::DoProcess(){ track = j; freqnext = freq = m_freqs[track]; phase = m_phases[track]; - amp = m_amps[track]; + amp = m_amps[track]; ampnext = 0.f; } - } - else{ + } + else{ // new tracks contin = true; track = -1; @@ -93,7 +93,7 @@ AdSyn::DoProcess(){ incra = (ampnext - amp)/m_vecsize; incrph = (freqnext - freq)/m_vecsize; for(m_vecpos=0; m_vecpos < m_vecsize; m_vecpos++){ - if(m_enable) { + if(m_enable) { // table lookup oscillator phase += f*m_ratio; while(phase < 0) phase += m_size; @@ -104,7 +104,7 @@ AdSyn::DoProcess(){ a += incra; f += incrph; } - else m_output[m_vecpos] = 0.f; + else m_output[m_vecpos] = 0.f; } // keep amp, freq, and phase values for next time @@ -112,11 +112,74 @@ AdSyn::DoProcess(){ m_amps[i3] = ampnext; m_freqs[i3] = freqnext; m_phases[i3] = phase; - m_trackID[i3] = ID; + m_trackID[i3] = ID; i += 3; - } + } else notcontin++; - } + } + return 1; + } + else{ + m_error = 1; + return 0; + } +} + +SimplAdSyn::SimplAdSyn(){ +} + +SimplAdSyn::SimplAdSyn(SinAnal* input, int maxtracks, Table* table, + double pitch, double scale, int vecsize, double sr) + :AdSyn(input, maxtracks, table, pitch, scale, vecsize, sr){ +} + +SimplAdSyn::~SimplAdSyn(){ +} + +short +SimplAdSyn::DoProcess(){ + if(m_input){ + double ampnext, amp, freq, freqnext, phase; + double* tab = m_ptable->GetTable(); + if((m_tracks = ((SinAnal *)m_input)->GetTracks()) > m_maxtracks){ + m_tracks = m_maxtracks; + } + memset(m_output, 0, sizeof(double)*m_vecsize); + + for(int track = 0; track < m_tracks; track++){ + ampnext = m_input->Output(track * 3) * m_scale; + freqnext = m_input->Output((track * 3) + 1) * m_pitch; + freq = m_freqs[track]; + phase = m_phases[track]; + amp = m_amps[track]; + + // interpolation & track synthesis loop + double a, f, frac, incra, incrph; + int ndx; + a = amp; + f = freq; + incra = (ampnext - amp) / m_vecsize; + incrph = (freqnext - freq) / m_vecsize; + for(m_vecpos=0; m_vecpos < m_vecsize; m_vecpos++){ + if(m_enable) { + // table lookup oscillator + phase += f * m_ratio; + while(phase < 0) phase += m_size; + while(phase >= m_size) phase -= m_size; + ndx = Ftoi(phase); + frac = phase - ndx; + m_output[m_vecpos] += a*(tab[ndx] + (tab[ndx+1] - tab[ndx])*frac); + a += incra; + f += incrph; + } + else m_output[m_vecpos] = 0.f; + } + + // keep amp, freq, and phase values for next time + m_amps[track] = ampnext; + m_freqs[track] = freqnext; + m_phases[track] = phase; + } return 1; } else{ diff --git a/src/sndobj/AdSyn.h b/src/sndobj/AdSyn.h index 1d62d01..089e3b1 100644 --- a/src/sndobj/AdSyn.h +++ b/src/sndobj/AdSyn.h @@ -26,9 +26,7 @@ #include "ReSyn.h" class AdSyn : public ReSyn { - public: - AdSyn(); AdSyn(SinAnal* input, int maxtracks, Table* table, double pitch = 1.f, double scale=1.f, @@ -37,4 +35,15 @@ class AdSyn : public ReSyn { short DoProcess(); }; + +class SimplAdSyn : public AdSyn { + public: + SimplAdSyn(); + SimplAdSyn(SinAnal* input, int maxtracks, Table* table, + double pitch = 1.f, double scale=1.f, + int vecsize=DEF_VECSIZE, double sr=DEF_SR); + ~SimplAdSyn(); + short DoProcess(); +}; + #endif diff --git a/src/sndobj/SinSyn.cpp b/src/sndobj/SinSyn.cpp index 7d31e15..e91ed16 100644 --- a/src/sndobj/SinSyn.cpp +++ b/src/sndobj/SinSyn.cpp @@ -23,7 +23,6 @@ #include "SinSyn.h" SinSyn::SinSyn(){ - m_factor = m_vecsize/m_sr; m_facsqr = m_factor*m_factor; m_ptable = 0; @@ -45,7 +44,6 @@ SinSyn::SinSyn(){ SinSyn::SinSyn(SinAnal* input, int maxtracks, Table* table, double scale, int vecsize, double sr) :SndObj(input, vecsize, sr){ - m_ptable = table; m_size = m_ptable->GetLen(); m_LoTWOPI = m_size/TWOPI; @@ -61,7 +59,10 @@ SinSyn::SinSyn(SinAnal* input, int maxtracks, Table* table, m_phases = new double[m_maxtracks]; m_trackID = new int[m_maxtracks]; - memset(m_phases, 0, sizeof(double)*m_maxtracks); + memset(m_freqs, 0, sizeof(double) * m_maxtracks); + memset(m_amps, 0, sizeof(double) * m_maxtracks); + memset(m_phases, 0, sizeof(double) * m_maxtracks); + memset(m_trackID, 0, sizeof(int) * m_maxtracks); m_incr = 0.f; m_ratio = m_size/m_sr; @@ -70,21 +71,17 @@ SinSyn::SinSyn(SinAnal* input, int maxtracks, Table* table, AddMsg("table", 24); AddMsg("timescale", 24); memset(m_trackID, 0, sizeof(int)); - } SinSyn::~SinSyn(){ - delete[] m_freqs; delete[] m_amps; delete[] m_phases; delete[] m_trackID; - } - void -SinSyn::SetTable(Table *table) -{ +void +SinSyn::SetTable(Table *table){ m_ptable = table; m_size = m_ptable->GetLen(); m_LoTWOPI = m_size/TWOPI; @@ -93,26 +90,19 @@ SinSyn::SetTable(Table *table) int SinSyn::Connect(char* mess, void* input){ - switch (FindMsg(mess)){ - case 24: SetTable((Table *) input); return 1; default: return SndObj::Connect(mess,input); - } - } - int SinSyn::Set(char* mess, double value){ - switch(FindMsg(mess)){ - case 21: SetMaxTracks((int)value); return 1; @@ -123,36 +113,34 @@ SinSyn::Set(char* mess, double value){ default: return SndObj::Set(mess, value); - } } - void SinSyn::SetMaxTracks(int maxtracks){ - if(m_maxtracks){ - delete[] m_freqs; delete[] m_amps; delete[] m_phases; delete[] m_trackID; - } m_maxtracks = maxtracks; + m_freqs = new double[m_maxtracks]; m_amps = new double[m_maxtracks]; m_phases = new double[m_maxtracks]; m_trackID = new int[m_maxtracks]; + memset(m_freqs, 0, sizeof(double) * m_maxtracks); + memset(m_amps, 0, sizeof(double) * m_maxtracks); + memset(m_phases, 0, sizeof(double) * m_maxtracks); + memset(m_trackID, 0, sizeof(int) * m_maxtracks); } short -SinSyn::DoProcess() { - +SinSyn::DoProcess(){ if(m_input){ - double ampnext,amp,freq, freqnext, phase,phasenext; double a2, a3, phasediff, cph; int i3, i, j, ID, track; @@ -265,4 +253,3 @@ SinSyn::DoProcess() { } } - |