From c4888bea71326f7a69e8214af0d9c2a62a60b887 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 4 Feb 2026 13:08:13 +0100 Subject: feat(audio): Implement audio backend abstraction (Task #51.1) Created interface-based audio backend system to enable testing without hardware. This is the foundation for robust tracker timing verification. Changes: - Created AudioBackend interface with init/start/shutdown methods - Added test-only hooks: on_voice_triggered() and on_frames_rendered() - Moved miniaudio implementation to MiniaudioBackend class - Refactored audio.cc to use backend abstraction with auto-fallback - Added time tracking to synth.cc (elapsed time from rendered frames) - Created test_audio_backend.cc to verify backend injection works - Fixed audio test linking to include util/procedural dependencies All test infrastructure guarded by #if !defined(STRIP_ALL) for zero size impact on final build. Production path unchanged, 100% backward compatible. All 13 tests pass. handoff(Claude): Task #51.1 complete, audio backend abstraction ready Co-Authored-By: Claude Sonnet 4.5 --- src/audio/audio_backend.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/audio/audio_backend.h (limited to 'src/audio/audio_backend.h') diff --git a/src/audio/audio_backend.h b/src/audio/audio_backend.h new file mode 100644 index 0000000..4a2b7fb --- /dev/null +++ b/src/audio/audio_backend.h @@ -0,0 +1,44 @@ +// This file is part of the 64k demo project. +// It defines the interface for audio backend implementations. +// Enables testing without hardware by abstracting audio output. + +#pragma once + +// AudioBackend interface for audio output abstraction +// Production uses MiniaudioBackend, tests use MockAudioBackend +class AudioBackend { + public: + virtual ~AudioBackend() {} + + // Initialize backend resources + virtual void init() = 0; + + // Start audio playback/recording + virtual void start() = 0; + + // Clean up backend resources + virtual void shutdown() = 0; + +#if !defined(STRIP_ALL) + // Hook called when a voice is triggered (test-only) + // timestamp: Time in seconds when voice was triggered + // spectrogram_id: ID of the spectrogram being played + // volume: Voice volume (0.0 - 1.0) + // pan: Pan position (-1.0 left, 0.0 center, 1.0 right) + virtual void on_voice_triggered(float timestamp, int spectrogram_id, + float volume, float pan) { + // Default implementation does nothing (production path) + (void)timestamp; + (void)spectrogram_id; + (void)volume; + (void)pan; + } + + // Hook called after rendering audio frames (test-only) + // num_frames: Number of frames rendered + virtual void on_frames_rendered(int num_frames) { + // Default implementation does nothing (production path) + (void)num_frames; + } +#endif /* !defined(STRIP_ALL) */ +}; -- cgit v1.2.3