Csound Csound-dev Csound-tekno Search About

python problems

Date2007-10-25 09:26
Fromjoachim heintz
Subjectpython problems
Attachmentspyproblem.csd  
Hello all -

after reading Andres' article in the Csound Journal (thanks for this, Andres!) I tried a little job with the python opcodes. But it's not working as I expected, so I am asking you for help.
My goal was to get the universal time. This is the csd (also in the attachment):

pyinit
pyruni "import time"

instr 1

pylruni {{
a = time.time()
print "pythonzeit = " + str(a); for comparing
}}

itim pylevali "a"
print itim; expected to be the same as above

endin


i1 0 1
i1 1.1 .5

The output is the following:

1. first rendering:
pythonzeit = 1193259253.04
instr 1:  itim = 1193259264.000
B  0.000 ..  1.100 T  1.100 TT  1.100 M:      0.0
pythonzeit = 1193259253.3
instr 1:  itim = 1193259264.000
B  1.100 ..  1.600 T  1.600 TT  1.600 M:      0.0

2. rendering again some seconds later:
pythonzeit = 1193259259.7
instr 1:  itim = 1193259264.000
B  0.000 ..  1.100 T  1.100 TT  1.100 M:      0.0
pythonzeit = 1193259259.77
instr 1:  itim = 1193259264.000
B  1.100 ..  1.600 T  1.600 TT  1.600 M:      0.0


My problems:
1. Why is itim not reinitialized, neither in the 2 calls of i1 in one performance, nor in the second rendering?
2. Why is itim rounded to an integer?
3. Why is "pythonzeit" and "itim" not the same value, at least at the first call of the instrument?
4. "pythonzeit" seems not to increase correctly; the difference in starting time between the two instances of instr 1 should result in a difference of the 2 printouts of "pythonzeit" of 1.1 seconds, but it's less.

I am using Python 2.5 on OS X 10.4. Csound 5.06 (via Terminal).

Thanks for any help -

joachim



Date2007-10-25 18:26
FromAnthony Kozar
SubjectRe: python problems
joachim heintz wrote on 10/25/07 4:26 AM:

> 4. "pythonzeit" seems not to increase correctly; the difference in
> starting time between the two instances of instr 1 should result in a
> difference of the 2 printouts of "pythonzeit" of 1.1 seconds, but
> it's less.

I don't know about your other questions, but this one is due to the fact
that Csound does not perform the calculations for notes at time intervals
matching the time intervals in "score time" and Python is reading the real
clock in your computer.  Normally, Csound tries to render the audio as
quickly as it can, which is why a score of several minutes length might run
in a few seconds in non-real-time mode.  Even in real-time mode, Csound must
render the audio ahead of the time at which it must be played-back.

> I am using Python 2.5 on OS X 10.4. Csound 5.06 (via Terminal).

I doubt this is causing you problems, but I will note that the OS X Csound
packages use the system's default Python 2.3 distribution for the Python
opcodes.  Unless you compiled Csound yourself, you should consider your
Python orchestra code to be using Python 2.3.

Anthony Kozar
Providing custom open-source software services for musicians:
http://services.anthonykozar.net/

Date2007-10-25 18:49
FromCesare Marilungo
SubjectRe: python problems
Hi joachim,

If you check the elpsed time like this you're getting the time at the 
instrument instance creation.

If you want to have the csound score time in a python instance you can 
pass p2 to it. Something like this:



pyinit

instr 1

pyassigni "a", p2

pyruni {{
print "now a is:", a
a = a * 2 #I just do something with it to be sure it gets updated when 
we print it below
}}

itim     pyevali     "a"
print itim ; should print p2*2

endin



i1 0 1
i1 1.5 1



joachim heintz wrote:
> Hello all -
>
> after reading Andres' article in the Csound Journal (thanks for this, 
> Andres!) I tried a little job with the python opcodes. But it's not 
> working as I expected, so I am asking you for help.
> My goal was to get the universal time. This is the csd (also in the 
> attachment):
>
> pyinit
> pyruni "import time"
>
> instr 1
>
> pylruni {{
> a = time.time()
> print "pythonzeit = " + str(a); for comparing
> }}
>
> itim pylevali "a"
> print itim; expected to be the same as above
>
> endin
>
>
> i1 0 1
> i1 1.1 .5
>
> The output is the following:
>
> 1. first rendering:
> pythonzeit = 1193259253.04
> instr 1:  itim = 1193259264.000
> B  0.000 ..  1.100 T  1.100 TT  1.100 M:      0.0
> pythonzeit = 1193259253.3
> instr 1:  itim = 1193259264.000
> B  1.100 ..  1.600 T  1.600 TT  1.600 M:      0.0
>
> 2. rendering again some seconds later:
> pythonzeit = 1193259259.7
> instr 1:  itim = 1193259264.000
> B  0.000 ..  1.100 T  1.100 TT  1.100 M:      0.0
> pythonzeit = 1193259259.77
> instr 1:  itim = 1193259264.000
> B  1.100 ..  1.600 T  1.600 TT  1.600 M:      0.0
>
>
> My problems:
> 1. Why is itim not reinitialized, neither in the 2 calls of i1 in one 
> performance, nor in the second rendering?
> 2. Why is itim rounded to an integer?
> 3. Why is "pythonzeit" and "itim" not the same value, at least at the 
> first call of the instrument?
> 4. "pythonzeit" seems not to increase correctly; the difference in 
> starting time between the two instances of instr 1 should result in a 
> difference of the 2 printouts of "pythonzeit" of 1.1 seconds, but it's 
> less.
>
> I am using Python 2.5 on OS X 10.4. Csound 5.06 (via Terminal).
>
> Thanks for any help -
>
> joachim
>
>
>
> ------------------------------------------------------------------------
>


-- 
www.cesaremarilungo.com