[PD-dev] Creating an external / sinewave equation example

Patrice Colet colet.patrice at free.fr
Sat Sep 10 10:52:47 CEST 2011


----- "Rick T" <ratulloch at gmail.com> a écrit :

> On Fri, Sep 9, 2011 at 4:37 PM, Patrice Colet < colet.patrice at free.fr
> > wrote:
> 
> 
> 
> 
> ----- "Rick T" < ratulloch at gmail.com > a écrit :
> 
> > On Fri, Sep 9, 2011 at 2:46 PM, Patrice Colet <
> colet.patrice at free.fr
> > > wrote:
> >
> >
> > Hello, I'm not a C expert but I see errors in your code
> >
> > ----- "Rick T" < ratulloch at gmail.com > a écrit :
> >
> >
> > > Greetings All
> > >
> > >
> > > I'm having trouble getting my external to work, It compiles with 5
> > > warnings
> > > sineq.c:48: warning: unused variable ‘x’
> > > sineq.c:49: warning: unused variable ‘in1’
> > > sineq.c:50: warning: unused variable ‘in2’
> > > sineq.c:51: warning: unused variable ‘in3’
> > > sineq.c:52: warning: unused variable ‘in4’
> > >
> >
> > in http://iem.at/pd/externals-HOWTO/node6.html it's not a t_float
> but
> > a t_sample for using those variables
> >
> >
> >
> > True but the variables in my external are floats not samples like in
> > the example pan~ which takes in 2 different signals. I'm taking in 4
> > different floats (numbers)
> >
> 
> Allright, maybe you should directly name your variables amp freq phase
> and vertoff
> instead of in1 in2 in3 and in4
> 
> 
> Changing these just caused more errors I think the *in and *out are a
> pd reserved class to create inputs and outputs
> 

the *in and *out are just variable names, representing samples from the signal vector,
in bassemu~.c they are called *inbuf and *outbuf...

AFAIU you just need an output signal, would you mind trying something like this:


static void sineq_tilde_amp (t_sineq_tilde *x, t_floatarg f)
{
	if ((f >= 0) && (f <= 1))
		x->amp = f;
	else
		x->amp = 0;
}


static void sineq_tilde_freq (t_sineq_tilde *x, t_floatarg f)
{
	if ((f > 0) && (f <= 20000))
		x->freq = f;
	else
		x->freq = 0;
}



static void sineq_tilde_phase (t_sineq_tilde *x, t_floatarg f)
{
	if ((f >= -1) && (f <= 1))
		x->phase = f;
	else
		if (f < -1) x->phase = -1;
		if (f > 1) x->phase = 1;
}


static void sineq_tilde_vertoff (t_sineq_tilde *x, t_floatarg f)
{
	if ((f >= -1) && (f <= 1))
		x->vertoff = f;
	else
		if (f < -1) x->vertoff = -1;
		if (f > 1) x->vertoff = 1;
}




t_int *sineq_tilde_perform(t_int *w)
{
        t_sineq_tilde *x        = (t_sineq_tilde *)(w[1]);    
        t_sample           *out = (t_sample *)(w[2]);
        int                   n = (int)           (w[3]);

        while (n--)
        {      
                *out++ = x->amp*sin(2*PI*x->freq+(deg2rad(x->phase)))+x->vertoff;
        }
        return (w+4);
}

static void *sineq_tilde_new(t_symbol *s, int argc, t_atom *argv)
{
	unsigned int numargs;
    t_sineq_tilde *x = (t_sineq_tilde *)pd_new(sineq_tilde_class);

	outlet_new(&x->x_obj, gensym("signal"));
    return (x);
}


void sineq_tilde_dsp(t_sineq_tilde *x, t_signal **sp)
{
        dsp_add(sineq_tilde_perform, 3, x,
                sp[0]->s_vec, sp[0]->s_n);
}
 
void sineq_tilde_setup(void)
{
        sineq_tilde_class = class_new(gensym("sineq~"),
                (t_newmethod)sineq_tilde_new, 0,
                sizeof(t_sineq_tilde), 0,
                A_DEFFLOAT, 0);
        class_addmethod(sineq_tilde_class,
                (t_method)sineq_tilde_dsp, gensym("dsp"), 0);
        CLASS_MAINSIGNALIN(sineq_tilde_class,t_sineq_tilde, f);
	class_addmethod(sineq_tilde, (t_method)sineq_tilde_amp,	gensym("amp"), A_DEFFLOAT, 0);
	class_addmethod(sineq_tilde, (t_method)sineq_tilde_freq, gensym("freq"), A_DEFFLOAT, 0);
	class_addmethod(sineq_tilde, (t_method)sineq_tilde_phase, gensym("phase"), A_DEFFLOAT, 0);
	class_addmethod(sineq_tilde, (t_method)sineq_tilde_vertoff, gensym("vertoff"), A_DEFFLOAT, 0);
}


