Forums > Dev

Problem with Float inlet

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);
}


May 22, 2006 | 6:52 pm

You need to declare your subsample_float() method with a double arg, not
a float.

jb


May 22, 2006 | 7:00 pm

On May 22, 2006, at 8:56 AM, Enda wrote:

>
> void subsample_float(t_subsample *x, t_float val)
> {
> post("Float in: %d", val);
> x->x_deltime = val;
> }

If you are on PC, you need to make sure all float message arguments
are defined as a double. On PPC floats and doubles are passed on the
stack as Doubles. This is not true on x86. Otherwise I didn’t notice
anything suspect in your code (aside from the unused val passsed into
your new method, which has no float type argument as defined in setup
()).

-Joshua


May 23, 2006 | 5:38 pm

Thanks for that, the external is now compiling and working correctly. just one other little question, you said the there was an unused variable called val which didnt match the float defn inthe setup, was that referring to this code?? Im not 100% sure what you mean.
Thanks again!
enda


May 23, 2006 | 5:54 pm

On May 22, 2006, at 8:56 AM, Enda wrote:

> setup((t_messlist **)&subsample_class,(method)subsample_new,
> (method)dsp_free,
> (short)sizeof(t_subsample), 0L, 0);

subsample_new as registered in setup() has no typelist args. However
below it has a val arg which is unused. Surely not a real problem,
unless you try to use val at some point.

> 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);
> }

-Joshua


Viewing 5 posts - 1 through 5 (of 5 total)