diff options
-rw-r--r-- | sndobj.py | 24 | ||||
-rw-r--r-- | sndobj/AdSyn.cpp | 181 |
2 files changed, 101 insertions, 104 deletions
@@ -144,31 +144,31 @@ class SimplSndObjAnalysisWrapper(simplsndobj.SinAnal): data to the SndObj synthesis objects.""" def __init__(self): simplsndobj.SinAnal.__init__(self) - self.peaks = [] + self.partials = [] def GetTracks(self): - return len(self.peaks) + return len(self.partials) def GetTrackID(self, partial_number): - if partial_number < len(self.peaks): - return self.peaks[partial_number].partial_id + if partial_number < len(self.partials): + return partial_number else: # TODO: what should this return if no matching partial found? return 0 def Output(self, position): peak = int(position) / 3 - if peak > len(self.peaks): + if peak > len(self.partials): # TODO: what should this return if no matching partial found? return 0.0 data_field = int(position) % 3 if data_field is 0: - return self.peaks[peak].amplitude + return self.partials[peak].amplitude elif data_field is 1: - return self.peaks[peak].frequency + return self.partials[peak].frequency elif data_field is 2: - return self.peaks[peak].phase + return self.partials[peak].phase class SndObjSynthesis(simpl.Synthesis): @@ -196,11 +196,11 @@ class SndObjSynthesis(simpl.Synthesis): self._synth.Set('max tracks', num_partials) self._max_partials = num_partials - def synth_frame(self, peaks): + def synth_frame(self, frame): "Synthesises a frame of audio, given a list of peaks from tracks" - self._analysis.peaks = peaks - if len(peaks) > self._max_partials: - self.max_partials = len(peaks) + self._analysis.partials = frame.partials + if len(frame.partials) > self._max_partials: + self.max_partials = len(frame.partials) self._synth.DoProcess() self._synth.PopOut(self._current_frame) return self._current_frame diff --git a/sndobj/AdSyn.cpp b/sndobj/AdSyn.cpp index 28fa209..5b1a514 100644 --- a/sndobj/AdSyn.cpp +++ b/sndobj/AdSyn.cpp @@ -1,4 +1,4 @@ - + //////////////////////////////////////////////////////////////////////// // This file is part of the SndObj library // @@ -26,104 +26,101 @@ AdSyn::AdSyn(){ } AdSyn::AdSyn(SinAnal* input, int maxtracks, Table* table, - double pitch, double scale, int vecsize, double sr) - :ReSyn(input, maxtracks, table, pitch, scale, 1.f, vecsize, sr){ + double pitch, double scale, int vecsize, double sr) + :ReSyn(input, maxtracks, table, pitch, scale, 1.f, vecsize, sr){ } AdSyn::~AdSyn(){ } short -AdSyn::DoProcess() { - - if(m_input){ - - double ampnext,amp,freq,freqnext,phase; - int i3, i, j, ID, track; - int notcontin = 0; - bool contin = false; - int oldtracks = m_tracks; - 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 each track - i = j = 0; - while(i < m_tracks*3){ - - i3 = i/3; - ampnext = m_input->Output(i)*m_scale; - freqnext = m_input->Output(i+1)*m_pitch; - ID = ((SinAnal *)m_input)->GetTrackID(i3); +AdSyn::DoProcess(){ + if(m_input){ + double ampnext,amp,freq,freqnext,phase; + int i3, i, j, ID, track; + int notcontin = 0; + bool contin = false; + int oldtracks = m_tracks; + 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 each track + i = j = 0; + while(i < m_tracks*3){ + i3 = i/3; + ampnext = m_input->Output(i)*m_scale; + 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(i3 < oldtracks-notcontin){ + if(m_trackID[j]==ID){ + // if this is a continuing track + track = j; + contin = true; + freq = m_freqs[track]; + phase = m_phases[track]; + amp = m_amps[track]; + } + else{ + // if this is a dead track + contin = false; + track = j; + freqnext = freq = m_freqs[track]; + phase = m_phases[track]; + amp = m_amps[track]; + ampnext = 0.f; + } + } + else{ + // new tracks + contin = true; + track = -1; + freq = freqnext; + phase = -freq*m_factor; + amp = 0.f; + } - if(m_trackID[j]==ID){ - // if this is a continuing track - track = j; - contin = true; - freq = m_freqs[track]; - phase = m_phases[track]; - amp = m_amps[track]; - } - else { - // if this is a dead track - contin = false; - track = j; - freqnext = freq = m_freqs[track]; - phase = m_phases[track]; - amp = m_amps[track]; - ampnext = 0.f; - } - } - else{ - // new tracks - contin = true; - track = -1; - freq = freqnext; - phase = -freq*m_factor; - amp = 0.f; - } - - // 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; - } + // 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 - if(contin){ - m_amps[i3] = ampnext; - m_freqs[i3] = freqnext; - m_phases[i3] = phase; - m_trackID[i3] = ID; - i += 3; - } else notcontin++; - } - return 1; - } - else { - m_error = 1; - return 0; - } - + // keep amp, freq, and phase values for next time + if(contin){ + m_amps[i3] = ampnext; + m_freqs[i3] = freqnext; + m_phases[i3] = phase; + m_trackID[i3] = ID; + i += 3; + } + else notcontin++; + } + return 1; + } + else{ + m_error = 1; + return 0; + } } |