Loading Multiple Files Into Buffers

The other day I was helping  friend with some Supercollider code involving buffers.  Normally in Supercollider you can load a buffer with code that looks like the following

b = Buffer.read(s, “file extension”);

This simply loads a buffer onto the server and assigns it to b.  Then we can use PlayBuf to play it back

SynthDef(“buffer”, (arg bufnum, numchannel = 1;

var in;

a = PlayBuf.ar(numchanel, bufnum, rate, trigger, startpos, loop, donAction:2);

Out.ar(0, a);

}).send(s, \bufnum, b);

In the previous code bufnum is the buffer number assigned to the file.  At the send of the synthdef we use \bufnum, b to assign the buffer number to argument bufnum. doneAction is an argument that controls when the synth gets freed from the server or not.  Look at the doneAction help file to read about them.  There are 14 of them.


If only 1 sound file is being used loading the buffer is very easy.  If we have multiple files then this method is not going to work.  To load a file full of sounds the object Buffer is not even used.  Instead “SoundFile” is used which is a little counter intuitive.  The following code shows how to load many sounds from a file into individual buffers.

b = SoundFile.collect(“filepath/*”, s)

This in turn will load every sound in the file into a separate buffer and give it a number value.  It is important to add the * at the end of the path otherwise Supercollider will load a blank array.  Then we can say


to load a window with each buffers information.

Using the inspect window we can then get all of the buffer numbers to be used in the PlayBuf code.


b = SoundFile.collect(“filepath/*”, s)

SynthDef(“buffer”, (arg bufnum, numchannel = 1, rate = 1, ;

var in;

a = PlayBuf.ar(numchanel, bufnum, rate, loop: 1, donAction:2);

Out.ar(0, a);


a = Synth(“buffer”, [\bufnum, 1, \rate, 1.3]);



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s