diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-04 13:10:57 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-04 13:10:57 +0100 |
| commit | bb49daa17cfbb244a239b620372eaf27ed252b0f (patch) | |
| tree | d6272414920748a7b5744c896a8bc79b3f1a32aa /src/audio | |
| parent | c4888bea71326f7a69e8214af0d9c2a62a60b887 (diff) | |
feat(audio): Implement mock audio backend for testing (Task #51.2)
Created MockAudioBackend for deterministic audio event recording and
timing verification. Enables robust tracker synchronization testing.
Changes:
- Created VoiceTriggerEvent structure (timestamp, spec_id, volume, pan)
- Implemented MockAudioBackend with event recording capabilities
- Added time tracking: manual (advance_time) and automatic (on_frames_rendered)
- Created test_mock_backend.cc with 6 comprehensive test scenarios
- Verified synth integration and audio_render_silent compatibility
- Added to CMake test builds
All test infrastructure guarded by #if !defined(STRIP_ALL). Zero size
impact on production build. All 14 tests pass.
handoff(Claude): Task #51.2 complete, mock backend ready for tracker tests
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/audio')
| -rw-r--r-- | src/audio/mock_audio_backend.cc | 45 | ||||
| -rw-r--r-- | src/audio/mock_audio_backend.h | 56 |
2 files changed, 101 insertions, 0 deletions
diff --git a/src/audio/mock_audio_backend.cc b/src/audio/mock_audio_backend.cc new file mode 100644 index 0000000..3f5a57a --- /dev/null +++ b/src/audio/mock_audio_backend.cc @@ -0,0 +1,45 @@ +// This file is part of the 64k demo project. +// It implements the mock audio backend for testing. +// Records voice trigger events with precise timestamps. + +#include "mock_audio_backend.h" + +#if !defined(STRIP_ALL) + +MockAudioBackend::MockAudioBackend() : current_time_sec_(0.0f) { +} + +MockAudioBackend::~MockAudioBackend() { +} + +void MockAudioBackend::init() { + // No-op for mock backend +} + +void MockAudioBackend::start() { + // No-op for mock backend +} + +void MockAudioBackend::shutdown() { + // No-op for mock backend +} + +void MockAudioBackend::on_voice_triggered(float timestamp, int spectrogram_id, + float volume, float pan) { + // Record the event with the timestamp provided by synth + VoiceTriggerEvent event; + event.timestamp_sec = timestamp; + event.spectrogram_id = spectrogram_id; + event.volume = volume; + event.pan = pan; + recorded_events_.push_back(event); +} + +void MockAudioBackend::on_frames_rendered(int num_frames) { + // Update internal time based on frames rendered + // This is called by audio_render_silent() for seek/fast-forward simulation + const float delta_sec = (float)num_frames / (float)kSampleRate; + current_time_sec_ += delta_sec; +} + +#endif /* !defined(STRIP_ALL) */ diff --git a/src/audio/mock_audio_backend.h b/src/audio/mock_audio_backend.h new file mode 100644 index 0000000..963d9cb --- /dev/null +++ b/src/audio/mock_audio_backend.h @@ -0,0 +1,56 @@ +// 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 <vector> + +// 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; + + // 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<VoiceTriggerEvent>& 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<VoiceTriggerEvent> recorded_events_; + float current_time_sec_; +}; + +#endif /* !defined(STRIP_ALL) */ |
