[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] buffer problems w/ auto-recorder
Hiho,
On Wednesday 04 March 2009 09:39:54 Andre Castro wrote:
> Dear list, I'm working on a auto input recorder, that record only what
> is under the amp follower threshold.
> To this point it seems to work well.
>
> However I'm trying to implement a autonomous buffer recording system,
> adding a new buffer every time it stops recording, the audio is copied
> to a new buffer.
>
> I don't know where I'm messing it up, but in the end the resultant
> recorded buffers turn out to have recorded the same moments, are
> repeated and seems to have bits of audio from previous buffers. Quite
> confusing (and I've tried it a lot).
>
> Would anyone would be kind enough to help to solve this.
>
> Cheers,
>
> andré
>
>
>
>
> ~buffers=List[]; //empty list of buffers
> b= Buffer.alloc(s, 44100*30,1); //long buffer to record in to
>
> //Synth doing amp analysis and recording
> //use headphones to prevent feedback
> SynthDef(\gate, {arg sample, lagTime=0, thresh= 0.01, ampAttack=0.04,
> ampRelease=0.04, attack=0.05, release=0.05, delTime=0, bufnum, run;
> var source, trigger, envelope, on, off, time, output, record;
>
> source = AudioIn.ar(1);
> trigger = (Lag.kr(Amplitude.kr(source,
> ampAttack,ampRelease),lagTime) < thresh);
> envelope = EnvGen.kr(Env.asr(attack, 1, release, 1,curve:'sine'),
> trigger); output = DelayN.ar(source, 1, delTime) * envelope;
> on = Trig1.kr(trigger);
> off = Trig1.kr(1-trigger);
> time = Line.kr(0, 1000000 ,1000000);
> SendTrig.kr(on,1,time);
> SendTrig.kr(off,0,time);
> record= RecordBuf.ar(output*2, bufnum, 0, 1, run);
> Out.ar(1, output);
> }).send(s);
>
>
> //OSCresponder that send rec mesg to Synthdef and adds recorded buffers
> to buffer list
> ~state = OSCresponder(s.addr,'/tr',{ arg time,responder,msg;
> [time,responder,msg];
> msg[2].postln.switch(
> 1, {~startTime= Main.elapsedTime;
> ~gate.set(\bufnum,b.bufnum, \run,1); },
>
> 0, {~endTime= Main.elapsedTime;
> ~length=(~endTime-~startTime);
> ~gate.set(\run,0);
> ~buffers.add(Buffer.alloc(s, 44100*~length, 1) );
I imagine that Buffer.alloc is asynchronous, so it can take a while for it to
be ready to copy data into. So you may want to use the completion message of
Buffer.alloc to do the copying (see Buffer helpfile).
Also you might want to change the line into:
~buffers = ~buffers.add(Buffer.alloc(s, 44100*~length, 1) );
see the Array.add documentation :
"For Arrays, the 'add' method may or may not return the same Array object. It
will add the argument to the receiver if there is space, otherwise it returns
a new Array object with the argument added."
I hope that helps.
sincerely,
Marije
_______________________________________________
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/