Writing Externals For Max
Writing Externals For Max
Revising
multy~
We will use multy~ from chapter 3 to demonstrate porting from Max 5 to Max 6. At
the time of this writing a Max 6 SDK has not been publicly released. Therefore we
cannot provide an actual Max 6 project on the CD-ROM. Instead, the revised code
file multy~.c is included in this folder. When the Max 6 SDK is available, you can
simply move the revised multy~ code into a Max 6 project.
Figure 1 The Max 5 perform routine for multy~.
All signal vectors, along with the object, are taken from the *w integer array. The
order of these elements must correspond to the order in which they are sent in the
dsp_add() function call inside your dsp method. In line 11, make certain to return
the correct pointer, or the external will crash.
Now lets have a look at the 64-bit version of this perform routine, shown in Figure 2.
1 void multy_perform64(t_multy *x, t_object *dsp64,
double **ins, long numins, double **outs,
long numouts, long vectorsize, long flags,
void *userparam)
2 {
3
t_double *in1 = ins[0];
4
t_double *in2 = ins[1];
5
t_double *out = outs[0];
6
int n = vectorsize;
7
while(n--){
8
*out++ = *in1++ * *in2++;
9
}
10 }
Figure
2
The
Max
6
64-bit
perform
routine
for
multy~.
In line 1 of Figure 2, several new arguments are passed. These arguments provide
more structure than in the previous style (characteristic of Max 4, Max 5 and Pd),
where any mix of signal vectors, objects and other data could be passed in any order
on the integer array *w. The 64-bit perform routine distinguishes between inlets and
outlets, provides the signal vector size, and provides the number of signal inlets and
outlets. Since we are now doing 64-bit processing, the signal vectors are declared as
type
t_double
(which is defined as
double
in the new header file
z_sampletype.h).
Despite these changes, the DSP algorithm itself (in lines 7-9 of Figure 2) remains
exactly the same as for the older multy~ perform routine. However there is one thing
missing: We no longer need to return a pointer to the next address on the DSP chain.
Max 6 deals with signal routing behind the scenes, in order to facilitate smooth
transitions whenever the DSP configuration changes (thus no more glitches when
adding new audio objects to a patch). Since a pointer is no longer returned, you can
no longer crash Max/MSP by returning the wrong pointer. With nothing to return,
multy_perform64() is declared as type
void rather than t_int*.
Figure 3 The Max 5 dsp method for multy~.
Figure 6 Adding multy~ to the DSP chain with an object_method() call.