From 22a0bd8b5142568b015a6fa25e9b0de1540ea47a Mon Sep 17 00:00:00 2001 From: amartin Date: Thu, 16 Aug 2007 07:32:41 +0000 Subject: merge --- (limited to 'Util') diff --git a/Util/CSoundClient.py b/Util/CSoundClient.py index 0a10d21..8cc9ec2 100644 --- a/Util/CSoundClient.py +++ b/Util/CSoundClient.py @@ -26,7 +26,8 @@ class _CSoundClientPlugin: ATTACK, \ DECAY, \ FILTERTYPE, \ - FILTERCUTOFF ) = range(12) + FILTERCUTOFF, \ + INSTRUMENT2 ) = range(13) def __init__(self): sc_initialize( Config.PLUGIN_UNIVORC, Config.PLUGIN_DEBUG, @@ -204,9 +205,12 @@ class _CSoundClientPlugin: sc_loop_updateEvent( (page<<16)+id, self.FILTERTYPE, value, cmd) elif (parameter == NoteDB.PARAMETER.FILTERCUTOFF): sc_loop_updateEvent( (page<<16)+id, self.FILTERCUTOFF, value, cmd) + elif (parameter == NoteDB.PARAMETER.INSTRUMENT2): + sc_loop_updateEvent( (page<<16)+id, self.INSTRUMENT2, value, cmd) else: if (Config.DEBUG > 0): print 'ERROR: loopUpdate(): unsupported parameter change' + def loopPlay(self, dbnote, active): qid = (dbnote.page << 16) + dbnote.id sc_loop_addScoreEvent( qid, 1, active, 'i', self.csnote_to_array(dbnote.cs)) @@ -233,7 +237,8 @@ class _CSoundClientPlugin: csnote.filterCutoff, csnote.tied, csnote.instrumentId, - csnote.mode) + csnote.mode, + csnote.instrumentId2 ) def csnote_to_array1( self, onset, pitch, @@ -248,7 +253,8 @@ class _CSoundClientPlugin: filterCutoff = 1000, tied = False, instrumentId = Config.INSTRUMENTS["flute"].instrumentId, - mode = 'edit' ): + mode = 'edit', + instrumentId2 = -1 ): instrument = Config.INSTRUMENTSID[instrumentId] if instrument.kit != None: @@ -281,6 +287,14 @@ class _CSoundClientPlugin: instrument_id_offset = 0 else: instrument_id_offset = 100 + + if instrumentId2 != -1: + instrument2 = Config.INSTRUMENTSID[instrumentId2] + csInstrumentId2 = (instrument2.csoundInstrumentId + 100) * 0.0001 + secondInstrument = Config.INSTRUMENT_TABLE_OFFSET + instrumentId2 + csInstrumentId2 + else: + secondInstrument = -1 + a = array.array('f') a.extend( [ (instrument.csoundInstrumentId + (trackId+1) + instrument_id_offset) + trackId * 0.01, @@ -297,7 +311,8 @@ class _CSoundClientPlugin: filterCutoff, instrument.loopStart, instrument.loopEnd, - instrument.crossDur ]) + instrument.crossDur, + secondInstrument ]) return a diff --git a/Util/CSoundNote.py b/Util/CSoundNote.py index d41fc11..7b2019e 100644 --- a/Util/CSoundNote.py +++ b/Util/CSoundNote.py @@ -1,23 +1,23 @@ import Config -from Generation.GenerationConstants import GenerationConstants class CSoundNote : def __init__( self, - onset, - pitch, - amplitude, - pan, - duration, - trackId, - instrumentId = Config.INSTRUMENTS["flute"].instrumentId, - attack = 0.002, - decay = 0.098, - reverbSend = 0.1, - filterType = 0, + onset, + pitch, + amplitude, + pan, + duration, + trackId, + instrumentId = Config.INSTRUMENTS["flute"].instrumentId, + attack = 0.005, + decay = 0.098, + reverbSend = 0.1, + filterType = 0, filterCutoff = 1000, tied = False, - mode = 'edit' ): - + mode = 'edit', + instrumentId2 = -1 ): + self.onset = onset self.pitch = pitch self.amplitude = amplitude @@ -34,6 +34,14 @@ class CSoundNote : self.filterCutoff = filterCutoff self.tied = tied self.mode = mode + self.instrumentId2 = instrumentId2 + + def clone( self ): + return CSoundNote( self.onset, self.pitch, self.amplitude, self.pan, + self.duration, self.trackId, self.instrumentId, + self.attack, self.decay, self.reverbSend, + self.filterType, self.filterCutoff, self.tied, + self.mode, self.instrumentId2 ) def __getstate__unused(self): return {'onset': self.onset, @@ -67,13 +75,3 @@ class CSoundNote : self.tied = dict['tied'] self.mode = dict['mode'] self.nchanges = 0 - - def clone( self ): - return CSoundNote( self.onset, self.pitch, self.amplitude, self.pan, - self.duration, self.trackId, self.instrumentId, - self.attack, self.decay, self.reverbSend, - self.filterType, self.filterCutoff, self.tied, - self.mode ) - - - diff --git a/Util/Clooper/aclient.cpp b/Util/Clooper/aclient.cpp index baa7419..1755438 100644 --- a/Util/Clooper/aclient.cpp +++ b/Util/Clooper/aclient.cpp @@ -30,6 +30,7 @@ static double pytime(const struct timeval * tv) #define ERROR_HERE if (_debug && (VERBOSE > 0)) fprintf(_debug, "ERROR: %s:%i\n", __FILE__, __LINE__) #define IF_DEBUG(N) if (_debug && (VERBOSE > N)) +#define FLOAT_TO_SHORT(in,out) __asm__ __volatile__ ("fistps %0" : "=m" (out) : "t" (in) : "st") ; int VERBOSE = 3; FILE * _debug = NULL; @@ -472,11 +473,11 @@ struct TamTamSound return 1; } - assert(up_ratio = sys_stuff->rate / csound_frame_rate); + assert(up_ratio == (signed)(sys_stuff->rate / csound_frame_rate)); bool do_upsample = (signed)sys_stuff->period_size != csound_nframes; - float *upbuf = do_upsample ? new float[ sys_stuff->period_size * nchannels ]: NULL; //2 channels - int cbuf_pos = csound_nframes; + short *upbuf = new short[ sys_stuff->period_size * nchannels ]; + int cbuf_pos = csound_nframes; // trigger a call to csoundPerformBuffer immediately float *cbuf = NULL; int up_pos = 0; int ratio_pos = 0; @@ -487,6 +488,7 @@ struct TamTamSound { up_pos = 0; int messed = 0; + short cursample[2]={0,0}; while(!messed) { if (cbuf_pos == csound_nframes) @@ -495,13 +497,17 @@ struct TamTamSound if (csoundPerformBuffer(csound)) { messed = 1;break;} cbuf = csoundGetOutputBuffer(csound); } - upbuf[2*up_pos+0] = cbuf[cbuf_pos*2+0]; - upbuf[2*up_pos+1] = cbuf[cbuf_pos*2+1]; + upbuf[2*up_pos+0] = cursample[0]; + upbuf[2*up_pos+1] = cursample[1]; if (++ratio_pos == up_ratio) { ratio_pos = 0; ++cbuf_pos; + cbuf[cbuf_pos*2+0] *= (float) ((1<<15)-100.0f); + cbuf[cbuf_pos*2+1] *= (float) ((1<<15)-100.0f); + FLOAT_TO_SHORT( cbuf[cbuf_pos*2+0], cursample[0]); + FLOAT_TO_SHORT( cbuf[cbuf_pos*2+1], cursample[1]); } if (++up_pos == (signed)sys_stuff->period_size) break; @@ -512,9 +518,14 @@ struct TamTamSound } else //fill one period of audio directly from csound { - //if (0 > sys_stuff->readbuf((char*)csoundGetInputBuffer(csound))) break; if (csoundPerformBuffer(csound)) break; - if (0 > sys_stuff->writebuf(csound_nframes,csoundGetOutputBuffer(csound))) break; + cbuf = csoundGetOutputBuffer(csound); + for (int i = 0; i < csound_nframes * nchannels; ++i) + { + cbuf[i] *= (float) ((1<<15)-100.0f); + FLOAT_TO_SHORT( cbuf[i], upbuf[i]); + } + if (0 > sys_stuff->writebuf(csound_nframes,upbuf)) break; } if (thread_playloop) @@ -533,7 +544,7 @@ struct TamTamSound } sys_stuff->close(1); - if (do_upsample) delete [] upbuf; + delete [] upbuf; ll->printf(2, "INFO: performance thread returning 0\n"); return 0; } diff --git a/Util/Clooper/aclient.so b/Util/Clooper/aclient.so index b089412..97c9cbb 100755 --- a/Util/Clooper/aclient.so +++ b/Util/Clooper/aclient.so Binary files differ diff --git a/Util/Clooper/audio.cpp b/Util/Clooper/audio.cpp index 0d901e6..e93ea54 100644 --- a/Util/Clooper/audio.cpp +++ b/Util/Clooper/audio.cpp @@ -45,7 +45,8 @@ struct SystemStuff snd_pcm_t *phandle; snd_pcm_uframes_t period_size; unsigned int rate; - SystemStuff(log_t * ll) : ll(ll), phandle(NULL), period_size(0), rate(0) + const snd_pcm_format_t sample_format; + SystemStuff(log_t * ll) : ll(ll), phandle(NULL), period_size(0), rate(0), sample_format(SND_PCM_FORMAT_S16) { } ~SystemStuff() @@ -95,8 +96,8 @@ struct SystemStuff if ( 0 > snd_pcm_hw_params_set_rate_resample(phandle, hw, 0)) { ERROR_HERE; goto open_error;} if ( 0 > snd_pcm_hw_params_test_access(phandle, hw, SND_PCM_ACCESS_RW_INTERLEAVED)){ ERROR_HERE; goto open_error;} if ( 0 > snd_pcm_hw_params_set_access(phandle, hw, SND_PCM_ACCESS_RW_INTERLEAVED)){ ERROR_HERE; goto open_error;} - if ( 0 > snd_pcm_hw_params_test_format(phandle, hw, SND_PCM_FORMAT_FLOAT)) { ERROR_HERE; goto open_error;} - if ( 0 > snd_pcm_hw_params_set_format(phandle, hw, SND_PCM_FORMAT_FLOAT)) { ERROR_HERE; goto open_error;} + if ( 0 > snd_pcm_hw_params_test_format(phandle, hw, sample_format)) { ERROR_HERE; goto open_error;} + if ( 0 > snd_pcm_hw_params_set_format(phandle, hw, sample_format)) { ERROR_HERE; goto open_error;} if ( 0 > snd_pcm_hw_params_set_channels(phandle, hw, 2)) { ERROR_HERE; goto open_error;} if ( snd_pcm_hw_params_test_rate(phandle, hw, rate, 0)) @@ -181,7 +182,7 @@ open_error: } if (0 > snd_pcm_prepare(phandle)) { ERROR_HERE; } } - int writebuf(snd_pcm_uframes_t frame_count, float * frame_data) + int writebuf(snd_pcm_uframes_t frame_count, short int * frame_data) { if (!phandle) { diff --git a/Util/NoteDB.py b/Util/NoteDB.py index f6ec5de..d334670 100644 --- a/Util/NoteDB.py +++ b/Util/NoteDB.py @@ -14,8 +14,9 @@ class PARAMETER: ATTACK, \ DECAY, \ FILTERTYPE, \ - FILTERCUTOFF \ - = range(13) #python-stye enum + FILTERCUTOFF, \ + INSTRUMENT2 \ + = range(14) #python-stye enum class Note: def __init__( self, page, track, id, cs ): @@ -30,7 +31,7 @@ class Page: self.ticks = beats*Config.TICKS_PER_BEAT self.color = color - + if not instruments: self.instruments = [ Config.INSTRUMENTS["kalimba"].instrumentId for i in range(Config.NUMBER_OF_TRACKS-1) ] + [ Config.INSTRUMENTS["drum1kit"].instrumentId ] else: @@ -213,7 +214,7 @@ class NoteDB: i += 1 self.tune = self.tune[:at] + sorted + self.tune[at:] - + #self._updateBeatsBefore( low ) for l in self.pageListeners: @@ -242,9 +243,9 @@ class NoteDB: self.deleteNotes( dstream + [-1] ) if len(ustream): self.updateNotes( ustream + [-1] ) - + self.pages[page].beats = value - self.pages[page].ticks = ticks + self.pages[page].ticks = ticks #self._updateBeatsBefore(self.tune.index(page)) elif parameter == PARAMETER.PAGE_COLOR: self.pages[page].color = value @@ -302,7 +303,7 @@ class NoteDB: # for i in range(ind, len(self.tune)): # self.beatsBefore[self.tune[ind]] = beats # beats += self.pages[self.tune[ind]].beats - + #======================================================= @@ -482,6 +483,8 @@ class NoteDB: self.noteD[page][track][id].cs.filterType = value elif parameter == PARAMETER.FILTERCUTOFF: self.noteD[page][track][id].cs.filterCutoff = value + elif parameter == PARAMETER.INSTRUMENT2: + self.noteD[page][track][id].cs.instrumentId2 = value for par in self.parasiteList.keys(): self.parasiteD[page][track][par][id].updateParameter( parameter, value ) -- cgit v0.9.1