[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] automated buffer -- How's that get in there?!?
Hi James,
I've implemented the changes you cited -- the following code is what
I'm running. (sorry to keep posting this mess, Y'all)
//Create the pool for the buffers to swim in. The tilde makes the variable
'global' so it may be
//accessed by operators (synths, funtions, calls) outside this particular
funtion.
(
~pool = Array.fill(2, { (buffer: Buffer.alloc(s, 44100*3), status:
\empty) });
//load SynthDefs to the server. The \recorder is a 'symbol' or unique name
that matches this synth
//changed .send(s) to .load(s)
SynthDef(\recorder, { arg targetbufnum, outbus = 0;
var sig = AudioIn.ar(1);
RecordBuf.ar(sig, targetbufnum);
Out.ar(outbus, sig);
Line.kr(0, 1, BufDur.kr(targetbufnum), doneAction:2);
}).send(s);
SynthDef(\player, { arg sourcebufnum, outbus = 0;
var sig = PlayBuf.ar(1, sourcebufnum);
Out.ar(outbus, sig);
}).send(s);
SynthDef(\filterHp, { arg sourcebufnum, targetbufnum, outbus = 0;
var sig = PlayBuf.ar(1, sourcebufnum);
HPF.ar(sig, 1000);
RecordBuf.ar(sig, targetbufnum);
Out.ar(outbus, sig);
Line.kr(0, 1, BufDur.kr(sourcebufnum), doneAction:2);
}).send(s);
SynthDef(\filterResonz, { arg sourcebufnum, targetbufnum, outbus = 0;
var sig = PlayBuf.ar(1, sourcebufnum);
Resonz.ar(sig, 1000, 500);
RecordBuf.ar(sig, targetbufnum);
Out.ar(outbus, sig);
Line.kr(0, 1, BufDur.kr(sourcebufnum), doneAction:2);
}).send(s);
SynthDef(\filterLp, { arg sourcebufnum, targetbufnum, outbus = 0;
var sig = PlayBuf.ar(1, sourcebufnum);
LPF.ar(sig, 400);
RecordBuf.ar(sig, targetbufnum);
Out.ar(outbus, sig);
Line.kr(0, 1, BufDur.kr(sourcebufnum), doneAction:2);
}).send(s);
//The nodeWatcher will send information on the nodes, buffers to ...
~watcher = NodeWatcher.newFrom(s);
~stateManager = { |buffer, node, endState = \ready|
buffer.status = \busy; // don't let anyone else use this buffer
// below is to make sure the state changes when the synth
stops
~watcher.register(node);
Updater(node, { |node, flag|
(flag == \n_end).if({
buffer.status = endState;
});
node.releaseDependants;
});
};
//Pass the filter synths into the global filter symbol thingy
~filters = #[\filterResonz, \filterHp,
\filterLp, \filterHighpass];
//This bit runs the playing and filtering.
r = Task({
var buf1, buf2, node;
4.do{
#[\play, \filter].wchoose(#[0.67, 0.33]).switch //#'s define
a literal array -
// wchoose = weighted choose - % follows
{ \play } {
buf1 = ~pool.select({ |b| b.status == \ready
}).tryPerform(\choose);
buf1.notNil.if({
node = Synth(\player,
[\sourcebufnum, buf1.buffer.bufnum]);
~stateManager.value(buf1, node);
});
}
{ \filter } {
buf1 = ~pool.select({ |b| b.status == \ready
}).tryPerform(\choose);
buf2 = ~pool.select({ |b| b.status == \empty
}).tryPerform(\choose);
(buf1.notNil and: { buf2.notNil }).if({
node = Synth(~filters.choose,
[\sourcebufnum, buf1.buffer.bufnum,
\targetbufnum,
buf2.target.bufnum]);
~stateManager.value(buf1, node);
~stateManager.value(buf2, node);
};
rrand(4.0, 8.0).wait;
)};
}});
//This bit will eventually handle the recording.
~rec = Routine({
var buf1, buf2, node;
1.do {buf1 = ~pool.select({ |b| b.status == \empty }).tryPerform(\choose);
Line.kr(0, 1, BufDur.kr(\targetbufnum), doneAction: 2);
buf1.notNil.if({
node = Synth(\recorder, [\targetbufnum,
buf1.buffer.bufnum]);
node.debug("started synth");
~stateManager.value(buf1, node);
});5.wait
}
})
)
r.play; //Run the selection task -- playing and filtering.
r.stop;//kill the selection task
~rec.reset.play; //Run the recording routine.
~rec.stop; //Stop the recording routine.
~pool.post; //manually check the state of the buffer pool.
Now, when I run the ~rec Routine, there is a change in the buffer state.
[ ( 'buffer': Buffer(0, 132300, 1, 44100, nil), 'status': busy ), (
'buffer': Buffer(1, 132300, 1, 44100, nil), 'status': empty ) ][ ( 'buffer':
Buffer(0, 132300, 1, 44100, nil), 'status': busy ), ( 'buffer': Buffer(1,
132300, 1, 44100, nil), 'status': empty ) ]
The first buffer, the one I recorded into is now "busy". What this tells me
is that either the buffer is still open, or some part of the recording synth
is still working because it should read "\ready" i think. (so the Task can
filter it, etc.) Do I need to build something into the recorder syth that
changes the state to \ready when it is done with it? I'm a little confused
because the statemanager refers to both buffers and nodes regarding the
stati -- \busy, \ready, \empty -- so I can't tell if there's any problem in
there.
Might the problem be in the ~rec routine? I'm trying to understand how
turning the routine off (~rec.stop;) actually closes the buffer and changes
the state. (unless this is done by the RecBuf object itself -- the stopping
and closing part -- and the statemanager knows to change the state of the
bufer to \ready -- in which case I do understand it)
Sorry, no more debugging output. In fact, I have no output at all except
the usual "task" "routine" stuff when entering them. When I use the rec
routine I get
a Routine
started synth: Synth("recorder" : 1000)
which seems right. Then when I turn the routine off (which seems inelegant
-- and problematic...) it merely says
a Routine
I suppose, according to your last e-mail, that the 'buf1.debug' bit is
broken -- because there's nothing that actually says 'buf1.debug' in the
code. There is, however, the node.debug bit in the record routine, but you
can see that above.
Ongoing appreciation -
-Scott
--
View this message in context: http://www.nabble.com/automated-buffer----How%27s-that-get-in-there-%21--t1030376.html#a3148862
Sent from the Supercollider - User forum at Nabble.com.