Pure Data: Auto-loading Samples

In the Peep sound installation, I needed to load upwards of 600 sound samples into a Pure Data composition. I decded that the easiest way would be to develope a sequential file naming system for the files, which were used randomly in the composition: "0.wav, 1.wav, 2.wav, ...", etc.:

I then created a nested comp with a table for each audio file:

 Pure data arrays

After that, there's a function which runs on load time with load bang: 

Let's go through this step-by-step:

Runs the function as soon as the composition is loaded.

Number box (131)
This is the total number of audio files in the folder named, "01".

Trigger, Float, Bang [t f b]
This object sets the order of operations and allows you to execute processes in a particular order in PD, from right to left. This object can accept any number of operations: [t b f f f f], [t b b b], etc. In this case, it first bangs the "0" into the float box, then passes the number 131 into the [until] object. 

This iterates until whatever number was input is reached. Be careful with this object... if you bang it without an input number, it will count indefinitely until PD freezes.

makefilename accepts variables to make strings. This is useful when you want to iterate a bunch of file names or arrays, as shown here. 

The pack object takes a series of inputs and outputs a list. [pack s s]: pack accepts floats, symbols, pointers, lists, and more. In this case, it's accepting two symbols, hence the "s s", and sending them into the message that opens audio files and loads them into the arrays. See the [pack] object in the Pure Data help section for more info, it's extremely powerful. 

Soundfiler reads audio data from a file and writes it to an array, or reads audio data from an array and writes it to a file. It's a powerful object worthy of review in the PD help section. [soundfiler] is getting instructions from the message above it, which is in turn getting the filename and array name from the [pack] object above it. 

This writes a value to an index of an array. In this case, I'm adding to an array with the sample length of each audio file (23608 samples in this case). Each index in the array corresponds to the filename that was loaded into an audio array (as you see, 130 is being fed into the right inlet). I use this array, which I've called sampleSizeArray, to know how long each audio file is played, and to do some other timing actions when a sample if finished. Essentially is a database of sample lengths for the 600 audio clips. I used [tabread] in the composition to play the audio from the arrays, and with [tabread] you need to know how many samples are in a piece of audio. Maybe more on that later.