music.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 21 Oct 2017 02:10:33 -0700
changeset 801 46acd70caa6a
parent 797 b4b6adff699a
child 817 aef7a1784ffd
permissions -rw-r--r--
Fixed FluidSynth support and added a default soundfont path on Linux
slouken@777
     1
/*
slouken@777
     2
  SDL_mixer:  An audio mixer library based on the SDL library
slouken@777
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@777
     4
slouken@777
     5
  This software is provided 'as-is', without any express or implied
slouken@777
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@777
     7
  arising from the use of this software.
slouken@777
     8
slouken@777
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@777
    10
  including commercial applications, and to alter it and redistribute it
slouken@777
    11
  freely, subject to the following restrictions:
slouken@777
    12
slouken@777
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@777
    14
     claim that you wrote the original software. If you use this software
slouken@777
    15
     in a product, an acknowledgment in the product documentation would be
slouken@777
    16
     appreciated but is not required.
slouken@777
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@777
    18
     misrepresented as being the original software.
slouken@777
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@777
    20
*/
slouken@777
    21
#include "SDL_mixer.h"
slouken@777
    22
slouken@777
    23
#ifndef MUSIC_H_
slouken@777
    24
#define MUSIC_H_
slouken@777
    25
slouken@777
    26
/* Supported music APIs, in order of preference */
slouken@777
    27
slouken@777
    28
typedef enum
slouken@777
    29
{
slouken@777
    30
    MIX_MUSIC_CMD,
slouken@777
    31
    MIX_MUSIC_WAVE,
slouken@777
    32
    MIX_MUSIC_MODPLUG,
slouken@777
    33
    MIX_MUSIC_MIKMOD,
slouken@777
    34
    MIX_MUSIC_FLUIDSYNTH,
slouken@777
    35
    MIX_MUSIC_TIMIDITY,
slouken@777
    36
    MIX_MUSIC_NATIVEMIDI,
slouken@777
    37
    MIX_MUSIC_OGG,
slouken@777
    38
    MIX_MUSIC_MPG123,
slouken@777
    39
    MIX_MUSIC_MAD,
slouken@777
    40
    MIX_MUSIC_SMPEG,
slouken@777
    41
    MIX_MUSIC_FLAC,
slouken@777
    42
    MIX_MUSIC_LAST
slouken@777
    43
} Mix_MusicAPI;
slouken@777
    44
slouken@777
    45
slouken@777
    46
/* Music API implementation */
slouken@777
    47
slouken@777
    48
typedef struct
slouken@777
    49
{
slouken@777
    50
    const char *tag;
slouken@777
    51
    Mix_MusicAPI api;
slouken@777
    52
    Mix_MusicType type;
slouken@777
    53
    SDL_bool loaded;
slouken@777
    54
    SDL_bool opened;
slouken@777
    55
slouken@777
    56
    /* Load the library */
slouken@777
    57
    int (*Load)(void);
slouken@777
    58
slouken@777
    59
    /* Initialize for the audio output */
slouken@777
    60
    int (*Open)(const SDL_AudioSpec *spec);
slouken@777
    61
slouken@777
    62
    /* Create a music object from an SDL_RWops stream
slouken@777
    63
     * If the function returns NULL, 'src' will be freed if needed by the caller.
slouken@777
    64
     */
slouken@777
    65
    void *(*CreateFromRW)(SDL_RWops *src, int freesrc);
slouken@777
    66
slouken@777
    67
    /* Create a music object from a file, if SDL_RWops are not supported */
slouken@777
    68
    void *(*CreateFromFile)(const char *file);
slouken@777
    69
slouken@777
    70
    /* Set the volume */
slouken@777
    71
    void (*SetVolume)(void *music, int volume);
slouken@777
    72
slouken@797
    73
    /* Start playing music from the beginning with an optional loop count */
slouken@797
    74
    int (*Play)(void *music, int play_count);
slouken@777
    75
slouken@777
    76
    /* Returns SDL_TRUE if music is still playing */
slouken@777
    77
    SDL_bool (*IsPlaying)(void *music);
slouken@777
    78
slouken@777
    79
    /* Get music data, returns the number of bytes left */
slouken@777
    80
    int (*GetAudio)(void *music, void *data, int bytes);
slouken@777
    81
slouken@777
    82
    /* Seek to a play position (in seconds) */
slouken@777
    83
    int (*Seek)(void *music, double position);
slouken@777
    84
slouken@777
    85
    /* Pause playing music */
slouken@777
    86
    void (*Pause)(void *music);
slouken@777
    87
slouken@777
    88
    /* Resume playing music */
slouken@777
    89
    void (*Resume)(void *music);
slouken@777
    90
slouken@777
    91
    /* Stop playing music */
slouken@777
    92
    void (*Stop)(void *music);
slouken@777
    93
slouken@777
    94
    /* Delete a music object */
slouken@777
    95
    void (*Delete)(void *music);
slouken@777
    96
slouken@777
    97
    /* Close the library and clean up */
slouken@777
    98
    void (*Close)(void);
slouken@777
    99
slouken@777
   100
    /* Unload the library */
slouken@777
   101
    void (*Unload)(void);
slouken@777
   102
slouken@777
   103
} Mix_MusicInterface;
slouken@777
   104
slouken@777
   105
slouken@777
   106
extern int load_music(void);
slouken@777
   107
extern Mix_MusicType detect_music_type_from_magic(const Uint8 *magic);
slouken@788
   108
extern int get_num_music_interfaces(void);
slouken@777
   109
extern Mix_MusicInterface *get_music_interface(int index);
slouken@777
   110
extern SDL_bool has_music(Mix_MusicType type);
slouken@777
   111
extern int open_music(const SDL_AudioSpec *spec);
slouken@797
   112
extern int music_pcm_getaudio(void *context, void *data, int bytes, int volume,
slouken@797
   113
                              int (*GetSome)(void *context, void *data, int bytes, SDL_bool *done));
slouken@777
   114
extern void music_mixer(void *udata, Uint8 *stream, int len);
slouken@777
   115
extern void close_music(void);
slouken@777
   116
extern void unload_music(void);
slouken@777
   117
slouken@777
   118
extern char *music_cmd;
slouken@777
   119
extern SDL_AudioSpec music_spec;
slouken@777
   120
slouken@777
   121
#endif /* MUSIC_H_ */
slouken@777
   122
slouken@777
   123
/* vi: set ts=4 sw=4 expandtab: */