diff options
Diffstat (limited to 'src/audio')
| -rw-r--r-- | src/audio/synth.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/audio/synth.cc b/src/audio/synth.cc index e4f6c75..b9af771 100644 --- a/src/audio/synth.cc +++ b/src/audio/synth.cc @@ -7,6 +7,7 @@ #include "audio/window.h" #include <atomic> #include <math.h> +#include <stdio.h> // For printf #include <string.h> // For memset struct Voice { @@ -33,11 +34,14 @@ static struct { static Voice g_voices[MAX_VOICES]; static volatile float g_current_output_peak = 0.0f; // Global peak for visualization +static float g_hamming_window[WINDOW_SIZE]; // Static window for optimization void synth_init() { memset(&g_synth_data, 0, sizeof(g_synth_data)); memset(g_voices, 0, sizeof(g_voices)); g_current_output_peak = 0.0f; + // Initialize the Hamming window once + hamming_window_512(g_hamming_window); } void synth_shutdown() { @@ -130,8 +134,9 @@ void synth_trigger_voice(int spectrogram_id, float volume, float pan) { } void synth_render(float *output_buffer, int num_frames) { - float window[WINDOW_SIZE]; - hamming_window_512(window); + // Use the pre-calculated window + // float window[WINDOW_SIZE]; + // hamming_window_512(window); // Faster decay for more responsive visuals g_current_output_peak *= 0.90f; @@ -160,7 +165,7 @@ void synth_render(float *output_buffer, int num_frames) { float windowed_frame[DCT_SIZE]; for (int j = 0; j < DCT_SIZE; ++j) { - windowed_frame[j] = spectral_frame[j] * window[j]; + windowed_frame[j] = spectral_frame[j] * g_hamming_window[j]; // Use static window } idct_512(windowed_frame, v.time_domain_buffer); @@ -196,4 +201,6 @@ int synth_get_active_voice_count() { return count; } -float synth_get_output_peak() { return g_current_output_peak; }
\ No newline at end of file +float synth_get_output_peak() { + return g_current_output_peak; +}
\ No newline at end of file |
