From c7e06404013c8907ee3bb90865918b4aa013f61a Mon Sep 17 00:00:00 2001
From: Patrick Moessler <pub@asaril.de>
Date: Thu, 20 Mar 2025 22:05:08 +0100
Subject: [PATCH] fix fft window init

---
 src/audio.rs | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/audio.rs b/src/audio.rs
index 9b90ebf..76d771c 100644
--- a/src/audio.rs
+++ b/src/audio.rs
@@ -11,7 +11,6 @@ pub type AudioBuffer = [i32; AUDIO_SAMPLES_PER_BUF];
 pub type DspBuffer = [f32; AUDIO_SAMPLES_PER_BUF];
 
 static FFT_WINDOW_CELL: StaticCell<DspBuffer> = StaticCell::new();
-static FFT_WINDOW: Option<&DspBuffer> = None;
 
 #[derive(Clone, Copy, Default)]
 pub struct AudioStats {
@@ -22,6 +21,7 @@ pub struct AudioStats {
 
 pub struct AudioProcessor {
     pub stats: AudioStats,
+    window: &'static DspBuffer,
 }
 
 impl Default for AudioProcessor {
@@ -32,14 +32,13 @@ impl Default for AudioProcessor {
             esp_dsp::dsps_wind_hann_f32(buf.as_mut_ptr(), AUDIO_SAMPLES_PER_BUF as i32);
         }
 
-        FFT_WINDOW_CELL.init(buf);
-
         AudioProcessor {
             stats: AudioStats {
                 floating_max: 0i32,
                 current_powers: [0f32; AUDIO_BANDS],
                 avg_powers: [0f32; AUDIO_BANDS],
             },
+            window: FFT_WINDOW_CELL.init(buf),
         }
     }
 }
@@ -76,7 +75,7 @@ impl AudioProcessor {
         unsafe {
             esp_nofail!(esp_dsp::dsps_mul_f32_ae32(
                 fft.as_ptr(),
-                FFT_WINDOW.expect("windows not initialized!").as_ptr(),
+                self.window.as_ptr(),
                 fft.as_mut_ptr(),
                 AUDIO_SAMPLES_PER_BUF as i32,
                 1,