DEADSOFTWARE

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