/
SDL_mixer.h
2784 lines (2643 loc) · 108 KB
/
SDL_mixer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
SDL_mixer: An audio mixer library based on the SDL library
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/**
* \file SDL_mixer.h
*
* Header file for SDL_mixer library
*
* A simple library to play and mix sounds and musics
*/
#ifndef SDL_MIXER_H_
#define SDL_MIXER_H_
#include "SDL_stdinc.h"
#include "SDL_rwops.h"
#include "SDL_audio.h"
#include "SDL_endian.h"
#include "SDL_version.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
*/
#define SDL_MIXER_MAJOR_VERSION 2
#define SDL_MIXER_MINOR_VERSION 6
#define SDL_MIXER_PATCHLEVEL 2
/**
* This macro can be used to fill a version structure with the compile-time
* version of the SDL_mixer library.
*/
#define SDL_MIXER_VERSION(X) \
{ \
(X)->major = SDL_MIXER_MAJOR_VERSION; \
(X)->minor = SDL_MIXER_MINOR_VERSION; \
(X)->patch = SDL_MIXER_PATCHLEVEL; \
}
/* Backwards compatibility */
#define MIX_MAJOR_VERSION SDL_MIXER_MAJOR_VERSION
#define MIX_MINOR_VERSION SDL_MIXER_MINOR_VERSION
#define MIX_PATCHLEVEL SDL_MIXER_PATCHLEVEL
#define MIX_VERSION(X) SDL_MIXER_VERSION(X)
#if SDL_MIXER_MAJOR_VERSION < 3 && SDL_MAJOR_VERSION < 3
/**
* This is the version number macro for the current SDL_mixer version.
*
* In versions higher than 2.9.0, the minor version overflows into
* the thousands digit: for example, 2.23.0 is encoded as 4300.
* This macro will not be available in SDL 3.x or SDL_mixer 3.x.
*
* Deprecated, use SDL_MIXER_VERSION_ATLEAST or SDL_MIXER_VERSION instead.
*/
#define SDL_MIXER_COMPILEDVERSION \
SDL_VERSIONNUM(SDL_MIXER_MAJOR_VERSION, SDL_MIXER_MINOR_VERSION, SDL_MIXER_PATCHLEVEL)
#endif /* SDL_MIXER_MAJOR_VERSION < 3 && SDL_MAJOR_VERSION < 3 */
/**
* This macro will evaluate to true if compiled with SDL_mixer at least X.Y.Z.
*/
#define SDL_MIXER_VERSION_ATLEAST(X, Y, Z) \
((SDL_MIXER_MAJOR_VERSION >= X) && \
(SDL_MIXER_MAJOR_VERSION > X || SDL_MIXER_MINOR_VERSION >= Y) && \
(SDL_MIXER_MAJOR_VERSION > X || SDL_MIXER_MINOR_VERSION > Y || SDL_MIXER_PATCHLEVEL >= Z))
/**
* Query the version of SDL_mixer that the program is linked against.
*
* This function gets the version of the dynamically linked SDL_mixer library.
* This is separate from the SDL_MIXER_VERSION() macro, which tells you what
* version of the SDL_mixer headers you compiled against.
*
* This returns static internal data; do not free or modify it!
*
* \returns a pointer to the version information.
*
* \since This function is available since SDL_mixer 2.0.0.
*/
extern DECLSPEC const SDL_version * SDLCALL Mix_Linked_Version(void);
/**
* Initialization flags
*/
typedef enum
{
MIX_INIT_FLAC = 0x00000001,
MIX_INIT_MOD = 0x00000002,
MIX_INIT_MP3 = 0x00000008,
MIX_INIT_OGG = 0x00000010,
MIX_INIT_MID = 0x00000020,
MIX_INIT_OPUS = 0x00000040
} MIX_InitFlags;
/**
* Initialize SDL_mixer.
*
* This function loads dynamic libraries that SDL_mixer needs, and prepares
* them for use. This must be the first function you call in SDL_mixer, and if
* it fails you should not continue with the library.
*
* Flags should be one or more flags from MIX_InitFlags OR'd together. It
* returns the flags successfully initialized, or 0 on failure.
*
* Currently, these flags are:
*
* - `MIX_INIT_FLAC`
* - `MIX_INIT_MOD`
* - `MIX_INIT_MP3`
* - `MIX_INIT_OGG`
* - `MIX_INIT_MID`
* - `MIX_INIT_OPUS`
*
* More flags may be added in a future SDL_mixer release.
*
* This function may need to load external shared libraries to support various
* codecs, which means this function can fail to initialize that support on an
* otherwise-reasonable system if the library isn't available; this is not
* just a question of exceptional circumstances like running out of memory at
* startup!
*
* Note that you may call this function more than once to initialize with
* additional flags. The return value will reflect both new flags that
* successfully initialized, and also include flags that had previously been
* initialized as well.
*
* As this will return previously-initialized flags, it's legal to call this
* with zero (no flags set). This is a safe no-op that can be used to query
* the current initialization state without changing it at all.
*
* Since this returns previously-initialized flags as well as new ones, and
* you can call this with zero, you should not check for a zero return value
* to determine an error condition. Instead, you should check to make sure all
* the flags you require are set in the return value. If you have a game with
* data in a specific format, this might be a fatal error. If you're a generic
* media player, perhaps you are fine with only having WAV and MP3 support and
* can live without Opus playback, even if you request support for everything.
*
* Unlike other SDL satellite libraries, calls to Mix_Init do not stack; a
* single call to Mix_Quit() will deinitialize everything and does not have to
* be paired with a matching Mix_Init call. For that reason, it's considered
* best practices to have a single Mix_Init and Mix_Quit call in your program.
* While this isn't required, be aware of the risks of deviating from that
* behavior.
*
* After initializing SDL_mixer, the next step is to open an audio device to
* prepare to play sound (with Mix_OpenAudio() or Mix_OpenAudioDevice()), and
* load audio data to play with that device.
*
* \param flags initialization flags, OR'd together.
* \returns all currently initialized flags.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_Quit
*/
extern DECLSPEC int SDLCALL Mix_Init(int flags);
/**
* Deinitialize SDL_mixer.
*
* This should be the last function you call in SDL_mixer, after freeing all
* other resources and closing all audio devices. This will unload any shared
* libraries it is using for various codecs.
*
* After this call, a call to Mix_Init(0) will return 0 (no codecs loaded).
*
* You can safely call Mix_Init() to reload various codec support after this
* call.
*
* Unlike other SDL satellite libraries, calls to Mix_Init do not stack; a
* single call to Mix_Quit() will deinitialize everything and does not have to
* be paired with a matching Mix_Init call. For that reason, it's considered
* best practices to have a single Mix_Init and Mix_Quit call in your program.
* While this isn't required, be aware of the risks of deviating from that
* behavior.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_Init
*/
extern DECLSPEC void SDLCALL Mix_Quit(void);
/**
* The default mixer has 8 simultaneous mixing channels
*/
#ifndef MIX_CHANNELS
#define MIX_CHANNELS 8
#endif
/* Good default values for a PC soundcard */
#define MIX_DEFAULT_FREQUENCY 44100
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define MIX_DEFAULT_FORMAT AUDIO_S16LSB
#else
#define MIX_DEFAULT_FORMAT AUDIO_S16MSB
#endif
#define MIX_DEFAULT_CHANNELS 2
#define MIX_MAX_VOLUME SDL_MIX_MAXVOLUME /* Volume of a chunk */
/**
* The internal format for an audio chunk
*/
typedef struct Mix_Chunk {
int allocated;
Uint8 *abuf;
Uint32 alen;
Uint8 volume; /* Per-sample volume, 0-128 */
} Mix_Chunk;
/**
* The different fading types supported
*/
typedef enum {
MIX_NO_FADING,
MIX_FADING_OUT,
MIX_FADING_IN
} Mix_Fading;
/**
* These are types of music files (not libraries used to load them)
*/
typedef enum {
MUS_NONE,
MUS_CMD,
MUS_WAV,
MUS_MOD,
MUS_MID,
MUS_OGG,
MUS_MP3,
MUS_MP3_MAD_UNUSED,
MUS_FLAC,
MUS_MODPLUG_UNUSED,
MUS_OPUS
} Mix_MusicType;
/**
* The internal format for a music chunk interpreted via codecs
*/
typedef struct _Mix_Music Mix_Music;
/**
* Open the default audio device for playback.
*
* An audio device is what generates sound, so the app must open one to make
* noise.
*
* This function will check if SDL's audio system is initialized, and if not,
* it will initialize it by calling `SDL_Init(SDL_INIT_AUDIO)` on your behalf.
* You are free to (and encouraged to!) initialize it yourself before calling
* this function, as this gives your program more control over the process.
*
* This function might cover all of an application's needs, but for those that
* need more flexibility, the more powerful version of this function is
* Mix_OpenAudioDevice(). This function is equivalent to calling:
*
* ```c
* Mix_OpenAudioDevice(frequency, format, nchannels, chunksize, NULL,
* SDL_AUDIO_ALLOW_FREQUENCY_CHANGE |
* SDL_AUDIO_ALLOW_CHANNELS_CHANGE);
* ```
*
* If you aren't particularly concerned with the specifics of the audio
* device, and your data isn't in a specific format, the values you use here
* can just be reasonable defaults. SDL_mixer will convert audio data you feed
* it to the correct format on demand.
*
* That being said, if you have control of your audio data and you know its
* format ahead of time, you can save CPU time by opening the audio device in
* that exact format so SDL_mixer does not have to spend time converting
* anything behind the scenes, and can just pass the data straight through to
* the hardware. On some platforms, where the hardware only supports specific
* settings, you might have to be careful to make everything match, but your
* own data is often easier to control, so aim to open the device for what you
* need.
*
* The other reason to care about specific formats: if you plan to touch the
* mix buffer directly (with Mix_SetPostMix, a registered effect, or
* Mix_HookMusic), you might have code that expects it to be in a specific
* format, and you should specify that here.
*
* The audio device frequency is specified in Hz; in modern times, 48000 is
* often a reasonable default.
*
* The audio device format is one of SDL's AUDIO_* constants. AUDIO_S16SYS
* (16-bit audio) is probably a safe default. More modern systems may prefer
* AUDIO_F32SYS (32-bit floating point audio).
*
* The audio device channels are generally 1 for mono output, or 2 for stereo,
* but the brave can try surround sound configs with 4 (quad), 6 (5.1), 7
* (6.1) or 8 (7.1).
*
* The audio device's chunk size is the number of sample frames (one sample
* per frame for mono output, two samples per frame in a stereo setup, etc)
* that are fed to the device at once. The lower the number, the lower the
* latency, but you risk dropouts if it gets too low. 2048 is often a
* reasonable default, but your app might want to experiment with 1024 or
* 4096.
*
* You may only have one audio device open at a time; if you want to change a
* setting, you must close the device and reopen it, which is not something
* you can do seamlessly during playback.
*
* This function does not allow you to select a specific audio device on the
* system, it always chooses the best default it can on your behalf (which, in
* many cases, is exactly what you want anyhow). If you must choose a specific
* device, you can do so with Mix_OpenAudioDevice() instead.
*
* If this function reports success, you are ready to start making noise! Load
* some audio data and start playing!
*
* The app can use Mix_QuerySpec() to determine the final device settings.
*
* When done with an audio device, probably at the end of the program, the app
* should dispose of the device with Mix_CloseDevice().
*
* \param frequency the frequency to playback audio at (in Hz).
* \param format audio format, one of SDL's AUDIO_* values.
* \param channels number of channels (1 is mono, 2 is stereo, etc).
* \param chunksize audio buffer size in sample FRAMES (total samples divided
* by channel count).
* \returns 0 if successful, -1 on error.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_OpenAudioDevice
* \sa Mix_CloseDevice
*/
extern DECLSPEC int SDLCALL Mix_OpenAudio(int frequency, Uint16 format, int channels, int chunksize);
/**
* Open a specific audio device for playback.
*
* (A slightly simpler version of this function is available in
* Mix_OpenAudio(), which still might meet most applications' needs.)
*
* An audio device is what generates sound, so the app must open one to make
* noise.
*
* This function will check if SDL's audio system is initialized, and if not,
* it will initialize it by calling `SDL_Init(SDL_INIT_AUDIO)` on your behalf.
* You are free to (and encouraged to!) initialize it yourself before calling
* this function, as this gives your program more control over the process.
*
* If you aren't particularly concerned with the specifics of the audio
* device, and your data isn't in a specific format, the values you use here
* can just be reasonable defaults. SDL_mixer will convert audio data you feed
* it to the correct format on demand.
*
* That being said, if you have control of your audio data and you know its
* format ahead of time, you can save CPU time by opening the audio device in
* that exact format so SDL_mixer does not have to spend time converting
* anything behind the scenes, and can just pass the data straight through to
* the hardware. On some platforms, where the hardware only supports specific
* settings, you might have to be careful to make everything match, but your
* own data is often easier to control, so aim to open the device for what you
* need.
*
* The other reason to care about specific formats: if you plan to touch the
* mix buffer directly (with Mix_SetPostMix, a registered effect, or
* Mix_HookMusic), you might have code that expects it to be in a specific
* format, and you should specify that here.
*
* The audio device frequency is specified in Hz; in modern times, 48000 is
* often a reasonable default.
*
* The audio device format is one of SDL's AUDIO_* constants. AUDIO_S16SYS
* (16-bit audio) is probably a safe default. More modern systems may prefer
* AUDIO_F32SYS (32-bit floating point audio).
*
* The audio device channels are generally 1 for mono output, or 2 for stereo,
* but the brave can try surround sound configs with 4 (quad), 6 (5.1), 7
* (6.1) or 8 (7.1).
*
* The audio device's chunk size is the number of sample frames (one sample
* per frame for mono output, two samples per frame in a stereo setup, etc)
* that are fed to the device at once. The lower the number, the lower the
* latency, but you risk dropouts if it gets too low. 2048 is often a
* reasonable default, but your app might want to experiment with 1024 or
* 4096.
*
* You may only have one audio device open at a time; if you want to change a
* setting, you must close the device and reopen it, which is not something
* you can do seamlessly during playback.
*
* This function allows you to select specific audio hardware on the system
* with the `device` parameter. If you specify NULL, SDL_mixer will choose the
* best default it can on your behalf (which, in many cases, is exactly what
* you want anyhow). SDL_mixer does not offer a mechanism to determine device
* names to open, but you can use SDL_GetNumAudioDevices() to get a count of
* available devices and then SDL_GetAudioDeviceName() in a loop to obtain a
* list. If you do this, be sure to call `SDL_Init(SDL_INIT_AUDIO)` first to
* initialize SDL's audio system!
*
* The `allowed_changes` parameter specifies what settings are flexible. These
* are the `SDL_AUDIO_ALLOW_*` flags from SDL. These tell SDL_mixer that the
* app doesn't mind if a specific setting changes. For example, the app might
* need stereo data in Sint16 format, but if the sample rate or chunk size
* changes, the app can handle that. In that case, the app would specify
* `SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_SAMPLES_CHANGE`. In this
* case, if the system's hardware requires something other than the requested
* format, SDL_mixer can select what the hardware demands instead of the app.
* If the `SDL_AUDIO_ALLOW_` flag is not specified, SDL_mixer must convert
* data behind the scenes between what the app demands and what the hardware
* requires. If your app needs precisely what is requested, specify zero for
* `allowed_changes`.
*
* If changes were allowed, the app can use Mix_QuerySpec() to determine the
* final device settings.
*
* If this function reports success, you are ready to start making noise! Load
* some audio data and start playing!
*
* When done with an audio device, probably at the end of the program, the app
* should dispose of the device with Mix_CloseDevice().
*
* \param frequency the frequency to playback audio at (in Hz).
* \param format audio format, one of SDL's AUDIO_* values.
* \param channels number of channels (1 is mono, 2 is stereo, etc).
* \param chunksize audio buffer size in sample FRAMES (total samples divided
* by channel count).
* \param device the device name to open, or NULL to choose a reasonable
* default.
* \param allowed_changes Allow change flags (see SDL_AUDIO_ALLOW_* flags)
* \returns 0 if successful, -1 on error.
*
* \since This function is available since SDL_mixer 2.0.2.
*
* \sa Mix_OpenAudio
* \sa Mix_CloseDevice
* \sa Mix_QuerySpec
*/
extern DECLSPEC int SDLCALL Mix_OpenAudioDevice(int frequency, Uint16 format, int channels, int chunksize, const char* device, int allowed_changes);
/**
* Find out what the actual audio device parameters are.
*
* If Mix_OpenAudioDevice() was called with `allowed_changes` set to anything
* but zero, or Mix_OpenAudio() was used, some audio device settings may be
* different from the application's request. This function will report what
* the device is actually running at.
*
* Note this is only important if the app intends to touch the audio buffers
* being sent to the hardware directly. If an app just wants to play audio
* files and let SDL_mixer handle the low-level details, this function can
* probably be ignored.
*
* If the audio device is not opened, this function will return 0.
*
* \param frequency On return, will be filled with the audio device's
* frequency in Hz.
* \param format On return, will be filled with the audio device's format.
* \param channels On return, will be filled with the audio device's channel
* count.
* \returns 1 if the audio device has been opened, 0 otherwise.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_OpenAudio
* \sa Mix_OpenAudioDevice
*/
extern DECLSPEC int SDLCALL Mix_QuerySpec(int *frequency, Uint16 *format, int *channels);
/**
* Dynamically change the number of channels managed by the mixer.
*
* SDL_mixer deals with "channels," which is not the same thing as the
* mono/stereo channels; they might be better described as "tracks," as each
* one corresponds to a separate source of audio data. Three different WAV
* files playing at the same time would be three separate SDL_mixer channels,
* for example.
*
* An app needs as many channels as it has audio data it wants to play
* simultaneously, mixing them into a single stream to send to the audio
* device.
*
* SDL_mixer allocates `MIX_CHANNELS` (currently 8) channels when you open an
* audio device, which may be more than an app needs, but if the app needs
* more or wants less, this function can change it.
*
* If decreasing the number of channels, any upper channels currently playing
* are stopped. This will deregister all effects on those channels and call
* any callback specified by Mix_ChannelFinished() for each removed channel.
*
* If `numchans` is less than zero, this will return the current number of
* channels without changing anything.
*
* \param numchans the new number of channels, or < 0 to query current channel
* count.
* \returns the new number of allocated channels.
*
* \since This function is available since SDL_mixer 2.0.0.
*/
extern DECLSPEC int SDLCALL Mix_AllocateChannels(int numchans);
/**
* Load a supported audio format into a chunk.
*
* SDL_mixer has two separate data structures for audio data. One it calls a
* "chunk," which is meant to be a file completely decoded into memory up
* front, and the other it calls "music" which is a file intended to be
* decoded on demand. Originally, simple formats like uncompressed WAV files
* were meant to be chunks and compressed things, like MP3s, were meant to be
* music, and you would stream one thing for a game's music and make repeating
* sound effects with the chunks.
*
* In modern times, this isn't split by format anymore, and most are
* interchangeable, so the question is what the app thinks is worth
* predecoding or not. Chunks might take more memory, but once they are loaded
* won't need to decode again, whereas music always needs to be decoded on the
* fly. Also, crucially, there are as many channels for chunks as the app can
* allocate, but SDL_mixer only offers a single "music" channel.
*
* If `freesrc` is non-zero, the RWops will be closed before returning,
* whether this function succeeds or not. SDL_mixer reads everything it needs
* from the RWops during this call in any case.
*
* There is a separate function (a macro, before SDL_mixer 2.6.0) to read
* files from disk without having to deal with SDL_RWops:
* `Mix_LoadWAV("filename.wav")` will call this function and manage those
* details for you.
*
* When done with a chunk, the app should dispose of it with a call to
* Mix_FreeChunk().
*
* \param src an SDL_RWops that data will be read from.
* \param freesrc non-zero to close/free the SDL_RWops before returning, zero
* to leave it open.
* \returns a new chunk, or NULL on error.
*
* \since This function is available since SDL_mixer 2.6.0 (and as a macro
* since 2.0.0).
*
* \sa Mix_LoadWAV
* \sa Mix_FreeChunk
*/
extern DECLSPEC Mix_Chunk * SDLCALL Mix_LoadWAV_RW(SDL_RWops *src, int freesrc);
/**
* Load a supported audio format into a chunk.
*
* SDL_mixer has two separate data structures for audio data. One it calls a
* "chunk," which is meant to be a file completely decoded into memory up
* front, and the other it calls "music" which is a file intended to be
* decoded on demand. Originally, simple formats like uncompressed WAV files
* were meant to be chunks and compressed things, like MP3s, were meant to be
* music, and you would stream one thing for a game's music and make repeating
* sound effects with the chunks.
*
* In modern times, this isn't split by format anymore, and most are
* interchangeable, so the question is what the app thinks is worth
* predecoding or not. Chunks might take more memory, but once they are loaded
* won't need to decode again, whereas music always needs to be decoded on the
* fly. Also, crucially, there are as many channels for chunks as the app can
* allocate, but SDL_mixer only offers a single "music" channel.
*
* If you would rather use the abstract SDL_RWops interface to load data from
* somewhere other than the filesystem, you can use Mix_LoadWAV_RW() instead.
*
* When done with a chunk, the app should dispose of it with a call to
* Mix_FreeChunk().
*
* Note that before SDL_mixer 2.6.0, this function was a macro that called
* Mix_LoadWAV_RW(), creating a RWops and setting `freesrc` to 1. This macro
* has since been promoted to a proper API function. Older binaries linked
* against a newer SDL_mixer will still call Mix_LoadWAV_RW directly, as they
* are using the macro, which was available since the dawn of time.
*
* \param file the filesystem path to load data from.
* \returns a new chunk, or NULL on error.
*
* \since This function is available since SDL_mixer 2.6.0 (and as a macro
* since 2.0.0).
*
* \sa Mix_LoadWAV_RW
* \sa Mix_FreeChunk
*/
extern DECLSPEC Mix_Chunk * SDLCALL Mix_LoadWAV(const char *file);
/**
* Load a supported audio format into a music object.
*
* SDL_mixer has two separate data structures for audio data. One it calls a
* "chunk," which is meant to be a file completely decoded into memory up
* front, and the other it calls "music" which is a file intended to be
* decoded on demand. Originally, simple formats like uncompressed WAV files
* were meant to be chunks and compressed things, like MP3s, were meant to be
* music, and you would stream one thing for a game's music and make repeating
* sound effects with the chunks.
*
* In modern times, this isn't split by format anymore, and most are
* interchangeable, so the question is what the app thinks is worth
* predecoding or not. Chunks might take more memory, but once they are loaded
* won't need to decode again, whereas music always needs to be decoded on the
* fly. Also, crucially, there are as many channels for chunks as the app can
* allocate, but SDL_mixer only offers a single "music" channel.
*
* When done with this music, the app should dispose of it with a call to
* Mix_FreeMusic().
*
* \param file a file path from where to load music data.
* \returns a new music object, or NULL on error.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_FreeMusic
*/
extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS(const char *file);
/**
* Load a supported audio format into a music object.
*
* SDL_mixer has two separate data structures for audio data. One it calls a
* "chunk," which is meant to be a file completely decoded into memory up
* front, and the other it calls "music" which is a file intended to be
* decoded on demand. Originally, simple formats like uncompressed WAV files
* were meant to be chunks and compressed things, like MP3s, were meant to be
* music, and you would stream one thing for a game's music and make repeating
* sound effects with the chunks.
*
* In modern times, this isn't split by format anymore, and most are
* interchangeable, so the question is what the app thinks is worth
* predecoding or not. Chunks might take more memory, but once they are loaded
* won't need to decode again, whereas music always needs to be decoded on the
* fly. Also, crucially, there are as many channels for chunks as the app can
* allocate, but SDL_mixer only offers a single "music" channel.
*
* If `freesrc` is non-zero, the RWops will be closed before returning,
* whether this function succeeds or not. SDL_mixer reads everything it needs
* from the RWops during this call in any case.
*
* As a convenience, there is a function to read files from disk without
* having to deal with SDL_RWops: `Mix_LoadMUS("filename.mp3")` will manage
* those details for you.
*
* This function attempts to guess the file format from incoming data. If the
* caller knows the format, or wants to force it, it should use
* Mix_LoadMUSType_RW() instead.
*
* When done with this music, the app should dispose of it with a call to
* Mix_FreeMusic().
*
* \param src an SDL_RWops that data will be read from.
* \param freesrc non-zero to close/free the SDL_RWops before returning, zero
* to leave it open.
* \returns a new music object, or NULL on error.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_FreeMusic
*/
extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *src, int freesrc);
/**
* Load an audio format into a music object, assuming a specific format.
*
* SDL_mixer has two separate data structures for audio data. One it calls a
* "chunk," which is meant to be a file completely decoded into memory up
* front, and the other it calls "music" which is a file intended to be
* decoded on demand. Originally, simple formats like uncompressed WAV files
* were meant to be chunks and compressed things, like MP3s, were meant to be
* music, and you would stream one thing for a game's music and make repeating
* sound effects with the chunks.
*
* In modern times, this isn't split by format anymore, and most are
* interchangeable, so the question is what the app thinks is worth
* predecoding or not. Chunks might take more memory, but once they are loaded
* won't need to decode again, whereas music always needs to be decoded on the
* fly. Also, crucially, there are as many channels for chunks as the app can
* allocate, but SDL_mixer only offers a single "music" channel.
*
* This function loads music data, and lets the application specify the type
* of music being loaded, which might be useful if SDL_mixer cannot figure it
* out from the data stream itself.
*
* Currently, the following types are supported:
*
* - `MUS_NONE` (SDL_mixer should guess, based on the data)
* - `MUS_WAV` (Microsoft WAV files)
* - `MUS_MOD` (Various tracker formats)
* - `MUS_MID` (MIDI files)
* - `MUS_OGG` (Ogg Vorbis files)
* - `MUS_MP3` (MP3 files)
* - `MUS_FLAC` (FLAC files)
* - `MUS_OPUS` (Opus files)
*
* If `freesrc` is non-zero, the RWops will be closed before returning,
* whether this function succeeds or not. SDL_mixer reads everything it needs
* from the RWops during this call in any case.
*
* As a convenience, there is a function to read files from disk without
* having to deal with SDL_RWops: `Mix_LoadMUS("filename.mp3")` will manage
* those details for you (but not let you specify the music type explicitly)..
*
* When done with this music, the app should dispose of it with a call to
* Mix_FreeMusic().
*
* \param src an SDL_RWops that data will be read from.
* \param type the type of audio data provided by `src`.
* \param freesrc non-zero to close/free the SDL_RWops before returning, zero
* to leave it open.
* \returns a new music object, or NULL on error.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_FreeMusic
*/
extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc);
/**
* Load a WAV file from memory as quickly as possible.
*
* Unlike Mix_LoadWAV_RW, this function has several requirements, and unless
* you control all your audio data and know what you're doing, you should
* consider this function unsafe and not use it.
*
* - The provided audio data MUST be in Microsoft WAV format.
* - The provided audio data shouldn't use any strange WAV extensions.
* - The audio data MUST be in the exact same format as the audio device. This
* function will not attempt to convert it, or even verify it's in the right
* format.
* - The audio data must be valid; this function does not know the size of the
* memory buffer, so if the WAV data is corrupted, it can read past the end
* of the buffer, causing a crash.
* - The audio data must live at least as long as the returned Mix_Chunk,
* because SDL_mixer will use that data directly and not make a copy of it.
*
* This function will do NO error checking! Be extremely careful here!
*
* (Seriously, use Mix_LoadWAV_RW instead.)
*
* If this function is successful, the provided memory buffer must remain
* available until Mix_FreeChunk() is called on the returned chunk.
*
* \param mem memory buffer containing of a WAV file.
* \returns a new chunk, or NULL on error.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_LoadWAV_RW
* \sa Mix_FreeChunk
*/
extern DECLSPEC Mix_Chunk * SDLCALL Mix_QuickLoad_WAV(Uint8 *mem);
/**
* Load a raw audio data from memory as quickly as possible.
*
* The audio data MUST be in the exact same format as the audio device. This
* function will not attempt to convert it, or even verify it's in the right
* format.
*
* If this function is successful, the provided memory buffer must remain
* available until Mix_FreeChunk() is called on the returned chunk.
*
* \param mem memory buffer containing raw PCM data.
* \param len length of buffer pointed to by `mem`, in bytes.
* \returns a new chunk, or NULL on error.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_FreeChunk
*/
extern DECLSPEC Mix_Chunk * SDLCALL Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len);
/**
* Free an audio chunk.
*
* An app should call this function when it is done with a Mix_Chunk and wants
* to dispose of its resources.
*
* SDL_mixer will stop any channels this chunk is currently playing on. This
* will deregister all effects on those channels and call any callback
* specified by Mix_ChannelFinished() for each removed channel.
*
* \param chunk the chunk to free.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_LoadWAV
* \sa Mix_LoadWAV_RW
* \sa Mix_QuickLoad_WAV
* \sa Mix_QuickLoad_RAW
*/
extern DECLSPEC void SDLCALL Mix_FreeChunk(Mix_Chunk *chunk);
/**
* Free a music object.
*
* If this music is currently playing, it will be stopped.
*
* If this music is in the process of fading out (via Mix_FadeOutMusic()),
* this function will *block* until the fade completes. If you need to avoid
* this, be sure to call Mix_HaltMusic() before freeing the music.
*
* \param music the music object to free.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_LoadMUS
* \sa Mix_LoadMUS_RW
* \sa Mix_LoadMUSType_RW
*/
extern DECLSPEC void SDLCALL Mix_FreeMusic(Mix_Music *music);
/**
* Get a list of chunk decoders that this build of SDL_mixer provides.
*
* This list can change between builds AND runs of the program, if external
* libraries that add functionality become available. You must successfully
* call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
* as decoders are activated at device open time.
*
* Appearing in this list doesn't promise your specific audio file will
* decode...but it's handy to know if you have, say, a functioning Ogg Vorbis
* install.
*
* These return values are static, read-only data; do not modify or free it.
* The pointers remain valid until you call Mix_CloseAudio().
*
* \returns number of chunk decoders available.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_GetChunkDecoder
* \sa Mix_HasChunkDecoder
*/
extern DECLSPEC int SDLCALL Mix_GetNumChunkDecoders(void);
/**
* Get a chunk decoder's name.
*
* The requested decoder's index must be between zero and
* Mix_GetNumChunkDecoders()-1. It's safe to call this with an invalid index;
* this function will return NULL in that case.
*
* This list can change between builds AND runs of the program, if external
* libraries that add functionality become available. You must successfully
* call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
* as decoders are activated at device open time.
*
* \param index index of the chunk decoder.
* \returns the chunk decoder's name.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_GetNumChunkDecoders
*/
extern DECLSPEC const char * SDLCALL Mix_GetChunkDecoder(int index);
/**
* Check if a chunk decoder is available by name.
*
* This result can change between builds AND runs of the program, if external
* libraries that add functionality become available. You must successfully
* call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
* as decoders are activated at device open time.
*
* Decoder names are arbitrary but also obvious, so you have to know what
* you're looking for ahead of time, but usually it's the file extension in
* capital letters (some example names are "AIFF", "VOC", "WAV").
*
* \param name the decoder name to query.
* \returns SDL_TRUE if a decoder by that name is available, SDL_FALSE
* otherwise.
*
* \since This function is available since SDL_mixer 2.0.2.
*
* \sa Mix_GetNumChunkDecoders
* \sa Mix_GetChunkDecoder
*/
extern DECLSPEC SDL_bool SDLCALL Mix_HasChunkDecoder(const char *name);
/**
* Get a list of music decoders that this build of SDL_mixer provides.
*
* This list can change between builds AND runs of the program, if external
* libraries that add functionality become available. You must successfully
* call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
* as decoders are activated at device open time.
*
* Appearing in this list doesn't promise your specific audio file will
* decode...but it's handy to know if you have, say, a functioning Ogg Vorbis
* install.
*
* These return values are static, read-only data; do not modify or free it.
* The pointers remain valid until you call Mix_CloseAudio().
*
* \returns number of chunk decoders available.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_GetMusicDecoder
* \sa Mix_HasMusicDecoder
*/
extern DECLSPEC int SDLCALL Mix_GetNumMusicDecoders(void);
/**
* Get a music decoder's name.
*
* The requested decoder's index must be between zero and
* Mix_GetNumMusicDecoders()-1. It's safe to call this with an invalid index;
* this function will return NULL in that case.
*
* This list can change between builds AND runs of the program, if external
* libraries that add functionality become available. You must successfully
* call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
* as decoders are activated at device open time.
*
* \param index index of the music decoder.
* \returns the music decoder's name.
*
* \since This function is available since SDL_mixer 2.0.0.
*
* \sa Mix_GetNumMusicDecoders
*/
extern DECLSPEC const char * SDLCALL Mix_GetMusicDecoder(int index);
/**
* Check if a music decoder is available by name.
*
* This result can change between builds AND runs of the program, if external
* libraries that add functionality become available. You must successfully
* call Mix_OpenAudio() or Mix_OpenAudioDevice() before calling this function,
* as decoders are activated at device open time.
*
* Decoder names are arbitrary but also obvious, so you have to know what
* you're looking for ahead of time, but usually it's the file extension in
* capital letters (some example names are "MOD", "MP3", "FLAC").
*
* \param name the decoder name to query.
* \returns SDL_TRUE if a decoder by that name is available, SDL_FALSE
* otherwise.
*
* \since This function is available since SDL_mixer 2.6.0
*
* \sa Mix_GetNumMusicDecoders
* \sa Mix_GetMusicDecoder
*/
extern DECLSPEC SDL_bool SDLCALL Mix_HasMusicDecoder(const char *name);
/**
* Find out the format of a mixer music.
*
* If `music` is NULL, this will query the currently playing music (and return
* MUS_NONE if nothing is currently playing).
*
* \param music the music object to query, or NULL for the currently-playing
* music.
* \returns the Mix_MusicType for the music object.
*
* \since This function is available since SDL_mixer 2.0.0
*/
extern DECLSPEC Mix_MusicType SDLCALL Mix_GetMusicType(const Mix_Music *music);
/**
* Get the title for a music object, or its filename.
*
* This returns format-specific metadata. Not all file formats supply this!
*
* If `music` is NULL, this will query the currently-playing music.
*
* If music's title tag is missing or empty, the filename will be returned. If
* you'd rather have the actual metadata or nothing, use
* Mix_GetMusicTitleTag() instead.
*
* Please note that if the music was loaded from an SDL_RWops instead of a
* filename, the filename returned will be an empty string ("").
*
* This function never returns NULL! If no data is available, it will return
* an empty string ("").
*
* \param music the music object to query, or NULL for the currently-playing
* music.
* \returns the music's title if available, or the filename if not, or "".