master
ブランチ master
BrickBreaker / dep / include / SDL2 / SDL_mixer.h
109.2 KB、2836行 生 Blame 履歴
1/*
2 SDL_mixer: An audio mixer library based on the SDL library
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
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
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/**
23 * \file SDL_mixer.h
24 *
25 * Header file for SDL_mixer library
26 *
27 * A simple library to play and mix sounds and musics
28 */
29#ifndef SDL_MIXER_H_
30#define SDL_MIXER_H_
31
32#include "SDL_stdinc.h"
33#include "SDL_rwops.h"
34#include "SDL_audio.h"
35#include "SDL_endian.h"
36#include "SDL_version.h"
37#include "begin_code.h"
38
39/* Set up for C function definitions, even when using C++ */
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/**
45 * Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
46 */
47#define SDL_MIXER_MAJOR_VERSION 2
48#define SDL_MIXER_MINOR_VERSION 8
49#define SDL_MIXER_PATCHLEVEL 2
50
51/**
52 * This macro can be used to fill a version structure with the compile-time
53 * version of the SDL_mixer library.
54 */
55#define SDL_MIXER_VERSION(X) \
56{ \
57 (X)->major = SDL_MIXER_MAJOR_VERSION; \
58 (X)->minor = SDL_MIXER_MINOR_VERSION; \
59 (X)->patch = SDL_MIXER_PATCHLEVEL; \
60}
61
62/* Backwards compatibility */
63#define MIX_MAJOR_VERSION SDL_MIXER_MAJOR_VERSION
64#define MIX_MINOR_VERSION SDL_MIXER_MINOR_VERSION
65#define MIX_PATCHLEVEL SDL_MIXER_PATCHLEVEL
66#define MIX_VERSION(X) SDL_MIXER_VERSION(X)
67
68#if SDL_MIXER_MAJOR_VERSION < 3 && SDL_MAJOR_VERSION < 3
69
70/**
71 * This is the version number macro for the current SDL_mixer version.
72 *
73 * In versions higher than 2.9.0, the minor version overflows into the
74 * thousands digit: for example, 2.23.0 is encoded as 4300. This macro will
75 * not be available in SDL 3.x or SDL_mixer 3.x.
76 *
77 * Deprecated, use SDL_MIXER_VERSION_ATLEAST or SDL_MIXER_VERSION instead.
78 */
79#define SDL_MIXER_COMPILEDVERSION \
80 SDL_VERSIONNUM(SDL_MIXER_MAJOR_VERSION, SDL_MIXER_MINOR_VERSION, SDL_MIXER_PATCHLEVEL)
81#endif /* SDL_MIXER_MAJOR_VERSION < 3 && SDL_MAJOR_VERSION < 3 */
82
83/**
84 * This macro will evaluate to true if compiled with SDL_mixer at least X.Y.Z.
85 */
86#define SDL_MIXER_VERSION_ATLEAST(X, Y, Z) \
87 ((SDL_MIXER_MAJOR_VERSION >= X) && \
88 (SDL_MIXER_MAJOR_VERSION > X || SDL_MIXER_MINOR_VERSION >= Y) && \
89 (SDL_MIXER_MAJOR_VERSION > X || SDL_MIXER_MINOR_VERSION > Y || SDL_MIXER_PATCHLEVEL >= Z))
90
91/**
92 * Query the version of SDL_mixer that the program is linked against.
93 *
94 * This function gets the version of the dynamically linked SDL_mixer library.
95 * This is separate from the SDL_MIXER_VERSION() macro, which tells you what
96 * version of the SDL_mixer headers you compiled against.
97 *
98 * This returns static internal data; do not free or modify it!
99 *
100 * \returns a pointer to the version information.
101 *
102 * \since This function is available since SDL_mixer 2.0.0.
103 */
104extern DECLSPEC const SDL_version * SDLCALL Mix_Linked_Version(void);
105
106/**
107 * Initialization flags
108 */
109typedef enum MIX_InitFlags
110{
111 MIX_INIT_FLAC = 0x00000001,
112 MIX_INIT_MOD = 0x00000002,
113 MIX_INIT_MP3 = 0x00000008,
114 MIX_INIT_OGG = 0x00000010,
115 MIX_INIT_MID = 0x00000020,
116 MIX_INIT_OPUS = 0x00000040,
117 MIX_INIT_WAVPACK= 0x00000080
118} MIX_InitFlags;
119
120/**
121 * Initialize SDL_mixer.
122 *
123 * This function loads dynamic libraries that SDL_mixer needs, and prepares
124 * them for use.
125 *
126 * Note that, unlike other SDL libraries, this call is optional! If you load a
127 * music file, SDL_mixer will handle initialization on the fly. This function
128 * will let you know, up front, whether a specific format will be available
129 * for use.
130 *
131 * Flags should be one or more flags from MIX_InitFlags OR'd together. It
132 * returns the flags successfully initialized, or 0 on failure.
133 *
134 * Currently, these flags are:
135 *
136 * - `MIX_INIT_FLAC`
137 * - `MIX_INIT_MOD`
138 * - `MIX_INIT_MP3`
139 * - `MIX_INIT_OGG`
140 * - `MIX_INIT_MID`
141 * - `MIX_INIT_OPUS`
142 * - `MIX_INIT_WAVPACK`
143 *
144 * More flags may be added in a future SDL_mixer release.
145 *
146 * This function may need to load external shared libraries to support various
147 * codecs, which means this function can fail to initialize that support on an
148 * otherwise-reasonable system if the library isn't available; this is not
149 * just a question of exceptional circumstances like running out of memory at
150 * startup!
151 *
152 * Note that you may call this function more than once to initialize with
153 * additional flags. The return value will reflect both new flags that
154 * successfully initialized, and also include flags that had previously been
155 * initialized as well.
156 *
157 * As this will return previously-initialized flags, it's legal to call this
158 * with zero (no flags set). This is a safe no-op that can be used to query
159 * the current initialization state without changing it at all.
160 *
161 * Since this returns previously-initialized flags as well as new ones, and
162 * you can call this with zero, you should not check for a zero return value
163 * to determine an error condition. Instead, you should check to make sure all
164 * the flags you require are set in the return value. If you have a game with
165 * data in a specific format, this might be a fatal error. If you're a generic
166 * media player, perhaps you are fine with only having WAV and MP3 support and
167 * can live without Opus playback, even if you request support for everything.
168 *
169 * Unlike other SDL satellite libraries, calls to Mix_Init do not stack; a
170 * single call to Mix_Quit() will deinitialize everything and does not have to
171 * be paired with a matching Mix_Init call. For that reason, it's considered
172 * best practices to have a single Mix_Init and Mix_Quit call in your program.
173 * While this isn't required, be aware of the risks of deviating from that
174 * behavior.
175 *
176 * After initializing SDL_mixer, the next step is to open an audio device to
177 * prepare to play sound (with Mix_OpenAudio() or Mix_OpenAudioDevice()), and
178 * load audio data to play with that device.
179 *
180 * \param flags initialization flags, OR'd together.
181 * \returns all currently initialized flags.
182 *
183 * \since This function is available since SDL_mixer 2.0.0.
184 *
185 * \sa Mix_Quit
186 */
187extern DECLSPEC int SDLCALL Mix_Init(int flags);
188
189/**
190 * Deinitialize SDL_mixer.
191 *
192 * This should be the last function you call in SDL_mixer, after freeing all
193 * other resources and closing all audio devices. This will unload any shared
194 * libraries it is using for various codecs.
195 *
196 * After this call, a call to Mix_Init(0) will return 0 (no codecs loaded).
197 *
198 * You can safely call Mix_Init() to reload various codec support after this
199 * call.
200 *
201 * Unlike other SDL satellite libraries, calls to Mix_Init do not stack; a
202 * single call to Mix_Quit() will deinitialize everything and does not have to
203 * be paired with a matching Mix_Init call. For that reason, it's considered
204 * best practices to have a single Mix_Init and Mix_Quit call in your program.
205 * While this isn't required, be aware of the risks of deviating from that
206 * behavior.
207 *
208 * \since This function is available since SDL_mixer 2.0.0.
209 *
210 * \sa Mix_Init
211 */
212extern DECLSPEC void SDLCALL Mix_Quit(void);
213
214
215/**
216 * The default mixer has 8 simultaneous mixing channels
217 */
218#ifndef MIX_CHANNELS
219#define MIX_CHANNELS 8
220#endif
221
222/* Good default values for a PC soundcard */
223#define MIX_DEFAULT_FREQUENCY 44100
224#define MIX_DEFAULT_FORMAT AUDIO_S16SYS
225#define MIX_DEFAULT_CHANNELS 2
226#define MIX_MAX_VOLUME SDL_MIX_MAXVOLUME /* Volume of a chunk */
227
228/**
229 * The internal format for an audio chunk
230 */
231typedef struct Mix_Chunk {
232 int allocated;
233 Uint8 *abuf;
234 Uint32 alen;
235 Uint8 volume; /* Per-sample volume, 0-128 */
236} Mix_Chunk;
237
238/**
239 * The different fading types supported
240 */
241typedef enum Mix_Fading {
242 MIX_NO_FADING,
243 MIX_FADING_OUT,
244 MIX_FADING_IN
245} Mix_Fading;
246
247/**
248 * These are types of music files (not libraries used to load them)
249 */
250typedef enum Mix_MusicType {
251 MUS_NONE,
252 MUS_CMD,
253 MUS_WAV,
254 MUS_MOD,
255 MUS_MID,
256 MUS_OGG,
257 MUS_MP3,
258 MUS_MP3_MAD_UNUSED,
259 MUS_FLAC,
260 MUS_MODPLUG_UNUSED,
261 MUS_OPUS,
262 MUS_WAVPACK,
263 MUS_GME
264} Mix_MusicType;
265
266/**
267 * The internal format for a music chunk interpreted via codecs
268 */
269typedef struct Mix_Music Mix_Music;
270
271/**
272 * Open the default audio device for playback.
273 *
274 * An audio device is what generates sound, so the app must open one to make
275 * noise.
276 *
277 * This function will check if SDL's audio system is initialized, and if not,
278 * it will initialize it by calling `SDL_Init(SDL_INIT_AUDIO)` on your behalf.
279 * You are free to (and encouraged to!) initialize it yourself before calling
280 * this function, as this gives your program more control over the process.
281 *
282 * This function might cover all of an application's needs, but for those that
283 * need more flexibility, the more powerful version of this function is
284 * Mix_OpenAudioDevice(). This function is equivalent to calling:
285 *
286 * ```c
287 * Mix_OpenAudioDevice(frequency, format, nchannels, chunksize, NULL,
288 * SDL_AUDIO_ALLOW_FREQUENCY_CHANGE |
289 * SDL_AUDIO_ALLOW_CHANNELS_CHANGE);
290 * ```
291 *
292 * If you aren't particularly concerned with the specifics of the audio
293 * device, and your data isn't in a specific format, the values you use here
294 * can just be reasonable defaults. SDL_mixer will convert audio data you feed
295 * it to the correct format on demand.
296 *
297 * That being said, if you have control of your audio data and you know its
298 * format ahead of time, you may save CPU time by opening the audio device in
299 * that exact format so SDL_mixer does not have to spend time converting
300 * anything behind the scenes, and can just pass the data straight through to
301 * the hardware. On some platforms, where the hardware only supports specific
302 * settings, you might have to be careful to make everything match, but your
303 * own data is often easier to control, so aim to open the device for what you
304 * need.
305 *
306 * The other reason to care about specific formats: if you plan to touch the
307 * mix buffer directly (with Mix_SetPostMix, a registered effect, or
308 * Mix_HookMusic), you might have code that expects it to be in a specific
309 * format, and you should specify that here.
310 *
311 * The audio device frequency is specified in Hz; in modern times, 48000 is
312 * often a reasonable default.
313 *
314 * The audio device format is one of SDL's AUDIO_* constants. AUDIO_S16SYS
315 * (16-bit audio) is probably a safe default. More modern systems may prefer
316 * AUDIO_F32SYS (32-bit floating point audio).
317 *
318 * The audio device channels are generally 1 for mono output, or 2 for stereo,
319 * but the brave can try surround sound configs with 4 (quad), 6 (5.1), 7
320 * (6.1) or 8 (7.1).
321 *
322 * The audio device's chunk size is the number of sample frames (one sample
323 * per frame for mono output, two samples per frame in a stereo setup, etc)
324 * that are fed to the device at once. The lower the number, the lower the
325 * latency, but you risk dropouts if it gets too low. 2048 is often a
326 * reasonable default, but your app might want to experiment with 1024 or
327 * 4096.
328 *
329 * You may only have one audio device open at a time; if you want to change a
330 * setting, you must close the device and reopen it, which is not something
331 * you can do seamlessly during playback.
332 *
333 * This function does not allow you to select a specific audio device on the
334 * system, it always chooses the best default it can on your behalf (which, in
335 * many cases, is exactly what you want anyhow). If you must choose a specific
336 * device, you can do so with Mix_OpenAudioDevice() instead.
337 *
338 * If this function reports success, you are ready to start making noise! Load
339 * some audio data and start playing!
340 *
341 * The app can use Mix_QuerySpec() to determine the final device settings.
342 *
343 * When done with an audio device, probably at the end of the program, the app
344 * should dispose of the device with Mix_CloseAudio().
345 *
346 * \param frequency the frequency to playback audio at (in Hz).
347 * \param format audio format, one of SDL's AUDIO_* values.
348 * \param channels number of channels (1 is mono, 2 is stereo, etc).
349 * \param chunksize audio buffer size in sample FRAMES (total samples divided
350 * by channel count).
351 * \returns 0 if successful, -1 on error.
352 *
353 * \since This function is available since SDL_mixer 2.0.0.
354 *
355 * \sa Mix_OpenAudioDevice
356 * \sa Mix_CloseAudio
357 */
358extern DECLSPEC int SDLCALL Mix_OpenAudio(int frequency, Uint16 format, int channels, int chunksize);
359
360
361/**
362 * Open a specific audio device for playback.
363 *
364 * (A slightly simpler version of this function is available in
365 * Mix_OpenAudio(), which still might meet most applications' needs.)
366 *
367 * An audio device is what generates sound, so the app must open one to make
368 * noise.
369 *
370 * This function will check if SDL's audio system is initialized, and if not,
371 * it will initialize it by calling `SDL_Init(SDL_INIT_AUDIO)` on your behalf.
372 * You are free to (and encouraged to!) initialize it yourself before calling
373 * this function, as this gives your program more control over the process.
374 *
375 * If you aren't particularly concerned with the specifics of the audio
376 * device, and your data isn't in a specific format, the values you use here
377 * can just be reasonable defaults. SDL_mixer will convert audio data you feed
378 * it to the correct format on demand.
379 *
380 * That being said, if you have control of your audio data and you know its
381 * format ahead of time, you can save CPU time by opening the audio device in
382 * that exact format so SDL_mixer does not have to spend time converting
383 * anything behind the scenes, and can just pass the data straight through to
384 * the hardware. On some platforms, where the hardware only supports specific
385 * settings, you might have to be careful to make everything match, but your
386 * own data is often easier to control, so aim to open the device for what you
387 * need.
388 *
389 * The other reason to care about specific formats: if you plan to touch the
390 * mix buffer directly (with Mix_SetPostMix, a registered effect, or
391 * Mix_HookMusic), you might have code that expects it to be in a specific
392 * format, and you should specify that here.
393 *
394 * The audio device frequency is specified in Hz; in modern times, 48000 is
395 * often a reasonable default.
396 *
397 * The audio device format is one of SDL's AUDIO_* constants. AUDIO_S16SYS
398 * (16-bit audio) is probably a safe default. More modern systems may prefer
399 * AUDIO_F32SYS (32-bit floating point audio).
400 *
401 * The audio device channels are generally 1 for mono output, or 2 for stereo,
402 * but the brave can try surround sound configs with 4 (quad), 6 (5.1), 7
403 * (6.1) or 8 (7.1).
404 *
405 * The audio device's chunk size is the number of sample frames (one sample
406 * per frame for mono output, two samples per frame in a stereo setup, etc)
407 * that are fed to the device at once. The lower the number, the lower the
408 * latency, but you risk dropouts if it gets too low. 2048 is often a
409 * reasonable default, but your app might want to experiment with 1024 or
410 * 4096.
411 *
412 * You may only have one audio device open at a time; if you want to change a
413 * setting, you must close the device and reopen it, which is not something
414 * you can do seamlessly during playback.
415 *
416 * This function allows you to select specific audio hardware on the system
417 * with the `device` parameter. If you specify NULL, SDL_mixer will choose the
418 * best default it can on your behalf (which, in many cases, is exactly what
419 * you want anyhow). SDL_mixer does not offer a mechanism to determine device
420 * names to open, but you can use SDL_GetNumAudioDevices() to get a count of
421 * available devices and then SDL_GetAudioDeviceName() in a loop to obtain a
422 * list. If you do this, be sure to call `SDL_Init(SDL_INIT_AUDIO)` first to
423 * initialize SDL's audio system!
424 *
425 * The `allowed_changes` parameter specifies what settings are flexible. These
426 * are the `SDL_AUDIO_ALLOW_*` flags from SDL. These tell SDL_mixer that the
427 * app doesn't mind if a specific setting changes. For example, the app might
428 * need stereo data in Sint16 format, but if the sample rate or chunk size
429 * changes, the app can handle that. In that case, the app would specify
430 * `SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_SAMPLES_CHANGE`. In this
431 * case, if the system's hardware requires something other than the requested
432 * format, SDL_mixer can select what the hardware demands instead of the app.
433 * If the `SDL_AUDIO_ALLOW_` flag is not specified, SDL_mixer must convert
434 * data behind the scenes between what the app demands and what the hardware
435 * requires. If your app needs precisely what is requested, specify zero for
436 * `allowed_changes`.
437 *
438 * If changes were allowed, the app can use Mix_QuerySpec() to determine the
439 * final device settings.
440 *
441 * If this function reports success, you are ready to start making noise! Load
442 * some audio data and start playing!
443 *
444 * When done with an audio device, probably at the end of the program, the app
445 * should dispose of the device with Mix_CloseDevice().
446 *
447 * \param frequency the frequency to playback audio at (in Hz).
448 * \param format audio format, one of SDL's AUDIO_* values.
449 * \param channels number of channels (1 is mono, 2 is stereo, etc).
450 * \param chunksize audio buffer size in sample FRAMES (total samples divided
451 * by channel count).
452 * \param device the device name to open, or NULL to choose a reasonable
453 * default.
454 * \param allowed_changes Allow change flags (see SDL_AUDIO_ALLOW_* flags).
455 * \returns 0 if successful, -1 on error.
456 *
457 * \since This function is available since SDL_mixer 2.0.2.
458 *
459 * \sa Mix_OpenAudio
460 * \sa Mix_CloseDevice
461 * \sa Mix_QuerySpec
462 */
463extern DECLSPEC int SDLCALL Mix_OpenAudioDevice(int frequency, Uint16 format, int channels, int chunksize, const char* device, int allowed_changes);
464
465/**
466 * Suspend or resume the whole audio output.
467 *
468 * \param pause_on 1 to pause audio output, or 0 to resume.
469 *
470 * \since This function is available since SDL_mixer 2.8.0.
471 */
472extern DECLSPEC void SDLCALL Mix_PauseAudio(int pause_on);
473
474/**
475 * Find out what the actual audio device parameters are.
476 *
477 * If Mix_OpenAudioDevice() was called with `allowed_changes` set to anything
478 * but zero, or Mix_OpenAudio() was used, some audio device settings may be
479 * different from the application's request. This function will report what
480 * the device is actually running at.
481 *
482 * Note this is only important if the app intends to touch the audio buffers
483 * being sent to the hardware directly. If an app just wants to play audio
484 * files and let SDL_mixer handle the low-level details, this function can
485 * probably be ignored.
486 *
487 * If the audio device is not opened, this function will return 0.
488 *
489 * \param frequency On return, will be filled with the audio device's
490 * frequency in Hz.
491 * \param format On return, will be filled with the audio device's format.
492 * \param channels On return, will be filled with the audio device's channel
493 * count.
494 * \returns 1 if the audio device has been opened, 0 otherwise.
495 *
496 * \since This function is available since SDL_mixer 2.0.0.
497 *
498 * \sa Mix_OpenAudio
499 * \sa Mix_OpenAudioDevice
500 */
501extern DECLSPEC int SDLCALL Mix_QuerySpec(int *frequency, Uint16 *format, int *channels);
502
503/**
504 * Dynamically change the number of channels managed by the mixer.
505 *
506 * SDL_mixer deals with "channels," which is not the same thing as the
507 * mono/stereo channels; they might be better described as "tracks," as each
508 * one corresponds to a separate source of audio data. Three different WAV
509 * files playing at the same time would be three separate SDL_mixer channels,
510 * for example.
511 *
512 * An app needs as many channels as it has audio data it wants to play
513 * simultaneously, mixing them into a single stream to send to the audio
514 * device.
515 *
516 * SDL_mixer allocates `MIX_CHANNELS` (currently 8) channels when you open an
517 * audio device, which may be more than an app needs, but if the app needs
518 * more or wants less, this function can change it.
519 *
520 * If decreasing the number of channels, any upper channels currently playing
521 * are stopped. This will deregister all effects on those channels and call
522 * any callback specified by Mix_ChannelFinished() for each removed channel.
523 *
524 * If `numchans` is less than zero, this will return the current number of
525 * channels without changing anything.
526 *
527 * \param numchans the new number of channels, or < 0 to query current channel
528 * count.
529 * \returns the new number of allocated channels.
530 *
531 * \since This function is available since SDL_mixer 2.0.0.
532 */
533extern DECLSPEC int SDLCALL Mix_AllocateChannels(int numchans);
534
535/**
536 * Load a supported audio format into a chunk.
537 *
538 * SDL_mixer has two separate data structures for audio data. One it calls a
539 * "chunk," which is meant to be a file completely decoded into memory up
540 * front, and the other it calls "music" which is a file intended to be
541 * decoded on demand. Originally, simple formats like uncompressed WAV files
542 * were meant to be chunks and compressed things, like MP3s, were meant to be
543 * music, and you would stream one thing for a game's music and make repeating
544 * sound effects with the chunks.
545 *
546 * In modern times, this isn't split by format anymore, and most are
547 * interchangeable, so the question is what the app thinks is worth
548 * predecoding or not. Chunks might take more memory, but once they are loaded
549 * won't need to decode again, whereas music always needs to be decoded on the
550 * fly. Also, crucially, there are as many channels for chunks as the app can
551 * allocate, but SDL_mixer only offers a single "music" channel.
552 *
553 * If `freesrc` is non-zero, the RWops will be closed before returning,
554 * whether this function succeeds or not. SDL_mixer reads everything it needs
555 * from the RWops during this call in any case.
556 *
557 * There is a separate function (a macro, before SDL_mixer 2.6.0) to read
558 * files from disk without having to deal with SDL_RWops:
559 * `Mix_LoadWAV("filename.wav")` will call this function and manage those
560 * details for you.
561 *
562 * When done with a chunk, the app should dispose of it with a call to
563 * Mix_FreeChunk().
564 *
565 * \param src an SDL_RWops that data will be read from.
566 * \param freesrc non-zero to close/free the SDL_RWops before returning, zero
567 * to leave it open.
568 * \returns a new chunk, or NULL on error.
569 *
570 * \since This function is available since SDL_mixer 2.6.0 (and as a macro
571 * since 2.0.0).
572 *
573 * \sa Mix_LoadWAV
574 * \sa Mix_FreeChunk
575 */
576extern DECLSPEC Mix_Chunk * SDLCALL Mix_LoadWAV_RW(SDL_RWops *src, int freesrc);
577
578/**
579 * Load a supported audio format into a chunk.
580 *
581 * SDL_mixer has two separate data structures for audio data. One it calls a
582 * "chunk," which is meant to be a file completely decoded into memory up
583 * front, and the other it calls "music" which is a file intended to be
584 * decoded on demand. Originally, simple formats like uncompressed WAV files
585 * were meant to be chunks and compressed things, like MP3s, were meant to be
586 * music, and you would stream one thing for a game's music and make repeating
587 * sound effects with the chunks.
588 *
589 * In modern times, this isn't split by format anymore, and most are
590 * interchangeable, so the question is what the app thinks is worth
591 * predecoding or not. Chunks might take more memory, but once they are loaded
592 * won't need to decode again, whereas music always needs to be decoded on the
593 * fly. Also, crucially, there are as many channels for chunks as the app can
594 * allocate, but SDL_mixer only offers a single "music" channel.
595 *
596 * If you would rather use the abstract SDL_RWops interface to load data from
597 * somewhere other than the filesystem, you can use Mix_LoadWAV_RW() instead.
598 *
599 * When done with a chunk, the app should dispose of it with a call to
600 * Mix_FreeChunk().
601 *
602 * Note that before SDL_mixer 2.6.0, this function was a macro that called
603 * Mix_LoadWAV_RW(), creating a RWops and setting `freesrc` to 1. This macro
604 * has since been promoted to a proper API function. Older binaries linked
605 * against a newer SDL_mixer will still call Mix_LoadWAV_RW directly, as they
606 * are using the macro, which was available since the dawn of time.
607 *
608 * \param file the filesystem path to load data from.
609 * \returns a new chunk, or NULL on error.
610 *
611 * \since This function is available since SDL_mixer 2.6.0 (and as a macro
612 * since 2.0.0).
613 *
614 * \sa Mix_LoadWAV_RW
615 * \sa Mix_FreeChunk
616 */
617extern DECLSPEC Mix_Chunk * SDLCALL Mix_LoadWAV(const char *file);
618
619
620/**
621 * Load a supported audio format into a music object.
622 *
623 * SDL_mixer has two separate data structures for audio data. One it calls a
624 * "chunk," which is meant to be a file completely decoded into memory up
625 * front, and the other it calls "music" which is a file intended to be
626 * decoded on demand. Originally, simple formats like uncompressed WAV files
627 * were meant to be chunks and compressed things, like MP3s, were meant to be
628 * music, and you would stream one thing for a game's music and make repeating
629 * sound effects with the chunks.
630 *
631 * In modern times, this isn't split by format anymore, and most are
632 * interchangeable, so the question is what the app thinks is worth
633 * predecoding or not. Chunks might take more memory, but once they are loaded
634 * won't need to decode again, whereas music always needs to be decoded on the
635 * fly. Also, crucially, there are as many channels for chunks as the app can
636 * allocate, but SDL_mixer only offers a single "music" channel.
637 *
638 * When done with this music, the app should dispose of it with a call to
639 * Mix_FreeMusic().
640 *
641 * \param file a file path from where to load music data.
642 * \returns a new music object, or NULL on error.
643 *
644 * \since This function is available since SDL_mixer 2.0.0.
645 *
646 * \sa Mix_FreeMusic
647 */
648extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS(const char *file);
649
650/**
651 * Load a supported audio format into a music object.
652 *
653 * SDL_mixer has two separate data structures for audio data. One it calls a
654 * "chunk," which is meant to be a file completely decoded into memory up
655 * front, and the other it calls "music" which is a file intended to be
656 * decoded on demand. Originally, simple formats like uncompressed WAV files
657 * were meant to be chunks and compressed things, like MP3s, were meant to be
658 * music, and you would stream one thing for a game's music and make repeating
659 * sound effects with the chunks.
660 *
661 * In modern times, this isn't split by format anymore, and most are
662 * interchangeable, so the question is what the app thinks is worth
663 * predecoding or not. Chunks might take more memory, but once they are loaded
664 * won't need to decode again, whereas music always needs to be decoded on the
665 * fly. Also, crucially, there are as many channels for chunks as the app can
666 * allocate, but SDL_mixer only offers a single "music" channel.
667 *
668 * If `freesrc` is non-zero, the RWops will be closed when SDL_mixer is done
669 * with it, which will be before this function call returns if there is an
670 * error, or perhaps much later if the music is streaming for some time. The
671 * app should not attempt to use the RWops again, as it may become invalid
672 * without warning.
673 *
674 * As a convenience, there is a function to read files from disk without
675 * having to deal with SDL_RWops: `Mix_LoadMUS("filename.mp3")` will manage
676 * those details for you.
677 *
678 * This function attempts to guess the file format from incoming data. If the
679 * caller knows the format, or wants to force it, it should use
680 * Mix_LoadMUSType_RW() instead.
681 *
682 * When done with this music, the app should dispose of it with a call to
683 * Mix_FreeMusic().
684 *
685 * \param src an SDL_RWops that data will be read from.
686 * \param freesrc non-zero to close/free the SDL_RWops before returning, zero
687 * to leave it open.
688 * \returns a new music object, or NULL on error.
689 *
690 * \since This function is available since SDL_mixer 2.0.0.
691 *
692 * \sa Mix_FreeMusic
693 */
694extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *src, int freesrc);
695
696/**
697 * Load an audio format into a music object, assuming a specific format.
698 *
699 * SDL_mixer has two separate data structures for audio data. One it calls a
700 * "chunk," which is meant to be a file completely decoded into memory up
701 * front, and the other it calls "music" which is a file intended to be
702 * decoded on demand. Originally, simple formats like uncompressed WAV files
703 * were meant to be chunks and compressed things, like MP3s, were meant to be
704 * music, and you would stream one thing for a game's music and make repeating
705 * sound effects with the chunks.
706 *
707 * In modern times, this isn't split by format anymore, and most are
708 * interchangeable, so the question is what the app thinks is worth
709 * predecoding or not. Chunks might take more memory, but once they are loaded
710 * won't need to decode again, whereas music always needs to be decoded on the
711 * fly. Also, crucially, there are as many channels for chunks as the app can
712 * allocate, but SDL_mixer only offers a single "music" channel.
713 *
714 * This function loads music data, and lets the application specify the type
715 * of music being loaded, which might be useful if SDL_mixer cannot figure it
716 * out from the data stream itself.
717 *
718 * Currently, the following types are supported:
719 *
720 * - `MUS_NONE` (SDL_mixer should guess, based on the data)
721 * - `MUS_WAV` (Microsoft WAV files)
722 * - `MUS_MOD` (Various tracker formats)
723 * - `MUS_MID` (MIDI files)
724 * - `MUS_OGG` (Ogg Vorbis files)
725 * - `MUS_MP3` (MP3 files)
726 * - `MUS_FLAC` (FLAC files)
727 * - `MUS_OPUS` (Opus files)
728 * - `MUS_WAVPACK` (WavPack files)
729 *
730 * If `freesrc` is non-zero, the RWops will be closed when SDL_mixer is done
731 * with it, which will be before this function call returns if there is an
732 * error, or perhaps much later if the music is streaming for some time. The
733 * app should not attempt to use the RWops again, as it may become invalid
734 * without warning.
735 *
736 * As a convenience, there is a function to read files from disk without
737 * having to deal with SDL_RWops: `Mix_LoadMUS("filename.mp3")` will manage
738 * those details for you (but not let you specify the music type explicitly)..
739 *
740 * When done with this music, the app should dispose of it with a call to
741 * Mix_FreeMusic().
742 *
743 * \param src an SDL_RWops that data will be read from.
744 * \param type the type of audio data provided by `src`.
745 * \param freesrc non-zero to close/free the SDL_RWops before returning, zero
746 * to leave it open.
747 * \returns a new music object, or NULL on error.
748 *
749 * \since This function is available since SDL_mixer 2.0.0.
750 *
751 * \sa Mix_FreeMusic
752 */
753extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc);
754
755/**
756 * Load a WAV file from memory as quickly as possible.
757 *
758 * Unlike Mix_LoadWAV_RW, this function has several requirements, and unless
759 * you control all your audio data and know what you're doing, you should
760 * consider this function unsafe and not use it.
761 *
762 * - The provided audio data MUST be in Microsoft WAV format.
763 * - The provided audio data shouldn't use any strange WAV extensions.
764 * - The audio data MUST be in the exact same format as the audio device. This
765 * function will not attempt to convert it, or even verify it's in the right
766 * format.
767 * - The audio data must be valid; this function does not know the size of the
768 * memory buffer, so if the WAV data is corrupted, it can read past the end
769 * of the buffer, causing a crash.
770 * - The audio data must live at least as long as the returned Mix_Chunk,
771 * because SDL_mixer will use that data directly and not make a copy of it.
772 *
773 * This function will do NO error checking! Be extremely careful here!
774 *
775 * (Seriously, use Mix_LoadWAV_RW instead.)
776 *
777 * If this function is successful, the provided memory buffer must remain
778 * available until Mix_FreeChunk() is called on the returned chunk.
779 *
780 * \param mem memory buffer containing of a WAV file.
781 * \returns a new chunk, or NULL on error.
782 *
783 * \since This function is available since SDL_mixer 2.0.0.
784 *
785 * \sa Mix_LoadWAV_RW
786 * \sa Mix_FreeChunk
787 */
788extern DECLSPEC Mix_Chunk * SDLCALL Mix_QuickLoad_WAV(Uint8 *mem);
789
790/**
791 * Load a raw audio data from memory as quickly as possible.
792 *
793 * The audio data MUST be in the exact same format as the audio device. This
794 * function will not attempt to convert it, or even verify it's in the right
795 * format.
796 *
797 * If this function is successful, the provided memory buffer must remain
798 * available until Mix_FreeChunk() is called on the returned chunk.
799 *
800 * \param mem memory buffer containing raw PCM data.
801 * \param len length of buffer pointed to by `mem`, in bytes.
802 * \returns a new chunk, or NULL on error.
803 *
804 * \since This function is available since SDL_mixer 2.0.0.
805 *
806 * \sa Mix_FreeChunk
807 */
808extern DECLSPEC Mix_Chunk * SDLCALL Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len);
809
810/**
811 * Free an audio chunk.
812 *
813 * An app should call this function when it is done with a Mix_Chunk and wants
814 * to dispose of its resources.
815 *
816 * SDL_mixer will stop any channels this chunk is currently playing on. This
817 * will deregister all effects on those channels and call any callback
818 * specified by Mix_ChannelFinished() for each removed channel.
819 *
820 * \param chunk the chunk to free.
821 *
822 * \since This function is available since SDL_mixer 2.0.0.
823 *
824 * \sa Mix_LoadWAV
825 * \sa Mix_LoadWAV_RW
826 * \sa Mix_QuickLoad_WAV
827 * \sa Mix_QuickLoad_RAW
828 */
829extern DECLSPEC void SDLCALL Mix_FreeChunk(Mix_Chunk *chunk);
830
831/**
832 * Free a music object.
833 *
834 * If this music is currently playing, it will be stopped.
835 *
836 * If this music is in the process of fading out (via Mix_FadeOutMusic()),
837 * this function will *block* until the fade completes. If you need to avoid
838 * this, be sure to call Mix_HaltMusic() before freeing the music.
839 *
840 * \param music the music object to free.
841 *
842 * \since This function is available since SDL_mixer 2.0.0.
843 *
844 * \sa Mix_LoadMUS
845 * \sa Mix_LoadMUS_RW
846 * \sa Mix_LoadMUSType_RW
847 */
848extern DECLSPEC void SDLCALL Mix_FreeMusic(Mix_Music *music);
849
850/**
851 * Get a list of chunk decoders that this build of SDL_mixer provides.
852 *
853 * This list can change between builds AND runs of the program, if external
854 * libraries that add functionality become available. You must successfully
855 * call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
856 * as decoders are activated at device open time.
857 *
858 * Appearing in this list doesn't promise your specific audio file will
859 * decode...but it's handy to know if you have, say, a functioning Ogg Vorbis
860 * install.
861 *
862 * These return values are static, read-only data; do not modify or free it.
863 * The pointers remain valid until you call Mix_CloseAudio().
864 *
865 * \returns number of chunk decoders available.
866 *
867 * \since This function is available since SDL_mixer 2.0.0.
868 *
869 * \sa Mix_GetChunkDecoder
870 * \sa Mix_HasChunkDecoder
871 */
872extern DECLSPEC int SDLCALL Mix_GetNumChunkDecoders(void);
873
874/**
875 * Get a chunk decoder's name.
876 *
877 * The requested decoder's index must be between zero and
878 * Mix_GetNumChunkDecoders()-1. It's safe to call this with an invalid index;
879 * this function will return NULL in that case.
880 *
881 * This list can change between builds AND runs of the program, if external
882 * libraries that add functionality become available. You must successfully
883 * call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
884 * as decoders are activated at device open time.
885 *
886 * \param index index of the chunk decoder.
887 * \returns the chunk decoder's name.
888 *
889 * \since This function is available since SDL_mixer 2.0.0.
890 *
891 * \sa Mix_GetNumChunkDecoders
892 */
893extern DECLSPEC const char * SDLCALL Mix_GetChunkDecoder(int index);
894
895/**
896 * Check if a chunk decoder is available by name.
897 *
898 * This result can change between builds AND runs of the program, if external
899 * libraries that add functionality become available. You must successfully
900 * call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
901 * as decoders are activated at device open time.
902 *
903 * Decoder names are arbitrary but also obvious, so you have to know what
904 * you're looking for ahead of time, but usually it's the file extension in
905 * capital letters (some example names are "AIFF", "VOC", "WAV").
906 *
907 * \param name the decoder name to query.
908 * \returns SDL_TRUE if a decoder by that name is available, SDL_FALSE
909 * otherwise.
910 *
911 * \since This function is available since SDL_mixer 2.0.2.
912 *
913 * \sa Mix_GetNumChunkDecoders
914 * \sa Mix_GetChunkDecoder
915 */
916extern DECLSPEC SDL_bool SDLCALL Mix_HasChunkDecoder(const char *name);
917
918/**
919 * Get a list of music decoders that this build of SDL_mixer provides.
920 *
921 * This list can change between builds AND runs of the program, if external
922 * libraries that add functionality become available. You must successfully
923 * call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
924 * as decoders are activated at device open time.
925 *
926 * Appearing in this list doesn't promise your specific audio file will
927 * decode...but it's handy to know if you have, say, a functioning Ogg Vorbis
928 * install.
929 *
930 * These return values are static, read-only data; do not modify or free it.
931 * The pointers remain valid until you call Mix_CloseAudio().
932 *
933 * \returns number of music decoders available.
934 *
935 * \since This function is available since SDL_mixer 2.0.0.
936 *
937 * \sa Mix_GetMusicDecoder
938 * \sa Mix_HasMusicDecoder
939 */
940extern DECLSPEC int SDLCALL Mix_GetNumMusicDecoders(void);
941
942/**
943 * Get a music decoder's name.
944 *
945 * The requested decoder's index must be between zero and
946 * Mix_GetNumMusicDecoders()-1. It's safe to call this with an invalid index;
947 * this function will return NULL in that case.
948 *
949 * This list can change between builds AND runs of the program, if external
950 * libraries that add functionality become available. You must successfully
951 * call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
952 * as decoders are activated at device open time.
953 *
954 * \param index index of the music decoder.
955 * \returns the music decoder's name.
956 *
957 * \since This function is available since SDL_mixer 2.0.0.
958 *
959 * \sa Mix_GetNumMusicDecoders
960 */
961extern DECLSPEC const char * SDLCALL Mix_GetMusicDecoder(int index);
962
963/**
964 * Check if a music decoder is available by name.
965 *
966 * This result can change between builds AND runs of the program, if external
967 * libraries that add functionality become available. You must successfully
968 * call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
969 * as decoders are activated at device open time.
970 *
971 * Decoder names are arbitrary but also obvious, so you have to know what
972 * you're looking for ahead of time, but usually it's the file extension in
973 * capital letters (some example names are "MOD", "MP3", "FLAC").
974 *
975 * \param name the decoder name to query.
976 * \returns SDL_TRUE if a decoder by that name is available, SDL_FALSE
977 * otherwise.
978 *
979 * \since This function is available since SDL_mixer 2.6.0
980 *
981 * \sa Mix_GetNumMusicDecoders
982 * \sa Mix_GetMusicDecoder
983 */
984extern DECLSPEC SDL_bool SDLCALL Mix_HasMusicDecoder(const char *name);
985
986/**
987 * Find out the format of a mixer music.
988 *
989 * If `music` is NULL, this will query the currently playing music (and return
990 * MUS_NONE if nothing is currently playing).
991 *
992 * \param music the music object to query, or NULL for the currently-playing
993 * music.
994 * \returns the Mix_MusicType for the music object.
995 *
996 * \since This function is available since SDL_mixer 2.0.0
997 */
998extern DECLSPEC Mix_MusicType SDLCALL Mix_GetMusicType(const Mix_Music *music);
999
1000/**
1001 * Get the title for a music object, or its filename.
1002 *
1003 * This returns format-specific metadata. Not all file formats supply this!
1004 *
1005 * If `music` is NULL, this will query the currently-playing music.
1006 *
1007 * If music's title tag is missing or empty, the filename will be returned. If
1008 * you'd rather have the actual metadata or nothing, use
1009 * Mix_GetMusicTitleTag() instead.
1010 *
1011 * Please note that if the music was loaded from an SDL_RWops instead of a
1012 * filename, the filename returned will be an empty string ("").
1013 *
1014 * This function never returns NULL! If no data is available, it will return
1015 * an empty string ("").
1016 *
1017 * \param music the music object to query, or NULL for the currently-playing
1018 * music.
1019 * \returns the music's title if available, or the filename if not, or "".
1020 *
1021 * \since This function is available since SDL_mixer 2.6.0.
1022 *
1023 * \sa Mix_GetMusicTitleTag
1024 * \sa Mix_GetMusicArtistTag
1025 * \sa Mix_GetMusicAlbumTag
1026 * \sa Mix_GetMusicCopyrightTag
1027 */
1028extern DECLSPEC const char *SDLCALL Mix_GetMusicTitle(const Mix_Music *music);
1029
1030/**
1031 * Get the title for a music object.
1032 *
1033 * This returns format-specific metadata. Not all file formats supply this!
1034 *
1035 * If `music` is NULL, this will query the currently-playing music.
1036 *
1037 * Unlike this function, Mix_GetMusicTitle() produce a string with the music's
1038 * filename if a title isn't available, which might be preferable for some
1039 * applications.
1040 *
1041 * This function never returns NULL! If no data is available, it will return
1042 * an empty string ("").
1043 *
1044 * \param music the music object to query, or NULL for the currently-playing
1045 * music.
1046 * \returns the music's title if available, or "".
1047 *
1048 * \since This function is available since SDL_mixer 2.6.0.
1049 *
1050 * \sa Mix_GetMusicTitle
1051 * \sa Mix_GetMusicArtistTag
1052 * \sa Mix_GetMusicAlbumTag
1053 * \sa Mix_GetMusicCopyrightTag
1054 */
1055extern DECLSPEC const char *SDLCALL Mix_GetMusicTitleTag(const Mix_Music *music);
1056
1057/**
1058 * Get the artist name for a music object.
1059 *
1060 * This returns format-specific metadata. Not all file formats supply this!
1061 *
1062 * If `music` is NULL, this will query the currently-playing music.
1063 *
1064 * This function never returns NULL! If no data is available, it will return
1065 * an empty string ("").
1066 *
1067 * \param music the music object to query, or NULL for the currently-playing
1068 * music.
1069 * \returns the music's artist name if available, or "".
1070 *
1071 * \since This function is available since SDL_mixer 2.6.0.
1072 *
1073 * \sa Mix_GetMusicTitleTag
1074 * \sa Mix_GetMusicAlbumTag
1075 * \sa Mix_GetMusicCopyrightTag
1076 */
1077extern DECLSPEC const char *SDLCALL Mix_GetMusicArtistTag(const Mix_Music *music);
1078
1079/**
1080 * Get the album name for a music object.
1081 *
1082 * This returns format-specific metadata. Not all file formats supply this!
1083 *
1084 * If `music` is NULL, this will query the currently-playing music.
1085 *
1086 * This function never returns NULL! If no data is available, it will return
1087 * an empty string ("").
1088 *
1089 * \param music the music object to query, or NULL for the currently-playing
1090 * music.
1091 * \returns the music's album name if available, or "".
1092 *
1093 * \since This function is available since SDL_mixer 2.6.0.
1094 *
1095 * \sa Mix_GetMusicTitleTag
1096 * \sa Mix_GetMusicArtistTag
1097 * \sa Mix_GetMusicCopyrightTag
1098 */
1099extern DECLSPEC const char *SDLCALL Mix_GetMusicAlbumTag(const Mix_Music *music);
1100
1101/**
1102 * Get the copyright text for a music object.
1103 *
1104 * This returns format-specific metadata. Not all file formats supply this!
1105 *
1106 * If `music` is NULL, this will query the currently-playing music.
1107 *
1108 * This function never returns NULL! If no data is available, it will return
1109 * an empty string ("").
1110 *
1111 * \param music the music object to query, or NULL for the currently-playing
1112 * music.
1113 * \returns the music's copyright text if available, or "".
1114 *
1115 * \since This function is available since SDL_mixer 2.6.0.
1116 *
1117 * \sa Mix_GetMusicTitleTag
1118 * \sa Mix_GetMusicArtistTag
1119 * \sa Mix_GetMusicAlbumTag
1120 */
1121extern DECLSPEC const char *SDLCALL Mix_GetMusicCopyrightTag(const Mix_Music *music);
1122
1123typedef void (SDLCALL *Mix_MixCallback)(void *udata, Uint8 *stream, int len);
1124
1125/**
1126 * Set a function that is called after all mixing is performed.
1127 *
1128 * This can be used to provide real-time visual display of the audio stream or
1129 * add a custom mixer filter for the stream data.
1130 *
1131 * The callback will fire every time SDL_mixer is ready to supply more data to
1132 * the audio device, after it has finished all its mixing work. This runs
1133 * inside an SDL audio callback, so it's important that the callback return
1134 * quickly, or there could be problems in the audio playback.
1135 *
1136 * The data provided to the callback is in the format that the audio device
1137 * was opened in, and it represents the exact waveform SDL_mixer has mixed
1138 * from all playing chunks and music for playback. You are allowed to modify
1139 * the data, but it cannot be resized (so you can't add a reverb effect that
1140 * goes past the end of the buffer without saving some state between runs to
1141 * add it into the next callback, or resample the buffer to a smaller size to
1142 * speed it up, etc).
1143 *
1144 * The `arg` pointer supplied here is passed to the callback as-is, for
1145 * whatever the callback might want to do with it (keep track of some ongoing
1146 * state, settings, etc).
1147 *
1148 * Passing a NULL callback disables the post-mix callback until such a time as
1149 * a new one callback is set.
1150 *
1151 * There is only one callback available. If you need to mix multiple inputs,
1152 * be prepared to handle them from a single function.
1153 *
1154 * \param mix_func the callback function to become the new post-mix callback.
1155 * \param arg a pointer that is passed, untouched, to the callback.
1156 *
1157 * \since This function is available since SDL_mixer 2.0.0.
1158 *
1159 * \sa Mix_HookMusic
1160 */
1161extern DECLSPEC void SDLCALL Mix_SetPostMix(Mix_MixCallback mix_func, void *arg);
1162
1163/**
1164 * Add your own music player or additional mixer function.
1165 *
1166 * This works something like Mix_SetPostMix(), but it has some crucial
1167 * differences. Note that an app can use this _and_ Mix_SetPostMix() at the
1168 * same time. This allows an app to replace the built-in music playback,
1169 * either with it's own music decoder or with some sort of
1170 * procedurally-generated audio output.
1171 *
1172 * The supplied callback will fire every time SDL_mixer is preparing to supply
1173 * more data to the audio device. This runs inside an SDL audio callback, so
1174 * it's important that the callback return quickly, or there could be problems
1175 * in the audio playback.
1176 *
1177 * Running this callback is the first thing SDL_mixer will do when starting to
1178 * mix more audio. The buffer will contain silence upon entry, so the callback
1179 * does not need to mix into existing data or initialize the buffer.
1180 *
1181 * Note that while a callback is set through this function, SDL_mixer will not
1182 * mix any playing music; this callback is used instead. To disable this
1183 * callback (and thus reenable built-in music playback) call this function
1184 * with a NULL callback.
1185 *
1186 * The data written to by the callback is in the format that the audio device
1187 * was opened in, and upon return from the callback, SDL_mixer will mix any
1188 * playing chunks (but not music!) into the buffer. The callback cannot resize
1189 * the buffer (so you must be prepared to provide exactly the amount of data
1190 * demanded or leave it as silence).
1191 *
1192 * The `arg` pointer supplied here is passed to the callback as-is, for
1193 * whatever the callback might want to do with it (keep track of some ongoing
1194 * state, settings, etc).
1195 *
1196 * As there is only one music "channel" mixed, there is only one callback
1197 * available. If you need to mix multiple inputs, be prepared to handle them
1198 * from a single function.
1199 *
1200 * \param mix_func the callback function to become the new post-mix callback.
1201 * \param arg a pointer that is passed, untouched, to the callback.
1202 *
1203 * \since This function is available since SDL_mixer 2.0.0.
1204 *
1205 * \sa Mix_SetPostMix
1206 */
1207extern DECLSPEC void SDLCALL Mix_HookMusic(Mix_MixCallback mix_func, void *arg);
1208
1209typedef void (SDLCALL *Mix_MusicFinishedCallback)(void);
1210
1211/**
1212 * Set a callback that runs when a music object has stopped playing.
1213 *
1214 * This callback will fire when the currently-playing music has completed, or
1215 * when it has been explicitly stopped from a call to Mix_HaltMusic. As such,
1216 * this callback might fire from an arbitrary background thread at almost any
1217 * time; try to limit what you do here.
1218 *
1219 * It is legal to start a new music object playing in this callback (or
1220 * restart the one that just stopped). If the music finished normally, this
1221 * can be used to loop the music without a gap in the audio playback.
1222 *
1223 * Do not call SDL_LockAudio() from this callback; you will either be inside
1224 * the audio callback, or SDL_mixer will explicitly lock the audio before
1225 * calling your callback.
1226 *
1227 * A NULL pointer will disable the callback.
1228 *
1229 * \param music_finished the callback function to become the new notification
1230 * mechanism.
1231 *
1232 * \since This function is available since SDL_mixer 2.0.0.
1233 */
1234extern DECLSPEC void SDLCALL Mix_HookMusicFinished(Mix_MusicFinishedCallback music_finished);
1235
1236/**
1237 * Get a pointer to the user data for the current music hook.
1238 *
1239 * This returns the `arg` pointer last passed to Mix_HookMusic(), or NULL if
1240 * that function has never been called.
1241 *
1242 * \returns pointer to the user data previously passed to Mix_HookMusic.
1243 *
1244 * \since This function is available since SDL_mixer 2.0.0.
1245 */
1246extern DECLSPEC void * SDLCALL Mix_GetMusicHookData(void);
1247
1248typedef void (SDLCALL *Mix_ChannelFinishedCallback)(int channel);
1249
1250/**
1251 * Set a callback that runs when a channel has finished playing.
1252 *
1253 * The callback may be called from the mixer's audio callback or it could be
1254 * called as a result of Mix_HaltChannel(), etc.
1255 *
1256 * The callback has a single parameter, `channel`, which says what mixer
1257 * channel has just stopped.
1258 *
1259 * Do not call SDL_LockAudio() from this callback; you will either be inside
1260 * the audio callback, or SDL_mixer will explicitly lock the audio before
1261 * calling your callback.
1262 *
1263 * A NULL pointer will disable the callback.
1264 *
1265 * \param channel_finished the callback function to become the new
1266 * notification mechanism.
1267 *
1268 * \since This function is available since SDL_mixer 2.0.0.
1269 */
1270extern DECLSPEC void SDLCALL Mix_ChannelFinished(Mix_ChannelFinishedCallback channel_finished);
1271
1272
1273#define MIX_CHANNEL_POST (-2)
1274
1275/**
1276 * This is the format of a special effect callback:
1277 *
1278 * myeffect(int chan, void *stream, int len, void *udata);
1279 *
1280 * (chan) is the channel number that your effect is affecting. (stream) is the
1281 * buffer of data to work upon. (len) is the size of (stream), and (udata) is
1282 * a user-defined bit of data, which you pass as the last arg of
1283 * Mix_RegisterEffect(), and is passed back unmolested to your callback. Your
1284 * effect changes the contents of (stream) based on whatever parameters are
1285 * significant, or just leaves it be, if you prefer. You can do whatever you
1286 * like to the buffer, though, and it will continue in its changed state down
1287 * the mixing pipeline, through any other effect functions, then finally to be
1288 * mixed with the rest of the channels and music for the final output stream.
1289 *
1290 * DO NOT EVER call SDL_LockAudio() from your callback function!
1291 */
1292typedef void (SDLCALL *Mix_EffectFunc_t)(int chan, void *stream, int len, void *udata);
1293
1294/**
1295 * This is a callback that signifies that a channel has finished all its loops
1296 * and has completed playback.
1297 *
1298 * This gets called if the buffer plays out normally, or if you call
1299 * Mix_HaltChannel(), implicitly stop a channel via Mix_AllocateChannels(), or
1300 * unregister a callback while it's still playing.
1301 *
1302 * DO NOT EVER call SDL_LockAudio() from your callback function!
1303 */
1304typedef void (SDLCALL *Mix_EffectDone_t)(int chan, void *udata);
1305
1306
1307/**
1308 * Register a special effect function.
1309 *
1310 * At mixing time, the channel data is copied into a buffer and passed through
1311 * each registered effect function. After it passes through all the functions,
1312 * it is mixed into the final output stream. The copy to buffer is performed
1313 * once, then each effect function performs on the output of the previous
1314 * effect. Understand that this extra copy to a buffer is not performed if
1315 * there are no effects registered for a given chunk, which saves CPU cycles,
1316 * and any given effect will be extra cycles, too, so it is crucial that your
1317 * code run fast. Also note that the data that your function is given is in
1318 * the format of the sound device, and not the format you gave to
1319 * Mix_OpenAudio(), although they may in reality be the same. This is an
1320 * unfortunate but necessary speed concern. Use Mix_QuerySpec() to determine
1321 * if you can handle the data before you register your effect, and take
1322 * appropriate actions.
1323 *
1324 * You may also specify a callback (Mix_EffectDone_t) that is called when the
1325 * channel finishes playing. This gives you a more fine-grained control than
1326 * Mix_ChannelFinished(), in case you need to free effect-specific resources,
1327 * etc. If you don't need this, you can specify NULL.
1328 *
1329 * You may set the callbacks before or after calling Mix_PlayChannel().
1330 *
1331 * Things like Mix_SetPanning() are just internal special effect functions, so
1332 * if you are using that, you've already incurred the overhead of a copy to a
1333 * separate buffer, and that these effects will be in the queue with any
1334 * functions you've registered. The list of registered effects for a channel
1335 * is reset when a chunk finishes playing, so you need to explicitly set them
1336 * with each call to Mix_PlayChannel*().
1337 *
1338 * You may also register a special effect function that is to be run after
1339 * final mixing occurs. The rules for these callbacks are identical to those
1340 * in Mix_RegisterEffect, but they are run after all the channels and the
1341 * music have been mixed into a single stream, whereas channel-specific
1342 * effects run on a given channel before any other mixing occurs. These global
1343 * effect callbacks are call "posteffects". Posteffects only have their
1344 * Mix_EffectDone_t function called when they are unregistered (since the main
1345 * output stream is never "done" in the same sense as a channel). You must
1346 * unregister them manually when you've had enough. Your callback will be told
1347 * that the channel being mixed is `MIX_CHANNEL_POST` if the processing is
1348 * considered a posteffect.
1349 *
1350 * After all these effects have finished processing, the callback registered
1351 * through Mix_SetPostMix() runs, and then the stream goes to the audio
1352 * device.
1353 *
1354 * DO NOT EVER call SDL_LockAudio() from your callback function! You are
1355 * already running in the audio thread and the lock is already held!
1356 *
1357 * Note that unlike most SDL and SDL_mixer functions, this function returns
1358 * zero if there's an error, not on success. We apologize for the API design
1359 * inconsistency here.
1360 *
1361 * \param chan the channel to register an effect to, or MIX_CHANNEL_POST.
1362 * \param f effect the callback to run when more of this channel is to be
1363 * mixed.
1364 * \param d effect done callback.
1365 * \param arg argument.
1366 * \returns zero if error (no such channel), nonzero if added. Error messages
1367 * can be retrieved from Mix_GetError().
1368 *
1369 * \since This function is available since SDL_mixer 2.0.0.
1370 */
1371extern DECLSPEC int SDLCALL Mix_RegisterEffect(int chan, Mix_EffectFunc_t f, Mix_EffectDone_t d, void *arg);
1372
1373
1374/**
1375 * Explicitly unregister a special effect function.
1376 *
1377 * You may not need to call this at all, unless you need to stop an effect
1378 * from processing in the middle of a chunk's playback.
1379 *
1380 * Posteffects are never implicitly unregistered as they are for channels (as
1381 * the output stream does not have an end), but they may be explicitly
1382 * unregistered through this function by specifying MIX_CHANNEL_POST for a
1383 * channel.
1384 *
1385 * Note that unlike most SDL and SDL_mixer functions, this function returns
1386 * zero if there's an error, not on success. We apologize for the API design
1387 * inconsistency here.
1388 *
1389 * \param channel the channel to unregister an effect on, or MIX_CHANNEL_POST.
1390 * \param f effect the callback stop calling in future mixing iterations.
1391 * \returns zero if error (no such channel or effect), nonzero if removed.
1392 * Error messages can be retrieved from Mix_GetError().
1393 *
1394 * \since This function is available since SDL_mixer 2.0.0.
1395 */
1396extern DECLSPEC int SDLCALL Mix_UnregisterEffect(int channel, Mix_EffectFunc_t f);
1397
1398/**
1399 * Explicitly unregister all special effect functions.
1400 *
1401 * You may not need to call this at all, unless you need to stop all effects
1402 * from processing in the middle of a chunk's playback.
1403 *
1404 * Note that this will also shut off some internal effect processing, since
1405 * Mix_SetPanning() and others may use this API under the hood. This is called
1406 * internally when a channel completes playback. Posteffects are never
1407 * implicitly unregistered as they are for channels, but they may be
1408 * explicitly unregistered through this function by specifying
1409 * MIX_CHANNEL_POST for a channel.
1410 *
1411 * Note that unlike most SDL and SDL_mixer functions, this function returns
1412 * zero if there's an error, not on success. We apologize for the API design
1413 * inconsistency here.
1414 *
1415 * \param channel the channel to unregister all effects on, or
1416 * MIX_CHANNEL_POST.
1417 * \returns zero if error (no such channel), nonzero if all effects removed.
1418 * Error messages can be retrieved from Mix_GetError().
1419 *
1420 * \since This function is available since SDL_mixer 2.0.0.
1421 */
1422extern DECLSPEC int SDLCALL Mix_UnregisterAllEffects(int channel);
1423
1424
1425#define MIX_EFFECTSMAXSPEED "MIX_EFFECTSMAXSPEED"
1426
1427/*
1428 * These are the internally-defined mixing effects. They use the same API that
1429 * effects defined in the application use, but are provided here as a
1430 * convenience. Some effects can reduce their quality or use more memory in
1431 * the name of speed; to enable this, make sure the environment variable
1432 * MIX_EFFECTSMAXSPEED (see above) is defined before you call
1433 * Mix_OpenAudio().
1434 */
1435
1436
1437/**
1438 * Set the panning of a channel.
1439 *
1440 * The left and right channels are specified as integers between 0 and 255,
1441 * quietest to loudest, respectively.
1442 *
1443 * Technically, this is just individual volume control for a sample with two
1444 * (stereo) channels, so it can be used for more than just panning. If you
1445 * want real panning, call it like this:
1446 *
1447 * ```c
1448 * Mix_SetPanning(channel, left, 255 - left);
1449 * ```
1450 *
1451 * Setting `channel` to MIX_CHANNEL_POST registers this as a posteffect, and
1452 * the panning will be done to the final mixed stream before passing it on to
1453 * the audio device.
1454 *
1455 * This uses the Mix_RegisterEffect() API internally, and returns without
1456 * registering the effect function if the audio device is not configured for
1457 * stereo output. Setting both `left` and `right` to 255 causes this effect to
1458 * be unregistered, since that is the data's normal state.
1459 *
1460 * Note that an audio device in mono mode is a no-op, but this call will
1461 * return successful in that case. Error messages can be retrieved from
1462 * Mix_GetError().
1463 *
1464 * Note that unlike most SDL and SDL_mixer functions, this function returns
1465 * zero if there's an error, not on success. We apologize for the API design
1466 * inconsistency here.
1467 *
1468 * \param channel The mixer channel to pan or MIX_CHANNEL_POST.
1469 * \param left Volume of stereo left channel, 0 is silence, 255 is full
1470 * volume.
1471 * \param right Volume of stereo right channel, 0 is silence, 255 is full
1472 * volume.
1473 * \returns zero if error (no such channel or Mix_RegisterEffect() fails),
1474 * nonzero if panning effect enabled.
1475 *
1476 * \since This function is available since SDL_mixer 2.0.0.
1477 *
1478 * \sa Mix_SetPosition
1479 * \sa Mix_SetDistance
1480 */
1481extern DECLSPEC int SDLCALL Mix_SetPanning(int channel, Uint8 left, Uint8 right);
1482
1483
1484/**
1485 * Set the position of a channel.
1486 *
1487 * `angle` is an integer from 0 to 360, that specifies the location of the
1488 * sound in relation to the listener. `angle` will be reduced as necessary
1489 * (540 becomes 180 degrees, -100 becomes 260). Angle 0 is due north, and
1490 * rotates clockwise as the value increases. For efficiency, the precision of
1491 * this effect may be limited (angles 1 through 7 might all produce the same
1492 * effect, 8 through 15 are equal, etc). `distance` is an integer between 0
1493 * and 255 that specifies the space between the sound and the listener. The
1494 * larger the number, the further away the sound is. Using 255 does not
1495 * guarantee that the channel will be removed from the mixing process or be
1496 * completely silent. For efficiency, the precision of this effect may be
1497 * limited (distance 0 through 5 might all produce the same effect, 6 through
1498 * 10 are equal, etc). Setting `angle` and `distance` to 0 unregisters this
1499 * effect, since the data would be unchanged.
1500 *
1501 * If you need more precise positional audio, consider using OpenAL for
1502 * spatialized effects instead of SDL_mixer. This is only meant to be a basic
1503 * effect for simple "3D" games.
1504 *
1505 * If the audio device is configured for mono output, then you won't get any
1506 * effectiveness from the angle; however, distance attenuation on the channel
1507 * will still occur. While this effect will function with stereo voices, it
1508 * makes more sense to use voices with only one channel of sound, so when they
1509 * are mixed through this effect, the positioning will sound correct. You can
1510 * convert them to mono through SDL before giving them to the mixer in the
1511 * first place if you like.
1512 *
1513 * Setting the channel to MIX_CHANNEL_POST registers this as a posteffect, and
1514 * the positioning will be done to the final mixed stream before passing it on
1515 * to the audio device.
1516 *
1517 * This is a convenience wrapper over Mix_SetDistance() and Mix_SetPanning().
1518 *
1519 * Note that unlike most SDL and SDL_mixer functions, this function returns
1520 * zero if there's an error, not on success. We apologize for the API design
1521 * inconsistency here.
1522 *
1523 * \param channel The mixer channel to position, or MIX_CHANNEL_POST.
1524 * \param angle angle, in degrees. North is 0, and goes clockwise.
1525 * \param distance distance; 0 is the listener, 255 is maxiumum distance away.
1526 * \returns zero if error (no such channel or Mix_RegisterEffect() fails),
1527 * nonzero if position effect is enabled. Error messages can be
1528 * retrieved from Mix_GetError().
1529 *
1530 * \since This function is available since SDL_mixer 2.0.0.
1531 */
1532extern DECLSPEC int SDLCALL Mix_SetPosition(int channel, Sint16 angle, Uint8 distance);
1533
1534
1535/**
1536 * Set the "distance" of a channel.
1537 *
1538 * `distance` is an integer from 0 to 255 that specifies the location of the
1539 * sound in relation to the listener. Distance 0 is overlapping the listener,
1540 * and 255 is as far away as possible. A distance of 255 does not guarantee
1541 * silence; in such a case, you might want to try changing the chunk's volume,
1542 * or just cull the sample from the mixing process with Mix_HaltChannel(). For
1543 * efficiency, the precision of this effect may be limited (distances 1
1544 * through 7 might all produce the same effect, 8 through 15 are equal, etc).
1545 * (distance) is an integer between 0 and 255 that specifies the space between
1546 * the sound and the listener. The larger the number, the further away the
1547 * sound is. Setting the distance to 0 unregisters this effect, since the data
1548 * would be unchanged. If you need more precise positional audio, consider
1549 * using OpenAL for spatialized effects instead of SDL_mixer. This is only
1550 * meant to be a basic effect for simple "3D" games.
1551 *
1552 * Setting the channel to MIX_CHANNEL_POST registers this as a posteffect, and
1553 * the distance attenuation will be done to the final mixed stream before
1554 * passing it on to the audio device.
1555 *
1556 * This uses the Mix_RegisterEffect() API internally.
1557 *
1558 * Note that unlike most SDL and SDL_mixer functions, this function returns
1559 * zero if there's an error, not on success. We apologize for the API design
1560 * inconsistency here.
1561 *
1562 * \param channel The mixer channel to attenuate, or MIX_CHANNEL_POST.
1563 * \param distance distance; 0 is the listener, 255 is maxiumum distance away.
1564 * \returns zero if error (no such channel or Mix_RegisterEffect() fails),
1565 * nonzero if position effect is enabled. Error messages can be
1566 * retrieved from Mix_GetError().
1567 *
1568 * \since This function is available since SDL_mixer 2.0.0.
1569 */
1570extern DECLSPEC int SDLCALL Mix_SetDistance(int channel, Uint8 distance);
1571
1572
1573/**
1574 * Cause a channel to reverse its stereo.
1575 *
1576 * This is handy if the user has his speakers hooked up backwards, or you
1577 * would like to have a trippy sound effect.
1578 *
1579 * Calling this function with `flip` set to non-zero reverses the chunks's
1580 * usual channels. If `flip` is zero, the effect is unregistered.
1581 *
1582 * This uses the Mix_RegisterEffect() API internally, and thus is probably
1583 * more CPU intensive than having the user just plug in his speakers
1584 * correctly. Mix_SetReverseStereo() returns without registering the effect
1585 * function if the audio device is not configured for stereo output.
1586 *
1587 * If you specify MIX_CHANNEL_POST for `channel`, then this effect is used on
1588 * the final mixed stream before sending it on to the audio device (a
1589 * posteffect).
1590 *
1591 * Note that unlike most SDL and SDL_mixer functions, this function returns
1592 * zero if there's an error, not on success. We apologize for the API design
1593 * inconsistency here.
1594 *
1595 * \param channel The mixer channel to reverse, or MIX_CHANNEL_POST.
1596 * \param flip non-zero to reverse stereo, zero to disable this effect.
1597 * \returns zero if error (no such channel or Mix_RegisterEffect() fails),
1598 * nonzero if reversing effect is enabled. Note that an audio device
1599 * in mono mode is a no-op, but this call will return successful in
1600 * that case. Error messages can be retrieved from Mix_GetError().
1601 *
1602 * \since This function is available since SDL_mixer 2.0.0.
1603 */
1604extern DECLSPEC int SDLCALL Mix_SetReverseStereo(int channel, int flip);
1605
1606/* end of effects API. */
1607
1608
1609
1610/**
1611 * Reserve the first channels for the application.
1612 *
1613 * While SDL_mixer will use up to the number of channels allocated by
1614 * Mix_AllocateChannels(), this sets channels aside that will not be available
1615 * when calling Mix_PlayChannel with a channel of -1 (play on the first unused
1616 * channel). In this case, SDL_mixer will treat reserved channels as "used"
1617 * whether anything is playing on them at the moment or not.
1618 *
1619 * This is useful if you've budgeted some channels for dedicated audio and the
1620 * rest are just used as they are available.
1621 *
1622 * Calling this function will set channels 0 to `n - 1` to be reserved. This
1623 * will not change channel allocations. The number of reserved channels will
1624 * be clamped to the current number allocated.
1625 *
1626 * By default, no channels are reserved.
1627 *
1628 * \param num number of channels to reserve, starting at index zero.
1629 * \returns the number of reserved channels.
1630 *
1631 * \since This function is available since SDL_mixer 2.0.0.
1632 */
1633extern DECLSPEC int SDLCALL Mix_ReserveChannels(int num);
1634
1635
1636/* Channel grouping functions */
1637
1638/**
1639 * Assign a tag to a channel.
1640 *
1641 * A tag is an arbitary number that can be assigned to several mixer channels,
1642 * to form groups of channels.
1643 *
1644 * If 'tag' is -1, the tag is removed (actually -1 is the tag used to
1645 * represent the group of all the channels).
1646 *
1647 * This function replaces the requested channel's current tag; you may only
1648 * have one tag per channel.
1649 *
1650 * You may not specify MAX_CHANNEL_POST for a channel.
1651 *
1652 * \param which the channel to set the tag on.
1653 * \param tag an arbitrary value to assign a channel.
1654 * \returns non-zero on success, zero on error (no such channel).
1655 *
1656 * \since This function is available since SDL_mixer 2.0.0.
1657 */
1658extern DECLSPEC int SDLCALL Mix_GroupChannel(int which, int tag);
1659
1660/**
1661 * Assign several consecutive channels to the same tag.
1662 *
1663 * A tag is an arbitary number that can be assigned to several mixer channels,
1664 * to form groups of channels.
1665 *
1666 * If 'tag' is -1, the tag is removed (actually -1 is the tag used to
1667 * represent the group of all the channels).
1668 *
1669 * This function replaces the requested channels' current tags; you may only
1670 * have one tag per channel.
1671 *
1672 * You may not specify MAX_CHANNEL_POST for a channel.
1673 *
1674 * Note that this returns success and failure in the _opposite_ way from
1675 * Mix_GroupChannel(). We regret the API design mistake.
1676 *
1677 * \param from the first channel to set the tag on.
1678 * \param to the last channel to set the tag on, inclusive.
1679 * \param tag an arbitrary value to assign a channel.
1680 * \returns 0 if successful, negative on error.
1681 *
1682 * \since This function is available since SDL_mixer 2.0.0.
1683 */
1684extern DECLSPEC int SDLCALL Mix_GroupChannels(int from, int to, int tag);
1685
1686/**
1687 * Finds the first available channel in a group of channels.
1688 *
1689 * A tag is an arbitary number that can be assigned to several mixer channels,
1690 * to form groups of channels.
1691 *
1692 * This function searches all channels with a specified tag, and returns the
1693 * channel number of the first one it finds that is currently unused.
1694 *
1695 * If no channels with the specified tag are unused, this function returns -1.
1696 *
1697 * \param tag an arbitrary value, assigned to channels, to search for.
1698 * \returns first available channel, or -1 if none are available.
1699 *
1700 * \since This function is available since SDL_mixer 2.0.0.
1701 */
1702extern DECLSPEC int SDLCALL Mix_GroupAvailable(int tag);
1703
1704/**
1705 * Returns the number of channels in a group.
1706 *
1707 * If tag is -1, this will return the total number of channels allocated,
1708 * regardless of what their tag might be.
1709 *
1710 * \param tag an arbitrary value, assigned to channels, to search for.
1711 * \returns the number of channels assigned the specified tag.
1712 *
1713 * \since This function is available since SDL_mixer 2.0.0.
1714 */
1715extern DECLSPEC int SDLCALL Mix_GroupCount(int tag);
1716
1717/**
1718 * Find the "oldest" sample playing in a group of channels.
1719 *
1720 * Specifically, this function returns the channel number that is assigned the
1721 * specified tag, is currently playing, and has the lowest start time, based
1722 * on the value of SDL_GetTicks() when the channel started playing.
1723 *
1724 * If no channel with this tag is currently playing, this function returns -1.
1725 *
1726 * \param tag an arbitrary value, assigned to channels, to search through.
1727 * \returns the "oldest" sample playing in a group of channels.
1728 *
1729 * \since This function is available since SDL_mixer 2.0.0.
1730 *
1731 * \sa Mix_GroupNewer
1732 */
1733extern DECLSPEC int SDLCALL Mix_GroupOldest(int tag);
1734
1735/**
1736 * Find the "most recent" sample playing in a group of channels.
1737 *
1738 * Specifically, this function returns the channel number that is assigned the
1739 * specified tag, is currently playing, and has the highest start time, based
1740 * on the value of SDL_GetTicks() when the channel started playing.
1741 *
1742 * If no channel with this tag is currently playing, this function returns -1.
1743 *
1744 * \param tag an arbitrary value, assigned to channels, to search through.
1745 * \returns the "most recent" sample playing in a group of channels.
1746 *
1747 * \since This function is available since SDL_mixer 2.0.0.
1748 *
1749 * \sa Mix_GroupOldest
1750 */
1751extern DECLSPEC int SDLCALL Mix_GroupNewer(int tag);
1752
1753/**
1754 * Play an audio chunk on a specific channel.
1755 *
1756 * If the specified channel is -1, play on the first free channel (and return
1757 * -1 without playing anything new if no free channel was available).
1758 *
1759 * If a specific channel was requested, and there is a chunk already playing
1760 * there, that chunk will be halted and the new chunk will take its place.
1761 *
1762 * If `loops` is greater than zero, loop the sound that many times. If `loops`
1763 * is -1, loop "infinitely" (~65000 times).
1764 *
1765 * Note that before SDL_mixer 2.6.0, this function was a macro that called
1766 * Mix_PlayChannelTimed() with a fourth parameter ("ticks") of -1. This
1767 * function still does the same thing, but promotes it to a proper API
1768 * function. Older binaries linked against a newer SDL_mixer will still call
1769 * Mix_PlayChannelTimed directly, as they are using the macro, which was
1770 * available since the dawn of time.
1771 *
1772 * \param channel the channel on which to play the new chunk.
1773 * \param chunk the new chunk to play.
1774 * \param loops the number of times the chunk should loop, -1 to loop (not
1775 * actually) infinitely.
1776 * \returns which channel was used to play the sound, or -1 if sound could not
1777 * be played.
1778 *
1779 * \since This function is available since SDL_mixer 2.6.0 (and as a macro
1780 * since 2.0.0).
1781 */
1782extern DECLSPEC int SDLCALL Mix_PlayChannel(int channel, Mix_Chunk *chunk, int loops);
1783
1784/**
1785 * Play an audio chunk on a specific channel for a maximum time.
1786 *
1787 * If the specified channel is -1, play on the first free channel (and return
1788 * -1 without playing anything new if no free channel was available).
1789 *
1790 * If a specific channel was requested, and there is a chunk already playing
1791 * there, that chunk will be halted and the new chunk will take its place.
1792 *
1793 * If `loops` is greater than zero, loop the sound that many times. If `loops`
1794 * is -1, loop "infinitely" (~65000 times).
1795 *
1796 * `ticks` specifies the maximum number of milliseconds to play this chunk
1797 * before halting it. If you want the chunk to play until all data has been
1798 * mixed, specify -1.
1799 *
1800 * Note that this function does not block for the number of ticks requested;
1801 * it just schedules the chunk to play and notes the maximum for the mixer to
1802 * manage later, and returns immediately.
1803 *
1804 * \param channel the channel on which to play the new chunk.
1805 * \param chunk the new chunk to play.
1806 * \param loops the number of times the chunk should loop, -1 to loop (not
1807 * actually) infinitely.
1808 * \param ticks the maximum number of milliseconds of this chunk to mix for
1809 * playback.
1810 * \returns which channel was used to play the sound, or -1 if sound could not
1811 * be played.
1812 *
1813 * \since This function is available since SDL_mixer 2.0.0.
1814 */
1815extern DECLSPEC int SDLCALL Mix_PlayChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ticks);
1816
1817/**
1818 * Play a new music object.
1819 *
1820 * This will schedule the music object to begin mixing for playback.
1821 *
1822 * There is only ever one music object playing at a time; if this is called
1823 * when another music object is playing, the currently-playing music is halted
1824 * and the new music will replace it.
1825 *
1826 * Please note that if the currently-playing music is in the process of fading
1827 * out (via Mix_FadeOutMusic()), this function will *block* until the fade
1828 * completes. If you need to avoid this, be sure to call Mix_HaltMusic()
1829 * before starting new music.
1830 *
1831 * \param music the new music object to schedule for mixing.
1832 * \param loops the number of loops to play the music for (0 means "play once
1833 * and stop").
1834 * \returns zero on success, -1 on error.
1835 *
1836 * \since This function is available since SDL_mixer 2.0.0.
1837 */
1838extern DECLSPEC int SDLCALL Mix_PlayMusic(Mix_Music *music, int loops);
1839
1840/**
1841 * Play a new music object, fading in the audio.
1842 *
1843 * This will start the new music playing, much like Mix_PlayMusic() will, but
1844 * will start the music playing at silence and fade in to its normal volume
1845 * over the specified number of milliseconds.
1846 *
1847 * If there is already music playing, that music will be halted and the new
1848 * music object will take its place.
1849 *
1850 * If `loops` is greater than zero, loop the music that many times. If `loops`
1851 * is -1, loop "infinitely" (~65000 times).
1852 *
1853 * Fading music will change it's volume progressively, as if Mix_VolumeMusic()
1854 * was called on it (which is to say: you probably shouldn't call
1855 * Mix_VolumeMusic() on fading music).
1856 *
1857 * \param music the new music object to play.
1858 * \param loops the number of times the chunk should loop, -1 to loop (not
1859 * actually) infinitely.
1860 * \param ms the number of milliseconds to spend fading in.
1861 * \returns zero on success, -1 on error.
1862 *
1863 * \since This function is available since SDL_mixer 2.0.0.
1864 */
1865extern DECLSPEC int SDLCALL Mix_FadeInMusic(Mix_Music *music, int loops, int ms);
1866
1867/**
1868 * Play a new music object, fading in the audio, from a starting position.
1869 *
1870 * This will start the new music playing, much like Mix_PlayMusic() will, but
1871 * will start the music playing at silence and fade in to its normal volume
1872 * over the specified number of milliseconds.
1873 *
1874 * If there is already music playing, that music will be halted and the new
1875 * music object will take its place.
1876 *
1877 * If `loops` is greater than zero, loop the music that many times. If `loops`
1878 * is -1, loop "infinitely" (~65000 times).
1879 *
1880 * Fading music will change it's volume progressively, as if Mix_VolumeMusic()
1881 * was called on it (which is to say: you probably shouldn't call
1882 * Mix_VolumeMusic() on fading music).
1883 *
1884 * This function allows the caller to start the music playback past the
1885 * beginning of its audio data. You may specify a start position, in seconds,
1886 * and the playback and fade-in will start there instead of with the first
1887 * samples of the music.
1888 *
1889 * An app can specify a `position` of 0.0 to start at the beginning of the
1890 * music (or just call Mix_FadeInMusic() instead).
1891 *
1892 * To convert from milliseconds, divide by 1000.0.
1893 *
1894 * \param music the new music object to play.
1895 * \param loops the number of times the chunk should loop, -1 to loop (not
1896 * actually) infinitely.
1897 * \param ms the number of milliseconds to spend fading in.
1898 * \param position the start position within the music, in seconds, where
1899 * playback should start.
1900 * \returns zero on success, -1 on error.
1901 *
1902 * \since This function is available since SDL_mixer 2.0.0.
1903 */
1904extern DECLSPEC int SDLCALL Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position);
1905
1906/**
1907 * Play an audio chunk on a specific channel, fading in the audio.
1908 *
1909 * This will start the new sound playing, much like Mix_PlayChannel() will,
1910 * but will start the sound playing at silence and fade in to its normal
1911 * volume over the specified number of milliseconds.
1912 *
1913 * If the specified channel is -1, play on the first free channel (and return
1914 * -1 without playing anything new if no free channel was available).
1915 *
1916 * If a specific channel was requested, and there is a chunk already playing
1917 * there, that chunk will be halted and the new chunk will take its place.
1918 *
1919 * If `loops` is greater than zero, loop the sound that many times. If `loops`
1920 * is -1, loop "infinitely" (~65000 times).
1921 *
1922 * A fading channel will change it's volume progressively, as if Mix_Volume()
1923 * was called on it (which is to say: you probably shouldn't call Mix_Volume()
1924 * on a fading channel).
1925 *
1926 * Note that before SDL_mixer 2.6.0, this function was a macro that called
1927 * Mix_FadeInChannelTimed() with a fourth parameter ("ticks") of -1. This
1928 * function still does the same thing, but promotes it to a proper API
1929 * function. Older binaries linked against a newer SDL_mixer will still call
1930 * Mix_FadeInChannelTimed directly, as they are using the macro, which was
1931 * available since the dawn of time.
1932 *
1933 * \param channel the channel on which to play the new chunk, or -1 to find
1934 * any available.
1935 * \param chunk the new chunk to play.
1936 * \param loops the number of times the chunk should loop, -1 to loop (not
1937 * actually) infinitely.
1938 * \param ms the number of milliseconds to spend fading in.
1939 * \returns which channel was used to play the sound, or -1 if sound could not
1940 * be played.
1941 *
1942 * \since This function is available since SDL_mixer 2.6.0 (and as a macro
1943 * since 2.0.0).
1944 */
1945extern DECLSPEC int SDLCALL Mix_FadeInChannel(int channel, Mix_Chunk *chunk, int loops, int ms);
1946
1947/**
1948 * Play an audio chunk on a specific channel, fading in the audio, for a
1949 * maximum time.
1950 *
1951 * This will start the new sound playing, much like Mix_PlayChannel() will,
1952 * but will start the sound playing at silence and fade in to its normal
1953 * volume over the specified number of milliseconds.
1954 *
1955 * If the specified channel is -1, play on the first free channel (and return
1956 * -1 without playing anything new if no free channel was available).
1957 *
1958 * If a specific channel was requested, and there is a chunk already playing
1959 * there, that chunk will be halted and the new chunk will take its place.
1960 *
1961 * If `loops` is greater than zero, loop the sound that many times. If `loops`
1962 * is -1, loop "infinitely" (~65000 times).
1963 *
1964 * `ticks` specifies the maximum number of milliseconds to play this chunk
1965 * before halting it. If you want the chunk to play until all data has been
1966 * mixed, specify -1.
1967 *
1968 * Note that this function does not block for the number of ticks requested;
1969 * it just schedules the chunk to play and notes the maximum for the mixer to
1970 * manage later, and returns immediately.
1971 *
1972 * A fading channel will change it's volume progressively, as if Mix_Volume()
1973 * was called on it (which is to say: you probably shouldn't call Mix_Volume()
1974 * on a fading channel).
1975 *
1976 * \param channel the channel on which to play the new chunk, or -1 to find
1977 * any available.
1978 * \param chunk the new chunk to play.
1979 * \param loops the number of times the chunk should loop, -1 to loop (not
1980 * actually) infinitely.
1981 * \param ms the number of milliseconds to spend fading in.
1982 * \param ticks the maximum number of milliseconds of this chunk to mix for
1983 * playback.
1984 * \returns which channel was used to play the sound, or -1 if sound could not
1985 * be played.
1986 *
1987 * \since This function is available since SDL_mixer 2.0.0.
1988 */
1989extern DECLSPEC int SDLCALL Mix_FadeInChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ms, int ticks);
1990
1991/**
1992 * Set the volume for a specific channel.
1993 *
1994 * The volume must be between 0 (silence) and MIX_MAX_VOLUME (full volume).
1995 * Note that MIX_MAX_VOLUME is 128. Values greater than MIX_MAX_VOLUME are
1996 * clamped to MIX_MAX_VOLUME.
1997 *
1998 * Specifying a negative volume will not change the current volume; as such,
1999 * this can be used to query the current volume without making changes, as
2000 * this function returns the previous (in this case, still-current) value.
2001 *
2002 * If the specified channel is -1, this function sets the volume for all
2003 * channels, and returns _the average_ of all channels' volumes prior to this
2004 * call.
2005 *
2006 * The default volume for a channel is MIX_MAX_VOLUME (no attenuation).
2007 *
2008 * \param channel the channel on set/query the volume on, or -1 for all
2009 * channels.
2010 * \param volume the new volume, between 0 and MIX_MAX_VOLUME, or -1 to query.
2011 * \returns the previous volume. If the specified volume is -1, this returns
2012 * the current volume. If `channel` is -1, this returns the average
2013 * of all channels.
2014 *
2015 * \since This function is available since SDL_mixer 2.0.0.
2016 */
2017extern DECLSPEC int SDLCALL Mix_Volume(int channel, int volume);
2018
2019/**
2020 * Set the volume for a specific chunk.
2021 *
2022 * In addition to channels having a volume setting, individual chunks also
2023 * maintain a separate volume. Both values are considered when mixing, so both
2024 * affect the final attenuation of the sound. This lets an app adjust the
2025 * volume for all instances of a sound in addition to specific instances of
2026 * that sound.
2027 *
2028 * The volume must be between 0 (silence) and MIX_MAX_VOLUME (full volume).
2029 * Note that MIX_MAX_VOLUME is 128. Values greater than MIX_MAX_VOLUME are
2030 * clamped to MIX_MAX_VOLUME.
2031 *
2032 * Specifying a negative volume will not change the current volume; as such,
2033 * this can be used to query the current volume without making changes, as
2034 * this function returns the previous (in this case, still-current) value.
2035 *
2036 * The default volume for a chunk is MIX_MAX_VOLUME (no attenuation).
2037 *
2038 * \param chunk the chunk whose volume to adjust.
2039 * \param volume the new volume, between 0 and MIX_MAX_VOLUME, or -1 to query.
2040 * \returns the previous volume. If the specified volume is -1, this returns
2041 * the current volume. If `chunk` is NULL, this returns -1.
2042 *
2043 * \since This function is available since SDL_mixer 2.0.0.
2044 */
2045extern DECLSPEC int SDLCALL Mix_VolumeChunk(Mix_Chunk *chunk, int volume);
2046
2047/**
2048 * Set the volume for the music channel.
2049 *
2050 * The volume must be between 0 (silence) and MIX_MAX_VOLUME (full volume).
2051 * Note that MIX_MAX_VOLUME is 128. Values greater than MIX_MAX_VOLUME are
2052 * clamped to MIX_MAX_VOLUME.
2053 *
2054 * Specifying a negative volume will not change the current volume; as such,
2055 * this can be used to query the current volume without making changes, as
2056 * this function returns the previous (in this case, still-current) value.
2057 *
2058 * The default volume for music is MIX_MAX_VOLUME (no attenuation).
2059 *
2060 * \param volume the new volume, between 0 and MIX_MAX_VOLUME, or -1 to query.
2061 * \returns the previous volume. If the specified volume is -1, this returns
2062 * the current volume.
2063 *
2064 * \since This function is available since SDL_mixer 2.0.0.
2065 */
2066extern DECLSPEC int SDLCALL Mix_VolumeMusic(int volume);
2067
2068/**
2069 * Query the current volume value for a music object.
2070 *
2071 * \param music the music object to query.
2072 * \returns the music's current volume, between 0 and MIX_MAX_VOLUME (128).
2073 *
2074 * \since This function is available since SDL_mixer 2.6.0.
2075 */
2076extern DECLSPEC int SDLCALL Mix_GetMusicVolume(Mix_Music *music);
2077
2078/**
2079 * Set the master volume for all channels.
2080 *
2081 * SDL_mixer keeps a per-channel volume, a per-chunk volume, and a master
2082 * volume, and considers all three when mixing audio. This function sets the
2083 * master volume, which is applied to all playing channels when mixing.
2084 *
2085 * The volume must be between 0 (silence) and MIX_MAX_VOLUME (full volume).
2086 * Note that MIX_MAX_VOLUME is 128. Values greater than MIX_MAX_VOLUME are
2087 * clamped to MIX_MAX_VOLUME.
2088 *
2089 * Specifying a negative volume will not change the current volume; as such,
2090 * this can be used to query the current volume without making changes, as
2091 * this function returns the previous (in this case, still-current) value.
2092 *
2093 * Note that the master volume does not affect any playing music; it is only
2094 * applied when mixing chunks. Use Mix_VolumeMusic() for that.\
2095 *
2096 * \param volume the new volume, between 0 and MIX_MAX_VOLUME, or -1 to query.
2097 * \returns the previous volume. If the specified volume is -1, this returns
2098 * the current volume.
2099 *
2100 * \since This function is available since SDL_mixer 2.6.0.
2101 */
2102extern DECLSPEC int SDLCALL Mix_MasterVolume(int volume);
2103
2104/**
2105 * Halt playing of a particular channel.
2106 *
2107 * This will stop further playback on that channel until a new chunk is
2108 * started there.
2109 *
2110 * Specifying a channel of -1 will halt _all_ channels, except for any playing
2111 * music.
2112 *
2113 * Any halted channels will have any currently-registered effects
2114 * deregistered, and will call any callback specified by Mix_ChannelFinished()
2115 * before this function returns.
2116 *
2117 * You may not specify MAX_CHANNEL_POST for a channel.
2118 *
2119 * \param channel channel to halt, or -1 to halt all channels.
2120 * \returns 0 on success, or -1 on error.
2121 *
2122 * \since This function is available since SDL_mixer 2.0.0.
2123 */
2124extern DECLSPEC int SDLCALL Mix_HaltChannel(int channel);
2125
2126/**
2127 * Halt playing of a group of channels by arbitrary tag.
2128 *
2129 * This will stop further playback on all channels with a specific tag, until
2130 * a new chunk is started there.
2131 *
2132 * A tag is an arbitrary number that can be assigned to several mixer
2133 * channels, to form groups of channels.
2134 *
2135 * The default tag for a channel is -1.
2136 *
2137 * Any halted channels will have any currently-registered effects
2138 * deregistered, and will call any callback specified by Mix_ChannelFinished()
2139 * before this function returns.
2140 *
2141 * \param tag an arbitrary value, assigned to channels, to search for.
2142 * \returns zero, whether any channels were halted or not.
2143 *
2144 * \since This function is available since SDL_mixer 2.0.0.
2145 */
2146extern DECLSPEC int SDLCALL Mix_HaltGroup(int tag);
2147
2148/**
2149 * Halt playing of the music stream.
2150 *
2151 * This will stop further playback of music until a new music object is
2152 * started there.
2153 *
2154 * Any halted music will call any callback specified by
2155 * Mix_HookMusicFinished() before this function returns.
2156 *
2157 * \returns zero, regardless of whether any music was halted.
2158 *
2159 * \since This function is available since SDL_mixer 2.0.0.
2160 */
2161extern DECLSPEC int SDLCALL Mix_HaltMusic(void);
2162
2163/**
2164 * Change the expiration delay for a particular channel.
2165 *
2166 * The channel will halt after the 'ticks' milliseconds have elapsed, or
2167 * remove the expiration if 'ticks' is -1.
2168 *
2169 * This overrides the value passed to the fourth parameter of
2170 * Mix_PlayChannelTimed().
2171 *
2172 * Specifying a channel of -1 will set an expiration for _all_ channels.
2173 *
2174 * Any halted channels will have any currently-registered effects
2175 * deregistered, and will call any callback specified by Mix_ChannelFinished()
2176 * once the halt occurs.
2177 *
2178 * Note that this function does not block for the number of ticks requested;
2179 * it just schedules the chunk to expire and notes the time for the mixer to
2180 * manage later, and returns immediately.
2181 *
2182 * \param channel the channel to change the expiration time on.
2183 * \param ticks number of milliseconds from now to let channel play before
2184 * halting, -1 to not halt.
2185 * \returns the number of channels that changed expirations.
2186 *
2187 * \since This function is available since SDL_mixer 2.0.0.
2188 */
2189extern DECLSPEC int SDLCALL Mix_ExpireChannel(int channel, int ticks);
2190
2191/**
2192 * Halt a channel after fading it out for a specified time.
2193 *
2194 * This will begin a channel fading from its current volume to silence over
2195 * `ms` milliseconds. After that time, the channel is halted.
2196 *
2197 * Any halted channels will have any currently-registered effects
2198 * deregistered, and will call any callback specified by Mix_ChannelFinished()
2199 * once the halt occurs.
2200 *
2201 * A fading channel will change it's volume progressively, as if Mix_Volume()
2202 * was called on it (which is to say: you probably shouldn't call Mix_Volume()
2203 * on a fading channel).
2204 *
2205 * Note that this function does not block for the number of milliseconds
2206 * requested; it just schedules the chunk to fade and notes the time for the
2207 * mixer to manage later, and returns immediately.
2208 *
2209 * \param which the channel to fade out.
2210 * \param ms number of milliseconds to fade before halting the channel.
2211 * \returns the number of channels scheduled to fade.
2212 *
2213 * \since This function is available since SDL_mixer 2.0.0.
2214 */
2215extern DECLSPEC int SDLCALL Mix_FadeOutChannel(int which, int ms);
2216
2217/**
2218 * Halt a playing group of channels by arbitrary tag, after fading them out
2219 * for a specified time.
2220 *
2221 * This will begin fading a group of channels with a specific tag from their
2222 * current volumes to silence over `ms` milliseconds. After that time, those
2223 * channels are halted.
2224 *
2225 * A tag is an arbitrary number that can be assigned to several mixer
2226 * channels, to form groups of channels.
2227 *
2228 * The default tag for a channel is -1.
2229 *
2230 * Any halted channels will have any currently-registered effects
2231 * deregistered, and will call any callback specified by Mix_ChannelFinished()
2232 * once the halt occurs.
2233 *
2234 * A fading channel will change it's volume progressively, as if Mix_Volume()
2235 * was called on it (which is to say: you probably shouldn't call Mix_Volume()
2236 * on a fading channel).
2237 *
2238 * Note that this function does not block for the number of milliseconds
2239 * requested; it just schedules the group to fade and notes the time for the
2240 * mixer to manage later, and returns immediately.
2241 *
2242 * \param tag an arbitrary value, assigned to channels, to search for.
2243 * \param ms number of milliseconds to fade before halting the group.
2244 * \returns the number of channels that were scheduled for fading.
2245 *
2246 * \since This function is available since SDL_mixer 2.0.0.
2247 */
2248extern DECLSPEC int SDLCALL Mix_FadeOutGroup(int tag, int ms);
2249
2250/**
2251 * Halt the music stream after fading it out for a specified time.
2252 *
2253 * This will begin the music fading from its current volume to silence over
2254 * `ms` milliseconds. After that time, the music is halted.
2255 *
2256 * Any halted music will call any callback specified by
2257 * Mix_HookMusicFinished() once the halt occurs.
2258 *
2259 * Fading music will change it's volume progressively, as if Mix_VolumeMusic()
2260 * was called on it (which is to say: you probably shouldn't call
2261 * Mix_VolumeMusic() on a fading channel).
2262 *
2263 * Note that this function does not block for the number of milliseconds
2264 * requested; it just schedules the music to fade and notes the time for the
2265 * mixer to manage later, and returns immediately.
2266 *
2267 * \param ms number of milliseconds to fade before halting the channel.
2268 * \returns non-zero if music was scheduled to fade, zero otherwise. If no
2269 * music is currently playing, this returns zero.
2270 *
2271 * \since This function is available since SDL_mixer 2.0.0.
2272 */
2273extern DECLSPEC int SDLCALL Mix_FadeOutMusic(int ms);
2274
2275/**
2276 * Query the fading status of the music stream.
2277 *
2278 * This reports one of three values:
2279 *
2280 * - `MIX_NO_FADING`
2281 * - `MIX_FADING_OUT`
2282 * - `MIX_FADING_IN`
2283 *
2284 * If music is not currently playing, this returns `MIX_NO_FADING`.
2285 *
2286 * \returns the current fading status of the music stream.
2287 *
2288 * \since This function is available since SDL_mixer 2.0.0.
2289 */
2290extern DECLSPEC Mix_Fading SDLCALL Mix_FadingMusic(void);
2291
2292/**
2293 * Query the fading status of a channel.
2294 *
2295 * This reports one of three values:
2296 *
2297 * - `MIX_NO_FADING`
2298 * - `MIX_FADING_OUT`
2299 * - `MIX_FADING_IN`
2300 *
2301 * If nothing is currently playing on the channel, or an invalid channel is
2302 * specified, this returns `MIX_NO_FADING`.
2303 *
2304 * You may not specify MAX_CHANNEL_POST for a channel.
2305 *
2306 * You may not specify -1 for all channels; only individual channels may be
2307 * queried.
2308 *
2309 * \param which the channel to query.
2310 * \returns the current fading status of the channel.
2311 *
2312 * \since This function is available since SDL_mixer 2.0.0.
2313 */
2314extern DECLSPEC Mix_Fading SDLCALL Mix_FadingChannel(int which);
2315
2316/**
2317 * Pause a particular channel.
2318 *
2319 * Pausing a channel will prevent further playback of the assigned chunk but
2320 * will maintain the chunk's current mixing position. When resumed, this
2321 * channel will continue to mix the chunk where it left off.
2322 *
2323 * A paused channel can be resumed by calling Mix_Resume().
2324 *
2325 * A paused channel with an expiration will not expire while paused (the
2326 * expiration countdown will be adjusted once resumed).
2327 *
2328 * It is legal to halt a paused channel. Playing a new chunk on a paused
2329 * channel will replace the current chunk and unpause the channel.
2330 *
2331 * Specifying a channel of -1 will pause _all_ channels. Any music is
2332 * unaffected.
2333 *
2334 * You may not specify MAX_CHANNEL_POST for a channel.
2335 *
2336 * \param channel the channel to pause, or -1 to pause all channels.
2337 *
2338 * \since This function is available since SDL_mixer 2.0.0.
2339 */
2340extern DECLSPEC void SDLCALL Mix_Pause(int channel);
2341
2342/**
2343 * Resume a particular channel.
2344 *
2345 * It is legal to resume an unpaused or invalid channel; it causes no effect
2346 * and reports no error.
2347 *
2348 * If the paused channel has an expiration, its expiration countdown resumes
2349 * now, as well.
2350 *
2351 * Specifying a channel of -1 will resume _all_ paused channels. Any music is
2352 * unaffected.
2353 *
2354 * \param channel the channel to resume, or -1 to resume all paused channels.
2355 *
2356 * \since This function is available since SDL_mixer 2.0.0.
2357 */
2358extern DECLSPEC void SDLCALL Mix_Resume(int channel);
2359
2360/**
2361 * Query whether a particular channel is paused.
2362 *
2363 * If an invalid channel is specified, this function returns zero.
2364 *
2365 * \param channel the channel to query, or -1 to query all channels.
2366 * \return 1 if channel paused, 0 otherwise. If `channel` is -1, returns the
2367 * number of paused channels.
2368 *
2369 * \since This function is available since SDL_mixer 2.0.0.
2370 */
2371extern DECLSPEC int SDLCALL Mix_Paused(int channel);
2372
2373/**
2374 * Pause the music stream.
2375 *
2376 * Pausing the music stream will prevent further playback of the assigned
2377 * music object, but will maintain the object's current mixing position. When
2378 * resumed, this channel will continue to mix the music where it left off.
2379 *
2380 * Paused music can be resumed by calling Mix_ResumeMusic().
2381 *
2382 * It is legal to halt paused music. Playing a new music object when music is
2383 * paused will replace the current music and unpause the music stream.
2384 *
2385 * \since This function is available since SDL_mixer 2.0.0.
2386 */
2387extern DECLSPEC void SDLCALL Mix_PauseMusic(void);
2388
2389/**
2390 * Resume the music stream.
2391 *
2392 * It is legal to resume an unpaused music stream; it causes no effect and
2393 * reports no error.
2394 *
2395 * \since This function is available since SDL_mixer 2.0.0.
2396 */
2397extern DECLSPEC void SDLCALL Mix_ResumeMusic(void);
2398
2399/**
2400 * Rewind the music stream.
2401 *
2402 * This causes the currently-playing music to start mixing from the beginning
2403 * of the music, as if it were just started.
2404 *
2405 * It's a legal no-op to rewind the music stream when not playing.
2406 *
2407 * \since This function is available since SDL_mixer 2.0.0.
2408 */
2409extern DECLSPEC void SDLCALL Mix_RewindMusic(void);
2410
2411/**
2412 * Query whether the music stream is paused.
2413 *
2414 * \return 1 if music is paused, 0 otherwise.
2415 *
2416 * \since This function is available since SDL_mixer 2.0.0.
2417 *
2418 * \sa Mix_PauseMusic
2419 * \sa Mix_ResumeMusic
2420 */
2421extern DECLSPEC int SDLCALL Mix_PausedMusic(void);
2422
2423/**
2424 * Jump to a given order in mod music.
2425 *
2426 * This only applies to MOD music formats.
2427 *
2428 * \param order order.
2429 * \returns 0 if successful, or -1 if failed or isn't implemented.
2430 *
2431 * \since This function is available since SDL_mixer 2.6.0.
2432 */
2433extern DECLSPEC int SDLCALL Mix_ModMusicJumpToOrder(int order);
2434
2435/**
2436 * Start a track in music object.
2437 *
2438 * This only applies to GME music formats.
2439 *
2440 * \param music the music object.
2441 * \param track the track number to play. 0 is the first track.
2442 * \returns 0 if successful, or -1 if failed or isn't implemented.
2443 *
2444 * \since This function is available since SDL_mixer 2.8.0.
2445 */
2446extern DECLSPEC int SDLCALL Mix_StartTrack(Mix_Music *music, int track);
2447
2448/**
2449 * Get number of tracks in music object.
2450 *
2451 * This only applies to GME music formats.
2452 *
2453 * \param music the music object.
2454 * \returns number of tracks if successful, or -1 if failed or isn't
2455 * implemented.
2456 *
2457 * \since This function is available since SDL_mixer 2.8.0.
2458 */
2459extern DECLSPEC int SDLCALL Mix_GetNumTracks(Mix_Music *music);
2460
2461/**
2462 * Set the current position in the music stream, in seconds.
2463 *
2464 * To convert from milliseconds, divide by 1000.0.
2465 *
2466 * This function is only implemented for MOD music formats (set pattern order
2467 * number) and for WAV, OGG, FLAC, MP3, and MODPLUG music at the moment.
2468 *
2469 * \param position the new position, in seconds (as a double).
2470 * \returns 0 if successful, or -1 if it failed or not implemented.
2471 *
2472 * \since This function is available since SDL_mixer 2.0.0.
2473 */
2474extern DECLSPEC int SDLCALL Mix_SetMusicPosition(double position);
2475
2476/**
2477 * Get the time current position of music stream, in seconds.
2478 *
2479 * To convert to milliseconds, multiply by 1000.0.
2480 *
2481 * \param music the music object to query.
2482 * \returns -1.0 if this feature is not supported for some codec.
2483 *
2484 * \since This function is available since SDL_mixer 2.6.0.
2485 */
2486extern DECLSPEC double SDLCALL Mix_GetMusicPosition(Mix_Music *music);
2487
2488/**
2489 * Get a music object's duration, in seconds.
2490 *
2491 * To convert to milliseconds, multiply by 1000.0.
2492 *
2493 * If NULL is passed, returns duration of current playing music.
2494 *
2495 * \param music the music object to query.
2496 * \returns music duration in seconds, or -1.0 on error.
2497 *
2498 * \since This function is available since SDL_mixer 2.6.0.
2499 */
2500extern DECLSPEC double SDLCALL Mix_MusicDuration(Mix_Music *music);
2501
2502/**
2503 * Get the loop start time position of music stream, in seconds.
2504 *
2505 * To convert to milliseconds, multiply by 1000.0.
2506 *
2507 * If NULL is passed, returns duration of current playing music.
2508 *
2509 * \param music the music object to query.
2510 * \returns -1.0 if this feature is not used for this music or not supported
2511 * for some codec.
2512 *
2513 * \since This function is available since SDL_mixer 2.6.0.
2514 */
2515extern DECLSPEC double SDLCALL Mix_GetMusicLoopStartTime(Mix_Music *music);
2516
2517/**
2518 * Get the loop end time position of music stream, in seconds.
2519 *
2520 * To convert to milliseconds, multiply by 1000.0.
2521 *
2522 * If NULL is passed, returns duration of current playing music.
2523 *
2524 * \param music the music object to query.
2525 * \returns -1.0 if this feature is not used for this music or not supported
2526 * for some codec.
2527 *
2528 * \since This function is available since SDL_mixer 2.6.0.
2529 */
2530extern DECLSPEC double SDLCALL Mix_GetMusicLoopEndTime(Mix_Music *music);
2531
2532/**
2533 * Get the loop time length of music stream, in seconds.
2534 *
2535 * To convert to milliseconds, multiply by 1000.0.
2536 *
2537 * If NULL is passed, returns duration of current playing music.
2538 *
2539 * \param music the music object to query.
2540 * \returns -1.0 if this feature is not used for this music or not supported
2541 * for some codec.
2542 *
2543 * \since This function is available since SDL_mixer 2.6.0.
2544 */
2545extern DECLSPEC double SDLCALL Mix_GetMusicLoopLengthTime(Mix_Music *music);
2546
2547/**
2548 * Check the playing status of a specific channel.
2549 *
2550 * If the channel is currently playing, this function returns 1. Otherwise it
2551 * returns 0.
2552 *
2553 * If the specified channel is -1, all channels are checked, and this function
2554 * returns the number of channels currently playing.
2555 *
2556 * You may not specify MAX_CHANNEL_POST for a channel.
2557 *
2558 * Paused channels are treated as playing, even though they are not currently
2559 * making forward progress in mixing.
2560 *
2561 * \param channel channel.
2562 * \returns non-zero if channel is playing, zero otherwise. If `channel` is
2563 * -1, return the total number of channel playings.
2564 *
2565 * \since This function is available since SDL_mixer 2.0.0.
2566 */
2567extern DECLSPEC int SDLCALL Mix_Playing(int channel);
2568
2569/**
2570 * Check the playing status of the music stream.
2571 *
2572 * If music is currently playing, this function returns 1. Otherwise it
2573 * returns 0.
2574 *
2575 * Paused music is treated as playing, even though it is not currently making
2576 * forward progress in mixing.
2577 *
2578 * \returns non-zero if music is playing, zero otherwise.
2579 *
2580 * \since This function is available since SDL_mixer 2.0.0.
2581 */
2582extern DECLSPEC int SDLCALL Mix_PlayingMusic(void);
2583
2584/**
2585 * Run an external command as the music stream.
2586 *
2587 * This halts any currently-playing music, and next time the music stream is
2588 * played, SDL_mixer will spawn a process using the command line specified in
2589 * `command`. This command is not subject to shell expansion, and beyond some
2590 * basic splitting up of arguments, is passed to execvp() on most platforms,
2591 * not system().
2592 *
2593 * The command is responsible for generating sound; it is NOT mixed by
2594 * SDL_mixer! SDL_mixer will kill the child process if asked to halt the
2595 * music, but otherwise does not have any control over what the process does.
2596 *
2597 * You are strongly encouraged not to use this function without an extremely
2598 * good reason.
2599 *
2600 * \param command command.
2601 * \returns 0 if successful, -1 on error.
2602 *
2603 * \since This function is available since SDL_mixer 2.0.0.
2604 */
2605extern DECLSPEC int SDLCALL Mix_SetMusicCMD(const char *command);
2606
2607/**
2608 * This function does nothing, do not use.
2609 *
2610 * This was probably meant to expose a feature, but no codecs support it, so
2611 * it only remains for binary compatibility.
2612 *
2613 * Calling this function is a legal no-op that returns -1.
2614 *
2615 * \param value this parameter is ignored.
2616 * \returns -1.
2617 *
2618 * \since This function is available since SDL_mixer 2.0.0.
2619 */
2620extern DECLSPEC int SDLCALL Mix_SetSynchroValue(int value);
2621
2622/**
2623 * This function does nothing, do not use.
2624 *
2625 * This was probably meant to expose a feature, but no codecs support it, so
2626 * it only remains for binary compatibility.
2627 *
2628 * Calling this function is a legal no-op that returns -1.
2629 *
2630 * \returns -1.
2631 *
2632 * \since This function is available since SDL_mixer 2.0.0.
2633 */
2634extern DECLSPEC int SDLCALL Mix_GetSynchroValue(void);
2635
2636/**
2637 * Set SoundFonts paths to use by supported MIDI backends.
2638 *
2639 * You may specify multiple paths in a single string by separating them with
2640 * semicolons; they will be searched in the _reverse_ order listed (last one
2641 * listed will be the first one searched).
2642 *
2643 * This function replaces any previously-specified paths.
2644 *
2645 * Passing a NULL path will remove any previously-specified paths.
2646 *
2647 * Note that unlike most SDL and SDL_mixer functions, this function returns
2648 * zero if there's an error, not on success. We apologize for the API design
2649 * inconsistency here.
2650 *
2651 * \param paths Paths on the filesystem where SoundFonts are available,
2652 * separated by semicolons.
2653 * \returns 1 if successful, 0 on error (out of memory).
2654 *
2655 * \since This function is available since SDL_mixer 2.0.0.
2656 */
2657extern DECLSPEC int SDLCALL Mix_SetSoundFonts(const char *paths);
2658
2659/**
2660 * Get SoundFonts paths to use by supported MIDI backends.
2661 *
2662 * There are several factors that determine what will be reported by this
2663 * function:
2664 *
2665 * - If the boolean _SDL hint_ `"SDL_FORCE_SOUNDFONTS"` is set, AND the
2666 * `"SDL_SOUNDFONTS"` _environment variable_ is also set, this function will
2667 * return that environment variable regardless of whether
2668 * Mix_SetSoundFounts() was ever called.
2669 * - Otherwise, if Mix_SetSoundFonts() was successfully called with a non-NULL
2670 * path, this function will return the string passed to that function.
2671 * - Otherwise, if the `"SDL_SOUNDFONTS"` variable is set, this function will
2672 * return that environment variable.
2673 * - Otherwise, this function will search some common locations on the
2674 * filesystem, and if it finds a SoundFont there, it will return that.
2675 * - Failing everything else, this function returns NULL.
2676 *
2677 * This returns a pointer to internal (possibly read-only) memory, and it
2678 * should not be modified or free'd by the caller.
2679 *
2680 * \returns semicolon-separated list of sound font paths.
2681 *
2682 * \since This function is available since SDL_mixer 2.0.0.
2683 */
2684extern DECLSPEC const char* SDLCALL Mix_GetSoundFonts(void);
2685
2686typedef int (SDLCALL *Mix_EachSoundFontCallback)(const char*, void*);
2687
2688/**
2689 * Iterate SoundFonts paths to use by supported MIDI backends.
2690 *
2691 * This function will take the string reported by Mix_GetSoundFonts(), split
2692 * it up into separate paths, as delimited by semicolons in the string, and
2693 * call a callback function for each separate path.
2694 *
2695 * If there are no paths available, this returns 0 without calling the
2696 * callback at all.
2697 *
2698 * If the callback returns non-zero, this function stops iterating and returns
2699 * non-zero. If the callback returns 0, this function will continue iterating,
2700 * calling the callback again for further paths. If the callback never returns
2701 * 1, this function returns 0, so this can be used to decide if an available
2702 * soundfont is acceptable for use.
2703 *
2704 * \param function the callback function to call once per path.
2705 * \param data a pointer to pass to the callback for its own personal use.
2706 * \returns non-zero if callback ever returned non-zero, 0 on error or the
2707 * callback never returned non-zero.
2708 *
2709 * \since This function is available since SDL_mixer 2.0.0.
2710 *
2711 * \sa Mix_GetSoundFonts
2712 */
2713extern DECLSPEC int SDLCALL Mix_EachSoundFont(Mix_EachSoundFontCallback function, void *data);
2714
2715/**
2716 * Set full path of the Timidity config file.
2717 *
2718 * For example, "/etc/timidity.cfg"
2719 *
2720 * This is obviously only useful if SDL_mixer is using Timidity internally to
2721 * play MIDI files.
2722 *
2723 * \param path path to a Timidity config file.
2724 * \returns 1 if successful, 0 on error.
2725 *
2726 * \since This function is available since SDL_mixer 2.6.0.
2727 */
2728extern DECLSPEC int SDLCALL Mix_SetTimidityCfg(const char *path);
2729
2730/**
2731 * Get full path of a previously-specified Timidity config file.
2732 *
2733 * For example, "/etc/timidity.cfg"
2734 *
2735 * If a path has never been specified, this returns NULL.
2736 *
2737 * This returns a pointer to internal memory, and it should not be modified or
2738 * free'd by the caller.
2739 *
2740 * \returns the previously-specified path, or NULL if not set.
2741 *
2742 * \since This function is available since SDL_mixer 2.6.0.
2743 *
2744 * \sa Mix_SetTimidityCfg
2745 */
2746extern DECLSPEC const char* SDLCALL Mix_GetTimidityCfg(void);
2747
2748/**
2749 * Get the Mix_Chunk currently associated with a mixer channel.
2750 *
2751 * You may not specify MAX_CHANNEL_POST or -1 for a channel.
2752 *
2753 * \param channel the channel to query.
2754 * \returns the associated chunk, if any, or NULL if it's an invalid channel.
2755 *
2756 * \since This function is available since SDL_mixer 2.0.0.
2757 */
2758extern DECLSPEC Mix_Chunk * SDLCALL Mix_GetChunk(int channel);
2759
2760/**
2761 * Close the mixer, halting all playing audio.
2762 *
2763 * Any halted channels will have any currently-registered effects
2764 * deregistered, and will call any callback specified by Mix_ChannelFinished()
2765 * before this function returns.
2766 *
2767 * Any halted music will call any callback specified by
2768 * Mix_HookMusicFinished() before this function returns.
2769 *
2770 * Do not start any new audio playing during callbacks in this function.
2771 *
2772 * This will close the audio device. Attempting to play new audio after this
2773 * function returns will fail, until another successful call to
2774 * Mix_OpenAudio() or Mix_OpenAudioDevice().
2775 *
2776 * Note that (unlike Mix_OpenAudio optionally calling SDL_Init(SDL_INIT_AUDIO)
2777 * on the app's behalf), this will _not_ deinitialize the SDL audio subsystem
2778 * in any case. At some point after calling this function and Mix_Quit(), some
2779 * part of the application should be responsible for calling SDL_Quit() to
2780 * deinitialize all of SDL, including its audio subsystem.
2781 *
2782 * This function should be the last thing you call in SDL_mixer before
2783 * Mix_Quit(). However, the following notes apply if you don't follow this
2784 * advice:
2785 *
2786 * Note that this will not free any loaded chunks or music; you should dispose
2787 * of those resources separately. It is probably poor form to dispose of them
2788 * _after_ this function, but it is safe to call Mix_FreeChunk() and
2789 * Mix_FreeMusic() after closing the device.
2790 *
2791 * Note that any chunks or music you don't free may or may not work if you
2792 * call Mix_OpenAudio again, as the audio device may be in a new format and
2793 * the existing chunks will not be converted to match.
2794 *
2795 * \since This function is available since SDL_mixer 2.0.0.
2796 *
2797 * \sa Mix_Quit
2798 */
2799extern DECLSPEC void SDLCALL Mix_CloseAudio(void);
2800
2801/* We'll use SDL for reporting errors */
2802
2803/**
2804 * Report SDL_mixer errors
2805 *
2806 * \sa Mix_GetError
2807 */
2808#define Mix_SetError SDL_SetError
2809
2810/**
2811 * Get last SDL_mixer error
2812 *
2813 * \sa Mix_SetError
2814 */
2815#define Mix_GetError SDL_GetError
2816
2817/**
2818 * Clear last SDL_mixer error
2819 *
2820 * \sa Mix_SetError
2821 */
2822#define Mix_ClearError SDL_ClearError
2823
2824/**
2825 * Set OutOfMemory error
2826 */
2827#define Mix_OutOfMemory SDL_OutOfMemory
2828
2829/* Ends C function definitions when using C++ */
2830#ifdef __cplusplus
2831}
2832#endif
2833
2834#include "close_code.h"
2835
2836#endif /* SDL_MIXER_H_ */