[Csnd] Get Output Channel Pointer Csound Python API

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Csnd] Get Output Channel Pointer Csound Python API

epalaima
Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

Victor Lazzarini
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

Francois PINOT
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

epalaima
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

Francois PINOT
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

epalaima
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

Francois PINOT
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

epalaima
One more question. I'm running into a strange issue where the csds I run in ctcsound will reach the end of the score instantly and stop playing if they have an empty score (I often have an empty score since I mainly use Csound for signal processing or instrument design rather than composition, I use turnon and the like for the instruments). I have tried adding an empty ftable to the score as well as using an i statement i 1 0 -1 (run instrument 1 indefinitely) in the place of turnon. 

Any idea what might be causing this?

I am succeeding in getting the message output from Csound to my Python program. Thanks for all your help with that!

Here is the CSD and Python Program I am using for testing, as well the output from Csound:

CSD:
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0,0
-+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
turnon "test"
instr test
printks "\n\n5th!\n\n", .1
ares lfo .5, 220, 1
a5 lfo .5, 330, 1
outs ares+a5, ares+a5
endin

</CsInstruments>
<CsScore>
f 0 14400
</CsScore>
</CsoundSynthesizer>


Python:


import ctcsound
cs = ctcsound.Csound() 
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)
def StopCsound():
t.stop()
t.join()
def PlayCSD(csdName):
ret = cs.compile_("csound", csdName)
if ret == ctcsound.CSOUND_SUCCESS:
t = ctcsound.CsoundPerformanceThread(cs.csound())
t.play()

PlayCSD("5th.csd")

while True:
x = 0
StopCsound()


Csound Output:


virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09 (double samples) May 21 2017 
[commit: 4a54f2ccc6de1a05764028d5000f7d20fb4fda6e]
libsndfile-1.0.25
UnifiedCSD:  5th.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
instr test uses instrument number 1
Elapsed time at end of orchestra compile: real: 0.036s, CPU: 0.025s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.039s, CPU: 0.026s
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA output: total buffer size: 1024, period size: 256 
writing 512 sample blks of 64-bit floats to dac:hw:0,0 
SECTION 1:
inactive allocs returned to freespace
end of score.   overall amps:  0.00000  0.00000
  overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.073s, CPU: 0.049s
0 512 sample blks of 64-bit floats written to dac:hw:0,0


On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <[hidden email]> wrote:
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

Francois PINOT
It's a scope problem. You declare a second performance thread inside your PlayCSD function, so the performance thread declared at the global level is hidden by the second one. Here's the solution:

<CsoundSynthesizer>
<CsOptions>
  -odac:hw:0,0
  -+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 128
nchnls = 2
0dbfs  = 1.0

turnon "test"
instr test
       printks "\n\n5th!\n\n", .1
  ares lfo     .5, 220, 1
  a5   lfo     .5, 330, 1
       outs    ares+a5, ares+a5
endin
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

----------------------------------------------------------

import ctcsound

cs = ctcsound.Csound()
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)

def StopCsound():
    t.stop()
    t.join()

def PlayCSD(csdName):
    ret = cs.compile_("csound", csdName)
    if ret == ctcsound.CSOUND_SUCCESS:
        t.play()

PlayCSD("5th.csd")

while True:
    x = input()
    if x == 0:
        break
StopCsound()


François



2017-07-16 0:10 GMT+02:00 Emmett Palaima <[hidden email]>:
One more question. I'm running into a strange issue where the csds I run in ctcsound will reach the end of the score instantly and stop playing if they have an empty score (I often have an empty score since I mainly use Csound for signal processing or instrument design rather than composition, I use turnon and the like for the instruments). I have tried adding an empty ftable to the score as well as using an i statement i 1 0 -1 (run instrument 1 indefinitely) in the place of turnon. 

Any idea what might be causing this?

I am succeeding in getting the message output from Csound to my Python program. Thanks for all your help with that!

Here is the CSD and Python Program I am using for testing, as well the output from Csound:

CSD:
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0,0
-+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
turnon "test"
instr test
printks "\n\n5th!\n\n", .1
ares lfo .5, 220, 1
a5 lfo .5, 330, 1
outs ares+a5, ares+a5
endin

</CsInstruments>
<CsScore>
f 0 14400
</CsScore>
</CsoundSynthesizer>


Python:


import ctcsound
cs = ctcsound.Csound() 
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)
def StopCsound():
t.stop()
t.join()
def PlayCSD(csdName):
ret = cs.compile_("csound", csdName)
if ret == ctcsound.CSOUND_SUCCESS:
t = ctcsound.CsoundPerformanceThread(cs.csound())
t.play()

PlayCSD("5th.csd")

while True:
x = 0
StopCsound()


Csound Output:


virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09 (double samples) May 21 2017 
[commit: 4a54f2ccc6de1a05764028d5000f7d20fb4fda6e]
libsndfile-1.0.25
UnifiedCSD:  5th.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
instr test uses instrument number 1
Elapsed time at end of orchestra compile: real: 0.036s, CPU: 0.025s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.039s, CPU: 0.026s
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA output: total buffer size: 1024, period size: 256 
writing 512 sample blks of 64-bit floats to dac:hw:0,0 
SECTION 1:
inactive allocs returned to freespace
end of score.   overall amps:  0.00000  0.00000
  overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.073s, CPU: 0.049s
0 512 sample blks of 64-bit floats written to dac:hw:0,0


On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <[hidden email]> wrote:
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

epalaima
Okay thanks, that makes sense. On that note, how does t.join() work? Does that destroy the thread so that another would have to be created if I want to use a thread again?

In my program I am going to be playing and stopping multiple csds sequentially in the performance thread so what is the best way to stop the csd from playing and clear up whatever resources are in use? Would it be just:

t.stop()

Thanks!


On Jul 16, 2017, at 3:31 AM, Francois PINOT <[hidden email]> wrote:

It's a scope problem. You declare a second performance thread inside your PlayCSD function, so the performance thread declared at the global level is hidden by the second one. Here's the solution:

<CsoundSynthesizer>
<CsOptions>
  -odac:hw:0,0
  -+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 128
nchnls = 2
0dbfs  = 1.0

turnon "test"
instr test
       printks "\n\n5th!\n\n", .1
  ares lfo     .5, 220, 1
  a5   lfo     .5, 330, 1
       outs    ares+a5, ares+a5
endin
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

----------------------------------------------------------

import ctcsound

cs = ctcsound.Csound()
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)

def StopCsound():
    t.stop()
    t.join()

def PlayCSD(csdName):
    ret = cs.compile_("csound", csdName)
    if ret == ctcsound.CSOUND_SUCCESS:
        t.play()

PlayCSD("5th.csd")

while True:
    x = input()
    if x == 0:
        break
StopCsound()


François



2017-07-16 0:10 GMT+02:00 Emmett Palaima <[hidden email]>:
One more question. I'm running into a strange issue where the csds I run in ctcsound will reach the end of the score instantly and stop playing if they have an empty score (I often have an empty score since I mainly use Csound for signal processing or instrument design rather than composition, I use turnon and the like for the instruments). I have tried adding an empty ftable to the score as well as using an i statement i 1 0 -1 (run instrument 1 indefinitely) in the place of turnon. 

Any idea what might be causing this?

I am succeeding in getting the message output from Csound to my Python program. Thanks for all your help with that!

Here is the CSD and Python Program I am using for testing, as well the output from Csound:

