[xiph-commits] r17999 - trunk/chirptest

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Mon May 23 08:51:27 PDT 2011


Author: xiphmont
Date: 2011-05-23 08:51:27 -0700 (Mon, 23 May 2011)
New Revision: 17999

Modified:
   trunk/chirptest/chirp.c
   trunk/chirptest/chirptest.c
Log:
Optimize the fixed overflow guard


Modified: trunk/chirptest/chirp.c
===================================================================
--- trunk/chirptest/chirp.c	2011-05-23 15:03:34 UTC (rev 17998)
+++ trunk/chirptest/chirp.c	2011-05-23 15:51:27 UTC (rev 17999)
@@ -174,6 +174,8 @@
       float aS = sin(c->P);
       float move;
 
+      if(c->A==-1) continue;
+
       for(j=0;j<len;j++){
 
         /* no part of the nonlinear algorithm requires double
@@ -280,8 +282,9 @@
       if((aP*aP + bP*bP)>1e10 ||
          (cP*cP + dP*dP)>1e10 ||
          (eP*eP + fP*fP)>1e10){
-        flag=1;
-        continue;
+        /* mark this chirp inactive */
+        c->A=-1;
+        break;
       }
 
       {
@@ -445,6 +448,8 @@
       float tmpe3=0;
       float tmpf3=0;
 
+      if(ch[i].A==-1) continue;
+
       /* chirp param -> basis acc */
       ai[i] = toAi(ch[i].A, ch[i].P);
       bi[i] = toBi(ch[i].A, ch[i].P);
@@ -568,21 +573,30 @@
           tmpf*ttsin_table[i][j];
       }
 
+      ai[i] += tmpa;
+      bi[i] += tmpb;
+      ci[i] += tmpc;
+      di[i] += tmpd;
+      ei[i] += tmpe;
+      fi[i] += tmpf;
+
       /* guard overflow */
       if((ai[i]*ai[i] + bi[i]*bi[i])>1e10 ||
          (ci[i]*ci[i] + di[i]*di[i])>1e10 ||
          (ei[i]*ei[i] + fi[i]*fi[i])>1e10){
-        flag=1;
+        for (j=0;j<len;j++){
+          y[j] +=
+            ai[i]*cos_table[i][j]+
+            bi[i]*sin_table[i][j]+
+            ci[i]*tcos_table[i][j]+
+            di[i]*tsin_table[i][j]+
+            ei[i]*ttcos_table[i][j]+
+            fi[i]*ttsin_table[i][j];
+        }
+        ch[i].A=-1;
         continue;
       }
 
-      ai[i] += tmpa;
-      bi[i] += tmpb;
-      ci[i] += tmpc;
-      di[i] += tmpd;
-      ei[i] += tmpe;
-      fi[i] += tmpf;
-
       /* save new estimate */
       ch[i].A = toA(ai[i],bi[i]);
       ch[i].P = toP(ai[i],bi[i]);
@@ -696,6 +710,8 @@
     float tmpe3=0;
     float tmpf3=0;
 
+    if(ch[i].A==-1)continue;
+
     /* seed the basis accumulators from our passed in estimated parameters */
     /* Don't add in W; this is already included by the basis */
     ai[i] = toAi(ch[i].A, ch[i].P);
@@ -827,22 +843,30 @@
           tmpf*ttsin_table[i][j];
       }
 
+      ai[i] += tmpa;
+      bi[i] += tmpb;
+      ci[i] += tmpc;
+      di[i] += tmpd;
+      ei[i] += tmpe;
+      fi[i] += tmpf;
 
       /* guard overflow */
       if((ai[i]*ai[i] + bi[i]*bi[i])>1e10 ||
          (ci[i]*ci[i] + di[i]*di[i])>1e10 ||
          (ei[i]*ei[i] + fi[i]*fi[i])>1e10){
-        flag=1;
+        for (j=0;j<len;j++){
+          y[j] +=
+            ai[i]*cos_table[i][j]+
+            bi[i]*sin_table[i][j]+
+            ci[i]*tcos_table[i][j]+
+            di[i]*tsin_table[i][j]+
+            ei[i]*ttcos_table[i][j]+
+            fi[i]*ttsin_table[i][j];
+        }
+        ch[i].A=-1;
         continue;
       }
 
