10namespace Vkm::Engine {
17using VoiceId = uint32_t;
25inline constexpr size_t MAX_ACTIVE_VOICES = 128;
43 glm::vec3 position = {0.0f, 0.0f, 0.0f};
44 float minDistance = 1.0f;
45 float maxDistance = 50.0f;
54 float heardMinDistance()
const {
return std::isfinite(minDistance) ? std::max(0.0f, minDistance) : 0.0f; }
61 float heardMaxDistance()
const {
return std::isfinite(maxDistance) ? std::max(0.0f, maxDistance) : 0.0f; }
85 AudioDevice(
const AudioDevice& other) =
delete;
86 AudioDevice& operator=(
const AudioDevice& other) =
delete;
88 AudioDevice(AudioDevice && other) =
delete;
89 AudioDevice& operator=(AudioDevice && other) =
delete;
127 uint64_t
render(
float* frames, uint64_t frameCount);
265 void setListener(
const glm::vec3& position,
const glm::vec3& forward,
const glm::vec3& up);
284 bool isOpen() const noexcept {
return m_backend !=
nullptr; }
305 void reopenLostDevice();
308 std::unique_ptr<Backend> m_backend;
309 float m_masterVolume = 1.0f;
312 bool m_voiceBudgetSpent =
false;
uint64_t render(float *frames, uint64_t frameCount)
Pull mixed frames from an offline mixer into frames.
void updateVoice(VoiceId voice, const VoiceParams ¶ms)
Push a voice's parameters to the mixer; an unknown or finished voice is ignored.
size_t voiceCount() const
Number of voices the mixer currently holds.
void setListener(const glm::vec3 &position, const glm::vec3 &forward, const glm::vec3 &up)
Place the ear.
void setListenerActive(bool active)
Whether anything is listening.
void setMasterVolume(float volume)
Master gain applied to the whole mix.
void seekVoice(VoiceId voice, float seconds)
Move voice's cursor to seconds into its clip.
void reapFinishedVoices()
Release every voice that has played to its end, or been ramped out by stopVoice().
void resumeAllVoices()
Let every voice pauseAllVoices() is still holding play on.
void pauseVoice(VoiceId voice)
Hold voice at its cursor, silently, without ending it.
void pauseAllVoices()
Hold every voice that is sounding right now.
bool openOffline(uint32_t sampleRate, uint32_t channels)
Open the mixer with no device, to be pumped by render().
float masterVolume() const noexcept
The master gain the mix is running at, after setMasterVolume's sanitising.
Definition audio_device.h:291
void stopAllVoices()
Cut and release every voice at once, leaving the device open.
VoiceId play(const AudioClipAsset &clip, const VoiceParams ¶ms)
Start playing clip and return the voice driving it.
bool isVoiceActive(VoiceId voice) const
Whether voice is still there with audio left to play.
bool open()
Open the default playback device and start its mixer thread.
void close()
Stop every voice and shut the mixer down; idempotent.
bool isVoicePaused(VoiceId voice) const
Whether voice is being held by a pause rather than playing.
float voiceCursor(VoiceId voice) const
How far into its clip voice has played, in seconds.
void resumeVoice(VoiceId voice)
Let voice play on from where it was held, ramped back in.
void stopVoice(VoiceId voice)
Ramp voice to silence and let it go.
A sound: fully decoded interleaved PCM, plus the rate and layout it was written at.
Definition audio_clip_asset.h:58
Everything the mixer needs to know about one voice, pushed every frame.
Definition audio_device.h:32
float heardMinDistance() const
The near distance as the mixer takes it.
Definition audio_device.h:54
bool hasFar() const
Whether the voice fades with distance and so has a range past which it is silent.
Definition audio_device.h:68
float heardMaxDistance() const
The far distance as the mixer takes it.
Definition audio_device.h:61
float volume
Linear gain for this voice, multiplied into the master.
Definition audio_device.h:39