[xiph-commits] r13246 - trunk/ghost/monty/sinusoid

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Wed Jul 11 07:40:57 PDT 2007


Author: xiphmont
Date: 2007-07-11 07:40:57 -0700 (Wed, 11 Jul 2007)
New Revision: 13246

Modified:
   trunk/ghost/monty/sinusoid/sinusoids.c
   trunk/ghost/monty/sinusoid/sinusoids.h
   trunk/ghost/monty/sinusoid/test_sinusoids.c
Log:
An update to the thinking aloud; improvement of the weighted sliding mean curve generator.



Modified: trunk/ghost/monty/sinusoid/sinusoids.c
===================================================================
--- trunk/ghost/monty/sinusoid/sinusoids.c	2007-07-11 13:10:11 UTC (rev 13245)
+++ trunk/ghost/monty/sinusoid/sinusoids.c	2007-07-11 14:40:57 UTC (rev 13246)
@@ -10,7 +10,7 @@
  *                                                                  *
  ********************************************************************
 
- function: research-grade sinusoidal extraction sode
+ function: research-grade sinusoidal extraction code
  last mod: $Id$
 
  ********************************************************************/
@@ -22,94 +22,77 @@
 #include <stdlib.h>
 #include <string.h>
 
-/* f: input; log magnitude (decibel scale) of input spectrum */
+void level_mean(float *f, float *out, int n,
+		int lowindow, int hiwindow, int min, int rate){
+  int bark[n],i;
+  float binwidth = rate*.5f/n; 
+  float ibinwidth = 1.f/binwidth;
 
-void level_mean(float *f,float *out,int n, float lowindow, float hiwindow, int min, int rate){
-  float nevent[n];
-  float devent[n];
+  for(i=0;i<n;i++)
+    bark[i] = rint(toBark(i*binwidth) * 1024);
 
-  float nadd = 0.f;
-  float dadd = 0.f;
   float nacc = 0.f;
+  float nadd = 0.f;
   float dacc = 0.f;
-
-  float binwidth = rate*.5f/n; 
-  float ibinwidth = 1.f/binwidth;
-
-  int head=-1;
-  int tail=-1;
-  int i;
+  float dadd = 0.f;
   
-  memset(nevent,0,sizeof(nevent));
-  memset(devent,0,sizeof(devent));
+  int hihead=0;
+  int hitail=0;
+  int lohead=0;
+  int lotail=0;
 
-  /* init case for hi-side window */
-  int lo;
-  int hi = rint(fromBark(hiwindow)*ibinwidth);
-  if(hi<min)hi=min;
-
-  for(head=0;head<hi;head++){
-    float de = 1./hi;
-    float nu = f[head]*de;
-
-    nevent[head] -= nu;
-    devent[head] -= de;
-
-    nadd += nu;
-    dadd += de;
-    
-    nacc +=nadd;
-    dacc +=dadd;
-  }
-
   for(i=0;i<n;i++){
-    float bark = toBark(i*binwidth);
-    hi = rint(fromBark(bark+hiwindow)*ibinwidth)-i;
-    if(bark>lowindow)
-      lo = i-rint(fromBark(bark-lowindow)*ibinwidth);
-    else
-      lo = rint(fromBark(lowindow)*ibinwidth);
-    if(hi<min)hi=min;
-    if(lo<min)lo=min;
 
-    /* high side window*/
-    for(;head<i+hi;head++){
-      if(head<n){
-	float de = 1./hi;
-	float nu = f[head]*de;
+    for( ; hihead<n && (bark[hihead]<=bark[i]+hiwindow || hihead<i+min);hihead++){
+      int c = hihead-i+1;
+      float d = (c<min?1./min:1./c);
 
-	nevent[i+hi] -= nu;
-	devent[i+hi] -= de;
-	
-	nadd += nu;
-	dadd += de;
+      nadd += f[hihead]*d;
+      dadd += d;
 
+      while(c<min){
+	nacc += f[hihead]*d;
+	dacc += d;
+	c++;
       }
     }
 
-    /* low side window */
-    {
-      float de = 1./lo;
-      float nu = f[i]*de;
+    nacc += nadd;
+    dacc += dadd;
 
-      if(i+lo<n){
-	nevent[i+lo] += nu;
-	devent[i+lo] += de;
-      }
-      if(i<n){
-	nevent[i] -= nu;
-	devent[i] -= de;
-      }
+    if(lohead<n){
+      while(lohead<n && (bark[lohead]<=bark[i]+lowindow || lohead<i+min))
+	lohead++;
+    }else
+      lohead++;
+
+    {
+      int c = lohead-i;
+      float d = 1./c;
+      nadd -= f[i]*d;
+      dadd -= d;
     }
 
-    nadd += nevent[i];
-    dadd += devent[i];
+    for( ;lotail<i && bark[lotail]<bark[i]-lowindow && lotail<=i-min; lotail++){
+      int c = i-lotail;
+      float d = 1./c;
+      nadd += f[lotail]*d;
+      dadd += d;
+    }
     
-    nacc += nadd;
-    dacc += dadd;
+    while( hitail<i && bark[hitail]<bark[i]-hiwindow && hitail<=i-min)
+      hitail++;
 
-    out[i] = nacc/dacc; 
+    {
+      int c = i-hitail+1;
+      float d = (c<min?1./min:1./c);
+      nadd -= f[i]*d;
+      dadd -= d;
+    }
+
+    out[i] = nacc / dacc;
   }
+
 }
 
 

Modified: trunk/ghost/monty/sinusoid/sinusoids.h
===================================================================
--- trunk/ghost/monty/sinusoid/sinusoids.h	2007-07-11 13:10:11 UTC (rev 13245)
+++ trunk/ghost/monty/sinusoid/sinusoids.h	2007-07-11 14:40:57 UTC (rev 13246)
@@ -15,4 +15,4 @@
 
  ********************************************************************/
 
-extern void level_mean(float *f,float *out,int n, float lowindow, float hiwindow, int min, int rate);
+extern void level_mean(float *f,float *out,int n, int lowindow, int hiwindow, int min, int rate);

Modified: trunk/ghost/monty/sinusoid/test_sinusoids.c
===================================================================
--- trunk/ghost/monty/sinusoid/test_sinusoids.c	2007-07-11 13:10:11 UTC (rev 13245)
+++ trunk/ghost/monty/sinusoid/test_sinusoids.c	2007-07-11 14:40:57 UTC (rev 13246)
@@ -99,7 +99,7 @@
       mag_dB(fft_buf,BLOCK_SIZE*2);
       dump_vec(fft_buf,BLOCK_SIZE+1,"logmag",frame);
 
-      level_mean(fft_buf,weight,BLOCK_SIZE+1, 1.f,1.f, 10, 44100);
+      level_mean(fft_buf,weight,BLOCK_SIZE+1, 512,1024, 15, 44100);
       dump_vec(weight,BLOCK_SIZE+1,"weight",frame);
 
     }



More information about the commits mailing list