mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 13:08:24 +01:00
2168 lines
99 KiB
C#
2168 lines
99 KiB
C#
// <auto-generated/>
|
|
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
|
#nullable enable
|
|
|
|
namespace Brutal.SdlApi.Mixer
|
|
{
|
|
public static unsafe partial class SdlMixer
|
|
{
|
|
/// <summary>
|
|
/// Get the version of SDL_mixer that is linked against your program.
|
|
/// </summary>
|
|
/// <returns>the version of the linked library.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// This function may be called safely at any time, even before MIX_Init().
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static int Version() => PInvoke.Version();
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_Init</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void Init()
|
|
{
|
|
if (PInvoke.Init() == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_Init failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Report the number of audio decoders available for use.
|
|
/// </summary>
|
|
/// <returns>the number of decoders available.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// The return value can be used to call MIX_GetAudioDecoder() in a loop.
|
|
/// </para>
|
|
/// <para>
|
|
/// The number of decoders available is decided during MIX_Init() and does not
|
|
/// change until the library is deinitialized.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.GetAudioDecoder"/>
|
|
public static int GetNumAudioDecoders() => PInvoke.GetNumAudioDecoders();
|
|
|
|
/// <summary>
|
|
/// Report the name of a specific audio decoders.
|
|
/// </summary>
|
|
/// <param name="index">the index of the decoder to query.</param>
|
|
/// <returns>
|
|
/// a UTF-8 (really, ASCII) string of the decoder's name, or NULL if
|
|
/// <c>index</c> is invalid.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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".
|
|
/// </para>
|
|
/// <para>
|
|
/// 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().
|
|
/// </para>
|
|
/// <para>
|
|
/// The returned pointer is const memory owned by SDL_mixer; do not free it.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.GetNumAudioDecoders"/>
|
|
public static string? GetAudioDecoder(int index) => PInvoke.GetAudioDecoder(index);
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_CreateMixerDevice</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="devid">
|
|
/// the device to open for playback, or
|
|
/// SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK for the default.
|
|
/// </param>
|
|
/// <param name="spec">the audio format to request from the device. May be NULL.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_CreateMixer</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="spec">the audio format that mixer will generate.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static MixMixer CreateMixer(SdlAudioSpec* spec)
|
|
{
|
|
MixMixer result = PInvoke.CreateMixer(spec);
|
|
if (result.IsNull())
|
|
{
|
|
throw SdlException.FromError("MIX_CreateMixer failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Free a mixer.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer to destroy.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If this mixer was created with MIX_CreateMixerDevice(), this function will
|
|
/// also close the audio device and call SDL_QuitSubSystem(SDL_INIT_AUDIO).
|
|
/// </para>
|
|
/// <para>
|
|
/// 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()).
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// 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.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.CreateMixerDevice"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.CreateMixer"/>
|
|
public static void DestroyMixer(MixMixer mixer)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
PInvoke.DestroyMixer(mixer);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the properties associated with a mixer.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer to query.</param>
|
|
/// <returns>
|
|
/// a valid property ID on success or 0 on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The following read-only properties are provided by SDL_mixer:
|
|
/// </para>
|
|
/// <para>
|
|
/// - <c>MIX_PROP_MIXER_DEVICE_NUMBER</c>: 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().
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static uint GetMixerProperties(MixMixer mixer)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetMixerProperties(mixer);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_GetMixerFormat</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer to query.</param>
|
|
/// <param name="spec">where to store the mixer audio format.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void GetMixerFormat(MixMixer mixer, SdlAudioSpec* spec)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.GetMixerFormat(mixer, spec) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_GetMixerFormat failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lock a mixer by obtaining its internal mutex.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer to lock. May be NULL.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// Just about every SDL_mixer API <em>also</em> 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:
|
|
/// </para>
|
|
/// <para>
|
|
/// - 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// Do not lock the mixer for significant amounts of time, or it can cause
|
|
/// audio dropouts. Just do simple things quickly and unlock again.
|
|
/// </para>
|
|
/// <para>
|
|
/// Locking a NULL mixer is a safe no-op.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.UnlockMixer"/>
|
|
public static void LockMixer(MixMixer mixer)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
PInvoke.LockMixer(mixer);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unlock a mixer previously locked by a call to MIX_LockMixer().
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer to unlock. May be NULL.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// Unlocking a NULL mixer is a safe no-op.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This call must be paired with a previous MIX_LockMixer call
|
|
/// on the same thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.LockMixer"/>
|
|
public static void UnlockMixer(MixMixer mixer)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
PInvoke.UnlockMixer(mixer);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_LoadAudio_IO</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">a mixer this audio is intended to be used with. May be NULL.</param>
|
|
/// <param name="io">the SDL_IOStream to load data from.</param>
|
|
/// <param name="predecode">if true, data will be fully uncompressed before returning.</param>
|
|
/// <param name="closeio">
|
|
/// true if SDL_mixer should close <c>io</c> before returning
|
|
/// (success or failure).
|
|
/// </param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_LoadAudio</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">a mixer this audio is intended to be used with. May be NULL.</param>
|
|
/// <param name="path">the path on the filesystem to load data from.</param>
|
|
/// <param name="predecode">if true, data will be fully uncompressed before returning.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_LoadAudioNoCopy</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">a mixer this audio is intended to be used with. May be NULL.</param>
|
|
/// <param name="data">the buffer where the audio data lives.</param>
|
|
/// <param name="datalen">the size, in bytes, of the buffer.</param>
|
|
/// <param name="free_when_done">
|
|
/// if true, <c>data</c> will be given to SDL_free() when the
|
|
/// MIX_Audio is destroyed.
|
|
/// </param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_LoadAudioWithProperties</c>. Throws instead of returning a null handle on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="props">a set of properties on how to load audio.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static MixAudio LoadAudioWithProperties(uint props)
|
|
{
|
|
MixAudio result = PInvoke.LoadAudioWithProperties(props);
|
|
if (result.IsNull())
|
|
{
|
|
throw SdlException.FromError("MIX_LoadAudioWithProperties failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_LoadRawAudio_IO</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">a mixer this audio is intended to be used with. May be NULL.</param>
|
|
/// <param name="io">the SDL_IOStream to load data from.</param>
|
|
/// <param name="spec">what format the raw data is in.</param>
|
|
/// <param name="closeio">
|
|
/// true if SDL_mixer should close <c>io</c> before returning
|
|
/// (success or failure).
|
|
/// </param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_LoadRawAudio</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">a mixer this audio is intended to be used with. May be NULL.</param>
|
|
/// <param name="data">the raw PCM data to load.</param>
|
|
/// <param name="datalen">the size, in bytes, of the raw PCM data.</param>
|
|
/// <param name="spec">what format the raw data is in.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_LoadRawAudioNoCopy</c>. Throws instead of returning a null handle on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="mixer">a mixer this audio is intended to be used with. May be NULL.</param>
|
|
/// <param name="data">the buffer where the raw PCM data lives.</param>
|
|
/// <param name="datalen">the size, in bytes, of the buffer.</param>
|
|
/// <param name="spec">what format the raw data is in.</param>
|
|
/// <param name="free_when_done">
|
|
/// if true, <c>data</c> will be given to SDL_free() when the
|
|
/// MIX_Audio is destroyed.
|
|
/// </param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_CreateSineWaveAudio</c>. Throws instead of returning a null handle on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="mixer">a mixer this audio is intended to be used with. May be NULL.</param>
|
|
/// <param name="hz">the sinewave's frequency in Hz.</param>
|
|
/// <param name="amplitude">the sinewave's amplitude from 0.0f to 1.0f.</param>
|
|
/// <param name="ms">
|
|
/// the maximum number of milliseconds of audio to generate, or less
|
|
/// than zero to generate infinite audio.
|
|
/// </param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the properties associated with a MIX_Audio.
|
|
/// </summary>
|
|
/// <param name="audio">the audio to query.</param>
|
|
/// <returns>
|
|
/// a valid property ID on success or 0 on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// SDL_mixer offers some properties of its own, but this can also be a
|
|
/// convenient place to store app-specific data.
|
|
/// </para>
|
|
/// <para>
|
|
/// A SDL_PropertiesID is created the first time this function is called for a
|
|
/// given MIX_Audio, if necessary.
|
|
/// </para>
|
|
/// <para>
|
|
/// The following read-only properties are provided by SDL_mixer:
|
|
/// </para>
|
|
/// <para>
|
|
/// - <c>MIX_PROP_METADATA_TITLE_STRING</c>: the audio's title ("Smells Like Teen
|
|
/// Spirit").
|
|
/// - <c>MIX_PROP_METADATA_ARTIST_STRING</c>: the audio's artist name ("Nirvana").
|
|
/// - <c>MIX_PROP_METADATA_ALBUM_STRING</c>: the audio's album name ("Nevermind").
|
|
/// - <c>MIX_PROP_METADATA_COPYRIGHT_STRING</c>: the audio's copyright info
|
|
/// ("Copyright (c) 1991")
|
|
/// - <c>MIX_PROP_METADATA_TRACK_NUMBER</c>: the audio's track number on the album
|
|
/// (1)
|
|
/// - <c>MIX_PROP_METADATA_TOTAL_TRACKS_NUMBER</c>: the total tracks on the album
|
|
/// (13)
|
|
/// - <c>MIX_PROP_METADATA_YEAR_NUMBER</c>: the year the audio was released (1991)
|
|
/// - <c>MIX_PROP_METADATA_DURATION_FRAMES_NUMBER</c>: 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.
|
|
/// - <c>MIX_PROP_METADATA_DURATION_INFINITE_BOOLEAN</c>: if true, audio never runs
|
|
/// out of sound to generate. This isn't necessarily always known to
|
|
/// SDL_mixer, though.
|
|
/// </para>
|
|
/// <para>
|
|
/// Other properties, documented with MIX_LoadAudioWithProperties(), may also
|
|
/// be present.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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).
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static uint GetAudioProperties(MixAudio audio) => PInvoke.GetAudioProperties(audio);
|
|
|
|
/// <summary>
|
|
/// Get the length of a MIX_Audio's playback in sample frames.
|
|
/// </summary>
|
|
/// <param name="audio">the audio to query.</param>
|
|
/// <returns>
|
|
/// the length of the audio in sample frames, or MIX_DURATION_UNKNOWN
|
|
/// or MIX_DURATION_INFINITE.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// This reports the length of the data in <em>sample frames</em>, 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().
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// This will return a value >= 0 if a duration is known. It might also return
|
|
/// MIX_DURATION_UNKNOWN or MIX_DURATION_INFINITE.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static long GetAudioDuration(MixAudio audio) => PInvoke.GetAudioDuration(audio);
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_GetAudioFormat</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="audio">the audio to query.</param>
|
|
/// <param name="spec">on success, audio format details will be stored here.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void GetAudioFormat(MixAudio audio, SdlAudioSpec* spec)
|
|
{
|
|
if (PInvoke.GetAudioFormat(audio, spec) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_GetAudioFormat failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Destroy the specified audio.
|
|
/// </summary>
|
|
/// <param name="audio">the audio to destroy.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// But from the caller's perspective, once this function is called, it should
|
|
/// assume the <c>audio</c> pointer has become invalid.
|
|
/// </para>
|
|
/// <para>
|
|
/// Destroying a NULL MIX_Audio is a legal no-op.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static void DestroyAudio(MixAudio audio) => PInvoke.DestroyAudio(audio);
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_CreateTrack</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer on which to create this track.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Destroy the specified track.
|
|
/// </summary>
|
|
/// <param name="track">the track to destroy.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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 <em>not</em> be called.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// Destroying a NULL MIX_Track is a legal no-op.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static void DestroyTrack(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
PInvoke.DestroyTrack(track);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the properties associated with a track.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <returns>
|
|
/// a valid property ID on success or 0 on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Currently SDL_mixer assigns no properties of its own to a track, but this
|
|
/// can be a convenient place to store app-specific data.
|
|
/// </para>
|
|
/// <para>
|
|
/// A SDL_PropertiesID is created the first time this function is called for a
|
|
/// given track.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static uint GetTrackProperties(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetTrackProperties(track);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_GetTrackMixer</c>.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <remarks>
|
|
/// <b>Borrowed handle:</b> the returned handle is owned by SDL (or by another object) and must not be
|
|
/// disposed. Do not call <see cref="System.IDisposable.Dispose"/> on it; doing so would free a resource this
|
|
/// call does not own. A null handle is returned on failure.
|
|
/// </remarks>
|
|
public static MixMixer GetTrackMixer(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetTrackMixer(track);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrackAudio</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track on which to set a new audio input.</param>
|
|
/// <param name="audio">the new audio input to set. May be NULL.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void SetTrackAudio(MixTrack track, MixAudio audio)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.SetTrackAudio(track, audio) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_SetTrackAudio failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrackAudioStream</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track on which to set a new audio input.</param>
|
|
/// <param name="stream">the audio stream to use as the track's input.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void SetTrackAudioStream(MixTrack track, SdlAudioStream stream)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.SetTrackAudioStream(track, stream) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_SetTrackAudioStream failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrackIOStream</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track on which to set a new audio input.</param>
|
|
/// <param name="io">the new i/o stream to use as the track's input.</param>
|
|
/// <param name="closeio">if true, close the stream when done with it.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrackRawIOStream</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track on which to set a new audio input.</param>
|
|
/// <param name="io">the new i/o stream to use as the track's input.</param>
|
|
/// <param name="spec">the format of the PCM data that the SDL_IOStream will provide.</param>
|
|
/// <param name="closeio">if true, close the stream when done with it.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_TagTrack</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to add a tag to.</param>
|
|
/// <param name="tag">the tag to add.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void TagTrack(MixTrack track, string tag)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.TagTrack(track, tag) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_TagTrack failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove an arbitrary tag from a track.
|
|
/// </summary>
|
|
/// <param name="track">the track from which to remove a tag.</param>
|
|
/// <param name="tag">the tag to remove, or NULL to remove all current tags.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// It's legal to remove a tag that the track doesn't have; this function
|
|
/// doesn't report errors, so this simply does nothing.
|
|
/// </para>
|
|
/// <para>
|
|
/// Specifying a NULL tag will remove all tags on a track.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.TagTrack"/>
|
|
public static void UntagTrack(MixTrack track, string tag)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
PInvoke.UntagTrack(track, tag);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_GetTrackTags</c>.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
/// <remarks>
|
|
/// SDL returns a freshly <c>SDL_malloc</c>'d buffer for this call; the returned array is a managed copy, and
|
|
/// the native buffer is freed with <c>SDL_free</c> before this method returns.
|
|
/// </remarks>
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_GetTaggedTracks</c>.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer to query.</param>
|
|
/// <param name="tag">the tag to search.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
/// <remarks>
|
|
/// SDL returns a freshly <c>SDL_malloc</c>'d buffer for this call; the returned array is a managed copy, and
|
|
/// the native buffer is freed with <c>SDL_free</c> before this method returns. Each element is a
|
|
/// <b>borrowed handle</b>: it is owned by SDL, not created by this call, and must not be disposed. Do not
|
|
/// call <see cref="System.IDisposable.Dispose"/> on any element.
|
|
/// </remarks>
|
|
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<MixTrack>(ptr, count).ToArray();
|
|
}
|
|
finally
|
|
{
|
|
Sdl.PInvoke.Free(ptr);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrackPlaybackPosition</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to change.</param>
|
|
/// <param name="frames">the sample frame position to seek to.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void SetTrackPlaybackPosition(MixTrack track, long frames)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.SetTrackPlaybackPosition(track, frames) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_SetTrackPlaybackPosition failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the current input position of a playing track.
|
|
/// </summary>
|
|
/// <param name="track">the track to change.</param>
|
|
/// <returns>
|
|
/// the track's current sample frame position, or -1 on error; call
|
|
/// SDL_GetError() for details.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// (Not to be confused with MIX_GetTrack3DPosition(), which is positioning of
|
|
/// the track in 3D space, not the playback position of its audio data.)
|
|
/// </para>
|
|
/// <para>
|
|
/// Position is defined in <em>sample frames</em> 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// Stopped and paused tracks will report the position when they halted.
|
|
/// Playing tracks will report the current position, which will change over
|
|
/// time.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.SetTrackPlaybackPosition"/>
|
|
public static long GetTrackPlaybackPosition(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetTrackPlaybackPosition(track);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query whether a given track is fading.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <returns>
|
|
/// less than 0 if the track is fading out, greater than 0 if fading
|
|
/// in, zero otherwise.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This specifically checks if the track is <em>not stopped</em> (paused or playing),
|
|
/// and it is fading in or out, and returns the number of frames remaining in
|
|
/// the fade.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static long GetTrackFadeFrames(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetTrackFadeFrames(track);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query how many loops remain for a given track.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <returns>
|
|
/// the number of pending loops, zero if not looping, and -1 if
|
|
/// looping infinitely.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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 <em>was</em> looping but is on its final iteration of the loop (will stop
|
|
/// when this iteration completes), this will return zero.
|
|
/// </para>
|
|
/// <para>
|
|
/// A track that is looping infinitely will return -1. This value does not
|
|
/// report an error in this case.
|
|
/// </para>
|
|
/// <para>
|
|
/// A track that is stopped (not playing and not paused) will have zero loops
|
|
/// remaining.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static int GetTrackLoops(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetTrackLoops(track);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrackLoops</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to configure.</param>
|
|
/// <param name="num_loops">
|
|
/// new number of times to loop. Zero to disable looping, -1
|
|
/// to loop infinitely.
|
|
/// </param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_GetTrackAudio</c>.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <remarks>
|
|
/// <b>Borrowed handle:</b> the returned handle is owned by SDL (or by another object) and must not be
|
|
/// disposed. Do not call <see cref="System.IDisposable.Dispose"/> on it; doing so would free a resource this
|
|
/// call does not own. A null handle is returned on failure.
|
|
/// </remarks>
|
|
public static MixAudio GetTrackAudio(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetTrackAudio(track);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_GetTrackAudioStream</c>.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <remarks>
|
|
/// <b>Borrowed handle:</b> the returned handle is owned by SDL (or by another object) and must not be
|
|
/// disposed. Do not call <see cref="System.IDisposable.Dispose"/> on it; doing so would free a resource this
|
|
/// call does not own. A null handle is returned on failure.
|
|
/// </remarks>
|
|
public static SdlAudioStream GetTrackAudioStream(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetTrackAudioStream(track);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return the number of sample frames remaining to be mixed in a track.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <returns>the total sample frames still to be mixed, or -1 if unknown.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// Remaining audio is defined in <em>sample frames</em> 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// This function does not take into account fade-outs or looping, just the
|
|
/// current mixing position vs the duration of the track.
|
|
/// </para>
|
|
/// <para>
|
|
/// If the duration of the track isn't known, or <c>track</c> is NULL, this function
|
|
/// returns -1. A stopped track reports 0.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static long GetTrackRemaining(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetTrackRemaining(track);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convert milliseconds to sample frames for a track's current format.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <param name="ms">the milliseconds to convert to track-specific sample frames.</param>
|
|
/// <returns>
|
|
/// Converted number of sample frames, or -1 for errors/no input; call
|
|
/// SDL_GetError() for details.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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).
|
|
/// </para>
|
|
/// <para>
|
|
/// 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 <c>ms</c> is < 0,
|
|
/// this returns -1.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.TrackFramesToMS"/>
|
|
public static long TrackMSToFrames(MixTrack track, long ms)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.TrackMSToFrames(track, ms);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convert sample frames for a track's current format to milliseconds.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <param name="frames">the track-specific sample frames to convert to milliseconds.</param>
|
|
/// <returns>
|
|
/// Converted number of milliseconds, or -1 for errors/no input; call
|
|
/// SDL_GetError() for details.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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).
|
|
/// </para>
|
|
/// <para>
|
|
/// Sample frames are more precise than milliseconds, so out of necessity, this
|
|
/// function will approximate by rounding down to the closest full millisecond.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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 <c>frames</c> is < 0,
|
|
/// this returns -1.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.TrackMSToFrames"/>
|
|
public static long TrackFramesToMS(MixTrack track, long frames)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.TrackFramesToMS(track, frames);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convert milliseconds to sample frames for a MIX_Audio's format.
|
|
/// </summary>
|
|
/// <param name="audio">the audio to query.</param>
|
|
/// <param name="ms">the milliseconds to convert to audio-specific sample frames.</param>
|
|
/// <returns>
|
|
/// Converted number of sample frames, or -1 for errors/no input; call
|
|
/// SDL_GetError() for details.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This calculates time based on the audio's initial format, even if the
|
|
/// format would change mid-stream.
|
|
/// </para>
|
|
/// <para>
|
|
/// If <c>ms</c> is < 0, this returns -1.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.AudioFramesToMS"/>
|
|
public static long AudioMSToFrames(MixAudio audio, long ms) => PInvoke.AudioMSToFrames(audio, ms);
|
|
|
|
/// <summary>
|
|
/// Convert sample frames for a MIX_Audio's format to milliseconds.
|
|
/// </summary>
|
|
/// <param name="audio">the audio to query.</param>
|
|
/// <param name="frames">the audio-specific sample frames to convert to milliseconds.</param>
|
|
/// <returns>
|
|
/// Converted number of milliseconds, or -1 for errors/no input; call
|
|
/// SDL_GetError() for details.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This calculates time based on the audio's initial format, even if the
|
|
/// format would change mid-stream.
|
|
/// </para>
|
|
/// <para>
|
|
/// Sample frames are more precise than milliseconds, so out of necessity, this
|
|
/// function will approximate by rounding down to the closest full millisecond.
|
|
/// </para>
|
|
/// <para>
|
|
/// If <c>frames</c> is < 0, this returns -1.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.AudioMSToFrames"/>
|
|
public static long AudioFramesToMS(MixAudio audio, long frames) => PInvoke.AudioFramesToMS(audio, frames);
|
|
|
|
/// <summary>
|
|
/// Convert milliseconds to sample frames at a specific sample rate.
|
|
/// </summary>
|
|
/// <param name="sample_rate">the sample rate to use for conversion.</param>
|
|
/// <param name="ms">the milliseconds to convert to rate-specific sample frames.</param>
|
|
/// <returns>
|
|
/// Converted number of sample frames, or -1 for errors; call
|
|
/// SDL_GetError() for details.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If <c>sample_rate</c> is <= 0, this returns -1. If <c>ms</c> is < 0, this returns -1.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.FramesToMS"/>
|
|
public static long MSToFrames(int sample_rate, long ms) => PInvoke.MSToFrames(sample_rate, ms);
|
|
|
|
/// <summary>
|
|
/// Convert sample frames, at a specific sample rate, to milliseconds.
|
|
/// </summary>
|
|
/// <param name="sample_rate">the sample rate to use for conversion.</param>
|
|
/// <param name="frames">the rate-specific sample frames to convert to milliseconds.</param>
|
|
/// <returns>
|
|
/// Converted number of milliseconds, or -1 for errors; call
|
|
/// SDL_GetError() for details.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Sample frames are more precise than milliseconds, so out of necessity, this
|
|
/// function will approximate by rounding down to the closest full millisecond.
|
|
/// </para>
|
|
/// <para>
|
|
/// If <c>sample_rate</c> is <= 0, this returns -1. If <c>frames</c> is < 0, this returns
|
|
/// -1.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.MSToFrames"/>
|
|
public static long FramesToMS(int sample_rate, long frames) => PInvoke.FramesToMS(sample_rate, frames);
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_PlayTrack</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to start (or restart) mixing.</param>
|
|
/// <param name="options">a set of properties that control playback. May be zero.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void PlayTrack(MixTrack track, uint options)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.PlayTrack(track, options) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_PlayTrack failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_PlayTag</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer on which to look for tagged tracks.</param>
|
|
/// <param name="tag">the tag to use when searching for tracks.</param>
|
|
/// <param name="options">the set of options that will be applied to each track.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_PlayAudio</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer on which to play this audio.</param>
|
|
/// <param name="audio">the audio input to play.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void PlayAudio(MixMixer mixer, MixAudio audio)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.PlayAudio(mixer, audio) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_PlayAudio failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_StopTrack</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to halt.</param>
|
|
/// <param name="fade_out_frames">
|
|
/// the number of sample frames to spend fading out to
|
|
/// silence before halting. 0 to stop immediately.
|
|
/// </param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_StopAllTracks</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer on which to stop all tracks.</param>
|
|
/// <param name="fade_out_ms">
|
|
/// the number of milliseconds to spend fading out to
|
|
/// silence before halting. 0 to stop immediately.
|
|
/// </param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_StopTag</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer on which to stop tracks.</param>
|
|
/// <param name="tag">the tag to use when searching for tracks.</param>
|
|
/// <param name="fade_out_ms">
|
|
/// the number of milliseconds to spend fading out to
|
|
/// silence before halting. 0 to stop immediately.
|
|
/// </param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_PauseTrack</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to pause.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void PauseTrack(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.PauseTrack(track) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_PauseTrack failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_PauseAllTracks</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer on which to pause all tracks.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void PauseAllTracks(MixMixer mixer)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.PauseAllTracks(mixer) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_PauseAllTracks failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_PauseTag</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer on which to pause tracks.</param>
|
|
/// <param name="tag">the tag to use when searching for tracks.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void PauseTag(MixMixer mixer, string tag)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.PauseTag(mixer, tag) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_PauseTag failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_ResumeTrack</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to resume.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void ResumeTrack(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.ResumeTrack(track) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_ResumeTrack failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_ResumeAllTracks</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer on which to resume all tracks.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void ResumeAllTracks(MixMixer mixer)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.ResumeAllTracks(mixer) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_ResumeAllTracks failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_ResumeTag</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer on which to resume tracks.</param>
|
|
/// <param name="tag">the tag to use when searching for tracks.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void ResumeTag(MixMixer mixer, string tag)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.ResumeTag(mixer, tag) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_ResumeTag failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query if a track is currently playing.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <returns>true if playing, false otherwise.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If this returns true, the track is currently contributing to the mixer's
|
|
/// output (it's "playing"). It is not stopped nor paused.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.PlayTrack"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.PauseTrack"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.ResumeTrack"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.StopTrack"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.TrackPaused"/>
|
|
public static bool TrackPlaying(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.TrackPlaying(track) != 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query if a track is currently paused.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <returns>true if paused, false otherwise.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.PlayTrack"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.PauseTrack"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.ResumeTrack"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.StopTrack"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.TrackPlaying"/>
|
|
public static bool TrackPaused(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.TrackPaused(track) != 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetMixerGain</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer to adjust.</param>
|
|
/// <param name="gain">the new gain value.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void SetMixerGain(MixMixer mixer, float gain)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.SetMixerGain(mixer, gain) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_SetMixerGain failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a mixer's master gain control.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer to query.</param>
|
|
/// <returns>the mixer's current master gain.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This returns the last value set through MIX_SetMixerGain(), or 1.0f if no
|
|
/// value has ever been explicitly set.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.SetMixerGain"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.GetTrackGain"/>
|
|
public static float GetMixerGain(MixMixer mixer)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetMixerGain(mixer);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrackGain</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to adjust.</param>
|
|
/// <param name="gain">the new gain value.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void SetTrackGain(MixTrack track, float gain)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.SetTrackGain(track, gain) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_SetTrackGain failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a track's gain control.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <returns>the track's current gain.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This returns the last value set through MIX_SetTrackGain(), or 1.0f if no
|
|
/// value has ever been explicitly set.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.SetTrackGain"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.GetMixerGain"/>
|
|
public static float GetTrackGain(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetTrackGain(track);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTagGain</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer on which to look for tagged tracks.</param>
|
|
/// <param name="tag">the tag to use when searching for tracks.</param>
|
|
/// <param name="gain">the new gain value.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetMixerFrequencyRatio</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer to adjust.</param>
|
|
/// <param name="ratio">the frequency ratio. Must be between 0.01f and 100.0f.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void SetMixerFrequencyRatio(MixMixer mixer, float ratio)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.SetMixerFrequencyRatio(mixer, ratio) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_SetMixerFrequencyRatio failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a mixer's master frequency ratio.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer to query.</param>
|
|
/// <returns>the mixer's current master frequency ratio.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This returns the last value set through MIX_SetMixerFrequencyRatio(), or
|
|
/// 1.0f if no value has ever been explicitly set.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.SetMixerFrequencyRatio"/>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.GetTrackFrequencyRatio"/>
|
|
public static float GetMixerFrequencyRatio(MixMixer mixer)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetMixerFrequencyRatio(mixer);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrackFrequencyRatio</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track on which to change the frequency ratio.</param>
|
|
/// <param name="ratio">the frequency ratio. Must be between 0.01f and 100.0f.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void SetTrackFrequencyRatio(MixTrack track, float ratio)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.SetTrackFrequencyRatio(track, ratio) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_SetTrackFrequencyRatio failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query the frequency ratio of a track.
|
|
/// </summary>
|
|
/// <param name="track">the track on which to query the frequency ratio.</param>
|
|
/// <returns>
|
|
/// the current frequency ratio, or 0.0f on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// The default value is 1.0f.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.GetTrackFrequencyRatio"/>
|
|
public static float GetTrackFrequencyRatio(MixTrack track)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetTrackFrequencyRatio(track);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrackOutputChannelMap</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to change.</param>
|
|
/// <param name="chmap">the new channel map, NULL to reset to default.</param>
|
|
/// <param name="count">The number of channels in the map.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrackStereo</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to adjust.</param>
|
|
/// <param name="gains">the per-channel gains, or NULL to disable spatialization.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void SetTrackStereo(MixTrack track, MixStereoGains* gains)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.SetTrackStereo(track, gains) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_SetTrackStereo failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrack3DPosition</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track for which to set 3D position.</param>
|
|
/// <param name="position">the new 3D position for the track. May be NULL.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void SetTrack3DPosition(MixTrack track, MixPoint3D* position)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.SetTrack3DPosition(track, position) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_SetTrack3DPosition failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_GetTrack3DPosition</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to query.</param>
|
|
/// <param name="position">on successful return, will contain the track's position.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void GetTrack3DPosition(MixTrack track, MixPoint3D* position)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.GetTrack3DPosition(track, position) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_GetTrack3DPosition failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_CreateGroup</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer on which to create a mixing group.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Destroy a mixing group.
|
|
/// </summary>
|
|
/// <param name="group">the mixing group to destroy.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Any tracks currently assigned to this group will be reassigned to the
|
|
/// mixer's internal default group.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.CreateGroup"/>
|
|
public static void DestroyGroup(MixGroup group)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
PInvoke.DestroyGroup(group);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the properties associated with a group.
|
|
/// </summary>
|
|
/// <param name="group">the group to query.</param>
|
|
/// <returns>
|
|
/// a valid property ID on success or 0 on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Currently SDL_mixer assigns no properties of its own to a group, but this
|
|
/// can be a convenient place to store app-specific data.
|
|
/// </para>
|
|
/// <para>
|
|
/// A SDL_PropertiesID is created the first time this function is called for a
|
|
/// given group.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static uint GetGroupProperties(MixGroup group)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetGroupProperties(group);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_GetGroupMixer</c>.
|
|
/// </summary>
|
|
/// <param name="group">the group to query.</param>
|
|
/// <remarks>
|
|
/// <b>Borrowed handle:</b> the returned handle is owned by SDL (or by another object) and must not be
|
|
/// disposed. Do not call <see cref="System.IDisposable.Dispose"/> on it; doing so would free a resource this
|
|
/// call does not own. A null handle is returned on failure.
|
|
/// </remarks>
|
|
public static MixMixer GetGroupMixer(MixGroup group)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.GetGroupMixer(group);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_SetTrackGroup</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="track">the track to set mixing group assignment.</param>
|
|
/// <param name="group">the new mixing group to assign to. May be NULL.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void SetTrackGroup(MixTrack track, MixGroup group)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
if (PInvoke.SetTrackGroup(track, group) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_SetTrackGroup failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generate mixer output when not driving an audio device.
|
|
/// </summary>
|
|
/// <param name="mixer">the mixer for which to generate more audio.</param>
|
|
/// <param name="buffer">a pointer to a buffer to store audio in.</param>
|
|
/// <param name="buflen">the number of bytes to store in buffer.</param>
|
|
/// <returns>
|
|
/// The number of bytes of mixed audio, discounting appended silence,
|
|
/// on success, or -1 on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// The caller may request as much audio as desired, so long as <c>buflen</c> 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).
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// On success, this always fills <c>buffer</c> with <c>buflen</c> bytes of audio; if all
|
|
/// playing tracks finish mixing, it will fill the remaining buffer with
|
|
/// silence.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// This function can not be used with mixers from MIX_CreateMixerDevice();
|
|
/// those generate audio as needed internally.
|
|
/// </para>
|
|
/// <para>
|
|
/// This function returns the number of <em>bytes</em> of real audio mixed, which
|
|
/// might be less than <c>buflen</c>. While all <c>buflen</c> bytes of <c>buffer</c> 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).
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.CreateMixer"/>
|
|
public static int Generate(MixMixer mixer, void* buffer, int buflen)
|
|
{
|
|
SdlMixer.ExceptionAggregator.CheckExceptions();
|
|
return PInvoke.Generate(mixer, buffer, buflen);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_CreateAudioDecoder</c>. Throws instead of returning a null handle on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="path">the path on the filesystem from which to load data.</param>
|
|
/// <param name="props">decoder-specific properties. May be zero.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_CreateAudioDecoder_IO</c>. Throws instead of returning a null handle on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="io">the i/o stream from which to load data.</param>
|
|
/// <param name="closeio">if true, close the i/o stream when done with it.</param>
|
|
/// <param name="props">decoder-specific properties. May be zero.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Destroy the specified audio decoder.
|
|
/// </summary>
|
|
/// <param name="audiodecoder">the audio to destroy.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Destroying a NULL MIX_AudioDecoder is a legal no-op.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static void DestroyAudioDecoder(MixAudioDecoder audiodecoder) =>
|
|
PInvoke.DestroyAudioDecoder(audiodecoder);
|
|
|
|
/// <summary>
|
|
/// Get the properties associated with a MIX_AudioDecoder.
|
|
/// </summary>
|
|
/// <param name="audiodecoder">the audio decoder to query.</param>
|
|
/// <returns>
|
|
/// a valid property ID on success or 0 on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// SDL_mixer offers some properties of its own, but this can also be a
|
|
/// convenient place to store app-specific data.
|
|
/// </para>
|
|
/// <para>
|
|
/// A SDL_PropertiesID is created the first time this function is called for a
|
|
/// given MIX_AudioDecoder, if necessary.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Mixer.SdlMixer.PInvoke.GetAudioProperties"/>
|
|
public static uint GetAudioDecoderProperties(MixAudioDecoder audiodecoder) =>
|
|
PInvoke.GetAudioDecoderProperties(audiodecoder);
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>MIX_GetAudioDecoderFormat</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <param name="audiodecoder">the audio decoder to query.</param>
|
|
/// <param name="spec">on success, audio format details will be stored here.</param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void GetAudioDecoderFormat(MixAudioDecoder audiodecoder, SdlAudioSpec* spec)
|
|
{
|
|
if (PInvoke.GetAudioDecoderFormat(audiodecoder, spec) == 0)
|
|
{
|
|
throw SdlException.FromError("MIX_GetAudioDecoderFormat failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Decode more audio from a MIX_AudioDecoder.
|
|
/// </summary>
|
|
/// <param name="audiodecoder">the decoder from which to retrieve more data.</param>
|
|
/// <param name="buffer">the memory buffer to store decoded audio.</param>
|
|
/// <param name="buflen">the maximum number of bytes to store to <c>buffer</c>.</param>
|
|
/// <param name="spec">the format that audio data will be stored to <c>buffer</c>.</param>
|
|
/// <returns>
|
|
/// number of bytes decoded, or -1 on error; call SDL_GetError() for
|
|
/// more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Data is decoded on demand in whatever format is requested. The format is
|
|
/// permitted to change between calls.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_mixer 3.0.0.
|
|
/// </since>
|
|
public static int DecodeAudio(MixAudioDecoder audiodecoder, void* buffer, int buflen, SdlAudioSpec* spec) =>
|
|
PInvoke.DecodeAudio(audiodecoder, buffer, buflen, spec);
|
|
}
|
|
}
|