[PD-cvs] pd/src d_ugen.c,1.3.4.1.2.5.2.12,1.3.4.1.2.5.2.13

Mathieu Bouchard matju at users.sourceforge.net
Tue Jul 10 09:02:03 CEST 2007


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4955

Modified Files:
      Tag: desiredata
	d_ugen.c 
Log Message:
use PD_PLUSPLUS_FACE


Index: d_ugen.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/d_ugen.c,v
retrieving revision 1.3.4.1.2.5.2.12
retrieving revision 1.3.4.1.2.5.2.13
diff -C2 -d -r1.3.4.1.2.5.2.12 -r1.3.4.1.2.5.2.13
*** d_ugen.c	10 Jul 2007 05:49:58 -0000	1.3.4.1.2.5.2.12
--- d_ugen.c	10 Jul 2007 07:02:00 -0000	1.3.4.1.2.5.2.13
***************
*** 22,25 ****
--- 22,26 ----
   */
  
+ #define PD_PLUSPLUS_FACE
  #include "desire.h"
  #include <stdlib.h>
***************
*** 48,53 ****
  /* zero out a vector */
  t_int *zero_perform(t_int *w) {
!     t_float *out = (t_float *)(w[1]);
!     int n = (int)(w[2]);
      while (n--) *out++ = 0; 
      return w+3;
--- 49,54 ----
  /* zero out a vector */
  t_int *zero_perform(t_int *w) {
!     t_float *out = (t_float *)w[1];
!     int n = int(w[2]);
      while (n--) *out++ = 0; 
      return w+3;
***************
*** 55,60 ****
  
  t_int *zero_perf8(t_int *w) {
!     t_float *out = (t_float *)(w[1]);
!     int n = (int)(w[2]);
      for (; n; n -= 8, out += 8) {
          out[0] = 0;
--- 56,61 ----
  
  t_int *zero_perf8(t_int *w) {
!     t_float *out = (t_float *)w[1];
!     int n = int(w[2]);
      for (; n; n -= 8, out += 8) {
          out[0] = 0;
***************
*** 311,320 ****
      t_signal *sig;
      while ((sig = signal_usedlist)) {
!         signal_usedlist = sig->s_nextused;
! 	    if (!sig->s_isborrowed) {
  #ifndef VECTORALIGNMENT
!                 free(sig->s_vec);
  #else
!                 freealignedbytes(sig->s_vec, sig->s_vecsize * sizeof (*sig->s_vec));
  #endif
  	    }
--- 312,321 ----
      t_signal *sig;
      while ((sig = signal_usedlist)) {
!         signal_usedlist = sig->nextused;
! 	    if (!sig->isborrowed) {
  #ifndef VECTORALIGNMENT
!                 free(sig->v);
  #else
!                 freealignedbytes(sig->v, sig->vecsize * sizeof (*sig->v));
  #endif
  	    }
***************
*** 327,334 ****
  /* mark the signal "reusable." */
  extern "C" void signal_makereusable(t_signal *sig) {
!     int logn = ilog2(sig->s_vecsize);
  #if 1
      t_signal *s5;
!     for (s5 = signal_freeborrowed; s5; s5 = s5->s_nextfree) {
          if (s5 == sig) {
              bug("signal_free 3");
--- 328,335 ----
  /* mark the signal "reusable." */
  extern "C" void signal_makereusable(t_signal *sig) {
!     int logn = ilog2(sig->vecsize);
  #if 1
      t_signal *s5;
!     for (s5 = signal_freeborrowed; s5; s5 = s5->nextfree) {
          if (s5 == sig) {
              bug("signal_free 3");
***************
*** 336,340 ****
          }
      }
!     for (s5 = signal_freelist[logn]; s5; s5 = s5->s_nextfree) {
          if (s5 == sig) {
              bug("signal_free 4");
--- 337,341 ----
          }
      }
!     for (s5 = signal_freelist[logn]; s5; s5 = s5->nextfree) {
          if (s5 == sig) {
              bug("signal_free 4");
***************
*** 343,359 ****
      }
  #endif
!     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;
      } 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;
      }
--- 344,360 ----
      }
  #endif
!     if (ugen_loud) post("free %lx: %d", sig, sig->isborrowed);
!     if (sig->isborrowed) {
          /* if the signal is borrowed, decrement the borrowed-from signal's reference count, possibly marking it reusable too */
!         t_signal *s2 = sig->borrowedfrom;
          if ((s2 == sig) || !s2) bug("signal_free");
!         s2->refcount--;
!         if (!s2->refcount) signal_makereusable(s2);
!         sig->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->nextfree = signal_freelist[logn];
          signal_freelist[logn] = sig;
      }
***************
*** 373,377 ****
      /* first try to reclaim one from the free list */
      ret = *whichlist;
!     if (ret) *whichlist = ret->s_nextfree;
      else {
          /* LATER figure out what to do for out-of-space here! */
--- 374,378 ----
      /* first try to reclaim one from the free list */
      ret = *whichlist;
!     if (ret) *whichlist = ret->nextfree;
      else {
          /* LATER figure out what to do for out-of-space here! */
***************
*** 379,416 ****
          if (n) {
  #ifndef VECTORALIGNMENT
!             ret->s_vec = (t_sample *)getbytes(vecsize * sizeof (*ret->s_vec));
  #else
              /* T.Grill - make signal vectors aligned! */
!             ret->s_vec = (t_sample *)getalignedbytes(vecsize * sizeof (*ret->s_vec));
  #endif
!             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_vecsize = vecsize;
!     ret->s_sr = sr;
!     ret->s_refcount = 0;
!     ret->s_borrowedfrom = 0;
!     if (ugen_loud) post("new %lx: %d", ret, ret->s_isborrowed);
      return ret;
  }
  
! static t_signal *signal_newlike(const t_signal *sig) {return signal_new(sig->s_n, sig->s_sr);}
  
  extern "C" void signal_setborrowed(t_signal *sig, t_signal *sig2) {
!     if (!sig->s_isborrowed || sig->s_borrowedfrom) bug("signal_setborrowed");
      if (sig == sig2) bug("signal_setborrowed 2");
!     sig->s_borrowedfrom = sig2;
!     sig->s_vec = sig2->s_vec;
!     sig->s_n = sig2->s_n;
!     sig->s_vecsize = sig2->s_vecsize;
  }
  
! int signal_compatible(t_signal *s1, t_signal *s2) {return s1->s_n == s2->s_n && s1->s_sr == s2->s_sr;}
  
  /* ------------------ ugen ("unit generator") sorting ----------------- */
--- 380,417 ----
          if (n) {
  #ifndef VECTORALIGNMENT
!             ret->v = (t_sample *)getbytes(vecsize * sizeof (*ret->v));
  #else
              /* T.Grill - make signal vectors aligned! */
!             ret->v = (t_sample *)getalignedbytes(vecsize * sizeof (*ret->v));
  #endif
!             ret->isborrowed = 0;
          } else {
!             ret->v = 0;
!             ret->isborrowed = 1;
          }
!         ret->nextused = signal_usedlist;
          signal_usedlist = ret;
      }
!     ret->n = n;
!     ret->vecsize = vecsize;
!     ret->sr = sr;
!     ret->refcount = 0;
!     ret->borrowedfrom = 0;
!     if (ugen_loud) post("new %lx: %d", ret, ret->isborrowed);
      return ret;
  }
  
! static t_signal *signal_newlike(const t_signal *sig) {return signal_new(sig->n, sig->sr);}
  
  extern "C" void signal_setborrowed(t_signal *sig, t_signal *sig2) {
!     if (!sig->isborrowed || sig->borrowedfrom) bug("signal_setborrowed");
      if (sig == sig2) bug("signal_setborrowed 2");
!     sig->borrowedfrom = sig2;
!     sig->v = sig2->v;
!     sig->n = sig2->n;
!     sig->vecsize = sig2->vecsize;
  }
  
! int signal_compatible(t_signal *s1, t_signal *s2) {return s1->n == s2->n && s1->sr == s2->sr;}
  
  /* ------------------ ugen ("unit generator") sorting ----------------- */
***************
*** 484,494 ****
      int i, count;
      t_signal *sig;
!     for (count = 0, sig = signal_usedlist; sig; 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_freeborrowed; sig; count++, sig = sig->s_nextfree) {}
      post("free borrowed %d", count);
      ugen_loud = argc;
--- 485,495 ----
      int i, count;
      t_signal *sig;
!     for (count = 0, sig = signal_usedlist; sig; count++, sig = sig->nextused) {}
      post("used signals %d", count);
      for (i = 0; i < MAXLOGSIG; i++) {
!         for (count = 0, sig = signal_freelist[i]; sig; count++, sig = sig->nextfree) {}
          if (count) post("size %d: free %d", (1 << i), count);
      }
!     for (count = 0, sig = signal_freeborrowed; sig; count++, sig = sig->nextfree) {}
      post("free borrowed %d", count);
      ugen_loud = argc;
***************
*** 568,572 ****
      t_siginlet *uin;
      t_sigoutconnect *oc;
!     t_class *klass = pd_class(&u->obj->ob_pd);
      int i, n;
      /* suppress creating new signals for the outputs of signal
--- 569,573 ----
      t_siginlet *uin;
      t_sigoutconnect *oc;
!     t_class *klass = pd_class(u->obj);
      int i, n;
      /* suppress creating new signals for the outputs of signal
***************
*** 589,596 ****
              s3 = signal_new(dc->vecsize, dc->srate);
              /* post("%s: unconnected signal inlet set to zero", class_getname(u->obj->ob_pd)); */
!             if ((scalar = obj_findsignalscalar(u->obj, i))) dsp_add_scalarcopy(scalar, s3->s_vec, s3->s_n);
!             else dsp_add_zero(s3->s_vec, s3->s_n);
              uin->signal = s3;
!             s3->s_refcount = 1;
          }
      }
--- 590,597 ----
              s3 = signal_new(dc->vecsize, dc->srate);
              /* post("%s: unconnected signal inlet set to zero", class_getname(u->obj->ob_pd)); */
!             if ((scalar = obj_findsignalscalar(u->obj, i))) dsp_add_scalarcopy(scalar, s3->v, s3->n);
!             else dsp_add_zero(s3->v, s3->n);
              uin->signal = s3;
!             s3->refcount = 1;
          }
      }
***************
*** 600,604 ****
          int newrefcount;
          *sig = uin->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
--- 601,605 ----
          int newrefcount;
          *sig = uin->signal;
!         newrefcount = --(*sig)->refcount;
              /* if the reference count went to zero, we free the signal now,
              unless it's a subcanvas or outlet; these might keep the
***************
*** 606,610 ****
              case we increment the reference count; the corresponding decrement
              is in sig_makereusable(). */
!         if (nofreesigs) (*sig)->s_refcount++;
          else if (!newrefcount) signal_makereusable(*sig);
      }
--- 607,611 ----
              case we increment the reference count; the corresponding decrement
              is in sig_makereusable(). */
!         if (nofreesigs) (*sig)->refcount++;
          else if (!newrefcount) signal_makereusable(*sig);
      }
***************
*** 619,633 ****
              signal_new(0, dc->srate) :
              signal_new(dc->vecsize, dc->srate);
!         (*sig)->s_refcount = uout->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. */
!     mess1(&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. */
      for (sig = outsig, uout = u->out, i = u->nout; i--; sig++, uout++) {
!         if (!(*sig)->s_refcount) signal_makereusable(*sig);
      }
      if (ugen_loud) {
--- 620,634 ----
              signal_new(0, dc->srate) :
              signal_new(dc->vecsize, dc->srate);
!         (*sig)->refcount = uout->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. */
!     mess1(u->obj, 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. */
      for (sig = outsig, uout = u->out, i = u->nout; i--; sig++, uout++) {
!         if (!(*sig)->refcount) signal_makereusable(*sig);
      }
      if (ugen_loud) {
***************
*** 646,651 ****
  	    s2 = uin->signal;
              if (s2) {
!                 s1->s_refcount--;
!                 s2->s_refcount--;
                  if (!signal_compatible(s1, s2)) {
                      pd_error(u->obj, "%s: incompatible signal inputs", class_getname(u->obj->ob_pd));
--- 647,652 ----
  	    s2 = uin->signal;
              if (s2) {
!                 s1->refcount--;
!                 s2->refcount--;
                  if (!signal_compatible(s1, s2)) {
                      pd_error(u->obj, "%s: incompatible signal inputs", class_getname(u->obj->ob_pd));
***************
*** 653,661 ****
                  }
                  s3 = signal_newlike(s1);
!                 dsp_add_plus(s1->s_vec, s2->s_vec, s3->s_vec, s1->s_n);
                  uin->signal = s3;
!                 s3->s_refcount = 1;
!                 if (!s1->s_refcount) signal_makereusable(s1);
!                 if (!s2->s_refcount) signal_makereusable(s2);
              } else uin->signal = s1;
              uin->ngot++;
--- 654,662 ----
                  }
                  s3 = signal_newlike(s1);
!                 dsp_add_plus(s1->v, s2->v, s3->v, s1->n);
                  uin->signal = s3;
!                 s3->refcount = 1;
!                 if (!s1->refcount) signal_makereusable(s1);
!                 if (!s2->refcount) signal_makereusable(s2);
              } else uin->signal = s1;
              uin->ngot++;
***************
*** 708,712 ****
      /* search for an object of class "block~" */
      for (u = dc->ugenlist, blk = 0; u; u = u->next) {
!         t_pd *zz = &u->obj->ob_pd;
          if (pd_class(zz) == block_class) {
              if (blk) pd_error(blk, "conflicting block~ objects in same page");
--- 709,713 ----
      /* search for an object of class "block~" */
      for (u = dc->ugenlist, blk = 0; u; u = u->next) {
!         t_pd *zz = u->obj;
          if (pd_class(zz) == block_class) {
              if (blk) pd_error(blk, "conflicting block~ objects in same page");
***************
*** 770,777 ****
          t_signal **sigp;
          for (i = 0, sigp = dc->iosigs + dc->ninlets; i < 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);
              }
          }
--- 771,778 ----
          t_signal **sigp;
          for (i = 0, sigp = dc->iosigs + dc->ninlets; i < dc->noutlets; i++, sigp++) {
!             if ((*sigp)->isborrowed && !(*sigp)->borrowedfrom) {
                  signal_setborrowed(*sigp, signal_new(parent_vecsize, parent_srate));
!                 (*sigp)->refcount++;
!                 if (ugen_loud) post("set %lx->%lx", *sigp, (*sigp)->borrowedfrom);
              }
          }
***************
*** 786,790 ****
         which case outlet epilog code will kick in. */
      for (u = dc->ugenlist; u; u = u->next) {
!         t_pd *zz = &u->obj->ob_pd;
          t_signal **outsigs = dc->iosigs;
          if (outsigs) outsigs += dc->ninlets;
--- 787,791 ----
         which case outlet epilog code will kick in. */
      for (u = dc->ugenlist; u; u = u->next) {
!         t_pd *zz = u->obj;
          t_signal **outsigs = dc->iosigs;
          if (outsigs) outsigs += dc->ninlets;
***************
*** 822,831 ****
          /* this might imply that we have unfilled "borrowed" outputs which we'd better fill in now. */
          for (i = 0, sigp = dc->iosigs + dc->ninlets; i < 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);
              }
          }
--- 823,832 ----
          /* this might imply that we have unfilled "borrowed" outputs which we'd better fill in now. */
          for (i = 0, sigp = dc->iosigs + dc->ninlets; i < dc->noutlets; i++, sigp++) {
!             if ((*sigp)->isborrowed && !(*sigp)->borrowedfrom) {
                  t_signal *s3 = signal_new(parent_vecsize, parent_srate);
                  signal_setborrowed(*sigp, s3);
!                 (*sigp)->refcount++;
!                 dsp_add_zero(s3->v, s3->n);
!                 if (ugen_loud) post("oops, belatedly set %lx->%lx", *sigp, (*sigp)->borrowedfrom);
              }
          }
***************
*** 837,841 ****
      /* add epilogs for outlets. */
      for (u = dc->ugenlist; u; u = u->next) {
!         t_pd *zz = &u->obj->ob_pd;
          if (pd_class(zz) == voutlet_class) {
              t_signal **iosigs = dc->iosigs;
--- 838,842 ----
      /* add epilogs for outlets. */
      for (u = dc->ugenlist; u; u = u->next) {
!         t_pd *zz = u->obj;
          if (pd_class(zz) == voutlet_class) {
              t_signal **iosigs = dc->iosigs;
***************
*** 1004,1016 ****
    x->downsample=x->upsample=1;
    x->s_n = x->coefsize = x->bufsize = 0;
!   x->s_vec = x->coeffs = x->buffer  = 0;
  }
  
  void resample_free(t_resample *x) {
!   if (x->s_n) free(x->s_vec);
    if (x->coefsize) free(x->coeffs);
    if (x->bufsize) free(x->buffer);
    x->s_n = x->coefsize = x->bufsize = 0;
!   x->s_vec = x->coeffs = x->buffer  = 0;
  }
  
--- 1005,1017 ----
    x->downsample=x->upsample=1;
    x->s_n = x->coefsize = x->bufsize = 0;
!   x->v = x->coeffs = x->buffer  = 0;
  }
  
  void resample_free(t_resample *x) {
!   if (x->s_n) free(x->v);
    if (x->coefsize) free(x->coeffs);
    if (x->bufsize) free(x->buffer);
    x->s_n = x->coefsize = x->bufsize = 0;
!   x->v = x->coeffs = x->buffer  = 0;
  }
  
***************
*** 1053,1069 ****
  void resamplefrom_dsp(t_resample *x, t_sample *in, int insize, int outsize, int method) {
    if (insize==outsize) {
!     free(x->s_vec);
      x->s_n = 0;
!     x->s_vec = in;
      return;
    }
    if (x->s_n != outsize) {
!     t_float *buf=x->s_vec;
      free(buf);
      buf = (t_float *)t_getbytes(outsize * sizeof(*buf));
!     x->s_vec = buf;
      x->s_n   = outsize;
    }
!   resample_dsp(x, in, insize, x->s_vec, x->s_n, method);
    return;
  }
--- 1054,1070 ----
  void resamplefrom_dsp(t_resample *x, t_sample *in, int insize, int outsize, int method) {
    if (insize==outsize) {
!     free(x->v);
      x->s_n = 0;
!     x->v = in;
      return;
    }
    if (x->s_n != outsize) {
!     t_float *buf=x->v;
      free(buf);
      buf = (t_float *)t_getbytes(outsize * sizeof(*buf));
!     x->v = buf;
      x->s_n   = outsize;
    }
!   resample_dsp(x, in, insize, x->v, x->s_n, method);
    return;
  }
***************
*** 1071,1087 ****
  void resampleto_dsp(t_resample *x, t_sample *out, int insize, int outsize, int method) {
    if (insize==outsize) {
!     if (x->s_n) free(x->s_vec);
      x->s_n = 0;
!     x->s_vec = out;
      return;
    }
    if (x->s_n != insize) {
!     t_float *buf=x->s_vec;
      free(buf);
      buf = (t_float *)t_getbytes(insize * sizeof(*buf));
!     x->s_vec = buf;
      x->s_n   = insize;
    }
!   resample_dsp(x, x->s_vec, x->s_n, out, outsize, method);
    return;
  }
--- 1072,1088 ----
  void resampleto_dsp(t_resample *x, t_sample *out, int insize, int outsize, int method) {
    if (insize==outsize) {
!     if (x->s_n) free(x->v);
      x->s_n = 0;
!     x->v = out;
      return;
    }
    if (x->s_n != insize) {
!     t_float *buf=x->v;
      free(buf);
      buf = (t_float *)t_getbytes(insize * sizeof(*buf));
!     x->v = buf;
      x->s_n   = insize;
    }
!   resample_dsp(x, x->v, x->s_n, out, outsize, method);
    return;
  }





More information about the Pd-cvs mailing list