Csound Csound-dev Csound-tekno Search About

[Csnd] Using pycall to call a function with no parameters?

Date2007-11-03 15:30
FromLou Cohen
Subject[Csnd] Using pycall to call a function with no parameters?
Using pycall to call a function with no parameters? I’m using csound 5.04 on PPC Mac OS X 10.4.10 to interact with python and I’ve run into a small problem. This note is to check if this is a bug, maybe already fixed, or if I misunderstand something.

If I define a python function to have no input parameters (and one result,) it seems that csound dies when I try to invoke that function using pycall1i. Below is my csound code, followed by the terminal output. You will see that everything works as it should until the final pycall1i line, at which point csound halts (sometimes crashes.)

Clearly I can work around this by always defining at least one input parameter for a python function, even if I ignore it, but I want to be sure I haven’t misunderstood something...

thanks,
Lou


<CsoundSynthesizer>
<CsInstruments>
;</CsOptions>
; Select audio/midi flags here according to platform
; Audio out   Audio in    No messages
;-odac           -iadc    ; -d     ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o linseg.wav -W ;;; for file output any platform
;</CsOptions>
;<CsInstruments>
;*******************************
sr=48000
kr=480
ksmps=100
nchnls=1

pyinit

;define a function that ignores its input parameter d and uses globals a,b
pyruni {{
def myfun(d):
    c=a+b
    return c

}}

;define a function that has no input parameter, only uses globals a,b
pyruni {{
def myotherfun():
    c=a+b
    return c

}}

;use python to set globals a, b and call both functions
; also use python to print the outputs of the functions.
pyruni {{
a=1
b=2
print "myfun=", myfun(6)
print "myotherfun=", myotherfun()
a=1000
print "myfun=", myfun(6)
print "myotherfun=", myotherfun()
}}

;use csound to set one of the python globals
pyassigni    "a", 64
;use pyruni to call the function with the dummy input parameter
pyruni        {{print "myfun=", myfun(6)}}

;use pyruni to call the function with no input parameter
pyruni        {{print "myotherfun=", myotherfun()}}

;use pycall1i to call the function with the dummy input parameter
ic        pycall1i    "myfun", 1
;use csound to print the result
print        ic

;use pycall1i to call the function that has no input parameter (never gets here, or crashes here!)
iotherc        pycall1i    "myotherfun"
print        iotherc

instr 1
endin
</CsInstruments>
<CsScore>
f 0 900000 ;dummy table for realtime input
i 1 0 10000
e
</CsScore>

</CsoundSynthesizer>
----------------------------------------
terminal output:

Csound version 5.04.0 (float samples) Nov 10 2006
0dBFS level = 32768.0
myfun= 3
myotherfun= 3
myfun= 1002
myotherfun= 1002
myfun= 66.0
myotherfun= 66.0
instr 0:  ic = 66.000
Csound tidy up: Bus error
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.906s, CPU: 0.090s

---------------------------
Permanent email:           loucohen@jolc.net
Music and video:           http://ruccas.org/wiki.pl/Lou_Cohen
More music and video:      http://www.youtube.com/loucohen
Astronomy:                 http://www.jolc.net
----------------------------


Date2007-11-03 18:04
From"Oeyvind Brandtsegg"
Subject[Csnd] Re: Using pycall to call a function with no parameters?
AttachmentsNone