CSD:
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0,0
-+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
turnon "test"
instr test
printks "\n\n5th!\n\n", .1
ares lfo .5, 220, 1
a5 lfo .5, 330, 1
outs ares+a5, ares+a5
endin

</CsInstruments>
<CsScore>
f 0 14400
</CsScore>
</CsoundSynthesizer>


Python:


import ctcsound
cs = ctcsound.Csound() 
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)
def StopCsound():
t.stop()
t.join()
def PlayCSD(csdName):
ret = cs.compile_("csound", csdName)
if ret == ctcsound.CSOUND_SUCCESS:
t = ctcsound.CsoundPerformanceThread(cs.csound())
t.play()

PlayCSD("5th.csd")

while True:
x = 0
StopCsound()


Csound Output:


virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09 (double samples) May 21 2017 
[commit: 4a54f2ccc6de1a05764028d5000f7d20fb4fda6e]
libsndfile-1.0.25
UnifiedCSD:  5th.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
instr test uses instrument number 1
Elapsed time at end of orchestra compile: real: 0.036s, CPU: 0.025s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.039s, CPU: 0.026s
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA output: total buffer size: 1024, period size: 256 
writing 512 sample blks of 64-bit floats to dac:hw:0,0 
SECTION 1:
inactive allocs returned to freespace
end of score.   overall amps:  0.00000  0.00000
  overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.073s, CPU: 0.049s
0 512 sample blks of 64-bit floats written to dac:hw:0,0


On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <[hidden email]> wrote:
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

Victor Lazzarini
Join() just joins the thread. It blocks until
the thread is finished. Stop() makes the thread
finish.Join is used to make sure the thread is completed before moving on.

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 16 Jul 2017, at 16:21, Emmett Palaima <[hidden email]> wrote:

Okay thanks, that makes sense. On that note, how does t.join() work? Does that destroy the thread so that another would have to be created if I want to use a thread again?

In my program I am going to be playing and stopping multiple csds sequentially in the performance thread so what is the best way to stop the csd from playing and clear up whatever resources are in use? Would it be just:

t.stop()

Thanks!


On Jul 16, 2017, at 3:31 AM, Francois PINOT <[hidden email]> wrote:

It's a scope problem. You declare a second performance thread inside your PlayCSD function, so the performance thread declared at the global level is hidden by the second one. Here's the solution:

<CsoundSynthesizer>
<CsOptions>
  -odac:hw:0,0
  -+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 128
nchnls = 2
0dbfs  = 1.0

turnon "test"
instr test
       printks "\n\n5th!\n\n", .1
  ares lfo     .5, 220, 1
  a5   lfo     .5, 330, 1
       outs    ares+a5, ares+a5
endin
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

----------------------------------------------------------

import ctcsound

cs = ctcsound.Csound()
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)

def StopCsound():
    t.stop()
    t.join()

def PlayCSD(csdName):
    ret = cs.compile_("csound", csdName)
    if ret == ctcsound.CSOUND_SUCCESS:
        t.play()

PlayCSD("5th.csd")

while True:
    x = input()
    if x == 0:
        break
StopCsound()


François



2017-07-16 0:10 GMT+02:00 Emmett Palaima <[hidden email]>:
One more question. I'm running into a strange issue where the csds I run in ctcsound will reach the end of the score instantly and stop playing if they have an empty score (I often have an empty score since I mainly use Csound for signal processing or instrument design rather than composition, I use turnon and the like for the instruments). I have tried adding an empty ftable to the score as well as using an i statement i 1 0 -1 (run instrument 1 indefinitely) in the place of turnon. 

Any idea what might be causing this?

I am succeeding in getting the message output from Csound to my Python program. Thanks for all your help with that!

Here is the CSD and Python Program I am using for testing, as well the output from Csound:

CSD:
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0,0
-+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
turnon "test"
instr test
printks "\n\n5th!\n\n", .1
ares lfo .5, 220, 1
a5 lfo .5, 330, 1
outs ares+a5, ares+a5
endin

</CsInstruments>
<CsScore>
f 0 14400
</CsScore>
</CsoundSynthesizer>


Python:


import ctcsound
cs = ctcsound.Csound() 
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)
def StopCsound():
t.stop()
t.join()
def PlayCSD(csdName):
ret = cs.compile_("csound", csdName)
if ret == ctcsound.CSOUND_SUCCESS:
t = ctcsound.CsoundPerformanceThread(cs.csound())
t.play()

PlayCSD("5th.csd")

while True:
x = 0
StopCsound()


Csound Output:


virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09 (double samples) May 21 2017 
[commit: 4a54f2ccc6de1a05764028d5000f7d20fb4fda6e]
libsndfile-1.0.25
UnifiedCSD:  5th.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
instr test uses instrument number 1
Elapsed time at end of orchestra compile: real: 0.036s, CPU: 0.025s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.039s, CPU: 0.026s
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA output: total buffer size: 1024, period size: 256 
writing 512 sample blks of 64-bit floats to dac:hw:0,0 
SECTION 1:
inactive allocs returned to freespace
end of score.   overall amps:  0.00000  0.00000
  overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.073s, CPU: 0.049s
0 512 sample blks of 64-bit floats written to dac:hw:0,0


On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <[hidden email]> wrote:
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

epalaima
In reply to this post by epalaima
I am also getting an error when trying to get the value of an audio channel in python as follows:

audio = cs.audioChannel("Audio", 128)

Also tried:
print(cs.audioChannel("Audio", 128)) 
and
audio, myType = cs.audioChannel("Audio", 128)

In my csd ksmps = 128 and I am setting the value of the channel as follows:

chnset aout, "Audio"


I get the following error:

 Traceback (most recent call last):
  File "ctcscope.py", line 165, in <module>
    Scope()
  File "ctcscope.py", line 146, in Scope
    audio = cs.audioChannel("Audio", 128)
  File "/home/pi/.local/lib/python2.7/site-packages/ctcsound.py", line 1603, in audioChannel
    ptr = samples.ctypes.data_as(POINTER(MYFLT))
AttributeError: 'int' object has no attribute 'ctypes'

Any idea what is causing this? Getting the value of control channels works correctly.

On Sun, Jul 16, 2017 at 11:21 AM, Emmett Palaima <[hidden email]> wrote:
Okay thanks, that makes sense. On that note, how does t.join() work? Does that destroy the thread so that another would have to be created if I want to use a thread again?

In my program I am going to be playing and stopping multiple csds sequentially in the performance thread so what is the best way to stop the csd from playing and clear up whatever resources are in use? Would it be just:

t.stop()

Thanks!


On Jul 16, 2017, at 3:31 AM, Francois PINOT <[hidden email]> wrote:

It's a scope problem. You declare a second performance thread inside your PlayCSD function, so the performance thread declared at the global level is hidden by the second one. Here's the solution:

<CsoundSynthesizer>
<CsOptions>
  -odac:hw:0,0
  -+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 128
nchnls = 2
0dbfs  = 1.0

turnon "test"
instr test
       printks "\n\n5th!\n\n", .1
  ares lfo     .5, 220, 1
  a5   lfo     .5, 330, 1
       outs    ares+a5, ares+a5
endin
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

----------------------------------------------------------

import ctcsound

cs = ctcsound.Csound()
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)

def StopCsound():
    t.stop()
    t.join()

def PlayCSD(csdName):
    ret = cs.compile_("csound", csdName)
    if ret == ctcsound.CSOUND_SUCCESS:
        t.play()

