//
// Generated by Brutal.Sdl.Generate; do not edit by hand.
#nullable enable
namespace Brutal.SdlApi.Mixer
{
public static unsafe partial class SdlMixer
{
///
/// Get the version of SDL_mixer that is linked against your program.
///
/// the version of the linked library.
///
///
/// If you are linking to SDL_mixer dynamically, then it is possible that the
/// current version will be different than the version you compiled against.
/// This function returns the current version, while SDL_MIXER_VERSION is the
/// version you compiled with.
///
///
/// This function may be called safely at any time, even before MIX_Init().
///
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static int Version() => PInvoke.Version();
///
/// Ergonomic wrapper over MIX_Init. Throws instead of returning false on failure.
///
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void Init()
{
if (PInvoke.Init() == 0)
{
throw SdlException.FromError("MIX_Init failed");
}
}
///
/// Report the number of audio decoders available for use.
///
/// the number of decoders available.
///
///
/// An audio decoder is what turns specific audio file formats into usable PCM
/// data. For example, there might be an MP3 decoder, or a WAV decoder, etc.
/// SDL_mixer probably has several decoders built in.
///
///
/// The return value can be used to call MIX_GetAudioDecoder() in a loop.
///
///
/// The number of decoders available is decided during MIX_Init() and does not
/// change until the library is deinitialized.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static int GetNumAudioDecoders() => PInvoke.GetNumAudioDecoders();
///
/// Report the name of a specific audio decoders.
///
/// the index of the decoder to query.
///
/// a UTF-8 (really, ASCII) string of the decoder's name, or NULL if
/// index is invalid.
///
///
///
/// An audio decoder is what turns specific audio file formats into usable PCM
/// data. For example, there might be an MP3 decoder, or a WAV decoder, etc.
/// SDL_mixer probably has several decoders built in.
///
///
/// The names are capital English letters and numbers, low-ASCII. They don't
/// necessarily map to a specific file format; Some decoders, like "XMP"
/// operate on multiple file types, and more than one decoder might handle the
/// same file type, like "DRMP3" vs "MPG123". Note that in that last example,
/// neither decoder is called "MP3".
///
///
/// The index of a specific decoder is decided during MIX_Init() and does not
/// change until the library is deinitialized. Valid indices are between zero
/// and the return value of MIX_GetNumAudioDecoders().
///
///
/// The returned pointer is const memory owned by SDL_mixer; do not free it.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static string? GetAudioDecoder(int index) => PInvoke.GetAudioDecoder(index);
///
/// Ergonomic wrapper over MIX_CreateMixerDevice. Throws instead of returning a null handle on failure.
///
///
/// the device to open for playback, or
/// SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK for the default.
///
/// the audio format to request from the device. May be NULL.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixMixer CreateMixerDevice(uint devid, SdlAudioSpec* spec)
{
MixMixer result = PInvoke.CreateMixerDevice(devid, spec);
if (result.IsNull())
{
throw SdlException.FromError("MIX_CreateMixerDevice failed");
}
return result;
}
///
/// Ergonomic wrapper over MIX_CreateMixer. Throws instead of returning a null handle on failure.
///
/// the audio format that mixer will generate.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixMixer CreateMixer(SdlAudioSpec* spec)
{
MixMixer result = PInvoke.CreateMixer(spec);
if (result.IsNull())
{
throw SdlException.FromError("MIX_CreateMixer failed");
}
return result;
}
///
/// Free a mixer.
///
/// the mixer to destroy.
///
///
/// If this mixer was created with MIX_CreateMixerDevice(), this function will
/// also close the audio device and call SDL_QuitSubSystem(SDL_INIT_AUDIO).
///
///
/// Any MIX_Group or MIX_Track created for this mixer will also be destroyed.
/// Do not access them again or attempt to destroy them after the device is
/// destroyed. MIX_Audio objects will not be destroyed, since they can be
/// shared between mixers (but those will all be destroyed during MIX_Quit()).
///
///
///
/// If this is used with a MIX_Mixer from MIX_CreateMixerDevice,
/// then this function should only be called on the main thread.
/// If this is used with a MIX_Mixer from MIX_CreateMixer, then
/// it is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
///
public static void DestroyMixer(MixMixer mixer)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
PInvoke.DestroyMixer(mixer);
}
///
/// Get the properties associated with a mixer.
///
/// the mixer to query.
///
/// a valid property ID on success or 0 on failure; call
/// SDL_GetError() for more information.
///
///
///
/// The following read-only properties are provided by SDL_mixer:
///
///
/// - MIX_PROP_MIXER_DEVICE_NUMBER: the SDL_AudioDeviceID that this mixer has
/// opened for playback. This will be zero (no device) if the mixer was
/// created with Mix_CreateMixer() instead of Mix_CreateMixerDevice().
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static uint GetMixerProperties(MixMixer mixer)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetMixerProperties(mixer);
}
///
/// Ergonomic wrapper over MIX_GetMixerFormat. Throws instead of returning false on failure.
///
/// the mixer to query.
/// where to store the mixer audio format.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void GetMixerFormat(MixMixer mixer, SdlAudioSpec* spec)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.GetMixerFormat(mixer, spec) == 0)
{
throw SdlException.FromError("MIX_GetMixerFormat failed");
}
}
///
/// Lock a mixer by obtaining its internal mutex.
///
/// the mixer to lock. May be NULL.
///
///
/// While locked, the mixer will not be able to mix more audio or change its
/// internal state in another thread. Those other threads will block until the
/// mixer is unlocked again.
///
///
/// Under the hood, this function calls SDL_LockMutex(), so all the same rules
/// apply: the lock can be recursive, it must be unlocked the same number of
/// times from the same thread that locked it, etc.
///
///
/// Just about every SDL_mixer API also locks the mixer while doing its work,
/// as does the SDL audio device thread while actual mixing is in progress, so
/// basic use of this library never requires the app to explicitly lock the
/// device to be thread safe. There are two scenarios where this can be useful,
/// however:
///
///
/// - The app has a provided a callback that the mixing thread might call, and
/// there is some app state that needs to be protected against race
/// conditions as changes are made and mixing progresses simultaneously. Any
/// lock can be used for this, but this is a conveniently-available lock.
/// - The app wants to make multiple, atomic changes to the mix. For example,
/// to start several tracks at the exact same moment, one would lock the
/// mixer, call MIX_PlayTrack multiple times, and then unlock again; all the
/// tracks will start mixing on the same sample frame.
///
///
/// Each call to this function must be paired with a call to MIX_UnlockMixer
/// from the same thread. It is safe to lock a mixer multiple times; it remains
/// locked until the final matching unlock call.
///
///
/// Do not lock the mixer for significant amounts of time, or it can cause
/// audio dropouts. Just do simple things quickly and unlock again.
///
///
/// Locking a NULL mixer is a safe no-op.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static void LockMixer(MixMixer mixer)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
PInvoke.LockMixer(mixer);
}
///
/// Unlock a mixer previously locked by a call to MIX_LockMixer().
///
/// the mixer to unlock. May be NULL.
///
///
/// While locked, the mixer will not be able to mix more audio or change its
/// internal state another thread. Those other threads will block until the
/// mixer is unlocked again.
///
///
/// Under the hood, this function calls SDL_LockMutex(), so all the same rules
/// apply: the lock can be recursive, it must be unlocked the same number of
/// times from the same thread that locked it, etc.
///
///
/// Unlocking a NULL mixer is a safe no-op.
///
///
///
/// This call must be paired with a previous MIX_LockMixer call
/// on the same thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static void UnlockMixer(MixMixer mixer)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
PInvoke.UnlockMixer(mixer);
}
///
/// Ergonomic wrapper over MIX_LoadAudio_IO. Throws instead of returning a null handle on failure.
///
/// a mixer this audio is intended to be used with. May be NULL.
/// the SDL_IOStream to load data from.
/// if true, data will be fully uncompressed before returning.
///
/// true if SDL_mixer should close io before returning
/// (success or failure).
///
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixAudio LoadAudioIO(MixMixer mixer, nint io, bool predecode, bool closeio)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
MixAudio result = PInvoke.LoadAudioIO(
mixer,
io,
predecode ? (byte)1 : (byte)0,
closeio ? (byte)1 : (byte)0
);
if (result.IsNull())
{
throw SdlException.FromError("MIX_LoadAudio_IO failed");
}
return result;
}
///
/// Ergonomic wrapper over MIX_LoadAudio. Throws instead of returning a null handle on failure.
///
/// a mixer this audio is intended to be used with. May be NULL.
/// the path on the filesystem to load data from.
/// if true, data will be fully uncompressed before returning.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixAudio LoadAudio(MixMixer mixer, string path, bool predecode)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
MixAudio result = PInvoke.LoadAudio(mixer, path, predecode ? (byte)1 : (byte)0);
if (result.IsNull())
{
throw SdlException.FromError("MIX_LoadAudio failed");
}
return result;
}
///
/// Ergonomic wrapper over MIX_LoadAudioNoCopy. Throws instead of returning a null handle on failure.
///
/// a mixer this audio is intended to be used with. May be NULL.
/// the buffer where the audio data lives.
/// the size, in bytes, of the buffer.
///
/// if true, data will be given to SDL_free() when the
/// MIX_Audio is destroyed.
///
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixAudio LoadAudioNoCopy(MixMixer mixer, void* data, nuint datalen, bool free_when_done)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
MixAudio result = PInvoke.LoadAudioNoCopy(mixer, data, datalen, free_when_done ? (byte)1 : (byte)0);
if (result.IsNull())
{
throw SdlException.FromError("MIX_LoadAudioNoCopy failed");
}
return result;
}
///
/// Ergonomic wrapper over MIX_LoadAudioWithProperties. Throws instead of returning a null handle on
/// failure.
///
/// a set of properties on how to load audio.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixAudio LoadAudioWithProperties(uint props)
{
MixAudio result = PInvoke.LoadAudioWithProperties(props);
if (result.IsNull())
{
throw SdlException.FromError("MIX_LoadAudioWithProperties failed");
}
return result;
}
///
/// Ergonomic wrapper over MIX_LoadRawAudio_IO. Throws instead of returning a null handle on failure.
///
/// a mixer this audio is intended to be used with. May be NULL.
/// the SDL_IOStream to load data from.
/// what format the raw data is in.
///
/// true if SDL_mixer should close io before returning
/// (success or failure).
///
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixAudio LoadRawAudioIO(MixMixer mixer, nint io, SdlAudioSpec* spec, bool closeio)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
MixAudio result = PInvoke.LoadRawAudioIO(mixer, io, spec, closeio ? (byte)1 : (byte)0);
if (result.IsNull())
{
throw SdlException.FromError("MIX_LoadRawAudio_IO failed");
}
return result;
}
///
/// Ergonomic wrapper over MIX_LoadRawAudio. Throws instead of returning a null handle on failure.
///
/// a mixer this audio is intended to be used with. May be NULL.
/// the raw PCM data to load.
/// the size, in bytes, of the raw PCM data.
/// what format the raw data is in.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixAudio LoadRawAudio(MixMixer mixer, void* data, nuint datalen, SdlAudioSpec* spec)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
MixAudio result = PInvoke.LoadRawAudio(mixer, data, datalen, spec);
if (result.IsNull())
{
throw SdlException.FromError("MIX_LoadRawAudio failed");
}
return result;
}
///
/// Ergonomic wrapper over MIX_LoadRawAudioNoCopy. Throws instead of returning a null handle on
/// failure.
///
/// a mixer this audio is intended to be used with. May be NULL.
/// the buffer where the raw PCM data lives.
/// the size, in bytes, of the buffer.
/// what format the raw data is in.
///
/// if true, data will be given to SDL_free() when the
/// MIX_Audio is destroyed.
///
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixAudio LoadRawAudioNoCopy(
MixMixer mixer,
void* data,
nuint datalen,
SdlAudioSpec* spec,
bool free_when_done
)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
MixAudio result = PInvoke.LoadRawAudioNoCopy(
mixer,
data,
datalen,
spec,
free_when_done ? (byte)1 : (byte)0
);
if (result.IsNull())
{
throw SdlException.FromError("MIX_LoadRawAudioNoCopy failed");
}
return result;
}
///
/// Ergonomic wrapper over MIX_CreateSineWaveAudio. Throws instead of returning a null handle on
/// failure.
///
/// a mixer this audio is intended to be used with. May be NULL.
/// the sinewave's frequency in Hz.
/// the sinewave's amplitude from 0.0f to 1.0f.
///
/// the maximum number of milliseconds of audio to generate, or less
/// than zero to generate infinite audio.
///
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixAudio CreateSineWaveAudio(MixMixer mixer, int hz, float amplitude, long ms)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
MixAudio result = PInvoke.CreateSineWaveAudio(mixer, hz, amplitude, ms);
if (result.IsNull())
{
throw SdlException.FromError("MIX_CreateSineWaveAudio failed");
}
return result;
}
///
/// Get the properties associated with a MIX_Audio.
///
/// the audio to query.
///
/// a valid property ID on success or 0 on failure; call
/// SDL_GetError() for more information.
///
///
///
/// SDL_mixer offers some properties of its own, but this can also be a
/// convenient place to store app-specific data.
///
///
/// A SDL_PropertiesID is created the first time this function is called for a
/// given MIX_Audio, if necessary.
///
///
/// The following read-only properties are provided by SDL_mixer:
///
///
/// - MIX_PROP_METADATA_TITLE_STRING: the audio's title ("Smells Like Teen
/// Spirit").
/// - MIX_PROP_METADATA_ARTIST_STRING: the audio's artist name ("Nirvana").
/// - MIX_PROP_METADATA_ALBUM_STRING: the audio's album name ("Nevermind").
/// - MIX_PROP_METADATA_COPYRIGHT_STRING: the audio's copyright info
/// ("Copyright (c) 1991")
/// - MIX_PROP_METADATA_TRACK_NUMBER: the audio's track number on the album
/// (1)
/// - MIX_PROP_METADATA_TOTAL_TRACKS_NUMBER: the total tracks on the album
/// (13)
/// - MIX_PROP_METADATA_YEAR_NUMBER: the year the audio was released (1991)
/// - MIX_PROP_METADATA_DURATION_FRAMES_NUMBER: The sample frames worth of
/// PCM data that comprise this audio. It might be off by a little if the
/// decoder only knows the duration as a unit of time.
/// - MIX_PROP_METADATA_DURATION_INFINITE_BOOLEAN: if true, audio never runs
/// out of sound to generate. This isn't necessarily always known to
/// SDL_mixer, though.
///
///
/// Other properties, documented with MIX_LoadAudioWithProperties(), may also
/// be present.
///
///
/// Note that the metadata properties are whatever SDL_mixer finds in things
/// like ID3 tags, and they often have very little standardized formatting, may
/// be missing, and can be completely wrong if the original data is
/// untrustworthy (like an MP3 from a P2P file sharing service).
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static uint GetAudioProperties(MixAudio audio) => PInvoke.GetAudioProperties(audio);
///
/// Get the length of a MIX_Audio's playback in sample frames.
///
/// the audio to query.
///
/// the length of the audio in sample frames, or MIX_DURATION_UNKNOWN
/// or MIX_DURATION_INFINITE.
///
///
///
/// This information is also available via the
/// MIX_PROP_METADATA_DURATION_FRAMES_NUMBER property, but it's common enough
/// to provide a simple accessor function.
///
///
/// This reports the length of the data in sample frames, so sample-perfect
/// mixing can be possible. Sample frames are only meaningful as a measure of
/// time if the sample rate (frequency) is also known. To convert from sample
/// frames to milliseconds, use MIX_AudioFramesToMS().
///
///
/// Not all audio file formats can report the complete length of the data they
/// will produce through decoding: some can't calculate it, some might produce
/// infinite audio.
///
///
/// Also, some file formats can only report duration as a unit of time, which
/// means SDL_mixer might have to estimate sample frames from that information.
/// With less precision, the reported duration might be off by a few sample
/// frames in either direction.
///
///
/// This will return a value >= 0 if a duration is known. It might also return
/// MIX_DURATION_UNKNOWN or MIX_DURATION_INFINITE.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static long GetAudioDuration(MixAudio audio) => PInvoke.GetAudioDuration(audio);
///
/// Ergonomic wrapper over MIX_GetAudioFormat. Throws instead of returning false on failure.
///
/// the audio to query.
/// on success, audio format details will be stored here.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void GetAudioFormat(MixAudio audio, SdlAudioSpec* spec)
{
if (PInvoke.GetAudioFormat(audio, spec) == 0)
{
throw SdlException.FromError("MIX_GetAudioFormat failed");
}
}
///
/// Destroy the specified audio.
///
/// the audio to destroy.
///
///
/// MIX_Audio is reference-counted internally, so this function only unrefs it.
/// If doing so causes the reference count to drop to zero, the MIX_Audio will
/// be deallocated. This allows the system to safely operate if the audio is
/// still assigned to a MIX_Track at the time of destruction. The actual
/// destroying will happen when the track stops using it.
///
///
/// But from the caller's perspective, once this function is called, it should
/// assume the audio pointer has become invalid.
///
///
/// Destroying a NULL MIX_Audio is a legal no-op.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static void DestroyAudio(MixAudio audio) => PInvoke.DestroyAudio(audio);
///
/// Ergonomic wrapper over MIX_CreateTrack. Throws instead of returning a null handle on failure.
///
/// the mixer on which to create this track.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixTrack CreateTrack(MixMixer mixer)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
MixTrack result = PInvoke.CreateTrack(mixer);
if (result.IsNull())
{
throw SdlException.FromError("MIX_CreateTrack failed");
}
return result;
}
///
/// Destroy the specified track.
///
/// the track to destroy.
///
///
/// If the track is currently playing, it will be stopped immediately, without
/// any fadeout. If there is a callback set through
/// MIX_SetTrackStoppedCallback(), it will not be called.
///
///
/// If the mixer is currently mixing in another thread, this will block until
/// it finishes. Destroying a track from the mixer thread itself (during a
/// callback) will cause it to be destroyed as soon as this iteration of the
/// mixer thread is not using it; in this scenario, destroying a track and then
/// making futher changes to it is considered undefined behavior.
///
///
/// Destroying a NULL MIX_Track is a legal no-op.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static void DestroyTrack(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
PInvoke.DestroyTrack(track);
}
///
/// Get the properties associated with a track.
///
/// the track to query.
///
/// a valid property ID on success or 0 on failure; call
/// SDL_GetError() for more information.
///
///
///
/// Currently SDL_mixer assigns no properties of its own to a track, but this
/// can be a convenient place to store app-specific data.
///
///
/// A SDL_PropertiesID is created the first time this function is called for a
/// given track.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static uint GetTrackProperties(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetTrackProperties(track);
}
///
/// Ergonomic wrapper over MIX_GetTrackMixer.
///
/// the track to query.
///
/// Borrowed handle: the returned handle is owned by SDL (or by another object) and must not be
/// disposed. Do not call on it; doing so would free a resource this
/// call does not own. A null handle is returned on failure.
///
public static MixMixer GetTrackMixer(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetTrackMixer(track);
}
///
/// Ergonomic wrapper over MIX_SetTrackAudio. Throws instead of returning false on failure.
///
/// the track on which to set a new audio input.
/// the new audio input to set. May be NULL.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrackAudio(MixTrack track, MixAudio audio)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrackAudio(track, audio) == 0)
{
throw SdlException.FromError("MIX_SetTrackAudio failed");
}
}
///
/// Ergonomic wrapper over MIX_SetTrackAudioStream. Throws instead of returning false on failure.
///
/// the track on which to set a new audio input.
/// the audio stream to use as the track's input.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrackAudioStream(MixTrack track, SdlAudioStream stream)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrackAudioStream(track, stream) == 0)
{
throw SdlException.FromError("MIX_SetTrackAudioStream failed");
}
}
///
/// Ergonomic wrapper over MIX_SetTrackIOStream. Throws instead of returning false on failure.
///
/// the track on which to set a new audio input.
/// the new i/o stream to use as the track's input.
/// if true, close the stream when done with it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrackIOStream(MixTrack track, nint io, bool closeio)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrackIOStream(track, io, closeio ? (byte)1 : (byte)0) == 0)
{
throw SdlException.FromError("MIX_SetTrackIOStream failed");
}
}
///
/// Ergonomic wrapper over MIX_SetTrackRawIOStream. Throws instead of returning false on failure.
///
/// the track on which to set a new audio input.
/// the new i/o stream to use as the track's input.
/// the format of the PCM data that the SDL_IOStream will provide.
/// if true, close the stream when done with it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrackRawIOStream(MixTrack track, nint io, SdlAudioSpec* spec, bool closeio)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrackRawIOStream(track, io, spec, closeio ? (byte)1 : (byte)0) == 0)
{
throw SdlException.FromError("MIX_SetTrackRawIOStream failed");
}
}
///
/// Ergonomic wrapper over MIX_TagTrack. Throws instead of returning false on failure.
///
/// the track to add a tag to.
/// the tag to add.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void TagTrack(MixTrack track, string tag)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.TagTrack(track, tag) == 0)
{
throw SdlException.FromError("MIX_TagTrack failed");
}
}
///
/// Remove an arbitrary tag from a track.
///
/// the track from which to remove a tag.
/// the tag to remove, or NULL to remove all current tags.
///
///
/// A tag can be any valid C string in UTF-8 encoding. It can be useful to
/// group tracks in various ways. For example, everything in-game might be
/// marked as "game", so when the user brings up the settings menu, the app can
/// pause all tracks involved in gameplay at once, but keep background music
/// and menu sound effects running.
///
///
/// It's legal to remove a tag that the track doesn't have; this function
/// doesn't report errors, so this simply does nothing.
///
///
/// Specifying a NULL tag will remove all tags on a track.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static void UntagTrack(MixTrack track, string tag)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
PInvoke.UntagTrack(track, tag);
}
///
/// Ergonomic wrapper over MIX_GetTrackTags.
///
/// the track to query.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
///
/// SDL returns a freshly SDL_malloc'd buffer for this call; the returned array is a managed copy, and
/// the native buffer is freed with SDL_free before this method returns.
///
public static string[] GetTrackTags(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
int count;
var ptr = PInvoke.GetTrackTags(track, &count);
if (ptr is null)
throw SdlException.FromError("MIX_GetTrackTags failed");
try
{
var result = new string[count];
for (var i = 0; i < count; i++)
result[i] = Marshal.PtrToStringUTF8((nint)ptr[i])!;
return result;
}
finally
{
Sdl.PInvoke.Free(ptr);
}
}
///
/// Ergonomic wrapper over MIX_GetTaggedTracks.
///
/// the mixer to query.
/// the tag to search.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
///
/// SDL returns a freshly SDL_malloc'd buffer for this call; the returned array is a managed copy, and
/// the native buffer is freed with SDL_free before this method returns. Each element is a
/// borrowed handle: it is owned by SDL, not created by this call, and must not be disposed. Do not
/// call on any element.
///
public static MixTrack[] GetTaggedTracks(MixMixer mixer, string tag)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
int count;
var ptr = PInvoke.GetTaggedTracks(mixer, tag, &count);
if (ptr is null)
throw SdlException.FromError("MIX_GetTaggedTracks failed");
try
{
return new ReadOnlySpan(ptr, count).ToArray();
}
finally
{
Sdl.PInvoke.Free(ptr);
}
}
///
/// Ergonomic wrapper over MIX_SetTrackPlaybackPosition. Throws instead of returning false on failure.
///
/// the track to change.
/// the sample frame position to seek to.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrackPlaybackPosition(MixTrack track, long frames)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrackPlaybackPosition(track, frames) == 0)
{
throw SdlException.FromError("MIX_SetTrackPlaybackPosition failed");
}
}
///
/// Get the current input position of a playing track.
///
/// the track to change.
///
/// the track's current sample frame position, or -1 on error; call
/// SDL_GetError() for details.
///
///
///
/// (Not to be confused with MIX_GetTrack3DPosition(), which is positioning of
/// the track in 3D space, not the playback position of its audio data.)
///
///
/// Position is defined in sample frames of decoded audio, not units of time,
/// so that sample-perfect mixing can be achieved. To instead operate in units
/// of time, use MIX_TrackFramesToMS() to convert the return value to
/// milliseconds.
///
///
/// Stopped and paused tracks will report the position when they halted.
/// Playing tracks will report the current position, which will change over
/// time.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static long GetTrackPlaybackPosition(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetTrackPlaybackPosition(track);
}
///
/// Query whether a given track is fading.
///
/// the track to query.
///
/// less than 0 if the track is fading out, greater than 0 if fading
/// in, zero otherwise.
///
///
///
/// This specifically checks if the track is not stopped (paused or playing),
/// and it is fading in or out, and returns the number of frames remaining in
/// the fade.
///
///
/// If fading out, the returned value will be negative. When fading in, the
/// returned value will be positive. If not fading, this function returns zero.
///
///
/// On various errors (MIX_Init() was not called, the track is NULL), this
/// returns 0, but there is no mechanism to distinguish errors from tracks that
/// aren't fading.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static long GetTrackFadeFrames(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetTrackFadeFrames(track);
}
///
/// Query how many loops remain for a given track.
///
/// the track to query.
///
/// the number of pending loops, zero if not looping, and -1 if
/// looping infinitely.
///
///
///
/// This returns the number of loops still pending; if a track will eventually
/// complete and loop to play again one more time, this will return 1. If a
/// track was looping but is on its final iteration of the loop (will stop
/// when this iteration completes), this will return zero.
///
///
/// A track that is looping infinitely will return -1. This value does not
/// report an error in this case.
///
///
/// A track that is stopped (not playing and not paused) will have zero loops
/// remaining.
///
///
/// On various errors (MIX_Init() was not called, the track is NULL), this
/// returns zero, but there is no mechanism to distinguish errors from
/// non-looping tracks.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static int GetTrackLoops(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetTrackLoops(track);
}
///
/// Ergonomic wrapper over MIX_SetTrackLoops. Throws instead of returning false on failure.
///
/// the track to configure.
///
/// new number of times to loop. Zero to disable looping, -1
/// to loop infinitely.
///
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrackLoops(MixTrack track, int num_loops)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrackLoops(track, num_loops) == 0)
{
throw SdlException.FromError("MIX_SetTrackLoops failed");
}
}
///
/// Ergonomic wrapper over MIX_GetTrackAudio.
///
/// the track to query.
///
/// Borrowed handle: the returned handle is owned by SDL (or by another object) and must not be
/// disposed. Do not call on it; doing so would free a resource this
/// call does not own. A null handle is returned on failure.
///
public static MixAudio GetTrackAudio(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetTrackAudio(track);
}
///
/// Ergonomic wrapper over MIX_GetTrackAudioStream.
///
/// the track to query.
///
/// Borrowed handle: the returned handle is owned by SDL (or by another object) and must not be
/// disposed. Do not call on it; doing so would free a resource this
/// call does not own. A null handle is returned on failure.
///
public static SdlAudioStream GetTrackAudioStream(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetTrackAudioStream(track);
}
///
/// Return the number of sample frames remaining to be mixed in a track.
///
/// the track to query.
/// the total sample frames still to be mixed, or -1 if unknown.
///
///
/// If the track is playing or paused, and its total duration is known, this
/// will report how much audio is left to mix. If the track is playing, future
/// calls to this function will report different values.
///
///
/// Remaining audio is defined in sample frames of decoded audio, not units
/// of time, so that sample-perfect mixing can be achieved. To instead operate
/// in units of time, use MIX_TrackFramesToMS() to convert the return value to
/// milliseconds.
///
///
/// This function does not take into account fade-outs or looping, just the
/// current mixing position vs the duration of the track.
///
///
/// If the duration of the track isn't known, or track is NULL, this function
/// returns -1. A stopped track reports 0.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static long GetTrackRemaining(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetTrackRemaining(track);
}
///
/// Convert milliseconds to sample frames for a track's current format.
///
/// the track to query.
/// the milliseconds to convert to track-specific sample frames.
///
/// Converted number of sample frames, or -1 for errors/no input; call
/// SDL_GetError() for details.
///
///
///
/// This calculates time based on the track's current input format, which can
/// change when its input does, and also if that input changes formats
/// mid-stream (for example, if decoding a file that is two MP3s concatenated
/// together).
///
///
/// On various errors (MIX_Init() was not called, the track is NULL), this
/// returns -1. If the track has no input, this returns -1. If ms is < 0,
/// this returns -1.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static long TrackMSToFrames(MixTrack track, long ms)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.TrackMSToFrames(track, ms);
}
///
/// Convert sample frames for a track's current format to milliseconds.
///
/// the track to query.
/// the track-specific sample frames to convert to milliseconds.
///
/// Converted number of milliseconds, or -1 for errors/no input; call
/// SDL_GetError() for details.
///
///
///
/// This calculates time based on the track's current input format, which can
/// change when its input does, and also if that input changes formats
/// mid-stream (for example, if decoding a file that is two MP3s concatenated
/// together).
///
///
/// Sample frames are more precise than milliseconds, so out of necessity, this
/// function will approximate by rounding down to the closest full millisecond.
///
///
/// On various errors (MIX_Init() was not called, the track is NULL), this
/// returns -1. If the track has no input, this returns -1. If frames is < 0,
/// this returns -1.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static long TrackFramesToMS(MixTrack track, long frames)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.TrackFramesToMS(track, frames);
}
///
/// Convert milliseconds to sample frames for a MIX_Audio's format.
///
/// the audio to query.
/// the milliseconds to convert to audio-specific sample frames.
///
/// Converted number of sample frames, or -1 for errors/no input; call
/// SDL_GetError() for details.
///
///
///
/// This calculates time based on the audio's initial format, even if the
/// format would change mid-stream.
///
///
/// If ms is < 0, this returns -1.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static long AudioMSToFrames(MixAudio audio, long ms) => PInvoke.AudioMSToFrames(audio, ms);
///
/// Convert sample frames for a MIX_Audio's format to milliseconds.
///
/// the audio to query.
/// the audio-specific sample frames to convert to milliseconds.
///
/// Converted number of milliseconds, or -1 for errors/no input; call
/// SDL_GetError() for details.
///
///
///
/// This calculates time based on the audio's initial format, even if the
/// format would change mid-stream.
///
///
/// Sample frames are more precise than milliseconds, so out of necessity, this
/// function will approximate by rounding down to the closest full millisecond.
///
///
/// If frames is < 0, this returns -1.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static long AudioFramesToMS(MixAudio audio, long frames) => PInvoke.AudioFramesToMS(audio, frames);
///
/// Convert milliseconds to sample frames at a specific sample rate.
///
/// the sample rate to use for conversion.
/// the milliseconds to convert to rate-specific sample frames.
///
/// Converted number of sample frames, or -1 for errors; call
/// SDL_GetError() for details.
///
///
///
/// If sample_rate is <= 0, this returns -1. If ms is < 0, this returns -1.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static long MSToFrames(int sample_rate, long ms) => PInvoke.MSToFrames(sample_rate, ms);
///
/// Convert sample frames, at a specific sample rate, to milliseconds.
///
/// the sample rate to use for conversion.
/// the rate-specific sample frames to convert to milliseconds.
///
/// Converted number of milliseconds, or -1 for errors; call
/// SDL_GetError() for details.
///
///
///
/// Sample frames are more precise than milliseconds, so out of necessity, this
/// function will approximate by rounding down to the closest full millisecond.
///
///
/// If sample_rate is <= 0, this returns -1. If frames is < 0, this returns
/// -1.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static long FramesToMS(int sample_rate, long frames) => PInvoke.FramesToMS(sample_rate, frames);
///
/// Ergonomic wrapper over MIX_PlayTrack. Throws instead of returning false on failure.
///
/// the track to start (or restart) mixing.
/// a set of properties that control playback. May be zero.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void PlayTrack(MixTrack track, uint options)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.PlayTrack(track, options) == 0)
{
throw SdlException.FromError("MIX_PlayTrack failed");
}
}
///
/// Ergonomic wrapper over MIX_PlayTag. Throws instead of returning false on failure.
///
/// the mixer on which to look for tagged tracks.
/// the tag to use when searching for tracks.
/// the set of options that will be applied to each track.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void PlayTag(MixMixer mixer, string tag, uint options)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.PlayTag(mixer, tag, options) == 0)
{
throw SdlException.FromError("MIX_PlayTag failed");
}
}
///
/// Ergonomic wrapper over MIX_PlayAudio. Throws instead of returning false on failure.
///
/// the mixer on which to play this audio.
/// the audio input to play.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void PlayAudio(MixMixer mixer, MixAudio audio)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.PlayAudio(mixer, audio) == 0)
{
throw SdlException.FromError("MIX_PlayAudio failed");
}
}
///
/// Ergonomic wrapper over MIX_StopTrack. Throws instead of returning false on failure.
///
/// the track to halt.
///
/// the number of sample frames to spend fading out to
/// silence before halting. 0 to stop immediately.
///
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void StopTrack(MixTrack track, long fade_out_frames)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.StopTrack(track, fade_out_frames) == 0)
{
throw SdlException.FromError("MIX_StopTrack failed");
}
}
///
/// Ergonomic wrapper over MIX_StopAllTracks. Throws instead of returning false on failure.
///
/// the mixer on which to stop all tracks.
///
/// the number of milliseconds to spend fading out to
/// silence before halting. 0 to stop immediately.
///
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void StopAllTracks(MixMixer mixer, long fade_out_ms)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.StopAllTracks(mixer, fade_out_ms) == 0)
{
throw SdlException.FromError("MIX_StopAllTracks failed");
}
}
///
/// Ergonomic wrapper over MIX_StopTag. Throws instead of returning false on failure.
///
/// the mixer on which to stop tracks.
/// the tag to use when searching for tracks.
///
/// the number of milliseconds to spend fading out to
/// silence before halting. 0 to stop immediately.
///
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void StopTag(MixMixer mixer, string tag, long fade_out_ms)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.StopTag(mixer, tag, fade_out_ms) == 0)
{
throw SdlException.FromError("MIX_StopTag failed");
}
}
///
/// Ergonomic wrapper over MIX_PauseTrack. Throws instead of returning false on failure.
///
/// the track to pause.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void PauseTrack(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.PauseTrack(track) == 0)
{
throw SdlException.FromError("MIX_PauseTrack failed");
}
}
///
/// Ergonomic wrapper over MIX_PauseAllTracks. Throws instead of returning false on failure.
///
/// the mixer on which to pause all tracks.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void PauseAllTracks(MixMixer mixer)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.PauseAllTracks(mixer) == 0)
{
throw SdlException.FromError("MIX_PauseAllTracks failed");
}
}
///
/// Ergonomic wrapper over MIX_PauseTag. Throws instead of returning false on failure.
///
/// the mixer on which to pause tracks.
/// the tag to use when searching for tracks.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void PauseTag(MixMixer mixer, string tag)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.PauseTag(mixer, tag) == 0)
{
throw SdlException.FromError("MIX_PauseTag failed");
}
}
///
/// Ergonomic wrapper over MIX_ResumeTrack. Throws instead of returning false on failure.
///
/// the track to resume.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void ResumeTrack(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.ResumeTrack(track) == 0)
{
throw SdlException.FromError("MIX_ResumeTrack failed");
}
}
///
/// Ergonomic wrapper over MIX_ResumeAllTracks. Throws instead of returning false on failure.
///
/// the mixer on which to resume all tracks.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void ResumeAllTracks(MixMixer mixer)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.ResumeAllTracks(mixer) == 0)
{
throw SdlException.FromError("MIX_ResumeAllTracks failed");
}
}
///
/// Ergonomic wrapper over MIX_ResumeTag. Throws instead of returning false on failure.
///
/// the mixer on which to resume tracks.
/// the tag to use when searching for tracks.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void ResumeTag(MixMixer mixer, string tag)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.ResumeTag(mixer, tag) == 0)
{
throw SdlException.FromError("MIX_ResumeTag failed");
}
}
///
/// Query if a track is currently playing.
///
/// the track to query.
/// true if playing, false otherwise.
///
///
/// If this returns true, the track is currently contributing to the mixer's
/// output (it's "playing"). It is not stopped nor paused.
///
///
/// On various errors (MIX_Init() was not called, the track is NULL), this
/// returns false, but there is no mechanism to distinguish errors from
/// non-playing tracks.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
///
///
///
///
public static bool TrackPlaying(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.TrackPlaying(track) != 0;
}
///
/// Query if a track is currently paused.
///
/// the track to query.
/// true if paused, false otherwise.
///
///
/// If this returns true, the track is not currently contributing to the
/// mixer's output but will when resumed (it's "paused"). It is not playing nor
/// stopped.
///
///
/// On various errors (MIX_Init() was not called, the track is NULL), this
/// returns false, but there is no mechanism to distinguish errors from
/// non-playing tracks.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
///
///
///
///
public static bool TrackPaused(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.TrackPaused(track) != 0;
}
///
/// Ergonomic wrapper over MIX_SetMixerGain. Throws instead of returning false on failure.
///
/// the mixer to adjust.
/// the new gain value.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetMixerGain(MixMixer mixer, float gain)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetMixerGain(mixer, gain) == 0)
{
throw SdlException.FromError("MIX_SetMixerGain failed");
}
}
///
/// Get a mixer's master gain control.
///
/// the mixer to query.
/// the mixer's current master gain.
///
///
/// This returns the last value set through MIX_SetMixerGain(), or 1.0f if no
/// value has ever been explicitly set.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
///
public static float GetMixerGain(MixMixer mixer)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetMixerGain(mixer);
}
///
/// Ergonomic wrapper over MIX_SetTrackGain. Throws instead of returning false on failure.
///
/// the track to adjust.
/// the new gain value.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrackGain(MixTrack track, float gain)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrackGain(track, gain) == 0)
{
throw SdlException.FromError("MIX_SetTrackGain failed");
}
}
///
/// Get a track's gain control.
///
/// the track to query.
/// the track's current gain.
///
///
/// This returns the last value set through MIX_SetTrackGain(), or 1.0f if no
/// value has ever been explicitly set.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
///
public static float GetTrackGain(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetTrackGain(track);
}
///
/// Ergonomic wrapper over MIX_SetTagGain. Throws instead of returning false on failure.
///
/// the mixer on which to look for tagged tracks.
/// the tag to use when searching for tracks.
/// the new gain value.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTagGain(MixMixer mixer, string tag, float gain)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTagGain(mixer, tag, gain) == 0)
{
throw SdlException.FromError("MIX_SetTagGain failed");
}
}
///
/// Ergonomic wrapper over MIX_SetMixerFrequencyRatio. Throws instead of returning false on failure.
///
/// the mixer to adjust.
/// the frequency ratio. Must be between 0.01f and 100.0f.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetMixerFrequencyRatio(MixMixer mixer, float ratio)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetMixerFrequencyRatio(mixer, ratio) == 0)
{
throw SdlException.FromError("MIX_SetMixerFrequencyRatio failed");
}
}
///
/// Get a mixer's master frequency ratio.
///
/// the mixer to query.
/// the mixer's current master frequency ratio.
///
///
/// This returns the last value set through MIX_SetMixerFrequencyRatio(), or
/// 1.0f if no value has ever been explicitly set.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
///
public static float GetMixerFrequencyRatio(MixMixer mixer)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetMixerFrequencyRatio(mixer);
}
///
/// Ergonomic wrapper over MIX_SetTrackFrequencyRatio. Throws instead of returning false on failure.
///
/// the track on which to change the frequency ratio.
/// the frequency ratio. Must be between 0.01f and 100.0f.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrackFrequencyRatio(MixTrack track, float ratio)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrackFrequencyRatio(track, ratio) == 0)
{
throw SdlException.FromError("MIX_SetTrackFrequencyRatio failed");
}
}
///
/// Query the frequency ratio of a track.
///
/// the track on which to query the frequency ratio.
///
/// the current frequency ratio, or 0.0f on failure; call
/// SDL_GetError() for more information.
///
///
///
/// The frequency ratio is used to adjust the rate at which audio data is
/// consumed. Changing this effectively modifies the speed and pitch of the
/// track's audio. A value greater than 1.0f will play the audio faster, and at
/// a higher pitch. A value less than 1.0f will play the audio slower, and at a
/// lower pitch. 1.0f is normal speed.
///
///
/// The default value is 1.0f.
///
///
/// On various errors (MIX_Init() was not called, the track is NULL), this
/// returns 0.0f. Since this is not a valid value to set, this can be seen as
/// an error state.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static float GetTrackFrequencyRatio(MixTrack track)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetTrackFrequencyRatio(track);
}
///
/// Ergonomic wrapper over MIX_SetTrackOutputChannelMap. Throws instead of returning false on failure.
///
/// the track to change.
/// the new channel map, NULL to reset to default.
/// The number of channels in the map.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrackOutputChannelMap(MixTrack track, int* chmap, int count)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrackOutputChannelMap(track, chmap, count) == 0)
{
throw SdlException.FromError("MIX_SetTrackOutputChannelMap failed");
}
}
///
/// Ergonomic wrapper over MIX_SetTrackStereo. Throws instead of returning false on failure.
///
/// the track to adjust.
/// the per-channel gains, or NULL to disable spatialization.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrackStereo(MixTrack track, MixStereoGains* gains)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrackStereo(track, gains) == 0)
{
throw SdlException.FromError("MIX_SetTrackStereo failed");
}
}
///
/// Ergonomic wrapper over MIX_SetTrack3DPosition. Throws instead of returning false on failure.
///
/// the track for which to set 3D position.
/// the new 3D position for the track. May be NULL.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrack3DPosition(MixTrack track, MixPoint3D* position)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrack3DPosition(track, position) == 0)
{
throw SdlException.FromError("MIX_SetTrack3DPosition failed");
}
}
///
/// Ergonomic wrapper over MIX_GetTrack3DPosition. Throws instead of returning false on failure.
///
/// the track to query.
/// on successful return, will contain the track's position.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void GetTrack3DPosition(MixTrack track, MixPoint3D* position)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.GetTrack3DPosition(track, position) == 0)
{
throw SdlException.FromError("MIX_GetTrack3DPosition failed");
}
}
///
/// Ergonomic wrapper over MIX_CreateGroup. Throws instead of returning a null handle on failure.
///
/// the mixer on which to create a mixing group.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixGroup CreateGroup(MixMixer mixer)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
MixGroup result = PInvoke.CreateGroup(mixer);
if (result.IsNull())
{
throw SdlException.FromError("MIX_CreateGroup failed");
}
return result;
}
///
/// Destroy a mixing group.
///
/// the mixing group to destroy.
///
///
/// Any tracks currently assigned to this group will be reassigned to the
/// mixer's internal default group.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static void DestroyGroup(MixGroup group)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
PInvoke.DestroyGroup(group);
}
///
/// Get the properties associated with a group.
///
/// the group to query.
///
/// a valid property ID on success or 0 on failure; call
/// SDL_GetError() for more information.
///
///
///
/// Currently SDL_mixer assigns no properties of its own to a group, but this
/// can be a convenient place to store app-specific data.
///
///
/// A SDL_PropertiesID is created the first time this function is called for a
/// given group.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static uint GetGroupProperties(MixGroup group)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetGroupProperties(group);
}
///
/// Ergonomic wrapper over MIX_GetGroupMixer.
///
/// the group to query.
///
/// Borrowed handle: the returned handle is owned by SDL (or by another object) and must not be
/// disposed. Do not call on it; doing so would free a resource this
/// call does not own. A null handle is returned on failure.
///
public static MixMixer GetGroupMixer(MixGroup group)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.GetGroupMixer(group);
}
///
/// Ergonomic wrapper over MIX_SetTrackGroup. Throws instead of returning false on failure.
///
/// the track to set mixing group assignment.
/// the new mixing group to assign to. May be NULL.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void SetTrackGroup(MixTrack track, MixGroup group)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
if (PInvoke.SetTrackGroup(track, group) == 0)
{
throw SdlException.FromError("MIX_SetTrackGroup failed");
}
}
///
/// Generate mixer output when not driving an audio device.
///
/// the mixer for which to generate more audio.
/// a pointer to a buffer to store audio in.
/// the number of bytes to store in buffer.
///
/// The number of bytes of mixed audio, discounting appended silence,
/// on success, or -1 on failure; call SDL_GetError() for more
/// information.
///
///
///
/// SDL_mixer allows the creation of MIX_Mixer objects that are not connected
/// to an audio device, by calling MIX_CreateMixer() instead of
/// MIX_CreateMixerDevice(). Such mixers will not generate output until
/// explicitly requested through this function.
///
///
/// The caller may request as much audio as desired, so long as buflen is a
/// multiple of the sample frame size specified when creating the mixer (for
/// example, if requesting stereo Sint16 audio, buflen must be a multiple of 4:
/// 2 bytes-per-channel times 2 channels).
///
///
/// The mixer will mix as quickly as possible; since it works in sample frames
/// instead of time, it can potentially generate enormous amounts of audio in a
/// small amount of time.
///
///
/// On success, this always fills buffer with buflen bytes of audio; if all
/// playing tracks finish mixing, it will fill the remaining buffer with
/// silence.
///
///
/// Each call to this function will pick up where it left off, playing tracks
/// will continue to mix from the point the previous call completed, etc. The
/// mixer state can be changed between each call in any way desired: tracks can
/// be added, played, stopped, changed, removed, etc. Effectively this function
/// does the same thing SDL_mixer does internally when the audio device needs
/// more audio to play.
///
///
/// This function can not be used with mixers from MIX_CreateMixerDevice();
/// those generate audio as needed internally.
///
///
/// This function returns the number of bytes of real audio mixed, which
/// might be less than buflen. While all buflen bytes of buffer will be
/// initialized, if available tracks to mix run out, the end of the buffer will
/// be initialized with silence; this silence will not be counted in the return
/// value, so the caller has the option to identify how much of the buffer has
/// legimitate contents vs appended silence. As such, any value >= 0 signifies
/// success. A return value of -1 means failure (out of memory, invalid
/// parameters, etc).
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static int Generate(MixMixer mixer, void* buffer, int buflen)
{
SdlMixer.ExceptionAggregator.CheckExceptions();
return PInvoke.Generate(mixer, buffer, buflen);
}
///
/// Ergonomic wrapper over MIX_CreateAudioDecoder. Throws instead of returning a null handle on
/// failure.
///
/// the path on the filesystem from which to load data.
/// decoder-specific properties. May be zero.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixAudioDecoder CreateAudioDecoder(string path, uint props)
{
MixAudioDecoder result = PInvoke.CreateAudioDecoder(path, props);
if (result.IsNull())
{
throw SdlException.FromError("MIX_CreateAudioDecoder failed");
}
return result;
}
///
/// Ergonomic wrapper over MIX_CreateAudioDecoder_IO. Throws instead of returning a null handle on
/// failure.
///
/// the i/o stream from which to load data.
/// if true, close the i/o stream when done with it.
/// decoder-specific properties. May be zero.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static MixAudioDecoder CreateAudioDecoderIO(nint io, bool closeio, uint props)
{
MixAudioDecoder result = PInvoke.CreateAudioDecoderIO(io, closeio ? (byte)1 : (byte)0, props);
if (result.IsNull())
{
throw SdlException.FromError("MIX_CreateAudioDecoder_IO failed");
}
return result;
}
///
/// Destroy the specified audio decoder.
///
/// the audio to destroy.
///
///
/// Destroying a NULL MIX_AudioDecoder is a legal no-op.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static void DestroyAudioDecoder(MixAudioDecoder audiodecoder) =>
PInvoke.DestroyAudioDecoder(audiodecoder);
///
/// Get the properties associated with a MIX_AudioDecoder.
///
/// the audio decoder to query.
///
/// a valid property ID on success or 0 on failure; call
/// SDL_GetError() for more information.
///
///
///
/// SDL_mixer offers some properties of its own, but this can also be a
/// convenient place to store app-specific data.
///
///
/// A SDL_PropertiesID is created the first time this function is called for a
/// given MIX_AudioDecoder, if necessary.
///
///
/// The file-specific metadata exposed through this function is identical to
/// those available through MIX_GetAudioProperties(). Please refer to that
/// function's documentation for details.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
///
public static uint GetAudioDecoderProperties(MixAudioDecoder audiodecoder) =>
PInvoke.GetAudioDecoderProperties(audiodecoder);
///
/// Ergonomic wrapper over MIX_GetAudioDecoderFormat. Throws instead of returning false on failure.
///
/// the audio decoder to query.
/// on success, audio format details will be stored here.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void GetAudioDecoderFormat(MixAudioDecoder audiodecoder, SdlAudioSpec* spec)
{
if (PInvoke.GetAudioDecoderFormat(audiodecoder, spec) == 0)
{
throw SdlException.FromError("MIX_GetAudioDecoderFormat failed");
}
}
///
/// Decode more audio from a MIX_AudioDecoder.
///
/// the decoder from which to retrieve more data.
/// the memory buffer to store decoded audio.
/// the maximum number of bytes to store to buffer.
/// the format that audio data will be stored to buffer.
///
/// number of bytes decoded, or -1 on error; call SDL_GetError() for
/// more information.
///
///
///
/// Data is decoded on demand in whatever format is requested. The format is
/// permitted to change between calls.
///
///
/// This function will return the number of bytes decoded, which may be less
/// than requested if there was an error or end-of-file. A return value of zero
/// means the entire file was decoded, -1 means an unrecoverable error
/// happened.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_mixer 3.0.0.
///
public static int DecodeAudio(MixAudioDecoder audiodecoder, void* buffer, int buflen, SdlAudioSpec* spec) =>
PInvoke.DecodeAudio(audiodecoder, buffer, buflen, spec);
}
}