Write your own Pure Data External! (Part 2)
So, the first thing you’ll want to do is create a folder for your project. In the folder, you’ll want a copy of the files in this .zip archive. m_pd.h is a header file which you will use in every external you write. It allows your external to use the functions defined for use by PD. The makefile will automate the compilation process. You’ll want to edit it (using a text editor) to make sure the path to your PD.app is correct.
The .zip also contains a file called randomwalk.c that I’ll be using as the example file for these tutorials. Open it in your text editor. Skipping over the comment at the top, you’ll notice that I’m #include-ing m_pd.h. You’ll have to do that for every external, assuming you want it to compile.
Skip down a bit to this chunk of code:
static t_class *randomwalk_class; // declares a pointer to the object
typedef struct _randomwalk
{
t_object x_obj; // the required t_object
t_float current; // the current value
t_float step; // step width
t_float lower, upper; // bounds
t_outlet *f_out; // outlet pointer
} t_randomwalk;
The first line declares a pointer to your object, which will allow PD to reference it. We’ll define it below.
This defines the variables that your object will have access to. Every object needs to have the t_object x_obj; line, this allows the object to store PD-specific information, which we don’t have to worry about right now. You’ll notice that the next three variables are all of t_float type. This is essentially the same as a float variable, but PD defines it’s own atomic types, which are used to facilitate portability cross-platform. Here, I’ve defined three variables for the random-walk procedure. Finally, the t_outlet *f_out; is a pointer to an outlet. The name f_out is just a convention so that we remember that this outlet is going to output float's.
In the next segment, I’ll talk about our setup function, found in the
void randomwalk_setup() function below.





Musician/hacker living in San Diego, CA. Studying computer music at UCSD.