Windowing in Pd

This example illustrates how to create several window functions in Pd. The equations to these functions can be found here. Inside the [pd makewindow] subpatch, each window is drawn by evaluating the function from 0 to N-1, where N is the size of the window, in this case being 1024. The iterator works by sending a bang message to the left inlet of the [until] object which in turn causes it to continuously send bang messages, much like the [uzi] object in Max. These messages are sent to a [float] object, abbreviated to [f] here, which is initialized to 0. The [float] object is connected to an increment object, [+ 1], which is fed to a modulus object: [mod 1024]. The incremented values will pass directly through the [mod 1024] object back to the [float] object, incrementing it’s value in the process. However, when the input of the [mod 1024] object reaches 1024 the output folds over to 0. This 0 is picked up by the [select 0] or [sel 0] object, which does exactly what it sounds like, and disables the [until] object. The window values are calculated by the [expr] object and written to the window array by the [tabwrite window] object. Since the window functions in the [expr] objects are very similar to C syntax it would be quite easy to turn these into a routine in your programming language of choice. Calculating a Hann window in C might look something like this:

int i;
for(i=0;i<N;i++){
window[i] = 0.5*(1-cos(2*3.1415926535*i/(N-1)));
}

where window is a pointer to an array of length N, and N is the window length.

Link to Pd patch

Leave a comment

Filed under C, Programming, Pure Data

Leave a comment