SDL2.Mixer.pas 36 KB

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