[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] Buffers and live playback
Hi everyone,
Using a foot pedal, I'm trying to set up a situation in which I'll play into a microphone for a length of time, and when I lift the pedal, it plays back. This is simple enough with PlayBuf, but for a current composition, I wish to apply live time stretching. For this reason, I want to use the warp1 ugen. Perhaps this isn't the right thing to do. I intend to play for about two minutes, but I want to have a buffer of about five, because I'll be improvising and the time could be vastly different. Here's what I'd do with PlayBuf:
SynthDef("loopRec", {arg distortion, thresHold, level,bufnum, recOn=1, releaseT=0.1;
var input, amp, gate, env;
env=EnvGen.kr(Env.asr(0.01, 1.0, releaseT), recOn, doneAction: 2);
input =
AudioIn.ar(1)*env;
amp = Amplitude.kr(input, 0.05, 0.05);
gate = Lag.kr(amp > thresHold, 0.05);
RecordBuf.ar( input, bufnum, 0, 1.0, 0.0)
}).send(s);
SynthDef("loopPlay", {arg out, trig, volume, bufnum, duration;
Out.ar(
out,
PlayBuf.ar(1, bufnum,BufRateScale.kr(bufnum)], Impulse.kr(duration.reciprocal), 0, 1)*volume
)}).send(s);
MIDIIn.noteOn = {arg src, chan, num, vel;
if(num == 50, {"recording".postln; ~time =
Main.elapsedTime; ~looper.free; ~record = Synth("loopRec", [\thresHold, 0.001, \level, 0.05, \bufnum, ~buffer.bufnum, \recOn, 1]); });
};
MIDIIn.noteOff = {arg src, chan, num, vel;
if(num == 50, {"playing".postln;
//~record.free;
~record.set(\recOn, 0.0);
~trig = Main.elapsedTime-~time; ~looper = Synth("loopPlay", [\out, 0, \bufnum, ~buffer.bufnum, \duration, ~trig+0.09, \volume, 1]);
};
Now my desire to use it in Warp with a Phasor:
SynthDef(\warp, {arg out, bufnum, timeBus, pitchBus;
var pointer, filelength, env, dir, time, freq, mx;
time = 180;
freq = 1;
pointer = Phasor.ar(0, (time*SampleRate.ir).reciprocal, 0, 1);
Out.ar(out, Warp1.ar(bufnum, pointer, freq, 0.1, 8, 0.05, 0.0));
}).send(s);
The last argument in Phasor is where the tricky part seems to be. This currently will play through the entire buffer, even if I've only recorded for twenty seconds or so. I can of course use an impulse trigger like I did in the PlayBuf way, but the numbers are still inaccurate for timing (instead of playing for three minutes, it will play for however long my impulse trigger would be, and the time stretching wouldn't be accurate).
This seems like something up your alley Josh. Any help from anyone would be most appreciated however.
Thanks!
Cliff