diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-10-25 23:54:03 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-10-25 23:54:03 +0300 |
commit | 03378679c6e7b5833ddca59d9aacc22a22f7654c (patch) | |
tree | fd3849e22cc1a6fc3e8858a0e530122a94ddd281 /src | |
parent | c1090f81650347ef03a1d50783f8b77b02646f9e (diff) | |
download | plus-03378679c6e7b5833ddca59d9aacc22a22f7654c.tar.gz plus-03378679c6e7b5833ddca59d9aacc22a22f7654c.tar.bz2 plus-03378679c6e7b5833ddca59d9aacc22a22f7654c.tar.xz plus-03378679c6e7b5833ddca59d9aacc22a22f7654c.zip |
Add sdlmusichelper with some SDL/SDL2 functions.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/resources/loaders/musicloader.cpp | 11 | ||||
-rw-r--r-- | src/resources/soundeffect.cpp | 2 | ||||
-rw-r--r-- | src/soundmanager.cpp | 5 | ||||
-rw-r--r-- | src/utils/sdl2musichelper.cpp | 53 | ||||
-rw-r--r-- | src/utils/sdl2musichelper.h | 44 | ||||
-rw-r--r-- | src/utils/sdlmusichelper.cpp | 43 | ||||
-rw-r--r-- | src/utils/sdlmusichelper.h | 48 |
8 files changed, 200 insertions, 10 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 1f31e0f51..9674e0e2b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -644,10 +644,14 @@ BASE_SRC += client.h \ utils/sdl2helper.h \ utils/sdl2logger.cpp \ utils/sdl2logger.h \ + utils/sdl2musichelper.cpp \ + utils/sdl2musichelper.h \ utils/sdlcheckutils.cpp \ utils/sdlcheckutils.h \ utils/sdlhelper.cpp \ utils/sdlhelper.h \ + utils/sdlmusichelper.cpp \ + utils/sdlmusichelper.h \ utils/sdlmemoryobject.h \ fs/specialfolder.cpp \ fs/specialfolder.h \ diff --git a/src/resources/loaders/musicloader.cpp b/src/resources/loaders/musicloader.cpp index 7ac151c12..01fa55cc6 100644 --- a/src/resources/loaders/musicloader.cpp +++ b/src/resources/loaders/musicloader.cpp @@ -29,6 +29,7 @@ #include "resources/resourcemanager/resourcemanager.h" #include "utils/checkutils.h" +#include "utils/sdlmusichelper.h" #include "debug.h" @@ -53,19 +54,15 @@ namespace rl->path.c_str()); return nullptr; } -#ifdef USE_SDL2 - if (Mix_Music *const music = Mix_LoadMUSType_RW(rw, MUS_OGG, 1)) + if (Mix_Music *const music = SDL::LoadMUSOgg_RW(rw)) { +#ifdef USE_SDL2 return new SDLMusic(music, nullptr, rl->path); - } #else // USE_SDL2 - // Mix_LoadMUSType_RW was added without version changed in SDL1.2 :( - if (Mix_Music *const music = Mix_LoadMUS_RW(rw)) - { return new SDLMusic(music, rw, rl->path); - } #endif // USE_SDL2 + } logger->log("Error, failed to load music: %s", SDL_GetError()); return nullptr; diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index db7c5d462..55a48abd0 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -34,7 +34,7 @@ bool SoundEffect::play(const int loops, const int volume, { Mix_VolumeChunk(mChunk, volume); - return Mix_PlayChannel(channel, mChunk, loops) != -1; + return Mix_PlayChannelTimed(channel, mChunk, loops, -1) != -1; } int SoundEffect::calcMemoryLocal() const diff --git a/src/soundmanager.cpp b/src/soundmanager.cpp index d08b58c1f..5a9ddb333 100644 --- a/src/soundmanager.cpp +++ b/src/soundmanager.cpp @@ -42,6 +42,7 @@ #include "utils/cast.h" #endif #include "utils/checkutils.h" +#include "utils/sdlmusichelper.h" PRAGMA48(GCC diagnostic push) PRAGMA48(GCC diagnostic ignored "-Wshadow") @@ -168,14 +169,14 @@ void SoundManager::init() break; } - const int res = Mix_OpenAudio(config.getIntValue("audioFrequency"), + const int res = SDL::MixOpenAudio(config.getIntValue("audioFrequency"), MIX_DEFAULT_FORMAT, channels, audioBuffer); if (res < 0) { logger->log("SoundManager::init Could not initialize audio: %s", SDL_GetError()); - if (Mix_OpenAudio(22010, MIX_DEFAULT_FORMAT, 2, audioBuffer) < 0) + if (SDL::MixOpenAudio(22010, MIX_DEFAULT_FORMAT, 2, audioBuffer) < 0) return; logger->log("Fallback to stereo audio"); } diff --git a/src/utils/sdl2musichelper.cpp b/src/utils/sdl2musichelper.cpp new file mode 100644 index 000000000..300f79991 --- /dev/null +++ b/src/utils/sdl2musichelper.cpp @@ -0,0 +1,53 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013-2017 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifdef USE_SDL2 + +#include "utils/sdl2musichelper.h" + +#include "debug.h" + +int SDL::MixOpenAudio(const int frequency, + const uint16_t format, + const int nchannels, + const int chunksize) +{ +#if SDL_MIXER_VERSION_ATLEAST(2, 0, 2) + return Mix_OpenAudioDevice(frequency, + format, + nchannels, + chunksize, + nullptr, + SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_CHANNELS_CHANGE); +#else // SDL_MIXER_VERSION_ATLEAST(2, 0, 2) + + return Mix_OpenAudio(frequency, + format, + nchannels, + chunksize); +#endif // SDL_MIXER_VERSION_ATLEAST(2, 0, 2) +} + +Mix_Music *SDL::LoadMUSOgg_RW(SDL_RWops *const rw) +{ + return Mix_LoadMUSType_RW(rw, MUS_OGG, 1); +} + +#endif // USE_SDL2 diff --git a/src/utils/sdl2musichelper.h b/src/utils/sdl2musichelper.h new file mode 100644 index 000000000..6c9207563 --- /dev/null +++ b/src/utils/sdl2musichelper.h @@ -0,0 +1,44 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013-2017 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef UTILS_SDL2MUSICHELPER_H +#define UTILS_SDL2MUSICHELPER_H + +#ifdef USE_SDL2 + +#include "localconsts.h" + +PRAGMA48(GCC diagnostic push) +PRAGMA48(GCC diagnostic ignored "-Wshadow") +#include <SDL_mixer.h> +PRAGMA48(GCC diagnostic pop) + +namespace SDL +{ + int MixOpenAudio(const int frequency, + const uint16_t format, + const int nchannels, + const int chunksize); + + Mix_Music *LoadMUSOgg_RW(SDL_RWops *const rw); +} // namespace SDL + +#endif // USE_SDL2 +#endif // UTILS_SDL2MUSICHELPER_H diff --git a/src/utils/sdlmusichelper.cpp b/src/utils/sdlmusichelper.cpp new file mode 100644 index 000000000..2987f9533 --- /dev/null +++ b/src/utils/sdlmusichelper.cpp @@ -0,0 +1,43 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013-2017 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef USE_SDL2 + +#include "utils/sdlmusichelper.h" + +#include "debug.h" + +int SDL::MixOpenAudio(const int frequency, + const uint16_t format, + const int nchannels, + const int chunksize) +{ + return Mix_OpenAudio(frequency, + format, + nchannels, + chunksize); +} + +Mix_Music *SDL::LoadMUSOgg_RW(SDL_RWops *const rw) +{ + return Mix_LoadMUS_RW(rw); +} + +#endif // USE_SDL2 diff --git a/src/utils/sdlmusichelper.h b/src/utils/sdlmusichelper.h new file mode 100644 index 000000000..b07aa9a10 --- /dev/null +++ b/src/utils/sdlmusichelper.h @@ -0,0 +1,48 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013-2017 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef UTILS_SDLMUSICHELPER_H +#define UTILS_SDLMUSICHELPER_H + +#ifdef USE_SDL2 +#include "utils/sdl2musichelper.h" +UTILS_SDL2MUSICHELPER_H + +#else + +#include "localconsts.h" + +PRAGMA48(GCC diagnostic push) +PRAGMA48(GCC diagnostic ignored "-Wshadow") +#include <SDL_mixer.h> +PRAGMA48(GCC diagnostic pop) + +namespace SDL +{ + int MixOpenAudio(const int frequency, + const uint16_t format, + const int nchannels, + const int chunksize); + + Mix_Music *LoadMUSOgg_RW(SDL_RWops *const rw); +} // namespace SDL + +#endif // USE_SDL2 +#endif // UTILS_SDLMUSICHELPER_H |