[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] automated buffer -- How's that get in there?!?
Okaaaaaay.
I've recently used the following code to test the piece. It doesn't work.
At least, there's no sound, and the buffers are not being filled by the
recording bit so the processing can't occur anyway. I imagine there's
something wrong with my buffer code -- the part where I define the pool.
Anyway, have a look.
s = Server.local;
s.boot;
//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(10, { (buffer: Buffer.alloc(s, completionMessage: 2),
state:
\empty) });
)
//load SynthDefs to the server. The \recorder is a 'symbol' or unique name
that matches this synth
(
SynthDef(\recorder, { arg targetbufnum, outbus = 0;
var sig = AudioIn.ar(1);
RecordBuf.ar(sig, targetbufnum);
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);
)
~watcher = NodeWatcher.newFrom(s);
(
~stateManager = { |buffer, node, endState = \ready|
buffer.state = \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.state = 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;
loop {
#[\play, \filter].wchoose(#[0.67, 0.33]).switch //#'s define
a literal array -
// wchoose = weighted choose - % follows
{ \play } {
buf1 = ~pool.select({ |b| b.state == \ready
}).tryPerform(\choose);
buf1.notNil.if({
node = Synth(\player,
[\sourcebufnum, buf1.buffer.bufnum]);
~stateManager.value(buf1, node);
});
}
{ \filter } {
buf1 = ~pool.select({ |b| b.state == \ready
}).tryPerform(\choose);
buf2 = ~pool.select({ |b| b.state == \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;
)};
}});
)
r.play;
r.stop;
//This bit will eventually handle the recording.
(
~rec = Routine({
var buf1, buf2, node;
n.do {buf1 = ~pool.select({ |b| b.state == \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);
});
}
})
)
//From James -- to test
(
~rec = Routine({
var buf1, buf2, node;
n.do {buf1 = ~pool.select({ |b| b.state == \empty
}).tryPerform(\choose);
buf1.debug("buffer selection");
buf1.notNil.if({node = Synth(\recorder, [\targetbufnum,
buf1.buffer.bufnum]);
node.debug("started synth");
~stateManager.value(buf1, node);
});
}
})
)
~rec.play;
~rec.stop;
~pool.post;
Also, there's no player synth so that bit won't work either! I'm sure
there's a conceptual gap in the code somewhere that's preventing proper
functioning, but I've been brain-dead lately, so that stands to reason!
Thanks,
-Scott
--
View this message in context: http://www.nabble.com/automated-buffer----How%27s-that-get-in-there-%21--t1030376.html#a3059548
Sent from the Supercollider - User forum at Nabble.com.