Hi,
I’m trying to build a basic looper using RecordBuf and PlayBuf, but I’m having a problem with looping the buffer at the point I ended the recording rather than at the end of the buffer.
I’m starting from:
~buf1 = Buffer.alloc(s, s.sampleRate * 10, 1); // 10 second buffer
(
SynthDef(\rec, { arg out = 0, bufnum, rec = 0;
var in;
in = SoundIn.ar(0);
RecordBuf.ar(in, bufnum, run: rec, doneAction: 0, loop: 1);
}).add;
SynthDef(\play, {
arg bufnum, rate = 1, start = 0, loop = 1;
var sig;
sig = PlayBuf.ar(1, bufnum, rate, 0, start, loop, 0);
Out.ar(0, sig);
}).add;
)
~rec = Synth(\rec, [\bufnum, ~buf1, \rec, 1]); // Starts recording in ~buf1
~rec.set(\rec, 0); // Stops the recording
~play = Synth(\play, [\bufnum, ~buf1, \loop, 1]) // Plays it, looped
So if I record for example 5 seconds into the 10 second buffer, it will play the 5 seconds, then 5 seconds of silence (the remainder of the buffer), and only then loop around. What I want is to loop just those 5 seconds of sound.
(Also as this is for use in beat-less music, I need a solution that works outside of tempo and bar syncronicity, unlike some projects I found online for beat-based music.)
My first thougth (and only so far) was to have a DetectSilence on the PlayBuf trigger, so that it jumps to the startPos when the buffer becomes silent, however it seems that there is a problem with having the DetectSilence inside the Ugen it’s detecting.
(On the sig line above I tried and got an error:
sig = PlayBuf.ar(1, bufnum, rate, DetectSilence.ar(sig), start, loop);
)
I’m not experienced at all with more complex controlling like that, so I would be very thankful for some help (and I bet there is a very simple and also very clever way to solve this)