summaryrefslogtreecommitdiff
path: root/src/sndobj
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-08-23 16:19:11 +0100
committerJohn Glover <j@johnglover.net>2012-08-23 16:19:11 +0100
commite160337c4e45c53772f2c311aef1a7429e73ab51 (patch)
tree4be6df6a5bc63d0ac54bb3d07f381445b0359ad1 /src/sndobj
parente4ab5141d33d0c94a1c82091a02cfc7ecffc65fd (diff)
downloadsimpl-e160337c4e45c53772f2c311aef1a7429e73ab51.tar.gz
simpl-e160337c4e45c53772f2c311aef1a7429e73ab51.tar.bz2
simpl-e160337c4e45c53772f2c311aef1a7429e73ab51.zip
[sndobj] Fix bug in SndObjSynthesis. Partial IDs were not being handled correctly, added new class based on AdSyn that does not rely on IDs.
Diffstat (limited to 'src/sndobj')
-rw-r--r--src/sndobj/AdSyn.cpp95
-rw-r--r--src/sndobj/AdSyn.h13
-rw-r--r--src/sndobj/SinSyn.cpp37
3 files changed, 102 insertions, 43 deletions
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() {
}
}
-