// // Copyright: Copyright 2003 Craig Stuart Sapp // Programmer: Craig Stuart Sapp // Creation Date: Tue Mar 11 08:27:27 PST 2003 // Last Modified: Tue Mar 11 08:33:43 PST 2003 // Filename: dcblock.c // Web Address: http://peabody.sapp.org/class/dmp2/lab/dcblock/dcblock.c // Syntax: C; Max4/MSP2 External Object; CodeWarrior 6.0 // OS: Mac OS 9; PPC // // Description: A DC blocking filter to remove unwanted bias from a signal. // #include "ext.h" #include "z_dsp.h" typedef struct { t_pxobject msp_data; // must always be the first field; used by MSP float lastinput; // the last signal value to come into the filter. float lastoutput; // the last signal value to go out of the filter. float gain; // will be set to 0.995 for best 44.1 srate behavior. } 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); void MessageClear (MyObject* mo); 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); addmess((method)MessageClear, "clear", 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); dsp_setup((t_pxobject*)mo, 1); // 1 signal input outlet_new((t_pxobject*)mo, "signal"); // outlet 1 mo->gain = 0.995; // set gain for dcblock filter. MessageClear(mo); return mo; } ////////////////////////////////////////////////////////////////////////// // // 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(count) dsp_add(Perform, 5, 5, mo, signal[0]->s_vec, signal[1]->s_vec, signal[0]->s_n); } ////////////////////////////// // // MessageClear -- clear the memory of the past signal value (set it to 0). // void MessageClear(MyObject *mo) { mo->lastinput = 0.0; mo->lastoutput = 0.0; } ////////////////////////////// // // Perform -- do the calculations for one sample group. // t_int* Perform(t_int *parameters) { long pcount = (long) (parameters[1]); MyObject *mo = (MyObject*)(parameters[2]); t_float *input = (t_float*) (parameters[3]); t_float *output = (t_float*) (parameters[4]); long count = (long) (parameters[5]); long i; for (i=0; ilastinput + mo->gain * mo->lastoutput; mo->lastinput = input[i]; mo->lastoutput = output[i]; } return parameters+pcount+1; }