You are here: Home Interaction SnoRRRhea SuperCollider patch

SuperCollider patch

snoRRRhea.sc.txt — Plain Text, 1Kb

File contents

(
// allocate a Buffer
s = Server.local;
b = Buffer.alloc(s, 44100 * 60 * 5, 1); // a five minutes 1 channel Buffer

SynthDef("Recordbuf save", { arg out=0,bufnum=0;
  var in, amp, env;

  in = SoundIn.ar(0);
  amp = Amplitude.kr(
    in,
    5.0, 5.0,
    add: -0.02
    );
  amp = max(0, amp);
  RecordBuf.ar(in, bufnum, run: amp, loop: 1);
}).store;

SynthDef("RecordBuf play",{ arg out=0,bufnum=0;
  var playbuf, env;
  playbuf = PlayBuf.ar(1, bufnum, loop:1);
  env = Line.kr(0.8, 1, 60 * 5, doneAction: 2);
  Out.ar(out, playbuf * env);
}).store;
)

( // listen to snoRRRhea

  var player = Synth.newPaused("RecordBuf play", [\out, 0, \bufnum, b]);
  var recorder = Synth.newPaused("Recordbuf save", [\out, 0, \bufnum, b]);
  var port = SerialPort("/dev/ttyUSB0", baudrate: 9600);
  var ch;

  Routine.new ({
    loop({
      ch = port.read.asAscii;
      if (ch == $1, {recorder.run(true); "ON".postln;});
      if (ch == $0, {recorder.run(false); player.run(false); "OFF".postln;});
      if (ch == $T, {player.run(true); "TRIGGER".postln;});
    }).play;
  }).play;
)

( // stop listening; important if you want to restart
  SerialPort.closeAll;
)

( // just play what's been recorded
  Synth("RecordBuf play", [\out, 0, \bufnum, b]).play;
)

Document Actions