Copyright 2008
Ambisonic Convolution for SuperCollider
s.options.numAudioBusChannels;
s.options.numOutputBusChannels;
s.options.numInputBusChannels;
a = CtkSynthDef(giveMeInput, {arg inbus;
Out.ar(0, In.ar(inbus, 1))
});
b = a.new.inbus_(s.options.numOutputBusChannels).play;
a = CtkSynthDef(giveMeInput, {arg inbus;
Out.ar(0, SoundIn.ar([0, 1])) // read in the first and second audio bus
});
b = a.new.play;
// My code starts here.
(
s = Server.internal.boot;
Server.default = s;
s.scope(2);
//FreqScope.new;
~options = ServerOptions.new.numOutputBusChannels_(5).memSize = 65536;
)
(
~ambi_volve = CtkSynthDef(ambi_volve, {arg dur, loc, buffer, impw, impx, impy, impz, start, amp = 0, rate=1, out = 0, scale = 0;
var src, env, ambi, ampw, ampx, ampy, ampz, cross = 10, trig = 0, src_out;
amp = amp.dbamp;
env = EnvGen.kr(Env([0, amp, amp, 0], [0.01, dur - 0.02, 0.01]), doneAction: 0);
src = PlayBuf.ar(1, buffer, rate * BufRateScale.kr(buffer), 1.0,
start * BufSampleRate.kr(buffer), 1.0);
src_out = src * amp;
src = src * scale.dbamp;
//How do I crossfade impulse buffers?
// 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);
// FFT size MUST be a power of 2
w = ampw.dbamp * (Convolution2.ar(src,impw, trig, 32768));
x = ampx.dbamp * (Convolution2.ar(src,impx, trig, 32768));
y = ampy.dbamp * (Convolution2.ar(src,impy, trig, 32768));
z = ampz.dbamp * (Convolution2.ar(src,impz, trig, 32768));
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, [src_out, ambi[0], ambi[1], ambi[2], ambi[3]]);
});
~decodeQuad = CtkSynthDef(decodeQuad, { arg buf_w, buf_x, buf_y, buf_z, amp=1, dur;
var w, x, y, z;
w = PlayBuf.ar(1, buf_w, BufRateScale.kr(buf_w), loop: 0);
x = PlayBuf.ar(1, buf_x, BufRateScale.kr(buf_x), loop: 0);
y = PlayBuf.ar(1, buf_y, BufRateScale.kr(buf_y), loop: 0);
z = PlayBuf.ar(1, buf_z, BufRateScale.kr(buf_z), loop: 0);
Line.kr(0, 1, dur, doneAction: 2);
Out.ar(0, BFDecode1.ar(w, x, y, z,
[-0.25pi, 0.25pi, 0.75pi, 1.25pi],
[0.25pi,0.25pi,0.25pi,0.25pi]) * amp);
});
)
(
// create new CtkScore
~score = CtkScore.new;
// create buffer and add it to the score
//~buf = CtkBuffer("/Volumes/MEGA/z003/witch.aiff".standardizePath).addTo(~score);
//
//~impw = CtkBuffer("/Volumes/MEGA/z003/chap_clap_w.aif".standardizePath).addTo(~score);
//~impx = CtkBuffer("/Volumes/MEGA/z003/chap_clap_x.aif".standardizePath).addTo(~score);
//~impy = CtkBuffer("/Volumes/MEGA/z003/chap_clap_y.aif".standardizePath).addTo(~score);
//~impz = CtkBuffer("/Volumes/MEGA/z003/chap_clap_z.aif".standardizePath).addTo(~score);
~buf_w = CtkBuffer("~/Documents/School/Thesis/ThesisAudio/clearing_1.aif".standardizePath).addTo(~score);
~buf_x = CtkBuffer("~/Documents/School/Thesis/ThesisAudio/clearing_2.aif".standardizePath).addTo(~score);
~buf_y = CtkBuffer("~/Documents/School/Thesis/ThesisAudio/clearing_3.aif".standardizePath).addTo(~score);
~buf_z = CtkBuffer("~/Documents/School/Thesis/ThesisAudio/clearing_4.aif".standardizePath).addTo(~score);
)
~decodeQuad.new(0, 13).buf_w_(~buf_w).buf_x_(~buf_x).buf_y_(~buf_y).buf_z_(~buf_z).amp_(0.3).dur_(13).addTo(~score);
(
~note = ~ambi_volve.new(0, 120)
.buffer_(~buf)
.impw_(~impw)
.impx_(~impx)
.impy_(~impy)
.impz_(~impz)
.ampw_(Env([-10.0, -10.0], [1], exp))
.ampx_(Env([-10.0, -10.0], [1], exp))
.ampy_(Env([-10.0, -10.0], [1], exp))
.ampz_(Env([-10.0, -10.0], [1], exp))
.scale_(-10)
.amp_(-10)
.rate_(1)
.dur_(120) // probably want dur and duration to be the same
.start_(0)
.addTo(~score);
)
// play it!
~score.play(s);
~score.write("~/Documents/School/Thesis/z003/clearing.aif".standardizePath, 13, 96000, options: ServerOptions.new.numOutputBusChannels_(4));
// open file
Player.new("~/Documents/School/Thesis/z003/clearing.aif".standardizePath).gui;
// write sound file out
~score.write("~/Snd/convolver.aiff".standardizePath, sampleFormat: "int24", options: ~options);
// open file
Player.new("~/Snd/convolver.aiff".standardizePath).gui;