summaryrefslogtreecommitdiff
path: root/doc/HOWTO.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/HOWTO.md')
-rw-r--r--doc/HOWTO.md59
1 files changed, 59 insertions, 0 deletions
diff --git a/doc/HOWTO.md b/doc/HOWTO.md
index e562679..5af3f05 100644
--- a/doc/HOWTO.md
+++ b/doc/HOWTO.md
@@ -6,6 +6,7 @@ This document describes the common commands for building and testing the project
* **Real-time Audio Synthesis**: The demo features a multi-voice synthesizer that generates audio in real-time from spectrograms.
* **Dynamic Sound Updates**: Spectrograms can be updated dynamically and safely during runtime for evolving soundscapes.
+* **Unified Audio Engine**: The `AudioEngine` class manages audio subsystem initialization, ensuring correct setup order and eliminating initialization fragility.
## Building
@@ -62,6 +63,64 @@ if you have the public ssh key authorized on the VPS, you can use
to clone the repo and work on it.
+## Audio System
+
+### AudioEngine
+
+The audio subsystem uses `AudioEngine` to manage initialization and lifecycle. This ensures correct setup order and eliminates initialization fragility.
+
+**Usage in production code:**
+
+```cpp
+#include "audio/audio_engine.h"
+
+// Initialize audio backend (miniaudio)
+audio_init();
+
+// Initialize audio engine (manages synth + tracker)
+static AudioEngine g_audio_engine;
+g_audio_engine.init();
+
+// In main loop: update with music time
+g_audio_engine.update(music_time);
+
+// Cleanup
+g_audio_engine.shutdown();
+audio_shutdown();
+```
+
+**What to use AudioEngine for:**
+- Initialization: `engine.init()` replaces separate `synth_init()` + `tracker_init()` calls
+- Updates: `engine.update(music_time)` replaces `tracker_update()`
+- Cleanup: `engine.shutdown()` ensures proper teardown
+- Seeking: `engine.seek(time)` for timeline navigation (debug builds only)
+
+**Direct synth API usage:**
+For performance-critical or low-level operations, direct synth API calls are valid:
+- `synth_register_spectrogram()` - Register audio samples
+- `synth_trigger_voice()` - Trigger sound playback
+- `synth_get_output_peak()` - Get audio peak for visualization
+- `synth_render()` - Low-level audio rendering
+
+**Testing:**
+Tests should use `AudioEngine` for initialization:
+
+```cpp
+#include "audio/audio_engine.h"
+
+void test_example() {
+ AudioEngine engine;
+ engine.init();
+
+ // Test code here
+ engine.update(1.0f);
+
+ engine.shutdown();
+}
+```
+
+For low-level synth-only tests, you can still call `synth_init()` directly.
+
## Debugging
### Seeking / Fast-Forward