From fc3d3c0a4f110a23335398c327ac0a4fc949d5cb Mon Sep 17 00:00:00 2001 From: Guenter Geiger Date: Mon, 17 Jun 2002 10:13:57 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r12, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/ggee/; revision=13 --- signal/apply~.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 signal/apply~.c (limited to 'signal/apply~.c') diff --git a/signal/apply~.c b/signal/apply~.c new file mode 100644 index 0000000..7463383 --- /dev/null +++ b/signal/apply~.c @@ -0,0 +1,151 @@ +/* (C) Guenter Geiger */ + + +#include "math.h" +#include + +/* ----------------------------- apply ----------------------------- */ +static t_class *apply_class; + + +typedef double (*t_apply_onearg)(double); +typedef double (*t_apply_twoarg)(double); + +static double nop(double f) { + return f; +} + +typedef struct _funlist { + char* name; + t_int* fun; + int numarg; + char* desc; +} t_funlist; + +#define MFUN1(x,d) {#x,(t_int*)x,1,d} + +static t_funlist funlist[] = + { + MFUN1(nop,"does nothing"), + MFUN1(sin,"calculate sine"), + MFUN1(asin,"calculate arcus sine"), + MFUN1(cos,"calculate cosine"), + MFUN1(acos,"calculate arcus cosine"), + MFUN1(tan,"calculate tangent"), + MFUN1(atan,"calculate arcus tangent"), + + MFUN1(sinh,""), + MFUN1(asinh,""), + MFUN1(cosh,""), + MFUN1(acosh,""), + MFUN1(tanh,""), + MFUN1(atanh,""), + + MFUN1(exp,""), + MFUN1(expm1,""), + // MFUN1(exp10), + // MFUN1(pow10), + MFUN1(log,""), + MFUN1(log1p,""), + MFUN1(log10,""), + // MFUN1(log2), + MFUN1(sqrt,""), + MFUN1(cbrt,""), + + + MFUN1(rint,""), + // MFUN1(round), + MFUN1(ceil,""), + MFUN1(floor,""), + // MFUN1(trunc), + + MFUN1(erf,""), + MFUN1(erfc,""), + MFUN1(gamma,""), + MFUN1(lgamma,""), + // MFUN1(tgamma), + + MFUN1(j0,""), + MFUN1(j1,""), + MFUN1(y0,""), + MFUN1(j1,"") + }; + + + +typedef struct _apply +{ + t_object x_obj; + t_int* x_fun; +} t_apply; + +static void *apply_new(t_symbol *s, int argc, t_atom *argv) +{ + t_symbol* fname; + int i; + int numfun = sizeof(funlist)/sizeof(t_funlist); + t_apply *x = (t_apply *)pd_new(apply_class); + outlet_new(&x->x_obj, &s_signal); + + x->x_fun = (t_int*)nop; + if (argc < 1) { + post("nop operation requested"); + } + else { + if (argv[0].a_type != A_SYMBOL) + goto nofun; + fname = atom_getsymbol(argv); + for (i=0;is_name,funlist[i].name)) + x->x_fun = funlist[i].fun; + + + + } + + + return (x); + nofun: + post("apply first argument has to be a function"); + return (x); +} + + +static void apply_what(t_apply* x) +{ + int i; + int numfun = sizeof(funlist)/sizeof(t_funlist); + for (i=0;ix_fun)(*in1++); + return (w+5); +} + + +void dsp_add_apply(t_apply* x,t_sample *in1, t_sample *out, int n) +{ + dsp_add(apply_perform, 4,x, in1, out, n); +} + +static void apply_dsp(t_apply *x, t_signal **sp) +{ + dsp_add_apply(x,sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); +} + +void apply_tilde_setup(void) +{ + apply_class = class_new(gensym("apply~"), (t_newmethod)apply_new, 0, + sizeof(t_apply), 0, A_GIMME, 0); + class_addmethod(apply_class, nullfn, gensym("signal"), 0); + class_addmethod(apply_class, (t_method)apply_dsp, gensym("dsp"), 0); + class_addmethod(apply_class, (t_method)apply_what, gensym("what"), 0); +} -- cgit v1.2.1