Holiday notice: Cycling '74 will be closed Monday, October 9th. Manual authorization, support cases, and manual order processing will be delayed.

May 22 2006 | 3:56 pm

Hi everybody,
Im trying to write an external for the first time and I'm having a problem which I could do with some help on. Essentially I'm trying to inititally just create a simple MSP object that I can then use as a basis for further work. This object is a simple gain object with a single signal input and output, and a float input. This float is simply the gain factor that the ip signal is multiplied by.
The object compiles and runs fine until you change the float value and then it stops working (although it doesnt crash or anything, the audio cuts out). I'm pretty certain the problem is with my code for dealing with the float input but I cant see what it is. I've included the code, any help would be greatly appreciated!
thanks,
enda

#include "ext.h"
#include "z_dsp.h"
#include
// Test object, a gain multiplier

void *subsample_class;

typedef struct _subsample
{
t_pxobject x_obj;
t_float x_deltime;
} t_subsample;

void *subsample_new(double deltime);
t_int *subsample_perform(t_int *w);
void subsample_dsp(t_subsample *x, t_signal **sp, short *count);
void subsample_float(t_subsample *x, t_float val);

void main(void)
{
setup((t_messlist **)&subsample_class,(method)subsample_new, (method)dsp_free,
(short)sizeof(t_subsample), 0L, 0);
addmess((method)subsample_dsp, "dsp", A_CANT, 0);
addftx((method)subsample_float, 1);
dsp_initclass();
}

void *subsample_new(double val) // New instance routine for non-signal ip
{
t_subsample *x = (t_subsample *)newobject(subsample_class);
x->x_deltime= 1.0;
floatin((t_pxobject *)x,1);
dsp_setup((t_pxobject *)x,1);
outlet_new((t_pxobject *)x, "signal");
return (x);
}

void subsample_float(t_subsample *x, t_float val)
{
post("Float in: %d", val);
x->x_deltime = val;
}
void subsample_dsp(t_subsample *x, t_signal **sp, short *count)
{
dsp_add(subsample_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n, x);
}

t_int *subsample_perform(t_int *w)
{
t_float *inL = (t_float *)(w[1]);
t_float *outL = (t_float *)(w[2]);
int n = (int)(w[3]);
t_subsample *x = (t_subsample *)w[4];
while (n--)
*outL++ = x->x_deltime * *inL++;
return (w + 5);
}