From 53f05d96ff8e49c87977fa91a06ebade8893606e Mon Sep 17 00:00:00 2001 From: "N.N." Date: Fri, 5 Sep 2003 10:03:46 +0000 Subject: *** empty log message *** svn path=/trunk/externals/miXed/; revision=931 --- cyclone/sickle/Makefile.sources | 1 + cyclone/sickle/Scope.c | 14 +-- cyclone/sickle/allsickles.c | 2 + cyclone/sickle/buffir.c | 213 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 220 insertions(+), 10 deletions(-) create mode 100644 cyclone/sickle/buffir.c (limited to 'cyclone/sickle') diff --git a/cyclone/sickle/Makefile.sources b/cyclone/sickle/Makefile.sources index d39cc17..901be5b 100644 --- a/cyclone/sickle/Makefile.sources +++ b/cyclone/sickle/Makefile.sources @@ -19,6 +19,7 @@ bitnot.c \ bitor.c \ bitshift.c \ bitxor.c \ +buffir.c \ capture.c \ cartopol.c \ change.c \ diff --git a/cyclone/sickle/Scope.c b/cyclone/sickle/Scope.c index 8a09d78..adfa51b 100644 --- a/cyclone/sickle/Scope.c +++ b/cyclone/sickle/Scope.c @@ -794,7 +794,7 @@ static void scope_vis(t_gobj *z, t_glist *glist, int vis) if (vis) { t_scopehandle *sh = (t_scopehandle *)x->x_handle; -#ifndef PD_MINOR_VERSION +#if FORKY_VERSION < 37 rtext_new(glist, t, glist->gl_editor->e_rtext, 0); #endif sprintf(sh->h_pathname, ".x%x.h%x", (int)cv, (int)sh); @@ -805,7 +805,7 @@ static void scope_vis(t_gobj *z, t_glist *glist, int vis) } else { -#ifndef PD_MINOR_VERSION +#if FORKY_VERSION < 37 t_rtext *rt = glist_findrtext(glist, t); if (rt) rtext_free(rt); #endif @@ -848,14 +848,7 @@ static t_widgetbehavior scope_widgetbehavior = scope_delete, scope_vis, scope_click, - /* As of 0.37, pd does not have these last two elements in */ - /* a t_widgetbehavoir anymore. */ -#if PD_MAJOR_VERSION == 0 -#if PD_MINOR_VERSION < 37 || !defined(PD_MINOR_VERSION) - scope_save, - 0 -#endif -#endif + FORKY_WIDGETPADDING }; static void scope_setxymode(t_scope *x, int xymode) @@ -1040,6 +1033,7 @@ void Scope_tilde_setup(void) gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); class_setwidget(scope_class, &scope_widgetbehavior); + forky_setsavefn(scope_class, scope_save); scopehandle_class = class_new(gensym("_scopehandle"), 0, 0, sizeof(t_scopehandle), CLASS_PD, 0); class_addmethod(scopehandle_class, (t_method)scopehandle__clickhook, diff --git a/cyclone/sickle/allsickles.c b/cyclone/sickle/allsickles.c index d062c61..7771cf8 100644 --- a/cyclone/sickle/allsickles.c +++ b/cyclone/sickle/allsickles.c @@ -20,6 +20,7 @@ void bitnot_tilde_setup(void); void bitor_tilde_setup(void); void bitshift_tilde_setup(void); void bitxor_tilde_setup(void); +void buffir_tilde_setup(void); void capture_tilde_setup(void); void cartopol_tilde_setup(void); void change_tilde_setup(void); @@ -98,6 +99,7 @@ void allsickles_setup(void) bitor_tilde_setup(); bitshift_tilde_setup(); bitxor_tilde_setup(); + buffir_tilde_setup(); capture_tilde_setup(); cartopol_tilde_setup(); change_tilde_setup(); diff --git a/cyclone/sickle/buffir.c b/cyclone/sickle/buffir.c new file mode 100644 index 0000000..0551501 --- /dev/null +++ b/cyclone/sickle/buffir.c @@ -0,0 +1,213 @@ +/* Copyright (c) 2003 krzYszcz and others. + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ + +#include +#include "m_pd.h" +#include "common/loud.h" +#include "sickle/sic.h" +#include "sickle/arsic.h" + +#define BUFFIR_DEFSIZE 0 /* CHECKED */ +#define BUFFIR_MAXSIZE 128 + +typedef struct _buffir +{ + t_arsic x_arsic; + t_pd *x_offinlet; + t_pd *x_sizinlet; + t_float *x_lohead; + t_float *x_hihead; + int x_histsize; + t_float *x_histlo; + t_float *x_histhi; + t_float x_histini[2 * BUFFIR_MAXSIZE]; +} t_buffir; + +static t_class *buffir_class; + +static void buffir_setrange(t_buffir *x, t_floatarg f1, t_floatarg f2) +{ + int off = (int)f1; + int siz = (int)f2; + if (off < 0) + off = 0; + if (siz <= 0) + siz = BUFFIR_DEFSIZE; + if (siz > x->x_histsize) + { + int newsize, pos = x->x_lohead - x->x_histlo; + int oldbytes = x->x_histsize * sizeof(*x->x_histlo); + static int warned = 0; + if (!warned) + { + loud_incompatible(buffir_class, "stretching history buffer"); + warned = 1; + } + newsize = x->x_histsize * 2; + while (newsize < siz) newsize *= 2; + if (x->x_histlo == x->x_histini) + { + if (!(x->x_histlo = getbytes(2 * newsize * sizeof(*x->x_histlo)))) + x->x_histlo = x->x_histini; + else + { + x->x_histhi = x->x_histlo + newsize; + memcpy(x->x_histhi + pos - x->x_histsize, + x->x_lohead, oldbytes); + x->x_lohead = x->x_histlo + pos; + x->x_hihead = x->x_histhi + pos; + x->x_histsize = newsize; + } + } + else + { + if (!(x->x_histlo = + resizebytes(x->x_histlo, 2 * oldbytes, + 2 * newsize * sizeof(*x->x_histlo)))) + { + x->x_histsize = BUFFIR_MAXSIZE; + x->x_histlo = x->x_histini; + memset(x->x_histlo, 0, + 2 * x->x_histsize * sizeof(*x->x_histlo)); + x->x_lohead = x->x_histlo; + x->x_hihead = x->x_histhi = x->x_histlo + x->x_histsize; + } + else + { + x->x_histhi = x->x_histlo + newsize; + memcpy(x->x_histhi + pos - x->x_histsize, + x->x_lohead, oldbytes); + x->x_lohead = x->x_histlo + pos; + x->x_hihead = x->x_histhi + pos; + x->x_histsize = newsize; + } + } + } + pd_float(x->x_offinlet, off); + pd_float(x->x_sizinlet, siz); +} + +static void buffir_clear(t_buffir *x) +{ + memset(x->x_histlo, 0, 2 * x->x_histsize * sizeof(*x->x_histlo)); + x->x_lohead = x->x_histlo; + x->x_hihead = x->x_histhi = x->x_histlo + x->x_histsize; +} + +static void buffir_set(t_buffir *x, t_symbol *s, t_floatarg f1, t_floatarg f2) +{ + arsic_setarray((t_arsic *)x, s, 1); + buffir_setrange(x, f1, f2); +} + +static t_int *buffir_perform(t_int *w) +{ + t_arsic *sic = (t_arsic *)(w[1]); + t_buffir *x = (t_buffir *)sic; + int nblock = (int)(w[2]); + t_float *xin = (t_float *)(w[3]); + t_float *out = (t_float *)(w[6]); + t_float *lohead = x->x_lohead; + t_float *hihead = x->x_hihead; + if (sic->s_playable) + { + t_float *oin = (t_float *)(w[4]); + t_float *sin = (t_float *)(w[5]); + int vecsize = sic->s_vecsize; + t_float *vec = sic->s_vectors[0]; /* playable implies nonzero (mono) */ + int histsize = x->x_histsize; + while (nblock--) + { + /* CHECKME every sample or once per block. + If once per block, then LATER think about performance. */ + /* CHECKME rounding */ + int off = (int)*oin++; + int npoints = (int)*sin++; + if (off < 0) + off = 0; + if (npoints > histsize) + npoints = histsize; + if (npoints > vecsize - off) + npoints = vecsize - off; + if (npoints > 0) + { + t_float *coefp = vec + off; + t_float *hp = hihead; + t_float sum = 0.; + *lohead++ = *hihead++ = *xin++; + while (npoints--) + sum += *coefp++ * *hp--; + *out++ = sum; + } + else + { + *lohead++ = *hihead++ = *xin++; + *out++ = 0.; + } + if (lohead >= x->x_histhi) + { + lohead = x->x_histlo; + hihead = x->x_histhi; + } + } + } + else while (nblock--) + { + *lohead++ = *hihead++ = *xin++; + *out++ = 0.; + if (lohead >= x->x_histhi) + { + lohead = x->x_histlo; + hihead = x->x_histhi; + } + } + x->x_lohead = lohead; + x->x_hihead = hihead; + return (w + 7); +} + +static void buffir_dsp(t_buffir *x, t_signal **sp) +{ + arsic_dsp((t_arsic *)x, sp, buffir_perform, 1); +} + +static void buffir_free(t_buffir *x) +{ + if (x->x_histlo != x->x_histini) + freebytes(x->x_histlo, 2 * x->x_histsize * sizeof(*x->x_histlo)); + arsic_free((t_arsic *)x); +} + +static void *buffir_new(t_symbol *s, t_floatarg f1, t_floatarg f2) +{ + /* CHECKME always the first channel used. */ + /* three auxiliary signals: main, offset and size inputs */ + t_buffir *x = (t_buffir *)arsic_new(buffir_class, s, 0, 0, 3); + if (x) + { + arsic_setminsize((t_arsic *)x, 1); + x->x_offinlet = (t_pd *)sic_newinlet((t_sic *)x, f1); + x->x_sizinlet = (t_pd *)sic_newinlet((t_sic *)x, f2); + outlet_new((t_object *)x, &s_signal); + x->x_histsize = BUFFIR_MAXSIZE; + x->x_histlo = x->x_histini; + buffir_clear(x); + buffir_setrange(x, f1, f2); + } + return (x); +} + +void buffir_tilde_setup(void) +{ + buffir_class = class_new(gensym("buffir~"), + (t_newmethod)buffir_new, + (t_method)buffir_free, + sizeof(t_buffir), 0, + A_DEFSYM, A_DEFFLOAT, A_DEFFLOAT, 0); + arsic_setup(buffir_class, buffir_dsp, SIC_FLOATTOSIGNAL); + class_addmethod(buffir_class, (t_method)buffir_clear, + gensym("clear"), 0); + class_addmethod(buffir_class, (t_method)buffir_set, + gensym("set"), A_SYMBOL, A_DEFFLOAT, A_DEFFLOAT, 0); +} -- cgit v1.2.1