Hi! I’m looking for a way to take record an audio input and to play it in halfspeed and quarter speed during alive performance. Like a continuous stream of the incoming audio but delayed (so the recording buffer and the playhead won’t overlap) in different speeds. I’ve tried but can’t come up with something reliable and good.
The idea is like a really basic counterpoint system that builds layers from the input over time. I’m planning to use this with an acoustic feedback system i SuperCollider that I’ve been working on to expand the sound palette.
It seems like this should be an easy concept to put into code but I guess I’m too much of a beginner for this.
Thanks! :))
Here is some code to demonstrate playback at various speeds:
s.boot;
// setup
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
c = Buffer.alloc(s, b.numFrames);
(
~bus = Bus.audio(s, 1);
~inGroup = Group.new;
~recGroup = Group.after(~inGroup)
)
(// write audio to ~bus
{
Out.ar(~bus, PlayBuf.ar(1, b, loop: 1));
}.play(target: ~inGroup)
)
// OR use live input
// { Out.ar(~bus, SoundIn.ar(0)) }.play(target: ~inGroup) //
(
x = {
var in = In.ar(~bus, 1);
var phase = Phasor.ar(0, 1, 0, inf); // this phasor is used for recording the live input
var phase2 = Phasor.ar(0, \rate.kr(1), 0, inf) % c.numFrames; // this phasor is used for play back of the recorded input
BufWr.ar(in, c, phase); // write the input to buffer 'c' using 'phase'
BufRd.ar(1, c, phase2); // play back buffer 'c' using 'phase2'
}.play(target: ~recGroup)
)
/// change playback speed
x.set(\rate, 0.5) // half speed
x.set(\rate, 0.25) // quarter speed