unh... I've been breaking my head, but can't seem to to get around it.
The buffers added to the ~buffers Array are all empty (no sound).
It might be something in completionMessage that is not write. I'm not
exactly sure of this code
Buffer.alloc(s, 44100*~length, 1, completionMessage: {|buf|
~buffers = ~buffers.add(buf);
b.copyData(~buffers.last, 0, 0, 44100*~length) } );
};)
Sorry for this newby questions.
the whole code follows
a
~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=0, 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);
~state = OSCresponder(s.addr,'/tr',{ arg time,responder,msg;
[time,responder,msg];
msg[2].switch(
1, {~startTime= Main.elapsedTime;
~gate.set(\bufnum,b.bufnum, \run,1); },
0, {~endTime= Main.elapsedTime;
~length=(~endTime-~startTime);
~gate.set(\run,0);
Buffer.alloc(s, 44100*~length, 1,
completionMessage: {|buf|
~buffers = ~buffers.add(buf);
b.copyData(~buffers.last, 0, 0, 44100*~length) } );
};)
}).add
~gate= Synth (\gate, [ \tresh, 0.001,\ampAttack,0.01, \ampRelease,0.1,
\lagTime, 4, \delTime,0, \lagTime2, 0]);
~gate.free;
~state.remove;
~buffers.size
~buffers[0].plot
Martin . wrote:
Hola Andre,
here:
~buffers.add(Buffer.alloc(s, 44100*~length, 1,
completionMessage: {b.copyData(~buffers.last, 0,
0, 44100*~length)} ));
the buffer is not actually added to the Array ~buffers at the time when
you are trying to access it with ~buffers.last.
this works though im not sure if its the most effective way:
Buffer.alloc(s, 44100*~length, 1,
completionMessage: {|buf|
~buffers= ~buffers.add(buf);
b.copyData(~buffers.last, 0, 0, 44100*~length)} );
good luck with it!
/martin
On Fri, Mar 6, 2009 at 10:37 AM, Andre
Castro <andrecastro@xxxxxxxxx>
wrote:
Thank you so much for your
help Marije. (I realised then I'd sent the
code with a few bugs. sorry for that).
The completionMessage seems to to the job. I manage to get onto the
buffers what was being recorded. However, I start getting an error
message every time ~state is zero: ERROR: Message 'bufnum' not
understood and I don't why SC doesn't understand \bufnum
Any idea of how I can solve this?
i'm a bit crap with SC, don't get around around using it as much as I
wished.
best
a
here's again the code, with the changes
~buffers=List[]; //empty list of buffers
b= Buffer.alloc(s, 44100*30,1); //long buffer to record in to
//Synth: 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=0, 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);
~state = OSCresponder(s.addr,'/tr',{ arg time,responder,msg,
completionMessage;
[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);
~complet;
~gate.set(\run,0);
~buffers.add(Buffer.alloc(s, 44100*~length, 1,
completionMessage: {b.copyData(~buffers.last, 0,
0, 44100*~length)} ));
};)
}).add
~state.remove;
~gate= Synth (\gate, [ \tresh, 0.001,\ampAttack,0.01, \ampRelease,0.1,
\lagTime, 4, \delTime,0, \lagTime2, 0]);
~gate.free
~buffers.size
~buffers[0].plot
nescivi wrote:
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/
|