sdl2-2.1.0: Both high- and low-level bindings to the SDL library (version 2.0.3).

Safe HaskellNone
LanguageHaskell2010

SDL.Audio

Contents

Description

SDL.Audio provides a high-level API to SDL's audio device capabilities.

Synopsis

Managing AudioDevices

data AudioDevice Source

An open audio device. These can be created via openAudioDevice and should be closed with closeAudioDevice

Instances

Opening and Closing AudioDevices

openAudioDevice :: MonadIO m => OpenDeviceSpec -> m (AudioDevice, AudioSpec) Source

Attempt to open the closest matching AudioDevice, as specified by the given OpenDeviceSpec.

See SDL_OpenAudioDevice for C documentation.

closeAudioDevice :: MonadIO m => AudioDevice -> m () Source

See SDL_CloseAudioDevice for C documentation.

data OpenDeviceSpec Source

A specification to openAudioDevice, indicating the desired output format. Note that many of these properties are Changeable, meaning that you can choose whether or not SDL should interpret your specification as an unbreakable request (Mandate), or as an approximation Desire.

Constructors

forall sampleType . OpenDeviceSpec 

Fields

openDeviceFreq :: !(Changeable CInt)

The output audio frequency in herts.

openDeviceFormat :: !(Changeable (AudioFormat sampleType))

The format of audio that will be sampled from the output buffer.

openDeviceChannels :: !(Changeable Channels)

The amount of audio channels.

openDeviceSamples :: !Word16

Output audio buffer size in samples. This should be a power of 2.

openDeviceCallback :: forall actualSampleType. AudioFormat actualSampleType -> IOVector actualSampleType -> IO ()

A callback to invoke whenever new sample data is required. The callback will be passed a single MVector that must be filled with audio data.

openDeviceUsage :: !AudioDeviceUsage

How you intend to use the opened AudioDevice - either for outputting or capturing audio.

openDeviceName :: !(Maybe Text)

The name of the AudioDevice that should be opened. If Nothing, any suitable AudioDevice will be used.

data Channels Source

How many channels audio should be played on

Constructors

Mono

A single speaker configuration

Stereo

A traditional left/right stereo system

Quad 
FivePointOne
  1. 1 surround sound

data Changeable a Source

Used to indicate to SDL whether it is allowed to open other audio devices (if a property is marked as a Desire) or if it should fail if the device is unavailable (Mandate).

Constructors

Mandate !a

Mandate this exact property value, and fail if a matching audio device cannot be found.

Desire !a

Desire this property value, but allow other audio devices to be opened.

Working with Opened Devices

Locking AudioDevices

setAudioDeviceLocked :: MonadIO m => AudioDevice -> LockState -> m () Source

Lock an AudioDevice such that its associated callback will not be called until the device is unlocked.

data LockState Source

Whether a device should be locked or unlocked.

Constructors

Locked

Lock the device, preventing the callback from producing data.

Unlocked

Unlock the device, resuming calls to the callback.

Switching Playback States

data PlaybackState Source

Whether to allow an AudioDevice to play sound or remain paused.

Constructors

Pause

Pause the AudioDevice, which will stop producing/capturing audio.

Play

Resume the AudioDevice.

setAudioDevicePlaybackState :: MonadIO m => AudioDevice -> PlaybackState -> m () Source

Change the playback state of an AudioDevice.

Querying an AudioDevices Status.

data AudioDeviceStatus Source

Opened devices are always Playing or Paused in normal circumstances. A failing device may change its status to Stopped at any time, and closing a device will progress to Stopped too.

Constructors

Playing

The AudioDevice is playing.

Paused

The AudioDevice is paused.

Stopped

The AudioDevice is stopped.

AudioFormat

data AudioFormat sampleType where Source

Information about what format an audio bytestream is. The type variable t indicates the type used for audio buffer samples. It is determined by the choice of the provided SampleBitSize. For example:

AudioFormat UnsignedInteger Sample8Bit Native :: AudioFormat Word8

Indicating that an 8-bit audio format in the platforms native endianness uses a buffer of Word8 values.

Instances

Eq (AudioFormat sampleType) Source 
Ord (AudioFormat sampleType) Source 
Show (AudioFormat sampleType) Source 

Enumerating AudioDevices

getAudioDeviceNames :: MonadIO m => AudioDeviceUsage -> m (Maybe (Vector Text)) Source

Enumerate all AudioDevices attached to this system, that can be used as specified by the given AudioDeviceUsage. SDL cannot always guarantee that this list can be produced, in which case Nothing will be returned.

AudioSpec

data AudioSpec Source

AudioSpec is the concrete specification of how an AudioDevice was sucessfully opened. Unlike OpenDeviceSpec, which specifies what you want, AudioSpec specifies what you have.

audioSpecFreq :: AudioSpec -> CInt Source

DSP frequency (samples per second)

audioSpecFormat :: AudioSpec -> AudioFormat sampleType Source

Audio data format

audioSpecChannels :: AudioSpec -> Channels Source

Number of separate sound channels

audioSpecSilence :: AudioSpec -> Word8 Source

Calculated udio buffer silence value

audioSpecSize :: AudioSpec -> Word32 Source

Calculated audio buffer size in bytes

audioSpecCallback :: AudioSpec -> AudioFormat sampleType -> IOVector sampleType -> IO () Source

The function to call when the audio device needs more data

Audio Drivers

getAudioDrivers :: MonadIO m => m (Vector AudioDriver) Source

Obtain a list of all possible audio drivers for this system. These drivers can be used to specificially initialize the audio system.

currentAudioDriver :: MonadIO m => m (Maybe Text) Source

Query SDL for the name of the currently initialized audio driver, if possible. This will return Nothing if no driver has been initialized.

data AudioDriver Source

An abstract description of an audio driver on the host machine.

audioDriverName :: AudioDriver -> Text Source

Get the human readable name of an AudioDriver

Explicit Initialization

audioInit :: MonadIO m => AudioDriver -> m () Source

Explicitly initialize the audio system against a specific AudioDriver. Note that most users will not need to do this, as the normal initialization routines will already take care of this for you.