0

Sorry if this is very obvious, I'm very new to SuperCollider. I've followed a few suggestions from other threads but this application appears unique as I'm using OSC data from Max 8. I've run out of time so I'd hugely appreciate any suggestions.

I'm trying to change the amplitude of my Synth using AmpCompA. I can change the frequency in realtime using OSC messages from Max 8, however, I can't apply AmpCompA in realtime using the same trigger/message. Is this possible another way?

Here is the code:

// setup synth
(
SynthDef.new("sine", {arg out = 0, freq = 200, amp = 1.0;
var sin;
    sin = SinOsc.ar(freq);
Out.ar(out, sin * amp);
}).send(s);
)

x = Synth.new("sine", [\freq, 200, \amp, 1.0]);

//test parameter setting
x.set(\freq, 400);
x.set(\amp, 0.1);
x.free;


//read from OSC message
(
f = { |msg|
    if(msg[0] != '/status.reply') {
        b = 1.0 * AmpCompA.kr(msg[1]);
        x.set(\freq, msg[1]); //this does work when I send an OSC message from Max 8
        x.set(\amp, b);  //this doesn't work? Can't set a control to UGen error
    }
};
thisProcess.addOSCRecvFunc(f);
)

s.sendMsg("/n_free", x);

Max 8 Screenshot

Error:

ERROR: can't set a control to a UGen CALL STACK: Exception:reportError arg this = Nil:handleError arg this = nil arg error = Thread:handleError arg this = arg error = Object:throw arg this = UGen:asControlInput arg this = Object:asOSCArgEmbeddedArray arg this = arg array = [*1] < FunctionDef in Method SequenceableCollection:asOSCArgArray > arg e = ArrayedCollection:do arg this = [*2] arg function = var i = 1 SequenceableCollection:asOSCArgArray arg this = [*2] var array = [*1] Node:set arg this = arg args = [*2] < FunctionDef in Method Collection:collectInPlace > arg item = arg i = 1 ArrayedCollection:do arg this = [*2] arg function = var i = 1 Collection:collectInPlace arg this = [*2] arg function = FunctionList:value arg this = arg args = [*4] var res = nil Main:recvOSCmessage arg this = arg time = 626.8060463 arg replyAddr = arg recvPort = 57120 arg msg = [*2] ^^ The preceding error dump is for ERROR: can't set a control to a UGen

1 Answers1

0

You can use the x.set to send numbers to a synthdef, but you can't use them to send functions or uGens. AmpCompA is a UGen - and therefore can only be used inside a synthdef.

You can modify your synthdef to use it:

(
SynthDef.new("sine", {arg out = 0, freq = 200, amp = 1.0;
var sin;
    sin = SinOsc.ar(freq);
Out.ar(out, sin * amp * AmpCompA.kr(freq));
}).send(s);
)

Your OSC message function only would ever send the frequency: x.set(\freq, msg[1]); The SynthDef uses the frequency to compute the psychoacoustic amplitude change.

les_h
  • 347
  • 1
  • 8