I didn't try this code but i think it should look like this

You might want to post this thread in pd_list, then more people that is able to help would interact.




> 
> 
> 
> 
> 
> >
> >
> > >
> > > It does a "make" successfully but I get this warning message
> > > /usr/bin/ld: warning: cannot find entry symbol xport_dynamic;
> > > defaulting to 00000000000007f0
> > >
> >
> > it's certainly caused by your makefile during linking, it's rather
> > export_dynamic, you've certainly made a typo ^^
> >
> >
> >
> > I thought so to but when I take a look at the make file it looks
> fine
> > here's a link to the code in (pastebin)
> >
> 
> Okay, in fact you should write:
> 
> -Wl,-export-dynamic to pass it with gcc
> 
> 
> This caused compilation to fail so I had to take it out
> 
> 

What does the console say?

> 
> 
> 
> 
> 
> > >
> > > but when I try and add it in PD it says "couldn't create". I've
> > looked
> > > at the pan~ tutorial and the d_osc.c file as recommended, which
> did
> > > help. I tried to take pieces from the two which I thought were
> > > applicable to my situation but I'm still having some issues.
> > >
> >
> > maybe a little look into bassmu~ source code could also be
> interesting
> 
> 
> 
> I looked into it but this seems more complex than the d_osc.c file I
> need easier at the moment not more complex
> 
> 


I've found bassemu~.c perform part easier to understand than d_osc~.c that's why I suggested to have a look.




> 
> >
> >
> >
> > Do you know the name for the source file or know where I can find
> it?
> > I typed in bassmu~
> > in PD and nothing came back.
> >
> 
> ah sorry I've made a typo :D
> it's bassemu~
> 
> you can get it in pd-extended externals sources
> 
> 
> 
> 
> >
> >
> >
> >
> >
> >
> > >
> > > Here's a link to the workflow (dropbox)
> > > http://dl.dropbox.com/u/6576402/questions/pd/Sine_EQ_Diagram.jpg
> > >
> > >
> > > Here's a link to the C code online (pastebin)
> > > http://pastebin.com/9rK3szUE
> > >
> > >
> > >
> > >
> > > My external is a reproduction of the sinewave equation with 4
> inputs
> > > and one output my logic is to have 4 inlets one for the
> > > frequency,amplitude,phase and vertical offset and an output for
> the
> > > created signal. Granted this isn't the final equation but this
> will
> > > help me understand how to create the full equation once done. If
> you
> > > want to see the full equation I'll be using here's a link to it
> > below.
> > > Basically it's a 1 second periodic signal with the sample rate at
> > > 44100 which the equation gives me control over the
> > > frequency,amplitude,phase and vertical offset, which will be
> > > controlled by a usb midi controller.
> > >
> > >
> > > Another question I have is what do I use for the t (time) for my
> > final
> > > equation is that the t_sample object in PD? or do I need to create
> a
> > > for loop counting from 1-44100 for a 1 second 44100 sampled
> > equation?
> > >
> > >
> > > http://dl.dropbox.com/u/6576402/questions/eq1.txt
> > >
> > >
> > >
> > >
> > > PS: I'm compiling on ubuntu 10.04 using gcc
> > >
> > > On Sun, Sep 4, 2011 at 12:13 PM, Martin Peach <
> > > martin.peach at sympatico.ca > wrote:
> > >
> > >
> > > On 2011-09-04 16:52, Rick T wrote:
> > > ...
> > >
> > >
> > >
> > >
> > > I've been able to find instructions on how to create a hello world
> > > C-external but not one that creates a simple sine wave from a
> > sinewave
> > > equation like A*sin(w*t+p)
> > > ( https://secure.wikimedia.org/ wikipedia/en/wiki/Sine_wave ) Does
> > > anyone
> > > have one or know where to find one.
> > >
> > > The canonical reference is here:
> > > http://iem.at/pd/externals- HOWTO/node6.html
> > > You just need to plug your equation into the perform routine.
> > > Also check the source for osc~ in d_osc.c of the Pd source, which
> > uses
> > > a fancy 32-bit float cosine table scanning method that was useful
> > when
> > > it mattered but is getting obsolete as a call to sin() is probably
> > > just as fast nowadays.
> > >
> > > Martin
> > >
> > >
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > Pd-dev mailing list
> > > Pd-dev at iem.at
> > > http://lists.puredata.info/listinfo/pd-dev
> >
> > --
> > Patrice Colet
> >
> >
> >
> > Aloha
> > and thanks for the help every bit helps --
> 
> --
> Patrice Colet
> 
> 
> 
> 
> aloha
> Rick 
> _______________________________________________
> Pd-dev mailing list
> Pd-dev at iem.at
> http://lists.puredata.info/listinfo/pd-dev

-- 
Patrice Colet 



More information about the Pd-dev mailing list