Skip to content

Instantly share code, notes, and snippets.

@ofZach
Created October 3, 2014 18:35
Show Gist options
  • Save ofZach/f64f27f03cd0e57b4434 to your computer and use it in GitHub Desktop.
Save ofZach/f64f27f03cd0e57b4434 to your computer and use it in GitHub Desktop.
supercollider examples
// some small examples from in-class
f = { 1 + 1 + 1};
f.value;
a = {SinOsc.ar(440)}.play
a.free
a = {SinOsc.ar(440, 0, 0.4)}.play
a.free
x = { arg freq=440; SinOsc.ar(freq, 0, 0.2).dup }.play
y = { arg freq=440; SinOsc.ar(freq, 0, 0.2).dup }.play
x.set(\freq,400);
x.free
y.free
x = {arg freq=440; SinOsc.ar([freq, freq+5], 0, 0.2)}.play;
x.set(\freq, 880);
x.set(\freq, 220);
x.free
x = {
arg cf, mf, index, modulator;
cf = MouseY.kr(1, 800);
mf = MouseX.kr(1, 300);
index = 2;
modulator = SinOsc.ar(mf, mul: mf * index);
SinOsc.ar(cf + modulator, mul: 0.3).dup // .dup = duplicate = cheap stereo
}.play;
x.free
x = play{SinOsc.ar(OnePole.ar(Mix(
LFSaw.ar([1,0.99],[0,0.6],2000,2000).trunc([10,30])*[1,-1]
),0.98)).dup*0.1}
x.free
{16.do({{SinOsc.ar(Rand(220,880), 0 ,0.05)}.play; 0.1.wait;})}.fork;
(
x = {
var freq = MouseX.kr(100, 1000, 1) / SampleRate.ir;
var distance = 3.00;
var index = MouseY.kr(0.42, 0.99);
var theta, beta, num, denom, son;
// Two phasors which will ramp from zero to 2pi
theta = Phasor.ar(0, freq, 0, 2pi);
beta = Phasor.ar(0, freq * distance, 0, 2pi);
num = sin(theta) - (index * sin(theta - beta));
denom = 1 + index.squared - (2 * index * cos(beta));
son = num / denom;
Out.ar(0, Pan2.ar(son * 0.3));
}.freqscope; // Use ".freqscope" or ".scope", both are illustrative.
)
{
({RHPF.ar(OnePole.ar(BrownNoise.ar, 0.99), LPF.ar(BrownNoise.ar, 14)
* 400 + 500, 0.03, 0.003)}!2)
+ ({RHPF.ar(OnePole.ar(BrownNoise.ar, 0.99), LPF.ar(BrownNoise.ar, 20)
* 800 + 1000, 0.03, 0.005)}!2)
* 4
}.play
SynthDef.new("tutorial-PinkNoise", { Out.ar(0, PinkNoise.ar(0.3)) }).send(s);
x = Synth.new("tutorial-PinkNoise");
y = Synth.new("tutorial-PinkNoise");
x.free; y.free;
SynthDef("mySuperCoolSynth", { Out.ar(0, SinOsc.ar(Rand(440, 660), 0, 0.2)) }).send(s);
x = Synth("mySuperCoolSynth");
y = Synth("tutorial-Rand");
z = Synth("tutorial-Rand");
x.free; y.free; z.free;
{ SinOsc.ar(SinOsc.kr(MouseY.kr(0, 50))*MouseX.kr(0,1000) + 100) }.play;
{ Pan2.ar(PinkNoise.ar(0.2), SinOsc.kr(0.5)) }.play; //moving
{ PinkNoise.ar(0.2) + Saw.ar(300, 0.2) }.play;
{
var a, b;
a = [SinOsc.ar(440, 0, 0.2), Saw.ar(662, 0.2)];
b = [SinOsc.ar(442, 0, 0.2), Saw.ar(660, 0.2)];
Mix([a, b]).postln;
}.play;
(
var n = 8;
{
Mix.fill(n,
{ SinOsc.ar(500 + 500.0.rand, 0, 1 / n) }
)
}.play;
)
play{({|k|({|i|y=SinOsc;y.ar(i*k*k,y.ar(i*k**i/[2,5])*Decay.kr(Dust.kr(2/4**i),y.ar(0.1)+1*k+i,k*2000))}!8).product}!16).sum}//#supercollider
play{f=LocalIn.ar(2).tanh;k=Latch.kr(f[0].abs,Impulse.kr(3/4));LocalOut.ar(f+CombC.ar(Blip.ar([2,6],10*k+500,0.9),1,k*0.3,100*f));f}//44.1kHz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment