Advertisement
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;
- float amp; /*amplitude*/
- float freq; /*frequency*/
- t_sample f_sineq;
- float f;
- float phase; /*phase in radians*/
- float vertoff; /*vertical offset*/
- } t_sineq_tilde;
- 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 >= -2*PI) && (f <= 2*PI))
- x->phase = f;
- else
- if (f < -2*PI) x->phase = -2*PI;
- if (f > 2*PI) x->phase = 2*PI;
- }
- 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);
- }
- 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;
- }
- 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_class, (t_method)sineq_tilde_amp, gensym("amp"), A_DEFFLOAT, 0);
- class_addmethod(sineq_tilde_class, (t_method)sineq_tilde_freq, gensym("freq"), A_DEFFLOAT, 0);
- class_addmethod(sineq_tilde_class, (t_method)sineq_tilde_phase, gensym("phase"), A_DEFFLOAT, 0);
- class_addmethod(sineq_tilde_class, (t_method)sineq_tilde_vertoff, gensym("vertoff"), A_DEFFLOAT, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement