Csound API / Python
Date | 2017-08-10 07:50 |
From | Rene |
Subject | Csound API / Python |
Hello list, My beginning with Csound API. I get a Csound Segmentation fault when I want to use CsoundChannelList. Here after the test files I use and the output log. Any hints appreciated! Regards, René bus.py: import csnd6 import time cs = csnd6.CppSound() cs.Compile("bus.csd") chnlst = csnd6.CsoundChannelList(cs) n = chnlst.Count() print '......Using', n, 'channels' for i in range(n): print 'Channel name:', chnlst.Name(i) bus.csd: <CsoundSynthesizer> <CsOptions> -odac </CsOptions> <CsInstruments> chn_k "var1", 3 chn_k "var2", 3 instr 1 kvar1 chnget "var1" kvar2 chnget "var2" endin </CsInstruments> <CsScore> i 1 0 1 </CsScore> </CsoundSynthesizer> output log: moi@linux ~/Works/Python/CsPy_API $ python ./bus.py: virtual_keyboard real time MIDI plugin for Csound 0dBFS level = 32768.0 --Csound version 6.09.1 (double samples) Jul 14 2017 [commit: none] libsndfile-1.0.25 UnifiedCSD: bus.csd STARTING FILE Creating options Creating orchestra Creating score rtaudio: ALSA module enabled rtmidi: ALSA Raw MIDI module enabled Elapsed time at end of orchestra compile: real: 0.002s, CPU: 0.002s sorting score ... ... done Elapsed time at end of score sort: real: 0.002s, CPU: 0.002s graphics suppressed, ascii substituted 0dBFS level = 32768.0 orch now loaded audio buffered in 256 sample-frame blocks ALSA output: total buffer size: 1024, period size: 256 writing 256 sample blks of 64-bit floats to dac SECTION 1: ......Using 2 channels Channel name: var1 Channel name: var2 backtrace() returned 15 addresses /home/moi/Programmes/csound/ /lib/x86_64-linux-gnu/libc.so. /home/moi/Programmes/csound/ /home/moi/Programmes/csound/ /home/moi/Programmes/csound/_ python(PyEval_EvalFrameEx+ python(PyEval_EvalFrameEx+ python(PyEval_EvalCodeEx+ python(PyEval_EvalCode+0x19) [0x4c2509] python() [0x4f1def] python(PyRun_FileExFlags+0x82) [0x4ec652] python(PyRun_ python(Py_Main+0x68a) [0x49e14a] /lib/x86_64-linux-gnu/libc.so. python(_start+0x29) [0x49d9d9] Csound tidy up: Segmentation fault inactive allocs returned to freespace end of score. overall amps: 0.0 overall samples out of range: 0 0 errors in performance Elapsed time at end of performance: real: 0.266s, CPU: 0.007s 0 256 sample blks of 64-bit floats written to dac moi@linux ~/Works/Python/CsPy_API $ |
Date | 2017-08-10 08:44 |
From | Francois PINOT |
Subject | Re: Csound API / Python |
When you ask for a channel list, Csound allocates memory for filling a list of controlChannelInfo_t structs. Before leaving you have to delete this list using DeleteChannelList with an argument which is a pointer to the memory block allocated by Csound. This is quite convoluted with csnd6. You could use ctcsound instead. ctcsound is a Python binding file to the Csound API based on the ctypes module. It works with python 2.7 and python 3.x as well. It is distributed with csound since version 6.07. The only requirement is that ctcsound needs numpy.import ctcsound cs = ctcsound.Csound() cs.compileCsd("bus.csd") cs.start() chnlst, err = cs.listChannels() if err == '': n = len(chnlst) print('......Using', n, 'channels') for i in range(n): print('Channel name:', chnlst[i].name) # Free memory allocated by Csound for channel list cs.deleteChannelList(chnlst) cs.stop() 2017-08-10 8:50 GMT+02:00 Rene <rene.djack1@gmail.com>:
|
Date | 2017-08-10 10:26 |
From | Rene |
Subject | Re: Csound API / Python |
Thanks François, Your example is fine on my system, so I switch to ctcsound.2017-08-10 9:44 GMT+02:00 Francois PINOT <fggpinot@gmail.com>:
|