Digital Music Programming II: thru~




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


Source Code Example Usage
thru.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, 1);
   outlet_new((t_pxobject*)mo, "signal");
   return mo;
}

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


t_int* Perform(t_int *parameters) {
   long     pcount  = (long)    (parameters[1]);
   t_float *input   = (t_float*)(parameters[2]);
   t_float *output  = (t_float*)(parameters[3]);
   long     count   = (long)    (parameters[4]);
   long     i;

   for (i=0; i<count; i++) {
      output[i] = input[i];
   }
   
   return parameters+pcount+1;
}


Exercises

  1. Compile and test the thru~ object.

  2. Verify that the output of thru~ is equivalent to its input with the following patch:

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