ctcsound Question
Date | 2016-05-15 16:58 |
From | Mitch Kaufman |
Subject | ctcsound Question |
Attachments | CtcsoundAPIExamples.ipynb |
Hi, I've been trying to learn the ctcsound python API and to do so I put together a jupyter notebook of the Csound API Python examples that Stephen Yi put together using Python 3.5.1 (see attached). There is one part of the API that I am unclear of and that's how to use the Channel Pointer within ctcsound. Could someone explain how to use this in the context of this example? This is contained in Example 8 of the attached jupyter notebook. Example 7 using setControlChannel works fine. I would appreciate the help. import ctcsound from random import randint, random class RandomLine(object): def __init__(self, base, range): self.curVal = 0.0 self.reset() self.base = base self.range = range def reset(self): self.dur = randint(256,512) self.end = random() self.slope = (self.end - self.curVal) / self.dur def getValue(self): self.dur -= 1 if(self.dur < 0): self.reset() retVal = self.curVal self.curVal += self.slope return self.base + (self.range * retVal) # Our Orchestra for our project orc = """ sr=44100 ksmps=32 nchnls=2 0dbfs=1 instr 1 kamp chnget "amp" kfreq chnget "freq" printk 0.5, kamp printk 0.5, kfreq aout vco2 kamp, kfreq aout moogladder aout, 2000, 0.25 outs aout, aout endin""" c = ctcsound.Csound() # create an instance of Csound c.setOption("-odac") # Set option for Csound c.setOption("-m7") # Set option for Csound c.compileOrc(orc) # Compile Orchestra from String sco = "i1 0 60\n" c.readScore(sco) # Read in Score generated from notes c.start() # When compiling from strings, this call is necessary before doing any performing c.setControlChannel("amp", amp.getValue()) # NOT CORRECT Initialize channel value before running Csound c.setControlChannel("freq", freq.getValue()) # NOT CORRECT Initialize channel value before running Csound # NOT CORRECT the following calls store the Channel Pointer retreived from Csound into the # CsoundMYFLTArray Objects c.channelPtr("amp", CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL) c.channelPtr("freq", CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL) amp = RandomLine(.4, .2) freq = RandomLine(400, 80) ampChannel.SetValue(0, amp.getValue()) # note we are now setting values on the CsoundMYFLTArray freqChannel.SetValue(0, freq.getValue()) #print amp.getValue() #print freq.getValue() while (c.performKsmps() == 0): ampChannel.SetValue(0, amp.getValue()) freqChannel.SetValue(0, freq.getValue()) c.stop() Regards, Mitch |
Date | 2016-05-15 19:45 |
From | Francois PINOT |
Subject | Re: ctcsound Question |
Hi Mitch, nice work!# The following calls return a tuple. The first value of the tuple is a numpy array # encapsulating the Channel Pointer retrieved from Csound and the second # value is an err message, if an error happened (here it is discarded with _). ampChannel, _ = c.channelPtr("amp", ctcsound.CSOUND_CONTROL_CHANNEL | ctcsound.CSOUND_INPUT_CHANNEL) freqChannel, _ = c.channelPtr("freq", ctcsound.CSOUND_CONTROL_CHANNEL | ctcsound.CSOUND_INPUT_CHANNEL) amp = RandomLine(.4, .2) freq = RandomLine(400, 80) ampChannel[0] = amp.getValue() # note we are now setting values in the ndarrays freqChannel[0] = freq.getValue() #print amp.getValue() #print freq.getValue() while (c.performKsmps() == 0): ampChannel[0] = amp.getValue() freqChannel[0] = freq.getValue() 2016-05-15 17:58 GMT+02:00 Mitch Kaufman <mitch.kaufman@hotmail.com>:
|
Date | 2016-05-15 20:02 |
From | Andres Cabrera |
Subject | Re: ctcsound Question |
Hi, Is ctcsound now part of the csound sources? If it is, I would make icsound use it instead of the swig python wrapper. If it isn't, it should be :)On Sun, May 15, 2016 at 11:45 AM, Francois PINOT <fggpinot@gmail.com> wrote:
|
Date | 2016-05-15 20:59 |
From | Francois PINOT |
Subject | Re: ctcsound Question |
Hi Andrés, it is in the sources since 2 April.2016-05-15 21:02 GMT+02:00 Andres Cabrera <mantaraya36@gmail.com>:
|
Date | 2016-05-16 00:35 |
From | Mitch Kaufman |
Subject | Re: ctcsound Question |
Thanks Francois. That did the trick. I'll try to get the other examples working. Regards, Mitch
|
Date | 2016-05-16 12:03 |
From | Mitch Kaufman |
Subject | Re: ctcsound Question |
Attachments | CtcsoundAPIExamples.ipynb test1.csd |
This jupyter notebook on ctcsound has been completed. I'm putting it up here in case anyone wants to use it to learn the ctcsound API. These should be the only files needed if anaconda is installed and running on Python 3 (except for ctcsound). Thanks again for the help, Francois. Regards, Mitch Date: Sun, 15 May 2016 19:35:47 -0400 From: mitch.kaufman@HOTMAIL.COM Subject: Re: [Csnd] ctcsound Question To: CSOUND@LISTSERV.HEANET.IE Thanks Francois. That did the trick. I'll try to get the other examples working. Regards, Mitch 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 |
Date | 2016-05-16 14:55 |
From | Francois PINOT |
Subject | Re: ctcsound Question |
Hello Mitch, I've added your notebook in github. I added a sentence citing you as the author in the intro.2016-05-16 13:03 GMT+02:00 Mitch Kaufman <mitch.kaufman@hotmail.com>:
|