music.h
author Sam Lantinga <slouken@libsdl.org>
Tue, 17 Oct 2017 02:33:47 -0700
changeset 777 92882ef2ab81
child 788 db19b544ea54
permissions -rw-r--r--
Rewrote music.c to support any number of decode libraries using a compiled-in plugin interface
Mix_LoadWAV_RW() can now load sound formats that were previously available only as music.

This is still work in progress. Testing and project updates need to happen on other platforms.
     1 /*
     2   SDL_mixer:  An audio mixer library based on the SDL library
     3   Copyright (C) 1997-2017 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_SMPEG,
    41     MIX_MUSIC_FLAC,
    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 */
    74     int (*Play)(void *music);
    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 load_music(void);
   107 extern Mix_MusicType detect_music_type_from_magic(const Uint8 *magic);
   108 extern int get_num_music_interfaces();
   109 extern Mix_MusicInterface *get_music_interface(int index);
   110 extern SDL_bool has_music(Mix_MusicType type);
   111 extern int open_music(const SDL_AudioSpec *spec);
   112 extern void music_mixer(void *udata, Uint8 *stream, int len);
   113 extern void close_music(void);
   114 extern void unload_music(void);
   115 
   116 extern char *music_cmd;
   117 extern int volatile music_active;
   118 extern int music_loops;
   119 extern int music_volume;
   120 extern SDL_AudioSpec music_spec;
   121 extern char *soundfont_paths;
   122 
   123 #endif /* MUSIC_H_ */
   124 
   125 /* vi: set ts=4 sw=4 expandtab: */