PlayCSD("5th.csd")

while True:
    x = input()
    if x == 0:
        break
StopCsound()


François



2017-07-16 0:10 GMT+02:00 Emmett Palaima <[hidden email]>:
One more question. I'm running into a strange issue where the csds I run in ctcsound will reach the end of the score instantly and stop playing if they have an empty score (I often have an empty score since I mainly use Csound for signal processing or instrument design rather than composition, I use turnon and the like for the instruments). I have tried adding an empty ftable to the score as well as using an i statement i 1 0 -1 (run instrument 1 indefinitely) in the place of turnon. 

Any idea what might be causing this?

I am succeeding in getting the message output from Csound to my Python program. Thanks for all your help with that!

Here is the CSD and Python Program I am using for testing, as well the output from Csound:

CSD:
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0,0
-+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
turnon "test"
instr test
printks "\n\n5th!\n\n", .1
ares lfo .5, 220, 1
a5 lfo .5, 330, 1
outs ares+a5, ares+a5
endin

</CsInstruments>
<CsScore>
f 0 14400
</CsScore>
</CsoundSynthesizer>


Python:


import ctcsound
cs = ctcsound.Csound() 
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)
def StopCsound():
t.stop()
t.join()
def PlayCSD(csdName):
ret = cs.compile_("csound", csdName)
if ret == ctcsound.CSOUND_SUCCESS:
t = ctcsound.CsoundPerformanceThread(cs.csound())
t.play()

PlayCSD("5th.csd")

while True:
x = 0
StopCsound()


Csound Output:


virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09 (double samples) May 21 2017 
[commit: 4a54f2ccc6de1a05764028d5000f7d20fb4fda6e]
libsndfile-1.0.25
UnifiedCSD:  5th.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
instr test uses instrument number 1
Elapsed time at end of orchestra compile: real: 0.036s, CPU: 0.025s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.039s, CPU: 0.026s
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA output: total buffer size: 1024, period size: 256 
writing 512 sample blks of 64-bit floats to dac:hw:0,0 
SECTION 1:
inactive allocs returned to freespace
end of score.   overall amps:  0.00000  0.00000
  overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.073s, CPU: 0.049s
0 512 sample blks of 64-bit floats written to dac:hw:0,0


On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <[hidden email]> wrote:
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

Victor Lazzarini
 Indexing is zero-based, 0 to ksmps-1

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 16 Jul 2017, at 18:42, Emmett Palaima <[hidden email]> wrote:

I am also getting an error when trying to get the value of an audio channel in python as follows:

audio = cs.audioChannel("Audio", 128)

Also tried:
print(cs.audioChannel("Audio", 128)) 
and
audio, myType = cs.audioChannel("Audio", 128)

In my csd ksmps = 128 and I am setting the value of the channel as follows:

chnset aout, "Audio"


I get the following error:

 Traceback (most recent call last):
  File "ctcscope.py", line 165, in <module>
    Scope()
  File "ctcscope.py", line 146, in Scope
    audio = cs.audioChannel("Audio", 128)
  File "/home/pi/.local/lib/python2.7/site-packages/ctcsound.py", line 1603, in audioChannel
    ptr = samples.ctypes.data_as(POINTER(MYFLT))
AttributeError: 'int' object has no attribute 'ctypes'

Any idea what is causing this? Getting the value of control channels works correctly.

On Sun, Jul 16, 2017 at 11:21 AM, Emmett Palaima <[hidden email]> wrote:
Okay thanks, that makes sense. On that note, how does t.join() work? Does that destroy the thread so that another would have to be created if I want to use a thread again?

In my program I am going to be playing and stopping multiple csds sequentially in the performance thread so what is the best way to stop the csd from playing and clear up whatever resources are in use? Would it be just:

t.stop()

Thanks!


On Jul 16, 2017, at 3:31 AM, Francois PINOT <[hidden email]> wrote:

It's a scope problem. You declare a second performance thread inside your PlayCSD function, so the performance thread declared at the global level is hidden by the second one. Here's the solution:

<CsoundSynthesizer>
<CsOptions>
  -odac:hw:0,0
  -+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 128
nchnls = 2
0dbfs  = 1.0

turnon "test"
instr test
       printks "\n\n5th!\n\n", .1
  ares lfo     .5, 220, 1
  a5   lfo     .5, 330, 1
       outs    ares+a5, ares+a5
endin
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

----------------------------------------------------------

import ctcsound

cs = ctcsound.Csound()
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)

def StopCsound():
    t.stop()
    t.join()

def PlayCSD(csdName):
    ret = cs.compile_("csound", csdName)
    if ret == ctcsound.CSOUND_SUCCESS:
        t.play()

PlayCSD("5th.csd")

while True:
    x = input()
    if x == 0:
        break
StopCsound()


François



2017-07-16 0:10 GMT+02:00 Emmett Palaima <[hidden email]>:
One more question. I'm running into a strange issue where the csds I run in ctcsound will reach the end of the score instantly and stop playing if they have an empty score (I often have an empty score since I mainly use Csound for signal processing or instrument design rather than composition, I use turnon and the like for the instruments). I have tried adding an empty ftable to the score as well as using an i statement i 1 0 -1 (run instrument 1 indefinitely) in the place of turnon. 

Any idea what might be causing this?

I am succeeding in getting the message output from Csound to my Python program. Thanks for all your help with that!

Here is the CSD and Python Program I am using for testing, as well the output from Csound:

CSD:
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0,0
-+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
turnon "test"
instr test
printks "\n\n5th!\n\n", .1
ares lfo .5, 220, 1
a5 lfo .5, 330, 1
outs ares+a5, ares+a5
endin

</CsInstruments>
<CsScore>
f 0 14400
</CsScore>
</CsoundSynthesizer>


Python:


import ctcsound
cs = ctcsound.Csound() 
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)
def StopCsound():
t.stop()
t.join()
def PlayCSD(csdName):
ret = cs.compile_("csound", csdName)
if ret == ctcsound.CSOUND_SUCCESS:
t = ctcsound.CsoundPerformanceThread(cs.csound())
t.play()

PlayCSD("5th.csd")

while True:
x = 0
StopCsound()


Csound Output:


virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09 (double samples) May 21 2017 
[commit: 4a54f2ccc6de1a05764028d5000f7d20fb4fda6e]
libsndfile-1.0.25
UnifiedCSD:  5th.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
instr test uses instrument number 1
Elapsed time at end of orchestra compile: real: 0.036s, CPU: 0.025s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.039s, CPU: 0.026s
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA output: total buffer size: 1024, period size: 256 
writing 512 sample blks of 64-bit floats to dac:hw:0,0 
SECTION 1:
inactive allocs returned to freespace
end of score.   overall amps:  0.00000  0.00000
  overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.073s, CPU: 0.049s
0 512 sample blks of 64-bit floats written to dac:hw:0,0


On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <[hidden email]> wrote:
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

Francois PINOT
In reply to this post by epalaima
You might consider using "Real-time" performance mode:

