Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*compiled on ubuntu 10.04 Linux*/
- #include "m_pd.h"
- #include "math.h"
- #define PI 3.14159265358979323846
- #define deg2rad(deg) ((deg * PI) / 180.0)
- #define rad2deg(rad) ((180.0 * rad) / PI)
- static t_class *sineq_tilde_class;
- typedef struct _sineq_tilde
- {
- t_object x_obj;
- t_float amp; /*amplitude*/
- t_float freq; /*frequency*/
- t_sample f_sineq;
- t_float f;
- t_float phase; /*phase in radians*/
- t_float vertoff; /*vertical offset*/
- } t_sineq_tilde;
- void *sineq_tilde_new(t_floatarg f)
- {
- t_sineq_tilde *x =(t_sineq_tilde *)pd_new(sineq_tilde_class);
- x->f_sineq = f;
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, &s_float);
- floatinlet_new(&x->x_obj, &x->amp);
- floatinlet_new(&x->x_obj, &x->freq);
- floatinlet_new(&x->x_obj, &x->phase);
- floatinlet_new(&x->x_obj, &x->vertoff);
- x->amp = 0;
- x->freq = 0;
- x->phase = 0;
- x->vertoff = 0;
- outlet_new(&x->x_obj, gensym("signal"));
- return (void *)x;
- }
- t_int *sineq_tilde_perform(t_int *w)
- {
- t_sineq_tilde *x = (t_sineq_tilde *)(w[1]);
- t_float *in1 = (t_float *)(w[2]);
- t_float *in2 = (t_float *)(w[3]);
- t_float *in3 = (t_float *)(w[4]);
- t_float *in4 = (t_float *)(w[5]);
- t_sample *out = (t_sample *)(w[6]);
- int n = (int) (w[7]);
- /*not sure how to implement the t value here*/
- /*t_sample f_sineq = y=amp*sin(freq*time+phase)+vertoff */
- while (n--)
- {
- float amp=w[2];
- float freq=w[3];
- float phase=w[4];
- float vertoff=w[5];
- *out++ = amp*sin(2*PI*freq+(deg2rad(phase)))+vertoff;
- }
- return (w+8);
- }
- void sineq_tilde_dsp(t_sineq_tilde *x, t_signal **sp)
- {
- dsp_add(sineq_tilde_perform, 7, x,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,
- sp[4]->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);
- }
Advertisement
Add Comment
Please, Sign In to add comment