ReXGlue SDK
Loading...
Searching...
No Matches
audio_system.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <span>
14#include <string>
15
17#include <rex/platform.h>
18#include <rex/module.h>
19#include <rex/result.h>
20#include <rex/setting.h>
22#include <rex/types.h>
23#include <rex/utility.h>
24
25namespace rex::apu {
26
27enum class AudioStreamID : u32 {};
28
30using AudioFrame = std::span<const f32, kAudioFrameSamples>;
31
32struct AudioStats {
33 u32 open_streams = 0;
34 u32 queued_frames = 0;
35 u64 underruns = 0;
36 u32 latency_us = 0;
37};
38
39class REX_APU_API AudioSettings final : public SettingOwner {
40 public:
41 AudioSettings();
42
43 REX_SETTING(std::string, driver, "sdl3",
44 "Audio driver, none for silence in an app that does not require audio", kStartupOnly);
45 REX_SETTING(bool, mute, false, "Mute the audio output");
46 REX_SETTING(bool, mute_unfocused, false, "Mute while the window does not have focus");
47 REX_SETTING(f64, gain, 1.0, "Output gain, 1 is unity", Range{0.0, 4.0});
48 REX_SETTING(f64, center, 1.0, "Center level on a surround device", Range{0.0, 2.0});
49 REX_SETTING(f64, surround, 1.0, "Surround level on a surround device", Range{0.0, 2.0});
50 REX_SETTING(f64, lfe, 1.0, "LFE level on a surround device", Range{0.0, 2.0});
51 REX_SETTING(f64, peak_limit, 0.0, "Silence a stream that stays above this peak, 0 is off",
52 Range{0.0, 8.0});
53 REX_SETTING(u32, max_queued_frames, 8, "Frames a stream may queue", Range{4, 64}, kUntilLaunch);
54};
55
65 static constexpr u32 kMaxStreams = 8;
66
67 virtual AudioSettings& GetSettings() = 0;
68
75 [[nodiscard]] virtual Result<AudioStreamID> OpenStream(
76 MoveOnlyFunction<void()> on_frame_played) = 0;
77
81 virtual void CloseStream(AudioStreamID stream) = 0;
82
88 [[nodiscard]] virtual Result<void> Submit(AudioStreamID stream, AudioFrame frame) = 0;
89
94 virtual u32 GetOutputChannels() const = 0;
95
99 virtual AudioStats GetStats() const = 0;
100
102 virtual void SetFocused(bool focused) = 0;
103};
104
105} // namespace rex::apu
SettingOwner(std::string_view scope)
Definition audio_system.h:39
Definition audio_system.h:64
Interfaces, factory and module declaration.
#define REX_DECLARE_INTERFACE(Name, version)
Definition module.h:114
Definition app.h:41
std::span< const f32, kAudioFrameSamples > AudioFrame
Definition audio_system.h:30
typename detail::MoveOnlyFunctionFor< Signature >::type MoveOnlyFunction
Definition utility.h:254
std::expected< T, Error > Result
Definition result.h:98
Platform flags, packing macros and export markers.
#define REX_APU_API
Definition platform.h:211
Typed settings and the owners that declare them.
The registry of every registered setting.
Definition setting.h:78
Definition audio_system.h:32
u64 underruns
Definition audio_system.h:35
u32 latency_us
Definition audio_system.h:36
Integer types, byte order wrappers and size literals.
Move only function, const propagating pointer and scope guard.