1 /*
2   SDL_mixer:  An audio mixer library based on the SDL library
3   Copyright (C) 1997-2018 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 #include "SDL_mixer.h"
22 
23 #ifndef MUSIC_H_
24 #define MUSIC_H_
25 
26 /* Supported music APIs, in order of preference */
27 
28 typedef enum
29 {
30     MIX_MUSIC_CMD,
31     MIX_MUSIC_WAVE,
32     MIX_MUSIC_MODPLUG,
33     MIX_MUSIC_MIKMOD,
34     MIX_MUSIC_FLUIDSYNTH,
35     MIX_MUSIC_TIMIDITY,
36     MIX_MUSIC_NATIVEMIDI,
37     MIX_MUSIC_OGG,
38     MIX_MUSIC_MPG123,
39     MIX_MUSIC_MAD,
40     MIX_MUSIC_FLAC,
41     MIX_MUSIC_OPUS,
42     MIX_MUSIC_LAST
43 } Mix_MusicAPI;
44 
45 
46 /* Music API implementation */
47 
48 typedef struct
49 {
50     const char *tag;
51     Mix_MusicAPI api;
52     Mix_MusicType type;
53     SDL_bool loaded;
54     SDL_bool opened;
55 
56     /* Load the library */
57     int (*Load)(void);
58 
59     /* Initialize for the audio output */
60     int (*Open)(const SDL_AudioSpec *spec);
61 
62     /* Create a music object from an SDL_RWops stream
63      * If the function returns NULL, 'src' will be freed if needed by the caller.
64      */
65     void *(*CreateFromRW)(SDL_RWops *src, int freesrc);
66 
67     /* Create a music object from a file, if SDL_RWops are not supported */
68     void *(*CreateFromFile)(const char *file);
69 
70     /* Set the volume */
71     void (*SetVolume)(void *music, int volume);
72 
73     /* Start playing music from the beginning with an optional loop count */
74     int (*Play)(void *music, int play_count);
75 
76     /* Returns SDL_TRUE if music is still playing */
77     SDL_bool (*IsPlaying)(void *music);
78 
79     /* Get music data, returns the number of bytes left */
80     int (*GetAudio)(void *music, void *data, int bytes);
81 
82     /* Seek to a play position (in seconds) */
83     int (*Seek)(void *music, double position);
84 
85     /* Pause playing music */
86     void (*Pause)(void *music);
87 
88     /* Resume playing music */
89     void (*Resume)(void *music);
90 
91     /* Stop playing music */
92     void (*Stop)(void *music);
93 
94     /* Delete a music object */
95     void (*Delete)(void *music);
96 
97     /* Close the library and clean up */
98     void (*Close)(void);
99 
100     /* Unload the library */
101     void (*Unload)(void);
102 
103 } Mix_MusicInterface;
104 
105 
106 extern int get_num_music_interfaces(void);
107 extern Mix_MusicInterface *get_music_interface(int index);
108 extern Mix_MusicType detect_music_type_from_magic(const Uint8 *magic);
109 extern SDL_bool load_music_type(Mix_MusicType type);
110 extern SDL_bool open_music_type(Mix_MusicType type);
111 extern SDL_bool has_music(Mix_MusicType type);
112 extern void open_music(const SDL_AudioSpec *spec);
113 extern int music_pcm_getaudio(void *context, void *data, int bytes, int volume,
114                               int (*GetSome)(void *context, void *data, int bytes, SDL_bool *done));
115 extern void SDLCALL music_mixer(void *udata, Uint8 *stream, int len);
116 extern void close_music(void);
117 extern void unload_music(void);
118 
119 extern char *music_cmd;
120 extern SDL_AudioSpec music_spec;
121 
122 #endif /* MUSIC_H_ */
123 
124 /* vi: set ts=4 sw=4 expandtab: */
125