From 302d883f34864bc66a5e04532ae27d7e89fd94e8 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 28 Jan 2026 09:31:13 +0100 Subject: style: Add 3-line descriptive headers to all source files This commit applies a new project-wide rule that every source file must begin with a concise 3-line comment header describing its purpose. - Updated CONTRIBUTING.md with the new rule. - Applied headers to all .cc and .h files in src/ and tools/. - Fixed various minor compilation errors and missing includes discovered during the header update process. --- src/audio/synth.cc | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/audio/synth.cc') 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 +#include #include // 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( + g_synth_data.spectrograms[spectrogram_id].spectral_data_b); } else { - return g_synth_data.spectrograms[spectrogram_id].spectral_data_a; + return const_cast( + 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; } -- cgit v1.2.3