[PD-cvs] pd/extra/sigmund~ sigmund~.c,1.2,1.3

Miller Puckette millerpuckette at users.sourceforge.net
Fri Jul 20 05:25:22 CEST 2007


Update of /cvsroot/pure-data/pd/extra/sigmund~
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29296/pd/extra/sigmund~

Modified Files:
	sigmund~.c 
Log Message:
various bug fixes.



Index: sigmund~.c
===================================================================
RCS file: /cvsroot/pure-data/pd/extra/sigmund~/sigmund~.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** sigmund~.c	22 Oct 2006 21:46:10 -0000	1.2
--- sigmund~.c	20 Jul 2007 03:25:20 -0000	1.3
***************
*** 182,185 ****
--- 182,202 ----
  }
  
+ static void sigmund_remask(int maxbin, int bestindex, float powmask, 
+     float maxpower, float *maskbuf)
+ {
+     int bin;
+     int bin1 = (bestindex > 52 ? bestindex-50:2);
+     int bin2 = (maxbin < bestindex + 50 ? bestindex + 50 : maxbin);
+     for (bin = bin1; bin < bin2; bin++)
+     {
+         float bindiff = bin - bestindex;
+         float mymask;
+         mymask = powmask/ (1. + bindiff * bindiff * bindiff * bindiff);
+         if (bindiff < 2 && bindiff > -2)
+             mymask = 2*maxpower;
+         if (mymask > maskbuf[bin])
+             maskbuf[bin] = mymask;
+     } 
+ }
  
  static void sigmund_getrawpeaks(int npts, float *insamps,
***************
*** 192,199 ****
      int count, peakcount = 0;
      float *fp1, *fp2;
!     float *rawpow, *rawreal, *rawimag, *maskbuf;
!     float *bigbuf = alloca(sizeof (float ) * (2*NEGBINS + 5*npts));
      int maxbin = hifreq/fperbin;
-     int altwind = (param3 == 1);
      int tweak = (param3 == 0);
      if (maxbin > npts - NEGBINS)
--- 209,215 ----
      int count, peakcount = 0;
      float *fp1, *fp2;
!     float *rawpow, *rawreal, *rawimag, *maskbuf, *powbuf;
!     float *bigbuf = alloca(sizeof (float ) * (2*NEGBINS + 6*npts));
      int maxbin = hifreq/fperbin;
      int tweak = (param3 == 0);
      if (maxbin > npts - NEGBINS)
***************
*** 201,205 ****
      if (loud) post("tweak %d", tweak);
      maskbuf = bigbuf + npts2;
!     rawreal = maskbuf + npts+NEGBINS;
      rawimag = rawreal+npts+NEGBINS;
      for (i = 0; i < npts; i++)
--- 217,222 ----
      if (loud) post("tweak %d", tweak);
      maskbuf = bigbuf + npts2;
!     powbuf = maskbuf + npts;
!     rawreal = powbuf + npts+NEGBINS;
      rawimag = rawreal+npts+NEGBINS;
      for (i = 0; i < npts; i++)
***************
*** 237,241 ****
      rawimag[-3] = -rawimag[3];
      rawimag[-4] = -rawimag[4];
! 
      for (peakcount = 0; peakcount < npeak; peakcount++)
      {
--- 254,265 ----
      rawimag[-3] = -rawimag[3];
      rawimag[-4] = -rawimag[4];
! #if 1
!     for (i = 0, fp1 = rawreal, fp2 = rawimag; i < npts-1; i++, fp1++, fp2++)
!     {
!         float x1 = fp1[1] - fp1[-1], x2 = fp2[1] - fp2[-1]; 
!         powbuf[i] = x1*x1+x2*x2;
!     }
!     powbuf[npts-1] = 0;
! #endif
      for (peakcount = 0; peakcount < npeak; peakcount++)
      {
***************
*** 244,274 ****
              ampoutreal, ampoutimag, freqout, freqcount1, freqcount2, powmask;
          int bestindex = -1;
          for (bin = 2, fp1 = rawreal+2, fp2 = rawimag+2;
              bin < maxbin; bin++, fp1++, fp2++)
          {
!             float x1, x2, a1, a2, b1, b2, thresh;
!             if (altwind)
!             {
!                 x1 = fp1[0] - 0.5*(fp1[-2] +fp1[2]);
!                 x2 = fp2[0] - 0.5*(fp2[-2] +fp2[2]);
!                 a1 = fp1[4] - 0.5*(fp1[2] +fp1[6]);
!                 a2 = fp2[2] - 0.5*(fp2[2] +fp2[6]);
!                 b1 = fp1[-4] - 0.5*(fp1[-2] +fp1[-6]);
!                 b2 = fp2[-4] - 0.5*(fp2[-2] +fp2[-6]);
!                 thresh = param2 * (a1*a1+a2*a2+b1*b1+b2*b2);
!             }
!             else
!             {
!                 x1 = fp1[1] - fp1[-1];
!                 x2 = fp2[1] - fp2[-1];
!                 a1 = fp1[3] - fp1[1];
!                 a2 = fp2[3] - fp2[1];
!                 b1 = fp1[-1] - fp1[-3];
!                 b2 = fp2[-1] - fp2[-3];
!                 thresh = param2 * (a1*a1+a2*a2+b1*b1+b2*b2);
!             }
!             pow1 = x1*x1+x2*x2;
              if (pow1 > maxpower && pow1 > maskbuf[bin])
              {
                  if (pow1 > thresh)
                      maxpower = pow1, bestindex = bin;
--- 268,279 ----
              ampoutreal, ampoutimag, freqout, freqcount1, freqcount2, powmask;
          int bestindex = -1;
+ 
          for (bin = 2, fp1 = rawreal+2, fp2 = rawimag+2;
              bin < maxbin; bin++, fp1++, fp2++)
          {
!             pow1 = powbuf[bin];
              if (pow1 > maxpower && pow1 > maskbuf[bin])
              {
+                 float thresh = param2 * (powbuf[bin-2]+powbuf[bin+2]);
                  if (pow1 > thresh)
                      maxpower = pow1, bestindex = bin;
***************
*** 276,279 ****
--- 281,285 ----
              totalpower += pow1;
          }
+ 
          if (totalpower <= 0 || maxpower < 1e-10*totalpower || bestindex < 0)
              break;
***************
*** 285,328 ****
              post("maxpower %f, powmask %f, param1 %f",
                  maxpower, powmask, param1);
!         for (bin = 2; bin < maxbin; bin++)
!         {
!             float bindiff = bin - bestindex;
!             float mymask =
!                 powmask/ (1. + bindiff * bindiff * bindiff * bindiff);
!             if (bindiff < 2 && bindiff > -2)
!                 mymask = 2*maxpower;
!             if (mymask > maskbuf[bin])
!                 maskbuf[bin] = mymask;
!         } 
          
          if (loud > 1)
              post("best index %d, total power %f", bestindex, totalpower);
!         if (altwind)
!         {
!             windreal = W_ALPHA * fp1[0] - (0.5 * W_BETA) * (fp1[2] + fp1[-2]);
!             windimag = W_ALPHA * fp2[0] - (0.5 * W_BETA) * (fp2[2] + fp2[-2]);
!             windpower = windreal * windreal + windimag * windimag;
!             detune = (
!                 (W_BETA*(rawreal[bestindex-2] - rawreal[bestindex+2])) *
!                 (2.0 * W_ALPHA * rawreal[bestindex] - 
!                     W_BETA * (rawreal[bestindex-2] + rawreal[bestindex+2]))
!                         +
!                 (W_BETA*(rawimag[bestindex-2] - rawimag[bestindex+2])) *
!                 (2.0 * W_ALPHA * rawimag[bestindex] - 
!                     W_BETA * (rawimag[bestindex-2] + rawimag[bestindex+2]))
!                             ) / (4.0 * windpower);
!         }
!         else
!         {
!             windreal = fp1[1] - fp1[-1];
!             windimag = fp2[1] - fp2[-1];
!             windpower = windreal * windreal + windimag * windimag;
!             detune = ((fp1[1] * fp1[1] - fp1[-1]*fp1[-1]) 
!                 + (fp2[1] * fp2[1] - fp2[-1]*fp2[-1])) / (2 * windpower);
!             if (loud > 2) post("(-1) %f %f; (1) %f %f",
!                 fp1[-1], fp2[-1], fp1[1], fp2[1]);
!             if (loud > 2) post("peak %f %f",
!                 fp1[0], fp2[0]);
!         }
          if (detune > 0.5)
              detune = 0.5;
--- 291,309 ----
              post("maxpower %f, powmask %f, param1 %f",
                  maxpower, powmask, param1);
!         sigmund_remask(maxbin, bestindex, powmask, maxpower, maskbuf);
          
          if (loud > 1)
              post("best index %d, total power %f", bestindex, totalpower);
! 
!         windreal = fp1[1] - fp1[-1];
!         windimag = fp2[1] - fp2[-1];
!         windpower = windreal * windreal + windimag * windimag;
!         detune = ((fp1[1] * fp1[1] - fp1[-1]*fp1[-1]) 
!             + (fp2[1] * fp2[1] - fp2[-1]*fp2[-1])) / (2 * windpower);
!         if (loud > 2) post("(-1) %f %f; (1) %f %f",
!             fp1[-1], fp2[-1], fp1[1], fp2[1]);
!         if (loud > 2) post("peak %f %f",
!             fp1[0], fp2[0]);
! 
          if (detune > 0.5)
              detune = 0.5;
***************
*** 335,341 ****
          sinpidetune = sin(pidetune);
          cospidetune = cos(pidetune);
!         if (altwind)
!             ampcorrect = 1.0 / window_hann_mag(pidetune, sinpidetune);
!         else ampcorrect = 1.0 / window_mag(pidetune, cospidetune);
  
          ampout = ampcorrect *sqrt(windpower);
--- 316,320 ----
          sinpidetune = sin(pidetune);
          cospidetune = cos(pidetune);
!         ampcorrect = 1.0 / window_mag(pidetune, cospidetune);
  
          ampout = ampcorrect *sqrt(windpower);
***************
*** 845,852 ****
  {
      t_sigmund *x = (t_sigmund *)pd_new(sigmund_class);
      x->x_param1 = 0;
      x->x_param2 = 0.6;
      x->x_param3 = 0;
-     x->x_npts = NPOINTS_DEF;
      x->x_hop = HOP_DEF;
      x->x_mode = MODE_STREAM;
--- 824,831 ----
  {
      t_sigmund *x = (t_sigmund *)pd_new(sigmund_class);
+     x->x_npts = NPOINTS_DEF;
      x->x_param1 = 0;
      x->x_param2 = 0.6;
      x->x_param3 = 0;
      x->x_hop = HOP_DEF;
      x->x_mode = MODE_STREAM;
***************
*** 864,868 ****
      x->x_ntrack = 0;
      x->x_dopitch = x->x_donote = x->x_dotracks = 0;
!     
      while (argc > 0)
      {
--- 843,848 ----
      x->x_ntrack = 0;
      x->x_dopitch = x->x_donote = x->x_dotracks = 0;
!     x->x_inbuf = 0;
! 
      while (argc > 0)
      {
***************
*** 887,891 ****
          else if (!strcmp(firstarg->s_name, "-npts") && argc > 1)
          {
!             sigmund_npts(x, atom_getfloatarg(1, argc, argv));
              argc -= 2; argv += 2;
          }
--- 867,871 ----
          else if (!strcmp(firstarg->s_name, "-npts") && argc > 1)
          {
!             x->x_npts = atom_getfloatarg(1, argc, argv);
              argc -= 2; argv += 2;
          }
***************
*** 1009,1027 ****
      x->x_clock = clock_new(&x->x_obj.ob_pd, (t_method)sigmund_clock);
      
-         /* check parameter ranges */
-     if (x->x_npts < NPOINTS_MIN)
-         post("sigmund~: minimum points %d", NPOINTS_MIN),
-             x->x_npts = NPOINTS_MIN;
-     if (x->x_npts != (1 << sigmund_ilog2(x->x_npts)))
-         post("sigmund~: adjusting analysis size to %d points",
-             (x->x_npts = (1 << sigmund_ilog2(x->x_npts))));
-     if (x->x_hop != (1 << sigmund_ilog2(x->x_hop)))
-         post("sigmund~: adjusting hop size to %d points",
-             (x->x_hop = (1 << sigmund_ilog2(x->x_hop))));
-     if (x->x_mode == MODE_STREAM)
-         x->x_inbuf = getbytes(sizeof(*x->x_inbuf) * x->x_npts);
-     else x->x_inbuf = 0;
      x->x_infill = 0;
      x->x_countdown = 0;
      notefinder_init(&x->x_notefinder);
      sigmund_clear(x);
--- 989,995 ----
      x->x_clock = clock_new(&x->x_obj.ob_pd, (t_method)sigmund_clock);
      
      x->x_infill = 0;
      x->x_countdown = 0;
+     sigmund_npts(x, x->x_npts);
      notefinder_init(&x->x_notefinder);
      sigmund_clear(x);
***************
*** 1159,1170 ****
  static void sigmund_npts(t_sigmund *x, t_floatarg f)
  {
!     x->x_npts = f;
          /* check parameter ranges */
!     if (x->x_npts < NPOINTS_MIN)
          post("sigmund~: minimum points %d", NPOINTS_MIN),
!             x->x_npts = NPOINTS_MIN;
!     if (x->x_npts != (1 << sigmund_ilog2(x->x_npts)))
          post("sigmund~: adjusting analysis size to %d points",
!             (x->x_npts = (1 << sigmund_ilog2(x->x_npts))));
  }
  
--- 1127,1149 ----
  static void sigmund_npts(t_sigmund *x, t_floatarg f)
  {
!     int nwas = x->x_npts, npts = f;
          /* check parameter ranges */
!     if (npts < NPOINTS_MIN)
          post("sigmund~: minimum points %d", NPOINTS_MIN),
!             npts = NPOINTS_MIN;
!     if (npts != (1 << sigmund_ilog2(npts)))
          post("sigmund~: adjusting analysis size to %d points",
!             (npts = (1 << sigmund_ilog2(npts))));
!     if (npts != nwas)
!         x->x_countdown = x->x_infill  = 0;
!     if (x->x_mode == MODE_STREAM)
!     {
!         if (x->x_inbuf)
!             x->x_inbuf = resizebytes(x->x_inbuf,
!                 sizeof(*x->x_inbuf) * nwas, sizeof(*x->x_inbuf) * npts);
!         else x->x_inbuf = getbytes(sizeof(*x->x_inbuf) * npts);
!     }
!     else x->x_inbuf = 0;
!     x->x_npts = npts;
  }
  
***************
*** 1262,1265 ****
--- 1241,1246 ----
      int n = (int)(w[3]);
  
+     if (x->x_hop % n)
+         return (w+4);
      if (x->x_countdown > 0)
          x->x_countdown -= n;
***************
*** 1331,1335 ****
      class_addmethod(sigmund_class, (t_method)sigmund_printnext,
          gensym("printnext"), A_FLOAT, 0);
!     post("sigmund version 0.02");
  }
  
--- 1312,1316 ----
      class_addmethod(sigmund_class, (t_method)sigmund_printnext,
          gensym("printnext"), A_FLOAT, 0);
!     post("sigmund version 0.03");
  }
  





More information about the Pd-cvs mailing list