DEADSOFTWARE

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