1-Create a csound instance
2-Set options
3-Set params
4-Start the csound engine
5-Start a performance thread
6-Compile csd's, orchestras and/or scores as needed
7-Events loop (you can also compile csd's, orchestras, and scores within the loop)
8-Finish the performance thread and the program.

Notice that options and params inside csd's are not read.

Here's an example:

import ctcsound

csd1 = '''<CsoundSynthesizer>

<CsOptions>
  -d -o dac -m0
</CsOptions>

<CsInstruments>
sr     = 48000
ksmps  = 100
nchnls = 2
0dbfs  = 1

          instr 1
idur      =         p3
iamp      =         p4
icps      =         cpspch(p5)
irise     =         p6
idec      =         p7
ipan      =         p8

kenv      linen     iamp, irise, idur, idec
kenv      =         kenv*kenv
asig      poscil    kenv, icps
a1, a2    pan2      asig, ipan
          outs      a1, a2
          endin
</CsInstruments>

<CsScore>
</CsScore>
</CsoundSynthesizer>'''

cs = ctcsound.Csound()
cs.setOption("-d")
cs.setOption("-odac")
p = ctcsound.CsoundParams()
cs.createMessageBuffer(toStdOut=False)

cs.params(p)
p.nchnls_override = 2
p.e0dbfs_override = 1.0
cs.setParams(p)
cs.start()
pt = ctcsound.CsoundPerformanceThread(cs.csound())
pt.play()
cs.compileCsdText(csd1)
cs.compileCsd("5th.csd")

while True:
    c = input()
    if c == 1:
        pt.scoreEvent(False, 'i', (1, 0, 1, 0.5, 8.06, 0.05, 0.3, 0.5))
    elif c == 2:
        pt.scoreEvent(False, 'i', (1, 0.5, 1, 0.5, 9.06, 0.05, 0.3, 0.5))
    elif c == 0:
        break

pt.stop()
pt.join()

François

2017-07-16 17:21 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay thanks, that makes sense. On that note, how does t.join() work? Does that destroy the thread so that another would have to be created if I want to use a thread again?

In my program I am going to be playing and stopping multiple csds sequentially in the performance thread so what is the best way to stop the csd from playing and clear up whatever resources are in use? Would it be just:

t.stop()

Thanks!


On Jul 16, 2017, at 3:31 AM, Francois PINOT <[hidden email]> wrote:

It's a scope problem. You declare a second performance thread inside your PlayCSD function, so the performance thread declared at the global level is hidden by the second one. Here's the solution:

<CsoundSynthesizer>
<CsOptions>
  -odac:hw:0,0
  -+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 128
nchnls = 2
0dbfs  = 1.0

turnon "test"
instr test
       printks "\n\n5th!\n\n", .1
  ares lfo     .5, 220, 1
  a5   lfo     .5, 330, 1
       outs    ares+a5, ares+a5
endin
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

----------------------------------------------------------

import ctcsound

cs = ctcsound.Csound()
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)

def StopCsound():
    t.stop()
    t.join()

def PlayCSD(csdName):
    ret = cs.compile_("csound", csdName)
    if ret == ctcsound.CSOUND_SUCCESS:
        t.play()

PlayCSD("5th.csd")

while True:
    x = input()
    if x == 0:
        break
StopCsound()


François



2017-07-16 0:10 GMT+02:00 Emmett Palaima <[hidden email]>:
One more question. I'm running into a strange issue where the csds I run in ctcsound will reach the end of the score instantly and stop playing if they have an empty score (I often have an empty score since I mainly use Csound for signal processing or instrument design rather than composition, I use turnon and the like for the instruments). I have tried adding an empty ftable to the score as well as using an i statement i 1 0 -1 (run instrument 1 indefinitely) in the place of turnon. 

Any idea what might be causing this?

I am succeeding in getting the message output from Csound to my Python program. Thanks for all your help with that!

Here is the CSD and Python Program I am using for testing, as well the output from Csound:

CSD:
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0,0
-+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
turnon "test"
instr test
printks "\n\n5th!\n\n", .1
ares lfo .5, 220, 1
a5 lfo .5, 330, 1
outs ares+a5, ares+a5
endin

</CsInstruments>
<CsScore>
f 0 14400
</CsScore>
</CsoundSynthesizer>


Python:


import ctcsound
cs = ctcsound.Csound() 
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)
def StopCsound():
t.stop()
t.join()
def PlayCSD(csdName):
ret = cs.compile_("csound", csdName)
if ret == ctcsound.CSOUND_SUCCESS:
t = ctcsound.CsoundPerformanceThread(cs.csound())
t.play()

PlayCSD("5th.csd")

while True:
x = 0
StopCsound()


Csound Output:


virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09 (double samples) May 21 2017 
[commit: 4a54f2ccc6de1a05764028d5000f7d20fb4fda6e]
libsndfile-1.0.25
UnifiedCSD:  5th.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
instr test uses instrument number 1
Elapsed time at end of orchestra compile: real: 0.036s, CPU: 0.025s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.039s, CPU: 0.026s
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA output: total buffer size: 1024, period size: 256 
writing 512 sample blks of 64-bit floats to dac:hw:0,0 
SECTION 1:
inactive allocs returned to freespace
end of score.   overall amps:  0.00000  0.00000
  overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.073s, CPU: 0.049s
0 512 sample blks of 64-bit floats written to dac:hw:0,0


On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <[hidden email]> wrote:
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

epalaima
How would I stop the currently playing csd and then launch another using this method?

I am trying to do that now but get an error:

Csound is already started, call csoundReset()
before starting again 

But when I add cs.reset() to my StopCsound function I get a segmentation fault. This seems to happen no matter where in the program cs.reset() is located?

Any idea what is causing this? Also do you have any advice to give on the audioChannel error? 

On Sun, Jul 16, 2017 at 3:14 PM, Francois PINOT <[hidden email]> wrote:
You might consider using "Real-time" performance mode:

1-Create a csound instance
2-Set options
3-Set params
4-Start the csound engine
5-Start a performance thread
6-Compile csd's, orchestras and/or scores as needed
7-Events loop (you can also compile csd's, orchestras, and scores within the loop)
8-Finish the performance thread and the program.

Notice that options and params inside csd's are not read.

Here's an example:

import ctcsound

csd1 = '''<CsoundSynthesizer>

<CsOptions>
  -d -o dac -m0
</CsOptions>

<CsInstruments>
sr     = 48000
ksmps  = 100
nchnls = 2
0dbfs  = 1

          instr 1
idur      =         p3
iamp      =         p4
icps      =         cpspch(p5)
irise     =         p6
idec      =         p7
ipan      =         p8

kenv      linen     iamp, irise, idur, idec
kenv      =         kenv*kenv
asig      poscil    kenv, icps
a1, a2    pan2      asig, ipan
          outs      a1, a2
          endin
</CsInstruments>

<CsScore>
</CsScore>
</CsoundSynthesizer>'''

cs = ctcsound.Csound()
cs.setOption("-d")
cs.setOption("-odac")
p = ctcsound.CsoundParams()
cs.createMessageBuffer(toStdOut=False)

cs.params(p)
p.nchnls_override = 2
p.e0dbfs_override = 1.0
cs.setParams(p)
cs.start()
pt = ctcsound.CsoundPerformanceThread(cs.csound())
pt.play()
cs.compileCsdText(csd1)
cs.compileCsd("5th.csd")

while True:
    c = input()
    if c == 1:
        pt.scoreEvent(False, 'i', (1, 0, 1, 0.5, 8.06, 0.05, 0.3, 0.5))
    elif c == 2:
        pt.scoreEvent(False, 'i', (1, 0.5, 1, 0.5, 9.06, 0.05, 0.3, 0.5))
    elif c == 0:
        break

pt.stop()
pt.join()

François

2017-07-16 17:21 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay thanks, that makes sense. On that note, how does t.join() work? Does that destroy the thread so that another would have to be created if I want to use a thread again?

In my program I am going to be playing and stopping multiple csds sequentially in the performance thread so what is the best way to stop the csd from playing and clear up whatever resources are in use? Would it be just:

t.stop()

Thanks!


On Jul 16, 2017, at 3:31 AM, Francois PINOT <[hidden email]> wrote:

It's a scope problem. You declare a second performance thread inside your PlayCSD function, so the performance thread declared at the global level is hidden by the second one. Here's the solution:

<CsoundSynthesizer>
<CsOptions>
  -odac:hw:0,0
  -+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 128
nchnls = 2
0dbfs  = 1.0

turnon "test"
instr test
       printks "\n\n5th!\n\n", .1
  ares lfo     .5, 220, 1
  a5   lfo     .5, 330, 1
       outs    ares+a5, ares+a5
endin
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

----------------------------------------------------------

import ctcsound

cs = ctcsound.Csound()
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)

