14 #include <fc_config.h>
20 #include <SDL2/SDL_mixer.h>
41 #ifdef FREECIV_MSWINDOWS
47 static Mix_Music *
mus =
nullptr;
48 static std::array<sample, MIX_CHANNELS>
samples;
56 Mix_VolumeMusic(volume * MIX_MAX_VOLUME);
57 Mix_Volume(-1, volume * MIX_MAX_VOLUME);
72 Mix_Chunk *wave =
nullptr;
74 if (fullpath.isEmpty()) {
84 mus = Mix_LoadMUS(qUtf8Printable(fullpath));
86 qCritical(
"Can't open file \"%s\"", qUtf8Printable(fullpath));
91 Mix_PlayMusic(
mus, -1);
93 Mix_PlayMusic(
mus, 0);
94 Mix_HookMusicFinished(cb);
96 qDebug(
"Playing file \"%s\" on music channel", qUtf8Printable(fullpath));
105 log_debug(
"Playing file \"%s\" from cache",
106 qUtf8Printable(fullpath));
113 wave = Mix_LoadWAV(qUtf8Printable(fullpath));
114 if (wave ==
nullptr) {
115 qCritical(
"Can't open file \"%s\"", qUtf8Printable(fullpath));
121 int i = Mix_PlayChannel(-1, wave, 0);
123 qDebug(
"No available sound channel to play %s.", qUtf8Printable(tag));
127 qDebug(
"Playing file \"%s\" on channel %d", qUtf8Printable(fullpath), i);
131 Mix_FreeChunk(
samples[i].wave);
147 Mix_FadeOutMusic(2000);
157 while (Mix_Playing(-1) != 0) {
170 if (SDL_WasInit(SDL_INIT_VIDEO)) {
171 SDL_QuitSubSystem(SDL_INIT_AUDIO);
185 if (SDL_WasInit(SDL_INIT_VIDEO)) {
186 return SDL_InitSubSystem(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
188 return SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
203 for (i = 0; i < MIX_CHANNELS; i++) {
205 Mix_FreeChunk(
samples[i].wave);
209 if (
mus !=
nullptr) {
223 const int audio_rate = MIX_DEFAULT_FREQUENCY;
224 const int audio_format = MIX_DEFAULT_FORMAT;
225 const int audio_channels = 2;
232 if (Mix_OpenAudio(audio_rate, audio_format, audio_channels,
buf_size)
234 qCritical(
"Error calling Mix_OpenAudio");
240 Mix_AllocateChannels(MIX_CHANNELS);
241 for (i = 0; i < MIX_CHANNELS; i++) {
257 self.
name = QStringLiteral(
"sdl");
259 QStringLiteral(
"Simple DirectMedia Library (SDL) mixer plugin");
void audio_add_plugin(struct audio_plugin *p)
Add a plugin.
void(* audio_finished_callback)()
static void sdl_audio_wait()
Wait for audio to die on all channels.
static void sdl_audio_set_volume(double volume)
Set the volume.
static int init_sdl_audio()
Init SDL.
static void sdl_audio_stop()
Stop music.
static std::array< sample, MIX_CHANNELS > samples
static bool sdl_audio_init()
Initialize.
static double sdl_audio_get_volume()
Get the volume.
void audio_sdl_init()
Initialize.
static double sdl_audio_volume
static void sdl_audio_shutdown()
Clean up.
static void quit_sdl_audio()
Quit SDL.
static bool sdl_audio_play(const QString &tag, const QString &fullpath, bool repeat, audio_finished_callback cb)
Play sound.
static struct ai_type * self
#define log_debug(message,...)