Polyphase Game Engine
Loading...
Searching...
No Matches
Audio.h
Go to the documentation of this file.
1#pragma once
2
3#include "EngineTypes.h"
4
5class Stream;
6class SoundWave;
7class Audio3D;
8
10{
11 uint32_t mNumChannels = 2;
12 uint32_t mSampleRate = 44100;
13 uint32_t mBytesPerSample = 2;
14};
15
19
21 uint32_t voiceIndex,
22 SoundWave* soundWave,
23 float volume,
24 float pitch,
25 bool loop,
26 float startTime,
27 bool spatial);
28
29void AUD_Stop(uint32_t voiceIndex);
30bool AUD_IsPlaying(uint32_t voiceIndex);
31void AUD_SetVolume(uint32_t voiceIndex, float leftVolume, float rightVolume);
32void AUD_SetPitch(uint32_t voiceIndex, float pitch);
33
34uint8_t* AUD_AllocWaveBuffer(uint32_t size);
35void AUD_FreeWaveBuffer(void* buffer);
37
38// ------------------------------------------------------------------------------------------------
39// Streaming voices — push-based PCM output for long-form / runtime-generated audio.
40//
41// Intended for use by native addons (e.g. the VideoPlayer) that decode PCM at runtime and
42// can't pre-bake it into a SoundWave asset. Each open stream is backed by a dedicated source
43// voice on the platform mixer. The engine owns the voice; the caller owns the raw PCM buffer
44// which must remain valid until the corresponding SubmitStreamBuffer call returns OR the
45// stream is closed. The backend copies the bytes into its own staging buffer synchronously.
46//
47// Returns: stream id (non-zero on success, 0 on failure).
48// sampleRate: PCM frames per second (e.g. 48000).
49// numChannels: 1 (mono) or 2 (stereo) supported by the Windows/XAudio2 backend.
50// bitsPerSample: 16 supported (other values return 0 on Windows).
51// ------------------------------------------------------------------------------------------------
52uint32_t AUD_OpenStream(uint32_t sampleRate, uint32_t numChannels, uint32_t bitsPerSample);
53void AUD_CloseStream(uint32_t streamId);
54// Returns the number of bytes the backend accepted. 0 means the submit queue is full and the
55// caller should retry next tick. Non-zero but < byteSize is not returned by the current backend
56// (it either fully accepts or fully rejects).
57int32_t AUD_SubmitStreamBuffer(uint32_t streamId, const uint8_t* data, uint32_t byteSize);
58// Total samples-per-channel consumed by the stream since Open. The video player's A/V sync uses
59// this as the master clock: `audio_time_seconds = played_samples / sample_rate`.
60uint64_t AUD_GetStreamPlayedSamples(uint32_t streamId);
61void AUD_SetStreamVolume(uint32_t streamId, float volume);
62void AUD_SetStreamPaused(uint32_t streamId, bool paused);
63// Drop every buffer currently queued on the stream without waiting for them to play.
64// Used on seek / loop so the voice doesn't keep playing stale pre-seek audio.
65// SamplesPlayed keeps climbing (XAudio2 can't reset it without destroying the voice);
66// callers should take a snapshot via GetStreamPlayedSamples() right after Flush and
67// subtract it from subsequent readings to recover a seek-relative clock.
68void AUD_FlushStream(uint32_t streamId);
69
70// Platform Independent
71void AUD_EncodeVorbis(Stream& inStream, Stream& outStream, PcmFormat format);
72void AUD_DecodeVorbis(Stream& inStream, Stream& outStream, PcmFormat format);
void AUD_Initialize()
void AUD_ProcessWaveBuffer(SoundWave *soundWave)
void AUD_Shutdown()
uint8_t * AUD_AllocWaveBuffer(uint32_t size)
void AUD_DecodeVorbis(Stream &inStream, Stream &outStream, PcmFormat format)
Definition Audio.cpp:209
uint32_t AUD_OpenStream(uint32_t sampleRate, uint32_t numChannels, uint32_t bitsPerSample)
void AUD_EncodeVorbis(Stream &inStream, Stream &outStream, PcmFormat format)
Definition Audio.cpp:20
void AUD_Play(uint32_t voiceIndex, SoundWave *soundWave, float volume, float pitch, bool loop, float startTime, bool spatial)
void AUD_Update()
uint64_t AUD_GetStreamPlayedSamples(uint32_t streamId)
int32_t AUD_SubmitStreamBuffer(uint32_t streamId, const uint8_t *data, uint32_t byteSize)
bool AUD_IsPlaying(uint32_t voiceIndex)
void AUD_SetStreamVolume(uint32_t streamId, float volume)
void AUD_SetPitch(uint32_t voiceIndex, float pitch)
void AUD_Stop(uint32_t voiceIndex)
void AUD_SetVolume(uint32_t voiceIndex, float leftVolume, float rightVolume)
void AUD_CloseStream(uint32_t streamId)
void AUD_SetStreamPaused(uint32_t streamId, bool paused)
void AUD_FreeWaveBuffer(void *buffer)
void AUD_FlushStream(uint32_t streamId)
Definition Audio3d.h:8
Definition SoundWave.h:6
Definition Stream.h:21
Definition Audio.h:10
uint32_t mBytesPerSample
Definition Audio.h:13
uint32_t mSampleRate
Definition Audio.h:12
uint32_t mNumChannels
Definition Audio.h:11