Actually I got it working except for one last thing..
Need to be able to run the initial convolution function each time preset changes.
Gonna take the rest of the night off but gonna finish tomorrow I think. Here's the code--->
// preparation; essentially, allocate an impulse response buffer, then
// follow a special buffer preparation step to set up the data the plugin needs.
// Different options are provided commented out for loading impulse responses from soundfiles.
(
// also 4096 works on my machine; 1024 too often and amortisation too pushed, 8192 more high load FFT
s = Server.default;
// Set up options for the Bela
s.options.numAnalogInChannels = 2;
s.options.numAnalogOutChannels = 2;
s.options.numDigitalChannels = 0;
s.options.maxLogins = 4;
s.options.blockSize = 16;
s.options.numInputBusChannels = 2;
s.options.numOutputBusChannels = 2;
~input = SoundIn.ar(0);
~fftsize = 512;
~newpreset = 1;
~impulse = "./cymbal.wav";
s.waitForBoot {
~load = {
var ir, irbuffer, bufsize;
// // MONO ONLY
// pre-existing impulse response sound files
// (could also use any general soundfile too for cross-synthesis effects)
// synthesise the honourable 'Dan Stowell' impulse response
ir = [1] ++ 0.dup(100) ++ (
(1, 0.99998 .. 0)
.collect {|f|
f = f.squared.squared;
f = if(f.coin) { 0 }{ f.squared };
f = if(0.5.coin) { 0 - f } { f }
} * 0.1
);
ir = ir.normalizeSum;
~irbuffer = Buffer.read(s,~impulse);
s.sync;
bufsize = PartConv.calcBufSize(~fftsize, ~irbuffer);
// ~numpartitions= PartConv.calcNumPartitions(~fftsize, ~irbuffer);
~irspectrum = Buffer.alloc(s, bufsize, 1);
~irspectrum.preparePartConv(~irbuffer, ~fftsize);
s.sync;
~irbuffer.free; // don't need time domain data anymore, just needed spectral version
// wet and dry outputs
{
var input, wet;
input = SoundIn.ar(0);
wet = AnalogIn.ar(1) * -0.55 + 0.55;
PartConv.ar(input, ~fftsize, ~irspectrum.bufnum) * wet;
}.play;
{
var dry;
dry = AnalogIn.ar(1) * 0.77;
SoundIn.ar(0) * dry;
}.play;
}.fork;
//reading analog
~ctrl = {
var a0 = AnalogIn.kr(0);
SendReply.kr(Impulse.kr(10), '/ctrl', [a0]);
}.play;
~preset = 1.0;
~currentpre = 0;
OSCdef('listen', {arg msg;
~preset = msg[3].linlin(0.0, 1.0, 0.0, 1.0).trunc(0.01);
// [~preset].postln;
p = ~preset;
x = case
{ (p <= 1) && (p >= 0.97) && (p != ~newpreset)} { y = 1 ; ~newpreset = p; y.postln; ~impulse = "./cymbal.wav"; ~load; }
{ (p <= 0.90) && (p >= 0.81) && (p != ~newpreset)} { y = 2 ; ~newpreset = p; y.postln; ~impulse = "./church.wav"; ~load;}
{ (p <= 0.77) && (p >= 0.70) && (p != ~newpreset)} { y = 3 ; ~newpreset = p }
{ (p <= 0.66) && (p >= 0.55) && (p != ~newpreset)} { y = 4 ; ~newpreset = p }
{ (p <= 0.50) && (p >= 0.40) && (p != ~newpreset)} { y = 5; ~newpreset = p}
{ (p <= 0.37) && (p >= 0.29) && (p != ~newpreset)} { y = 6; ~newpreset = p };
}, '/ctrl');
}
)