#617599 audacity: 32 bits floats 64 bits long and snd_fft behaviour

Package:
audacity
Source:
audacity
Description:
fast, cross-platform audio editor
Submitter:
jmg
Date:
2025-07-31 18:05:02 UTC
Severity:
normal
Tags:
#617599#5
Date:
2011-03-09 20:46:33 UTC
From:
To:
I have a nyquist script using snd-fft api which have a random beaviour on my computer
where floats are 32 bits and long 64 bits.
Each time I execute the script, result is different, when it should be about equal.

I 'd like to know if same random issue occur on 32 bits systems.
-------------8<--- Here after extracts of the debian source 
-------------8<--- ./lib-src/libnyquist/nyquist/nyqsrc/fft.c
110          * in the block. Here, there are 4 more longs after the size, and
111          * then room for 3*len floats (assumes that floats and longs take
112          * equal space).

130         window = (float *) &(s->extra[OFFSET + 2 * len]);

141     samples = (float *) &(s->extra[OFFSET]);
142     temp_fft = samples + len;
143     window = temp_fft + len;

// Note that as s->extra seams to be long pointer while samples and temp_fft seams to
// be float pointers, I am not confident that windows from line 130 and 143 might overlap.
-------------8<--- Here after the bits processor detector // long_and_float_size.c void main () { printf ("sizeof ( long ) = %d\n", sizeof(long) ); printf ("sizeof ( float ) = %d\n", sizeof(float) ); return sizeof(float) == sizeof(long); } // :~$ ./a.out // sizeof ( long ) = 8 // sizeof ( float ) = 4
-------------8<--- Here after the nyquist script ;nyquist plug-in ;version 1 ;type analyze ;categories "http://audacityteam.org/namespace#OnsetDetector" ;name "FFT ..." ;action "FFT tests..." ;info "Released under terms of the GNU General Public License version 2" ;control freq_basses2 "Filtre basses Hz" int "" 40 5 200 (setf s1 (if (arrayp s) (snd-add (aref s 0) (aref s 1)) s)) ; ajout des canaux gaucHe et droite dans un canal unifie, s1 (defun signal_basses () (force-srate 1000 (lp s1 60.0 ) ) ) ; Filtre des frequences inferieures à 60 Hz (setq l NIL ) (setq result-fft NIL) (setq result-fft (snd-fft (snd-copy (signal_basses) ) 128 0 NIL ) ) (do ( (n 0) (X 1.0) ) ( (> n 60) NIL ) (print (list n (aref result-fft (* 2 n ) ) ) ) (setq n ( + 1 n ) ) ) (setq label "toto") (setq l (cons (list 0.0 label) l)) l
#617599#10
Date:
2011-03-09 21:43:58 UTC
From:
To:
To reproduce the bug.

Use a 64 amd processor.

Install the nyquist script in ~/.audacity-files/plug-ins/fft.ny

If you cannot load a sound with bass such as bachata,
use the audacity menu: Générer/Sons/ Sinuosiadal 40Hz Amplitue 0,8
or nicer and more audible : Générer/Risset Drum/50 Hz Decay 2s

Launch the FFT script from Analyse/FFT ...
Choose to Validate or Debug

And look the 60 values displayed in the console.
Values about offset 40 or 50 are assumed to be greater
than others for a signal frequency around 40 or 50 Hz..

#617599#15
Date:
2011-03-10 22:25:21 UTC
From:
To:
Here is a patch that probably only work on amd 64 bits machines and compatibles as
it assumes sizeof long equals sizeof double.
--- ./lib-src/libnyquist/nyquist/nyqsrc/fft.c.original	2011-03-10 21:44:23.000000000 +0100
+++ ./lib-src/libnyquist/nyquist/nyqsrc/fft.c	2011-03-10 21:58:01.000000000 +0100
@@ -31,7 +31,7 @@
  * extra[2] -> INDEX (current sample index in current block)
  * extra[3] -> FILLCNT (how many samples in buffer)
  * extra[4] -> TERMCNT (how many samples until termination)
- * extra[5 .. 5+len-1] -> samples (stored as floats)
+ * extra[5 .. 5+len-1] -> samples (stored as doubles)
  * extra[5+len .. 5+2*len-1] -> array of samples to fft
  * extra[5+2*len ... 5+3*len-1] -> window coefficients
  *
@@ -56,7 +56,7 @@
 #define SAMPLES list->block->samples

 /* DEBUGGING PRINT FUNCTION:
-    void printfloats(char *caption, float *data, int len)
+    void printdoubles(char *caption, double *data, int len)
     {
         int i;
         printf("%s: ", caption);
@@ -67,7 +67,7 @@
     }
 */