def StopCsound():
    t.stop()
    t.join()

def PlayCSD(csdName):
    ret = cs.compile_("csound", csdName)
    if ret == ctcsound.CSOUND_SUCCESS:
        t.play()

PlayCSD("5th.csd")

while True:
    x = input()
    if x == 0:
        break
StopCsound()


François



2017-07-16 0:10 GMT+02:00 Emmett Palaima <[hidden email]>:
One more question. I'm running into a strange issue where the csds I run in ctcsound will reach the end of the score instantly and stop playing if they have an empty score (I often have an empty score since I mainly use Csound for signal processing or instrument design rather than composition, I use turnon and the like for the instruments). I have tried adding an empty ftable to the score as well as using an i statement i 1 0 -1 (run instrument 1 indefinitely) in the place of turnon. 

Any idea what might be causing this?

I am succeeding in getting the message output from Csound to my Python program. Thanks for all your help with that!

Here is the CSD and Python Program I am using for testing, as well the output from Csound:

CSD:
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0,0
-+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
turnon "test"
instr test
printks "\n\n5th!\n\n", .1
ares lfo .5, 220, 1
a5 lfo .5, 330, 1
outs ares+a5, ares+a5
endin

</CsInstruments>
<CsScore>
f 0 14400
</CsScore>
</CsoundSynthesizer>


Python:


import ctcsound
cs = ctcsound.Csound() 
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)
def StopCsound():
t.stop()
t.join()
def PlayCSD(csdName):
ret = cs.compile_("csound", csdName)
if ret == ctcsound.CSOUND_SUCCESS:
t = ctcsound.CsoundPerformanceThread(cs.csound())
t.play()

PlayCSD("5th.csd")

while True:
x = 0
StopCsound()


Csound Output:


virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09 (double samples) May 21 2017 
[commit: 4a54f2ccc6de1a05764028d5000f7d20fb4fda6e]
libsndfile-1.0.25
UnifiedCSD:  5th.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
instr test uses instrument number 1
Elapsed time at end of orchestra compile: real: 0.036s, CPU: 0.025s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.039s, CPU: 0.026s
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA output: total buffer size: 1024, period size: 256 
writing 512 sample blks of 64-bit floats to dac:hw:0,0 
SECTION 1:
inactive allocs returned to freespace
end of score.   overall amps:  0.00000  0.00000
  overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.073s, CPU: 0.049s
0 512 sample blks of 64-bit floats written to dac:hw:0,0


On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <[hidden email]> wrote:
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

epalaima
Nevermind, I figured out that I needed to call cs.destroyMessageBuffer() before calling cs.reset()

That just leaves the audioChannel error: 

I am also getting an error when trying to get the value of an audio channel in python as follows:

audio = cs.audioChannel("Audio", 128)

Also tried:
print(cs.audioChannel("Audio", 128)) 
and
audio, myType = cs.audioChannel("Audio", 128)

In my csd ksmps = 128 and I am setting the value of the channel as follows:

chnset aout, "Audio"


I get the following error:

 Traceback (most recent call last):
  File "ctcscope.py", line 165, in <module>
    Scope()
  File "ctcscope.py", line 146, in Scope
    audio = cs.audioChannel("Audio", 128)
  File "/home/pi/.local/lib/python2.7/site-packages/ctcsound.py", line 1603, in audioChannel
    ptr = samples.ctypes.data_as(POINTER(MYFLT))
AttributeError: 'int' object has no attribute 'ctypes'


On Sun, Jul 16, 2017 at 3:29 PM, Emmett Palaima <[hidden email]> wrote:
How would I stop the currently playing csd and then launch another using this method?

I am trying to do that now but get an error:

Csound is already started, call csoundReset()
before starting again 

But when I add cs.reset() to my StopCsound function I get a segmentation fault. This seems to happen no matter where in the program cs.reset() is located?

Any idea what is causing this? Also do you have any advice to give on the audioChannel error? 

On Sun, Jul 16, 2017 at 3:14 PM, Francois PINOT <[hidden email]> wrote:
You might consider using "Real-time" performance mode:

1-Create a csound instance
2-Set options
3-Set params
4-Start the csound engine
5-Start a performance thread
6-Compile csd's, orchestras and/or scores as needed
7-Events loop (you can also compile csd's, orchestras, and scores within the loop)
8-Finish the performance thread and the program.

Notice that options and params inside csd's are not read.

Here's an example:

import ctcsound

csd1 = '''<CsoundSynthesizer>

<CsOptions>
  -d -o dac -m0
</CsOptions>

<CsInstruments>
sr     = 48000
ksmps  = 100
nchnls = 2
0dbfs  = 1

          instr 1
idur      =         p3
iamp      =         p4
icps      =         cpspch(p5)
irise     =         p6
idec      =         p7
ipan      =         p8

kenv      linen     iamp, irise, idur, idec
kenv      =         kenv*kenv
asig      poscil    kenv, icps
a1, a2    pan2      asig, ipan
          outs      a1, a2
          endin
</CsInstruments>

<CsScore>
</CsScore>
</CsoundSynthesizer>'''

cs = ctcsound.Csound()
cs.setOption("-d")
cs.setOption("-odac")
p = ctcsound.CsoundParams()
cs.createMessageBuffer(toStdOut=False)

cs.params(p)
p.nchnls_override = 2
p.e0dbfs_override = 1.0
cs.setParams(p)
cs.start()
pt = ctcsound.CsoundPerformanceThread(cs.csound())
pt.play()
cs.compileCsdText(csd1)
cs.compileCsd("5th.csd")

while True:
    c = input()
    if c == 1:
        pt.scoreEvent(False, 'i', (1, 0, 1, 0.5, 8.06, 0.05, 0.3, 0.5))
    elif c == 2:
        pt.scoreEvent(False, 'i', (1, 0.5, 1, 0.5, 9.06, 0.05, 0.3, 0.5))
    elif c == 0:
        break

pt.stop()
pt.join()

François

2017-07-16 17:21 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay thanks, that makes sense. On that note, how does t.join() work? Does that destroy the thread so that another would have to be created if I want to use a thread again?

In my program I am going to be playing and stopping multiple csds sequentially in the performance thread so what is the best way to stop the csd from playing and clear up whatever resources are in use? Would it be just:

t.stop()

Thanks!


On Jul 16, 2017, at 3:31 AM, Francois PINOT <[hidden email]> wrote:

It's a scope problem. You declare a second performance thread inside your PlayCSD function, so the performance thread declared at the global level is hidden by the second one. Here's the solution:

<CsoundSynthesizer>
<CsOptions>
  -odac:hw:0,0
  -+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 128
nchnls = 2
0dbfs  = 1.0

turnon "test"
instr test
       printks "\n\n5th!\n\n", .1
  ares lfo     .5, 220, 1
  a5   lfo     .5, 330, 1
       outs    ares+a5, ares+a5
endin
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

----------------------------------------------------------

import ctcsound

cs = ctcsound.Csound()
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)

