/Users/hercules/trunk/SDL-1.2/include/SDL_audio.h File Reference

#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "SDL_endian.h"
#include "SDL_mutex.h"
#include "SDL_thread.h"
#include "SDL_rwops.h"
#include "begin_code.h"
#include "close_code.h"

Go to the source code of this file.

Data Structures

struct  SDL_AudioSpec
struct  SDL_AudioCVT

Defines

#define SDL_LoadWAV(file, spec, audio_buf, audio_len)   SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
#define SDL_MIX_MAXVOLUME   128
Audio format flags
defaults to LSB byte order

#define AUDIO_U8   0x0008
#define AUDIO_S8   0x8008
#define AUDIO_U16LSB   0x0010
#define AUDIO_S16LSB   0x8010
#define AUDIO_U16MSB   0x1010
#define AUDIO_S16MSB   0x9010
#define AUDIO_U16   AUDIO_U16LSB
#define AUDIO_S16   AUDIO_S16LSB
Native audio byte ordering
#define AUDIO_U16SYS   AUDIO_U16LSB
#define AUDIO_S16SYS   AUDIO_S16LSB

Enumerations

enum  SDL_audiostatus { SDL_AUDIO_STOPPED = 0, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED }

Functions

DECLSPEC char *SDLCALL SDL_AudioDriverName (char *namebuf, int maxlen)
DECLSPEC int SDLCALL SDL_OpenAudio (SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
DECLSPEC SDL_audiostatus SDLCALL SDL_GetAudioStatus (void)
DECLSPEC void SDLCALL SDL_PauseAudio (int pause_on)
DECLSPEC SDL_AudioSpec *SDLCALL SDL_LoadWAV_RW (SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
DECLSPEC void SDLCALL SDL_FreeWAV (Uint8 *audio_buf)
DECLSPEC int SDLCALL SDL_BuildAudioCVT (SDL_AudioCVT *cvt, Uint16 src_format, Uint8 src_channels, int src_rate, Uint16 dst_format, Uint8 dst_channels, int dst_rate)
DECLSPEC int SDLCALL SDL_ConvertAudio (SDL_AudioCVT *cvt)
DECLSPEC void SDLCALL SDL_MixAudio (Uint8 *dst, const Uint8 *src, Uint32 len, int volume)
DECLSPEC void SDLCALL SDL_CloseAudio (void)
Audio Init and Quit
These functions are used internally, and should not be used unless you have a specific need to specify the audio driver you want to use. You should normally use SDL_Init() or SDL_InitSubSystem().

DECLSPEC int SDLCALL SDL_AudioInit (const char *driver_name)
DECLSPEC void SDLCALL SDL_AudioQuit (void)
Audio Locks
The lock manipulated by these functions protects the callback function. During a LockAudio/UnlockAudio pair, you can be guaranteed that the callback function is not running. Do not call these from the callback function or you will cause deadlock.

DECLSPEC void SDLCALL SDL_LockAudio (void)
DECLSPEC void SDLCALL SDL_UnlockAudio (void)


Detailed Description

Access to the raw audio mixing buffer for the SDL library

Define Documentation

#define AUDIO_S16LSB   0x8010

Signed 16-bit samples

#define AUDIO_S16MSB   0x9010

As above, but big-endian byte order

#define AUDIO_S8   0x8008

Signed 8-bit samples

#define AUDIO_U16LSB   0x0010

Unsigned 16-bit samples

#define AUDIO_U16MSB   0x1010

As above, but big-endian byte order

#define AUDIO_U8   0x0008

Unsigned 8-bit samples

#define SDL_LoadWAV ( file,
spec,
audio_buf,
audio_len   )     SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)

Compatibility convenience function -- loads a WAV from a file


Function Documentation

DECLSPEC char* SDLCALL SDL_AudioDriverName ( char *  namebuf,
int  maxlen 
)

This function fills the given character buffer with the name of the current audio driver, and returns a pointer to it if the audio driver has been initialized. It returns NULL if no driver has been initialized.

