There was also a buffer overrun in the frequency analysis code, which
caused very unpredictable results. Patch attached.

For explanation:
http://www.network-theory.co.uk/docs/gslref/gsl-ref_245.html

        The terms for k=0 and k=N/2 are both purely real, and count as a
        special case. Their real parts are stored in locations 0 and N/2
        respectively, while their imaginary parts which are zero are not
        stored.

The zero value did already have special treatment, but it was again used
in the loop as the value of j, causing ch1[window_size - j] to overrun.
--- analysis.c.orig     2006-04-06 12:54:28.000000000 +0300
+++ analysis.c  2006-04-06 12:42:03.000000000 +0300
@@ -618,8 +618,10 @@
         gsl_fft_real_radix2_transform (ch1, 1, window_size);
         
         mags [0] = fabs (ch1 [0]);
-        
-        for (j = 0; j < window_size / 2; j++) {
+       if (mags [0] > ch1max)
+            ch1max = mags [j];
+
+        for (j = 1; j < window_size / 2; j++) {
             mags [j] = sqrt (ch1 [j] * ch1 [j] + ch1 [window_size - j] * ch1 
[window_size - j]);
             
             if (mags [j] > ch1max)
@@ -632,8 +634,10 @@
         
         if (wsfile->header.modus == 2) {
             mags [0] = fabs (ch2 [0]);
+           if (mags [0] > ch2max)
+               ch2max = mags [j];
             
-            for (j = 0; j < window_size / 2; j++) {
+            for (j = 1; j < window_size / 2; j++) {
                 mags [j] = sqrt (ch2 [j] * ch2 [j] + ch2 [window_size - j] * 
ch2 [window_size - j]);
                 
                 if (mags [j] > ch2max)

Reply via email to