diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-05 20:09:34 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-05 20:09:34 +0100 |
| commit | 3b201f2cb4d5917bb2fd76051c073b71ad6b3b27 (patch) | |
| tree | 912447a2b4231373e60603bd93ff86499a0d2d91 /src | |
| parent | de9c11d44788a9039ba1ef70f2d255898df37016 (diff) | |
feat(audio): Complete Phase 3 - Migrate main.cc to AudioEngine (Task #56)
Migrated production code (main.cc) to use AudioEngine instead of directly
calling synth_init() and tracker_init(), eliminating initialization order
dependencies in the demo entry point.
Changes:
- Added #include "audio/audio_engine.h" to main.cc
- Replaced synth_init() + tracker_init() with AudioEngine::init()
- Replaced tracker_update(g_music_time) with g_audio_engine.update(g_music_time)
- Preserved direct synth calls (synth_register_spectrogram, synth_get_output_peak)
as these are valid API usage
Results:
- All 20 tests pass (100% pass rate)
- Demo runs successfully without crashes
- Initialization order fragility eliminated in production code
- Test suite time: 8.13s (unchanged)
Known Technical Debt (deferred to Phase 4):
- audio_init() still calls synth_init() internally for backwards compatibility
- This causes double initialization (harmless but fragile)
- Some tests rely on this behavior
- Will be cleaned up in Phase 4 with other compatibility shims
handoff(Claude): Completed Task #56 Phase 3 - production code now uses AudioEngine.
Phase 4 (Cleanup) remains: remove old global functions, update remaining tests,
remove backwards compatibility shims, update documentation.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/main.cc b/src/main.cc index 42adf6b..4542824 100644 --- a/src/main.cc +++ b/src/main.cc @@ -4,6 +4,7 @@ #include "3d/renderer.h" #include "audio/audio.h" +#include "audio/audio_engine.h" #include "audio/gen.h" #include "audio/synth.h" #include "audio/tracker.h" @@ -101,9 +102,12 @@ int main(int argc, char** argv) { } #endif + // Initialize audio backend (miniaudio device) audio_init(); - synth_init(); - tracker_init(); + + // Initialize audio engine (synth + tracker unified management) + 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 @@ -182,7 +186,7 @@ int main(int argc, char** argv) { } // Pass music_time (not physical time) to tracker - tracker_update(g_music_time); + g_audio_engine.update(g_music_time); // Fill ring buffer with upcoming audio (look-ahead rendering) // CRITICAL: Scale dt by tempo to render enough audio during acceleration/deceleration @@ -209,7 +213,7 @@ int main(int argc, char** argv) { // PRE-FILL: Fill ring buffer with initial 200ms before starting audio device // This prevents underrun on first callback - tracker_update(g_music_time); + g_audio_engine.update(g_music_time); audio_render_ahead(g_music_time, 1.0f / 60.0f); // Fill buffer with lookahead // Start audio (or render to WAV file) |
