Skip to content

Instantly share code, notes, and snippets.

@lisongx
Last active October 31, 2016 15:12
Show Gist options
  • Save lisongx/4dde4ecfb72570986aca23396715bc99 to your computer and use it in GitHub Desktop.
Save lisongx/4dde4ecfb72570986aca23396715bc99 to your computer and use it in GitHub Desktop.
buffer piece

New piece on Buffer

For two players on OSCRadio

Utils

(
var idRangeStart = 10000, idRangeEnd = 14000;
var nodeId = idRangeStart;
~getNodeId = {
	if(nodeId == idRangeEnd, {
		nodeId = idRangeStart;
	}, {
			nodeId = (nodeId + 1);
	})
};)

Buffers

Each player have their own buffer, let's just have buffer 0 and buffer 1 loading on our all side.

Sean's buffer: Buffer 0 Tadashi's buffer: Buffer 1

The buffer's sampling rate is 44100Hz , single channel and duration should less than 10 seconds

Synthdef

Each player will wrote their a sample playback synth, with your own envelope, with a custom effect control

(
SynthDef(\play0, {|out=0, bufnum=0, rate=1.0, amp=0.2, effect=0.5, pan=0, start=0, playlen=1, dur=10|
	var sig, env, frames, startPos, bufdur, trigger, playdur;
  frames = BufFrames.kr(bufnum);
  bufdur = BufDur.kr(bufnum);
  playdur = bufdur * playlen;
  trigger  = Impulse.kr(1/playdur);
  startPos = start * frames;

  frames = BufFrames.kr(bufnum);

  // change to your envelope
  env = EnvGen.ar(
    Env.perc(attackTime:0.4, releaseTime:0.3),
    timeScale: dur,
    doneAction:2
  );

	sig = PlayBuf.ar(
    1, bufnum,
    rate: BufRateScale.kr(bufnum)*rate,
    trigger: trigger,
    loop: 1,
    startPos:startPos)*amp;
	sig = sig*env;
   // use your own effect with the param shift from 0 to 1.
  sig = FreqShift.ar(sig, freq: 300*effect.linlin(0, 1, -1, 1));
	sig = sig*env*amp;
	sig = Pan2.ar(sig, pan);
 	Out.ar(out, sig);
}).doSend(~oscHub);
)

so Sean has \play0, Tadashi wrote \play1

Play

For now, we just use this as a sart to improve, you can use both \play0 and \play1 to play buffer 0 and buffer 1. All other settings are free to change.

(
 ~oscHub.sendMsg(
   "/s_new", \play0, ~getNodeId.value(), 0, 1,
   \bufnum, b.bufnum,
   \rate, 0.2,
   \amp, 0.5,
   \pan, 0,
   \effect, 0.1,
   );
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment