| This is very good; making it possible to access audio channels
as well as control and string channels is a great thing. Great
job, well done.
Victor
At 11:09 13/12/2005, you wrote:
>On Sunday 11 December 2005 23:47, Victor Lazzarini wrote:
>
> > Thanks a lot. The CsoundArgVList class is new as well isn't
> > it? I hadn't seen it before.
>
>Here are a few more examples for these new classes:
> CsoundChannelList
> CsoundOpcodeList
> CsoundUtilityList
> CsoundMYFLTArray
> CsoundArgVList
>
>------------------------ chn_list.py ------------------------
>
>#!/usr/bin/python
>
>import csnd
>import wave
>import array
>import math
>
>csound = csnd.Csound()
>
># create and compile a CSD file
>
>f = open('chntest.csd', 'w')
>print >> f, '''
>
>
>sr = 48000
>ksmps = 32
>nchnls = 1
>
>gkfco init 1000
>gkfco chnexport "FilterFreq", 1, 3, 1000, 200, 4000
>gSfname chnexport "FileName", 1
>gaout chnexport "AudioOutput", 2
>
> instr 1
> printf_i "The file name is: '%s'\\n", 1, gSfname
>a1 vco2 20 / sqrt(gkfco), 220
>a2 pareq a1, gkfco, 0, gkfco / 220, 2
>gaout = taninv(a2) * 0.6
> endin
>
>
>
>
>i 1 0 5
>e
>
>
>
>'''
>f.close()
>err = csound.Compile('-d', '-n', 'chntest.csd')
>if (err != 0):
> raise(SystemExit(err))
>
># create and print a channel list
>
>controlInput = ''
>audioOutput = ''
>stringInput = ''
>
>chnlst = csnd.CsoundChannelList(csound)
>n = chnlst.Count()
>if n > 0:
> print '============================================================'
> print n, ' channels'
> print '------------------------------------------------------------'
> for i in range(n):
> print 'Name: ', chnlst.Name(i)
> tmp = 'unknown'
> if chnlst.IsControlChannel(i):
> tmp = 'control'
> elif chnlst.IsAudioChannel(i):
> tmp = 'audio'
> elif chnlst.IsStringChannel(i):
> tmp = 'string'
> print 'Type: ', tmp
> print 'Input: ', ['no', 'yes'][chnlst.IsInputChannel(i)]
> print 'Output: ', ['no', 'yes'][chnlst.IsOutputChannel(i)]
> if chnlst.SubType(i) > 0:
> tmp = ['integer', 'linear', 'exponential']
> print 'Subtype: ', tmp[chnlst.SubType(i) - 1]
> print 'Default value: ', chnlst.DefaultValue(i)
> print 'Minimum value: ', chnlst.MinValue(i)
> print 'Maximum value: ', chnlst.MaxValue(i)
> print '------------------------------------------------------------'
> if chnlst.IsControlChannel(i) and chnlst.IsInputChannel(i):
> if chnlst.SubType(i) == csnd.CSOUND_CONTROL_CHANNEL_EXP:
> controlInput = chnlst.Name(i)
> if chnlst.IsAudioChannel(i) and chnlst.IsOutputChannel(i):
> audioOutput = chnlst.Name(i)
> if chnlst.IsStringChannel(i) and chnlst.IsInputChannel(i):
> stringInput = chnlst.Name(i)
>
># free memory used by the channel list; call this before csound.Reset()
>
>chnlst.Clear()
>
>if controlInput == '' or audioOutput == '':
> csound.Reset()
> raise(SystemExit(0))
>
># if found an exponential control input channel and an audio output channel,
># perform the orchestra
>
># get pointer to the control input channel
>ptr1 = csnd.CsoundMYFLTArray()
>csound.GetChannelPtr(ptr1.GetPtr(), controlInput,
> csnd.CSOUND_CONTROL_CHANNEL + csnd.CSOUND_INPUT_CHANNEL)
># get pointer to the audio output channel
>ptr2 = csnd.CsoundMYFLTArray()
>csound.GetChannelPtr(ptr2.GetPtr(), audioOutput,
> csnd.CSOUND_AUDIO_CHANNEL + csnd.CSOUND_OUTPUT_CHANNEL)
># if there is a string input channel, write the file name to it
>if stringInput != '':
> ptr3 = csnd.CsoundMYFLTArray()
> csound.GetChannelPtr(ptr3.GetPtr(), stringInput,
> csnd.CSOUND_STRING_CHANNEL +
> csnd.CSOUND_INPUT_CHANNEL)
> ptr3.SetStringValue('chntest.wav', csound.GetStrVarMaxLen())
> ptr3 = None
># get the range of the control channel
>tmp, dflt, minVal, maxVal = csound.GetControlChannelParams(controlInput)
>ksmps = csound.GetKsmps()
>
># open a 16 bit mono WAV file for storing the audio output
>
>f = wave.open('chntest.wav', 'wb')
>f.setframerate(int(csound.GetSr()))
>f.setnchannels(1)
>f.setsampwidth(2)
>buf = array.array('B')
>
># writes a floating point sample (-1.0 to 1.0) to the buffer
>
>def writeSample(x):
> nn = int(x * 32767.0)
> if nn < 0:
> if nn > -32768:
> nn = 65536 + nn
> else:
> nn = 32768
> elif nn > 32767:
> nn = 32767
> buf.append(nn & 255)
> buf.append(nn >> 8)
>
>x = maxVal
>c1 = math.pow(0.5, (1.0 / csound.GetKr()))
>
>while 1:
> # set control input
> ptr1.SetValue(0, x)
> x = minVal + ((x - minVal) * c1)
> # perform one control period
> if csound.PerformKsmps() != 0:
> break
> # get audio output
> for i in range(ksmps):
> writeSample(ptr2.GetValue(i))
>
># write sound file
>
>f.writeframes(buf)
>f.close()
>
># clean up
>
>csound.Reset()
>
>------------------------ opcodlst.py ------------------------
>
>#!/usr/bin/python
>
>import csnd
>
>csound = csnd.Csound()
>
># compile something so that we can create an opcode list
>
>csound.Compile('-d', '-m0', '-H0', '-n', 'examples/trapped.csd')
>
># write the opcode list to a file 'opcodelist.txt'
>
>oplst = csnd.CsoundOpcodeList(csound)
>f = open('opcodelist.txt', 'w')
>n = oplst.Count()
>print >> f, n, ' opcodes'
>for i in range(n):
> print >> f,
> '-------------------------------------------------------------'
> print >> f, 'Name: ', oplst.Name(i)
> print >> f, 'Output types: ', oplst.OutTypes(i)
> print >> f, 'Input types: ', oplst.InTypes(i)
>f.close()
>
># free memory used by the opcode list; call this before csound.Reset()
>
>oplst.Clear()
>
>csound.Reset()
>
>------------------------ util_lst.py ------------------------
>
>#!/usr/bin/python
>
>import sys
>import csnd
>
>csound = csnd.Csound()
>
># load utility plugins
>
>csound.PreCompile()
>
># create and print the utility list
>
>ulst = csnd.CsoundUtilityList(csound)
>n = ulst.Count()
>print n, ' utilities:'
>for i in range(n):
> print ' ', ulst.Name(i)
> print ' ', csound.GetUtilityDescription(ulst.Name(i))
>
># free memory used by the utility list; call this before csound.Reset()
>
>ulst.Clear()
>
># if there are command line arguments, run the sndinfo utility
>
>n = sys.argv.__len__()
>if n > 1:
> args = csnd.CsoundArgVList()
> args.Append('sndinfo')
> print
> for i in range(1, n):
> args.Append(sys.argv[i])
> err = csound.RunUtility('sndinfo', args.argc(), args.argv())
> print 'sndinfo returns: ', err
> args.Clear()
>
># clean up
>
>csound.Reset()
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
>for problems? Stop! Download the new AJAX search engine that makes
>searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
>http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
>_______________________________________________
>Csound-devel mailing list
>Csound-devel@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/csound-devel
Victor Lazzarini
Music Technology Laboratory
Music Department
National University of Ireland, Maynooth
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net |