SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::MixerRef Struct Reference

Reference for Mixer. More...

Inheritance diagram for SDL::MixerRef:
Inheritance graph
[legend]
Collaboration diagram for SDL::MixerRef:
Collaboration graph
[legend]

Public Member Functions

constexpr MixerRef (MixerRaw resource) noexcept
 Constructs from raw Mixer. More...
 
constexpr MixerRef (const Mixer &resource) noexcept
 Constructs from Mixer. More...
 
constexpr MixerRef (Mixer &&resource) noexcept
 Constructs from Mixer. More...
 
constexpr MixerRef (const MixerRef &other) noexcept
 Copy constructor.
 
constexpr MixerRef (MixerRef &&other) noexcept
 Move constructor.
 
 ~MixerRef ()
 Destructor.
 
MixerRefoperator= (const MixerRef &other) noexcept
 Assignment operator.
 
constexpr operator MixerRaw () const noexcept
 Converts to MixerRaw.
 
constexpr Mixer (std::nullptr_t=nullptr) noexcept
 Default ctor.
 
constexpr Mixer (MixerRaw resource) noexcept
 Constructs from raw Mixer. More...
 
constexpr Mixer (const Mixer &other) noexcept=delete
 Copy constructor.
 
constexpr Mixer (Mixer &&other) noexcept
 Move constructor.
 
constexpr Mixer (const MixerRef &other)=delete
 
constexpr Mixer (MixerRef &&other)=delete
 
 Mixer (AudioDeviceRef devid, const AudioSpec &spec)
 Create a mixer that plays sound directly to an audio device. More...
 
 Mixer (const AudioSpec &spec)
 Create a mixer that generates audio to a memory buffer. More...
 
- Public Member Functions inherited from SDL::Mixer
constexpr Mixer (std::nullptr_t=nullptr) noexcept
 Default ctor.
 
constexpr Mixer (MixerRaw resource) noexcept
 Constructs from raw Mixer. More...
 
constexpr Mixer (const Mixer &other) noexcept=delete
 Copy constructor.
 
constexpr Mixer (Mixer &&other) noexcept
 Move constructor.
 
constexpr Mixer (const MixerRef &other)=delete
 
constexpr Mixer (MixerRef &&other)=delete
 
 Mixer (AudioDeviceRef devid, const AudioSpec &spec)
 Create a mixer that plays sound directly to an audio device. More...
 
 Mixer (const AudioSpec &spec)
 Create a mixer that generates audio to a memory buffer. More...
 
 ~Mixer ()
 Destructor.
 
constexpr Mixeroperator= (Mixer &&other) noexcept
 Assignment operator.
 
Mixeroperator= (const Mixer &other)=delete
 Assignment operator.
 
constexpr MixerRaw get () const noexcept
 Retrieves underlying MixerRaw.
 
constexpr MixerRaw release () noexcept
 Retrieves underlying MixerRaw and clear this.
 
constexpr auto operator<=> (const Mixer &other) const noexcept=default
 Comparison.
 
constexpr operator bool () const noexcept
 Converts to bool.
 
void Destroy ()
 Free a mixer. More...
 
PropertiesRef GetProperties ()
 Get the properties associated with a mixer. More...
 
void GetFormat (AudioSpec *spec)
 Get the audio format a mixer is generating. More...
 
MixerLock Lock ()
 Lock a mixer by obtaining its internal mutex. More...
 
void Unlock (MixerLock &&lock)
 Unlock a mixer previously locked by a call to Mixer.Lock(). More...
 
Audio LoadAudio_IO (IOStreamRef io, bool predecode, bool closeio=false)
 Load audio for playback from an IOStream. More...
 
Audio LoadAudio (StringParam path, bool predecode)
 Load audio for playback from a file. More...
 
Audio LoadAudioNoCopy (SourceBytes data, bool free_when_done)
 Load audio for playback from a memory buffer without making a copy. More...
 
Audio LoadRawAudio_IO (IOStreamRef io, const AudioSpec &spec, bool closeio=false)
 Load raw PCM data from an IOStream. More...
 
Audio LoadRawAudio (SourceBytes data, const AudioSpec &spec)
 Load raw PCM data from a memory buffer. More...
 
Audio LoadRawAudioNoCopy (SourceBytes data, const AudioSpec &spec, bool free_when_done)
 Load raw PCM data from a memory buffer without making a copy. More...
 
Audio CreateSineWaveAudio (int hz, float amplitude, Sint64 ms)
 Create a Audio that generates a sinewave. More...
 
TrackRef CreateTrack ()
 Create a new track on a mixer. More...
 
OwnArray< TrackRefGetTaggedTracks (StringParam tag)
 Get all tracks with a specific tag. More...
 
void PlayTag (StringParam tag, PropertiesRef options)
 Start (or restart) mixing all tracks with a specific tag for playback. More...
 
