DEADSOFTWARE

osx: fix library linking (sdl_mixer)
[d2df-sdl.git] / src / lib / sdl2 / SDL2_mixer.pas
1 {$MODE DELPHI}
2 unit SDL2_mixer;
4 {*
5 SDL_mixer: An audio mixer library based on the SDL library
6 Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
8 This software is provided 'as-is', without any express or implied
9 warranty. In no event will the authors be held liable for any damages
10 arising from the use of this software.
12 Permission is granted to anyone to use this software for any purpose,
13 including commercial applications, and to alter it and redistribute it
14 freely, subject to the following restrictions:
16 1. The origin of this software must not be misrepresented; you must not
17 claim that you wrote the original software. If you use this software
18 in a product, an acknowledgment in the product documentation would be
19 appreciated but is not required.
20 2. Altered source versions must be plainly marked as such, and must not be
21 misrepresented as being the original software.
22 3. This notice may not be removed or altered from any source distribution.
23 *}
25 {* ChangeLog: (Header Translation)
26 ----------
28 v.1.72-stable; 29.09.2013: fixed bug with procedures without parameters
29 (they must have brackets)
30 v.1.70-stable; 16.09.2013: Initial Commit
32 *}
34 interface
36 {$I jedi.inc}
38 uses
39 SDL2;
41 const
42 {$IFDEF WINDOWS}
43 MIX_LibName = 'SDL2_mixer.dll';
44 {$ENDIF}
46 {$IFDEF UNIX}
47 {$IFDEF DARWIN}
48 {$LINKLIB libSDL2_mixer}
49 MIX_LibName = 'libSDL2_mixer.dylib';
50 {$ELSE}
51 {$IFDEF FPC}
52 MIX_LibName = 'libSDL2_mixer.so';
53 {$ELSE}
54 MIX_LibName = 'libSDL2_mixer.so.0';
55 {$ENDIF}
56 {$ENDIF}
57 {$ENDIF}
59 {$IFDEF MACOS}
60 MIX_LibName = 'SDL2_mixer';
61 {$IFDEF FPC}
62 {$linklib libSDL2_mixer}
63 {$ENDIF}
64 {$ENDIF}
66 {* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL *}
67 const
68 SDL_MIXER_MAJOR_VERSION = 2;
69 SDL_MIXER_MINOR_VERSION = 0;
70 SDL_MIXER_PATCHLEVEL = 0;
72 {* This macro can be used to fill a version structure with the compile-time
73 * version of the SDL_mixer library.
74 *}
75 procedure SDL_MIXER_VERSION(Out X: TSDL_Version);
77 {* Backwards compatibility *}
78 const
79 MIX_MAJOR_VERSION = SDL_MIXER_MAJOR_VERSION;
80 MIX_MINOR_VERSION = SDL_MIXER_MINOR_VERSION;
81 MIX_PATCHLEVEL = SDL_MIXER_PATCHLEVEL;
83 procedure MIX_VERSION(Out X: TSDL_Version);
85 {* This function gets the version of the dynamically linked SDL_mixer library.
86 it should NOT be used to fill a version structure, instead you should
87 use the SDL_MIXER_VERSION() macro.
88 *}
89 function Mix_Linked_Version: PSDL_Version cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_Linked_Version' {$ENDIF} {$ENDIF};
91 const
92 MIX_INIT_FLAC = $00000001;
93 MIX_INIT_MOD = $00000002;
94 MIX_INIT_MODPLUG = $00000004;
95 MIX_INIT_MP3 = $00000008;
96 MIX_INIT_OGG = $00000010;
97 MIX_INIT_FLUIDSYNTH = $00000020;
98 type
99 TMIX_InitFlags = Byte;
101 {* Loads dynamic libraries and prepares them for use. Flags should be
102 one or more flags from MIX_InitFlags OR'd together.
103 It returns the flags successfully initialized, or 0 on failure.
104 *}
105 function Mix_Init(flags: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_Init' {$ENDIF} {$ENDIF};
107 {* Unloads libraries loaded with Mix_Init *}
108 procedure Mix_Quit() cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_Quit' {$ENDIF} {$ENDIF};
111 {* The default mixer has 8 simultaneous mixing channels *}
112 {$IFNDEF MIX_CHANNELS}
113 const
114 MIX_CHANNELS = 8;
115 {$ENDIF}
117 {* Good default values for a PC soundcard *}
118 const
119 MIX_DEFAULT_FREQUENCY = 22050;
120 MIX_DEFAULT_CHANNELS = 2;
121 MIX_MAX_VOLUME = 128; {* Volume of a chunk *}
123 {$IFDEF FPC}
124 {$IF DEFINED(ENDIAN_LITTLE)}
125 MIX_DEFAULT_FORMAT = AUDIO_S16LSB;
126 {$ELSEIF DEFINED(ENDIAN_BIG)}
127 MIX_DEFAULT_FORMAT = AUDIO_S16MSB;
128 {$ELSE}
129 {$FATAL Unable to determine endianness.}
130 {$IFEND}
131 {$ENDIF}
133 {* The internal format for an audio chunk *}
134 type
135 PMix_Chunk = ^TMix_Chunk;
136 TMix_Chunk = record
137 allocated: Integer;
138 abuf: PUInt8;
139 alen: UInt32;
140 volume: UInt8; {* Per-sample volume, 0-128 *}
141 end;
143 {* The different fading types supported *}
144 type
145 TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN);
147 TMix_MusicType = (MUS_NONE,
148 MUS_CMD,
149 MUS_WAV,
150 MUS_MOD,
151 MUS_MID,
152 MUS_OGG,
153 MUS_MP3,
154 MUS_MP3_MAD,
155 MUS_FLAC,
156 MUS_MODPLUG);
158 {* The internal format for a music chunk interpreted via mikmod *}
159 PMix_Music = ^TMix_Music;
160 TMix_Music = record end;
162 {* Open the mixer with a certain audio format *}
163 function Mix_OpenAudio(frequency: Integer; format: UInt16; channels: Integer; chunksize: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_OpenAudio' {$ENDIF} {$ENDIF};
165 {* Dynamically change the number of channels managed by the mixer.
166 If decreasing the number of channels, the upper channels are
167 stopped.
168 This function returns the new number of allocated channels.
169 *}
170 function Mix_AllocateChannels(numchans: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_AllocateChannels' {$ENDIF} {$ENDIF};
172 {* Find out what the actual audio device parameters are.
173 This function returns 1 if the audio has been opened, 0 otherwise.
174 *}
175 function Mix_QuerySpec(frequency: PInt; format: PUInt16; channels: PInt): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_QuerySpec' {$ENDIF} {$ENDIF};
177 {* Load a wave file or a music (.mod .s3m .it .xm) file *}
178 function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: Integer): PMix_Chunk cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_LoadWAV_RW' {$ENDIF} {$ENDIF};
179 function Mix_LoadWAV(_file: PAnsiChar): PMix_Chunk;
180 function Mix_LoadMUS(_file: PAnsiChar): PMix_Music cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_LoadMUS' {$ENDIF} {$ENDIF};
182 {* Load a music file from an SDL_RWop object (Ogg and MikMod specific currently)
183 Matt Campbell (matt@campbellhome.dhs.org) April 2000 *}
184 function Mix_LoadMUS_RW(src: PSDL_RWops; freesrc: Integer): PMix_Music cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_LoadMUS_RW' {$ENDIF} {$ENDIF};
186 {* Load a music file from an SDL_RWop object assuming a specific format *}
187 function Mix_LoadMUSType_RW(src: PSDL_RWops; _type: TMix_MusicType; freesrc: Integer): PMix_Music cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_LoadMUSType_RW' {$ENDIF} {$ENDIF};
189 {* Load a wave file of the mixer format from a memory buffer *}
190 function Mix_QuickLoad_WAV(mem: PUInt8): PMix_Chunk cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_QuickLoad_WAV' {$ENDIF} {$ENDIF};
192 {* Load raw audio data of the mixer format from a memory buffer *}
193 function Mix_QuickLoad_RAW(mem: PUInt8; len: UInt32): PMix_Chunk cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_QuickLoad_RAW' {$ENDIF} {$ENDIF};
195 {* Free an audio chunk previously loaded *}
196 procedure Mix_FreeChunk(chunk: PMix_Chunk) cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_FreeChunk' {$ENDIF} {$ENDIF};
197 procedure Mix_FreeMusic(music: PMix_Music) cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_FreeMusic' {$ENDIF} {$ENDIF};
199 {* Get a list of chunk/music decoders that this build of SDL_mixer provides.
200 This list can change between builds AND runs of the program, if external
201 libraries that add functionality become available.
202 You must successfully call Mix_OpenAudio() before calling these functions.
203 This API is only available in SDL_mixer 1.2.9 and later.
205 // usage...
206 int i;
207 const int total = Mix_GetNumChunkDecoders();
208 for (i = 0; i < total; i++)
209 printf("Supported chunk decoder: [%s]\n", Mix_GetChunkDecoder(i));
211 Appearing in this list doesn't promise your specific audio file will
212 decode...but it's handy to know if you have, say, a functioning Timidity
213 install.
215 These return values are static, read-only data; do not modify or free it.
216 The pointers remain valid until you call Mix_CloseAudio().
217 *}
218 function Mix_GetNumChunkDecoders: Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GetNumChunkDecoders' {$ENDIF} {$ENDIF};
219 function Mix_GetChunkDecoder(index: Integer): PAnsiChar cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GetChunkDecoder' {$ENDIF} {$ENDIF};
220 function Mix_GetNumMusicDecoders: Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GetNumMusicDecoders' {$ENDIF} {$ENDIF};
221 function Mix_GetMusicDecoder(index: Integer): PAnsiChar cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GetMusicDecoder' {$ENDIF} {$ENDIF};
223 {* Find out the music format of a mixer music, or the currently playing
224 music, if 'music' is NULL.
225 *}
226 function Mix_GetMusicType(music: TMix_Music): TMix_MusicType cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GetMusicType' {$ENDIF} {$ENDIF};
228 {* Set a function that is called after all mixing is performed.
229 This can be used to provide real-time visual display of the audio stream
230 or add a custom mixer filter for the stream data.
231 *}
232 type
233 TMix_Func = procedure(udata: Pointer; stream: PUInt8; len: Integer);
235 procedure Mix_SetPostMix(func: TMix_Func; arg: Pointer) cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_SetPostMix' {$ENDIF} {$ENDIF};
237 {* Add your own music player or additional mixer function.
238 If 'mix_func' is NULL, the default music player is re-enabled.
239 *}
240 procedure Mix_HookMusic(func: TMix_Func; arg: Pointer) cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_HookMusic' {$ENDIF} {$ENDIF};
242 {* Add your own callback when the music has finished playing.
243 This callback is only called if the music finishes naturally.
244 *}
245 type
246 PMix_Music_Finished = ^TMix_Music_Finished;
247 TMix_Music_Finished = procedure();
248 procedure Mix_HookMusicFinished(music_finished: PMix_Music_Finished) cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_HookMusicFinished' {$ENDIF} {$ENDIF};
250 {* Get a pointer to the user data for the current music hook *}
251 function Mix_GetMusicHookData: Pointer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GetMusicHookData' {$ENDIF} {$ENDIF};
253 {*
254 * Add your own callback when a channel has finished playing. NULL
255 * to disable callback. The callback may be called from the mixer's audio
256 * callback or it could be called as a result of Mix_HaltChannel(), etc.
257 * do not call SDL_LockAudio() from this callback; you will either be
258 * inside the audio callback, or SDL_mixer will explicitly lock the audio
259 * before calling your callback.
260 *}
261 type
262 TMix_Channel_Finished = procedure(channel: Integer); cdecl;
263 procedure Mix_ChannelFinished(channel_finished: TMix_Channel_Finished) cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_ChannelFinished' {$ENDIF} {$ENDIF};
265 {* Special Effects API by ryan c. gordon. (icculus@icculus.org) *}
266 const
267 MIX_CHANNEL_POST = -2;
269 {* This is the format of a special effect callback:
271 * myeffect(int chan, void *stream, int len, void *udata);
273 * (chan) is the channel number that your effect is affecting. (stream) is
274 * the buffer of data to work upon. (len) is the size of (stream), and
275 * (udata) is a user-defined bit of data, which you pass as the last arg of
276 * Mix_RegisterEffect(), and is passed back unmolested to your callback.
277 * Your effect changes the contents of (stream) based on whatever parameters
278 * are significant, or just leaves it be, if you prefer. You can do whatever
279 * you like to the buffer, though, and it will continue in its changed state
280 * down the mixing pipeline, through any other effect functions, then finally
281 * to be mixed with the rest of the channels and music for the final output
282 * stream.
284 * DO NOT EVER call SDL_LockAudio() from your callback function!
285 *}
286 type
287 TMix_EffectFunc_t = procedure(chan: Integer; stream: Pointer; len: Integer; udata: Pointer);
289 {*
290 * This is a callback that signifies that a channel has finished all its
291 * loops and has completed playback. This gets called if the buffer
292 * plays out normally, or if you call Mix_HaltChannel(), implicitly stop
293 * a channel via Mix_AllocateChannels(), or unregister a callback while
294 * it's still playing.
296 * DO NOT EVER call SDL_LockAudio() from your callback function!
297 *}
298 type
299 TMix_EffectDone_t = procedure(chan: Integer; udata: Pointer);
301 {* Register a special effect function. At mixing time, the channel data is
302 * copied into a buffer and passed through each registered effect function.
303 * After it passes through all the functions, it is mixed into the final
304 * output stream. The copy to buffer is performed once, then each effect
305 * function performs on the output of the previous effect. Understand that
306 * this extra copy to a buffer is not performed if there are no effects
307 * registered for a given chunk, which saves CPU cycles, and any given
308 * effect will be extra cycles, too, so it is crucial that your code run
309 * fast. Also note that the data that your function is given is in the
310 * format of the sound device, and not the format you gave to Mix_OpenAudio(),
311 * although they may in reality be the same. This is an unfortunate but
312 * necessary speed concern. Use Mix_QuerySpec() to determine if you can
313 * handle the data before you register your effect, and take appropriate
314 * actions.
315 * You may also specify a callback (Mix_EffectDone_t) that is called when
316 * the channel finishes playing. This gives you a more fine-grained control
317 * than Mix_ChannelFinished(), in case you need to free effect-specific
318 * resources, etc. If you don't need this, you can specify NULL.
319 * You may set the callbacks before or after calling Mix_PlayChannel().
320 * Things like Mix_SetPanning() are just internal special effect functions,
321 * so if you are using that, you've already incurred the overhead of a copy
322 * to a separate buffer, and that these effects will be in the queue with
323 * any functions you've registered. The list of registered effects for a
324 * channel is reset when a chunk finishes playing, so you need to explicitly
325 * set them with each call to Mix_PlayChannel*().
326 * You may also register a special effect function that is to be run after
327 * final mixing occurs. The rules for these callbacks are identical to those
328 * in Mix_RegisterEffect, but they are run after all the channels and the
329 * music have been mixed into a single stream, whereas channel-specific
330 * effects run on a given channel before any other mixing occurs. These
331 * global effect callbacks are call "posteffects". Posteffects only have
332 * their Mix_EffectDone_t function called when they are unregistered (since
333 * the main output stream is never "done" in the same sense as a channel).
334 * You must unregister them manually when you've had enough. Your callback
335 * will be told that the channel being mixed is (MIX_CHANNEL_POST) if the
336 * processing is considered a posteffect.
338 * After all these effects have finished processing, the callback registered
339 * through Mix_SetPostMix() runs, and then the stream goes to the audio
340 * device.
342 * DO NOT EVER call SDL_LockAudio() from your callback function!
344 * returns zero if error (no such channel), nonzero if added.
345 * Error messages can be retrieved from Mix_GetError().
346 *}
347 function Mix_RegisterEffect(chan: Integer; f: TMix_EffectFunc_t; d: TMix_EffectDone_t; arg: Pointer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_RegisterEffect' {$ENDIF} {$ENDIF};
349 {* You may not need to call this explicitly, unless you need to stop an
350 * effect from processing in the middle of a chunk's playback.
351 * Posteffects are never implicitly unregistered as they are for channels,
352 * but they may be explicitly unregistered through this function by
353 * specifying MIX_CHANNEL_POST for a channel.
354 * returns zero if error (no such channel or effect), nonzero if removed.
355 * Error messages can be retrieved from Mix_GetError().
356 *}
357 function Mix_UnregisterEffect(channel: Integer; f: TMix_EffectFunc_t): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_UnregisterEffect' {$ENDIF} {$ENDIF};
359 {* You may not need to call this explicitly, unless you need to stop all
360 * effects from processing in the middle of a chunk's playback. Note that
361 * this will also shut off some internal effect processing, since
362 * Mix_SetPanning() and others may use this API under the hood. This is
363 * called internally when a channel completes playback.
364 * Posteffects are never implicitly unregistered as they are for channels,
365 * but they may be explicitly unregistered through this function by
366 * specifying MIX_CHANNEL_POST for a channel.
367 * returns zero if error (no such channel), nonzero if all effects removed.
368 * Error messages can be retrieved from Mix_GetError().
369 *}
370 function Mix_UnregisterAllEffects(channel: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_UnregisterEffects' {$ENDIF} {$ENDIF};
372 const
373 MIX_EFFECTSMAXSPEED = 'MIX_EFFECTSMAXSPEED';
375 {*
376 * These are the internally-defined mixing effects. They use the same API that
377 * effects defined in the application use, but are provided here as a
378 * convenience. Some effects can reduce their quality or use more memory in
379 * the name of speed; to enable this, make sure the environment variable
380 * MIX_EFFECTSMAXSPEED (see above) is defined before you call
381 * Mix_OpenAudio().
382 *}
384 {* Set the panning of a channel. The left and right channels are specified
385 * as integers between 0 and 255, quietest to loudest, respectively.
387 * Technically, this is just individual volume control for a sample with
388 * two (stereo) channels, so it can be used for more than just panning.
389 * If you want real panning, call it like this:
391 * Mix_SetPanning(channel, left, 255 - left);
393 * ...which isn't so hard.
395 * Setting (channel) to MIX_CHANNEL_POST registers this as a posteffect, and
396 * the panning will be done to the final mixed stream before passing it on
397 * to the audio device.
399 * This uses the Mix_RegisterEffect() API internally, and returns without
400 * registering the effect function if the audio device is not configured
401 * for stereo output. Setting both (left) and (right) to 255 causes this
402 * effect to be unregistered, since that is the data's normal state.
404 * returns zero if error (no such channel or Mix_RegisterEffect() fails),
405 * nonzero if panning effect enabled. Note that an audio device in mono
406 * mode is a no-op, but this call will return successful in that case.
407 * Error messages can be retrieved from Mix_GetError().
408 *}
409 function Mix_SetPanning(channel: Integer; left: UInt8; right: UInt8): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_SetPanning' {$ENDIF} {$ENDIF};
411 {* Set the position of a channel. (angle) is an integer from 0 to 360, that
412 * specifies the location of the sound in relation to the listener. (angle)
413 * will be reduced as neccesary (540 becomes 180 degrees, -100 becomes 260).
414 * Angle 0 is due north, and rotates clockwise as the value increases.
415 * For efficiency, the precision of this effect may be limited (angles 1
416 * through 7 might all produce the same effect, 8 through 15 are equal, etc).
417 * (distance) is an integer between 0 and 255 that specifies the space
418 * between the sound and the listener. The larger the number, the further
419 * away the sound is. Using 255 does not guarantee that the channel will be
420 * culled from the mixing process or be completely silent. For efficiency,
421 * the precision of this effect may be limited (distance 0 through 5 might
422 * all produce the same effect, 6 through 10 are equal, etc). Setting (angle)
423 * and (distance) to 0 unregisters this effect, since the data would be
424 * unchanged.
426 * If you need more precise positional audio, consider using OpenAL for
427 * spatialized effects instead of SDL_mixer. This is only meant to be a
428 * basic effect for simple "3D" games.
430 * If the audio device is configured for mono output, then you won't get
431 * any effectiveness from the angle; however, distance attenuation on the
432 * channel will still occur. While this effect will function with stereo
433 * voices, it makes more sense to use voices with only one channel of sound,
434 * so when they are mixed through this effect, the positioning will sound
435 * correct. You can convert them to mono through SDL before giving them to
436 * the mixer in the first place if you like.
438 * Setting (channel) to MIX_CHANNEL_POST registers this as a posteffect, and
439 * the positioning will be done to the final mixed stream before passing it
440 * on to the audio device.
442 * This is a convenience wrapper over Mix_SetDistance() and Mix_SetPanning().
444 * returns zero if error (no such channel or Mix_RegisterEffect() fails),
445 * nonzero if position effect is enabled.
446 * Error messages can be retrieved from Mix_GetError().
447 *}
448 function Mix_SetPosition(channel: Integer; angle: SInt16; distance: UInt8): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_SetPosition' {$ENDIF} {$ENDIF};
450 {* Set the "distance" of a channel. (distance) is an integer from 0 to 255
451 * that specifies the location of the sound in relation to the listener.
452 * Distance 0 is overlapping the listener, and 255 is as far away as possible
453 * A distance of 255 does not guarantee silence; in such a case, you might
454 * want to try changing the chunk's volume, or just cull the sample from the
455 * mixing process with Mix_HaltChannel().
456 * For efficiency, the precision of this effect may be limited (distances 1
457 * through 7 might all produce the same effect, 8 through 15 are equal, etc).
458 * (distance) is an integer between 0 and 255 that specifies the space
459 * between the sound and the listener. The larger the number, the further
460 * away the sound is.
461 * Setting (distance) to 0 unregisters this effect, since the data would be
462 * unchanged.
463 * If you need more precise positional audio, consider using OpenAL for
464 * spatialized effects instead of SDL_mixer. This is only meant to be a
465 * basic effect for simple "3D" games.
467 * Setting (channel) to MIX_CHANNEL_POST registers this as a posteffect, and
468 * the distance attenuation will be done to the final mixed stream before
469 * passing it on to the audio device.
471 * This uses the Mix_RegisterEffect() API internally.
473 * returns zero if error (no such channel or Mix_RegisterEffect() fails),
474 * nonzero if position effect is enabled.
475 * Error messages can be retrieved from Mix_GetError().
476 *}
477 function Mix_SetDistance(channel: Integer; distance: UInt8): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_SetDistance' {$ENDIF} {$ENDIF};
479 {*
480 * !!! FIXME : Haven't implemented, since the effect goes past the
481 * end of the sound buffer. Will have to think about this.
482 * --ryan.
483 *}
484 //#if 0
485 {* Causes an echo effect to be mixed into a sound. (echo) is the amount
486 * of echo to mix. 0 is no echo, 255 is infinite (and probably not
487 * what you want).
489 * Setting (channel) to MIX_CHANNEL_POST registers this as a posteffect, and
490 * the reverbing will be done to the final mixed stream before passing it on
491 * to the audio device.
493 * This uses the Mix_RegisterEffect() API internally. If you specify an echo
494 * of zero, the effect is unregistered, as the data is already in that state.
496 * returns zero if error (no such channel or Mix_RegisterEffect() fails),
497 * nonzero if reversing effect is enabled.
498 * Error messages can be retrieved from Mix_GetError().
499 *}
500 //extern no_parse_DECLSPEC int SDLCALL Mix_SetReverb(int channel, Uint8 echo);
501 //#endif
503 {* Causes a channel to reverse its stereo. This is handy if the user has his
504 * speakers hooked up backwards, or you would like to have a minor bit of
505 * psychedelia in your sound code. :) Calling this function with (flip)
506 * set to non-zero reverses the chunks's usual channels. If (flip) is zero,
507 * the effect is unregistered.
509 * This uses the Mix_RegisterEffect() API internally, and thus is probably
510 * more CPU intensive than having the user just plug in his speakers
511 * correctly. Mix_SetReverseStereo() returns without registering the effect
512 * function if the audio device is not configured for stereo output.
514 * If you specify MIX_CHANNEL_POST for (channel), then this the effect is used
515 * on the final mixed stream before sending it on to the audio device (a
516 * posteffect).
518 * returns zero if error (no such channel or Mix_RegisterEffect() fails),
519 * nonzero if reversing effect is enabled. Note that an audio device in mono
520 * mode is a no-op, but this call will return successful in that case.
521 * Error messages can be retrieved from Mix_GetError().
522 *}
523 function Mix_SetReverseStereo(channel: Integer; flip: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_SetReverseStereo' {$ENDIF} {$ENDIF};
525 {* end of effects API. --ryan. *}
527 {* Reserve the first channels (0 -> n-1) for the application, i.e. don't allocate
528 them dynamically to the next sample if requested with a -1 value below.
529 Returns the number of reserved channels.
530 *}
531 function Mix_ReserveChannels(num: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_ReverseChannels' {$ENDIF} {$ENDIF};
533 {* Channel grouping functions *}
535 {* Attach a tag to a channel. A tag can be assigned to several mixer
536 channels, to form groups of channels.
537 If 'tag' is -1, the tag is removed (actually -1 is the tag used to
538 represent the group of all the channels).
539 Returns true if everything was OK.
540 *}
541 function Mix_GroupChannel(which: Integer; tag: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GroupChannel' {$ENDIF} {$ENDIF};
542 {* Assign several consecutive channels to a group *}
543 function Mix_GroupChannels(from: Integer; _to: Integer; tag: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GroupChannels' {$ENDIF} {$ENDIF};
544 {* Finds the first available channel in a group of channels,
545 returning -1 if none are available.
546 *}
547 function Mix_GroupAvailable(tag: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GroupAvailable' {$ENDIF} {$ENDIF};
548 {* Returns the number of channels in a group. This is also a subtle
549 way to get the total number of channels when 'tag' is -1
550 *}
551 function Mix_GroupCount(tag: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GroupCount' {$ENDIF} {$ENDIF};
552 {* Finds the "oldest" sample playing in a group of channels *}
553 function Mix_GroupOldest(tag: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GroupOldest' {$ENDIF} {$ENDIF};
554 {* Finds the "most recent" (i.e. last) sample playing in a group of channels *}
555 function Mix_GroupNewer(tag: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GroupNewer' {$ENDIF} {$ENDIF};
557 {* Play an audio chunk on a specific channel.
558 If the specified channel is -1, play on the first free channel.
559 If 'loops' is greater than zero, loop the sound that many times.
560 If 'loops' is -1, loop inifinitely (~65000 times).
561 Returns which channel was used to play the sound.
562 *}
563 function Mix_PlayChannel(channel: Integer; chunk: PMix_Chunk; loops: Integer): Integer;
564 {* The same as above, but the sound is played at most 'ticks' milliseconds *}
565 function Mix_PlayChannelTimed(channel: Integer; chunk: PMix_Chunk; loops: Integer; ticks: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_PlayChannelTimed' {$ENDIF} {$ENDIF};
566 function Mix_PlayMusic(music: PMix_Music; loops: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_PlayMusic' {$ENDIF} {$ENDIF};
568 {* Fade in music or a channel over "ms" milliseconds, same semantics as the "Play" functions *}
569 function Mix_FadeInMusic(music: PMix_Music; loops: Integer; ms: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_FadeInMusic' {$ENDIF} {$ENDIF};
570 function Mix_FadeInMusicPos(music: PMix_Music; loops: Integer; ms: Integer; position: Double): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_FadeInMusicPos' {$ENDIF} {$ENDIF};
571 function Mix_FadeInChannel(channel: Integer; chunk: PMix_Chunk; loops: Integer; ms: Integer): Integer;
572 function Mix_FadeInChannelTimed(channel: Integer; chunk: PMix_Chunk; loops: Integer; ms: Integer; ticks: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_FadeInChannelTimed' {$ENDIF} {$ENDIF};
574 {* Set the volume in the range of 0-128 of a specific channel or chunk.
575 If the specified channel is -1, set volume for all channels.
576 Returns the original volume.
577 If the specified volume is -1, just return the current volume.
578 *}
579 function Mix_Volume(channel: Integer; volume: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_Volume' {$ENDIF} {$ENDIF};
580 function Mix_VolumeChunk(chunk: PMix_Chunk; volume: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_VolumeChunk' {$ENDIF} {$ENDIF};
581 function Mix_VolumeMusic(volume: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_VolumeMusic' {$ENDIF} {$ENDIF};
583 {* Halt playing of a particular channel *}
584 function Mix_HaltChannel(channel: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_HaltChannel' {$ENDIF} {$ENDIF};
585 function Mix_HaltGroup(tag: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_HaltGroup' {$ENDIF} {$ENDIF};
586 function Mix_HaltMusic: Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_HaltMusic' {$ENDIF} {$ENDIF};
588 {* Change the expiration delay for a particular channel.
589 The sample will stop playing after the 'ticks' milliseconds have elapsed,
590 or remove the expiration if 'ticks' is -1
591 *}
592 function Mix_ExpireChannel(channel: Integer; ticks: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_ExpireChannel' {$ENDIF} {$ENDIF};
594 {* Halt a channel, fading it out progressively till it's silent
595 The ms parameter indicates the number of milliseconds the fading
596 will take.
597 *}
598 function Mix_FadeOutChannel(which: Integer; ms: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_FadeOutChannel' {$ENDIF} {$ENDIF};
599 function Mix_FadeOutGroup(tag: Integer; ms: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_FadeOutGroup' {$ENDIF} {$ENDIF};
600 function Mix_FadeOutMusic(ms: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_FadeOutMusic' {$ENDIF} {$ENDIF};
602 {* Query the fading status of a channel *}
603 function Mix_FadingMusic: TMix_Fading cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_FadingMusic' {$ENDIF} {$ENDIF};
604 function Mix_FadingChannel(which: Integer): TMix_Fading cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_FadingChannel' {$ENDIF} {$ENDIF};
606 {* Pause/Resume a particular channel *}
607 procedure Mix_Pause(channel: Integer) cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_Pause' {$ENDIF} {$ENDIF};
608 procedure Mix_Resume(channel: Integer) cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_Resume' {$ENDIF} {$ENDIF};
609 function Mix_Paused(channel: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_Paused' {$ENDIF} {$ENDIF};
611 {* Pause/Resume the music stream *}
612 procedure Mix_PauseMusic cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_PauseMusic' {$ENDIF} {$ENDIF};
613 procedure Mix_ResumeMusic cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_ResumeMusic' {$ENDIF} {$ENDIF};
614 procedure Mix_RewindMusic cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_RewindMusic' {$ENDIF} {$ENDIF};
615 function Mix_PausedMusic: Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_PausedMusic' {$ENDIF} {$ENDIF};
617 {* Set the current position in the music stream.
618 This returns 0 if successful, or -1 if it failed or isn't implemented.
619 This function is only implemented for MOD music formats (set pattern
620 order number) and for OGG, FLAC, MP3_MAD, and MODPLUG music (set
621 position in seconds), at the moment.
622 *}
623 function Mix_SetMusicPosition(position: Double): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_SetMusicPosition' {$ENDIF} {$ENDIF};
625 {* Check the status of a specific channel.
626 If the specified channel is -1, check all channels.
627 *}
628 function Mix_Playing(channel: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_Playing' {$ENDIF} {$ENDIF};
629 function Mix_PlayingMusic: Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_PlayingMusic' {$ENDIF} {$ENDIF};
631 {* Stop music and set external music playback command *}
632 function Mix_SetMusicCMD(command: PAnsiChar): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_SetMusicCMD' {$ENDIF} {$ENDIF};
634 {* Synchro value is set by MikMod from modules while playing *}
635 function Mix_SetSynchroValue(value: Integer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_SetSynchroValue' {$ENDIF} {$ENDIF};
636 function Mix_GetSynchroValue: Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GetSynchroValue' {$ENDIF} {$ENDIF};
638 {* Set/Get/Iterate SoundFonts paths to use by supported MIDI backends *}
639 function Mix_SetSoundFonts(paths: PAnsiChar): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_SetSoundFonts' {$ENDIF} {$ENDIF};
640 function Mix_GetSoundFonts: PAnsiChar cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GetSoundFonts' {$ENDIF} {$ENDIF};
642 type
643 TMix_SoundFunc = function(c: PAnsiChar; p: Pointer): Integer;
645 function Mix_EachSoundFont(func: TMix_SoundFunc; data: Pointer): Integer cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_EachSoundFont' {$ENDIF} {$ENDIF};
647 {* Get the Mix_Chunk currently associated with a mixer channel
648 Returns NULL if it's an invalid channel, or there's no chunk associated.
649 *}
650 function Mix_GetChunk(channel: Integer): PMix_Chunk cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_GetChunk' {$ENDIF} {$ENDIF};
652 {* Close the mixer, halting all playing audio *}
653 procedure Mix_CloseAudio cdecl; external MIX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_MIX_CloseAudio' {$ENDIF} {$ENDIF};
655 {* We'll use SDL for reporting errors *}
656 function Mix_SetError(const fmt: PAnsiChar): SInt32; cdecl;
657 function Mix_GetError: PAnsiChar; cdecl;
659 implementation
661 procedure SDL_MIXER_VERSION(Out X: TSDL_Version);
662 begin
663 X.major := SDL_MIXER_MAJOR_VERSION;
664 X.minor := SDL_MIXER_MINOR_VERSION;
665 X.patch := SDL_MIXER_PATCHLEVEL;
666 end;
668 procedure MIX_VERSION(Out X: TSDL_Version);
669 begin
670 SDL_MIXER_VERSION(X);
671 end;
673 function Mix_FadeInChannel(channel: Integer; chunk: PMix_Chunk; loops: Integer; ms: Integer): Integer;
674 begin
675 Result := Mix_FadeInChannelTimed(channel, chunk, loops, ms, -1);
676 end;
678 function Mix_PlayChannel(channel: Integer; chunk: PMix_Chunk; loops: Integer): Integer;
679 begin
680 Result := Mix_PlayChannelTimed(channel, chunk, loops, -1);
681 end;
683 function Mix_LoadWAV(_file: PAnsiChar): PMix_Chunk;
684 begin
685 Result := Mix_LoadWAV_RW(SDL_RWFromFile(_file, 'rb'), 1);
686 end;
688 function Mix_SetError(const fmt: PAnsiChar): SInt32; cdecl;
689 begin
690 Result := SDL_SetError(fmt);
691 end;
693 function Mix_GetError: PAnsiChar; cdecl;
694 begin
695 Result := SDL_GetError();
696 end;
698 end.