DECLSPEC int SDLCALL SDL_BuildAudioCVT ( SDL_AudioCVT cvt,
Uint16  src_format,
Uint8  src_channels,
int  src_rate,
Uint16  dst_format,
Uint8  dst_channels,
int  dst_rate 
)

This function takes a source format and rate and a destination format and rate, and initializes the 'cvt' structure with information needed by SDL_ConvertAudio() to convert a buffer of audio data from one format to the other.

Returns:
This function returns 0, or -1 if there was an error.

DECLSPEC void SDLCALL SDL_CloseAudio ( void   ) 

This function shuts down audio processing and closes the audio device.

DECLSPEC int SDLCALL SDL_ConvertAudio ( SDL_AudioCVT cvt  ) 

Once you have initialized the 'cvt' structure using SDL_BuildAudioCVT(), created an audio buffer cvt->buf, and filled it with cvt->len bytes of audio data in the source format, this function will convert it in-place to the desired format. The data conversion may expand the size of the audio data, so the buffer cvt->buf should be allocated after the cvt structure is initialized by SDL_BuildAudioCVT(), and should be cvt->len*cvt->len_mult bytes long.

DECLSPEC void SDLCALL SDL_FreeWAV ( Uint8 *  audio_buf  ) 

This function frees data previously allocated with SDL_LoadWAV_RW()

DECLSPEC SDL_audiostatus SDLCALL SDL_GetAudioStatus ( void   ) 

Get the current audio state

DECLSPEC SDL_AudioSpec* SDLCALL SDL_LoadWAV_RW ( SDL_RWops src,
int  freesrc,
SDL_AudioSpec spec,
Uint8 **  audio_buf,
Uint32 *  audio_len 
)

This function loads a WAVE from the data source, automatically freeing that source if 'freesrc' is non-zero. For example, to load a WAVE file, you could do:

 SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...); 

If this function succeeds, it returns the given SDL_AudioSpec, filled with the audio data format of the wave data, and sets 'audio_buf' to a malloc()'d buffer containing the audio data, and sets 'audio_len' to the length of that audio buffer, in bytes. You need to free the audio buffer with SDL_FreeWAV() when you are done with it.

This function returns NULL and sets the SDL error message if the wave file cannot be opened, uses an unknown data format, or is corrupt. Currently raw and MS-ADPCM WAVE files are supported.

DECLSPEC void SDLCALL SDL_MixAudio ( Uint8 *  dst,
const Uint8 *  src,
Uint32  len,
int  volume 
)

This takes two audio buffers of the playing audio format and mixes them, performing addition, volume adjustment, and overflow clipping. The volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME for full audio volume. Note this does not change hardware volume. This is provided for convenience -- you can mix your own audio data.

DECLSPEC int SDLCALL SDL_OpenAudio ( SDL_AudioSpec desired,
SDL_AudioSpec obtained 
)

This function opens the audio device with the desired parameters, and returns 0 if successful, placing the actual hardware parameters in the structure pointed to by 'obtained'. If 'obtained' is NULL, the audio data passed to the callback function will be guaranteed to be in the requested format, and will be automatically converted to the hardware audio format if necessary. This function returns -1 if it failed to open the audio device, or couldn't set up the audio thread.

The audio device starts out playing silence when it's opened, and should be enabled for playing by calling SDL_PauseAudio(0) when you are ready for your audio callback function to be called. Since the audio driver may modify the requested size of the audio buffer, you should allocate any local mixing buffers after you open the audio device.

See also:
SDL_AudioSpec

DECLSPEC void SDLCALL SDL_PauseAudio ( int  pause_on  ) 

This function pauses and unpauses the audio callback processing. It should be called with a parameter of 0 after opening the audio device to start playing sound. This is so you can safely initialize data for your callback function after opening the audio device. Silence will be written to the audio device during the pause.


Generated on Mon Sep 21 21:29:50 2009 for Simple DirectMedia Layer by  doxygen 1.5.8