5 * These are what the 16 bits in SDL_AudioFormat currently mean...
6 * (Unspecified bits are always zero).
9 ++-----------------------sample is signed if set
11 || ++-----------sample is bigendian if set
13 || || ++---sample is float if set
15 || || || +---sample bit size---+
17 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
19 * There are macros in SDL 2.0 and later to query these bits.
22 TSDL_AudioFormat = UInt16;
28 SDL_AUDIO_MASK_BITSIZE = ($FF);
29 SDL_AUDIO_MASK_DATATYPE = (1 shl 8);
30 SDL_AUDIO_MASK_ENDIAN = (1 shl 12);
31 SDL_AUDIO_MASK_SIGNED = (1 shl 15);
33 function SDL_AUDIO_BITSIZE(x: Cardinal): Cardinal;
34 function SDL_AUDIO_ISFLOAT(x: Cardinal): Cardinal;
35 function SDL_AUDIO_ISBIGENDIAN(x: Cardinal): Cardinal;
36 function SDL_AUDIO_ISSIGNED(x: Cardinal): Cardinal;
37 function SDL_AUDIO_ISINT(x: Cardinal): Cardinal;
38 function SDL_AUDIO_ISLITTLEENDIAN(x: Cardinal): Cardinal;
39 function SDL_AUDIO_ISUNSIGNED(x: Cardinal): Cardinal;
44 * Defaults to LSB byte order.
47 AUDIO_U8 = $0008; {**< Unsigned 8-bit samples *}
48 AUDIO_S8 = $8008; {**< Signed 8-bit samples *}
49 AUDIO_U16LSB = $0010; {**< Unsigned 16-bit samples *}
50 AUDIO_S16LSB = $8010; {**< Signed 16-bit samples *}
51 AUDIO_U16MSB = $1010; {**< As above, but big-endian byte order *}
52 AUDIO_S16MSB = $9010; {**< As above, but big-endian byte order *}
53 AUDIO_U16 = AUDIO_U16LSB;
54 AUDIO_S16 = AUDIO_S16LSB;
60 AUDIO_S32LSB = $8020; {**< 32-bit integer samples *}
61 AUDIO_S32MSB = $9020; {**< As above, but big-endian byte order *}
62 AUDIO_S32 = AUDIO_S32LSB;
68 AUDIO_F32LSB = $8120; {**< 32-bit floating point samples *}
69 AUDIO_F32MSB = $9120; {**< As above, but big-endian byte order *}
70 AUDIO_F32 = AUDIO_F32LSB;
73 * Native audio byte ordering
76 {$IF DEFINED(ENDIAN_LITTLE)}
77 AUDIO_U16SYS = AUDIO_U16LSB;
78 AUDIO_S16SYS = AUDIO_S16LSB;
79 AUDIO_S32SYS = AUDIO_S32LSB;
80 AUDIO_F32SYS = AUDIO_F32LSB;
81 {$ELSEIF DEFINED(ENDIAN_BIG)}
82 AUDIO_U16SYS = AUDIO_U16MSB;
83 AUDIO_S16SYS = AUDIO_S16MSB;
84 AUDIO_S32SYS = AUDIO_S32MSB;
85 AUDIO_F32SYS = AUDIO_F32MSB;
87 {$FATAL Cannot determine endianness.}
94 * Which audio format changes are allowed when opening a device.
97 SDL_AUDIO_ALLOW_FREQUENCY_CHANGE = $00000001;
98 SDL_AUDIO_ALLOW_FORMAT_CHANGE = $00000002;
99 SDL_AUDIO_ALLOW_CHANNELS_CHANGE = $00000004;
100 SDL_AUDIO_ALLOW_ANY_CHANGE = (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE or
101 SDL_AUDIO_ALLOW_FORMAT_CHANGE or
102 SDL_AUDIO_ALLOW_CHANNELS_CHANGE);
107 * This function is called when the audio device needs more data.
109 * userdata An application-specific parameter saved in
110 * the SDL_AudioSpec structure
111 * stream A pointer to the audio data buffer.
112 * len The length of that buffer in bytes.
114 * Once the callback returns, the buffer will no longer be valid.
115 * Stereo samples are stored in a LRLRLR ordering.
118 TSDL_AudioCallback = procedure(userdata: Pointer; stream: PUInt8; len: Integer) cdecl;
121 * The calculated values in this structure are calculated by SDL_OpenAudio().
124 PSDL_AudioSpec = ^TSDL_AudioSpec;
125 TSDL_AudioSpec = record
126 freq: Integer; {**< DSP frequency -- samples per second *}
127 format: TSDL_AudioFormat; {**< Audio data format *}
128 channels: UInt8; {**< Number of channels: 1 mono, 2 stereo *}
129 silence: UInt8; {**< Audio buffer silence value (calculated) *}
130 samples: UInt16; {**< Audio buffer size in samples (power of 2) *}
131 padding: UInt16; {**< Necessary for some compile environments *}
132 size: UInt32; {**< Audio buffer size in bytes (calculated) *}
133 callback: TSDL_AudioCallback;
137 PSDL_AudioCVT = ^TSDL_AudioCVT;
138 TSDL_AudioFilter = procedure(cvt: PSDL_AudioCVT; format: TSDL_AudioFormat) cdecl;
141 * A structure to hold a set of audio conversion filters and buffers.
143 TSDL_AudioCVT = record
144 needed: Integer; {**< Set to 1 if conversion possible *}
145 src_format: TSDL_AudioFormat; {**< Source audio format *}
146 dst_format: TSDL_AudioFormat; {**< Target audio format *}
147 rate_incr: Double; {**< Rate conversion increment *}
148 buf: PUInt8; {**< Buffer to hold entire audio data *}
149 len: Integer; {**< Length of original audio buffer *}
150 len_cvt: Integer; {**< Length of converted audio buffer *}
151 len_mult: Integer; {**< buffer must be len*len_mult big *}
152 len_ratio: Double; {**< Given len, final size is len*len_ratio *}
153 filters: array[0..9] of TSDL_AudioFilter; {**< Filter list *}
154 filter_index: Integer; {**< Current audio conversion function *}
158 {* Function prototypes *}
161 * Driver discovery functions
163 * These functions return the list of built in audio drivers, in the
164 * order that they are normally initialized by default.
167 function SDL_GetNumAudioDrivers: Integer cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetNumAudioDrivers' {$ENDIF} {$ENDIF};
168 function SDL_GetAudioDriver(index: Integer): PAnsiChar cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetAudioDriver' {$ENDIF} {$ENDIF};
171 * Initialization and cleanup
173 * These functions are used internally, and should not be used unless
174 * you have a specific need to specify the audio driver you want to
175 * use. You should normally use SDL_Init() or SDL_InitSubSystem().
178 function SDL_AudioInit(driver_name: PAnsiChar): Integer cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AudioInit' {$ENDIF} {$ENDIF};
179 procedure SDL_AudioQuit cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AudioQuit' {$ENDIF} {$ENDIF};
182 * This function returns the name of the current audio driver, or NULL
183 * if no driver has been initialized.
185 function SDL_GetCurrentAudioDriver: PAnsiChar cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetCurrentAudioDriver' {$ENDIF} {$ENDIF};
188 * This function opens the audio device with the desired parameters, and
189 * returns 0 if successful, placing the actual hardware parameters in the
190 * structure pointed to by obtained. If obtained is NULL, the audio
191 * data passed to the callback function will be guaranteed to be in the
192 * requested format, and will be automatically converted to the hardware
193 * audio format if necessary. This function returns -1 if it failed
194 * to open the audio device, or couldn't set up the audio thread.
196 * When filling in the desired audio spec structure,
197 * - desired->freq should be the desired audio frequency in samples-per-
199 * - desired->format should be the desired audio format.
200 * - desired->samples is the desired size of the audio buffer, in
201 * samples. This number should be a power of two, and may be adjusted by
202 * the audio driver to a value more suitable for the hardware. Good values
203 * seem to range between 512 and 8096 inclusive, depending on the
204 * application and CPU speed. Smaller values yield faster response time,
205 * but can lead to underflow if the application is doing heavy processing
206 * and cannot fill the audio buffer in time. A stereo sample consists of
207 * both right and left channels in LR ordering.
208 * Note that the number of samples is directly related to time by the
209 * following formula: ms := (samples*1000)/freq;
210 * - desired->size is the size in bytes of the audio buffer, and is
211 * calculated by SDL_OpenAudio().
212 * - desired->silence is the value used to set the buffer to silence,
213 * and is calculated by SDL_OpenAudio().
214 * - desired->callback should be set to a function that will be called
215 * when the audio device is ready for more data. It is passed a pointer
216 * to the audio buffer, and the length in bytes of the audio buffer.
217 * This function usually runs in a separate thread, and so you should
218 * protect data structures that it accesses by calling SDL_LockAudio()
219 * and SDL_UnlockAudio() in your code.
220 * - desired->userdata is passed as the first parameter to your callback
223 * The audio device starts out playing silence when it's opened, and should
224 * be enabled for playing by calling SDL_PauseAudio(0) when you are ready
225 * for your audio callback function to be called. Since the audio driver
226 * may modify the requested size of the audio buffer, you should allocate
227 * any local mixing buffers after you open the audio device.
229 function SDL_OpenAudio(desired: PSDL_AudioSpec; obtained: PSDL_AudioSpec): Integer cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_OpenAudio' {$ENDIF} {$ENDIF};
232 * SDL Audio Device IDs.
234 * A successful call to SDL_OpenAudio() is always device id 1, and legacy
235 * SDL audio APIs assume you want this device ID. SDL_OpenAudioDevice() calls
236 * always returns devices >= 2 on success. The legacy calls are good both
237 * for backwards compatibility and when you don't care about multiple,
238 * specific, or capture devices.
241 TSDL_AudioDeviceID = UInt32;
244 * Get the number of available devices exposed by the current driver.
245 * Only valid after a successfully initializing the audio subsystem.
246 * Returns -1 if an explicit list of devices can't be determined; this is
247 * not an error. For example, if SDL is set up to talk to a remote audio
248 * server, it can't list every one available on the Internet, but it will
249 * still allow a specific host to be specified to SDL_OpenAudioDevice().
251 * In many common cases, when this function returns a value <= 0, it can still
252 * successfully open the default device (NULL for first argument of
253 * SDL_OpenAudioDevice()).
255 function SDL_GetNumAudioDevices(iscapture: Integer): Integer cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetNumAudioDevices' {$ENDIF} {$ENDIF};
258 * Get the human-readable name of a specific audio device.
259 * Must be a value between 0 and (number of audio devices-1).
260 * Only valid after a successfully initializing the audio subsystem.
261 * The values returned by this function reflect the latest call to
262 * SDL_GetNumAudioDevices(); recall that function to redetect available
265 * The string returned by this function is UTF-8 encoded, read-only, and
266 * managed internally. You are not to free it. If you need to keep the
267 * string for any length of time, you should make your own copy of it, as it
268 * will be invalid next time any of several other SDL functions is called.
270 function SDL_GetAudioDeviceName(index: Integer; iscapture: Integer): PAnsiChar cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetAudioDeviceName' {$ENDIF} {$ENDIF};
273 * Open a specific audio device. Passing in a device name of NULL requests
274 * the most reasonable default (and is equivalent to calling SDL_OpenAudio()).
276 * The device name is a UTF-8 string reported by SDL_GetAudioDeviceName(), but
277 * some drivers allow arbitrary and driver-specific strings, such as a
278 * hostname/IP address for a remote audio server, or a filename in the
281 * 0 on error, a valid device ID that is >= 2 on success.
283 * SDL_OpenAudio(), unlike this function, always acts on device ID 1.
285 function SDL_OpenAudioDevice(device: PAnsiChar;
287 desired: PSDL_AudioSpec;
288 obtained: PSDL_AudioSpec;
289 allowed_changes: Integer): TSDL_AudioDeviceID cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_OpenAudioDevice' {$ENDIF} {$ENDIF};
294 * Get the current audio state.
298 TSDL_AudioStatus = (SDL_AUDIO_STOPPED,SDL_AUDIO_PLAYING,SDL_AUDIO_PAUSED);
300 function SDL_GetAudioStatus: TSDL_AudioStatus cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetAudioStatus' {$ENDIF} {$ENDIF};
302 function SDL_GetAudioDeviceStatus(dev: TSDL_AudioDeviceID): TSDL_AudioStatus cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetAudioDeviceStatus' {$ENDIF} {$ENDIF};
306 * Pause audio functions
308 * These functions pause and unpause the audio callback processing.
309 * They should be called with a parameter of 0 after opening the audio
310 * device to start playing sound. This is so you can safely initialize
311 * data for your callback function after opening the audio device.
312 * Silence will be written to the audio device during the pause.
315 procedure SDL_PauseAudio(pause_on: Integer) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_PauseAudio' {$ENDIF} {$ENDIF};
316 procedure SDL_PauseAudioDevice(dev: TSDL_AudioDeviceID; pause_on: Integer) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_PauseAudioDevice' {$ENDIF} {$ENDIF};
317 {*Pause audio functions*}
320 * This function loads a WAVE from the data source, automatically freeing
321 * that source if freesrc is non-zero. For example, to load a WAVE file,
324 * SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...);
327 * If this function succeeds, it returns the given SDL_AudioSpec,
328 * filled with the audio data format of the wave data, and sets
329 * *audio_buf to a malloc()'d buffer containing the audio data,
330 * and sets *audio_len to the length of that audio buffer, in bytes.
331 * You need to free the audio buffer with SDL_FreeWAV() when you are
334 * This function returns NULL and sets the SDL error message if the
335 * wave file cannot be opened, uses an unknown data format, or is
336 * corrupt. Currently raw and MS-ADPCM WAVE files are supported.
338 function SDL_LoadWAV_RW(src: PSDL_RWops; freesrc: Integer; spec: PSDL_AudioSpec; audio_buf: PPUInt8; audio_len: PUInt32): PSDL_AudioSpec cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_LoadWAV_RW' {$ENDIF} {$ENDIF};
341 * Loads a WAV from a file.
342 * Compatibility convenience function.
345 function SDL_LoadWAV(_file: PAnsiChar; spec: PSDL_AudioSpec; audio_buf: PPUInt8; audio_len: PUInt32): PSDL_AudioSpec;
348 * This function frees data previously allocated with SDL_LoadWAV_RW()
350 procedure SDL_FreeWAV(audio_buf: PUInt8) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_FreeWAV' {$ENDIF} {$ENDIF};
353 * This function takes a source format and rate and a destination format
354 * and rate, and initializes the cvt structure with information needed
355 * by SDL_ConvertAudio() to convert a buffer of audio data from one format
358 * -1 if the format conversion is not supported, 0 if there's
359 * no conversion needed, or 1 if the audio filter is set up.
361 function SDL_BuildAudioCVT(cvt: PSDL_AudioCVT;
362 src_format: TSDL_AudioFormat;
365 dst_format: TSDL_AudioFormat;
367 dst_rate: Integer): Integer cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_BuildAudioCVT' {$ENDIF} {$ENDIF};
370 * Once you have initialized the cvt structure using SDL_BuildAudioCVT(),
371 * created an audio buffer cvt->buf, and filled it with cvt->len bytes of
372 * audio data in the source format, this function will convert it in-place
373 * to the desired format.
375 * The data conversion may expand the size of the audio data, so the buffer
376 * cvt->buf should be allocated after the cvt structure is initialized by
377 * SDL_BuildAudioCVT(), and should be cvt->len*cvt->len_mult bytes long.
379 function SDL_ConvertAudio(cvt: PSDL_AudioCVT): Integer cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ConvertAudio' {$ENDIF} {$ENDIF};
382 SDL_MIX_MAXVOLUME = 128;
385 * This takes two audio buffers of the playing audio format and mixes
386 * them, performing addition, volume adjustment, and overflow clipping.
387 * The volume ranges from 0 - 128, and should be set to ::SDL_MIX_MAXVOLUME
388 * for full audio volume. Note this does not change hardware volume.
389 * This is provided for convenience -- you can mix your own audio data.
391 procedure SDL_MixAudio(dst: PUInt8; src: PUInt8; len: UInt32; volume: Integer) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_MixAudio' {$ENDIF} {$ENDIF};
394 * This works like SDL_MixAudio(), but you specify the audio format instead of
395 * using the format of audio device 1. Thus it can be used when no audio
396 * device is open at all.
398 procedure SDL_MixAudioFormat(dst: PUInt8; src: PUInt8; format: TSDL_AudioFormat; len: UInt32; volume: Integer) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_MixAudioFormat' {$ENDIF} {$ENDIF};
401 * Audio lock functions
403 * The lock manipulated by these functions protects the callback function.
404 * During a SDL_LockAudio()/SDL_UnlockAudio() pair, you can be guaranteed that
405 * the callback function is not running. Do not call these from the callback
406 * function or you will cause deadlock.
409 procedure SDL_LockAudio cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_LockAudio' {$ENDIF} {$ENDIF};
410 procedure SDL_LockAudioDevice(dev: TSDL_AudioDeviceID) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_LockAudioDevice' {$ENDIF} {$ENDIF};
411 procedure SDL_UnlockAudio cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_Unlock' {$ENDIF} {$ENDIF};
412 procedure SDL_UnlockAudioDevice(dev: TSDL_AudioDeviceID) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_UnlockAudioDevice' {$ENDIF} {$ENDIF};
413 {*Audio lock functions*}
416 * This function shuts down audio processing and closes the audio device.
418 procedure SDL_CloseAudio cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CloseAudio' {$ENDIF} {$ENDIF};
419 procedure SDL_CloseAudioDevice(dev: TSDL_AudioDeviceID) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CloseAudioDevice' {$ENDIF} {$ENDIF};
422 * 1 if audio device is still functioning, zero if not, -1 on error.
424 function SDL_AudioDeviceConnected(dev: TSDL_AudioDeviceID): Integer cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AudioDeviceConnected' {$ENDIF} {$ENDIF};