sdl2_mixer.pas 37 KB

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