OK, so I looked at the makefile in externals/build/linux and this is my new makefile (which seems to work):
-----------makefile--------------------------------
LDFLAGS = -Wl,-export_dynamic -shared
LIB = -lc -lm
INCLUDE = -I. -I/usr/local/include
BIN_DIR = ../general
LIB_DIR = lib
EXT = pd_linux
STRIP = strip --strip-unneeded -R .note -R .comment
CC = gcc
LINUXCFLAGS = -fPIC -DPD -DUNIX -O2 -funroll-loops -fomit-frame-pointer \\
-Wall -W -Wshadow -Wstrict-prototypes \\
-Wno-unused -Wno-parentheses -Wno-switch
sphere:
$(CC) $(LINUXCFLAGS) $(INCLUDE) -o $(LIB_DIR)/sphere~.o -c sphere~.c
$(CC) $(LDFLAGS) -o $(BIN_DIR)/sphere~.$(EXT) $(LIB_DIR)/sphere~.o $(LIB)
chmod a-x \"$(BIN_DIR)/sphere~.$(EXT)\"
$(STRIP) sphere~.$(EXT)
rm -f \"$(LIB_DIR)/sphere~.o\"
fftbin:
$(CC) $(LINUXCFLAGS) $(INCLUDE) -o $(LIB_DIR)/fftbin~.o -c fftbin~.c
$(CC) $(LDFLAGS) -o $(BIN_DIR)/fftbin~.$(EXT) $(LIB_DIR)/fftbin~.o $(LIB)
chmod a-x $(BIN_DIR)/fftbin~.$(EXT)
$(STRIP) $(BIN_DIR)/fftbin~.$(EXT)
rm -f $(LIB_DIR)/fftbin~.o
----------------------------------------------------
So, my external loads fine, but when I invoke it I get:
Segmentation fault
which is an error I cant really use to debug, other then my my perform
function is using too many (t_int *w) elements, or Im not asking for
enough elements in my dsp function. Also I get too many inlets. I want
one signal rate inlet that takes signal and bang, like snapshot, and
another that takes in control rate floats (int). The dsp_add function
and its relation to the perform functions (t_int *w) has always
confused me. Could someone help me to get this straight in my head?
Thanks for all the help Frank and carmen,
-thewade
Heres my code again:
------fftbin~.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(\"fftbin~\"),
(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(\"fftbin~: written by thewade with help from the PD list\");
}