summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-06 22:07:00 +0100
committerskal <pascal.massimino@gmail.com>2026-02-06 22:07:00 +0100
commitb60797c157717bafd834a4b7bc58120b95dffe46 (patch)
treefd9bf5033207316074737b8c39066712b530518f /src
parent02beca9eaddbc3bf60e121b1932d2eb4a41221b8 (diff)
clean up main.cc
Diffstat (limited to 'src')
-rw-r--r--src/main.cc78
1 files changed, 10 insertions, 68 deletions
diff --git a/src/main.cc b/src/main.cc
index 02a59c5..978a34e 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -21,35 +21,6 @@
#include <cstdlib>
#include <cstring>
-#define SPEC_FRAMES 16
-
-static float* g_spec_buffer_a[SPEC_FRAMES * DCT_SIZE] = {0};
-static float* g_spec_buffer_b[SPEC_FRAMES * DCT_SIZE] = {0};
-
-// Global storage for the melody to ensure it persists
-// Global storage for the melody to ensure it persists
-// std::vector<float> g_melody_data; // Tracker now handles melody generation
-
-// int generate_melody() { ... } // Replaced by tracker
-
-float* generate_tone(float* buffer, float freq) {
- if (buffer == nullptr) {
- buffer = (float*)calloc(SPEC_FRAMES * DCT_SIZE, sizeof(float));
- } else {
- memset(buffer, 0, SPEC_FRAMES * DCT_SIZE * sizeof(float));
- }
- for (int frame = 0; frame < SPEC_FRAMES; ++frame) {
- float* spec_frame = buffer + frame * DCT_SIZE;
- float amplitude = 1000. * powf(1.0f - (float)frame / SPEC_FRAMES, 2.0f);
-
- int bin = (int)(freq / (32000.0f / 2.0f) * DCT_SIZE);
- if (bin > 0 && bin < DCT_SIZE) {
- spec_frame[bin] = amplitude;
- }
- }
- return buffer;
-}
-
int main(int argc, char** argv) {
PlatformState platform_state;
bool fullscreen_enabled = false;
@@ -109,12 +80,6 @@ int main(int argc, char** argv) {
static AudioEngine g_audio_engine;
g_audio_engine.init();
- // Still keep the dynamic tone for bass (can be integrated into tracker too)
- const float* g_spec_buffer_a = generate_tone(nullptr, 110.0f); // A2
- const float* g_spec_buffer_b = generate_tone(nullptr, 110.0f);
- const Spectrogram bass_spec = {g_spec_buffer_a, g_spec_buffer_b, SPEC_FRAMES};
- int bass_id = synth_register_spectrogram(&bass_spec);
-
// Generate and play melody (replaced by tracker)
// int melody_id = generate_melody();
// synth_trigger_voice(melody_id, 0.6f, 0.0f);
@@ -124,10 +89,7 @@ int main(int argc, char** argv) {
static float g_tempo_scale = 1.0f; // 1.0 = normal speed
static double g_last_physical_time = 0.0;
- double last_beat_time = 0.0;
- int beat_count = 0;
-
- auto update_game_logic = [&](double t) {
+ auto fill_audio_buffer = [&](double t) {
// Variable tempo system - acceleration phases for demo effect
// Phase 1 (0-5s): Steady 1.0x
// Phase 2 (5-10s): Steady 1.0x
@@ -165,26 +127,6 @@ int main(int argc, char** argv) {
g_last_physical_time = t;
g_music_time += dt * g_tempo_scale;
- if (t - last_beat_time > (60.0f / g_tracker_score.bpm) / 2.0) { // 8th notes
- last_beat_time = t; // Sync to t
-
- const int step = beat_count % 16;
-
- /*
- // Bass pattern
- if (step % 4 == 0) {
- float* back_buffer = synth_begin_update(bass_id);
- if (back_buffer) {
- float bass_freq = (step < 8) ? 110.0f : 164.82f; // A3 then E3
- generate_tone(back_buffer, bass_freq);
- synth_commit_update(bass_id);
- }
- synth_trigger_voice(bass_id, 0.9f, 1.2f);
- }
- */
- ++beat_count;
- }
-
// Pass music_time (not physical time) to tracker
g_audio_engine.update(g_music_time);
@@ -203,7 +145,7 @@ int main(int argc, char** argv) {
// We step at ~60hz
const double step = 1.0 / 60.0;
for (double t = 0.0; t < seek_time; t += step) {
- update_game_logic(t);
+ fill_audio_buffer(t);
audio_render_silent((float)step);
}
@@ -246,7 +188,7 @@ int main(int argc, char** argv) {
gpu_resize(last_width, last_height);
}
- double current_time = platform_state.time + seek_time; // Offset logic time
+ const double current_time = platform_state.time + seek_time; // Offset logic time
// Auto-exit when demo finishes (if duration is specified)
if (demo_duration > 0.0f && current_time >= demo_duration) {
@@ -256,18 +198,18 @@ int main(int argc, char** argv) {
break;
}
- update_game_logic(current_time);
+ fill_audio_buffer(current_time);
- float aspect_ratio = platform_state.aspect_ratio;
+ const float aspect_ratio = platform_state.aspect_ratio;
// Adjusted multiplier for visuals (preventing constant 1.0 saturation)
- float raw_peak = synth_get_output_peak();
- float visual_peak = fminf(raw_peak * 8.0f, 1.0f);
+ const float raw_peak = synth_get_output_peak();
+ const float visual_peak = fminf(raw_peak * 8.0f, 1.0f);
// Calculate beat information for synchronization
- float beat_time = (float)current_time * g_tracker_score.bpm / 60.0f;
- int beat_number = (int)beat_time;
- float beat = fmodf(beat_time, 1.0f); // Fractional part (0.0 to 1.0)
+ const float beat_time = (float)current_time * g_tracker_score.bpm / 60.0f;
+ const int beat_number = (int)beat_time;
+ const float beat = fmodf(beat_time, 1.0f); // Fractional part (0.0 to 1.0)
#if !defined(STRIP_ALL)
// Print beat/time info periodically for identifying sync points