teaching machines

WAV Abstraction in Pure Data

Those poor students who get a teacher that is teaching a subject for the first time. I’m that teacher these next three weeks, and our subject matter is digital music and Pure Data. One of the questions I was asked in this first week is how to create an abstraction that plays an arbitrary WAV file. I didn’t have the answer, but I do now!

The client of this abstraction should be able to specify the path to the WAV file as either a creation argument or as a message. The WAV should be played when a bang or the path message fires. Like this:

To read a sound file and play it, we use the readsf~ object. It expects a compound message of the form open PATH, start. But per the client needs, PATH can’t be hardcoded in the abstraction. It needs to be a parameter.

I knew that I could reference the creation argument in the abstraction with $1, but this didn’t work in open $1, start. The reason is that $ references are interpreted in two different ways. In objects, $1 refers to the first creation argument. In message boxes, $1 refers to the first element of the list passed into it.

We need a medley of components to work with these dual semantics. First, we need an object to capture the creation argument. Second, we need the object to forward the captured value to the open message. The symbol object satifies both these needs, with the added benefit of also firing on bangs.

That leads us to this solution:


Leave a Reply

Your email address will not be published. Required fields are marked *