Csound Csound-dev Csound-tekno Search About

ctcsound Question

Date2016-05-15 16:58
FromMitch Kaufman
Subjectctcsound Question
AttachmentsCtcsoundAPIExamples.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

Date2016-05-15 19:45
FromFrancois PINOT
SubjectRe: ctcsound Question
Hi Mitch,

nice work!

CsoundMYFLTArray is an helper class added in Csnd6. ctcsound uses a different approach. When a pointer is returned by a function of the API, ctcsound encapsulates this pointer in an ndarray (numpy array). You should call channelPtr like this:

# 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()

Regards

Francois

2016-05-15 17:58 GMT+02:00 Mitch Kaufman <mitch.kaufman@hotmail.com>:
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
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

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

Date2016-05-15 20:02
FromAndres Cabrera
SubjectRe: 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 :)


Cheers,
Andrés

On Sun, May 15, 2016 at 11:45 AM, Francois PINOT <fggpinot@gmail.com> wrote:
Hi Mitch,

nice work!

CsoundMYFLTArray is an helper class added in Csnd6. ctcsound uses a different approach. When a pointer is returned by a function of the API, ctcsound encapsulates this pointer in an ndarray (numpy array). You should call channelPtr like this:

# 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()

Regards

Francois

2016-05-15 17:58 GMT+02:00 Mitch Kaufman <mitch.kaufman@hotmail.com>:
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
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

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

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

Date2016-05-15 20:59
FromFrancois PINOT
SubjectRe: ctcsound Question
Hi Andrés,

it is in the sources since 2 April.

Regards

Francois

2016-05-15 21:02 GMT+02:00 Andres Cabrera <mantaraya36@gmail.com>:
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 :)


Cheers,
Andrés

On Sun, May 15, 2016 at 11:45 AM, Francois PINOT <fggpinot@gmail.com> wrote:
Hi Mitch,

nice work!

CsoundMYFLTArray is an helper class added in Csnd6. ctcsound uses a different approach. When a pointer is returned by a function of the API, ctcsound encapsulates this pointer in an ndarray (numpy array). You should call channelPtr like this:

# 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()

Regards

Francois

2016-05-15 17:58 GMT+02:00 Mitch Kaufman <mitch.kaufman@hotmail.com>:
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
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

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

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

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

Date2016-05-16 00:35
FromMitch Kaufman
SubjectRe: ctcsound Question
Thanks Francois. That did the trick. I'll try to get the other examples working. 

Regards,
Mitch


On May 15, 2016, at 2:45 PM, Francois PINOT <fggpinot@GMAIL.COM> wrote:

Hi Mitch,

nice work!

CsoundMYFLTArray is an helper class added in Csnd6. ctcsound uses a different approach. When a pointer is returned by a function of the API, ctcsound encapsulates this pointer in an ndarray (numpy array). You should call channelPtr like this:

# 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()

Regards

Francois

2016-05-15 17:58 GMT+02:00 Mitch Kaufman <mitch.kaufman@hotmail.com>:
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
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

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

Date2016-05-16 12:03
FromMitch Kaufman
SubjectRe: ctcsound Question
AttachmentsCtcsoundAPIExamples.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


On May 15, 2016, at 2:45 PM, Francois PINOT <fggpinot@GMAIL.COM> wrote:

Hi Mitch,

nice work!

CsoundMYFLTArray is an helper class added in Csnd6. ctcsound uses a different approach. When a pointer is returned by a function of the API, ctcsound encapsulates this pointer in an ndarray (numpy array). You should call channelPtr like this:

# 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()

Regards

Francois

2016-05-15 17:58 GMT+02:00 Mitch Kaufman <mitch.kaufman@hotmail.com>:
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
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

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
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

Date2016-05-16 14:55
FromFrancois PINOT
SubjectRe: ctcsound Question
Hello Mitch,

I've  added your notebook in github. I added  a sentence citing you as the author in the intro.

Thanks.

François

2016-05-16 13:03 GMT+02:00 Mitch Kaufman <mitch.kaufman@hotmail.com>:
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


On May 15, 2016, at 2:45 PM, Francois PINOT <fggpinot@GMAIL.COM> wrote:

Hi Mitch,

nice work!

CsoundMYFLTArray is an helper class added in Csnd6. ctcsound uses a different approach. When a pointer is returned by a function of the API, ctcsound encapsulates this pointer in an ndarray (numpy array). You should call channelPtr like this:

# 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()

Regards

Francois

2016-05-15 17:58 GMT+02:00 Mitch Kaufman <mitch.kaufman@hotmail.com>:
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
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

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
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
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

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