From 4f8c7c28f8ece71d15ed28ae30f253725f1efa39 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 20 Oct 2012 18:32:25 +0000 Subject: update code format to pd-style: astyle --style=ansi --align-pointer=name *.c svn path=/trunk/externals/moonlib/; revision=16427 --- tabenv.c | 185 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 93 insertions(+), 92 deletions(-) (limited to 'tabenv.c') diff --git a/tabenv.c b/tabenv.c index 9b52fbe..b499e22 100644 --- a/tabenv.c +++ b/tabenv.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA typedef struct tabenv { - /*env part*/ + /*env part*/ t_object x_obj; /* header */ t_outlet *x_outlet; /* a "float" outlet */ t_clock *x_clock; /* a "clock" object */ @@ -40,9 +40,9 @@ typedef struct tabenv int x_npoints; /* analysis window size in samples */ float x_result; /* result to output */ float x_sumbuf[MAXOVERLAP]; /* summing buffer */ - float x_f; - - /*tabplay part*/ + float x_f; + + /*tabplay part*/ int x_tabphase; int x_nsampsintab; int x_limit; @@ -64,11 +64,11 @@ static void *tabenv_new(t_symbol *s,t_floatarg fnpoints, t_floatarg fperiod) if (npoints < 1) npoints = 1024; if (period < 1) period = npoints/2; if (period < npoints / MAXOVERLAP + 1) - period = npoints / MAXOVERLAP + 1; + period = npoints / MAXOVERLAP + 1; if (!(buf = getbytes(sizeof(float) * (npoints + MAXVSTAKEN)))) { - error("env: couldn't allocate buffer"); - return (0); + error("env: couldn't allocate buffer"); + return (0); } x = (t_tabenv *)pd_new(tabenv_class); x->x_buf = buf; @@ -77,17 +77,17 @@ static void *tabenv_new(t_symbol *s,t_floatarg fnpoints, t_floatarg fperiod) x->x_period = period; for (i = 0; i < MAXOVERLAP; i++) x->x_sumbuf[i] = 0; for (i = 0; i < npoints; i++) - buf[i] = (1. - cos((2 * 3.14159 * i) / npoints))/npoints; + buf[i] = (1. - cos((2 * 3.14159 * i) / npoints))/npoints; for (; i < npoints+MAXVSTAKEN; i++) buf[i] = 0; x->x_clock = clock_new(x, (t_method)tabenv_tick); x->x_outlet = outlet_new(&x->x_obj, gensym("float")); x->x_f = 0; - /* tabplay */ + /* tabplay */ x->x_tabphase = 0x7fffffff; x->x_limit = 0; x->x_arrayname = s; - + return (x); } @@ -97,34 +97,34 @@ static t_int *sigenv_perform(t_int *w) t_float *in = (t_float *)(w[2]); int n = (int)(w[3]); int count; - float *sump; + float *sump; in += n; for (count = x->x_phase, sump = x->x_sumbuf; - count < x->x_npoints; count += x->x_realperiod, sump++) + count < x->x_npoints; count += x->x_realperiod, sump++) { - float *hp = x->x_buf + count; - float *fp = in; - float sum = *sump; - int i; - - for (i = 0; i < n; i++) - { - fp--; - sum += *hp++ * (*fp * *fp); - } - *sump = sum; + float *hp = x->x_buf + count; + float *fp = in; + float sum = *sump; + int i; + + for (i = 0; i < n; i++) + { + fp--; + sum += *hp++ * (*fp * *fp); + } + *sump = sum; } sump[0] = 0; x->x_phase -= n; if (x->x_phase < 0) { - x->x_result = x->x_sumbuf[0]; - for (count = x->x_realperiod, sump = x->x_sumbuf; - count < x->x_npoints; count += x->x_realperiod, sump++) - sump[0] = sump[1]; - sump[0] = 0; - x->x_phase = x->x_realperiod - n; - clock_delay(x->x_clock, 0L); + x->x_result = x->x_sumbuf[0]; + for (count = x->x_realperiod, sump = x->x_sumbuf; + count < x->x_npoints; count += x->x_realperiod, sump++) + sump[0] = sump[1]; + sump[0] = 0; + x->x_phase = x->x_realperiod - n; + clock_delay(x->x_clock, 0L); } return (w+4); } @@ -134,28 +134,28 @@ static t_int *tabplay_tilde_perform(t_int *w) t_tabenv *x = (t_tabenv *)(w[1]); t_float *out = (t_float *)(w[2]), *fp; int n = (int)(w[3]), phase = x->x_phase, - endphase = (x->x_nsampsintab < x->x_limit ? - x->x_nsampsintab : x->x_limit), nxfer, n3; + endphase = (x->x_nsampsintab < x->x_limit ? + x->x_nsampsintab : x->x_limit), nxfer, n3; if (!x->x_vec || phase >= endphase) - goto zero; - + goto zero; + nxfer = endphase - phase; fp = x->x_vec + phase; if (nxfer > n) - nxfer = n; + nxfer = n; n3 = n - nxfer; phase += nxfer; while (nxfer--) - *out++ = *fp++; + *out++ = *fp++; if (phase >= endphase) { - clock_delay(x->x_clock, 0); - x->x_phase = 0x7fffffff; - while (n3--) - *out++ = 0; + clock_delay(x->x_clock, 0); + x->x_phase = 0x7fffffff; + while (n3--) + *out++ = 0; } else x->x_phase = phase; - + return (w+4); zero: while (n--) *out++ = 0; @@ -167,35 +167,35 @@ static void tabenv_perform_64(t_tabenv *x,t_float *in) { int n = 64; int count; - float *sump; + float *sump; in += n; for (count = x->x_phase, sump = x->x_sumbuf; - count < x->x_npoints; count += x->x_realperiod, sump++) + count < x->x_npoints; count += x->x_realperiod, sump++) { - float *hp = x->x_buf + count; - float *fp = in; - float sum = *sump; - int i; - - for (i = 0; i < n; i++) - { - fp--; - sum += *hp++ * (*fp * *fp); - } - *sump = sum; + float *hp = x->x_buf + count; + float *fp = in; + float sum = *sump; + int i; + + for (i = 0; i < n; i++) + { + fp--; + sum += *hp++ * (*fp * *fp); + } + *sump = sum; } sump[0] = 0; x->x_phase -= n; if (x->x_phase < 0) { - x->x_result = x->x_sumbuf[0]; - for (count = x->x_realperiod, sump = x->x_sumbuf; - count < x->x_npoints; count += x->x_realperiod, sump++) - sump[0] = sump[1]; - sump[0] = 0; - x->x_phase = x->x_realperiod - n; - /*clock_delay(x->x_clock, 0L);*/ - outlet_float(x->x_outlet, powtodb(x->x_result)); + x->x_result = x->x_sumbuf[0]; + for (count = x->x_realperiod, sump = x->x_sumbuf; + count < x->x_npoints; count += x->x_realperiod, sump++) + sump[0] = sump[1]; + sump[0] = 0; + x->x_phase = x->x_realperiod - n; + /*clock_delay(x->x_clock, 0L);*/ + outlet_float(x->x_outlet, powtodb(x->x_result)); } } @@ -207,14 +207,14 @@ static void tabenv_set(t_tabenv *x, t_symbol *s) x->x_arrayname = s; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { - if (*s->s_name) pd_error(x, "tabenv: %s: no such array", - x->x_arrayname->s_name); - x->x_vec = 0; + if (*s->s_name) pd_error(x, "tabenv: %s: no such array", + x->x_arrayname->s_name); + x->x_vec = 0; } else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec)) { - error("%s: bad template for tabenv", x->x_arrayname->s_name); - x->x_vec = 0; + error("%s: bad template for tabenv", x->x_arrayname->s_name); + x->x_vec = 0; } else garray_usedindsp(a); } @@ -222,48 +222,49 @@ static void tabenv_set(t_tabenv *x, t_symbol *s) static void sigenv_dsp(t_tabenv *x, t_signal **sp) { if (x->x_period % sp[0]->s_n) x->x_realperiod = - x->x_period + sp[0]->s_n - (x->x_period % sp[0]->s_n); + x->x_period + sp[0]->s_n - (x->x_period % sp[0]->s_n); else x->x_realperiod = x->x_period; dsp_add(sigenv_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); if (sp[0]->s_n > MAXVSTAKEN) bug("sigenv_dsp"); } static void tabenv_list(t_tabenv *x, t_symbol *s, - int argc, t_atom *argv) + int argc, t_atom *argv) { long start = atom_getfloatarg(0, argc, argv); long length = atom_getfloatarg(1, argc, argv); - float *limitp,*p; - int i; + float *limitp,*p; + int i; - tabenv_set(x, x->x_arrayname); + tabenv_set(x, x->x_arrayname); - if (start < 0) start = 0; + if (start < 0) start = 0; if (length <= 0) - x->x_limit = 0x7fffffff; + x->x_limit = 0x7fffffff; else - x->x_limit = start + length; + x->x_limit = start + length; x->x_tabphase = start; - if(length <= 0) length = x->x_nsampsintab - 1; - if(start >= x->x_nsampsintab) start = x->x_nsampsintab - 1; - if((start + length) >= x->x_nsampsintab) - length = x->x_nsampsintab - 1 - start; - - limitp = x->x_vec + start + length - 63; - /*limitp = x->x_vec + 2048;*/ + if(length <= 0) length = x->x_nsampsintab - 1; + if(start >= x->x_nsampsintab) start = x->x_nsampsintab - 1; + if((start + length) >= x->x_nsampsintab) + length = x->x_nsampsintab - 1 - start; + + limitp = x->x_vec + start + length - 63; + /*limitp = x->x_vec + 2048;*/ /*if (x->x_period % length) x->x_realperiod = - x->x_period + length - (x->x_period % length); - else*/ x->x_realperiod = x->x_period; + x->x_period + length - (x->x_period % length); + else*/ + x->x_realperiod = x->x_period; - for(p = x->x_vec + start; p < limitp ; p += 64) - tabenv_perform_64( x , p ); + for(p = x->x_vec + start; p < limitp ; p += 64) + tabenv_perform_64( x , p ); } static void tabenv_reset(t_tabenv *x) { int i; - x->x_phase = 0; + x->x_phase = 0; for (i = 0; i < MAXOVERLAP; i++) x->x_sumbuf[i] = 0; } @@ -282,12 +283,12 @@ static void tabenv_ff(t_tabenv *x) /* cleanup on free */ void tabenv_setup(void ) { tabenv_class = class_new(gensym("tabenv"), (t_newmethod)tabenv_new, - (t_method)tabenv_ff, sizeof(t_tabenv), 0, A_DEFSYM, A_DEFFLOAT, A_DEFFLOAT, 0); + (t_method)tabenv_ff, sizeof(t_tabenv), 0, A_DEFSYM, A_DEFFLOAT, A_DEFFLOAT, 0); CLASS_MAINSIGNALIN(tabenv_class, t_tabenv, x_f); class_addmethod(tabenv_class, (t_method)tabenv_reset, - gensym("reset"), 0); + gensym("reset"), 0); class_addmethod(tabenv_class, (t_method)tabenv_set, - gensym("set"), A_DEFSYM, 0); + gensym("set"), A_DEFSYM, 0); class_addlist(tabenv_class, tabenv_list); } -- cgit v1.2.1