[PD-cvs] pd/src d_ugen.c,1.3.4.1.2.5.2.15,1.3.4.1.2.5.2.16

Mathieu Bouchard matju at users.sourceforge.net
Thu Jul 19 22:50:43 CEST 2007


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

Modified Files:
      Tag: desiredata
	d_ugen.c 
Log Message:
cleanup


Index: d_ugen.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/d_ugen.c,v
retrieving revision 1.3.4.1.2.5.2.15
retrieving revision 1.3.4.1.2.5.2.16
diff -C2 -d -r1.3.4.1.2.5.2.15 -r1.3.4.1.2.5.2.16
*** d_ugen.c	19 Jul 2007 17:54:53 -0000	1.3.4.1.2.5.2.15
--- d_ugen.c	19 Jul 2007 20:50:41 -0000	1.3.4.1.2.5.2.16
***************
*** 51,62 ****
      int n = int(w[2]);
      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;
      }
      return w+3;
--- 51,58 ----
      int n = int(w[2]);
      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;
      }
      return w+3;
***************
*** 309,325 ****
      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");
!             return;
!         }
!     }
!     for (s5 = signal_freelist[logn]; s5; s5 = s5->nextfree) {
!         if (s5 == sig) {
!             bug("signal_free 4");
!             return;
!         }
!     }
  #endif
      if (ugen_loud) post("free %lx: %d", sig, sig->isborrowed);
--- 305,310 ----
      int logn = ilog2(sig->vecsize);
  #if 1
!     for (t_signal *s5 = signal_freeborrowed;   s5; s5 = s5->nextfree) {if (s5 == sig) {bug("signal_free 3"); return;}}
!     for (t_signal *s5 = signal_freelist[logn]; s5; s5 = s5->nextfree) {if (s5 == sig) {bug("signal_free 4"); return;}}
  #endif
      if (ugen_loud) post("free %lx: %d", sig, sig->isborrowed);
***************
*** 601,611 ****
          (*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);
--- 586,594 ----
          (*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);
***************
*** 628,635 ****
                  s1->refcount--;
                  s2->refcount--;
!                 if (!signal_compatible(s1, s2)) {
!                     pd_error(u->obj, "%s: incompatible signal inputs", class_getname(u->obj->ob_pd));
!                     return;
!                 }
                  s3 = signal_newlike(s1);
                  dsp_add_plus(s1->v, s2->v, s3->v, s1->n);
--- 611,615 ----
                  s1->refcount--;
                  s2->refcount--;
!                 if (!signal_compatible(s1, s2)) {pd_error(u->obj, "%s: incompatible signal inputs", class_getname(u->obj->ob_pd)); return;}
                  s3 = signal_newlike(s1);
                  dsp_add_plus(s1->v, s2->v, s3->v, s1->n);
***************
*** 640,652 ****
              } else uin->signal = s1;
              uin->ngot++;
!             /* if we didn't fill this inlet don't bother yet */
!             if (uin->ngot < uin->nconnect)
!                 goto notyet;
!             /* if there's more than one, check them all */
!             if (u2->nin > 1) {
!                 for (uin = u2->in, n = u2->nin; n--; uin++)
!                     if (uin->ngot < uin->nconnect) goto notyet;
!             }
!             /* so now we can schedule the ugen.  */
              ugen_doit(dc, u2);
          notyet: ;
--- 620,625 ----
              } else uin->signal = s1;
              uin->ngot++;
!             if (uin->ngot < uin->nconnect) goto notyet;
!             if (u2->nin > 1) for (uin = u2->in, n = u2->nin; n--; uin++) if (uin->ngot < uin->nconnect) goto notyet;
              ugen_doit(dc, u2);
          notyet: ;
***************
*** 657,674 ****
  }
  
!     /* once the DSP graph is built, we call this routine to sort it.
!     This routine also deletes the graph; later we might want to leave the
!     graph around, in case the user is editing the DSP network, to save having
!     to recreate it all the time.  But not today.  */
! 
  extern "C" void ugen_done_graph(t_dspcontext *dc) {
-     t_ugenbox *u;
      t_sigoutlet *uout;
      t_siginlet *uin;
      int i, n;
      t_block *blk;
-     t_dspcontext *parent_context = dc->parentcontext;
-     float parent_srate;
-     int parent_vecsize;
      int period, frequency, phase, vecsize, calcsize;
      float srate;
--- 630,641 ----
  }
  
