Hello
I’m trying to do a few processes offline, quickly. So I am trying NRT. I manage to find a few examples but this is puzzling me. In the following code I’m reading from a buffer with PlayBuf and writing using BufWr… yet I cannot get anything else than the first sample of the output buffer to be updated.
Any NRT specialist with wisdom here? In the end, I’d like to batch process many buffers in a row… and this would be a great way. The processes I’m planning to use are custom \b_xxx
methods and that would be ace. I know I can do it in the language but it is slower.
Any pointer welcome
pa
(
fork {
var server, source, resultbuf, resultpath, oscpath, score, cond, sf, data, job;
server = Server(\nrt,
options: ServerOptions.new
.numOutputBusChannels_(2)
);
job = UniqueID.next.postln;
resultpath = "/tmp/NRT-" ++ job ++ ".wav";
oscpath = "/tmp/NRT-" ++ job ++ ".osc";
score = Score([
[0, (resultbuf = Buffer.new(server, 44100,1,0)).allocMsg],
[0, (source = Buffer.new(server, 1,1,0)).allocReadMsg(Platform.resourceDir +/+ "sounds/a11wlk01.wav")],
[0, [\d_recv, SynthDef(\testNRT, {BufWr.ar(PlayBuf.ar(1,source,1,doneAction: 2), resultbuf, Phasor.ar());}).asBytes]],
[0, Synth.basicNew(\testNRT, server).newMsg],
[1, resultbuf.writeMsg(resultpath, headerFormat: "WAVE", sampleFormat: "float")]
]);
cond = Condition.new;
score.recordNRT(oscpath, "/dev/null",
sampleRate: 44100,
options: server.options,
action: { cond.unhang } // this re-awakens the process after NRT is finished
);
cond.hang; // wait for completion
"done".postln;
sf = SoundFile.openRead(resultpath);
sf.readData(data = FloatArray.newClear(sf.numFrames));
sf.close;
// File.delete(oscpath);
// File.delete(resultpath);
server.remove;
data.size.postln;
data.postln; // these are your onsets!
};
)