Get Output Channel Pointer Csound Python API
Date | 2017-07-07 21:24 |
From | Emmett Palaima |
Subject | Get Output Channel Pointer Csound Python API |
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.
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
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! |
Date | 2017-07-07 21:32 |
From | Victor Lazzarini |
Subject | Re: Get Output Channel Pointer Csound Python API |
Don't use pointers, use csound.controlChannel()
help(ctcsound.Csound.controlChannel)
Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-07-07 22:03 |
From | Francois PINOT |
Subject | Re: Get Output Channel Pointer Csound Python API |
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çois2017-07-07 22:32 GMT+02:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
|
Date | 2017-07-10 15:48 |
From | Emmett Palaima |
Subject | Re: Get Output Channel Pointer Csound Python API |
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 <fggpinot@gmail.com> wrote:
|
Date | 2017-07-10 16:32 |
From | Francois PINOT |
Subject | Re: Get Output Channel Pointer Csound Python API |
The functions of the Csound API used with named channels are: ctcsound.controlChannel()2017-07-10 16:48 GMT+02:00 Emmett Palaima <epalaima@berklee.edu>:
|
Date | 2017-07-13 04:17 |
From | Emmett Palaima |
Subject | Re: Get Output Channel Pointer Csound Python API |
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 <fggpinot@gmail.com> wrote:
|
Date | 2017-07-13 08:34 |
From | Francois PINOT |
Subject | Re: Get Output Channel Pointer Csound Python API |
There are some methods allowing you to build your own log system: 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)createMessageBuffer(toStdOutFlag), firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt(), destroyMessageBuffer() 2017-07-13 5:17 GMT+02:00 Emmett Palaima <epalaima@berklee.edu>:
|
Date | 2017-07-15 23:10 |
From | Emmett Palaima |
Subject | Re: Get Output Channel Pointer Csound Python API |
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> Python: import ctcsound Csound Output: virtual_keyboard real time MIDI plugin for Csound
On Thu, Jul 13, 2017 at 3:34 AM, Francois PINOT <fggpinot@gmail.com> wrote:
|
Date | 2017-07-16 08:31 |
From | Francois PINOT |
Subject | Re: Get Output Channel Pointer Csound Python API |
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. cs.createMessageBuffer( 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 <epalaima@berklee.edu>:
|
Date | 2017-07-16 16:21 |
From | Emmett Palaima |
Subject | Re: Get Output Channel Pointer Csound Python API |
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!
|
Date | 2017-07-16 16:32 |
From | Victor Lazzarini |
Subject | Re: Get Output Channel Pointer Csound Python API |
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
|
Date | 2017-07-16 18:41 |
From | Emmett Palaima |
Subject | Re: Get Output Channel Pointer Csound Python API |
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:
I get the following error: Traceback (most recent call last): 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 <epalaima@berklee.edu> wrote:
|
Date | 2017-07-16 19:33 |
From | Victor Lazzarini |
Subject | Re: Get Output Channel Pointer Csound Python API |
Indexing is zero-based, 0 to ksmps-1
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-07-16 20:14 |
From | Francois PINOT |
Subject | Re: Get Output Channel Pointer Csound Python API |
You might consider using "Real-time" performance mode: 1-Create a csound instance4-Start the csound engine 5-Start a performance threadNotice 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() 2017-07-16 17:21 GMT+02:00 Emmett Palaima <epalaima@berklee.edu>:
|
Date | 2017-07-16 20:29 |
From | Emmett Palaima |
Subject | Re: Get Output Channel Pointer Csound Python API |
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() 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 <fggpinot@gmail.com> wrote:
|
Date | 2017-07-16 22:26 |
From | Emmett Palaima |
Subject | Re: Get Output Channel Pointer Csound Python API |
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:
I get the following error: Traceback (most recent call last): On Sun, Jul 16, 2017 at 3:29 PM, Emmett Palaima <epalaima@berklee.edu> wrote:
|
Date | 2017-07-16 22:37 |
From | Victor Lazzarini |
Subject | Re: Get Output Channel Pointer Csound Python API |
128 is out of range for ksmps=128 as I replied before.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-07-16 23:32 |
From | Emmett Palaima |
Subject | Re: Get Output Channel Pointer Csound Python API |
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 I get the following error: File "ctcchan.py", line 283, in <module> 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 <Victor.Lazzarini@nuim.ie> wrote:
|