diff options
Diffstat (limited to 'src/main.cc')
| -rw-r--r-- | src/main.cc | 148 |
1 files changed, 47 insertions, 101 deletions
diff --git a/src/main.cc b/src/main.cc index 842c174..55bb4a0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -6,6 +6,7 @@ #include "audio/audio.h" #include "audio/gen.h" #include "audio/synth.h" +#include "audio/tracker.h" #include "generated/assets.h" // Include generated asset header #include "gpu/gpu.h" #include "platform.h" @@ -16,8 +17,6 @@ #include <string.h> #include <vector> -#define DEMO_BPM 128.0f -#define SECONDS_PER_BEAT (60.0f / DEMO_BPM) #define SPEC_FRAMES 16 struct SpecHeader { @@ -48,68 +47,10 @@ 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 -std::vector<float> g_melody_data; - -int generate_melody() { - g_melody_data.clear(); - int melody_frames = 0; - - // Simple C Minor pentatonic-ish sequence - float notes[] = {261.63f, 311.13f, 349.23f, 392.00f, 466.16f, 523.25f}; - int num_notes = 6; - - // 128 beats at 128 BPM = 60 seconds - // Generate a random sequence - srand(12345); // Fixed seed for reproducibility - - for (int i = 0; i < 128; ++i) { - if (i % 4 == 0) - continue; // Rest on beat 1 of every bar - - NoteParams params = {}; - params.base_freq = notes[rand() % num_notes]; - if (rand() % 4 == 0) - params.base_freq *= 2.0f; // Occasional octave up - - params.duration_sec = (rand() % 2 == 0) ? 0.2f : 0.4f; - params.amplitude = 0.4f; - params.attack_sec = 0.05f; - params.decay_sec = 0.1f; - params.vibrato_rate = 6.0f; - params.vibrato_depth = 1.5f; - params.num_harmonics = 4; - params.harmonic_decay = 0.6f; - params.pitch_randomness = 0.5f; - params.amp_randomness = 0.05f; - - int note_frames = 0; - std::vector<float> note_data = - generate_note_spectrogram(params, ¬e_frames); - - // Apply some post-processing for texture - apply_spectral_noise(note_data, note_frames, 0.2f); // Add grit - if (i % 2 == 0) { - apply_spectral_comb(note_data, note_frames, 10.0f, - 0.8f); // Phaser-like effect - } - - // Calculate offset in frames - // i is the beat index (quarter notes) - // 1 beat = 60 / 128 seconds = 0.46875 sec - float beat_time = i * SECONDS_PER_BEAT; - int frame_offset = (int)(beat_time * 32000.0f / DCT_SIZE); - - paste_spectrogram(g_melody_data, &melody_frames, note_data, note_frames, - frame_offset); - } - - Spectrogram spec; - spec.spectral_data_a = g_melody_data.data(); - spec.spectral_data_b = g_melody_data.data(); - spec.num_frames = melody_frames; +// Global storage for the melody to ensure it persists +// std::vector<float> g_melody_data; // Tracker now handles melody generation - return synth_register_spectrogram(&spec); -} +// int generate_melody() { ... } // Replaced by tracker float* generate_tone(float* buffer, float freq) { if (buffer == nullptr) { @@ -163,59 +104,62 @@ int main(int argc, char** argv) { platform_init(&platform_state, fullscreen_enabled, width_ptr, height_ptr); gpu_init(&platform_state); audio_init(); + synth_init(); + tracker_init(); - // Register drum assets - int kick_id = register_spec_asset(AssetId::ASSET_KICK_1); - int snare_id = register_spec_asset(AssetId::ASSET_SNARE_1); - int hihat_id = register_spec_asset(AssetId::ASSET_HIHAT_1); + // Register drum assets (if still needed, can be moved to tracker samples) + // int kick_id = register_spec_asset(AssetId::ASSET_KICK_1); + // int snare_id = register_spec_asset(AssetId::ASSET_SNARE_1); + // int hihat_id = register_spec_asset(AssetId::ASSET_HIHAT_1); - // Still keep the dynamic tone for bass + // 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 - int melody_id = generate_melody(); - synth_trigger_voice(melody_id, 0.6f, 0.0f); + // Generate and play melody (replaced by tracker) + // int melody_id = generate_melody(); + // synth_trigger_voice(melody_id, 0.6f, 0.0f); - double last_beat_time = 0.0; - int beat_count = 0; + // double last_beat_time = 0.0; + // int beat_count = 0; auto update_game_logic = [&](double t) { - if (t - last_beat_time > SECONDS_PER_BEAT / 2.0) { // 8th notes - last_beat_time = t; // Sync to t + // if (t - last_beat_time > SECONDS_PER_BEAT / 2.0) { // 8th notes + // last_beat_time = t; // Sync to t - const int step = beat_count % 16; + // const int step = beat_count % 16; - // Kick on 1, 9, 11, 14... - if (step == 0 || step == 8 || step == 10 || step == 13) { - synth_trigger_voice(kick_id, 1.0f, 0.0f); - } + // // Kick on 1, 9, 11, 14... + // if (step == 0 || step == 8 || step == 10 || step == 13) { + // synth_trigger_voice(kick_id, 1.0f, 0.0f); + // } - // Snare on 4, 12 - if (step == 4 || step == 12) { - synth_trigger_voice(snare_id, 0.8f, step & 8 ? -1.0f : 1.0f); - } + // // Snare on 4, 12 + // if (step == 4 || step == 12) { + // synth_trigger_voice(snare_id, 0.8f, step & 8 ? -1.0f : 1.0f); + // } - // Hihat on every offbeat - if (step % 2 == 1) { - synth_trigger_voice(hihat_id, 0.5f, 0.3f); - } + // // Hihat on every offbeat + // if (step % 2 == 1) { + // synth_trigger_voice(hihat_id, 0.5f, 0.3f); + // } - // 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); - } + // // 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; - } + // ++beat_count; + // } + tracker_update((float)t); }; #if !defined(STRIP_ALL) @@ -261,7 +205,9 @@ int main(int argc, char** argv) { float raw_peak = synth_get_output_peak(); float visual_peak = fminf(raw_peak * 8.0f, 1.0f); - float beat = fmodf((float)current_time * DEMO_BPM / 60.0f, 1.0f); + // float beat = fmodf((float)current_time * DEMO_BPM / 60.0f, 1.0f); // Use + // tracker BPM + float beat = fmodf((float)current_time * g_tracker_score.bpm / 60.0f, 1.0f); gpu_draw(visual_peak, aspect_ratio, (float)current_time, beat); audio_update(); } |
