Skip to content

Instantly share code, notes, and snippets.

@triss
Created May 9, 2016 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triss/984632c11da04cdcb929677630af6bf3 to your computer and use it in GitHub Desktop.
Save triss/984632c11da04cdcb929677630af6bf3 to your computer and use it in GitHub Desktop.
Pitch/amp following OSC forwarder
// Pitch follower SynthDef
SynthDef.new(\pitchFollower, {
var amp, freq, hasFreq;
var input;
var osc;
var oscTrigger;
input = SoundIn.ar(0);
amp = Amplitude.kr(input);
#freq, hasFreq = Pitch.kr(input);
// Send back OSC to language 10 times per second
oscTrigger = Impulse.kr(10);
// note each message is given a number.
SendTrig.kr(oscTrigger, 0, amp);
SendTrig.kr(oscTrigger, 1, freq);
SendTrig.kr(oscTrigger, 2, hasFreq);
}).add;
// start the pitch follower synth
Synth(\pitchFollower);
// your network destination
~oscDestination = NetAddr("127.0.0.1", 12000);
// this is used to map back from SendTrig number to param name, could be
// done with an if/case or whatever - just so we know what OSC msg to send
~oscPaths = ["/amp", "/freq", "/hasFreq"];
// forward OSC messages sent by send trig on to destination.
OSCdef(\myOSCresponder, { arg msg, time;
var trigNumber, value;
// pull values out of msg array
trigNumber = msg[2];
value = msg[3];
// send the values
~oscDestination.sendMsg(~oscPaths[trigNumber], value);
}, "/tr");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment