From ed932acb5860bf8b9296169676499562a55d139e Mon Sep 17 00:00:00 2001 From: Miller Puckette Date: Mon, 6 Sep 2004 20:20:36 +0000 Subject: checking in version 0.38test5. Oops, I realize I forgot some more nice files, will add them and re-commit. svn path=/trunk/; revision=2010 --- pd/src/d_ugen.c | 862 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 431 insertions(+), 431 deletions(-) (limited to 'pd/src/d_ugen.c') diff --git a/pd/src/d_ugen.c b/pd/src/d_ugen.c index 2c359c38..b72bad50 100644 --- a/pd/src/d_ugen.c +++ b/pd/src/d_ugen.c @@ -43,7 +43,7 @@ void voutlet_dspepilog(struct _voutlet *x, t_signal **parentsigs, int myvecsize, int phase, int period, int frequency, int downsample, int upsample /* IOhannes */, int reblock, int switched); -t_int *zero_perform(t_int *w) /* zero out a vector */ +t_int *zero_perform(t_int *w) /* zero out a vector */ { t_float *out = (t_float *)(w[1]); int n = (int)(w[2]); @@ -58,14 +58,14 @@ t_int *zero_perf8(t_int *w) for (; n; n -= 8, out += 8) { - out[0] = 0; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = 0; - out[6] = 0; - out[7] = 0; + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 0; + out[6] = 0; + out[7] = 0; } return (w+3); } @@ -73,9 +73,9 @@ t_int *zero_perf8(t_int *w) void dsp_add_zero(t_sample *out, int n) { if (n&7) - dsp_add(zero_perform, 2, out, n); - else - dsp_add(zero_perf8, 2, out, n); + dsp_add(zero_perform, 2, out, n); + else + dsp_add(zero_perf8, 2, out, n); } /* ---------------------------- block~ ----------------------------- */ @@ -116,15 +116,15 @@ typedef struct _block t_object x_obj; int x_vecsize; int x_overlap; - int x_phase; /* from 0 to period-1; when zero we run the block */ - int x_period; /* submultiple of containing canvas */ - int x_frequency; /* supermultiple of comtaining canvas */ + int x_phase; /* from 0 to period-1; when zero we run the block */ + int x_period; /* submultiple of containing canvas */ + int x_frequency; /* supermultiple of comtaining canvas */ int x_count; - int x_blocklength; /* length of dspchain for this block */ - int x_epiloglength; /* length of epilog */ - char x_switched; /* true if we're acting as a a switch */ - char x_switchon; /* true if we're switched on */ - char x_reblock; /* true if inlets and outlets are reblocking */ + int x_blocklength; /* length of dspchain for this block */ + int x_epiloglength; /* length of epilog */ + char x_switched; /* true if we're acting as a a switch */ + char x_switchon; /* true if we're switched on */ + char x_reblock; /* true if inlets and outlets are reblocking */ int x_upsample; /* IOhannes: upsampling-factor */ int x_downsample; /* IOhannes: downsampling-factor */ @@ -134,7 +134,7 @@ static void block_set(t_block *x, t_floatarg fvecsize, t_floatarg foverlap, t_floatarg fupsample); static void *block_new(t_floatarg fvecsize, t_floatarg foverlap, - t_floatarg fupsample) /* IOhannes */ + t_floatarg fupsample) /* IOhannes */ { t_block *x = (t_block *)pd_new(block_class); x->x_phase = 0; @@ -154,9 +154,9 @@ static void block_set(t_block *x, t_floatarg fvecsize, t_floatarg foverlap, int overlap = foverlap; int dspstate = canvas_suspend_dsp(); if (overlap < 1) - overlap = 1; + overlap = 1; if (vecsize < 0) - vecsize = 0; /* this means we'll get it from parent later. */ + vecsize = 0; /* this means we'll get it from parent later. */ /* IOhannes { */ if (fupsample <= 0) upsample = downsample = 1; @@ -171,24 +171,24 @@ static void block_set(t_block *x, t_floatarg fvecsize, t_floatarg foverlap, if (vecsize && (vecsize != (1 << ilog2(vecsize)))) { - pd_error(x, "block~: vector size not a power of 2"); - vecsize = 64; + pd_error(x, "block~: vector size not a power of 2"); + vecsize = 64; } if (overlap != (1 << ilog2(overlap))) { - pd_error(x, "block~: overlap not a power of 2"); - overlap = 1; + pd_error(x, "block~: overlap not a power of 2"); + overlap = 1; } /* IOhannes { */ if (downsample != (1 << ilog2(downsample))) { - pd_error(x, "block~: downsampling not a power of 2"); - downsample = 1; + pd_error(x, "block~: downsampling not a power of 2"); + downsample = 1; } if (upsample != (1 << ilog2(upsample))) { - pd_error(x, "block~: upsampling not a power of 2"); - upsample = 1; + pd_error(x, "block~: upsampling not a power of 2"); + upsample = 1; } /* } IOhannes */ @@ -203,7 +203,7 @@ static void block_set(t_block *x, t_floatarg fvecsize, t_floatarg foverlap, } static void *switch_new(t_floatarg fvecsize, t_floatarg foverlap, - t_floatarg fupsample) /* IOhannes */ + t_floatarg fupsample) /* IOhannes */ { t_block *x = (t_block *)(block_new(fvecsize, foverlap, fupsample)); /* IOhannes */ x->x_switched = 1; @@ -214,7 +214,7 @@ static void *switch_new(t_floatarg fvecsize, t_floatarg foverlap, static void block_float(t_block *x, t_floatarg f) { if (x->x_switched) - x->x_switchon = (f != 0); + x->x_switchon = (f != 0); } #define PROLOGCALL 2 #define EPILOGCALL 2 @@ -223,21 +223,21 @@ static t_int *block_prolog(t_int *w) { t_block *x = (t_block *)w[1]; int phase = x->x_phase; - /* if we're switched off, jump past the epilog code */ + /* if we're switched off, jump past the epilog code */ if (!x->x_switchon) - return (w + x->x_blocklength); + return (w + x->x_blocklength); if (phase) { - phase++; - if (phase == x->x_period) phase = 0; - x->x_phase = phase; - return (w + x->x_blocklength); /* skip block; jump past epilog */ + phase++; + if (phase == x->x_period) phase = 0; + x->x_phase = phase; + return (w + x->x_blocklength); /* skip block; jump past epilog */ } else { - x->x_count = x->x_frequency; - x->x_phase = (x->x_period > 1 ? 1 : 0); - return (w + PROLOGCALL); /* beginning of block is next ugen */ + x->x_count = x->x_frequency; + x->x_phase = (x->x_period > 1 ? 1 : 0); + return (w + PROLOGCALL); /* beginning of block is next ugen */ } } @@ -246,12 +246,12 @@ static t_int *block_epilog(t_int *w) t_block *x = (t_block *)w[1]; int count = x->x_count - 1; if (!x->x_reblock) - return (w + x->x_epiloglength + EPILOGCALL); + return (w + x->x_epiloglength + EPILOGCALL); if (count) { - x->x_count = count; - return (w - (x->x_blocklength - - (PROLOGCALL + EPILOGCALL))); /* go to ugen after prolog */ + x->x_count = count; + return (w - (x->x_blocklength - + (PROLOGCALL + EPILOGCALL))); /* go to ugen after prolog */ } else return (w + EPILOGCALL); } @@ -272,11 +272,11 @@ void dsp_add(t_perfroutine f, int n, ...) va_list ap; dsp_chain = t_resizebytes(dsp_chain, dsp_chainsize * sizeof (t_int), - newsize * sizeof (t_int)); + newsize * sizeof (t_int)); dsp_chain[dsp_chainsize-1] = (t_int)f; va_start(ap, n); for (i = 0; i < n; i++) - dsp_chain[dsp_chainsize + i] = va_arg(ap, t_int); + dsp_chain[dsp_chainsize + i] = va_arg(ap, t_int); va_end(ap); dsp_chain[newsize-1] = 0; dsp_chainsize = newsize; @@ -288,10 +288,10 @@ void dsp_addv(t_perfroutine f, int n, t_int *vec) int newsize = dsp_chainsize + n+1, i; dsp_chain = t_resizebytes(dsp_chain, dsp_chainsize * sizeof (t_int), - newsize * sizeof (t_int)); + newsize * sizeof (t_int)); dsp_chain[dsp_chainsize-1] = (t_int)f; for (i = 0; i < n; i++) - dsp_chain[dsp_chainsize + i] = vec[i]; + dsp_chain[dsp_chainsize + i] = vec[i]; dsp_chain[newsize-1] = 0; dsp_chainsize = newsize; } @@ -300,9 +300,9 @@ void dsp_tick(void) { if (dsp_chain) { - t_int *ip; - for (ip = dsp_chain; *ip; ) ip = (*(t_perfroutine)(*ip))(ip); - dsp_phase++; + t_int *ip; + for (ip = dsp_chain; *ip; ) ip = (*(t_perfroutine)(*ip))(ip); + dsp_phase++; } } @@ -314,8 +314,8 @@ int ilog2(int n) if (n <= 0) return(0); while (n) { - r++; - n >>= 1; + r++; + n >>= 1; } return (r); } @@ -334,13 +334,13 @@ void signal_cleanup(void) int i; while (sig = signal_usedlist) { - signal_usedlist = sig->s_nextused; - if (!sig->s_isborrowed) - t_freebytes(sig->s_vec, sig->s_n * sizeof (*sig->s_vec)); - t_freebytes(sig, sizeof *sig); + signal_usedlist = sig->s_nextused; + if (!sig->s_isborrowed) + t_freebytes(sig->s_vec, sig->s_n * sizeof (*sig->s_vec)); + t_freebytes(sig, sizeof *sig); } for (i = 0; i <= MAXLOGSIG; i++) - signal_freelist[i] = 0; + signal_freelist[i] = 0; signal_freeborrowed = 0; } @@ -352,42 +352,42 @@ void signal_makereusable(t_signal *sig) t_signal *s5; for (s5 = signal_freeborrowed; s5; s5 = s5->s_nextfree) { - if (s5 == sig) - { - bug("signal_free 3"); - return; - } + if (s5 == sig) + { + bug("signal_free 3"); + return; + } } for (s5 = signal_freelist[logn]; s5; s5 = s5->s_nextfree) { - if (s5 == sig) - { - bug("signal_free 4"); - return; - } + if (s5 == sig) + { + bug("signal_free 4"); + return; + } } #endif - if (ugen_loud) post("free %x: %d", sig, sig->s_isborrowed); + if (ugen_loud) post("free %lx: %d", sig, sig->s_isborrowed); if (sig->s_isborrowed) { - /* if the signal is borrowed, decrement the borrowed-from signal's - reference count, possibly marking it reusable too */ - t_signal *s2 = sig->s_borrowedfrom; - if ((s2 == sig) || !s2) - bug("signal_free"); - s2->s_refcount--; - if (!s2->s_refcount) - signal_makereusable(s2); - sig->s_nextfree = signal_freeborrowed; - signal_freeborrowed = sig; + /* if the signal is borrowed, decrement the borrowed-from signal's + reference count, possibly marking it reusable too */ + t_signal *s2 = sig->s_borrowedfrom; + if ((s2 == sig) || !s2) + bug("signal_free"); + s2->s_refcount--; + if (!s2->s_refcount) + signal_makereusable(s2); + sig->s_nextfree = signal_freeborrowed; + signal_freeborrowed = sig; } else { - /* if it's a real signal (not borrowed), put it on the free list - so we can reuse it. */ - if (signal_freelist[logn] == sig) bug("signal_free 2"); - sig->s_nextfree = signal_freelist[logn]; - signal_freelist[logn] = sig; + /* if it's a real signal (not borrowed), put it on the free list + so we can reuse it. */ + if (signal_freelist[logn] == sig) bug("signal_free 2"); + sig->s_nextfree = signal_freelist[logn]; + signal_freelist[logn] = sig; } } @@ -403,40 +403,40 @@ t_signal *signal_new(int n, float sr) logn = ilog2(n); if (n) { - if (n != (1 << logn)) - bug("signal buffer not a power of 2"); - if (logn > MAXLOGSIG) - bug("signal buffer too large"); - whichlist = signal_freelist + logn; + if (n != (1 << logn)) + bug("signal buffer not a power of 2"); + if (logn > MAXLOGSIG) + bug("signal buffer too large"); + whichlist = signal_freelist + logn; } else - whichlist = &signal_freeborrowed; + whichlist = &signal_freeborrowed; - /* first try to reclaim one from the free list */ + /* first try to reclaim one from the free list */ if (ret = *whichlist) - *whichlist = ret->s_nextfree; + *whichlist = ret->s_nextfree; else { - /* LATER figure out what to do for out-of-space here! */ - ret = (t_signal *)t_getbytes(sizeof *ret); - if (n) - { - ret->s_vec = (t_sample *)getbytes(n * sizeof (*ret->s_vec)); - ret->s_isborrowed = 0; - } - else - { - ret->s_vec = 0; - ret->s_isborrowed = 1; - } - ret->s_nextused = signal_usedlist; - signal_usedlist = ret; + /* LATER figure out what to do for out-of-space here! */ + ret = (t_signal *)t_getbytes(sizeof *ret); + if (n) + { + ret->s_vec = (t_sample *)getbytes(n * sizeof (*ret->s_vec)); + ret->s_isborrowed = 0; + } + else + { + ret->s_vec = 0; + ret->s_isborrowed = 1; + } + ret->s_nextused = signal_usedlist; + signal_usedlist = ret; } ret->s_n = n; ret->s_sr = sr; ret->s_refcount = 0; ret->s_borrowedfrom = 0; - if (ugen_loud) post("new %x: %d", ret, ret->s_isborrowed); + if (ugen_loud) post("new %lx: %d", ret, ret->s_isborrowed); return (ret); } @@ -448,9 +448,9 @@ static t_signal *signal_newlike(const t_signal *sig) void signal_setborrowed(t_signal *sig, t_signal *sig2) { if (!sig->s_isborrowed || sig->s_borrowedfrom) - bug("signal_setborrowed"); + bug("signal_setborrowed"); if (sig == sig2) - bug("signal_setborrowed 2"); + bug("signal_setborrowed 2"); sig->s_borrowedfrom = sig2; sig->s_vec = sig2->s_vec; sig->s_n = sig2->s_n; @@ -507,9 +507,9 @@ struct _dspcontext t_signal **dc_iosigs; float dc_srate; int dc_vecsize; - char dc_toplevel; /* true if "iosigs" is invalid. */ - char dc_reblock; /* true if we have to reblock inlets/outlets */ - char dc_switched; /* true if we're switched */ + char dc_toplevel; /* true if "iosigs" is invalid. */ + char dc_reblock; /* true if we have to reblock inlets/outlets */ + char dc_switched; /* true if we're switched */ }; @@ -524,8 +524,8 @@ void ugen_stop(void) int i; if (dsp_chain) { - freebytes(dsp_chain, dsp_chainsize * sizeof (t_int)); - dsp_chain = 0; + freebytes(dsp_chain, dsp_chainsize * sizeof (t_int)); + dsp_chain = 0; } signal_cleanup(); @@ -552,20 +552,20 @@ void glob_foo(void *dummy, t_symbol *s, int argc, t_atom *argv) int i, count; t_signal *sig; for (count = 0, sig = signal_usedlist; sig; - count++, sig = sig->s_nextused) - ; + count++, sig = sig->s_nextused) + ; post("used signals %d", count); for (i = 0; i < MAXLOGSIG; i++) { - for (count = 0, sig = signal_freelist[i]; sig; - count++, sig = sig->s_nextfree) - ; - if (count) - post("size %d: free %d", (1 << i), count); + for (count = 0, sig = signal_freelist[i]; sig; + count++, sig = sig->s_nextfree) + ; + if (count) + post("size %d: free %d", (1 << i), count); } for (count = 0, sig = signal_freeborrowed; sig; - count++, sig = sig->s_nextfree) - ; + count++, sig = sig->s_nextfree) + ; post("free borrowed %d", count); ugen_loud = argc; @@ -606,11 +606,11 @@ void ugen_add(t_dspcontext *dc, t_object *obj) x->u_nin = obj_nsiginlets(obj); x->u_in = getbytes(x->u_nin * sizeof (*x->u_in)); for (uin = x->u_in, i = x->u_nin; i--; uin++) - uin->i_nconnect = 0; + uin->i_nconnect = 0; x->u_nout = obj_nsigoutlets(obj); x->u_out = getbytes(x->u_nout * sizeof (*x->u_out)); for (uout = x->u_out, i = x->u_nout; i--; uout++) - uout->o_connections = 0, uout->o_nconnect = 0; + uout->o_connections = 0, uout->o_nconnect = 0; } /* and then this to make all the connections. */ @@ -624,34 +624,34 @@ void ugen_connect(t_dspcontext *dc, t_object *x1, int outno, t_object *x2, int sigoutno = obj_sigoutletindex(x1, outno); int siginno = obj_siginletindex(x2, inno); if (ugen_loud) - post("%s -> %s: %d->%d", - class_getname(x1->ob_pd), - class_getname(x2->ob_pd), outno, inno); + post("%s -> %s: %d->%d", + class_getname(x1->ob_pd), + class_getname(x2->ob_pd), outno, inno); for (u1 = dc->dc_ugenlist; u1 && u1->u_obj != x1; u1 = u1->u_next); for (u2 = dc->dc_ugenlist; u2 && u2->u_obj != x2; u2 = u2->u_next); if (!u1 || !u2 || siginno < 0) { - pd_error(u1->u_obj, - "signal outlet connect to nonsignal inlet (ignored)"); - return; + pd_error(u1->u_obj, + "signal outlet connect to nonsignal inlet (ignored)"); + return; } if (sigoutno < 0 || sigoutno >= u1->u_nout || siginno >= u2->u_nin) { - bug("ugen_connect %s %s %d %d (%d %d)", - class_getname(x1->ob_pd), - class_getname(x2->ob_pd), sigoutno, siginno, u1->u_nout, - u2->u_nin); + bug("ugen_connect %s %s %d %d (%d %d)", + class_getname(x1->ob_pd), + class_getname(x2->ob_pd), sigoutno, siginno, u1->u_nout, + u2->u_nin); } uout = u1->u_out + sigoutno; uin = u2->u_in + siginno; - /* add a new connection to the outlet's list */ + /* add a new connection to the outlet's list */ oc = (t_sigoutconnect *)getbytes(sizeof *oc); oc->oc_next = uout->o_connections; uout->o_connections = oc; oc->oc_who = u2; oc->oc_inno = siginno; - /* update inlet and outlet counts */ + /* update inlet and outlet counts */ uout->o_nconnect++; uin->i_nconnect++; } @@ -662,7 +662,7 @@ static int ugen_index(t_dspcontext *dc, t_ugenbox *x) int ret; t_ugenbox *u; for (u = dc->dc_ugenlist, ret = 0; u; u = u->u_next, ret++) - if (u == x) return (ret); + if (u == x) return (ret); return (-1); } @@ -675,144 +675,144 @@ static void ugen_doit(t_dspcontext *dc, t_ugenbox *u) t_sigoutconnect *oc, *oc2; t_class *class = pd_class(&u->u_obj->ob_pd); int i, n; - /* suppress creating new signals for the outputs of signal - inlets and subpatchs; except in the case we're an inlet and "blocking" - is set. We don't yet know if a subcanvas will be "blocking" so there - we delay new signal creation, which will be handled by calling - signal_setborrowed in the ugen_done_graph routine below. */ + /* suppress creating new signals for the outputs of signal + inlets and subpatchs; except in the case we're an inlet and "blocking" + is set. We don't yet know if a subcanvas will be "blocking" so there + we delay new signal creation, which will be handled by calling + signal_setborrowed in the ugen_done_graph routine below. */ int nonewsigs = (class == canvas_class || - (class == vinlet_class) && !(dc->dc_reblock)); - /* when we encounter a subcanvas or a signal outlet, suppress freeing - the input signals as they may be "borrowed" for the super or sub - patch; same exception as above, but also if we're "switched" we - have to do a copy rather than a borrow. */ + (class == vinlet_class) && !(dc->dc_reblock)); + /* when we encounter a subcanvas or a signal outlet, suppress freeing + the input signals as they may be "borrowed" for the super or sub + patch; same exception as above, but also if we're "switched" we + have to do a copy rather than a borrow. */ int nofreesigs = (class == canvas_class || - (class == voutlet_class) && !(dc->dc_reblock || dc->dc_switched)); + (class == voutlet_class) && !(dc->dc_reblock || dc->dc_switched)); t_signal **insig, **outsig, **sig, *s1, *s2, *s3; t_ugenbox *u2; if (ugen_loud) post("doit %s %d %d", class_getname(class), nofreesigs, - nonewsigs); + nonewsigs); for (i = 0, uin = u->u_in; i < u->u_nin; i++, uin++) { - if (!uin->i_nconnect) - { - t_sample *scalar; - s3 = signal_new(dc->dc_vecsize, dc->dc_srate); - /* post("%s: unconnected signal inlet set to zero", - class_getname(u->u_obj->ob_pd)); */ - if (scalar = obj_findsignalscalar(u->u_obj, i)) - dsp_add_scalarcopy(scalar, s3->s_vec, s3->s_n); - else - dsp_add_zero(s3->s_vec, s3->s_n); - uin->i_signal = s3; - s3->s_refcount = 1; - } + if (!uin->i_nconnect) + { + t_sample *scalar; + s3 = signal_new(dc->dc_vecsize, dc->dc_srate); + /* post("%s: unconnected signal inlet set to zero", + class_getname(u->u_obj->ob_pd)); */ + if (scalar = obj_findsignalscalar(u->u_obj, i)) + dsp_add_scalarcopy(scalar, s3->s_vec, s3->s_n); + else + dsp_add_zero(s3->s_vec, s3->s_n); + uin->i_signal = s3; + s3->s_refcount = 1; + } } insig = (t_signal **)getbytes((u->u_nin + u->u_nout) * sizeof(t_signal *)); outsig = insig + u->u_nin; for (sig = insig, uin = u->u_in, i = u->u_nin; i--; sig++, uin++) { - int newrefcount; - *sig = uin->i_signal; - newrefcount = --(*sig)->s_refcount; - /* if the reference count went to zero, we free the signal now, - unless it's a subcanvas or outlet; these might keep the - signal around to send to objects connected to them. In this - case we increment the reference count; the corresponding decrement - is in sig_makereusable(). */ - if (nofreesigs) - (*sig)->s_refcount++; - else if (!newrefcount) - signal_makereusable(*sig); + int newrefcount; + *sig = uin->i_signal; + newrefcount = --(*sig)->s_refcount; + /* if the reference count went to zero, we free the signal now, + unless it's a subcanvas or outlet; these might keep the + signal around to send to objects connected to them. In this + case we increment the reference count; the corresponding decrement + is in sig_makereusable(). */ + if (nofreesigs) + (*sig)->s_refcount++; + else if (!newrefcount) + signal_makereusable(*sig); } for (sig = outsig, uout = u->u_out, i = u->u_nout; i--; sig++, uout++) { - /* similarly, for outlets of subcanvases we delay creating - them; instead we create "borrowed" ones so that the refcount - is known. The subcanvas replaces the fake signal with one showing - where the output data actually is, to avoid having to copy it. - For any other object, we just allocate a new output vector; - since we've already freed the inputs the objects might get called - "in place." */ - if (nonewsigs) - { - *sig = uout->o_signal = - signal_new(0, dc->dc_srate); - } - else - *sig = uout->o_signal = signal_new(dc->dc_vecsize, dc->dc_srate); - (*sig)->s_refcount = uout->o_nconnect; + /* similarly, for outlets of subcanvases we delay creating + them; instead we create "borrowed" ones so that the refcount + is known. The subcanvas replaces the fake signal with one showing + where the output data actually is, to avoid having to copy it. + For any other object, we just allocate a new output vector; + since we've already freed the inputs the objects might get called + "in place." */ + if (nonewsigs) + { + *sig = uout->o_signal = + signal_new(0, dc->dc_srate); + } + else + *sig = uout->o_signal = signal_new(dc->dc_vecsize, dc->dc_srate); + (*sig)->s_refcount = uout->o_nconnect; } - /* now call the DSP scheduling routine for the ugen. This - routine must fill in "borrowed" signal outputs in case it's either - a subcanvas or a signal inlet. */ + /* now call the DSP scheduling routine for the ugen. This + routine must fill in "borrowed" signal outputs in case it's either + a subcanvas or a signal inlet. */ mess1(&u->u_obj->ob_pd, gensym("dsp"), insig); - /* if any output signals aren't connected to anyone, free them - now; otherwise they'll either get freed when the reference count - goes back to zero, or even later as explained above. */ + /* if any output signals aren't connected to anyone, free them + now; otherwise they'll either get freed when the reference count + goes back to zero, or even later as explained above. */ for (sig = outsig, uout = u->u_out, i = u->u_nout; i--; sig++, uout++) { - if (!(*sig)->s_refcount) - signal_makereusable(*sig); + if (!(*sig)->s_refcount) + signal_makereusable(*sig); } if (ugen_loud) { - if (u->u_nin + u->u_nout == 0) post("put %s %d", - class_getname(u->u_obj->ob_pd), ugen_index(dc, u)); - else if (u->u_nin + u->u_nout == 1) post("put %s %d (%x)", - class_getname(u->u_obj->ob_pd), ugen_index(dc, u), sig[0]); - else if (u->u_nin + u->u_nout == 2) post("put %s %d (%x %x)", - class_getname(u->u_obj->ob_pd), ugen_index(dc, u), - sig[0], sig[1]); - else post("put %s %d (%x %x %x ...)", - class_getname(u->u_obj->ob_pd), ugen_index(dc, u), - sig[0], sig[1], sig[2]); + if (u->u_nin + u->u_nout == 0) post("put %s %d", + class_getname(u->u_obj->ob_pd), ugen_index(dc, u)); + else if (u->u_nin + u->u_nout == 1) post("put %s %d (%lx)", + class_getname(u->u_obj->ob_pd), ugen_index(dc, u), sig[0]); + else if (u->u_nin + u->u_nout == 2) post("put %s %d (%lx %lx)", + class_getname(u->u_obj->ob_pd), ugen_index(dc, u), + sig[0], sig[1]); + else post("put %s %d (%lx %lx %lx ...)", + class_getname(u->u_obj->ob_pd), ugen_index(dc, u), + sig[0], sig[1], sig[2]); } - /* pass it on and trip anyone whose last inlet was filled */ + /* pass it on and trip anyone whose last inlet was filled */ for (uout = u->u_out, i = u->u_nout; i--; uout++) { - s1 = uout->o_signal; - for (oc = uout->o_connections; oc; oc = oc->oc_next) - { - u2 = oc->oc_who; - uin = &u2->u_in[oc->oc_inno]; - /* if there's already someone here, sum the two */ - if (s2 = uin->i_signal) - { - s1->s_refcount--; - s2->s_refcount--; - if (!signal_compatible(s1, s2)) - { - pd_error(u->u_obj, "%s: incompatible signal inputs", - class_getname(u->u_obj->ob_pd)); - return; - } - s3 = signal_newlike(s1); - dsp_add_plus(s1->s_vec, s2->s_vec, s3->s_vec, s1->s_n); - uin->i_signal = s3; - s3->s_refcount = 1; - if (!s1->s_refcount) signal_makereusable(s1); - if (!s2->s_refcount) signal_makereusable(s2); - } - else uin->i_signal = s1; - uin->i_ngot++; - /* if we didn't fill this inlet don't bother yet */ - if (uin->i_ngot < uin->i_nconnect) - goto notyet; - /* if there's more than one, check them all */ - if (u2->u_nin > 1) - { - for (uin = u2->u_in, n = u2->u_nin; n--; uin++) - if (uin->i_ngot < uin->i_nconnect) goto notyet; - } - /* so now we can schedule the ugen. */ - ugen_doit(dc, u2); - notyet: ; - } + s1 = uout->o_signal; + for (oc = uout->o_connections; oc; oc = oc->oc_next) + { + u2 = oc->oc_who; + uin = &u2->u_in[oc->oc_inno]; + /* if there's already someone here, sum the two */ + if (s2 = uin->i_signal) + { + s1->s_refcount--; + s2->s_refcount--; + if (!signal_compatible(s1, s2)) + { + pd_error(u->u_obj, "%s: incompatible signal inputs", + class_getname(u->u_obj->ob_pd)); + return; + } + s3 = signal_newlike(s1); + dsp_add_plus(s1->s_vec, s2->s_vec, s3->s_vec, s1->s_n); + uin->i_signal = s3; + s3->s_refcount = 1; + if (!s1->s_refcount) signal_makereusable(s1); + if (!s2->s_refcount) signal_makereusable(s2); + } + else uin->i_signal = s1; + uin->i_ngot++; + /* if we didn't fill this inlet don't bother yet */ + if (uin->i_ngot < uin->i_nconnect) + goto notyet; + /* if there's more than one, check them all */ + if (u2->u_nin > 1) + { + for (uin = u2->u_in, n = u2->u_nin; n--; uin++) + if (uin->i_ngot < uin->i_nconnect) goto notyet; + } + /* so now we can schedule the ugen. */ + ugen_doit(dc, u2); + notyet: ; + } } t_freebytes(insig,(u->u_nin + u->u_nout) * sizeof(t_signal *)); u->u_done = 1; @@ -837,265 +837,265 @@ void ugen_done_graph(t_dspcontext *dc) int period, frequency, phase, vecsize; float srate; int chainblockbegin; /* DSP chain onset before block prolog code */ - int chainblockend; /* and after block epilog code */ - int chainafterall; /* and after signal outlet epilog */ + int chainblockend; /* and after block epilog code */ + int chainafterall; /* and after signal outlet epilog */ int reblock = 0, switched; int downsample = 1, upsample = 1; /* IOhannes */ /* debugging printout */ if (ugen_loud) { - post("ugen_done_graph..."); - for (u = dc->dc_ugenlist; u; u = u->u_next) - { - post("ugen: %s", class_getname(u->u_obj->ob_pd)); - for (uout = u->u_out, i = 0; i < u->u_nout; uout++, i++) - for (oc = uout->o_connections; oc; oc = oc->oc_next) - { - post("... out %d to %s, index %d, inlet %d", i, - class_getname(oc->oc_who->u_obj->ob_pd), - ugen_index(dc, oc->oc_who), oc->oc_inno); - } - } + post("ugen_done_graph..."); + for (u = dc->dc_ugenlist; u; u = u->u_next) + { + post("ugen: %s", class_getname(u->u_obj->ob_pd)); + for (uout = u->u_out, i = 0; i < u->u_nout; uout++, i++) + for (oc = uout->o_connections; oc; oc = oc->oc_next) + { + post("... out %d to %s, index %d, inlet %d", i, + class_getname(oc->oc_who->u_obj->ob_pd), + ugen_index(dc, oc->oc_who), oc->oc_inno); + } + } } - /* search for an object of class "block~" */ + /* search for an object of class "block~" */ for (u = dc->dc_ugenlist, blk = 0; u; u = u->u_next) { - t_pd *zz = &u->u_obj->ob_pd; - if (pd_class(zz) == block_class) - { - if (blk) - pd_error(blk, "conflicting block~ objects in same page"); - else blk = (t_block *)zz; - } + t_pd *zz = &u->u_obj->ob_pd; + if (pd_class(zz) == block_class) + { + if (blk) + pd_error(blk, "conflicting block~ objects in same page"); + else blk = (t_block *)zz; + } } - /* figure out block size, calling frequency, sample rate */ + /* figure out block size, calling frequency, sample rate */ if (parent_context) { - parent_srate = parent_context->dc_srate; - parent_vecsize = parent_context->dc_vecsize; + parent_srate = parent_context->dc_srate; + parent_vecsize = parent_context->dc_vecsize; } else { - parent_srate = sys_getsr(); - parent_vecsize = sys_getblksize(); + parent_srate = sys_getsr(); + parent_vecsize = sys_getblksize(); } if (blk) { - int realoverlap; - vecsize = blk->x_vecsize; - if (vecsize == 0) - vecsize = parent_vecsize; - realoverlap = blk->x_overlap; - if (realoverlap > vecsize) realoverlap = vecsize; - /* IOhannes { */ - downsample = blk->x_downsample; - upsample = blk->x_upsample; - if (downsample > parent_vecsize) downsample=parent_vecsize; - period = (vecsize * downsample)/ - (parent_vecsize * realoverlap * upsample); - frequency = (parent_vecsize * realoverlap * upsample)/ - (vecsize * downsample); - /* } IOhannes*/ - phase = blk->x_phase; - srate = parent_srate * realoverlap * upsample / downsample; - /* IOhannes */ - if (period < 1) period = 1; - if (frequency < 1) frequency = 1; - blk->x_frequency = frequency; - blk->x_period = period; - blk->x_phase = dsp_phase & (period - 1); - if (! parent_context || (realoverlap != 1) || - (vecsize != parent_vecsize) || - (downsample != 1) || (upsample != 1)) /* IOhannes */ - reblock = 1; - switched = blk->x_switched; + int realoverlap; + vecsize = blk->x_vecsize; + if (vecsize == 0) + vecsize = parent_vecsize; + realoverlap = blk->x_overlap; + if (realoverlap > vecsize) realoverlap = vecsize; + /* IOhannes { */ + downsample = blk->x_downsample; + upsample = blk->x_upsample; + if (downsample > parent_vecsize) downsample=parent_vecsize; + period = (vecsize * downsample)/ + (parent_vecsize * realoverlap * upsample); + frequency = (parent_vecsize * realoverlap * upsample)/ + (vecsize * downsample); + /* } IOhannes*/ + phase = blk->x_phase; + srate = parent_srate * realoverlap * upsample / downsample; + /* IOhannes */ + if (period < 1) period = 1; + if (frequency < 1) frequency = 1; + blk->x_frequency = frequency; + blk->x_period = period; + blk->x_phase = dsp_phase & (period - 1); + if (! parent_context || (realoverlap != 1) || + (vecsize != parent_vecsize) || + (downsample != 1) || (upsample != 1)) /* IOhannes */ + reblock = 1; + switched = blk->x_switched; } else { - srate = parent_srate; - vecsize = parent_vecsize; - downsample = upsample = 1;/* IOhannes */ - period = frequency = 1; - phase = 0; - if (!parent_context) reblock = 1; - switched = 0; + srate = parent_srate; + vecsize = parent_vecsize; + downsample = upsample = 1;/* IOhannes */ + period = frequency = 1; + phase = 0; + if (!parent_context) reblock = 1; + switched = 0; } dc->dc_reblock = reblock; dc->dc_switched = switched; dc->dc_srate = srate; dc->dc_vecsize = vecsize; - /* if we're reblocking or switched, we now have to create output - signals to fill in for the "borrowed" ones we have now. This - is also possibly true even if we're not blocked/switched, in - the case that there was a signal loop. But we don't know this - yet. */ + /* if we're reblocking or switched, we now have to create output + signals to fill in for the "borrowed" ones we have now. This + is also possibly true even if we're not blocked/switched, in + the case that there was a signal loop. But we don't know this + yet. */ if (dc->dc_iosigs && (switched || reblock)) { - t_signal **sigp; - for (i = 0, sigp = dc->dc_iosigs + dc->dc_ninlets; i < dc->dc_noutlets; - i++, sigp++) - { - if ((*sigp)->s_isborrowed && !(*sigp)->s_borrowedfrom) - { - signal_setborrowed(*sigp, - signal_new(parent_vecsize, parent_srate)); - (*sigp)->s_refcount++; - - if (ugen_loud) post("set %x->%x", *sigp, - (*sigp)->s_borrowedfrom); - } - } + t_signal **sigp; + for (i = 0, sigp = dc->dc_iosigs + dc->dc_ninlets; i < dc->dc_noutlets; + i++, sigp++) + { + if ((*sigp)->s_isborrowed && !(*sigp)->s_borrowedfrom) + { + signal_setborrowed(*sigp, + signal_new(parent_vecsize, parent_srate)); + (*sigp)->s_refcount++; + + if (ugen_loud) post("set %lx->%lx", *sigp, + (*sigp)->s_borrowedfrom); + } + } } if (ugen_loud) - post("reblock %d, switched %d", reblock, switched); - - /* schedule prologs for inlets and outlets. If the "reblock" flag - is set, an inlet will put code on the DSP chain to copy its input - into an internal buffer here, before any unit generators' DSP code - gets scheduled. If we don't "reblock", inlets will need to get - pointers to their corresponding inlets/outlets on the box we're inside, - if any. Outlets will also need pointers, unless we're switched, in - which case outlet epilog code will kick in. */ - + post("reblock %d, switched %d", reblock, switched); + + /* schedule prologs for inlets and outlets. If the "reblock" flag + is set, an inlet will put code on the DSP chain to copy its input + into an internal buffer here, before any unit generators' DSP code + gets scheduled. If we don't "reblock", inlets will need to get + pointers to their corresponding inlets/outlets on the box we're inside, + if any. Outlets will also need pointers, unless we're switched, in + which case outlet epilog code will kick in. */ + for (u = dc->dc_ugenlist; u; u = u->u_next) { - t_pd *zz = &u->u_obj->ob_pd; - t_signal **insigs = dc->dc_iosigs, **outsigs = dc->dc_iosigs; - if (outsigs) outsigs += dc->dc_ninlets; - - if (pd_class(zz) == vinlet_class) - vinlet_dspprolog((struct _vinlet *)zz, - dc->dc_iosigs, vecsize, dsp_phase, period, frequency, - downsample, upsample, /* IOhannes */ - reblock, switched); - else if (pd_class(zz) == voutlet_class) - voutlet_dspprolog((struct _voutlet *)zz, - outsigs, vecsize, dsp_phase, period, frequency, - downsample, upsample, /* IOhannes */ - reblock, switched); + t_pd *zz = &u->u_obj->ob_pd; + t_signal **insigs = dc->dc_iosigs, **outsigs = dc->dc_iosigs; + if (outsigs) outsigs += dc->dc_ninlets; + + if (pd_class(zz) == vinlet_class) + vinlet_dspprolog((struct _vinlet *)zz, + dc->dc_iosigs, vecsize, dsp_phase, period, frequency, + downsample, upsample, /* IOhannes */ + reblock, switched); + else if (pd_class(zz) == voutlet_class) + voutlet_dspprolog((struct _voutlet *)zz, + outsigs, vecsize, dsp_phase, period, frequency, + downsample, upsample, /* IOhannes */ + reblock, switched); } chainblockbegin = dsp_chainsize; - if (blk && (reblock || switched)) /* add the block DSP prolog */ - dsp_add(block_prolog, 1, blk); + if (blk && (reblock || switched)) /* add the block DSP prolog */ + dsp_add(block_prolog, 1, blk); - /* Initialize for sorting */ + /* Initialize for sorting */ for (u = dc->dc_ugenlist; u; u = u->u_next) { - u->u_done = 0; - for (uout = u->u_out, i = u->u_nout; i--; uout++) - uout->o_nsent = 0; - for (uin = u->u_in, i = u->u_nin; i--; uin++) - uin->i_ngot = 0, uin->i_signal = 0; + u->u_done = 0; + for (uout = u->u_out, i = u->u_nout; i--; uout++) + uout->o_nsent = 0; + for (uin = u->u_in, i = u->u_nin; i--; uin++) + uin->i_ngot = 0, uin->i_signal = 0; } - /* Do the sort */ + /* Do the sort */ for (u = dc->dc_ugenlist; u; u = u->u_next) { - /* check that we have no connected signal inlets */ - if (u->u_done) continue; - for (uin = u->u_in, i = u->u_nin; i--; uin++) - if (uin->i_nconnect) goto next; + /* check that we have no connected signal inlets */ + if (u->u_done) continue; + for (uin = u->u_in, i = u->u_nin; i--; uin++) + if (uin->i_nconnect) goto next; - ugen_doit(dc, u); + ugen_doit(dc, u); next: ; } - /* check for a DSP loop, which is evidenced here by the presence - of ugens not yet scheduled. */ - + /* check for a DSP loop, which is evidenced here by the presence + of ugens not yet scheduled. */ + for (u = dc->dc_ugenlist; u; u = u->u_next) - if (!u->u_done) + if (!u->u_done) { - t_signal **sigp; - pd_error(u->u_obj, - "DSP loop detected (some tilde objects not scheduled)"); - /* this might imply that we have unfilled "borrowed" outputs - which we'd better fill in now. */ - for (i = 0, sigp = dc->dc_iosigs + dc->dc_ninlets; i < dc->dc_noutlets; - i++, sigp++) - { - if ((*sigp)->s_isborrowed && !(*sigp)->s_borrowedfrom) - { - t_signal *s3 = signal_new(parent_vecsize, parent_srate); - signal_setborrowed(*sigp, s3); - (*sigp)->s_refcount++; - dsp_add_zero(s3->s_vec, s3->s_n); - if (ugen_loud) - post("oops, belatedly set %x->%x", *sigp, - (*sigp)->s_borrowedfrom); - } - } - break; /* don't need to keep looking. */ + t_signal **sigp; + pd_error(u->u_obj, + "DSP loop detected (some tilde objects not scheduled)"); + /* this might imply that we have unfilled "borrowed" outputs + which we'd better fill in now. */ + for (i = 0, sigp = dc->dc_iosigs + dc->dc_ninlets; i < dc->dc_noutlets; + i++, sigp++) + { + if ((*sigp)->s_isborrowed && !(*sigp)->s_borrowedfrom) + { + t_signal *s3 = signal_new(parent_vecsize, parent_srate); + signal_setborrowed(*sigp, s3); + (*sigp)->s_refcount++; + dsp_add_zero(s3->s_vec, s3->s_n); + if (ugen_loud) + post("oops, belatedly set %lx->%lx", *sigp, + (*sigp)->s_borrowedfrom); + } + } + break; /* don't need to keep looking. */ } if (blk && (reblock || switched)) /* add block DSP epilog */ - dsp_add(block_epilog, 1, blk); + dsp_add(block_epilog, 1, blk); chainblockend = dsp_chainsize; - /* add epilogs for outlets. */ + /* add epilogs for outlets. */ for (u = dc->dc_ugenlist; u; u = u->u_next) { - t_pd *zz = &u->u_obj->ob_pd; - if (pd_class(zz) == voutlet_class) - { - t_signal **iosigs = dc->dc_iosigs; - if (iosigs) iosigs += dc->dc_ninlets; - voutlet_dspepilog((struct _voutlet *)zz, - iosigs, vecsize, dsp_phase, period, frequency, - downsample, upsample, /* IOhannes */ - reblock, switched); - } + t_pd *zz = &u->u_obj->ob_pd; + if (pd_class(zz) == voutlet_class) + { + t_signal **iosigs = dc->dc_iosigs; + if (iosigs) iosigs += dc->dc_ninlets; + voutlet_dspepilog((struct _voutlet *)zz, + iosigs, vecsize, dsp_phase, period, frequency, + downsample, upsample, /* IOhannes */ + reblock, switched); + } } chainafterall = dsp_chainsize; if (blk) { - blk->x_blocklength = chainblockend - chainblockbegin; - blk->x_epiloglength = chainafterall - chainblockend; - blk->x_reblock = reblock; + blk->x_blocklength = chainblockend - chainblockbegin; + blk->x_epiloglength = chainafterall - chainblockend; + blk->x_reblock = reblock; } if (ugen_loud) { - t_int *ip; - if (!dc->dc_parentcontext) - for (i = dsp_chainsize, ip = dsp_chain; i--; ip++) - post("chain %x", *ip); - post("... ugen_done_graph done."); + t_int *ip; + if (!dc->dc_parentcontext) + for (i = dsp_chainsize, ip = dsp_chain; i--; ip++) + post("chain %lx", *ip); + post("... ugen_done_graph done."); } - /* now delete everything. */ + /* now delete everything. */ while (dc->dc_ugenlist) { - for (uout = dc->dc_ugenlist->u_out, n = dc->dc_ugenlist->u_nout; - n--; uout++) - { - oc = uout->o_connections; - while (oc) - { - oc2 = oc->oc_next; - freebytes(oc, sizeof *oc); - oc = oc2; - } - } + for (uout = dc->dc_ugenlist->u_out, n = dc->dc_ugenlist->u_nout; + n--; uout++) + { + oc = uout->o_connections; + while (oc) + { + oc2 = oc->oc_next; + freebytes(oc, sizeof *oc); + oc = oc2; + } + } freebytes(dc->dc_ugenlist->u_out, dc->dc_ugenlist->u_nout * sizeof (*dc->dc_ugenlist->u_out)); freebytes(dc->dc_ugenlist->u_in, dc->dc_ugenlist->u_nin * sizeof(*dc->dc_ugenlist->u_in)); - u = dc->dc_ugenlist; - dc->dc_ugenlist = u->u_next; - freebytes(u, sizeof *u); + u = dc->dc_ugenlist; + dc->dc_ugenlist = u->u_next; + freebytes(u, sizeof *u); } if (ugen_currentcontext == dc) - ugen_currentcontext = dc->dc_parentcontext; + ugen_currentcontext = dc->dc_parentcontext; else bug("ugen_currentcontext"); freebytes(dc, sizeof(*dc)); @@ -1115,11 +1115,11 @@ t_signal *ugen_getiosig(int index, int inout) void d_ugen_setup(void) /* really just block_setup */ { block_class = class_new(gensym("block~"), (t_newmethod)block_new, 0, - sizeof(t_block), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT/*IOhannes*/, 0); + sizeof(t_block), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT/*IOhannes*/, 0); class_addcreator((t_newmethod)switch_new, gensym("switch~"), - A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT/*IOhannes*/, 0); + A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT/*IOhannes*/, 0); class_addmethod(block_class, (t_method)block_set, gensym("set"), - A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0); + A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0); class_addmethod(block_class, (t_method)block_dsp, gensym("dsp"), 0); class_addfloat(block_class, block_float); } -- cgit v1.2.1