Envelope Buffer for NRT


I’ve been going through the NRT helpfile and modified the example to work with the GrainBuf Ugen. I can succesfully export audio with the in-built buffer and also read from multi-channel files. I want to add my own envelope buffers to the resource list. I am using the instance method .sendCollection. Everything seems to go through and I get no errors but I get no sound on the export. Any thoughts ? All the best, MJ


////////////////Server Setup for NRT 

var server = Server(\nrt_test,
	options: ServerOptions.new

//////////////// Synth Def

def = SynthDef(\granular,
		arg sndbuf, envbuf = (-1);
		var sig,env;
		env = EnvGen.kr(
				attackTime: \atk.kr(0.01), 
				releaseTime: \rel.kr(1.0)
		sig = GrainBuf.ar(
			numChannels: 2, 
			trigger: Impulse.kr(\trigger.kr(1)),
			dur: \gSize.kr(0.1) , 
			sndbuf: sndbuf,
			rate: BufRateScale.kr(sndbuf)* \rate.kr(1),
			pos: \pos.kr(0), 
			interp: 4,
			pan: \pan.kr(0),
			envbufnum: envbuf,	
		sig = sig * env * \amp.kr(1);
			bus: \out.kr(0),
			channelsArray: sig

////////////////////////////// Buffer instance creation (no memory assigned) 

winenv = Env([0.0,1.0,1.0,0.0],[0.0,0.5,1.0]).discretize,
env = Buffer.new(server,winenv.size,1),
buf = Buffer.new(server,0,1);

////////////////////////////// add Synth Def to the server

//////////////////////////// Pattern Score 

x = Pbind(
	\instrument, \granular,
	\sndbuf, buf,
	\envbuf, env,
	\dur, 0.125,
	\pos, Pwhite(0.0,1.0),
).asScore(duration: 20, timeOffset:0.001);

////////////////////////// Pattern Score Resources (allocate memory) 

x.add([0.0, [\d_recv, def.asBytes]]);
x.add([0.0, buf.allocReadChannelMsg(Platform.resourceDir +/+ "sounds/a11wlk01.wav", channels:[0])]);
x.add([0.0, env.sendCollection(winenv)]);


/////////////////////////// NRT Options 
	outputFilePath: ("~/desktop/" +/+ UniqueID.next ++ " granularTest.aiff").standardizePath,
	sampleRate: 44100,
	headerFormat: "AIFF",
	sampleFormat: "int16",
	options: server.options,
	duration: 20


You need to add OSC messages to the score… so you need a method that will return one or more OSC messages to fill the buffer.

sendCollection performs OSC messages, but does not return them. So it’s useless for NRT.

I’d suggest Buffer’s setnMsg.


Thanks for the OSC information! I was wondering what happens when .add is called

I have been playing around with setnMsg but I still get no audio - could you provide any further advice, please?

First I set it up at the beginning

winenv = Env([0.0,1.0,1.0,0.0],[0.0,0.5,1.0]).discretize(2.pow(10)),
env = Buffer.new(server,winenv.size,1),

then I’ve tried these

x.add([0.0, env.setnMsg(0,[winenv])]);


x.add([0.0, env.setnMsg(0,winenv)]);

do you know what I am missing?

It took awhile to find it, but… the answer is: you have to alloc the buffer before ‘setn’-ing it.

fork {
	var server = Server(\nrt, NetAddr.localAddr, s.options.copy);
	var buf = Buffer(server, 10, 1);
	var score = Score.new;
	// without this line, you get nothing
	score.add([0, buf.allocMsg].debug("alloc msg"));
	score.add([0, buf.setnMsg(0, (1..10))].debug("set msg"));
	score.add([0, [\d_recv, SynthDef(\print, { |bufnum|
		var trig = Impulse.kr(0);
		Poll.kr(trig, Index.kr(bufnum, (0..3)));
		FreeSelf.kr(trig <= 0);
	score.add([0, Synth.basicNew(\print, server).newMsg(args: [bufnum: buf])]);
	score.recordNRT(outputFilePath: "/dev/null", options: server.options,
		duration: 0.1, action: { "done".postln });

With the allocMsg line, Poll prints:

UGen(Index): 1
UGen(Index): 2
UGen(Index): 3
UGen(Index): 4

Without it, they’re all 0.


Fantastic! Thank you for your time and effort!!