summaryrefslogtreecommitdiff
path: root/src/audio
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-01-28 11:24:42 +0100
committerskal <pascal.massimino@gmail.com>2026-01-28 11:24:42 +0100
commita5fd304c9db6d6191a1ae2368bbe013f54c78aff (patch)
treebd0088562323943136fcf7cd4116111f7fbc9c38 /src/audio
parent895ebeb97eb5b00eed91089a2823a9979e5f31f6 (diff)
perf(synth): Optimize Hamming window generation
Moves the Hamming window initialization from synth_render to synth_init() to ensure it's generated only once, improving performance.
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/synth.cc15
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