// // Modified By: Craig Stuart Sapp // Creation Date: Mon Mar 10 13:34:05 PST 2003 // Last Modified: Mon Mar 10 13:49:52 PST 2003 // Filename: thrustereo.c // Source: Ichiro Fujinaga: Max/MSP Externals Tutorial, 2002, v2.41, p.34 // Web Address: http://peabody.sapp.org/class/dmp2/lab/thrustereo/thrustereo.c // Syntax: C; Max4/MSP2 External Object; CodeWarrior 6.0 // OS: Mac OS 9; PPC // // Description: Demonstration of how to receive and send multiple signal data // without modifying the data. // #include "ext.h" #include "z_dsp.h" typedef struct { t_pxobject msp_data; // must always be the first field; used by MSP } MyObject; void* object_data; // pointer to data for object (created in setup()); // function declarations: void main (void); void* create_object (void); void MessageDSP (MyObject* mo, t_signal** signal, short* count); t_int* Perform (t_int *parameters); ////////////////////////////////////////////////////////////////////////// // // Initialization functions: // void main(void) { setup((t_messlist**)&object_data, // the pointer for object data (method)create_object, // your function that initializes object (method)dsp_free, // your function that deinitializes object (short)sizeof(MyObject), // size of your object data struct NULL, // your menu function A_NOTHING); // A list of default parameters types // ending with A_NOTHING addmess((method)MessageDSP, "dsp", A_CANT, A_NOTHING); dsp_initclass(); } ////////////////////////////// // // create_object -- object initializing function. This function is // called by the setup() function inside of main(). Place code // here which will be used to initialized your data structure, // as well as the actual creation of the data storage itself. // The setup function will cause the pointer object_data to point // to the created data storage. // void* create_object(void) { MyObject *mo = (MyObject*)newobject(object_data); // create data storage dsp_setup((t_pxobject*)mo, 2); // create two inlets outlet_new((t_pxobject*)mo, "signal"); // outlet 2 outlet_new((t_pxobject*)mo, "signal"); // outlet 1 mo->msp_data.z_misc &= Z_NO_INPLACE; // inlets/outlets in unique memory return mo; // return pointer to data storage } ////////////////////////////////////////////////////////////////////////// // // Behavior functions: // ////////////////////////////// // // MessageDSP -- What to do when a "dsp" message arrives into the object. // void MessageDSP(MyObject* mo, t_signal** signal, short* count) { #pragma unused(mo) #pragma unused(count) dsp_add(Perform, 5, // size of sp depends on dsp_setup function 5, // how many parameters being sent (including this one) signal[0]->s_vec, // input signal 1 (left channel) signal[1]->s_vec, // input signal 2 (right channel) signal[2]->s_vec, // output signal 1 (left channel) signal[3]->s_vec, // output signal 2 (left channel) signal[0]->s_n); // size of the signal vector } ////////////////////////////// // // Perform -- do the action for one sample group (number of samples // specified by the value parametesr[5], which is to copy the input data into // the output data. // t_int* Perform(t_int *parameters) { long pcount = (long) (parameters[1]); t_float *inputL = (t_float*)(parameters[2]); t_float *inputR = (t_float*)(parameters[3]); t_float *outputL = (t_float*)(parameters[4]); t_float *outputR = (t_float*)(parameters[5]); long count = (long) (parameters[6]); long i; for (i=0; i