diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-07 14:00:23 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-07 14:00:23 +0100 |
| commit | a6a7bf0440dbabdc6c994c0fb21a8ac31c27be07 (patch) | |
| tree | 26663d3d65b110fca618d6fa33c83f7a8d1e362a /src/audio/audio.cc | |
| parent | da1d4e10731789191d8a23e60c3dd35217e6bdb0 (diff) | |
feat(audio): Add SilentBackend, fix peak measurement, reorganize backends
## Critical Fixes
**Peak Measurement Timing:**
- Fixed 400ms audio-visual desync by measuring peak at playback time
- Added get_realtime_peak() to AudioBackend interface
- Implemented real-time measurement in MiniaudioBackend audio callback
- Updated main.cc and test_demo.cc to use audio_get_realtime_peak()
**Peak Decay Rate:**
- Fixed slow decay (0.95 → 0.7 per callback)
- Old: 5.76 seconds to fade to 10% (constant flashing in test_demo)
- New: 1.15 seconds to fade to 10% (proper visual sync)
## New Features
**SilentBackend:**
- Test-only backend for testing audio.cc without hardware
- Controllable peak for testing edge cases
- Tracks frames rendered and voice triggers
- Added 7 comprehensive tests covering:
- Lifecycle (init/start/shutdown)
- Peak control and tracking
- Playback time and buffer management
- Integration with AudioEngine
## Refactoring
**Backend Organization:**
- Created src/audio/backend/ directory
- Moved all backend implementations to subdirectory
- Updated include paths and CMakeLists.txt
- Cleaner codebase structure
**Code Cleanup:**
- Removed unused register_spec_asset() function
- Added deprecation note to synth_get_output_peak()
## Testing
- All 28 tests passing (100%)
- New test: test_silent_backend
- Improved audio.cc test coverage significantly
## Documentation
- Created PEAK_FIX_SUMMARY.md with technical details
- Created TASKS_SUMMARY.md with complete task report
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/audio/audio.cc')
| -rw-r--r-- | src/audio/audio.cc | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/src/audio/audio.cc b/src/audio/audio.cc index b00d416..67345cf 100644 --- a/src/audio/audio.cc +++ b/src/audio/audio.cc @@ -4,7 +4,7 @@ #include "audio.h" #include "audio_backend.h" -#include "miniaudio_backend.h" +#include "backend/miniaudio_backend.h" #include "ring_buffer.h" #include "synth.h" #include "util/asset_manager.h" @@ -40,23 +40,6 @@ AudioBackend* audio_get_backend() { } #endif /* !defined(STRIP_ALL) */ -int register_spec_asset(AssetId id) { - size_t size; - const uint8_t* data = GetAsset(id, &size); - if (!data || size < sizeof(SpecHeader)) - return -1; - - const SpecHeader* header = (const SpecHeader*)data; - const float* spectral_data = (const float*)(data + sizeof(SpecHeader)); - - Spectrogram spec; - spec.spectral_data_a = spectral_data; - spec.spectral_data_b = spectral_data; // No double-buffer for static assets - spec.num_frames = header->num_frames; - - return synth_register_spectrogram(&spec); -} - void audio_init() { // Note: synth_init() must be called separately before using audio system. // In production code, use AudioEngine::init() which manages initialization @@ -189,6 +172,13 @@ float audio_get_playback_time() { (RING_BUFFER_SAMPLE_RATE * RING_BUFFER_CHANNELS); } +float audio_get_realtime_peak() { + if (g_audio_backend == nullptr) { + return 0.0f; + } + return g_audio_backend->get_realtime_peak(); +} + // Expose ring buffer for backends AudioRingBuffer* audio_get_ring_buffer() { return &g_ring_buffer; |