-      ai[i] += tmpa;
-      bi[i] += tmpb;
-      ci[i] += tmpc;
-      di[i] += tmpd;
-      ei[i] += tmpe;
-      fi[i] += tmpf;
-
       /* base convergence on basis projection movement this
          iteration */
       {
@@ -858,12 +882,17 @@
   }
 
   for(i=0;i<n;i++){
-    ch[i].A = toA(ai[i],bi[i]);
-    ch[i].P = toP(ai[i],bi[i]);
-    ch[i].W += (fitW ? toW(ai[i],bi[i],ci[i],di[i]) : 0);
-    ch[i].dA = (fitdA ? todA(ai[i],bi[i],ci[i],di[i]) : 0);
-    ch[i].dW += (fitdW ? todW(ai[i],bi[i],ei[i],fi[i]) : 0);
-    ch[i].ddA = (fitddA ? toddA(ai[i],bi[i],ei[i],fi[i]) : 0);
+    if(ch[i].A!=-1){
+      ch[i].A = toA(ai[i],bi[i]);
+      ch[i].P = toP(ai[i],bi[i]);
+      ch[i].W += (fitW ? toW(ai[i],bi[i],ci[i],di[i]) : 0);
+      ch[i].dA = (fitdA ? todA(ai[i],bi[i],ci[i],di[i]) : 0);
+      ch[i].dW += (fitdW ? todW(ai[i],bi[i],ei[i],fi[i]) : 0);
+      ch[i].ddA = (fitddA ? toddA(ai[i],bi[i],ei[i],fi[i]) : 0);
+    }else{
+      memset(ch+i,0,sizeof(ch[i]));
+      ch[i].A=-1;
+    }
 
     free(cos_table[i]);
     free(sin_table[i]);

Modified: trunk/chirptest/chirptest.c
===================================================================
--- trunk/chirptest/chirptest.c	2011-05-23 15:03:34 UTC (rev 17998)
+++ trunk/chirptest/chirptest.c	2011-05-23 15:51:27 UTC (rev 17999)
@@ -829,7 +829,10 @@
         if(expl || zeroes>1)
           strcat(subtitle2,", ");
 
-        strcat(subtitle2,"swept ");
+        if(arg->sweep_or_rand_p)
+          strcat(subtitle2,"randomized ");
+        else
+          strcat(subtitle2,"swept ");
         strcat(subtitle2,buf);
       }
     }
@@ -1042,7 +1045,10 @@
         if(expl || zeroes>1)
           strcat(subtitle2,", ");
 
-        strcat(subtitle2," swept ");
+        if(arg->sweep_or_rand_p)
+          strcat(subtitle2,"randomized ");
+        else
+          strcat(subtitle2," swept ");
         strcat(subtitle2,buf);
       }
     }
@@ -2495,7 +2501,7 @@
     /* fontsize */      18,
     /* titles */        0,0,0,0,0,0,
     /* blocksize */     256,
-    /* threads */       32,
+    /* threads */       8,
 
     /* window */        window_functions.sine,
     /* fit_tol */       .000001,
@@ -3013,6 +3019,13 @@
   arg.y_minor = 5;
   arg.yaxis_label = "test chirp amplitude (dB)";
 
+
+  arg.est.A_rel = 1;
+  arg.est_alt.A_rel = 1;
+
+  arg.est.W_0 = arg.est.W_1 = 1;
+  arg.est_alt.W_0 = arg.est_alt.W_1 = -1;
+
   arg.fit_nonlinear=0;
   arg.window = window_functions.rectangle;
   graph_1chirp("2ch-",&arg);



More information about the commits mailing list