From a6a7bf0440dbabdc6c994c0fb21a8ac31c27be07 Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 7 Feb 2026 14:00:23 +0100 Subject: feat(audio): Add SilentBackend, fix peak measurement, reorganize backends MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 --- src/audio/backend/mock_audio_backend.h | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/audio/backend/mock_audio_backend.h (limited to 'src/audio/backend/mock_audio_backend.h') diff --git a/src/audio/backend/mock_audio_backend.h b/src/audio/backend/mock_audio_backend.h new file mode 100644 index 0000000..55e89c5 --- /dev/null +++ b/src/audio/backend/mock_audio_backend.h @@ -0,0 +1,65 @@ +// This file is part of the 64k demo project. +// It implements a test-only mock audio backend for event recording. +// Used for tracker timing verification and audio synchronization tests. + +#pragma once + +#if !defined(STRIP_ALL) + +#include "../audio_backend.h" +#include + +// Event structure for recorded voice triggers +struct VoiceTriggerEvent { + float timestamp_sec; + int spectrogram_id; + float volume; + float pan; +}; + +// Mock audio backend that records all voice trigger events +// Used for testing tracker timing and synchronization +class MockAudioBackend : public AudioBackend { + public: + MockAudioBackend(); + ~MockAudioBackend() override; + + // AudioBackend interface (no-ops for mock) + void init() override; + void start() override; + void shutdown() override; + float get_realtime_peak() override; + + // Event recording hooks + void on_voice_triggered(float timestamp, int spectrogram_id, float volume, + float pan) override; + void on_frames_rendered(int num_frames) override; + + // Test interface methods + const std::vector& get_events() const { + return recorded_events_; + } + void clear_events() { + recorded_events_.clear(); + } + + // Manual time control for deterministic testing + void advance_time(float delta_sec) { + current_time_sec_ += delta_sec; + } + void set_time(float time_sec) { + current_time_sec_ = time_sec; + } + float get_current_time() const { + return current_time_sec_; + } + + // Sample rate used for frame-to-time conversion + static const int kSampleRate = 32000; + + private: + std::vector recorded_events_; + float current_time_sec_; +}; + +#endif /* !defined(STRIP_ALL) */ -- cgit v1.2.3