blob: 2d52858ff1c354c7cac96efa8b8afc975516bf3d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// This file is part of the 64k demo project.
// It implements a silent test backend for testing audio.cc without hardware.
// Useful for achieving high test coverage and triggering edge cases.
#pragma once
#if !defined(STRIP_ALL)
#include "../audio_backend.h"
#include <atomic>
// Silent backend for testing - no audio output, pure inspection
// Allows testing audio.cc logic (buffer management, playback time tracking)
// without requiring audio hardware or miniaudio
class SilentBackend : public AudioBackend {
public:
SilentBackend();
~SilentBackend() override;
// AudioBackend interface
void init() override;
void start() override;
void shutdown() override;
float get_realtime_peak() override;
// Test inspection interface
bool is_initialized() const {
return initialized_;
}
bool is_started() const {
return started_;
}
int get_frames_rendered() const {
return frames_rendered_.load();
}
int get_voice_trigger_count() const {
return voice_trigger_count_.load();
}
// Manual control for testing edge cases
void set_peak(float peak) {
test_peak_ = peak;
}
void reset_stats() {
frames_rendered_ = 0;
voice_trigger_count_ = 0;
}
// Event hooks (inherited from AudioBackend)
void on_voice_triggered(float timestamp, int spectrogram_id, float volume,
float pan) override;
void on_frames_rendered(int num_frames) override;
private:
bool initialized_;
bool started_;
std::atomic<int> frames_rendered_;
std::atomic<int> voice_trigger_count_;
float test_peak_; // Controllable peak for testing
};
#endif /* !defined(STRIP_ALL) */
|