20#ifdef SDL2_PLAIN_INCLUDE
25#include <SDL2/SDL_mixer.h>
45#ifdef FREECIV_MSWINDOWS
51static Mix_Music *
mus = NULL;
60 Mix_VolumeMusic(volume * MIX_MAX_VOLUME);
61 Mix_Volume(-1, volume * MIX_MAX_VOLUME);
80 Mix_Chunk *
wave = NULL;
92 mus = Mix_LoadMUS(fullpath);
94 log_error(
"Can't open file \"%s\"", fullpath);
98 Mix_PlayMusic(
mus, -1);
100 Mix_PlayMusic(
mus, 0);
101 Mix_HookMusicFinished(cb);
103 log_verbose(
"Playing file \"%s\" on music channel", fullpath);
110 for (j = 0; j < MIX_CHANNELS; j++) {
112 log_debug(
"Playing file \"%s\" from cache (slot %d)", fullpath, j);
119 wave = Mix_LoadWAV(fullpath);
121 log_error(
"Can't open file \"%s\"", fullpath);
126 i = Mix_PlayChannel(-1,
wave, 0);
132 log_verbose(
"Playing file \"%s\" on channel %d", fullpath, i);
153 Mix_FadeOutMusic(2000);
163 while (Mix_Playing(-1) != 0) {
176 if (SDL_WasInit(SDL_INIT_VIDEO)) {
177 SDL_QuitSubSystem(SDL_INIT_AUDIO);
191#if SDL_VERSION_ATLEAST(2, 0, 6)
192 SDL_SetHint(SDL_HINT_AUDIO_RESAMPLING_MODE,
"medium");
195 if (SDL_WasInit(SDL_INIT_VIDEO)) {
196 return SDL_InitSubSystem(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
198 return SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
215 for (i = 0; i < MIX_CHANNELS; i++) {
233 const int audio_rate = MIX_DEFAULT_FREQUENCY;
234 const int audio_format = MIX_DEFAULT_FORMAT;
235 const int audio_channels = 2;
242 if (Mix_OpenAudio(audio_rate, audio_format, audio_channels,
buf_size) < 0) {
243 log_error(
"Error calling Mix_OpenAudio");
250 Mix_AllocateChannels(MIX_CHANNELS);
251 for (i = 0; i < MIX_CHANNELS; i++) {
272 sz_strlcpy(
self.descr,
"Simple DirectMedia Library (SDL) mixer plugin");
void audio_add_plugin(struct audio_plugin *p)
void(* audio_finished_callback)(void)
static void sdl_audio_shutdown(struct audio_plugin *self)
void audio_sdl_init(void)
static void sdl_audio_wait(void)
static void quit_sdl_audio(void)
static void sdl_audio_set_volume(double volume)
static bool sdl_audio_play(const char *const tag, const char *const fullpath, bool repeat, audio_finished_callback cb)
static struct sample samples[MIX_CHANNELS]
static double sdl_audio_volume
static bool sdl_audio_init(struct audio_plugin *self)
static int init_sdl_audio(void)
static void sdl_audio_stop(void)
static double sdl_audio_get_volume(void)
static struct ai_type * self
#define log_verbose(message,...)
#define log_debug(message,...)
#define log_error(message,...)
#define sz_strlcpy(dest, src)