def setUpClass(self): self.initialData = { "string": "mydata", "number": 1956.2705, "boolean": True } self.cs = ctcsound.Csound(self.initialData)
def initOpcodes(self): '''Read the list of csound opcodes from Csound API. Thus we're sure that the opcode list is up to date, however it will be complete only if csound has been built with all the plugins. It is needed to compile an orchestra and score before calling CsoundOpcodeList() in order to get the opcode list. So we use a dummy csd string for that purpose (tricky isn't it?) ''' cs = ctcsound.Csound() dummy = '''<CsoundSynthesizer> <CsOptions> -dodac </CsOptions> <CsInstruments> instr 1 print p3 endin </CsInstruments> <CsScore> i1 0 1 e </CsScore> </CsoundSynthesizer>''' cs.compileCsdText("dummy.csd") lo, n = cs.newOpcodeList() print("{} opcodes registered".format(n)) for i in range(n): self[lo[i].opname] = 'opc' del cs
def __init__(self, debug=False): self.k = 0 self.cs = ctcsound.Csound() self.csd = None self.debug = debug if not self.debug: self.cs.setOption("--nodisplays")
def perform(orc, score, create_wav=False, wav_file='output.wav'): """ Inputs: * orc: csound orchestra in a string * score: csound score in a string * create_wav: boolean setting for if running this function will create an output wav file. Default False. * wav_file: file name for output wav file. Default 'output.wav'. Function reads input orc and score and plays the corresponding csound composition. It generates the corresponding wav file if create_wav is True. """ c = ctcsound.Csound() c.setOption("-odac") if (create_wav): output_file_flag = '-o ' + wav_file c.setOption(output_file_flag) # prepare the inputs c.compileOrc(orc) c.readScore(score) # performance c.start() c.perform() c.reset()
def __init__(self, duration, instrument, synthesis_parms, gesture_rate): self.duration = duration self.synthesis_parms = synthesis_parms # numpy array with size 10 for the instr submono # settings print(instrument) #set up csound self.cs = ctcsound.Csound() self.filename = '{}.wav'.format(datetime.now().strftime("%d-%m-%Y-%H-%M-%S-%f")) self.cs.setOption('-o/shape/sounds/{}'.format(self.filename)) #use for saving all audio files (can fill up disk quickly) self.cs.setOption('-m0') self.cs.setOption('-d') orcfile = open('/shape/synth/shape.orc', 'r') orc = orcfile.read() orcfile.close() self.cs.compileOrc(orc) self.cs.readScore("f0 .1") self.cs.start() instruments = ['sine', 'submono', 'additive', 'partikkel'] synthinstr = instruments.index(instrument) + 20 self.cs.inputMessage('''i{} 0 {} {}'''.format(synthinstr, duration, PITCH_OVERRIDE))#run synth self.cs.inputMessage('''i{} 0 {}'''.format(30, duration))#run analyzer self.parmtable = int(self.cs.controlChannel("parmvalue_table")[0]) self.analysistable = int(self.cs.controlChannel("analysis_table")[0]) self.analysis_values = self.cs.table(self.analysistable) # read analysis parameters from here # for downsampling analysis data to match gesture data ratio: self.gesture_rate = gesture_rate self.upsamp_ratio = (self.cs.sr()/self.gesture_rate)/self.cs.ksmps() print('Must be whole number:', self.upsamp_ratio) self.analysis_values_temp = np.zeros((int(self.upsamp_ratio),self.analysis_values.shape[0]))
def testcsoundapi(dur=20, nchnls=2, backend=None, sr=None): backend = backend or csound.get_default_backend() sr = sr or csound.get_sr(backend) cs = ctcsound.Csound() orc = f""" sr = {sr} ksmps = 128 nchnls = {nchnls} instr 1 iperiod = 1 kchn init -1 ktrig metro 1/idur kchn = (kchn + ktrig) % nchnls anoise pinker outch kchn+1, anoise printk2 kchn endin schedule(1, 0, {dur}) """ orc = textwrap.dedent(orc) options = ["-d", "-odac", "-+rtaudio=%s" % backend, "-m 0"] for opt in options: cs.setOption(opt) cs.compileOrc(orc) cs.start() pt = ctcsound.CsoundPerformanceThread(cs.csound()) pt.play() return pt
def compile_drum_file(bpm, track_length, file_name, output_file): """ This method takes a bpm, track_length, a file_name for the csd file (csound file) and an output_file. This method will compile the input csd file into the audio output_file (wav, for example). The input variables will be put in the correct spots according to the following format. {output_file} in the csd will be replaced with output_file, {bpm} will be replaced with bpm, and {number_of_beats} will be calculated from the track_length in seconds. """ track_minutes = track_length / 60.0 number_of_beats = int(bpm * track_minutes) c = ctcsound.Csound() f_in = open(file_name, "r") f_out = open("tmp.csd", "w") for line in f_in: if "{output_file}" in line: line = line.replace("{output_file}", output_file) if "{bpm}" in line: line = line.replace("{bpm}", str(bpm)) if "{number_of_beats}" in line: line = line.replace("{number_of_beats}", str(number_of_beats)) f_out.write(line) f_in.close() f_out.close() ret = c.compileCsd("tmp.csd") if ret == ctcsound.CSOUND_SUCCESS: c.start() c.perform() c.reset() # Remove temporary file os.remove("tmp.csd")
def __init__(self): print("init Csound") self.cs = ctcsound.Csound() # one level above self.working_dir = pl.Path(argv[0]).parent.absolute() self.audio_dir = self.working_dir / pl.Path("generated_sample") self.sample_path = self.audio_dir / pl.Path("e2.wav") logger.debug(f"Sample loaded: {self.sample_path}") self.csd = f"""
def createEngine(self): self.cs = ctcsound.Csound() res = self.cs.compileOrc(code) self.cs.setOption('-odac') if res == 0: self.cs.start() self.cs.setControlChannel('pitch', 1.0) self.cs.setControlChannel('volume', 1.0) self.perf = ctcsound.CsoundPerformanceThread(self.cs.csound()) self.perf.play() return True else: return False
def start(self, instr, instr_bank): print "Nebulae Starting" if self.currentInstr != self.new_instr: reset_settings_flag = True else: reset_settings_flag = False self.currentInstr = instr if self.c is None: self.c = ctcsound.Csound() self.log.spill_basic_info() floader = fileloader.FileLoader() floader.reload() self.orc_handle.generate_orc(instr, instr_bank) configData = self.orc_handle.getConfigDict() self.c.setOption("-iadc:hw:0,0") self.c.setOption("-odac:hw:0,0") # Set option for Csound if configData.has_key("-B"): self.c.setOption("-B" + str(configData.get("-B")[0])) else: self.c.setOption("-B512") # Liberal Buffer if configData.has_key("-b"): self.c.setOption("-b" + str(configData.get("-b")[0])) self.c.setOption("--realtime") self.c.setOption("-+rtaudio=alsa") # Set option for Csound if debug is True: self.c.setOption("-m7") else: self.c.setOption("-m0") # Set option for Csound self.c.setOption("-d") self.c.compileOrc( self.orc_handle.curOrc) # Compile Orchestra from String self.c.readScore( self.orc_handle.curSco) # Read in Score generated from notes self.c.start() # Start Csound self.c_handle = ch.ControlHandler( self.c, self.orc_handle.numFiles(), configData, self.new_instr, bank=self.new_bank) # Create handler for all csound comm. self.loadUI() self.pt = ctcsound.CsoundPerformanceThread( self.c.csound()) # Create CsoundPerformanceThread self.c_handle.setCsoundPerformanceThread(self.pt) self.pt.play() # Begin Performing the Score in the perforamnce thread self.c_handle.updateAll( ) # Update all values to ensure their at their initial state. if reset_settings_flag == True: print("Changing Instr File -- Resetting Secondary Settings") self.c_handle.restoreAltToDefault()
def _start_csound(self): cs = ctcsound.Csound() orc = self._csdstr.format(sr=self.sr, ksmps=128, backend=self.backend, numosc=self._numosc) options = ["-d", "-odac", "-+rtaudio=%s" % self.backend, "-m 0"] for opt in options: cs.setOption(opt) cs.compileOrc(orc) cs.start() pt = ctcsound.CsoundPerformanceThread(cs.csound()) pt.play() self._cs = cs self._pt = pt
def test_feature_extractors_output_something(): feature_extractors = ["pitch", "spectral", "mfcc"] audio_to_analyse = "aSig" for fe in feature_extractors: # the other extractors depend on RMS for now analyser = Analyser(["rms", fe], audio_to_analyse=audio_to_analyse) analysis_features = analyser.analysis_features ksmps = 64 orc = f""" sr=44100 ksmps={ksmps} nchnls=1 0dbfs=1 gifftsize = {ksmps * 2} instr 1 {audio_to_analyse} poscil 1.0, 220 out {audio_to_analyse} {analyser.analyser_csd} endin """ sco = """ i1 0 3 """ cs = ctcsound.Csound() cs.setOption("--nosound") cs.compileOrc(orc) cs.readScore(sco) cs.start() features = [] while cs.performBuffer() == 0: features.append([ cs.controlChannel(feature)[0] for feature in analysis_features ]) features = np.array(features) for i in range(len(analysis_features)): assert features[:, i].mean() > 0.0 cs.cleanup() cs.reset() del cs
def play(self) -> int: cs = ctcsound.Csound() rendered_script = self._csd.render() if cs.compileCsdText(rendered_script) == ctcsound.CSOUND_SUCCESS: cs.start() while cs.performKsmps() == ctcsound.CSOUND_SUCCESS: pass # NOTE: Must follow this order of operations for cleanup to avoid failing to close the CSound object, # holding the file handle open and leaking by continuing to write to that file. result: int = cs.cleanup() cs.reset() del cs return result else: raise InvalidScoreError( 'ctcsound.compileCsdTest() failed for rendered_script {}'. format(rendered_script))
def _startCsound(self): cs = ctcsound.Csound() orc = self._csdstr.format(sr=self.sr, ksmps=self.ksmps, nchnls=2, backend=self.backend, a4=self.a4) options = ["-d", "-odac", "-+rtaudio=%s" % self.backend, "-m 0"] for opt in options: cs.setOption(opt) logger.debug(orc) cs.compileOrc(orc) cs.start() pt = ctcsound.CsoundPerformanceThread(cs.csound()) pt.play() self._cs = cs self._pt = pt
def _start_csound(self): cs = ctcsound.Csound() csd = _csd_sinesynth.format( freq=self.freq, amp=self.amp, sr=self.sr, backend=self.backend, freqport=self.freqport, gain=self.gain) error = cs.compileCsdText(csd) if error: raise RuntimeError("Could not compile csound source") cs.start() pt = ctcsound.CsoundPerformanceThread(cs.csound()) pt.play() self._cs = cs self._pt = pt self._setControlChannel = ctcsound.libcsound.csoundSetControlChannel
def __init__(self, csound_orchestra: CSoundOrchestra = None, song: Optional[Song] = None): validate_type('csound_orchestra', csound_orchestra, CSoundOrchestra) validate_optional_type('song', song, Song) super(CSoundInteractivePlayer, self).__init__() self._orchestra = csound_orchestra self._song = song self._cs = ctcsound.Csound() self._cs.setOption('-d') self._cs.setOption('-odac') self._cs.setOption('-m0') if self._cs.compileOrc(str( self._orchestra)) != ctcsound.CSOUND_SUCCESS: raise InvalidOrchestraError( 'ctcsound.compileOrc() failed for {}'.format(self._orchestra)) self._played = False
def runCsd(csdName): """Run a csd stored in the user namespace. One can store a csd in the user name space with the %%csd magic. """ if slots[0] == None: slots[0] = ctcsound.Csound() cs = slots[0] ip = get_ipython() csd = ip.user_ns["__csd"][csdName] ret = cs.compileCsdText(csd) if ret == ctcsound.CSOUND_SUCCESS: cs.start() cs.perform() cs.reset() return 'OK' else: return 'Error'
def runOrcSco(orcName, scoName): """Run an orc and sco stored in the user namespace. One can store an orc in the user namespace with the %%orc magic, and a sco with the %%sco magic as well. """ if slots[0] == None: slots[0] = ctcsound.Csound() cs = slots[0] ip = get_ipython() orc = ip.user_ns["__orc"][orcName] ret = cs.compileOrc(orc) if ret != ctcsound.CSOUND_SUCCESS: return 'Error in orchestra' sco = ip.user_ns["__sco"][scoName] ret = cs.readScore(sco) if ret != ctcsound.CSOUND_SUCCESS: return 'Error in score' cs.start() cs.perform() cs.reset() return 'OK'
def perform(orc, score, create_wav=False): """ Inputs: orc - csound orchestra in a string sco - csound score in a string Function reads input orc and score and plays the corresponding csound composition. """ c = ctcsound.Csound() c.setOption("-odac") if (create_wav): c.setOption("-o output.wav") # prepare the inputs c.compileOrc(orc) c.readScore(score) # performance c.start() c.perform() c.reset()
def play_csound(orc_file, generator, args_list=['-odac', '-W'], string_values=None, silent=False): with open(orc_file, "r") as f: orc_string = f.read() if silent: args_list.append("-m0") args_list.append("-d") score_string = generator.generate_score_string() cs = ctcsound.Csound() cs.compileOrc(orc_string) cs.readScore(score_string) for x in args_list: cs.setOption(x) if string_values: for k in string_values.keys(): cs.setStringChannel(k, string_values[k]) cs.start() cs.perform() cs.stop()
def loop(self) -> int: result = 0 rendered_script = self._csd.render() try: cs = ctcsound.Csound() while True: # noinspection PyUnboundLocalVariable if cs.compileCsdText( rendered_script) == ctcsound.CSOUND_SUCCESS: cs.start() while cs.performKsmps() == ctcsound.CSOUND_SUCCESS: pass # NOTE: Must follow this order of operations for cleanup to avoid failing to close the CSound object # holding the file handle open and leaking by continuing to write to that file. result: int = cs.cleanup() cs.reset() else: raise InvalidScoreError( 'ctcsound.compileCsdTest() failed for rendered_script {}' .format(rendered_script)) except KeyboardInterrupt: del cs return result
def __init__(self): ctcsound.csoundInitialize(ctcsound.CSOUNDINIT_NO_SIGNAL_HANDLER) self._csnd = ctcsound.Csound() self._csnd.compileCsd(Config.PLUGIN_UNIVORC) self._csnd.setDebug(False) self._csnd.start() self._perfThread = ctcsound.CsoundPerformanceThread( self._csnd.csound()) self._perfThread.play() # TODO # sc_initialize(Config.PLUGIN_UNIVORC, Config.PLUGIN_DEBUG, # Config.PLUGIN_VERBOSE, Config.PLUGIN_RATE) self.on = False self.setMasterVolume(100.0) self.periods_per_buffer = 2 global _loop_default # TODO # _loop_default = self.loopCreate() self.instrumentDB = InstrumentDB.getRef() # temporyary dictionary of loopId: loopNumTicks, # while I wait for james to implement it properly self.jamesSux = {}
prints sprintf("Output filename: %s\\n", gS_MasterOutput_filename) fout gS_MasterOutput_filename, 18, aleft * i_amplitude_adjustment, aright * i_amplitude_adjustment non_has_filename: prints "MasterOutput i %9.4f t %9.4f d %9.4f k %9.4f v %9.4f p %9.4f #%3d\\n", p1, p2, p3, p4, p5, p1/6, active(p1) kstatus, kchan, kdata1, kdata2 midiin ;printf " midi in s %4d c %4d %4d %4d\\n", kdata2, kstatus, kchan, kdata1, kdata2 endin ''' # The "f 0" statement prevents an abrupt cutoff. sco = "f 0 90\n" + musx_csound.to_csound_score(f) print(sco) csound = ctcsound.Csound() csound.setOption("-+msg_color=0") csound.setOption("-d") csound.setOption("-m195") csound.setOption("-f") # Change this for your actual audio configuration, try "aplay -l" to see what they are. csound.setOption("-odac:plughw:1,0") # Can also be a soundfile. # csound.setOption("-otest.wav") csound.compileOrc(orc) csound.readScore(sco) csound.start() # Probably runs a bit smoother in an independent thread (this is a native thread, # not a Python thread). thread = ctcsound.CsoundPerformanceThread(csound.csound()) thread.play()
def i_spectral(xv, yv, itime, path='./', instr='noise'): # Normalization of the energy into FFT bins # must be power of 2 for oscil opcode nlines = xv.shape[0] nbins = int(np.sqrt(nlines) - np.sqrt(nlines) % 1)**2 while nbins > nlines or not (nbins != 0 and ((nbins & (nbins - 1)) == 0)): nbins = int((np.sqrt(nbins) - 1)**2) yfft = np.zeros((nbins), dtype=int) for n in range(nbins): yfft[n] = n + 1 xminf = xv[0] xmaxf = xv[-1] xvf = np.asarray(xv) xvs = (xv - xminf) / (xmaxf - xminf) * nbins for line in range(nlines): if xvs[line] >= nbins: xvs[line] = -1 xvf[line] = yfft[int(xvs[line])] # Normalization of the data shape into MIDI velocity yminf = min(yv) ymaxf = max(yv) yvf = np.asarray(yv) yvf = (yv - yminf) / (ymaxf - yminf) * 127 vel = np.zeros((nbins), dtype=float) nvel = 0 for note in range(nbins): for line in range(nlines): if xvf[line] == yfft[note]: vel[nvel] = yvf[line] nvel = nvel + 1 break ########## DSI file for CSound processing on fft grid ########### velmax = max(vel) f = open(path + 'DSI_CSound.dat', 'w') for line in range(int(nvel)): f.write(str(vel[line] / float(velmax)) + '\n') f.close() ########## Initialize and play CSound instruments ############ if instr == 'noise': csd_header = ''' <CsoundSynthesizer> <CsOptions> -odac ;-o ''' + path + '''DSI.wav -W </CsOptions> <CsInstruments> sr = 44100 ksmps = 64 nchnls = 2 0dbfs = 1 ;MAXIMUM AMPLITUDE massign 0,0 /**************************************************** instruments *****************************************************/ ifn0 ftgen 0,0,''' + str(nbins) + ''',23,"''' + path + '''DSI_CSound.dat" gifn0 = ifn0 /***************************************************** irn IR ifn irn - impulse response output function table number ifn - amplitude response function table number *****************************************************/ opcode IR,i,i ifn xin iflen2 = ftlen(ifn) iflen = 2*iflen2 iSpec[] init iflen2 icnt init 0 copyf2array iSpec,ifn iIR[] rifft r2c(iSpec) irn ftgen 0,0,iflen,7,0,iflen,0 while icnt < iflen2 do itmp = iIR[icnt] iIR[icnt] = iIR[icnt + iflen2] iIR[icnt + iflen2] = itmp icnt +=1 od copya2ftab iIR,irn xout irn endop /***************************************************** asig FIR ain,ifn ain - input audio ifn - amplitude response function table number *****************************************************/ opcode FIR,a,ai asig,ifn xin irn IR ifn xout dconv(asig,ftlen(irn),irn) endop ''' # DSI player csd_instr = ''' instr 99 kporttime linseg 0,0.001,0.05 kamp = 0.5 kamp portk kamp,kporttime kbeta= 0 asigL noise kamp, kbeta asigR noise kamp, kbeta asigL FIR asigL, gifn0 asigR FIR asigR, gifn0 kenv linseg 1, ''' + str(float(itime) - 0.1 * float(itime)) + ''',1,''' + str( 0.1 * float(itime)) + ''',0 asigL butterlp asigL, 6000 asigR butterlp asigR, 6000 asigL = asigL*kenv asigR = asigR*kenv outs asigL, asigR endin ''' csd_file = csd_header + csd_instr csd_tail = ''' </CsInstruments> <CsScore> i 99 0 ''' + str(itime) + ''' e </CsScore> </CsoundSynthesizer> ''' csd_file += csd_tail ############ Play ############ cs = ctcsound.Csound() cs.compileCsdText(csd_file) cs.start() cs.perform() cs.cleanup() cs.reset # Clean up files os.remove(path + 'DSI_CSound.dat')
def i_spectral2(xv,yv,itime,path='./',instr='noise'): # Normalization of the energy into FFT bins # must be power of 2 for oscil opcode - FIR filter done using scipy.fftpack nlines = xv.shape[0] nbins = int(np.sqrt(nlines)-np.sqrt(nlines)%1)**2 while nbins > nlines or not(nbins != 0 and ((nbins & (nbins - 1)) == 0)): nbins = int((np.sqrt(nbins)-1)**2) yfft = np.zeros((nbins),dtype=int) for n in range(nbins): yfft[n] = n+1 xminf = xv[0] xmaxf = xv[-1] xvf=np.asarray(xv) xvs = (xv-xminf)/(xmaxf-xminf)*nbins for line in range(nlines): if xvs[line] >= nbins: xvs[line] = -1 xvf[line] = yfft[int(xvs[line])] # Normalization of the data shape into MIDI velocity yminf = min(yv) ymaxf = max(yv) yvf=np.asarray(yv) yvf = (yv-yminf)/(ymaxf-yminf)*127 vel=np.zeros((nbins),dtype=float) nvel=0 for note in range(nbins): for line in range(nlines): if xvf[line] == yfft[note]: vel[nvel] = yvf[line] nvel=nvel+1 break ########## DSI file for CSound - Finite Impulse Response filter ########### velmax = max(vel) vel = vel/velmax ftvel = FFT.irfft(vel) ftvel = FFT.fftshift(ftvel) f=open(path+'DSI_CSound.dat','w') for line in range(int(nvel)): f.write(str(ftvel[line])+'\n') f.close() ########## Initialize and play CSound instruments ############ if instr == 'noise': csd_header = ''' <CsoundSynthesizer> <CsOptions> -odac ;-o '''+path+'''DSI.wav -W </CsOptions> <CsInstruments> sr = 44100 ksmps = 64 nchnls = 2 0dbfs = 1 ;MAXIMUM AMPLITUDE massign 0,0 ifn0 ftgen 0,0,'''+str(nbins)+''',-23,"'''+path+'''DSI_CSound.dat" gifn0 = ifn0 ''' # DSI player csd_instr = ''' instr 99 ;kporttime linseg 0,0.001,0.05 ;kamp = 0.5 ;kamp portk kamp,kporttime ;kbeta= 0 ;asigL noise kamp, kbeta ;asigR noise kamp, kbeta asigL pinker asigR pinker asigL dconv asigL, ftlen(gifn0), gifn0 asigR dconv asigR, ftlen(gifn0), gifn0 kenv linseg 1, '''+str(float(itime)-0.1*float(itime))+''',1,'''+str(0.1*float(itime))+''',0 asigL butterlp asigL, 3000 asigR butterlp asigR, 3000 asigL = asigL*kenv asigR = asigR*kenv asigL clip asigL, 2, 0.7 asigR clip asigR, 2, 0.7 outs asigL, asigR endin ''' csd_file = csd_header+csd_instr csd_tail = ''' </CsInstruments> <CsScore> i 99 0 '''+str(itime)+''' e </CsScore> </CsoundSynthesizer> ''' csd_file += csd_tail ############ Play ############ cs = ctcsound.Csound() cs.compileCsdText(csd_file) cs.start() cs.perform() cs.cleanup() cs.reset # Clean up files os.remove(path+'DSI_CSound.dat')
def setUpClass(self): self.cs = ctcsound.Csound() self.cs.compile_("csoundPerformanceThread", "simple.csd") self.pt = ctcsound.CsoundPerformanceThread(self.cs.csound())
0dbfs=1 ksmps = 1 instr 1 a1 init 1 abp = moogladder(a1,3200,0.2) abp1 = moogladder(a1,2200,0.7) abp2 = moogladder(a1,2100,0.9) out(abp,abp1,abp2) a1 = 0 endin schedule(1,0,1) ''' N = 16384 figure(figsize=(8, 6)) cs = csound.Csound() cs.setOption('-n') cs.compileOrc(code) cs.start() spout = cs.spout() nchnls = cs.nchnls() sr = cs.sr() sigs = zeros(sr * nchnls) n = 0 for i in range(0, int(len(sigs) / (nchnls * cs.ksmps()))): cs.performKsmps() for i in spout: sigs[n] = i / cs.get0dBFS() n += 1 win = zeros(N) + 1 #hanning(N)
ifreq = p4 imeth = p6 imethP1 = p7 imethP2 = p8 asig pluck ifreq, p5, p5, ifn, imeth, imethP1, imethP2 kres line 1, idur, 0 ; so tail does not leave DC offset hanging. asig = asig * kres if (nchnls == 2) then ; stereo out aL, aR pan2 asig, (kloc % 180) * 180 ; pan stereo (0=hardL,1=hardR) outs aL, aR else out asig ; mono out endif endin """ # import ctcsoud API ; instantiate & initialize the Csound() class import ctcsound cs = ctcsound.Csound() # instantiate the Csound() class cs.setOption("-odac") # DAC output cs.setOption("-b 4096") # output buffer size cs.setOption("-d") # suppress displays ; test! # --------- instantiate the RT perf thread ------------------ csPerf = ctcsound.CsoundPerformanceThread(cs.csound()) cs.readScore("f 0 z \n") # keep Csound running for a long time... # -------- sound "fonts" for "rendering" --------------------- cs.readScore("f 20 0 0 1 \"sounds/agogo1-H.wav\" 0 0 0 \n") cs.compileOrc(myOrcOptions) # SR, NrChans cs.start() # start CS synth csPerf.play() # start separate performance thread cs.compileOrc(pluckIt) # compile the pluckIt instrument def passCallback():
</CsOptions> <CsInstruments> sr = 44100 ;SAMPLE RATE ksmps = 16 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO) instr 1; ALWAYS ON - SEE SCORE kgain invalue "Gain" ainL, ainR ins outs ainL * kgain, ainR * kgain endin </CsInstruments> <CsScore> ;INSTR | START | DURATION i 1 0 10 ;INSTRUMENT 1 PLAYS FOR 1 HOUR (AND KEEPS PERFORMANCE GOING) </CsScore> </CsoundSynthesizer>''' cs = ctcsound.Csound() result = cs.compileCsdText(csd_text) result = cs.start() while True: result = cs.performKsmps() if result != 0: break result = cs.cleanup() cs.reset() del cs sys.exit(result)
def setUpClass(self): self.cs = ctcsound.Csound()