/* (C) Guenter Geiger */ #include "math.h" #include /* ----------------------------- exp ----------------------------- */ static t_class *exp_class; #define INVTWOPI 0.15915494f typedef struct _exp { t_object x_obj; } t_exp; static void *exp_new(t_symbol *s, int argc, t_atom *argv) { if (argc > 1) post("+~: extra arguments ignored"); { t_exp *x = (t_exp *)pd_new(exp_class); /* inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);*/ outlet_new(&x->x_obj, &s_signal); return (x); } } t_int *exp_perform(t_int *w) { t_float *in1 = (t_float *)(w[1]); t_float *out = (t_float *)(w[2]); int n = (int)(w[3]); while (n--) *out++ = (t_float) exp(*in1++); return (w+4); } t_int *exp_perf8(t_int *w) { t_float *in1 = (t_float *)(w[1]); t_float *out = (t_float *)(w[2]); int n = (int)(w[3]); for (; n; n -= 8, in1 += 8, out += 8) { float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3]; float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7]; out[0] = (t_float) exp(f0); out[1] = (t_float) exp(f1); out[2] = (t_float) exp(f2); out[3] = (t_float) exp(f3); out[4] = (t_float) exp(f4); out[5] = (t_float) exp(f5); out[6] = (t_float) exp(f6); out[7] = (t_float) exp(f7); } return (w+4); } void dsp_add_exp(t_sample *in1, t_sample *out, int n) { if (n&7) dsp_add(exp_perform, 3, in1, out, n); else dsp_add(exp_perf8, 3, in1, out, n); } static void exp_dsp(t_exp *x, t_signal **sp) { dsp_add_exp(sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); } void exp_tilde_setup(void) { exp_class = class_new(gensym("exp~"), (t_newmethod)exp_new, 0, sizeof(t_exp), 0, A_GIMME, 0); class_addmethod(exp_class, nullfn, gensym("signal"), 0); class_addmethod(exp_class, (t_method)exp_dsp, gensym("dsp"), 0); }