HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulesdl2-mixer-1.2.0.0Haskell2010

SDL.Mixer

Bindings to the SDL2_mixer library.

  • 18 types
  • 2 classes
  • 64 values

Audio setup

7 declarations

In order to use the rest of the library, you need to supply withAudio or openAudio with an Audio configuration.

datadata Format
#

A sample format.

Constructors

Instances5Bounded, Eq, Ord, Read, Show
  • Bounded FormatDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Eq FormatDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Ord FormatDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Read FormatDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Show FormatDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
datadata Output
#

The number of sound channels in output.

Instances5Bounded, Eq, Ord, Read, Show
  • Bounded OutputDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Eq OutputDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Ord OutputDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Read OutputDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Show OutputDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
typetype ChunkSize = Int
#

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.

Alternative

valuecloseAudio :: MonadIO m => m ()
#

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.

Loading audio data

5 declarations

Use load or decode to get both Chunk and Music values.

classclass Loadable a where
#

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.

Methods

Instances2Loadable
newtypenewtype Chunk
#

A loaded audio chunk.

Constructors

Instances4Eq, Show, HasVolume, Loadable
  • Eq ChunkDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Show ChunkDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • HasVolume ChunkDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Loadable ChunkDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
valuechunkDecoders :: MonadIO m => m [String]
#

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.

newtypenewtype Music
#

A loaded music file.

Music is played on a separate channel different from the normal mixing Channels.

To manipulate Music outside of post-processing callbacks, use the music variant functions listed below.

Constructors

Instances3Eq, Show, Loadable
  • Eq MusicDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Show MusicDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Loadable MusicDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
valuemusicDecoders :: MonadIO m => m [String]
#

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.

Chunks

0 declarations

Chunks are played on Channels, which can be combined into Groups.

Playing chunks

newtypenewtype Channel
#

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.

The starting Volume of each Channel is the maximum: 128.

Instances8Enum, Eq, Integral, Num, Ord, Real, …
patternpattern AllChannels :: Channel
#

Use this value when you wish to perform an operation on all Channels.

For more information, see each of the functions accepting a Channel.

valuesetChannels :: MonadIO m => Int -> m ()
#

Prepares 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.

newtypenewtype Times
#

How many times should a certain Chunk be played?

Instances6Enum, Eq, Integral, Num, Ord, Real
  • Enum TimesDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Eq TimesDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Integral TimesDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Num TimesDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Ord TimesDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Real TimesDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
patternpattern Once :: Times
#

A shorthand for playing once.

Grouping channels

newtypenewtype Group
#

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.

Instances6Enum, Eq, Integral, Num, Ord, Real
  • Enum GroupDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Eq GroupDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Integral GroupDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Num GroupDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Ord GroupDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Real GroupDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer

Controlling playback

Setting the volume

typetype Volume = Int
#

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.

classclass HasVolume a where
#

A class of all values that have a Volume.

Methods

Instances2HasVolume

Querying for status

datadata Fading
#

Describes whether a Channel is fading in, out, or not at all.

Instances4Eq, Ord, Read, Show
  • Eq FadingDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Ord FadingDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Read FadingDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer
  • Show FadingDefined in sdl2-mixer-1.2.0.0 · SDL.Mixer

Fading out

Reacting to finish

Music

0 declarations

Chunks and Music differ by the way they are played. While multiple Chunks can be played on different desired Channels at the same time, there can only be one Music playing at the same time.

Therefore, the functions used for Music are separate.

Playing music

valueplayMusic :: MonadIO m => Times -> Music -> m ()
#

Plays a given Music a certain number of Times.

The previously playing Music will be halted, unless it is fading out in which case a blocking wait occurs until it fades out completely.

Controlling playback

valuerewindMusic :: MonadIO m => m ()
#

Rewinds the Music to the beginning.

When playing new Music, it starts at the beginning by default.

This function only works with MOD, OGG, MP3 and NATIVEMIDI streams.

Setting the volume

Querying for status

Fading out

Reacting to finish

valuewhenMusicFinished :: MonadIO m => IO () -> m ()
#

Sets a callback that gets invoked each time a Music finishes playing.

Note: don't call other SDL.Mixer functions within this callback.

Effects

4 declarations
typetype Effect = Channel -> IOVector Word8 -> IO ()
#

A post-processing effect as a function operating on a mutable stream.

Note that, at the moment, this is a stream of bytes. Depending on the Audio Format you're using, you're probably going to want to treat is as a stream of 16-bit values instead.

typetype EffectFinished = Channel -> IO ()
#

A function called when a processor is finished being used.

This allows you to clean up any state you might have had.

In-built effects

valueeffectPan :: MonadIO m => Channel -> Volume -> Volume -> m (m ())
#

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.

valueeffectDistance :: MonadIO m => Channel -> Word8 -> m (m ())
#

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.

valueeffectPosition :: MonadIO m => Channel -> Int16 -> Word8 -> m (m ())
#

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.

Other

4 declarations
valueinitialize :: (Foldable f, MonadIO m) => f InitFlag -> m ()
#

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.

valuequit :: MonadIO m => m ()
#

Cleans up any loaded libraries, freeing memory.

valueversion :: (Integral a, MonadIO m) => m (a, a, a)
#

Gets the major, minor, patch versions of the linked SDL2_mixer library.