Digital Music Programming II: thrustereo~




This lab demonstrates how to receive and send multiple audio signals in an MSP objectmultiple .


Source Code Example Usage
thrustereo.c


#include "ext.h"
#include "z_dsp.h"

typedef struct {
   t_pxobject msp_data;
} MyObject;

void* object_data;

void   main            (void);
void*  create_object   (void);
void   MessageDSP      (MyObject* mo, t_signal** signal, short* count);
t_int* Perform         (t_int *parameters);

void main(void) {
   setup((t_messlist**)&object_data, (method)create_object, (method)dsp_free,
         (short)sizeof(MyObject), NULL, A_NOTHING);
   addmess((method)MessageDSP, "dsp", A_CANT, A_NOTHING);
   dsp_initclass();
}

void* create_object(void) {
   MyObject *mo = (MyObject*)newobject(object_data);
   dsp_setup((t_pxobject*)mo, 2);
   outlet_new((t_pxobject*)mo, "signal");
   outlet_new((t_pxobject*)mo, "signal");
   mo->msp_data.z_misc &= Z_NO_INPLACE;
   return mo;
}

void MessageDSP(MyObject* mo, t_signal** signal, short* count) {
   #pragma unused(mo)
   #pragma unused(count)
   dsp_add(Perform, 5, 5, signal[0]->s_vec, signal[1]->s_vec, signal[2]->s_vec,
         signal[3]->s_vec, signal[0]->s_n);
}

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<count; i++) {
      outputL[i] = inputL[i];
      outputR[i] = inputR[i];
   }

   return parameters+pcount+1;
}


Exercises

  1. Compile and test the thrustereo~ object.

  2. Verify that the two outputs of thrustereo~ are equivalent with the following patch:

    If you can here noise coming out of the thrustereo~ object, then the above patch should generate silence.