! /* once the DSP graph is built, we call this routine to sort it. This routine also deletes the graph; later we might
!    want to leave the graph around, in case the user is editing the DSP network, to save having to recreate it all the
!    time.  But not today.  */
  extern "C" void ugen_done_graph(t_dspcontext *dc) {
      t_sigoutlet *uout;
      t_siginlet *uin;
      int i, n;
      t_block *blk;
      int period, frequency, phase, vecsize, calcsize;
      float srate;
***************
*** 678,682 ****
      if (ugen_loud) {
          post("ugen_done_graph...");
!         for (u = dc->ugenlist; u; u = u->next) {
              post("ugen: %s", class_getname(u->obj->ob_pd));
              for (uout = u->out, i = 0; i < u->nout; uout++, i++)
--- 645,649 ----
      if (ugen_loud) {
          post("ugen_done_graph...");
!         for (t_ugenbox *u = dc->ugenlist; u; u = u->next) {
              post("ugen: %s", class_getname(u->obj->ob_pd));
              for (uout = u->out, i = 0; i < u->nout; uout++, i++)
***************
*** 687,691 ****
      }
      /* 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) {
--- 654,659 ----
      }
      /* search for an object of class "block~" */
!     blk = 0;
!     for (t_ugenbox *u = dc->ugenlist; u; u = u->next) {
          t_pd *zz = u->obj;
          if (pd_class(zz) == block_class) {
***************
*** 694,713 ****
          }
      }
!     /* figure out block size, calling frequency, sample rate */
!     if (parent_context) {
!         parent_srate = parent_context->srate;
!         parent_vecsize = parent_context->vecsize;
!     } else {
!         parent_srate = sys_getsr();
!         parent_vecsize = sys_getblksize();
!     }
      if (blk) {
          int realoverlap;
!         vecsize = blk->vecsize;
!         if (!vecsize) vecsize = parent_vecsize;
!         calcsize = blk->calcsize;
!         if (!calcsize) calcsize = vecsize;
!         realoverlap = blk->overlap;
!         if (realoverlap > vecsize) realoverlap = vecsize;
          /* IOhannes { */
          downsample = blk->downsample;
--- 662,673 ----
          }
      }
!     t_dspcontext *parent_context = dc->parentcontext;
!     float parent_srate = parent_context ? parent_context->srate   : sys_getsr();
!     int parent_vecsize = parent_context ? parent_context->vecsize : sys_getblksize();
      if (blk) {
          int realoverlap;
!         vecsize     = blk->vecsize; if (!vecsize) vecsize = parent_vecsize;
!         calcsize    = blk->calcsize;if (!calcsize) calcsize = vecsize;
!         realoverlap = blk->overlap; if (realoverlap > vecsize) realoverlap = vecsize;
          /* IOhannes { */
          downsample = blk->downsample;
***************
*** 743,750 ****
      dc->vecsize = vecsize;
      dc->calcsize = calcsize;
!     /* 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->iosigs && (switched || reblock)) {
          t_signal **sigp;
--- 703,709 ----
      dc->vecsize = vecsize;
      dc->calcsize = calcsize;
!     /* 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->iosigs && (switched || reblock)) {
          t_signal **sigp;
***************
*** 758,769 ****
      }
      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. */
!     for (u = dc->ugenlist; u; u = u->next) {
          t_pd *zz = u->obj;
          t_signal **outsigs = dc->iosigs;
--- 717,725 ----
      }
      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. */
!     for (t_ugenbox *u = dc->ugenlist; u; u = u->next) {
          t_pd *zz = u->obj;
          t_signal **outsigs = dc->iosigs;
***************
*** 782,786 ****
      }
      /* Initialize for sorting */
!     for (u = dc->ugenlist; u; u = u->next) {
          u->done = 0;
          for (uout = u->out, i = u->nout; i--; uout++) uout->nsent = 0;
--- 738,742 ----
      }
      /* Initialize for sorting */
!     for (t_ugenbox *u = dc->ugenlist; u; u = u->next) {
          u->done = 0;
          for (uout = u->out, i = u->nout; i--; uout++) uout->nsent = 0;
***************
*** 788,792 ****
      }
      /* Do the sort */
!     for (u = dc->ugenlist; u; u = u->next) {
          /* check that we have no connected signal inlets */
          if (u->done) continue;
--- 744,748 ----
      }
      /* Do the sort */
!     for (t_ugenbox *u = dc->ugenlist; u; u = u->next) {
          /* check that we have no connected signal inlets */
          if (u->done) continue;
***************
*** 797,801 ****
      }
      /* check for a DSP loop, which is evidenced here by the presence of ugens not yet scheduled. */
!     for (u = dc->ugenlist; u; u = u->next) if (!u->done) {
          t_signal **sigp;
          pd_error(u->obj, "DSP loop detected (some tilde objects not scheduled)");
--- 753,757 ----
      }
      /* check for a DSP loop, which is evidenced here by the presence of ugens not yet scheduled. */
!     for (t_ugenbox *u = dc->ugenlist; u; u = u->next) if (!u->done) {
          t_signal **sigp;
          pd_error(u->obj, "DSP loop detected (some tilde objects not scheduled)");
***************
*** 816,820 ****
      int chainblockend = dsp_chainsize; /* and after block epilog code */
      /* add epilogs for outlets. */
!     for (u = dc->ugenlist; u; u = u->next) {
          t_pd *zz = u->obj;
          if (pd_class(zz) == voutlet_class) {
--- 772,776 ----
      int chainblockend = dsp_chainsize; /* and after block epilog code */
      /* add epilogs for outlets. */
!     for (t_ugenbox *u = dc->ugenlist; u; u = u->next) {
          t_pd *zz = u->obj;
          if (pd_class(zz) == voutlet_class) {
***************
*** 849,853 ****
          free(dc->ugenlist->out);
          free(dc->ugenlist->in);
!         u = dc->ugenlist;
          dc->ugenlist = u->next;
          free(u);
--- 805,809 ----
          free(dc->ugenlist->out);
          free(dc->ugenlist->in);
!         t_ugenbox *u = dc->ugenlist;
          dc->ugenlist = u->next;
          free(u);
***************
*** 907,914 ****
    n = parent;
    out = dummy;
!   while(n--) {
!     *out=*in++;
!     out+=up;
!   }
    return w+5;
  }
--- 863,867 ----
    n = parent;
    out = dummy;
!   while(n--) {*out=*in++; out+=up;}
    return w+5;
  }
***************
*** 920,934 ****
    int parent   = int(w[4]);       /* original vectorsize */
    int i=up;
-   int n=parent;
    t_float *dum_out = out;
    t_float *dum_in  = in;
    while (i--) {
!     n = parent;
      out = dum_out+i;
      in  = dum_in;
!     while(n--){
!       *out=*in++;
!       out+=up;
!     }
    }
    return w+5;
--- 873,883 ----
    int parent   = int(w[4]);       /* original vectorsize */
    int i=up;
    t_float *dum_out = out;
    t_float *dum_in  = in;
    while (i--) {
!     int n = parent;
      out = dum_out+i;
      in  = dum_in;
!     while(n--) {*out=*in++; out+=up;}
    }
    return w+5;
***************
*** 942,951 ****
    const int parent   = int(w[5]); /* original vectorsize */
    const int length   = parent*up;
-   int n;
    t_float *fp;
    t_float a=*x->buffer, b=*in;
    const t_float up_inv = (t_float)1.0/up;
    t_float findex = 0.f;
!   for (n=0; n<length; n++) {
      const int index = int(findex+=up_inv);
      t_float frac=findex-index;
--- 891,899 ----
    const int parent   = int(w[5]); /* original vectorsize */
    const int length   = parent*up;
    t_float *fp;
    t_float a=*x->buffer, b=*in;
    const t_float up_inv = (t_float)1.0/up;
    t_float findex = 0.f;
!   for (int n=0; n<length; n++) {
      const int index = int(findex+=up_inv);
      t_float frac=findex-index;
***************
*** 964,969 ****
    /* 1st part of the upsampled signal-vector will be the original one
     * 2nd part of the upsampled signal-vector is just 0
!    * cool for FFT-data, where you only want to process the significant (1st) part of the vector
!    */
    t_float *in  = (t_float *)w[1]; /* original signal     */
    t_float *out = (t_float *)w[2]; /* upsampled signal    */
--- 912,916 ----
    /* 1st part of the upsampled signal-vector will be the original one
     * 2nd part of the upsampled signal-vector is just 0
!    * cool for FFT-data, where you only want to process the significant (1st) part of the vector */
    t_float *in  = (t_float *)w[1]; /* original signal     */
    t_float *out = (t_float *)w[2]; /* upsampled signal    */
***************
*** 973,977 ****
    int n=parent*(up-1);
    while (i--) *out++=*in++;
!   while(n--) *out++=0.f;
    return w+5;
  }
--- 920,924 ----
    int n=parent*(up-1);
    while (i--) *out++=*in++;
!   while (n--) *out++=0.f;
    return w+5;
  }
***************
*** 983,1009 ****
    x->method=0;
    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;
  }
- 
- /* dsp-adding */
  void resample_dsp(t_resample *x, t_sample* in, int insize, t_sample* out, int outsize, int method) {
!   if (insize == outsize) {
!     bug("nothing to be done");
!     return;
!   }
    if (insize > outsize) { /* downsampling */
!     if (insize % outsize) {
!       error("bad downsampling factor");
!       return;
!     }
      switch (method) {
      case RESAMPLE_BLOCK: dsp_add(downsampling_perform_block, 4, in, out, insize/outsize, insize); break;
--- 930,947 ----
    x->method=0;
    x->downsample=x->upsample=1;
!   x->n = x->coefsize = x->bufsize = 0;
!   x->v = x->coeffs   = x->buffer  = 0;
  }
  void resample_free(t_resample *x) {
!   if (x->n) free(x->v);
    if (x->coefsize) free(x->coeffs);
    if (x->bufsize) free(x->buffer);
!   x->n = x->coefsize = x->bufsize = 0;
!   x->v = x->coeffs   = x->buffer  = 0;
  }
  void resample_dsp(t_resample *x, t_sample* in, int insize, t_sample* out, int outsize, int method) {
!   if (insize == outsize) {bug("nothing to be done"); return;}
    if (insize > outsize) { /* downsampling */
!     if (insize % outsize) {error("bad downsampling factor"); return;}
      switch (method) {
      case RESAMPLE_BLOCK: dsp_add(downsampling_perform_block, 4, in, out, insize/outsize, insize); break;
***************
*** 1011,1018 ****
      }
    } else { /* upsampling */
!     if (outsize % insize) {
!       error("bad upsampling factor");
!       return;
!     }
      switch (method) {
      case RESAMPLE_HOLD: dsp_add(upsampling_perform_hold, 4, in, out, outsize/insize, insize); break;
--- 949,953 ----
      }
    } else { /* upsampling */
!     if (outsize % insize) {error("bad upsampling factor"); return;}
      switch (method) {
      case RESAMPLE_HOLD: dsp_add(upsampling_perform_hold, 4, in, out, outsize/insize, insize); break;
***************
*** 1030,1068 ****
    }
  }
- 
  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;
  }
- 
  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;
  }
  
--- 965,985 ----
    }
  }
  void resamplefrom_dsp(t_resample *x, t_sample *in, int insize, int outsize, int method) {
!   if (insize==outsize) {           free(x->v); x->n = 0; x->v = in; return;}
!   if (x->n != outsize) {
      free(x->v);
!     x->v = (t_float *)t_getbytes(outsize * sizeof(*x->v));
!     x->n = outsize;
    }
!   resample_dsp(x, in, insize, x->v, x->n, method);
  }
  void resampleto_dsp(t_resample *x, t_sample *out, int insize, int outsize, int method) {
!   if (insize==outsize) {if (x->n) free(x->v); x->n = 0; x->v = out; return;}
!   if (x->n != insize) {
!     free(x->v);
!     x->v = (t_float *)t_getbytes(insize * sizeof(*x->v));
!     x->n = insize;
    }
!   resample_dsp(x, x->v, x->n, out, outsize, method);
  }
  
***************
*** 1070,1080 ****
  
  static t_class *samplerate_tilde_class;
- 
  struct t_samplerate : t_object {
      t_canvas *canvas;
  };
- 
  extern "C" void *canvas_getblock(t_class *blockclass, t_canvas **canvasp);
- 
  static void samplerate_tilde_bang(t_samplerate *x) {
      float srate = sys_getsr();
--- 987,994 ----
***************
*** 1086,1090 ****
      outlet_float(x->ob_outlet, srate);
  }
- 
  static void *samplerate_tilde_new(t_symbol *s) {
      t_samplerate *x = (t_samplerate *)pd_new(samplerate_tilde_class);
--- 1000,1003 ----
***************
*** 1093,1097 ****
      return x;
  }
- 
  static void samplerate_tilde_setup() {
      samplerate_tilde_class = class_new(gensym("samplerate~"), (t_newmethod)samplerate_tilde_new, 0, sizeof(t_samplerate), 0, 0);
--- 1006,1009 ----





More information about the Pd-cvs mailing list