def StopCsound():
    t.stop()
    t.join()

def PlayCSD(csdName):
    ret = cs.compile_("csound", csdName)
    if ret == ctcsound.CSOUND_SUCCESS:
        t.play()

PlayCSD("5th.csd")

while True:
    x = input()
    if x == 0:
        break
StopCsound()


François



2017-07-16 0:10 GMT+02:00 Emmett Palaima <[hidden email]>:
One more question. I'm running into a strange issue where the csds I run in ctcsound will reach the end of the score instantly and stop playing if they have an empty score (I often have an empty score since I mainly use Csound for signal processing or instrument design rather than composition, I use turnon and the like for the instruments). I have tried adding an empty ftable to the score as well as using an i statement i 1 0 -1 (run instrument 1 indefinitely) in the place of turnon. 

Any idea what might be causing this?

I am succeeding in getting the message output from Csound to my Python program. Thanks for all your help with that!

Here is the CSD and Python Program I am using for testing, as well the output from Csound:

CSD:
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0,0
-+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
turnon "test"
instr test
printks "\n\n5th!\n\n", .1
ares lfo .5, 220, 1
a5 lfo .5, 330, 1
outs ares+a5, ares+a5
endin

</CsInstruments>
<CsScore>
f 0 14400
</CsScore>
</CsoundSynthesizer>


Python:


import ctcsound
cs = ctcsound.Csound() 
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)
def StopCsound():
t.stop()
t.join()
def PlayCSD(csdName):
ret = cs.compile_("csound", csdName)
if ret == ctcsound.CSOUND_SUCCESS:
t = ctcsound.CsoundPerformanceThread(cs.csound())
t.play()

PlayCSD("5th.csd")

while True:
x = 0
StopCsound()


Csound Output:


virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09 (double samples) May 21 2017 
[commit: 4a54f2ccc6de1a05764028d5000f7d20fb4fda6e]
libsndfile-1.0.25
UnifiedCSD:  5th.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
instr test uses instrument number 1
Elapsed time at end of orchestra compile: real: 0.036s, CPU: 0.025s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.039s, CPU: 0.026s
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA output: total buffer size: 1024, period size: 256 
writing 512 sample blks of 64-bit floats to dac:hw:0,0 
SECTION 1:
inactive allocs returned to freespace
end of score.   overall amps:  0.00000  0.00000
  overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.073s, CPU: 0.049s
0 512 sample blks of 64-bit floats written to dac:hw:0,0


On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <[hidden email]> wrote:
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

Victor Lazzarini
128 is out of range for ksmps=128 as I replied before.

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 16 Jul 2017, at 22:27, Emmett Palaima <[hidden email]> wrote:

Nevermind, I figured out that I needed to call cs.destroyMessageBuffer() before calling cs.reset()

That just leaves the audioChannel error: 

I am also getting an error when trying to get the value of an audio channel in python as follows:

audio = cs.audioChannel("Audio", 128)

Also tried:
print(cs.audioChannel("Audio", 128)) 
and
audio, myType = cs.audioChannel("Audio", 128)

In my csd ksmps = 128 and I am setting the value of the channel as follows:

chnset aout, "Audio"


I get the following error:

 Traceback (most recent call last):
  File "ctcscope.py", line 165, in <module>
    Scope()
  File "ctcscope.py", line 146, in Scope
    audio = cs.audioChannel("Audio", 128)
  File "/home/pi/.local/lib/python2.7/site-packages/ctcsound.py", line 1603, in audioChannel
    ptr = samples.ctypes.data_as(POINTER(MYFLT))
AttributeError: 'int' object has no attribute 'ctypes'


On Sun, Jul 16, 2017 at 3:29 PM, Emmett Palaima <[hidden email]> wrote:
How would I stop the currently playing csd and then launch another using this method?

I am trying to do that now but get an error:

Csound is already started, call csoundReset()
before starting again 

But when I add cs.reset() to my StopCsound function I get a segmentation fault. This seems to happen no matter where in the program cs.reset() is located?

Any idea what is causing this? Also do you have any advice to give on the audioChannel error? 

On Sun, Jul 16, 2017 at 3:14 PM, Francois PINOT <[hidden email]> wrote:
You might consider using "Real-time" performance mode:

1-Create a csound instance
2-Set options
3-Set params
4-Start the csound engine
5-Start a performance thread
6-Compile csd's, orchestras and/or scores as needed
7-Events loop (you can also compile csd's, orchestras, and scores within the loop)
8-Finish the performance thread and the program.

Notice that options and params inside csd's are not read.

Here's an example:

import ctcsound

csd1 = '''<CsoundSynthesizer>

<CsOptions>
  -d -o dac -m0
</CsOptions>

<CsInstruments>
sr     = 48000
ksmps  = 100
nchnls = 2
0dbfs  = 1

          instr 1
idur      =         p3
iamp      =         p4
icps      =         cpspch(p5)
irise     =         p6
idec      =         p7
ipan      =         p8

kenv      linen     iamp, irise, idur, idec
kenv      =         kenv*kenv
asig      poscil    kenv, icps
a1, a2    pan2      asig, ipan
          outs      a1, a2
          endin
</CsInstruments>

<CsScore>
</CsScore>
</CsoundSynthesizer>'''

cs = ctcsound.Csound()
cs.setOption("-d")
cs.setOption("-odac")
p = ctcsound.CsoundParams()
cs.createMessageBuffer(toStdOut=False)

cs.params(p)
p.nchnls_override = 2
p.e0dbfs_override = 1.0
cs.setParams(p)
cs.start()
pt = ctcsound.CsoundPerformanceThread(cs.csound())
pt.play()
cs.compileCsdText(csd1)
cs.compileCsd("5th.csd")

while True:
    c = input()
    if c == 1:
        pt.scoreEvent(False, 'i', (1, 0, 1, 0.5, 8.06, 0.05, 0.3, 0.5))
    elif c == 2:
        pt.scoreEvent(False, 'i', (1, 0.5, 1, 0.5, 9.06, 0.05, 0.3, 0.5))
    elif c == 0:
        break

pt.stop()
pt.join()

François

2017-07-16 17:21 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay thanks, that makes sense. On that note, how does t.join() work? Does that destroy the thread so that another would have to be created if I want to use a thread again?

In my program I am going to be playing and stopping multiple csds sequentially in the performance thread so what is the best way to stop the csd from playing and clear up whatever resources are in use? Would it be just:

t.stop()

Thanks!


On Jul 16, 2017, at 3:31 AM, Francois PINOT <[hidden email]> wrote:

It's a scope problem. You declare a second performance thread inside your PlayCSD function, so the performance thread declared at the global level is hidden by the second one. Here's the solution:

<CsoundSynthesizer>
<CsOptions>
  -odac:hw:0,0
  -+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 128
nchnls = 2
0dbfs  = 1.0

turnon "test"
instr test
       printks "\n\n5th!\n\n", .1
  ares lfo     .5, 220, 1
  a5   lfo     .5, 330, 1
       outs    ares+a5, ares+a5
endin
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

----------------------------------------------------------

import ctcsound

cs = ctcsound.Csound()
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)

