Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
SteamAudioBackend.h
1#pragma once
2
3#include <functional>
4#include <memory>
5
6#include <glm/glm.hpp>
7
8namespace Engine::Core {
9
24 public:
25 using SourceId = std::uint32_t;
26 static constexpr SourceId INVALID_SOURCE = 0;
27
32 using ReadFramesCallback = std::function<std::uint64_t(float* pFramesOut, std::uint64_t frameCount)>;
33
38 using DestroyCallback = std::function<void()>;
39
42
45
52 bool init(std::uint32_t sampleRate, std::uint32_t frameSize);
53
58 bool init(std::uint32_t sampleRate, std::uint32_t frameSize, const char* sofaFilePath);
59
64 void shutdown();
65
67 [[nodiscard]] bool isInitialized() const { return initialized_; }
68
74 void setListener(const glm::vec3& position, const glm::quat& orientation);
75
87 std::uint32_t channels, const glm::vec3& position, float volume, bool loop);
88
90 void updateSourcePosition(SourceId source, const glm::vec3& position);
91
93 void updateSourceVolume(SourceId source, float volume);
94
99 [[nodiscard]] bool isSourceFinished(SourceId source) const;
100
105 void removeSource(SourceId source);
106
112 void render(float* pFramesOutInterleavedStereo, std::uint32_t frameCount);
113
114 private:
115 struct Impl;
116 std::unique_ptr<Impl> impl_;
117 bool initialized_ = false;
118 };
119
120} // namespace Engine::Core
bool init(std::uint32_t sampleRate, std::uint32_t frameSize)
Initialize Steam Audio with the built-in HRTF.
SourceId addSource(ReadFramesCallback readFrames, DestroyCallback onDestroy, std::uint32_t channels, const glm::vec3 &position, float volume, bool loop)
Register a spatialized source.
void shutdown()
Shut down Steam Audio and release all sources and effects. Must not run concurrently with render() (c...
void removeSource(SourceId source)
Release a source. The read backend is destroyed asynchronously on the audio thread; the source stops ...
static constexpr SourceId INVALID_SOURCE
bool isInitialized() const
Returns whether init() succeeded and shutdown() has not been called.
void setListener(const glm::vec3 &position, const glm::quat &orientation)
Set the listener pose (headset position and world orientation).
std::function< std::uint64_t(float *pFramesOut, std::uint64_t frameCount)> ReadFramesCallback
Reads interleaved PCM frames in the source's native channel layout.
SteamAudioBackend & operator=(const SteamAudioBackend &)=delete
SteamAudioBackend(const SteamAudioBackend &)=delete
void updateSourcePosition(SourceId source, const glm::vec3 &position)
Move an existing source to a new world position.
bool isSourceFinished(SourceId source) const
Check whether a source reached the end of its audio.
void updateSourceVolume(SourceId source, float volume)
Change the base gain of an existing source.
bool init(std::uint32_t sampleRate, std::uint32_t frameSize, const char *sofaFilePath)
Initialize Steam Audio with an individualized HRTF from a SOFA file.
std::function< void()> DestroyCallback
Frees the source PCM backend (e.g. a miniaudio buffer). Invoked on the audio thread when the source i...
void render(float *pFramesOutInterleavedStereo, std::uint32_t frameCount)
Accumulate the spatialized mix into an interleaved stereo buffer.