summaryrefslogtreecommitdiff
path: root/src/audio/synth.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-01-28 00:41:07 +0100
committerskal <pascal.massimino@gmail.com>2026-01-28 00:41:07 +0100
commita7bcf5e9cd6884d010b5cec0146293a0515242fc (patch)
treebcc07dd93e19c7b429363c8cac1e9866762f6e6e /src/audio/synth.cc
parent9dcf94ab01269311b4e5d39be23c95560904c626 (diff)
feat: Implement fullscreen, keyboard controls, and pulsating heptagon
This commit fulfills tasks 1 and 2, and adds a synchronized visual effect. - **Fullscreen Mode**: Added '--fullscreen' command-line argument and dynamic toggling via 'F' key. - **Keyboard Controls**: Implemented 'Esc' to exit and 'F' to toggle fullscreen in 'src/platform.cc'. - **Synchronized Visuals**: Added a pulsating heptagon effect in 'src/gpu/gpu.cc' and 'src/gpu/shader.wgsl' that scales and changes color based on the real-time audio peak from the synth. - **Refactor**: Abstracted platform-specific WebGPU surface creation into 'src/platform.cc' to keep 'src/gpu/gpu.cc' cross-platform. - **Build System**: Corrected 'CMakeLists.txt' to properly link 'wgpu-native' and platform frameworks, and updated 'project_init.sh' to build the submodule. - **Documentation**: Updated 'HOWTO.md' and 'PROJECT_CONTEXT.md' with new features and decisions.
Diffstat (limited to 'src/audio/synth.cc')
-rw-r--r--src/audio/synth.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/audio/synth.cc b/src/audio/synth.cc
index 451fcdb..98c12d9 100644
--- a/src/audio/synth.cc
+++ b/src/audio/synth.cc
@@ -26,10 +26,12 @@ static struct {
} g_synth_data;
static Voice g_voices[MAX_VOICES];
+static float g_current_output_peak = 0.0f; // Global peak for visualization
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;
}
void synth_shutdown() {
@@ -123,6 +125,8 @@ void synth_render(float *output_buffer, int num_frames) {
float window[WINDOW_SIZE];
hamming_window_512(window);
+ float current_peak_in_frame = 0.0f;
+
for (int i = 0; i < num_frames; ++i) {
float left_sample = 0.0f;
float right_sample = 0.0f;
@@ -165,7 +169,11 @@ void synth_render(float *output_buffer, int num_frames) {
output_buffer[i * 2] = left_sample;
output_buffer[i * 2 + 1] = right_sample;
+
+ current_peak_in_frame =
+ fmaxf(current_peak_in_frame, fmaxf(fabsf(left_sample), fabsf(right_sample)));
}
+ g_current_output_peak = current_peak_in_frame;
}
int synth_get_active_voice_count() {
@@ -177,3 +185,5 @@ int synth_get_active_voice_count() {
}
return count;
}
+
+float synth_get_output_peak() { return g_current_output_peak; }