Csound Csound-dev Csound-tekno Search About

Csound API / Python

Date2017-08-10 07:50
FromRene
SubjectCsound 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!

I am on linux, csound 6.09.1, python 2.7.12

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/libcsound64.so.6.0(+0x3fd72) [0x7f313f176d72]
/lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7f31409244b0]
/home/moi/Programmes/csound/libcsound64.so.6.0(csoundDeleteChannelList+0x19) [0x7f313f1cc283]
/home/moi/Programmes/csound/libcsnd6.so.6.0(_ZN17CsoundChannelList5ClearEv+0x2b) [0x7f313f6f79c1]
/home/moi/Programmes/csound/_csnd6.so(+0xa2ac2) [0x7f313f9aeac2]
python(PyEval_EvalFrameEx+0x68a) [0x4c468a]
python(PyEval_EvalFrameEx+0x5d8f) [0x4c9d8f]
python(PyEval_EvalCodeEx+0x255) [0x4c2765]
python(PyEval_EvalCode+0x19) [0x4c2509]
python() [0x4f1def]
python(PyRun_FileExFlags+0x82) [0x4ec652]
python(PyRun_SimpleFileExFlags+0x191) [0x4eae31]
python(Py_Main+0x68a) [0x49e14a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f314090f830]
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 $




Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2017-08-10 08:44
FromFrancois PINOT
SubjectRe: 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.

With ctcsound, your program would be:

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()

François

2017-08-10 8:50 GMT+02:00 Rene <rene.djack1@gmail.com>:
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!

I am on linux, csound 6.09.1, python 2.7.12

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/libcsound64.so.6.0(+0x3fd72) [0x7f313f176d72]
/lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7f31409244b0]
/home/moi/Programmes/csound/libcsound64.so.6.0(csoundDeleteChannelList+0x19) [0x7f313f1cc283]
/home/moi/Programmes/csound/libcsnd6.so.6.0(_ZN17CsoundChannelList5ClearEv+0x2b) [0x7f313f6f79c1]
/home/moi/Programmes/csound/_csnd6.so(+0xa2ac2) [0x7f313f9aeac2]
python(PyEval_EvalFrameEx+0x68a) [0x4c468a]
python(PyEval_EvalFrameEx+0x5d8f) [0x4c9d8f]
python(PyEval_EvalCodeEx+0x255) [0x4c2765]
python(PyEval_EvalCode+0x19) [0x4c2509]
python() [0x4f1def]
python(PyRun_FileExFlags+0x82) [0x4ec652]
python(PyRun_SimpleFileExFlags+0x191) [0x4eae31]
python(Py_Main+0x68a) [0x49e14a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f314090f830]
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 $




Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2017-08-10 10:26
FromRene
SubjectRe: 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>:
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.

With ctcsound, your program would be:

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()

François

2017-08-10 8:50 GMT+02:00 Rene <rene.djack1@gmail.com>:
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!

I am on linux, csound 6.09.1, python 2.7.12

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/libcsound64.so.6.0(+0x3fd72) [0x7f313f176d72]
/lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7f31409244b0]
/home/moi/Programmes/csound/libcsound64.so.6.0(csoundDeleteChannelList+0x19) [0x7f313f1cc283]
/home/moi/Programmes/csound/libcsnd6.so.6.0(_ZN17CsoundChannelList5ClearEv+0x2b) [0x7f313f6f79c1]
/home/moi/Programmes/csound/_csnd6.so(+0xa2ac2) [0x7f313f9aeac2]
python(PyEval_EvalFrameEx+0x68a) [0x4c468a]
python(PyEval_EvalFrameEx+0x5d8f) [0x4c9d8f]
python(PyEval_EvalCodeEx+0x255) [0x4c2765]
python(PyEval_EvalCode+0x19) [0x4c2509]
python() [0x4f1def]
python(PyRun_FileExFlags+0x82) [0x4ec652]
python(PyRun_SimpleFileExFlags+0x191) [0x4eae31]
python(Py_Main+0x68a) [0x49e14a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f314090f830]
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 $




Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here