def StopCsound():
    t.stop()
    t.join()

def PlayCSD(csdName):
    ret = cs.compile_("csound", csdName)
    if ret == ctcsound.CSOUND_SUCCESS:
        t.play()

PlayCSD("5th.csd")

while True:
    x = input()
    if x == 0:
        break
StopCsound()


François



2017-07-16 0:10 GMT+02:00 Emmett Palaima <[hidden email]>:
One more question. I'm running into a strange issue where the csds I run in ctcsound will reach the end of the score instantly and stop playing if they have an empty score (I often have an empty score since I mainly use Csound for signal processing or instrument design rather than composition, I use turnon and the like for the instruments). I have tried adding an empty ftable to the score as well as using an i statement i 1 0 -1 (run instrument 1 indefinitely) in the place of turnon. 

Any idea what might be causing this?

I am succeeding in getting the message output from Csound to my Python program. Thanks for all your help with that!

Here is the CSD and Python Program I am using for testing, as well the output from Csound:

CSD:
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0,0
-+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
turnon "test"
instr test
printks "\n\n5th!\n\n", .1
ares lfo .5, 220, 1
a5 lfo .5, 330, 1
outs ares+a5, ares+a5
endin

</CsInstruments>
<CsScore>
f 0 14400
</CsScore>
</CsoundSynthesizer>


Python:


import ctcsound
cs = ctcsound.Csound() 
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)
def StopCsound():
t.stop()
t.join()
def PlayCSD(csdName):
ret = cs.compile_("csound", csdName)
if ret == ctcsound.CSOUND_SUCCESS:
t = ctcsound.CsoundPerformanceThread(cs.csound())
t.play()

PlayCSD("5th.csd")

while True:
x = 0
StopCsound()


Csound Output:


virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09 (double samples) May 21 2017 
[commit: 4a54f2ccc6de1a05764028d5000f7d20fb4fda6e]
libsndfile-1.0.25
UnifiedCSD:  5th.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
instr test uses instrument number 1
Elapsed time at end of orchestra compile: real: 0.036s, CPU: 0.025s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.039s, CPU: 0.026s
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA output: total buffer size: 1024, period size: 256 
writing 512 sample blks of 64-bit floats to dac:hw:0,0 
SECTION 1:
inactive allocs returned to freespace
end of score.   overall amps:  0.00000  0.00000
  overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.073s, CPU: 0.049s
0 512 sample blks of 64-bit floats written to dac:hw:0,0


On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <[hidden email]> wrote:
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Get Output Channel Pointer Csound Python API

epalaima
Okay, I am sorry, I just found that my gmail had done something weird where all your messages were being sent to another inbox, so I did not see your previous responses until now. Glad that I finally found those, they contain some very useful info. 

It seems from the documentation that cs.audioChannel my want me to pass in an ndarray as the second argument which I tried doing as follows:

audio = numpy.zeros(shape = 128)           #creates ndarray of default type float64 filled with zeros
print(audio)                                                #double checks array was created properly
print(cs.audioChannel("Audio", audio))     #reads audio channel and prints function return

I get the following error:

  File "ctcchan.py", line 283, in <module>
    print(cs.audioChannel("Audio", audio))
  File "/home/pi/.local/lib/python2.7/site-packages/ctcsound.py", line 1604, in audioChannel
    libcsound.csoundGetAudioChannel(self.cs, cstring(name), ptr)
ctypes.ArgumentError: argument 3: <type 'exceptions.TypeError'>: expected LP_c_long instance instead of LP_c_double


Let me know if you can see what I am doing incorrectly. Definitely getting closer to solving this one. Thanks for sticking with me and for helping so much with all my questions, I really appreciate it. 

On Sun, Jul 16, 2017 at 5:37 PM, Victor Lazzarini <[hidden email]> wrote:
128 is out of range for ksmps=128 as I replied before.

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 16 Jul 2017, at 22:27, Emmett Palaima <[hidden email]> wrote:

Nevermind, I figured out that I needed to call cs.destroyMessageBuffer() before calling cs.reset()

That just leaves the audioChannel error: 

I am also getting an error when trying to get the value of an audio channel in python as follows:

audio = cs.audioChannel("Audio", 128)

Also tried:
print(cs.audioChannel("Audio", 128)) 
and
audio, myType = cs.audioChannel("Audio", 128)

In my csd ksmps = 128 and I am setting the value of the channel as follows:

chnset aout, "Audio"


I get the following error:

 Traceback (most recent call last):
  File "ctcscope.py", line 165, in <module>
    Scope()
  File "ctcscope.py", line 146, in Scope
    audio = cs.audioChannel("Audio", 128)
  File "/home/pi/.local/lib/python2.7/site-packages/ctcsound.py", line 1603, in audioChannel
    ptr = samples.ctypes.data_as(POINTER(MYFLT))
AttributeError: 'int' object has no attribute 'ctypes'


On Sun, Jul 16, 2017 at 3:29 PM, Emmett Palaima <[hidden email]> wrote:
How would I stop the currently playing csd and then launch another using this method?

I am trying to do that now but get an error:

Csound is already started, call csoundReset()
before starting again 

But when I add cs.reset() to my StopCsound function I get a segmentation fault. This seems to happen no matter where in the program cs.reset() is located?

Any idea what is causing this? Also do you have any advice to give on the audioChannel error? 

On Sun, Jul 16, 2017 at 3:14 PM, Francois PINOT <[hidden email]> wrote:
You might consider using "Real-time" performance mode:

1-Create a csound instance
2-Set options
3-Set params
4-Start the csound engine
5-Start a performance thread
6-Compile csd's, orchestras and/or scores as needed
7-Events loop (you can also compile csd's, orchestras, and scores within the loop)
8-Finish the performance thread and the program.

Notice that options and params inside csd's are not read.

Here's an example:

import ctcsound

csd1 = '''<CsoundSynthesizer>

<CsOptions>
  -d -o dac -m0
</CsOptions>

<CsInstruments>
sr     = 48000
ksmps  = 100
nchnls = 2
0dbfs  = 1

          instr 1
idur      =         p3
iamp      =         p4
icps      =         cpspch(p5)
irise     =         p6
idec      =         p7
ipan      =         p8

kenv      linen     iamp, irise, idur, idec
kenv      =         kenv*kenv
asig      poscil    kenv, icps
a1, a2    pan2      asig, ipan
          outs      a1, a2
          endin
</CsInstruments>

<CsScore>
</CsScore>
</CsoundSynthesizer>'''

cs = ctcsound.Csound()
cs.setOption("-d")
cs.setOption("-odac")
p = ctcsound.CsoundParams()
cs.createMessageBuffer(toStdOut=False)

cs.params(p)
p.nchnls_override = 2
p.e0dbfs_override = 1.0
cs.setParams(p)
cs.start()
pt = ctcsound.CsoundPerformanceThread(cs.csound())
pt.play()
cs.compileCsdText(csd1)
cs.compileCsd("5th.csd")

while True:
    c = input()
    if c == 1:
        pt.scoreEvent(False, 'i', (1, 0, 1, 0.5, 8.06, 0.05, 0.3, 0.5))
    elif c == 2:
        pt.scoreEvent(False, 'i', (1, 0.5, 1, 0.5, 9.06, 0.05, 0.3, 0.5))
    elif c == 0:
        break

pt.stop()
pt.join()

François

2017-07-16 17:21 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay thanks, that makes sense. On that note, how does t.join() work? Does that destroy the thread so that another would have to be created if I want to use a thread again?

In my program I am going to be playing and stopping multiple csds sequentially in the performance thread so what is the best way to stop the csd from playing and clear up whatever resources are in use? Would it be just:

t.stop()

Thanks!


On Jul 16, 2017, at 3:31 AM, Francois PINOT <[hidden email]> wrote:

It's a scope problem. You declare a second performance thread inside your PlayCSD function, so the performance thread declared at the global level is hidden by the second one. Here's the solution:

<CsoundSynthesizer>
<CsOptions>
  -odac:hw:0,0
  -+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 128
nchnls = 2
0dbfs  = 1.0

turnon "test"
instr test
       printks "\n\n5th!\n\n", .1
  ares lfo     .5, 220, 1
  a5   lfo     .5, 330, 1
       outs    ares+a5, ares+a5
endin
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

----------------------------------------------------------

import ctcsound

cs = ctcsound.Csound()
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)

