Initializes the SDL2_mixer API.
This should be the first function you call after initializing SDL itself
with InitAudio.
Automatically cleans up the API when the inner computation finishes.
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05
Modulesdl2-mixer-1.2.0.0Haskell2010
Bindings to the SDL2_mixer library.
In order to use the rest of the library, you need to supply withAudio or openAudio with an Audio configuration.
Initializes the SDL2_mixer API.
This should be the first function you call after initializing SDL itself
with InitAudio.
Automatically cleans up the API when the inner computation finishes.
An audio configuration. Use this with withAudio.
AudioaudioFrequency :: IntA sampling frequency.
audioFormat :: FormatAn output sample format.
audioOutput :: OutputA sample format.
FormatU8Unsigned 8-bit samples.
FormatS8Signed 8-bit samples.
FormatU16_LSBUnsigned 16-bit samples, in little-endian byte order.
FormatS16_LSBSigned 16-bit samples, in little-endian byte order.
FormatU16_MSBUnsigned 16-bit samples, in big-endian byte order.
FormatS16_MSBsigned 16-bit samples, in big-endian byte order.
FormatU16_SysUnsigned 16-bit samples, in system byte order.
FormatS16_SysSigned 16-bit samples, in system byte order.
A default Audio configuration.
Same as def.
Uses 22050 as the audioFrequency, FormatS16_Sys as the audioFormat and Stereo as the audioOutput.
The size of each mixed sample.
The smaller this is, the more often callbacks will be invoked. If this is made too small on a slow system, the sounds may skip. If made too large, sound effects could lag.
An alternative to withAudio, also initializes the SDL2_mixer API.
However, openAudio does not take care of automatically calling closeAudio after a computation ends, so you have to take care to do so manually.
Shut down and clean up the SDL2_mixer API.
After calling this, all audio stops.
You don't have to call this if you're using withAudio.
A class of all values that can be loaded from some source. You can load both Chunks and Music this way.
Note that you must call withAudio before using these, since they have to know the audio configuration to properly convert the data for playback.
decode :: MonadIO m => ByteString -> m aLoad the value from a ByteString.
load :: MonadIO m => FilePath -> m aSame as decode, but loads from a file instead.
free :: MonadIO m => a -> m ()Frees the value's memory. It should no longer be used.
Note that you shouldn't free those values that are currently playing.
Returns the names of all chunk decoders currently available.
These depend on the availability of shared libraries for each of the
formats. The list may contain any of the following, and possibly others:
WAVE, AIFF, VOC, OFF, FLAC, MP3.
Returns the names of all music decoders currently available.
These depend on the availability of shared libraries for each of the
formats. The list may contain any of the following, and possibly others:
WAVE, MODPLUG, MIKMOD, TIMIDITY, FLUIDSYNTH, NATIVEMIDI, OGG,
FLAC, MP3.
A mixing channel.
Use the Integral instance to define these: the first channel is 0, the second 1 and so on.
The default number of Channels available at startup is 8, so note that you cannot usemore than these starting 8 if you haven't created more with setChannels.
Enum ChannelDefined in sdl2-mixer-1.2.0.0 · SDL.MixerEq ChannelDefined in sdl2-mixer-1.2.0.0 · SDL.MixerIntegral ChannelDefined in sdl2-mixer-1.2.0.0 · SDL.MixerNum ChannelDefined in sdl2-mixer-1.2.0.0 · SDL.MixerOrd ChannelDefined in sdl2-mixer-1.2.0.0 · SDL.MixerReal ChannelDefined in sdl2-mixer-1.2.0.0 · SDL.MixerShow ChannelDefined in sdl2-mixer-1.2.0.0 · SDL.MixerHasVolume ChannelDefined in sdl2-mixer-1.2.0.0 · SDL.MixerPrepares a given number of Channels for use.
There are 8 such Channels already prepared for use after withAudio is called.
You may call this multiple times, even with sounds playing. If setting a lesser number of Channels than are currently in use, the higher Channels will be stopped, their finish callbacks invoked, and their memory freed. Passing in 0 or less will therefore stop and free all mixing channels.
Any Music playing is not affected by this function.
Gets the number of Channels currently in use.
How many times should a certain Chunk be played?
Enum TimesDefined in sdl2-mixer-1.2.0.0 · SDL.MixerEq TimesDefined in sdl2-mixer-1.2.0.0 · SDL.MixerIntegral TimesDefined in sdl2-mixer-1.2.0.0 · SDL.MixerNum TimesDefined in sdl2-mixer-1.2.0.0 · SDL.MixerOrd TimesDefined in sdl2-mixer-1.2.0.0 · SDL.MixerReal TimesDefined in sdl2-mixer-1.2.0.0 · SDL.MixerA shorthand for playing once.
A shorthand for looping a Chunk forever.
A time in milliseconds.
An upper limit of time, in milliseconds.
A lack of an upper limit.
Same as playOn, but imposes an upper limit in Milliseconds to how long the Chunk can play.
The playing may still stop before the limit is reached.
This is the most generic play function variant.
Reserve a given number of Channels, starting from Channel 0.
A reserved Channel is considered not to be available for playing samples
when using any play or fadeIn function variant with AllChannels. In
other words, whenever you let SDL.Mixer pick the first available Channel
itself, these reserved Channels will not be considered.
A group of Channels.
Grouping Channels together allows you to perform some operations on all of them at once.
By default, all Channels are members of the DefaultGroup.
Enum GroupDefined in sdl2-mixer-1.2.0.0 · SDL.MixerEq GroupDefined in sdl2-mixer-1.2.0.0 · SDL.MixerIntegral GroupDefined in sdl2-mixer-1.2.0.0 · SDL.MixerNum GroupDefined in sdl2-mixer-1.2.0.0 · SDL.MixerOrd GroupDefined in sdl2-mixer-1.2.0.0 · SDL.MixerReal GroupDefined in sdl2-mixer-1.2.0.0 · SDL.MixerAssigns a given Channel to a certain Group.
If DefaultGroup is used, assigns the Channel the the default starting Group (essentially ungrouping them).
If AllChannels is used, assigns all Channels to the given Group.
Returns whether the Channel was successfully grouped or not. Failure is poosible if the Channel does not exist, for instance.
Same as groupChannel, but groups all Channels between the first and
last given, inclusive.
If DefaultGroup is used, assigns the entire Channel span to the default starting Group (essentially ungrouping them).
Using AllChannels is invalid.
Returns the number of Channels successfully grouped. This number may be less than the number of Channels given, for instance if some of them do not exist.
Returns the number of Channels within a Group.
If DefaultGroup is used, will return the number of all Channels, since all of them are within the default Group.
Gets the first inactive (not playing) Channel within a given Group, if any.
Using DefaultGroup will give you the first inactive Channel out of all that exist.
Resumes playing a Channel, or all Channels if AllChannels is used.
Halts playback on a Channel, or all Channels if AllChannels is used.
Same as halt, but only does so after a certain number of Milliseconds.
If AllChannels is used, it will halt all the Channels after the given time instead.
Same as halt, but halts an entire Group instead.
Note that using DefaultGroup here is the same as calling halt AllChannels.
A volume, where 0 is silent and 128 loudest.
Volumes lesser than 0 or greater than 128 function as if they are 0 and 128, respectively.
A class of all values that have a Volume.
getVolume :: MonadIO m => a -> m VolumeGets the value's currently set Volume.
If the value is a Channel and AllChannels is used, gets the average Volume of all Channels.
setVolume :: MonadIO m => Volume -> a -> m ()Sets a value's Volume.
If the value is a Chunk, the volume setting only takes effect when the Chunk is used on a Channel, being mixed into the output.
In case of being used on a Channel, the volume setting takes effect during the final mix, along with the Chunk volume. For instance, setting the Volume of a certain Channel to 64 will halve the volume of all Chunks played on that Channel. If AllChannels is used, sets all Channels to the given Volume instead.
Returns whether the given Channel is playing or not.
If AllChannels is used, this returns whether any of the channels is currently playing.
Returns how many Channels are currently playing.
Returns whether the given Channel is paused or not.
If AllChannels is used, this returns whether any of the channels is currently paused.
Returns how many Channels are currently paused.
Describes whether a Channel is fading in, out, or not at all.
Returns a Channel's Fading status.
Note that using AllChannels here is not valid, and will simply return the Fading status of the first Channel instead.
Gradually fade out a given playing Channel during the next Milliseconds, even if it is paused.
If AllChannels is used, fades out all the playing Channels instead.
Same as fadeOut, but fades out an entire Group instead.
Using DefaultGroup here is the same as calling fadeOut with AllChannels.
Sets a callback that gets invoked each time a Channel finishes playing.
A Channel finishes playing both when playback ends normally and when it is halted (also possibly via setChannels).
Note: don't call other SDL.Mixer functions within this callback.
A position in milliseconds within a piece of Music.
Plays a given Music a number of Times, but fading it in during a certain number of Milliseconds.
The fading only occurs during the first time the Music is played.
Same as fadeInMusic, but with a custom starting Music's Position.
Note that this only works on Music that setMusicPosition works on.
Same as fadeInMusicAt, but works with MOD Music.
Instead of milliseconds, specify the position with a pattern number.
Halts Music playback.
Similar to setMusicPosition, but works only with MOD Music.
Pass in the pattern number.
Gradually fade out the Music over a given number of Milliseconds.
The Music is set to fade out only when it is playing and not fading already.
Returns whether the Music was successfully set to fade out.
Sets a callback that gets invoked each time a Music finishes playing.
Note: don't call other SDL.Mixer functions within this callback.
A function called when a processor is finished being used.
This allows you to clean up any state you might have had.
A way to refer to the special Channel used for post-processing effects.
You can only use this value with effect and the other in-built effect functions such as effectPan and effectDistance.
Applies an in-built effect implementing panning.
Sets the left-channel and right-channel Volume to the given values.
This only works when Audio's Output is Stereo, which is the default.
Returns an action that, when executed, removes this effect. That action
simply calls effectPan with Volumes 128 and 128.
Applies a different volume based on the distance (as Word8) specified.
The volume is loudest at distance 0, quietest at distance 255.
Returns an action that, when executed, removes this effect. That action simply calls effectDistance with a distance of 0.
Simulates a simple 3D audio effect.
Accepts the angle in degrees (as Int16) in relation to the source of the sound (0 is directly in front, 90 directly to the right, and so on) and a distance (as Word8) from the source of the sound (where 255 is very far away, and 0 extremely close).
Returns an action that, when executed, removes this effect. That action simply calls effectPosition with both angle and distance set to 0.
Swaps the left and right channel sound.
If given True, will swap the sound channels.
Returns an action that, when executed, removes this effect. That action simply calls effectReverseStereo with False.
Initialize the library by loading support for a certain set of sample/music formats.
Note that calling this is not strictly necessary: support for a certain format will be loaded automatically when attempting to load data in that format. Using initialize allows you to decide when to load support.
You may call this function multiple times.
Used with initialize to designate loading support for a particular sample/music format.
Cleans up any loaded libraries, freeing memory.
Gets the major, minor, patch versions of the linked SDL2_mixer library.