bool PlayAudio (AudioRef audio)
 Play a Audio from start to finish without any management. More...
 
void StopAllTracks (Sint64 fade_out_ms)
 Halt all currently-playing tracks, possibly fading out over time. More...
 
void StopTag (StringParam tag, Sint64 fade_out_ms)
 Halt all tracks with a specific tag, possibly fading out over time. More...
 
void PauseAllTracks ()
 Pause all currently-playing tracks. More...
 
void PauseTag (StringParam tag)
 Pause all tracks with a specific tag. More...
 
void ResumeAllTracks ()
 Resume all currently-paused tracks. More...
 
void ResumeTag (StringParam tag)
 Resume all tracks with a specific tag. More...
 
void SetGain (float gain)
 Set a mixer's master gain control. More...
 
float GetGain ()
 Get a mixer's master gain control. More...
 
void SetTagGain (StringParam tag, float gain)
 Set the gain control of all tracks with a specific tag. More...
 
void SetFrequencyRatio (float ratio)
 Set a mixer's master frequency ratio. More...
 
float GetFrequencyRatio ()
 Get a mixer's master frequency ratio. More...
 
GroupRef CreateGroup ()
 Create a mixing group. More...
 
void SetPostMixCallback (PostMixCallback cb, void *userdata)
 Set a callback that fires when all mixing has completed. More...
 
void SetPostMixCallback (PostMixCB cb)
 Set a callback that fires when all mixing has completed. More...
 
int Generate (TargetBytes buffer)
 Generate mixer output when not driving an audio device. More...
 

Detailed Description

This does not take ownership!

Constructor & Destructor Documentation

◆ MixerRef() [1/3]

constexpr SDL::MixerRef::MixerRef ( MixerRaw  resource)
inlineconstexprnoexcept
Parameters
resourcea MixerRaw.

This does not takes ownership!

◆ MixerRef() [2/3]

constexpr SDL::MixerRef::MixerRef ( const Mixer resource)
inlineconstexprnoexcept
Parameters
resourcea Mixer.

This does not takes ownership!

◆ MixerRef() [3/3]

constexpr SDL::MixerRef::MixerRef ( Mixer &&  resource)
inlineconstexprnoexcept
Parameters
resourcea Mixer.

This will release the ownership from resource!

Member Function Documentation

◆ Mixer() [1/3]

SDL::Mixer::Mixer ( AudioDeviceRef  devid,
const AudioSpec spec 
)
inline

This is usually the function you want, vs CreateMixer().

You can choose a specific device ID to open, following SDL's usual rules, but often the correct choice is to specify AUDIO_DEVICE_DEFAULT_PLAYBACK and let SDL figure out what device to use (and seamlessly transition you to new hardware if the default changes).

Only playback devices make sense here. Attempting to open a recording device will fail.

This will call Init(INIT_AUDIO) internally; it's safe to call Init() before this call, too, if you intend to enumerate audio devices to choose one to open here.

An audio format can be requested, and the system will try to set the hardware to those specifications, or as close as possible, but this is just a hint. SDL_mixer will handle all data conversion behind the scenes in any case, and specifying a nullptr spec is a reasonable choice. The best reason to specify a format is because you know all your data is in that format and it might save some unnecessary CPU time on conversion.

The actual device format chosen is available through Mixer.GetFormat().

Once a mixer is created, next steps are usually to load audio (through Mixer.LoadAudio() and friends), create a track (Mixer.CreateTrack()), and play that audio through that track.

When done with the mixer, it can be destroyed with Mixer.Destroy().

Parameters
devidthe device to open for playback, or AUDIO_DEVICE_DEFAULT_PLAYBACK for the default.
specthe audio format to request from the device. May be nullptr.
Postcondition
a mixer that can be used to play audio on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL_mixer 3.0.0.
See also
CreateMixer
Mixer.Destroy

◆ Mixer() [2/3]

SDL::Mixer::Mixer ( const AudioSpec spec)
inline

Usually you want CreateMixerDevice() instead of this function. The mixer created here can be used with Mixer.Generate() to produce more data on demand, as fast as desired.

An audio format must be specified. This is the format it will output in. This cannot be nullptr.

Once a mixer is created, next steps are usually to load audio (through Mixer.LoadAudio() and friends), create a track (Mixer.CreateTrack()), and play that audio through that track.

When done with the mixer, it can be destroyed with Mixer.Destroy().

Parameters
specthe audio format that mixer will generate.
Postcondition
a mixer that can be used to generate audio on success.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL_mixer 3.0.0.
See also
CreateMixerDevice
Mixer.Destroy

◆ Mixer() [3/3]

constexpr SDL::Mixer::Mixer ( MixerRaw  resource)
inlineexplicitconstexprnoexcept
Parameters
resourcea MixerRaw to be wrapped.

This assumes the ownership, call release() if you need to take back.


The documentation for this struct was generated from the following file: