batchNRT A method for batch-processing audio files in NRT mode

Score.batchNRT(inputpath, outputpath, synthdefname)

If you have a folder full of sound files, and a SynthDef defining the process you want to be applied to the sound files, this method can do it for you.

The method is asynchronous, so it will return quickly but the Routine which is managing the process will carry on in the background. A message is posted (and optionally, a function evaluated) when the processing is complete.

The first three parameters must be specified:

inputpath - Path pattern for input files. For example, "~/data/*.wav" to load all wave files from one folder.

outputpath - Path for the folder in which output files are to be written. This must exist. Output will overwrite existing files if the filenames match.

synthdefname - The name of a SynthDef you have previously created and stored. It must take the following arguments: inbufnum, outbufnum (for the input and output buffer numbers, respectively)

By default, the output buffer is created with the same length as the input buffer, and the synth will be played for exactly that duration. If you want to change this (e.g. make it control rate, or make it slightly longer to account for reverberation, etc) you can supply outputlengthfunc, a function which will deduce the output buffer length (IN FRAMES) from an input file's length in seconds, and/or synthdurfunc, which will do the same for the synth running time (returning a time IN SECONDS). 

The input and output are assumed to be single-channel. You can change this using the inchannels and outchannels arguments. Processing will typically fail if you don't ensure that the number of in/out channels matches those in the SynthDef and the input files.

Other parameters:

synthparams - Additional parameters for the synth

plot - Set to true to automatically plot the results

outputnameadd - Append some text to the output filenames (before the file extension)

maxtimeperfile - Specify a "safety limit", limiting each file's NRT processing time to a maximum number of seconds

extrainitcommands - an array of extra commands you'd like prepending to the list

action - a function to be evaluated once all the processing is complete. It will be passed a list of paths for the files created.

opts - a ServerOptions object (NB options for number of output busses will be overwritten).

really - set this to false to skip the NRT part of the process (in other words, just perform the plotting/action). Useful for debug or rerunning actions.

See also: [Score], [Non-Realtime-Synthesis].


The first example is audio-rate, batch-processing a set of sounds to add reverb to them.

// First we'll create a SynthDef for adding a bit of reverb to a sound


SynthDef(\help_addalittlereverb, { |inbufnum, outbufnum, gain = 0.2|

var source;

source =, inbufnum,;{ source =, 0.050, [Rand(0, 0.05), Rand(0,0.05)], 1) } );[source * gain], outbufnum, loop:0);, (source * gain).dup);



// Now we'll run the SynthDef over a folder full of samples.

// Of course you need a folder with some sound files in,

// and also an output folder. You may need to alter the paths given in this code.



"~/svn/soundsamples/beatboxes/*.wav", // Input path pattern - note the asterisk wildcard

"~/dataoutput/addreverb", // Output path


outputnameadd: "-verbed",

outputlengthfunc: {|indur| (indur + 2) * 44100}, // Allow 2 seconds at end of file for reverberations

synthparams: [\gain, 0.9],

// opts:, // Reduces amount of info the server posts

synthdurfunc: {|indur| indur + 2} // Allow 2 seconds at end of file for reverberations



The second example is control-rate, for extracting a parameter (here the amplitude envelope) of the sounds. It also plots the results.

// First the synthdef


SynthDef(\help_param, { |inbufnum, outbufnum|

var source, amp, freq, hasfreq;

source =, inbufnum,;

amp =;, outbufnum,, * /, 0,, 0);, source.dup);



// Then we process the files



"~/svn/soundsamples/beatboxes/*.wav", // Input path pattern - note the asterisk wildcard

"~/dataoutput/parameters", // Output path


outputnameadd: "-parameters",

outputlengthfunc: {|indur| ((indur) * 44100 / 64).postln}, // Note the way the durations are scaled to the (standard) control rate