4#include "SDL3pp_audio.h"
5#include "SDL3pp_version.h"
7#ifdef SDL3PP_ENABLE_MIXER
9#include <SDL3_mixer/SDL_mixer.h>
661 bool free_when_done =
false);
1244 using MixerBase::MixerBase;
1260 :
Mixer(other.release())
1448 : m_lock(std::move(other.m_lock))
1479 std::swap(m_lock, other.m_lock);
1484 constexpr operator bool()
const {
return bool(m_lock); }
1702 using AudioBase::AudioBase;
1718 :
Audio(other.release())
3356 using TrackBase::TrackBase;
3372 :
Track(other.release())
3589 using GroupBase::GroupBase;
3605 :
Group(other.release())
3661#define SDL_MIXER_MAJOR_VERSION
3670#define SDL_MIXER_MINOR_VERSION
3679#define SDL_MIXER_MICRO_VERSION
3688#define SDL_MIXER_VERSION \
3690 SDL_MIXER_MAJOR_VERSION, SDL_MIXER_MINOR_VERSION, SDL_MIXER_MICRO_VERSION)
3697#define SDL_MIXER_VERSION_ATLEAST(X, Y, Z) \
3698 ((SDL_MIXER_MAJOR_VERSION >= X) && \
3699 (SDL_MIXER_MAJOR_VERSION > X || SDL_MIXER_MINOR_VERSION >= Y) && \
3700 (SDL_MIXER_MAJOR_VERSION > X || SDL_MIXER_MINOR_VERSION > Y || \
3701 SDL_MIXER_MICRO_VERSION >= Z))
3723inline int Version() {
return MIX_Version(); }
3743inline void Init() {
CheckError(MIX_Init()); }
3779inline void Quit() { MIX_Quit(); }
3836 return MIX_GetAudioDecoder(index);
3887 return Mixer(devid, spec);
3975 return CheckError(MIX_GetMixerProperties(mixer));
4111 std::move(lock).reset();
4116 if (!m_lock)
return;
4177 return Audio(mixer, io, predecode);
4182 return Audio(
get(), io, predecode);
4186 :
Audio(
CheckError(MIX_LoadAudio_IO(mixer, io.stream, predecode, io.closeio)))
4191 :
Audio(MIX_LoadAudio(mixer, path, predecode))
4201 :
Audio(
CheckError(MIX_LoadRawAudio_IO(mixer, io.stream, &spec, io.closeio)))
4207 MIX_LoadRawAudio(mixer, data.data(), data.size_bytes(), &spec)))
4241 return Audio(mixer, path, predecode);
4246 return Audio(
get(), path, predecode);
4307 bool free_when_done)
4370 return Audio(props);
4381 MIX_PROP_AUDIO_LOAD_IOSTREAM_POINTER;
4384 MIX_PROP_AUDIO_LOAD_CLOSEIO_BOOLEAN;
4387 MIX_PROP_AUDIO_LOAD_PREDECODE_BOOLEAN;
4390 MIX_PROP_AUDIO_LOAD_PREFERRED_MIXER_POINTER;
4394 MIX_PROP_AUDIO_LOAD_SKIP_METADATA_TAGS_BOOLEAN;
4397#if SDL_MIXER_VERSION_ATLEAST(3, 2, 4)
4400 MIX_PROP_AUDIO_LOAD_IGNORE_LOOPS_BOOLEAN;
4405 MIX_PROP_AUDIO_DECODER_STRING;
4445 return Audio(mixer, io, spec);
4491 return Audio(mixer, std::move(data), spec);
4496 return Audio(
get(), std::move(data), spec);
4542 bool free_when_done =
false)
4550 bool free_when_done)
4596 return Audio(
CheckError(MIX_CreateSineWaveAudio(mixer, hz, amplitude, ms)));
4651 return CheckError(MIX_GetAudioProperties(audio));
4667 MIX_PROP_METADATA_TITLE_STRING;
4670 MIX_PROP_METADATA_ARTIST_STRING;
4673 MIX_PROP_METADATA_ALBUM_STRING;
4676 MIX_PROP_METADATA_COPYRIGHT_STRING;
4679 MIX_PROP_METADATA_TRACK_NUMBER;
4682 MIX_PROP_METADATA_TOTAL_TRACKS_NUMBER;
4685 MIX_PROP_METADATA_YEAR_NUMBER;
4688 MIX_PROP_METADATA_DURATION_FRAMES_NUMBER;
4691 MIX_PROP_METADATA_DURATION_INFINITE_BOOLEAN;
4729 return MIX_GetAudioDuration(audio);
4865 return CheckError(MIX_GetTrackProperties(track));
4976 CheckError(MIX_SetTrackAudioStream(track, stream));
5158 MIX_UntagTrack(track, tag);
5179 auto result =
CheckError(MIX_GetTrackTags(track, &count));
5202 auto result =
CheckError(MIX_GetTaggedTracks(mixer, tag, &count));
5248 CheckError(MIX_SetTrackPlaybackPosition(track, frames));
5281 return MIX_GetTrackPlaybackPosition(track);
5313 return MIX_GetTrackFadeFrames(track);
5381 CheckError(MIX_SetTrackLoops(track, num_loops));
5411 return MIX_GetTrackAudio(track);
5439 return MIX_GetTrackAudioStream(track);
5474 return MIX_GetTrackRemaining(track);
5506 return MIX_TrackMSToFrames(track, ms.count());
5541 return Milliseconds(MIX_TrackFramesToMS(track, frames));
5570 return MIX_AudioMSToFrames(audio, ms.count());
5602 return Milliseconds(MIX_AudioFramesToMS(audio, frames));
5628 return MIX_MSToFrames(sample_rate, ms.count());
5654 return Milliseconds(MIX_FramesToMS(sample_rate, frames));
5793 MIX_PROP_PLAY_MAX_FRAME_NUMBER;
5796 MIX_PROP_PLAY_MAX_MILLISECONDS_NUMBER;
5799 MIX_PROP_PLAY_START_FRAME_NUMBER;
5802 MIX_PROP_PLAY_START_MILLISECOND_NUMBER;
5804#if SDL_MIXER_VERSION_ATLEAST(3, 2, 2)
5807 MIX_PROP_PLAY_START_ORDER_NUMBER;
5812 MIX_PROP_PLAY_LOOP_START_FRAME_NUMBER;
5815 MIX_PROP_PLAY_LOOP_START_MILLISECOND_NUMBER;
5819 MIX_PROP_PLAY_FADE_IN_FRAMES_NUMBER;
5822 MIX_PROP_PLAY_FADE_IN_MILLISECONDS_NUMBER;
5826 MIX_PROP_PLAY_FADE_IN_START_GAIN_FLOAT;
5829 MIX_PROP_PLAY_APPEND_SILENCE_FRAMES_NUMBER;
5833 MIX_PROP_PLAY_APPEND_SILENCE_MILLISECONDS_NUMBER;
5837 MIX_PROP_PLAY_HALT_WHEN_EXHAUSTED_BOOLEAN;
5877 CheckError(MIX_PlayTag(mixer, tag, options));
5917 return MIX_PlayAudio(mixer, audio);
5959 return MIX_StopTrack(track, fade_out_frames);
6001 CheckError(MIX_StopAllTracks(mixer, fade_out_ms));
6042 CheckError(MIX_StopTag(mixer, tag, fade_out_ms));
6418 CheckError(MIX_SetTagGain(mixer, tag, gain));
6455 CheckError(MIX_SetMixerFrequencyRatio(mixer, ratio));
6481 return MIX_GetMixerFrequencyRatio(mixer);
6514 CheckError(MIX_SetTrackFrequencyRatio(track, ratio));
6549 return MIX_GetTrackFrequencyRatio(track);
6595 MIX_SetTrackOutputChannelMap(track, chmap.data(),
narrowS32(chmap.size())));
6635 CheckError(MIX_SetTrackStereo(track, &gains));
6687 CheckError(MIX_SetTrack3DPosition(track, &position));
6714 CheckError(MIX_GetTrack3DPosition(track, &position));
6798 return CheckError(MIX_GetGroupProperties(group));
6892 CheckError(MIX_SetTrackStoppedCallback(track, cb, userdata));
6971 CheckError(MIX_SetTrackRawCallback(track, cb, userdata));
7052 CheckError(MIX_SetTrackCookedCallback(track, cb, userdata));
7129 CheckError(MIX_SetGroupPostMixCallback(group, cb, userdata));
7192 CheckError(MIX_SetPostMixCallback(mixer, cb, userdata));
7394 using AudioDecoderBase::AudioDecoderBase;
7538 :
AudioDecoder(MIX_CreateAudioDecoder_IO(io.stream, io.closeio, props))
7592 MIX_DestroyAudioDecoder(audiodecoder);
7622 return CheckError(MIX_GetAudioDecoderProperties(audiodecoder));
7648 CheckError(MIX_GetAudioDecoderFormat(audiodecoder, spec));
Lock a mixer by obtaining its internal mutex.
Definition SDL3pp_mixer.h:1394
MixerRef resource() const
Get the reference to locked resource.
Definition SDL3pp_mixer.h:1509
MixerLock(MixerLock &&other) noexcept
Move constructor.
Definition SDL3pp_mixer.h:1447
void release()
Releases the lock without unlocking.
Definition SDL3pp_mixer.h:1512
~MixerLock()
Unlock a mixer previously locked by a call to LockMixer().
Definition SDL3pp_mixer.h:1472
MixerLock(const MixerLock &other)=delete
Copy constructor.
MixerLock & operator=(MixerLock &&other) noexcept
Assignment operator.
Definition SDL3pp_mixer.h:1477
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr OwnArray(std::nullptr_t=nullptr)
Constructor.
Definition SDL3pp_ownPtr.h:50
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Source byte stream.
Definition SDL3pp_strings.h:246
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:310
constexpr const char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:313
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:58
Target byte stream.
Definition SDL3pp_strings.h:332
constexpr char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:418
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:415
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:383
SDL_AudioSpec AudioSpec
Format specifier for audio data.
Definition SDL3pp_audio.h:201
ResourceRefT< AudioStreamBase > AudioStreamRef
Reference for AudioStream.
Definition SDL3pp_audio.h:152
ResourceRefT< AudioDeviceBase > AudioDeviceRef
Reference for AudioDevice.
Definition SDL3pp_audio.h:136
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
void Quit()
Clean up all initialized subsystems.
Definition SDL3pp_init.h:329
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:56
void(SDLCALL *)(void *userdata, TrackRaw track) TrackStoppedCallback
A callback that fires when a Track is stopped.
Definition SDL3pp_mixer.h:1994
MakeFrontCallback< void(TrackRaw track)> TrackStoppedCB
A callback that fires when a Track is stopped.
Definition SDL3pp_mixer.h:2018
Audio LoadRawAudio(MixerRef mixer, SourceBytes data, const AudioSpec &spec)
Load raw PCM data from a memory buffer.
Definition SDL3pp_mixer.h:4487
void SetTrackStereo(TrackRef track, const StereoGains &gains)
Force a track to stereo output, with optionally left/right panning.
Definition SDL3pp_mixer.h:6633
Audio LoadAudioWithProperties(PropertiesRef props)
Load audio for playback through a collection of properties.
Definition SDL3pp_mixer.h:4368
void Destroy()
Destroy the specified audio.
Definition SDL3pp_mixer.h:4788
void SetTrackCookedCallback(TrackRef track, TrackMixCallback cb, void *userdata)
Set a callback that fires when the mixer has transformed a track's audio.
Definition SDL3pp_mixer.h:7048
AudioStreamRef GetAudioStream()
Query the AudioStream assigned to a track.
Definition SDL3pp_mixer.h:5442
bool Paused()
Query if a track is currently paused.
Definition SDL3pp_mixer.h:6276
PropertiesRef GetAudioDecoderProperties(AudioDecoderRef audiodecoder)
Get the properties associated with a AudioDecoder.
Definition SDL3pp_mixer.h:7620
AudioDecoder CreateAudioDecoder_IO(IOStreamParam io, PropertiesRef props=nullptr)
Create a AudioDecoder from an IOStream.
Definition SDL3pp_mixer.h:7573
float GetTrackFrequencyRatio(TrackRef track)
Query the frequency ratio of a track.
Definition SDL3pp_mixer.h:6547
void GetMixerFormat(MixerRef mixer, AudioSpec *spec)
Get the audio format a mixer is generating.
Definition SDL3pp_mixer.h:4021
MakeFrontCallback< void(GroupRaw group, const AudioSpec *spec, float *pcm, int samples)> GroupMixCB
A callback that fires when a Group has completed mixing.
Definition SDL3pp_mixer.h:3484
void SetTrackRawIOStream(TrackRef track, IOStreamParam io, const AudioSpec &spec)
Set a Track's input to an IOStream providing raw PCM data.
Definition SDL3pp_mixer.h:5087
void SetTagGain(StringParam tag, float gain)
Set the gain control of all tracks with a specific tag.
Definition SDL3pp_mixer.h:6421
void PauseTag(StringParam tag)
Pause all tracks with a specific tag.
Definition SDL3pp_mixer.h:6134
MIX_Group * GroupRaw
Alias to raw representation for Group.
Definition SDL3pp_mixer.h:163
void SetGain(float gain)
Set a mixer's master gain control.
Definition SDL3pp_mixer.h:6308
void SetTagGain(MixerRef mixer, StringParam tag, float gain)
Set the gain control of all tracks with a specific tag.
Definition SDL3pp_mixer.h:6416
void SetTrackPlaybackPosition(TrackRef track, Sint64 frames)
Seek a playing track to a new position in its input.
Definition SDL3pp_mixer.h:5246
void UntagTrack(TrackRef track, StringParam tag)
Remove an arbitrary tag from a track.
Definition SDL3pp_mixer.h:5156
void(SDLCALL *)(void *userdata, TrackRaw track, const AudioSpec *spec, float *pcm, int samples) TrackMixCallback
A callback that fires when a Track is mixing at various stages.
Definition SDL3pp_mixer.h:2056
void ResumeAllTracks()
Resume all currently-paused tracks.
Definition SDL3pp_mixer.h:6187
PropertiesRef GetProperties()
Get the properties associated with a group.
Definition SDL3pp_mixer.h:6801
PropertiesRef GetProperties()
Get the properties associated with a AudioDecoder.
Definition SDL3pp_mixer.h:7625
AudioRef GetAudio()
Query the Audio assigned to a track.
Definition SDL3pp_mixer.h:5414
Milliseconds FramesToMS(int sample_rate, Sint64 frames)
Convert sample frames, at a specific sample rate, to milliseconds.
Definition SDL3pp_mixer.h:5652
void PauseTag(MixerRef mixer, StringParam tag)
Pause all tracks with a specific tag.
Definition SDL3pp_mixer.h:6129
PropertiesRef GetProperties()
Get the properties associated with a Audio.
Definition SDL3pp_mixer.h:4654
void PlayTrack(TrackRef track, PropertiesRef options=nullptr)
Start (or restart) mixing a track for playback.
Definition SDL3pp_mixer.h:5773
Audio LoadAudio_IO(IOStreamParam io, bool predecode)
Load audio for playback from an IOStream.
Definition SDL3pp_mixer.h:4180
void Destroy()
Destroy the specified audio decoder.
Definition SDL3pp_mixer.h:7595
Sint64 TrackMSToFrames(TrackRef track, Milliseconds ms)
Convert milliseconds to sample frames for a track's current format.
Definition SDL3pp_mixer.h:5504
OwnArray< char * > GetTrackTags(TrackRef track)
Get the tags currently associated with a track.
Definition SDL3pp_mixer.h:5176
Sint64 MSToFrames(Milliseconds ms)
Convert milliseconds to sample frames for a track's current format.
Definition SDL3pp_mixer.h:5509
void Destroy()
Destroy the specified track.
Definition SDL3pp_mixer.h:4844
void ResumeTag(MixerRef mixer, StringParam tag)
Resume all tracks with a specific tag.
Definition SDL3pp_mixer.h:6214
Audio CreateSineWaveAudio(MixerRef mixer, int hz, float amplitude, Sint64 ms)
Create a Audio that generates a sinewave.
Definition SDL3pp_mixer.h:4591
void Unlock(MixerLock &&lock)
Unlock a mixer previously locked by a call to LockMixer().
Definition SDL3pp_mixer.h:4108
void SetTrackStoppedCallback(TrackRef track, TrackStoppedCallback cb, void *userdata)
Set a callback that fires when a Track is stopped.
Definition SDL3pp_mixer.h:6888
PropertiesRef GetProperties()
Get the properties associated with a track.
Definition SDL3pp_mixer.h:4868
const char * GetAudioDecoder(int index)
Report the name of a specific audio decoders.
Definition SDL3pp_mixer.h:3834
void GetAudioDecoderFormat(AudioDecoderRef audiodecoder, AudioSpec *spec)
Query the initial audio format of a AudioDecoder.
Definition SDL3pp_mixer.h:7646
bool PlayAudio(AudioRef audio)
Play a Audio from start to finish without any management.
Definition SDL3pp_mixer.h:5920
ResourceRefT< GroupBase > GroupRef
Reference for Group.
Definition SDL3pp_mixer.h:170
int Generate(TargetBytes buffer)
Generate mixer output when not driving an audio device.
Definition SDL3pp_mixer.h:7288
bool Resume()
Resume a currently-paused track.
Definition SDL3pp_mixer.h:6160
void DestroyAudioDecoder(AudioDecoderRaw audiodecoder)
Destroy the specified audio decoder.
Definition SDL3pp_mixer.h:7590
void UnlockMixer(MixerRef mixer)
Unlock a mixer previously locked by a call to LockMixer().
Definition SDL3pp_mixer.h:4106
bool Playing()
Query if a track is currently playing.
Definition SDL3pp_mixer.h:6249
Track CreateTrack(MixerRef mixer)
Create a new track on a mixer.
Definition SDL3pp_mixer.h:4812
MakeFrontCallback< void(TrackRaw track, const AudioSpec *spec, float *pcm, int samples)> TrackMixCB
A callback that fires when a Track is mixing at various stages.
Definition SDL3pp_mixer.h:2098
Audio LoadRawAudio_IO(IOStreamParam io, const AudioSpec &spec)
Load raw PCM data from an IOStream.
Definition SDL3pp_mixer.h:4448
void SetGain(float gain)
Set a track's gain control.
Definition SDL3pp_mixer.h:6360
void SetLoops(int num_loops)
Change the number of times a currently-playing track will loop.
Definition SDL3pp_mixer.h:5384
Point3D Get3DPosition()
Get a track's current position in 3D space.
Definition SDL3pp_mixer.h:6718
void SetGroupPostMixCallback(GroupRef group, GroupMixCallback cb, void *userdata)
Set a callback that fires when a mixer group has completed mixing.
Definition SDL3pp_mixer.h:7125
void Untag(StringParam tag)
Remove an arbitrary tag from a track.
Definition SDL3pp_mixer.h:5161
MixerLock(MixerRef resource)
Lock a mixer by obtaining its internal mutex.
Definition SDL3pp_mixer.h:4078
ResourceRefT< AudioDecoderBase > AudioDecoderRef
Reference for AudioDecoder.
Definition SDL3pp_mixer.h:186
bool Pause()
Pause a currently-playing track.
Definition SDL3pp_mixer.h:6074
void SetTrackAudioStream(TrackRef track, AudioStreamRef stream)
Set a Track's input to an AudioStream.
Definition SDL3pp_mixer.h:4974
int Generate(MixerRef mixer, TargetBytes buffer)
Generate mixer output when not driving an audio device.
Definition SDL3pp_mixer.h:7282
void SetAudioStream(AudioStreamRef stream)
Set a Track's input to an AudioStream.
Definition SDL3pp_mixer.h:4979
PropertiesRef GetProperties()
Get the properties associated with a mixer.
Definition SDL3pp_mixer.h:3978
void SetTrackOutputChannelMap(TrackRef track, std::span< const int > chmap)
Set the current output channel map of a track.
Definition SDL3pp_mixer.h:6592
Sint64 GetDuration()
Get the length of a Audio's playback in sample frames.
Definition SDL3pp_mixer.h:4732
void StopTag(StringParam tag, Sint64 fade_out_ms)
Halt all tracks with a specific tag, possibly fading out over time.
Definition SDL3pp_mixer.h:6045
void ResumeTag(StringParam tag)
Resume all tracks with a specific tag.
Definition SDL3pp_mixer.h:6219
Audio LoadAudioNoCopy(SourceBytes data, bool free_when_done)
Load audio for playback from a memory buffer without making a copy.
Definition SDL3pp_mixer.h:4313
void SetRawIOStream(IOStreamParam io, const AudioSpec &spec)
Set a Track's input to an IOStream providing raw PCM data.
Definition SDL3pp_mixer.h:5094
MIX_AudioDecoder * AudioDecoderRaw
Alias to raw representation for AudioDecoder.
Definition SDL3pp_mixer.h:179
OwnArray< TrackRef > GetTaggedTracks(StringParam tag)
Get all tracks with a specific tag.
Definition SDL3pp_mixer.h:5206
void DestroyMixer(MixerRaw mixer)
Free a mixer.
Definition SDL3pp_mixer.h:3952
AudioStreamRef GetTrackAudioStream(TrackRef track)
Query the AudioStream assigned to a track.
Definition SDL3pp_mixer.h:5437
Sint64 GetFadeFrames()
Query whether a given track is fading.
Definition SDL3pp_mixer.h:5316
bool Stop(Sint64 fade_out_frames)
Halt a currently-playing track, possibly fading out over time.
Definition SDL3pp_mixer.h:5962
void SetTrackRawCallback(TrackRef track, TrackMixCallback cb, void *userdata)
Set a callback that fires when a Track has initial decoded audio.
Definition SDL3pp_mixer.h:6967
Milliseconds AudioFramesToMS(AudioRef audio, Sint64 frames)
Convert sample frames for a Audio's format to milliseconds.
Definition SDL3pp_mixer.h:5600
void SetTrackAudio(TrackRef track, AudioRef audio)
Set a Track's input to a Audio.
Definition SDL3pp_mixer.h:4924
void StopTag(MixerRef mixer, StringParam tag, Sint64 fade_out_ms)
Halt all tracks with a specific tag, possibly fading out over time.
Definition SDL3pp_mixer.h:6040
void SetGroup(GroupRef group)
Assign a track to a mixing group.
Definition SDL3pp_mixer.h:6854
void(SDLCALL *)(void *userdata, MixerRaw mixer, const AudioSpec *spec, float *pcm, int samples) PostMixCallback
A callback that fires when all mixing has completed.
Definition SDL3pp_mixer.h:224
void SetStereo(const StereoGains &gains)
Force a track to stereo output, with optionally left/right panning.
Definition SDL3pp_mixer.h:6638
Sint64 GetPlaybackPosition()
Get the current input position of a playing track.
Definition SDL3pp_mixer.h:5284
Sint64 MSToFrames(int sample_rate, Milliseconds ms)
Convert milliseconds to sample frames at a specific sample rate.
Definition SDL3pp_mixer.h:5626
constexpr Sint64 DURATION_INFINITE
Infinite duration, when the audio never runs out of sound to generate.
Definition SDL3pp_mixer.h:4738
bool ResumeTrack(TrackRef track)
Resume a currently-paused track.
Definition SDL3pp_mixer.h:6158
void SetPostMixCallback(GroupMixCallback cb, void *userdata)
Set a callback that fires when a mixer group has completed mixing.
Definition SDL3pp_mixer.h:7160
void PlayTag(StringParam tag, PropertiesRef options)
Start (or restart) mixing all tracks with a specific tag for playback.
Definition SDL3pp_mixer.h:5880
void DestroyAudio(AudioRaw audio)
Destroy the specified audio.
Definition SDL3pp_mixer.h:4786
bool StopTrack(TrackRef track, Sint64 fade_out_frames)
Halt a currently-playing track, possibly fading out over time.
Definition SDL3pp_mixer.h:5957
bool PauseTrack(TrackRef track)
Pause a currently-playing track.
Definition SDL3pp_mixer.h:6072
float GetTrackGain(TrackRef track)
Get a track's gain control.
Definition SDL3pp_mixer.h:6378
void SetPostMixCallback(MixerRef mixer, PostMixCallback cb, void *userdata)
Set a callback that fires when all mixing has completed.
Definition SDL3pp_mixer.h:7188
PropertiesRef GetTrackProperties(TrackRef track)
Get the properties associated with a track.
Definition SDL3pp_mixer.h:4863
MakeFrontCallback< void(MixerRaw mixer, const AudioSpec *spec, float *pcm, int samples)> PostMixCB
A callback that fires when all mixing has completed.
Definition SDL3pp_mixer.h:264
MixerLock Lock()
Lock a mixer by obtaining its internal mutex.
Definition SDL3pp_mixer.h:4076
MIX_Track * TrackRaw
Alias to raw representation for Track.
Definition SDL3pp_mixer.h:147
Audio LoadAudio_IO(MixerRef mixer, IOStreamParam io, bool predecode)
Load audio for playback from an IOStream.
Definition SDL3pp_mixer.h:4175
float GetMixerGain(MixerRef mixer)
Get a mixer's master gain control.
Definition SDL3pp_mixer.h:6326
float GetFrequencyRatio()
Get a mixer's master frequency ratio.
Definition SDL3pp_mixer.h:6484
int GetNumAudioDecoders()
Report the number of audio decoders available for use.
Definition SDL3pp_mixer.h:3803
float GetFrequencyRatio()
Query the frequency ratio of a track.
Definition SDL3pp_mixer.h:6552
Sint64 GetAudioDuration(AudioRef audio)
Get the length of a Audio's playback in sample frames.
Definition SDL3pp_mixer.h:4727
void Destroy()
Destroy a mixing group.
Definition SDL3pp_mixer.h:6777
void SetAudio(AudioRef audio)
Set a Track's input to a Audio.
Definition SDL3pp_mixer.h:4929
Mixer CreateMixerDevice(AudioDeviceRef devid, OptionalRef< const AudioSpec > spec=std::nullopt)
Create a mixer that plays sound directly to an audio device.
Definition SDL3pp_mixer.h:3884
OwnArray< char * > GetTags()
Get the tags currently associated with a track.
Definition SDL3pp_mixer.h:5183
void StopAllTracks(MixerRef mixer, Sint64 fade_out_ms)
Halt all currently-playing tracks, possibly fading out over time.
Definition SDL3pp_mixer.h:5999
Sint64 GetTrackRemaining(TrackRef track)
Return the number of sample frames remaining to be mixed in a track.
Definition SDL3pp_mixer.h:5472
void SetOutputChannelMap(std::span< const int > chmap)
Set the current output channel map of a track.
Definition SDL3pp_mixer.h:6598
void TagTrack(TrackRef track, StringParam tag)
Assign an arbitrary tag to a track.
Definition SDL3pp_mixer.h:5126
PropertiesRef GetAudioProperties(AudioRef audio)
Get the properties associated with a Audio.
Definition SDL3pp_mixer.h:4649
Audio LoadAudio(MixerRef mixer, StringParam path, bool predecode)
Load audio for playback from a file.
Definition SDL3pp_mixer.h:4239
void PauseAllTracks(MixerRef mixer)
Pause all currently-playing tracks.
Definition SDL3pp_mixer.h:6096
void SetFrequencyRatio(float ratio)
Set a mixer's master frequency ratio.
Definition SDL3pp_mixer.h:6458
void SetStoppedCallback(TrackStoppedCallback cb, void *userdata)
Set a callback that fires when a Track is stopped.
Definition SDL3pp_mixer.h:6927
MixerRef GetMixer()
Get the Mixer that owns a Group.
Definition SDL3pp_mixer.h:6824
void SetPlaybackPosition(Sint64 frames)
Seek a playing track to a new position in its input.
Definition SDL3pp_mixer.h:5251
Audio LoadAudioNoCopy(MixerRef mixer, SourceBytes data, bool free_when_done)
Load audio for playback from a memory buffer without making a copy.
Definition SDL3pp_mixer.h:4305
Sint64 AudioMSToFrames(AudioRef audio, Milliseconds ms)
Convert milliseconds to sample frames for a Audio's format.
Definition SDL3pp_mixer.h:5568
void LockMixer(MixerRef mixer)
Lock a mixer by obtaining its internal mutex.
Definition SDL3pp_mixer.h:4074
void GetFormat(AudioSpec *spec)
Query the initial audio format of a AudioDecoder.
Definition SDL3pp_mixer.h:7651
PropertiesRef GetMixerProperties(MixerRef mixer)
Get the properties associated with a mixer.
Definition SDL3pp_mixer.h:3973
void SetPostMixCallback(PostMixCallback cb, void *userdata)
Set a callback that fires when all mixing has completed.
Definition SDL3pp_mixer.h:7221
float GetMixerFrequencyRatio(MixerRef mixer)
Get a mixer's master frequency ratio.
Definition SDL3pp_mixer.h:6479
void SetTrackFrequencyRatio(TrackRef track, float ratio)
Change the frequency ratio of a track.
Definition SDL3pp_mixer.h:6512
void GetFormat(AudioSpec *spec)
Query the initial audio format of a Audio.
Definition SDL3pp_mixer.h:4761
bool TrackPlaying(TrackRef track)
Query if a track is currently playing.
Definition SDL3pp_mixer.h:6247
int GetLoops()
Query how many loops remain for a given track.
Definition SDL3pp_mixer.h:5349
Milliseconds TrackFramesToMS(TrackRef track, Sint64 frames)
Convert sample frames for a track's current format to milliseconds.
Definition SDL3pp_mixer.h:5539
void reset()
Unlock a mixer previously locked by a call to LockMixer().
Definition SDL3pp_mixer.h:4114
void SetCookedCallback(TrackMixCallback cb, void *userdata)
Set a callback that fires when the mixer has transformed a track's audio.
Definition SDL3pp_mixer.h:7090
void Set3DPosition(const Point3D &position)
Set a track's position in 3D space.
Definition SDL3pp_mixer.h:6690
void SetIOStream(IOStreamParam io)
Set a Track's input to an IOStream.
Definition SDL3pp_mixer.h:5035
AudioDecoder CreateAudioDecoder(StringParam path, PropertiesRef props=nullptr)
Create a AudioDecoder from a path on the filesystem.
Definition SDL3pp_mixer.h:7526
Group CreateGroup(MixerRef mixer)
Create a mixing group.
Definition SDL3pp_mixer.h:6752
Sint64 GetTrackFadeFrames(TrackRef track)
Query whether a given track is fading.
Definition SDL3pp_mixer.h:5311
void SetTrackIOStream(TrackRef track, IOStreamParam io)
Set a Track's input to an IOStream.
Definition SDL3pp_mixer.h:5030
TrackRef CreateTrack()
Create a new track on a mixer.
Definition SDL3pp_mixer.h:4814
Sint64 MSToFrames(Milliseconds ms)
Convert milliseconds to sample frames for a Audio's format.
Definition SDL3pp_mixer.h:5573
Audio LoadRawAudio(SourceBytes data, const AudioSpec &spec)
Load raw PCM data from a memory buffer.
Definition SDL3pp_mixer.h:4494
PropertiesRef GetGroupProperties(GroupRef group)
Get the properties associated with a group.
Definition SDL3pp_mixer.h:6796
void SetMixerFrequencyRatio(MixerRef mixer, float ratio)
Set a mixer's master frequency ratio.
Definition SDL3pp_mixer.h:6453
constexpr Sint64 DURATION_UNKNOWN
Unknown duration, when the length of the audio can't be determined.
Definition SDL3pp_mixer.h:4735
void SetTrack3DPosition(TrackRef track, const Point3D &position)
Set a track's position in 3D space.
Definition SDL3pp_mixer.h:6685
MIX_Point3D Point3D
3D coordinates for SetTrack3DPosition.
Definition SDL3pp_mixer.h:1971
MIX_Audio * AudioRaw
Alias to raw representation for Audio.
Definition SDL3pp_mixer.h:131
bool PlayAudio(MixerRef mixer, AudioRef audio)
Play a Audio from start to finish without any management.
Definition SDL3pp_mixer.h:5915
void ResumeAllTracks(MixerRef mixer)
Resume all currently-paused tracks.
Definition SDL3pp_mixer.h:6182
void DestroyGroup(GroupRaw group)
Destroy a mixing group.
Definition SDL3pp_mixer.h:6775
Audio LoadAudio(StringParam path, bool predecode)
Load audio for playback from a file.
Definition SDL3pp_mixer.h:4244
void SetTrackGroup(TrackRef track, GroupRef group)
Assign a track to a mixing group.
Definition SDL3pp_mixer.h:6849
float GetGain()
Get a mixer's master gain control.
Definition SDL3pp_mixer.h:6328
MixerRef GetTrackMixer(TrackRef track)
Get the Mixer that owns a Track.
Definition SDL3pp_mixer.h:4886
MIX_Mixer * MixerRaw
Alias to raw representation for Mixer.
Definition SDL3pp_mixer.h:115
Audio LoadRawAudioNoCopy(SourceBytes data, const AudioSpec &spec, bool free_when_done=false)
Load raw PCM data from a memory buffer without making a copy.
Definition SDL3pp_mixer.h:4548
void GetFormat(AudioSpec *spec)
Get the audio format a mixer is generating.
Definition SDL3pp_mixer.h:4026
void PlayTag(MixerRef mixer, StringParam tag, PropertiesRef options)
Start (or restart) mixing all tracks with a specific tag for playback.
Definition SDL3pp_mixer.h:5875
void SetRawCallback(TrackMixCallback cb, void *userdata)
Set a callback that fires when a Track has initial decoded audio.
Definition SDL3pp_mixer.h:7006
Audio LoadRawAudioNoCopy(MixerRef mixer, SourceBytes data, const AudioSpec &spec, bool free_when_done=false)
Load raw PCM data from a memory buffer without making a copy.
Definition SDL3pp_mixer.h:4539
void StopAllTracks(Sint64 fade_out_ms)
Halt all currently-playing tracks, possibly fading out over time.
Definition SDL3pp_mixer.h:6004
MixerRef GetMixer()
Get the Mixer that owns a Track.
Definition SDL3pp_mixer.h:4891
MixerRef GetGroupMixer(GroupRef group)
Get the Mixer that owns a Group.
Definition SDL3pp_mixer.h:6819
ResourceRefT< AudioBase > AudioRef
Reference for Audio.
Definition SDL3pp_mixer.h:138
bool TrackPaused(TrackRef track)
Query if a track is currently paused.
Definition SDL3pp_mixer.h:6274
void SetMixerGain(MixerRef mixer, float gain)
Set a mixer's master gain control.
Definition SDL3pp_mixer.h:6303
void SetTrackGain(TrackRef track, float gain)
Set a track's gain control.
Definition SDL3pp_mixer.h:6355
void PauseAllTracks()
Pause all currently-playing tracks.
Definition SDL3pp_mixer.h:6101
void Play(PropertiesRef options=nullptr)
Start (or restart) mixing a track for playback.
Definition SDL3pp_mixer.h:5778
GroupRef CreateGroup()
Create a mixing group.
Definition SDL3pp_mixer.h:6754
int GetTrackLoops(TrackRef track)
Query how many loops remain for a given track.
Definition SDL3pp_mixer.h:5347
ResourceRefT< MixerBase > MixerRef
Reference for Mixer.
Definition SDL3pp_mixer.h:122
Audio LoadRawAudio_IO(MixerRef mixer, IOStreamParam io, const AudioSpec &spec)
Load raw PCM data from an IOStream.
Definition SDL3pp_mixer.h:4441
void SetFrequencyRatio(float ratio)
Change the frequency ratio of a track.
Definition SDL3pp_mixer.h:6517
void Destroy()
Free a mixer.
Definition SDL3pp_mixer.h:3954
Sint64 GetTrackPlaybackPosition(TrackRef track)
Get the current input position of a playing track.
Definition SDL3pp_mixer.h:5279
void DestroyTrack(TrackRaw track)
Destroy the specified track.
Definition SDL3pp_mixer.h:4842
void Tag(StringParam tag)
Assign an arbitrary tag to a track.
Definition SDL3pp_mixer.h:5131
void SetTrackLoops(TrackRef track, int num_loops)
Change the number of times a currently-playing track will loop.
Definition SDL3pp_mixer.h:5379
Audio CreateSineWaveAudio(int hz, float amplitude, Sint64 ms)
Create a Audio that generates a sinewave.
Definition SDL3pp_mixer.h:4599
Point3D GetTrack3DPosition(TrackRef track)
Get a track's current position in 3D space.
Definition SDL3pp_mixer.h:6711
Mixer CreateMixer(const AudioSpec &spec)
Create a mixer that generates audio to a memory buffer.
Definition SDL3pp_mixer.h:3927
void GetAudioFormat(AudioRef audio, AudioSpec *spec)
Query the initial audio format of a Audio.
Definition SDL3pp_mixer.h:4756
float GetGain()
Get a track's gain control.
Definition SDL3pp_mixer.h:6380
MIX_StereoGains StereoGains
A set of per-channel gains for tracks using SetTrackStereo().
Definition SDL3pp_mixer.h:1959
OwnArray< TrackRef > GetTaggedTracks(MixerRef mixer, StringParam tag)
Get all tracks with a specific tag.
Definition SDL3pp_mixer.h:5199
Milliseconds FramesToMS(Sint64 frames)
Convert sample frames for a track's current format to milliseconds.
Definition SDL3pp_mixer.h:5544
int DecodeAudio(TargetBytes buffer, const AudioSpec &spec)
Decode more audio from a AudioDecoder.
Definition SDL3pp_mixer.h:7686
Milliseconds FramesToMS(Sint64 frames)
Convert sample frames for a Audio's format to milliseconds.
Definition SDL3pp_mixer.h:5605
int DecodeAudio(AudioDecoderRef audiodecoder, TargetBytes buffer, const AudioSpec &spec)
Decode more audio from a AudioDecoder.
Definition SDL3pp_mixer.h:7676
void(SDLCALL *)(void *userdata, GroupRaw group, const AudioSpec *spec, float *pcm, int samples) GroupMixCallback
A callback that fires when a Group has completed mixing.
Definition SDL3pp_mixer.h:3445
Sint64 GetRemaining()
Return the number of sample frames remaining to be mixed in a track.
Definition SDL3pp_mixer.h:5477
ResourceRefT< TrackBase > TrackRef
Reference for Track.
Definition SDL3pp_mixer.h:154
AudioRef GetTrackAudio(TrackRef track)
Query the Audio assigned to a track.
Definition SDL3pp_mixer.h:5409
::Sint64 Sint64
A signed 64-bit integer type.
Definition SDL3pp_stdinc.h:311
std::chrono::milliseconds Milliseconds
Duration in Miliseconds (Uint32).
Definition SDL3pp_stdinc.h:341
Properties for configuring audio loading.
Definition SDL3pp_mixer.h:4378
constexpr auto LOAD_IGNORE_LOOPS_BOOLEAN
Load ignore loops enabled.
Definition SDL3pp_mixer.h:4399
constexpr auto DECODER_STRING
String for decoder.
Definition SDL3pp_mixer.h:4404
constexpr auto LOAD_CLOSEIO_BOOLEAN
Load closeio enabled.
Definition SDL3pp_mixer.h:4383
constexpr auto LOAD_IOSTREAM_POINTER
Pointer to load iostream.
Definition SDL3pp_mixer.h:4380
constexpr auto LOAD_PREDECODE_BOOLEAN
Load predecode enabled.
Definition SDL3pp_mixer.h:4386
constexpr auto LOAD_SKIP_METADATA_TAGS_BOOLEAN
Enable load skip metadata tags.
Definition SDL3pp_mixer.h:4393
constexpr auto LOAD_PREFERRED_MIXER_POINTER
Pointer to load preferred mixer.
Definition SDL3pp_mixer.h:4389
Properties for Mixer.
Definition SDL3pp_mixer.h:3988
constexpr auto DEVICE_NUMBER
Device number.
Definition SDL3pp_mixer.h:3990
Properties that can be used in the options parameter of Track.Play().
Definition SDL3pp_mixer.h:5788
constexpr auto START_MILLISECOND_NUMBER
Number for start millisecond.
Definition SDL3pp_mixer.h:5801
constexpr auto LOOPS_NUMBER
Number for loops.
Definition SDL3pp_mixer.h:5790
constexpr auto START_ORDER_NUMBER
Number for start order.
Definition SDL3pp_mixer.h:5806
constexpr auto MAX_FRAME_NUMBER
Number for max frame.
Definition SDL3pp_mixer.h:5792
constexpr auto HALT_WHEN_EXHAUSTED_BOOLEAN
Halt when exhausted enabled.
Definition SDL3pp_mixer.h:5836
constexpr auto LOOP_START_FRAME_NUMBER
Number for loop start frame.
Definition SDL3pp_mixer.h:5811
constexpr auto FADE_IN_START_GAIN_FLOAT
Float for fade in start gain.
Definition SDL3pp_mixer.h:5825
constexpr auto APPEND_SILENCE_FRAMES_NUMBER
Number for append silence frames.
Definition SDL3pp_mixer.h:5828
constexpr auto FADE_IN_MILLISECONDS_NUMBER
Number for fade in milliseconds.
Definition SDL3pp_mixer.h:5821
constexpr auto FADE_IN_FRAMES_NUMBER
Number for fade in frames.
Definition SDL3pp_mixer.h:5818
constexpr auto START_FRAME_NUMBER
Number for start frame.
Definition SDL3pp_mixer.h:5798
constexpr auto MAX_MILLISECONDS_NUMBER
Number for max milliseconds.
Definition SDL3pp_mixer.h:5795
constexpr auto APPEND_SILENCE_MILLISECONDS_NUMBER
Number for append silence milliseconds.
Definition SDL3pp_mixer.h:5832
constexpr auto LOOP_START_MILLISECOND_NUMBER
Number for loop start millisecond.
Definition SDL3pp_mixer.h:5814
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6262
Base class to Audio.
Definition SDL3pp_mixer.h:1521
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Base class to AudioDecoder.
Definition SDL3pp_mixer.h:7299
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An opaque object that represents an audio decoder.
Definition SDL3pp_mixer.h:7393
constexpr AudioDecoder(AudioDecoderRaw resource) noexcept
Constructs from raw AudioDecoder.
Definition SDL3pp_mixer.h:7403
constexpr AudioDecoder & operator=(AudioDecoder &&other) noexcept
Assignment operator.
Definition SDL3pp_mixer.h:7486
~AudioDecoder()
Destructor.
Definition SDL3pp_mixer.h:7483
constexpr AudioDecoder(AudioDecoder &&other) noexcept
Move constructor.
Definition SDL3pp_mixer.h:7409
An opaque object that represents audio data.
Definition SDL3pp_mixer.h:1701
constexpr Audio(Audio &&other) noexcept
Move constructor.
Definition SDL3pp_mixer.h:1717
constexpr Audio(AudioRaw resource) noexcept
Constructs from raw Audio.
Definition SDL3pp_mixer.h:1711
constexpr Audio & operator=(Audio &&other) noexcept
Assignment operator.
Definition SDL3pp_mixer.h:1936
~Audio()
Destructor.
Definition SDL3pp_mixer.h:1933
Base class to Group.
Definition SDL3pp_mixer.h:3493
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An opaque object that represents a grouping of tracks.
Definition SDL3pp_mixer.h:3588
~Group()
Destructor.
Definition SDL3pp_mixer.h:3642
constexpr Group & operator=(Group &&other) noexcept
Assignment operator.
Definition SDL3pp_mixer.h:3645
constexpr Group(GroupRaw resource) noexcept
Constructs from raw Group.
Definition SDL3pp_mixer.h:3598
constexpr Group(Group &&other) noexcept
Move constructor.
Definition SDL3pp_mixer.h:3604
Wrapper to be used as parameter to LoadFile_IO() and SaveFile_IO() and similar.
Definition SDL3pp_iostream.h:2243
IOStreamRef stream
The IOStream to read from or write to.
Definition SDL3pp_iostream.h:2244
bool closeio
Whether to close the IOStream after the operation.
Definition SDL3pp_iostream.h:2245
Definition SDL3pp_callbackWrapper.h:169
Base class to Mixer.
Definition SDL3pp_mixer.h:273
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An opaque object that represents a mixer.
Definition SDL3pp_mixer.h:1243
constexpr Mixer(MixerRaw resource) noexcept
Constructs from raw Mixer.
Definition SDL3pp_mixer.h:1253
constexpr Mixer(Mixer &&other) noexcept
Move constructor.
Definition SDL3pp_mixer.h:1259
~Mixer()
Destructor.
Definition SDL3pp_mixer.h:1342
constexpr Mixer & operator=(Mixer &&other) noexcept
Assignment operator.
Definition SDL3pp_mixer.h:1345
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93
Base class to Track.
Definition SDL3pp_mixer.h:2107
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An opaque object that represents a source of sound output to be mixed.
Definition SDL3pp_mixer.h:3355
constexpr Track & operator=(Track &&other) noexcept
Assignment operator.
Definition SDL3pp_mixer.h:3406
constexpr Track(TrackRaw resource) noexcept
Constructs from raw Track.
Definition SDL3pp_mixer.h:3365
constexpr Track(Track &&other) noexcept
Move constructor.
Definition SDL3pp_mixer.h:3371
~Track()
Destructor.
Definition SDL3pp_mixer.h:3403