diff options
Diffstat (limited to 'src/audio/synth.cc')
| -rw-r--r-- | src/audio/synth.cc | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/audio/synth.cc b/src/audio/synth.cc index a4f3b7a..8380301 100644 --- a/src/audio/synth.cc +++ b/src/audio/synth.cc @@ -1,8 +1,17 @@ +// This file is part of the 64k demo project. +// It implements the multi-voice additive synthesis engine. +// Supports real-time spectrogram updates and peak detection. + #include "synth.h" +#include "audio/dct.h" #include "audio/window.h" #include <atomic> +#include <math.h> #include <string.h> // For memset +// Declarations for DCT functions (could also be in dct.h) +void idct_512(const float *input, float *output); + struct Voice { bool active; int spectrogram_id; @@ -26,8 +35,7 @@ static struct { } g_synth_data; static Voice g_voices[MAX_VOICES]; -static volatile float g_current_output_peak = - 0.0f; // Global peak for visualization +static volatile float g_current_output_peak = 0.0f; // Global peak for visualization void synth_init() { memset(&g_synth_data, 0, sizeof(g_synth_data)); @@ -67,9 +75,11 @@ float *synth_begin_update(int spectrogram_id) { g_synth_data.active_spectrogram_data[spectrogram_id]; if (active_ptr == g_synth_data.spectrograms[spectrogram_id].spectral_data_a) { - return g_synth_data.spectrograms[spectrogram_id].spectral_data_b; + return const_cast<float *>( + g_synth_data.spectrograms[spectrogram_id].spectral_data_b); } else { - return g_synth_data.spectrograms[spectrogram_id].spectral_data_a; + return const_cast<float *>( + g_synth_data.spectrograms[spectrogram_id].spectral_data_a); } } @@ -173,8 +183,9 @@ void synth_render(float *output_buffer, int num_frames) { output_buffer[i * 2 + 1] = right_sample; // Update the peak with the new max (attack) - g_current_output_peak = fmaxf( - g_current_output_peak, fmaxf(fabsf(left_sample), fabsf(right_sample))); + g_current_output_peak = + fmaxf(g_current_output_peak, + fmaxf(fabsf(left_sample), fabsf(right_sample))); } } @@ -188,6 +199,4 @@ int synth_get_active_voice_count() { return count; } -float synth_get_output_peak() { - return g_current_output_peak; -} +float synth_get_output_peak() { return g_current_output_peak; } |
