[PD] Help with writing externals

"thewade" < pdman at aproximation.org
Fri Apr 2 22:59:08 CEST 2004


Frank Barknecht hat gesagen:

> Do you really need link in librt, libjack and libasound?
No, I just copied some of the makefile stuff from the pd/src directory

OK, so the -c option lets me build my external, but now I cant load it. im sure I didnt code something right, but I dont know what to do with this error message

/home/wade/pd/general/fft-bin~.pd_linux: /home/wade/pd/general/fft-bin~.pd_linux: ELF file\'s phentsize not the expected size

Below here lies my external code:
fft-bin~.c--------------------------------------
#include <m_pd.h>

/*-------------------------------------------------------*/
/*fftbin~                                                */
/* A tool to extract specific bins from the output of    */
/* fft~. Inlets are (from left to right):                */
/* The output of fft~ and bang, the bin number to        */
/* capture.                                              */
/* The outlet is a control rate float equal to the value */
/* of the bin in question.                               */
/*-------------------------------------------------------*/

static t_class *fftbin_tilde_class;

typedef struct _fftbin {
  t_object  x_obj;
  t_sample dummy;
  int x_bin;
  float x_f;
} t_fftbin;

void *fftbin_tilde_new(t_floatarg f)
{
  t_symbol *p_signal = gensym(\"signal\");
  t_symbol *p_float = gensym(\"float\");
  
  t_fftbin *ref = (t_fftbin *)pd_new(fftbin_tilde_class);
  ref->x_bin=f;
  ref->x_f=0;
  inlet_new(&ref->x_obj, &ref->x_obj.ob_pd, p_signal, p_signal); //signal/bang inlet
  inlet_new(&ref->x_obj, &ref->x_obj.ob_pd, p_float, p_float);   //bin inlet
  outlet_new(&ref->x_obj, p_float);                              //bin value outlet
  return (void *)ref;
}

t_int *fftbin_tilde_perform(t_int *w) 
{
  t_fftbin  *ref = (t_fftbin *)(w[1]);         //data structure
  t_sample  *in1 = (t_sample *)(w[2]);         //fft~ output
  int        in2 = (int)(w[3]);                //bin number
  t_sample  *out = (t_float *)(w[4]);          //outlet
  int        n   = (int)(w[5]);                //number of samples in block

  int bin         = in2;                       //get bin number
  if (bin<0) bin  = 0;                         //clip bin to between 0 and n-1
  if (bin>=n) bin = n-1;
  ref->x_bin      = bin;                       //set datstructure
  ref->x_f        = (t_float)*in1+ref->x_bin;  //again, set datastructure
  *out            = ref->x_f;                  //output float value of bin

  return (w+6);
}

void fftbin_tilde_dsp(t_fftbin *ref, t_signal **sp)
{
  dsp_add(fftbin_tilde_perform, 5, ref,
          sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
  //trying to send datastructure, block of samples (inlet 1), and float (inlet 2)
  //to perform\'s t_int *w
}

void fftbin_tilde_set(t_fftbin *x, t_floatarg f)
{
  x->x_f = f;
}

void fftbin_tilde_bang(t_fftbin *x)
{
  outlet_float(x->x_obj.ob_outlet, x->x_f);
}

void fftbin_tilde_setup(void) {
  fftbin_tilde_class = class_new(gensym(\"fft-bin~\"),
        (t_newmethod)fftbin_tilde_new,
        0, sizeof(t_fftbin),
        CLASS_DEFAULT,
        A_DEFFLOAT, 0);

  class_addmethod(fftbin_tilde_class, 
        (t_method)fftbin_tilde_dsp, gensym(\"dsp\"), 0);
  class_addmethod(fftbin_tilde_class, 
        (t_method)fftbin_tilde_set, gensym(\"set\"), A_DEFFLOAT, 0);
  class_addbang(fftbin_tilde_class, fftbin_tilde_bang);

  CLASS_MAINSIGNALIN(fftbin_tilde_class, t_fftbin, x_f);
  post(\"fft-bin~: written by thewade with help from the PD list\");
}




More information about the Pd-list mailing list