summaryrefslogtreecommitdiff
path: root/src/audio/synth.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-01-28 09:31:13 +0100
committerskal <pascal.massimino@gmail.com>2026-01-28 09:31:13 +0100
commit302d883f34864bc66a5e04532ae27d7e89fd94e8 (patch)
tree8f813865d5dc5b70ee8bf9ee4866546116859825 /src/audio/synth.cc
parentf804dcb9740540b3735628ebf8c006235cc56fca (diff)
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.
Diffstat (limited to 'src/audio/synth.cc')
-rw-r--r--src/audio/synth.cc27
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; }