ethompsy
Resume and CV

Copyright 2008

Ambisonic Rendering Code for SuperCollider

( s = Server.internal.boot; Server.default = s; s.scope(2); //FreqScope.new;

~options = ServerOptions.new.numOutputBusChannels_(4).memSize = 65536;
)

(
~ambis = CtkSynthDef(ambis, {arg dur, w, x, y, z, rate=1, start = 0, out = 0;
var ambi, ampw, ampx, ampy, ampz;

// ampw_env
ampw = EnvGen.kr(
Control.names([ampw]).kr(Env.newClear(4)),
timeScale: dur, doneAction: 2);

// ampx_env
ampx = EnvGen.kr(
Control.names([ampx]).kr(Env.newClear(4)),
timeScale: dur, doneAction: 2);

// ampy_env
ampy = EnvGen.kr(
Control.names([ampy]).kr(Env.newClear(4)),
timeScale: dur, doneAction: 2);

// ampz_env
ampz = EnvGen.kr(
Control.names([ampz]).kr(Env.newClear(4)),
timeScale: dur, doneAction: 2);

w = ampw.dbamp * (PlayBuf.ar(1, w, rate * BufRateScale.kr(w), 1.0,
start * BufSampleRate.kr(w), 1.0));
x = ampx.dbamp * (PlayBuf.ar(1, x, rate * BufRateScale.kr(x), 1.0,
start * BufSampleRate.kr(x), 1.0));
y = ampy.dbamp * (PlayBuf.ar(1, y, rate * BufRateScale.kr(y), 1.0,
start * BufSampleRate.kr(y), 1.0));
z = ampz.dbamp * (PlayBuf.ar(1, z, rate * BufRateScale.kr(z), 1.0,
start * BufSampleRate.kr(z), 1.0));

ambi = BFDecode1.ar(w, x, y, z, [-0.25pi, 0.25pi, 0.75pi, 1.25pi], [0.25pi,0.25pi,0.25pi,0.25pi]);

Out.ar(out, ambi[0], ambi[1], ambi[2], ambi[3]);
})
)

// create new CtkScore
~score = CtkScore.new;

// create buffer and add it to the score

~w = CtkBuffer("~/Snd/impulses/clearing_impulse_close_1.aif".standardizePath).addTo(~score);
~x = CtkBuffer("~/Snd/impulses/clearing_impulse_close_2.aif".standardizePath).addTo(~score);
~y = CtkBuffer("~/Snd/impulses/clearing_impulse_close_3.aif".standardizePath).addTo(~score);
~z = CtkBuffer("~/Snd/impulses/clearing_impulse_close_4.aif".standardizePath).addTo(~score);

(
~note = ~ambis.new(0, 23.5)
.w_(~w)
.x_(~x)
.y_(~y)
.z_(~z)
.ampw_(Env([2, -5.0], [1], exp))
.ampx_(Env([2, -5.0], [1], exp))
.ampy_(Env([2, -5.0], [1], exp))
.ampz_(Env([2, -5.0], [1], exp))
.rate_(1)
.start_(0)
.dur_(23.5) // probably want dur and duration to be the same
.addTo(~score);

)

// play it!
~score.play(s);

// write sound file out
~score.write("~/Snd/ambi.aiff".standardizePath, sampleFormat: "int24", options: ~options);

// open file
Player.new("~/Snd/ambi.aiff".standardizePath).gui;