def StopCsound():
    t.stop()
    t.join()

def PlayCSD(csdName):
    ret = cs.compile_("csound", csdName)
    if ret == ctcsound.CSOUND_SUCCESS:
        t.play()

PlayCSD("5th.csd")

while True:
    x = input()
    if x == 0:
        break
StopCsound()


François



2017-07-16 0:10 GMT+02:00 Emmett Palaima <[hidden email]>:
One more question. I'm running into a strange issue where the csds I run in ctcsound will reach the end of the score instantly and stop playing if they have an empty score (I often have an empty score since I mainly use Csound for signal processing or instrument design rather than composition, I use turnon and the like for the instruments). I have tried adding an empty ftable to the score as well as using an i statement i 1 0 -1 (run instrument 1 indefinitely) in the place of turnon. 

Any idea what might be causing this?

I am succeeding in getting the message output from Csound to my Python program. Thanks for all your help with that!

Here is the CSD and Python Program I am using for testing, as well the output from Csound:

CSD:
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0,0
-+rtaudio=alsa
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
turnon "test"
instr test
printks "\n\n5th!\n\n", .1
ares lfo .5, 220, 1
a5 lfo .5, 330, 1
outs ares+a5, ares+a5
endin

</CsInstruments>
<CsScore>
f 0 14400
</CsScore>
</CsoundSynthesizer>


Python:


import ctcsound
cs = ctcsound.Csound() 
t = ctcsound.CsoundPerformanceThread(cs.csound())
cs.createMessageBuffer(toStdOut=True)
def StopCsound():
t.stop()
t.join()
def PlayCSD(csdName):
ret = cs.compile_("csound", csdName)
if ret == ctcsound.CSOUND_SUCCESS:
t = ctcsound.CsoundPerformanceThread(cs.csound())
t.play()

PlayCSD("5th.csd")

while True:
x = 0
StopCsound()


Csound Output:


virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09 (double samples) May 21 2017 
[commit: 4a54f2ccc6de1a05764028d5000f7d20fb4fda6e]
libsndfile-1.0.25
UnifiedCSD:  5th.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
instr test uses instrument number 1
Elapsed time at end of orchestra compile: real: 0.036s, CPU: 0.025s
sorting score ...
... done
Elapsed time at end of score sort: real: 0.039s, CPU: 0.026s
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA output: total buffer size: 1024, period size: 256 
writing 512 sample blks of 64-bit floats to dac:hw:0,0 
SECTION 1:
inactive allocs returned to freespace
end of score.   overall amps:  0.00000  0.00000
  overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.073s, CPU: 0.049s
0 512 sample blks of 64-bit floats written to dac:hw:0,0


On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <[hidden email]> wrote:
There are some methods allowing you to build your own log system:

createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer()

you can see an example of this in the ICsound class of the csoundmagics.py file (https://github.com/fggp/ctcsound/blob/master/cookbook/csoundmagics/csoundmagics.py)

François

2017-07-13 5:17 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay, thanks for the explanation. I'll look into reworking my program using the ctcsound library. 

On another note, is there a method in ctcsound for getting the text output from a csd (in the form of startup info, print statements etc) ?

On Mon, Jul 10, 2017 at 11:32 AM, Francois PINOT <[hidden email]> wrote:
The functions of the Csound API used with named channels are:

ctcsound.controlChannel()
ctcsound.setControlChannel()
ctcsound.audioChannel()
ctcsound.setAudioChannel()
ctcsound.stringChannel()
ctcsound.setStringChannel()

The opcodes concerned in the orchestra are chani, chano, chnget, chnset. When using numbered channel with chani and chano, the API sees these channels as named channels, the name being derived from the channel number (i.e. 1 gives "1", 2 gives "2", etc.)

These six API functions are used to read or write a single value of the corresponding type.

Another possibility is to use the ubiquitous ctcsound.channelPtr() function. When dealing with an audio channel, this function will use a numpy array allowing you to send or receive ksmps samples.

You should have a look at the ctcsound.py file. Each method is documented. Or you can use the help function within a python terminal:

>>>import ctcsound
>>>cs = ctcsound.Csound()
>>>help(cs.channelPtr)

ctcsound was introduced in version 6.07 of Csound. It is an alternative to csnd6. It can be used with Python 2 and Python 3 as well, and it uses the facilities provided by numpy for connecting Csound buffers and buses to ndarrays.

François

2017-07-10 16:48 GMT+02:00 Emmett Palaima <[hidden email]>:
Okay I checked out the documentation and found the section on channels in this page: https://github.com/fggp/ctcsound/blob/097d9918fbf6cce564e0b1284d1263be74341e61/cookbook/07-icsound.ipynb

How does cs.channel("val") work with different types of channels? If I am attempting to receive any audio channel do I need to specify anything in setup or is the output of cs.channel("val") typecast automatically to an array of size ksmps?

I remember in the past having trouble finding anything on channels in ctcsound (in fact I seem to remember for a while the channels example was using csnd6 in conjunction with ctcsound). Is this something that was recently added? Either way it's great that that is available and I know about it now. 

On Fri, Jul 7, 2017 at 5:03 PM, Francois PINOT <[hidden email]> wrote:
From your example I see that you are using csnd6. You should use ctcsound instead as shown in Victor's answer. The only requirement is that you have numpy installed.

François

2017-07-07 22:32 GMT+02:00 Victor Lazzarini <[hidden email]>:
Don't use pointers, use csound.controlChannel()

help(ctcsound.Csound.controlChannel)

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 7 Jul 2017, at 23:24, Emmett Palaima <[hidden email]> wrote:

Hi, I have been working with the Csound Python API and was looking for documentation on how to get and use a pointer for an output channel (values going from Csound to Python via chnset opcode). I have looked at the Csound Python API examples on github (specifically example 8), which shows how to get a pointer for an input channel. 

I am trying to do something like this, but cannot figure out the syntax:

csoundInstance.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_OUTPUT_CHANNEL) 

ampChannel.GetValue(<not sure what args go here>)

Currently have it working with:

csoundInstance.GetChannel("myChannel")

but would like to make my program more efficient

Is there somewhere I can find documentation that outlines all the functions for the Python API? I the only documentation I can find is for the C API, and there is not always a 1 to 1 correlation. 

Thanks!


Csound mailing list [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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 [hidden email] 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
Loading...