Edit
I was originally trying to do something else, but when I tried to simplify my problem I ended up trying to play a sound in cabbage that was triggered by a button press from an Arduino device. Hence I had to update the title of this topic.
I have two small Csound programs that run fine independently of one another, but not together.
The first Program reads a value using the serial opcode, I have it hooked up to an Arduino and when I press a button it prints 1, and when I release it, it prints 0. The code looks like this
//Start Serial Communication
iSerialPort serialBegin "/COM3", 9600
//Read the values into a slower k-rate variable
kType serialRead iSerialPort
printks("\nValue is %d", 0.001, kType)
The second allows me to get input from my microphone and plays it back to me, it records when I press the button and stops recoding for the second press. The Sampler Opcode works fine, and the rest of the code looks like this.
kTrig = chnget:k("record")
kSpeed = chnget:k("speed")
kSampleLength = chnget:k("sampleLength")
kSpeed = 1
a1, a2 in
aOutput Sampler (a1 + a2), kTrig, kSpeed, kSampleLength, 1
aOutput *= chnget:k("gain")
outs aOutput, aOutput
The Problem is when I attempt to combine them I get crashing, and Csound doesn’t read anything from my mic. If I look at the settings in cabbage, I can see input being received from my microphone before I run anything with the serial opcode but after I run it the input stops receiving anything until I plug in and out my Arduino.
The Combined Code Looks like this
//Start Serial Communication
iSerialPort serialBegin "/COM3", 9600
//Read the values into a slower k-rate variable
kType serialRead iSerialPort
printks("\nValue is %d", 0.001, kType)
kTrig = kType //chnget:k("record")
kSpeed = chnget:k("speed")
kSampleLength = chnget:k("sampleLength")
kSpeed = 1
a1, a2 in
aOutput Sampler (a1 + a2), kTrig, kSpeed, kSampleLength, 1
aOutput *= chnget:k("gain")
outs aOutput, aOutput