Hi There, SCers -
I've been revisiting this bit of code from a few years ago, which worked for my needs at the time..but I'm finding I need some new solutions now..
I'd like to be able to tie some of these functions together and maybe remove the "oneShot" function, so that I could progressively record new buffers.
Ideally, I'd like to have three different buffers that were alternately recorded into, each time an amplitude exceeded the threshold. And I'd like to keep that process going.. instead of just having a single record function, as in the oneShot..Can anyone suggest some modifications?Thanks,GOn Tue, Sep 23, 2014 at 11:08 PM, Eli Fieldsteel <eli.fieldsteel@xxxxxxxxxx> wrote:Well, first of all, Buffers can be written to disk using the 'write' method.
So once you have your audio captured in a Buffer, the rest is fairly
straightforward.
If you're trying to automatically begin recording when a sound is detected,
you'll need to have some amplitude-tracking Synth already active. One
possible approach is to have the amp-tracking Synth send an OSC message back
to sclang, where an OSCdef can tell a buffer-recording Synth to start
capturing audio. DetectSilence will handle the termination of the recording.
This is how I'd do it, anyway. This kind of setup is appealing, but never
foolproof.
As far as I know, it's not possible to allocate a buffer in real-time, as
samples are being recorded into the buffer. Buffers need to be allocated
first, with a fixed size, and then the reserved memory space can be filled
and manipulated. So trimming the silence from the end after recording is
probably a necessary task. I'm still figuring this out. I've been trying a
conditional loop where SC checks a consecutive series of values in the
buffer using 'while' and 'getn', but the interpreter hangs. It's possible,
certainly, but I'm still working on a specific implementation. Maybe
somebody's already done this.
Anyway, here's some primitive code which will hopefully point you in a good
direction.
Eli
(
s.waitForBoot({
//sends a 'start' message to the client when
//amplitude crosses a threshold
SynthDef.new(\amptrack, {
arg in=0, thresh=0.2;
var sig, amp, rms;
sig = SoundIn.ar(in);
amp = Amplitude.kr(sig);
(amp>thresh).poll;
SendReply.kr(amp>thresh, '/start', [40]);
}).add;
//simple buffer record synthdef
SynthDef.new(\bufrecord, {
arg in=0, thresh=0.1, time=0.1, buf;
var sig;
sig = SoundIn.ar(0);
RecordBuf.ar(sig, buf);
//free the synth (stop recording) when input is silent
DetectSilence.ar(sig, thresh, time, 2);
}).add;
//an empty 5 second buffer
b = Buffer.alloc(s, 5*s.sampleRate, 1);
//receive start message and instantiate record synth
OSCdef.new(\amptrack, {
arg msg;
"start record".postln;
Synth.new(\bufrecord, [\buf, b.bufnum]);
}, '/start'
).oneShot; //oneshot prevents multiple record instances
});
)
//after instantiating this amplitude tracking synth,
//play a short sound (no longer than 5 seconds) into the microphone
x = Synth.new(\amptrack);
//test to see if it worked
b.play
//free the amplitude synth
x.free;
b.write(/*put parameters here*/);
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these. 2681727.n2.nabble.com/BufRecor d-and-triggering-tp7613503p761 3547.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/