Merge all of the audio provider switches into one

There's no point in splitting the audio library selection into multiple
CPP macros, since there can always only be one anyway. Merge all of them
into a single macro AUDIO_TK (for "toolkit") and have CMake select one
for the user, instead of making him choose (and potentially failing).
issue1247
Nicolas Hake 2014-08-01 21:05:55 +02:00
parent 474b6e1c31
commit 642ce2eb9c
12 changed files with 238 additions and 162 deletions

View File

@ -48,12 +48,6 @@ CMAKE_DEPENDENT_OPTION(USE_GTK "Use GTK for the developer mode" ON "USE_X11" OFF
CMAKE_DEPENDENT_OPTION(USE_GTK3 "Use GTK3 instead of GTK2" OFF "USE_GTK" OFF) CMAKE_DEPENDENT_OPTION(USE_GTK3 "Use GTK3 instead of GTK2" OFF "USE_GTK" OFF)
CMAKE_DEPENDENT_OPTION(USE_COCOA "Use Apple Cocoa for the developer mode and the windows." ON "APPLE" OFF) CMAKE_DEPENDENT_OPTION(USE_COCOA "Use Apple Cocoa for the developer mode and the windows." ON "APPLE" OFF)
if(APPLE)
SET(INITIAL_USE_OPEN_AL ON)
else()
SET(INITIAL_USE_OPEN_AL OFF)
endif()
option(USE_OPEN_AL "Use OpenAL to play sounds" ${INITIAL_USE_OPEN_AL})
option(WITH_AUTOMATIC_UPDATE "Automatic updates are downloaded from the project website." OFF) option(WITH_AUTOMATIC_UPDATE "Automatic updates are downloaded from the project website." OFF)
# We link Boost statically because that makes it easier for us to distribute # We link Boost statically because that makes it easier for us to distribute
@ -867,21 +861,8 @@ if(MAPE_GTK_FOUND)
link_directories(${MAPE_GTK_LIBRARY_DIRS}) link_directories(${MAPE_GTK_LIBRARY_DIRS})
endif() endif()
if(USE_OPEN_AL) # Select an audio library
if(MSVC) find_package("Audio")
if(${FIND_LIBRARY_USE_LIB64_PATHS})
FINDLIB(OPENAL_LIBRARY NAMES OpenAL64)
else()
FINDLIB(OPENAL_LIBRARY NAMES OpenAL32)
endif()
endif()
FINDLIB(OGG_LIBRARY NAMES libogg_static libogg ogg)
FINDLIB(VORBIS_LIBRARY NAMES libvorbis_static libvorbis vorbis)
FINDLIB(VORBISFILE_LIBRARY NAMES libvorbisfile_static libvorbisfile vorbisfile)
if(NOT APPLE)
FINDLIB(ALUT_LIBRARY NAMES alut_static alut)
endif()
endif()
############################################################################ ############################################################################
# Precompiled header support, part 1 (pre-target) # Precompiled header support, part 1 (pre-target)
@ -1061,14 +1042,9 @@ target_link_libraries(openclonk
libmisc libmisc
) )
if(USE_OPEN_AL) if(Audio_FOUND)
target_link_libraries(openclonk target_link_libraries(openclonk ${Audio_LIBRARIES})
${OPENAL_LIBRARY} include_directories(${Audio_INCLUDE_DIRS})
${ALUT_LIBRARY}
${VORBIS_LIBRARY}
${VORBISFILE_LIBRARY}
${OGG_LIBRARY}
)
endif() endif()
if(MAPE_GTK_FOUND) if(MAPE_GTK_FOUND)
@ -1320,7 +1296,7 @@ if(USE_X11)
) )
endif() endif()
if(USE_COCOA) if(USE_COCOA)
TARGET_LINK_LIBRARIES(openclonk "-framework Cocoa -framework AppKit -framework Quartz -framework OpenAL -framework AudioToolBox") TARGET_LINK_LIBRARIES(openclonk "-framework Cocoa -framework AppKit -framework Quartz")
endif() endif()
if (WIN32) if (WIN32)
# CMake is too incompetent to check whether these libraries can be linked to # CMake is too incompetent to check whether these libraries can be linked to
@ -1342,36 +1318,6 @@ if (WIN32)
if(MAPE_GTK_FOUND) if(MAPE_GTK_FOUND)
target_link_libraries(mape winmm) target_link_libraries(mape winmm)
endif() endif()
if(NOT USE_OPEN_AL)
find_package(FMod)
if(FMOD_FOUND)
set(HAVE_FMOD TRUE)
target_link_libraries(openclonk
${FMOD_LIBRARIES}
)
include_directories(${FMOD_INCLUDE_DIR})
else()
set(HAVE_FMOD FALSE)
endif()
endif()
else()
SET(HAVE_FMOD FALSE)
endif()
if(NOT HAVE_FMOD AND NOT USE_OPEN_AL OR USE_SDL_MAINLOOP AND NOT USE_OPEN_AL)
include(FindSDL)
SET(HAVE_SDL ${SDL_FOUND})
if(SDL_FOUND)
include_directories(${SDL_INCLUDE_DIR})
FINDLIB(SDLMIXER_LIBRARIES SDL_mixer)
if(SDLMIXER_LIBRARIES)
SET(HAVE_LIBSDL_MIXER ON)
endif()
target_link_libraries(openclonk
${SDL_LIBRARY}
${SDLMIXER_LIBRARIES}
)
endif()
endif() endif()
if(HAVE_UPNP) if(HAVE_UPNP)

View File

@ -0,0 +1,143 @@
# OpenClonk, http://www.openclonk.org
#
# Copyright (c) 2009-2014, The OpenClonk Team and contributors
#
# Distributed under the terms of the ISC license; see accompanying file
# "COPYING" for details.
#
# "Clonk" is a registered trademark of Matthes Bender, used with permission.
# See accompanying file "TRADEMARK" for details.
#
# To redistribute this file separately, substitute the full license texts
# for the above references.
# This module chooses an audio provider for use in OpenClonk.
macro(__FINDAUDIO_FINDOPENAL)
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(OpenAL "openal>=1.15.1")
pkg_check_modules(Alut "freealut>=1.1.0")
pkg_check_modules(OggVorbis "vorbisfile>=1.3.2" "vorbis>=1.3.2" "ogg>=1.3.0")
else()
if(MSVC OR APPLE)
find_path(OpenAL_INCLUDE_DIRS al.h PATH_SUFFIXES include/AL include/OpenAL include)
find_path(Vorbis_INCLUDE_DIRS vorbis/codec.h vorbis/vorbisfile.h PATH_SUFFIXES include)
find_library(Ogg_LIBRARY NAMES libogg_static libogg ogg)
find_library(Vorbis_LIBRARY NAMES libvorbis_static libvorbis vorbis)
find_library(Vorbisfile_LIBRARY NAMES libvorbisfile_static libvorbisfile vorbisfile)
if(OpenAL_INCLUDE_DIRS)
set(OpenAL_FOUND TRUE)
endif()
if(Vorbis_INCLUDE_DIRS AND Ogg_LIBRARY AND Vorbis_LIBRARY AND Vorbisfile_LIBRARY)
set(OggVorbis_FOUND TRUE)
set(OggVorbis_LIBRARIES ${Vorbisfile_LIBRARY} ${Vorbis_LIBRARY} ${Ogg_LIBRARY})
set(OggVorbis_INCLUDE_DIRS(${Vorbis_INCLUDE_DIRS}))
endif()
endif()
if(MSVC)
find_path(Alut_INCLUDE_DIRS alut.h PATH_SUFFIXES include/AL include/OpenAL include)
find_library(Alut_LIBRARY NAMES alut_static alut)
if(${FIND_LIBRARY_USE_LIB64_PATHS})
find_library(OpenAL_LIBRARY NAMES OpenAL64)
else()
find_library(OpenAL_LIBRARY NAMES OpenAL32)
endif()
if(NOT OpenAL_LIBRARY)
set(OpenAL_FOUND FALSE)
endif()
if(Alut_INCLUDE_DIRS AND Alut_LIBRARY)
set(Alut_FOUND TRUE)
set(Alut_LIBRARIES ${Alut_LIBRARY})
endif()
endif()
endif()
endmacro()
macro(__FINDAUDIO_FINDSDLMIXER)
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(SDLMixer "SDL_mixer>=1.2.12")
endif()
endmacro()
if(Audio_TK)
# Already chosen, don't do anything
elseif(USE_CONSOLE)
# Dedicated servers don't need audio output
set(Audio_TK "none")
set(Audio_FOUND TRUE)
else()
# Test for OpenAL
__FINDAUDIO_FINDOPENAL()
__FINDAUDIO_FINDSDLMIXER()
find_package("FMod")
if(OpenAL_FOUND AND (APPLE OR Alut_FOUND) AND OggVorbis_FOUND)
# Prefer OpenAL
set(Audio_TK "OpenAL")
elseif(SDLMixer_FOUND)
set(Audio_TK "SDL_Mixer")
elseif(FMOD_FOUND)
set(Audio_TK "FMod")
endif()
endif()
# Search for the libraries again. If the provider was selected automatically, this will be
# answered from cache; otherwise (because the user manually selected a provider) it will
# make sure the provider is available.
if(Audio_TK STREQUAL "OpenAL")
__FINDAUDIO_FINDOPENAL()
if(OpenAL_FOUND AND (APPLE OR Alut_FOUND) AND OggVorbis_FOUND)
set(Audio_FOUND TRUE)
set(Audio_LIBRARIES ${OpenAL_LIBRARIES} ${OggVorbis_LIBRARIES})
set(Audio_INCLUDE_DIRS ${OpenAL_INCLUDE_DIRS} ${OggVorbis_INCLUDE_DIRS})
if (NOT APPLE)
# Apple doesn't need freealut
set(Audio_LIBRARIES ${Audio_LIBRARIES} ${Alut_LIBRARIES})
set(Audio_INCLUDE_DIRS ${Audio_INCLUDE_DIRS} ${Alut_INCLUDE_DIRS})
else()
# but it uses the AudioToolBox framework
set(Audio_LIBRARIES ${Audio_LIBRARIES} "-framework OpenAL -framework AudioToolBox")
endif()
endif()
elseif(Audio_TK STREQUAL "SDL_Mixer")
__FINDAUDIO_FINDSDLMIXER()
if(SDLMixer_FOUND)
set(Audio_FOUND TRUE)
set(Audio_LIBRARIES ${SDLMixer_LIBRARIES})
set(Audio_INCLUDE_DIRS ${SDLMixer_INCLUDE_DIRS})
endif()
elseif(Audio_TK STREQUAL "FMod")
find_package("FMod")
if(FMOD_FOUND)
set(Audio_FOUND TRUE)
set(Audio_LIBRARIES ${FMOD_LIBRARIES})
set(Audio_INCLUDE_DIRS ${FMOD_INCLUDE_DIR})
endif()
elseif(Audio_TK STREQUAL "none")
set(Audio_FOUND TRUE)
set(Audio_LIBRARIES "")
set(Audio_INCLUDE_DIRS "")
endif()
if(Audio_FOUND)
string(TOUPPER "${Audio_TK}" Audio_TK_UPPER)
if(NOT Audio_FIND_QUIETLY)
message(STATUS "Using Audio toolkit: ${Audio_TK}")
endif()
elseif(Audio_TK)
message(FATAL_ERROR "User-requested audio provider not available.")
else()
set(Audio_FOUND FALSE)
set(Audio_TK "none")
string(TOUPPER "${Audio_TK}" Audio_TK_UPPER)
set(Audio_LIBRARIES "")
set(Audio_INCLUDE_DIRS "")
if(Audio_FIND_REQUIRED)
message(FATAL_ERROR "No audio provider was found")
else()
message(STATUS "Not enabling audio output.")
endif()
endif()

View File

@ -7,9 +7,6 @@
/* The backtrace function is declared in execinfo.h and works */ /* The backtrace function is declared in execinfo.h and works */
#cmakedefine HAVE_EXECINFO_H 1 #cmakedefine HAVE_EXECINFO_H 1
/* Whether FMOD shall be used */
#cmakedefine HAVE_FMOD 1
/* Define to 1 if you have the <history.h> header file. */ /* Define to 1 if you have the <history.h> header file. */
#cmakedefine HAVE_HISTORY_H 1 #cmakedefine HAVE_HISTORY_H 1
@ -28,9 +25,6 @@
/* Define if you have a readline compatible library */ /* Define if you have a readline compatible library */
#cmakedefine HAVE_LIBREADLINE 1 #cmakedefine HAVE_LIBREADLINE 1
/* Define to 1 if you have SDL_mixer. */
#cmakedefine HAVE_LIBSDL_MIXER 1
/* Define to 1 if you have the <locale.h> header file. */ /* Define to 1 if you have the <locale.h> header file. */
#cmakedefine HAVE_LOCALE_H 1 #cmakedefine HAVE_LOCALE_H 1
@ -160,9 +154,6 @@
/* MP3 music */ /* MP3 music */
#cmakedefine USE_MP3 1 #cmakedefine USE_MP3 1
/* OpenAL sound */
#cmakedefine USE_OPEN_AL 1
/* Define to 1 if SDL is used for the main loop */ /* Define to 1 if SDL is used for the main loop */
#cmakedefine USE_SDL_MAINLOOP 1 #cmakedefine USE_SDL_MAINLOOP 1
@ -192,3 +183,10 @@
/* Use Apple Cocoa for the UI */ /* Use Apple Cocoa for the UI */
#cmakedefine USE_COCOA 1 #cmakedefine USE_COCOA 1
/* Select an audio provider */
#define AUDIO_TK_NONE 0
#define AUDIO_TK_OPENAL 1
#define AUDIO_TK_FMOD 2
#define AUDIO_TK_SDL_MIXER 3
#define AUDIO_TK AUDIO_TK_${Audio_TK_UPPER}

View File

@ -38,7 +38,7 @@ C4StartupAboutDlg::C4StartupAboutDlg() : C4StartupDlg(LoadResStr("IDS_DLG_ABOUT"
C4GUI::ComponentAligner caMain(rcClient, 0,0, true); C4GUI::ComponentAligner caMain(rcClient, 0,0, true);
C4GUI::ComponentAligner caButtons(caMain.GetFromBottom(caMain.GetHeight()*1/8), 0,0, false); C4GUI::ComponentAligner caButtons(caMain.GetFromBottom(caMain.GetHeight()*1/8), 0,0, false);
C4GUI::CallbackButton<C4StartupAboutDlg> *btn; C4GUI::CallbackButton<C4StartupAboutDlg> *btn;
#ifdef HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
AddElement(new C4GUI::Label("Using FMOD Sound System, copyright (c) Firelight Technologies Pty, Ltd., 1994-2010.", AddElement(new C4GUI::Label("Using FMOD Sound System, copyright (c) Firelight Technologies Pty, Ltd., 1994-2010.",
caMain.GetFromBottom(rUseFont.GetLineHeight()))); caMain.GetFromBottom(rUseFont.GetLineHeight())));
#endif #endif

View File

@ -21,7 +21,7 @@
#include <C4Application.h> #include <C4Application.h>
#include <C4Log.h> #include <C4Log.h>
#ifdef HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
#include <fmod_errors.h> #include <fmod_errors.h>
#endif #endif
@ -53,7 +53,7 @@ bool C4MusicFile::Init(const char *szFile)
return true; return true;
} }
#if defined HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
bool C4MusicFileMID::Play(bool loop) bool C4MusicFileMID::Play(bool loop)
{ {
// check existance // check existance
@ -292,7 +292,7 @@ void C4MusicFileOgg::SetVolume(int iLevel)
FSOUND_SetVolume(Channel, (int) ((iLevel * 255) / 100)); FSOUND_SetVolume(Channel, (int) ((iLevel * 255) / 100));
} }
#elif defined HAVE_LIBSDL_MIXER #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
C4MusicFileSDL::C4MusicFileSDL(): C4MusicFileSDL::C4MusicFileSDL():
Data(NULL), Data(NULL),
Music(NULL) Music(NULL)

View File

@ -18,9 +18,9 @@
#ifndef INC_C4MusicFile #ifndef INC_C4MusicFile
#define INC_C4MusicFile #define INC_C4MusicFile
#if defined HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
#include <fmod.h> #include <fmod.h>
#elif defined HAVE_LIBSDL_MIXER #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
#define USE_RWOPS #define USE_RWOPS
#include <SDL_mixer.h> #include <SDL_mixer.h>
#undef USE_RWOPS #undef USE_RWOPS
@ -55,7 +55,7 @@ protected:
bool SongExtracted; bool SongExtracted;
}; };
#if defined HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
class C4MusicFileMID : public C4MusicFile class C4MusicFileMID : public C4MusicFile
{ {
public: public:
@ -123,7 +123,7 @@ protected:
bool Playing; bool Playing;
}; };
#elif defined HAVE_LIBSDL_MIXER #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
typedef struct _Mix_Music Mix_Music; typedef struct _Mix_Music Mix_Music;
class C4MusicFileSDL : public C4MusicFile class C4MusicFileSDL : public C4MusicFile
{ {
@ -138,6 +138,6 @@ protected:
char *Data; char *Data;
Mix_Music * Music; Mix_Music * Music;
}; };
#endif // HAVE_LIBSDL_MIXER #endif
#endif #endif

View File

@ -28,14 +28,17 @@
#include <C4Game.h> #include <C4Game.h>
#include <C4GraphicsSystem.h> #include <C4GraphicsSystem.h>
#if defined HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
#include <fmod_errors.h> #include <fmod_errors.h>
#elif defined HAVE_LIBSDL_MIXER #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
#include <SDL.h> #include <SDL.h>
#elif AUDIO_TK == AUDIO_TK_OPENAL && !defined(APPLE)
#ifdef _WIN32
// This is an ugly hack to make FreeALUT not dllimport everything.
#define _XBOX
#endif #endif
#include <alut.h>
#if defined(USE_OPEN_AL) && !defined(__APPLE__) #undef _XBOX
#include <AL/alut.h>
#endif #endif
C4MusicSystem::C4MusicSystem(): C4MusicSystem::C4MusicSystem():
@ -43,7 +46,7 @@ C4MusicSystem::C4MusicSystem():
SongCount(0), SongCount(0),
PlayMusicFile(NULL), PlayMusicFile(NULL),
Volume(100) Volume(100)
#ifdef USE_OPEN_AL #if AUDIO_TK == AUDIO_TK_OPENAL
, alcDevice(NULL), alcContext(NULL) , alcDevice(NULL), alcContext(NULL)
#endif #endif
{ {
@ -54,7 +57,7 @@ C4MusicSystem::~C4MusicSystem()
Clear(); Clear();
} }
#ifdef USE_OPEN_AL #if AUDIO_TK == AUDIO_TK_OPENAL
void C4MusicSystem::SelectContext() void C4MusicSystem::SelectContext()
{ {
alcMakeContextCurrent(alcContext); alcMakeContextCurrent(alcContext);
@ -63,7 +66,7 @@ void C4MusicSystem::SelectContext()
bool C4MusicSystem::InitializeMOD() bool C4MusicSystem::InitializeMOD()
{ {
#if defined HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
#ifdef _WIN32 #ifdef _WIN32
// Debug code // Debug code
switch (Config.Sound.FMMode) switch (Config.Sound.FMMode)
@ -97,7 +100,7 @@ bool C4MusicSystem::InitializeMOD()
// ok // ok
MODInitialized = true; MODInitialized = true;
return true; return true;
#elif defined HAVE_LIBSDL_MIXER #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
SDL_version compile_version; SDL_version compile_version;
const SDL_version * link_version; const SDL_version * link_version;
MIX_VERSION(&compile_version); MIX_VERSION(&compile_version);
@ -118,7 +121,7 @@ bool C4MusicSystem::InitializeMOD()
} }
MODInitialized = true; MODInitialized = true;
return true; return true;
#elif defined(USE_OPEN_AL) #elif AUDIO_TK == AUDIO_TK_OPENAL
alcDevice = alcOpenDevice(NULL); alcDevice = alcOpenDevice(NULL);
if (!alcDevice) if (!alcDevice)
{ {
@ -146,16 +149,16 @@ bool C4MusicSystem::InitializeMOD()
void C4MusicSystem::DeinitializeMOD() void C4MusicSystem::DeinitializeMOD()
{ {
#if defined HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
FSOUND_StopSound(FSOUND_ALL); /* to prevent some hangs in FMOD */ FSOUND_StopSound(FSOUND_ALL); /* to prevent some hangs in FMOD */
#ifdef DEBUG #ifdef DEBUG
Sleep(0); Sleep(0);
#endif #endif
FSOUND_Close(); FSOUND_Close();
#elif defined HAVE_LIBSDL_MIXER #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
Mix_CloseAudio(); Mix_CloseAudio();
SDL_Quit(); SDL_Quit();
#elif defined(USE_OPEN_AL) #elif AUDIO_TK == AUDIO_TK_OPENAL
#ifndef __APPLE__ #ifndef __APPLE__
alutExit(); alutExit();
#endif #endif
@ -237,7 +240,7 @@ void C4MusicSystem::Load(const char *szFile)
if (!szFile || !*szFile) return; if (!szFile || !*szFile) return;
C4MusicFile *NewSong=NULL; C4MusicFile *NewSong=NULL;
// get extension // get extension
#if defined HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
const char *szExt = GetExtension(szFile); const char *szExt = GetExtension(szFile);
// get type // get type
switch (GetMusicFileTypeByExtension(GetExtension(szFile))) switch (GetMusicFileTypeByExtension(GetExtension(szFile)))
@ -258,7 +261,7 @@ void C4MusicSystem::Load(const char *szFile)
break; break;
default: return; // safety default: return; // safety
} }
#elif defined HAVE_LIBSDL_MIXER #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
if (GetMusicFileTypeByExtension(GetExtension(szFile)) == MUSICTYPE_UNKNOWN) return; if (GetMusicFileTypeByExtension(GetExtension(szFile)) == MUSICTYPE_UNKNOWN) return;
NewSong = new C4MusicFileSDL; NewSong = new C4MusicFileSDL;
#endif #endif
@ -382,7 +385,7 @@ void C4MusicSystem::ClearSongs()
void C4MusicSystem::Clear() void C4MusicSystem::Clear()
{ {
#ifdef HAVE_LIBSDL_MIXER #if AUDIO_TK == AUDIO_TK_SDL_MIXER
// Stop a fadeout // Stop a fadeout
Mix_HaltMusic(); Mix_HaltMusic();
#endif #endif
@ -392,7 +395,7 @@ void C4MusicSystem::Clear()
void C4MusicSystem::Execute() void C4MusicSystem::Execute()
{ {
#ifndef HAVE_LIBSDL_MIXER #if AUDIO_TK != AUDIO_TK_SDL_MIXER
if (!::Game.iTick35) if (!::Game.iTick35)
#endif #endif
{ {
@ -513,7 +516,7 @@ MusicType GetMusicFileTypeByExtension(const char* ext)
{ {
if (SEqualNoCase(ext, "mid")) if (SEqualNoCase(ext, "mid"))
return MUSICTYPE_MID; return MUSICTYPE_MID;
#if defined HAVE_FMOD || defined HAVE_LIBSDL_MIXER #if AUDIO_TK == AUDIO_TK_FMOD || AUDIO_TK == AUDIO_TK_SDL_MIXER
else if (SEqualNoCase(ext, "xm") || SEqualNoCase(ext, "it") || SEqualNoCase(ext, "s3m") || SEqualNoCase(ext, "mod")) else if (SEqualNoCase(ext, "xm") || SEqualNoCase(ext, "it") || SEqualNoCase(ext, "s3m") || SEqualNoCase(ext, "mod"))
return MUSICTYPE_MOD; return MUSICTYPE_MOD;
#ifdef USE_MP3 #ifdef USE_MP3

View File

@ -22,14 +22,9 @@
#include <C4Group.h> #include <C4Group.h>
#if defined(USE_OPEN_AL) #if AUDIO_TK == AUDIO_TK_OPENAL
#ifdef __APPLE__ #include <al.h>
#import <OpenAL/al.h> #include <alc.h>
#import <OpenAL/alc.h>
#else
#include <AL/al.h>
#include <AL/alc.h>
#endif
#endif #endif
class C4MusicFileInfoNode; class C4MusicFileInfoNode;
@ -77,7 +72,7 @@ protected:
bool MODInitialized; bool MODInitialized;
bool InitializeMOD(); bool InitializeMOD();
void DeinitializeMOD(); void DeinitializeMOD();
#ifdef USE_OPEN_AL #if AUDIO_TK == AUDIO_TK_OPENAL
private: private:
ALCdevice* alcDevice; ALCdevice* alcDevice;
ALCcontext* alcContext; ALCcontext* alcContext;

View File

@ -19,12 +19,17 @@
#include <C4Application.h> #include <C4Application.h>
#if defined(USE_OPEN_AL) #if AUDIO_TK == AUDIO_TK_OPENAL
#if defined(__APPLE__) #if defined(__APPLE__)
#import <CoreFoundation/CoreFoundation.h> #import <CoreFoundation/CoreFoundation.h>
#import <AudioToolbox/AudioToolbox.h> #import <AudioToolbox/AudioToolbox.h>
#else #else
#include <AL/alut.h> #ifdef _WIN32
// This is an ugly hack to make FreeALUT not dllimport everything.
#define _XBOX
#endif
#include <alut.h>
#undef _XBOX
#endif #endif
#endif #endif
@ -33,7 +38,7 @@ using namespace C4SoundLoaders;
SoundLoader* SoundLoader::first_loader(NULL); SoundLoader* SoundLoader::first_loader(NULL);
#if defined(USE_OPEN_AL) && defined(__APPLE__) #if AUDIO_TK == AUDIO_TK_OPENAL && defined(__APPLE__)
namespace namespace
{ {
static OSStatus AudioToolBoxReadCallback(void* context, SInt64 inPosition, UInt32 requestCount, void* buffer, UInt32* actualCount) static OSStatus AudioToolBoxReadCallback(void* context, SInt64 inPosition, UInt32 requestCount, void* buffer, UInt32* actualCount)
@ -111,8 +116,7 @@ bool AppleSoundLoader::ReadInfo(SoundInfo* result, BYTE* data, size_t data_lengt
AppleSoundLoader AppleSoundLoader::singleton; AppleSoundLoader AppleSoundLoader::singleton;
#endif #endif
#ifdef USE_OPEN_AL #if AUDIO_TK == AUDIO_TK_OPENAL
size_t VorbisLoader::read_func(void* ptr, size_t byte_size, size_t size_to_read, void* datasource) size_t VorbisLoader::read_func(void* ptr, size_t byte_size, size_t size_to_read, void* datasource)
{ {
size_t spaceToEOF; size_t spaceToEOF;
@ -254,9 +258,8 @@ bool WavLoader::ReadInfo(SoundInfo* result, BYTE* data, size_t data_length, uint
WavLoader WavLoader::singleton; WavLoader WavLoader::singleton;
#endif #endif
#endif
#ifdef HAVE_LIBSDL_MIXER #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
#define USE_RWOPS #define USE_RWOPS
#include <SDL_mixer.h> #include <SDL_mixer.h>
@ -278,9 +281,8 @@ bool SDLMixerSoundLoader::ReadInfo(SoundInfo* result, BYTE* data, size_t data_le
} }
SDLMixerSoundLoader SDLMixerSoundLoader::singleton; SDLMixerSoundLoader SDLMixerSoundLoader::singleton;
#endif
#ifdef HAVE_FMOD #elif AUDIO_TK == AUDIO_TK_FMOD
bool FMODSoundLoader::ReadInfo(SoundInfo* result, BYTE* data, size_t data_length, uint32_t options) bool FMODSoundLoader::ReadInfo(SoundInfo* result, BYTE* data, size_t data_length, uint32_t options)
{ {
int32_t iOptions = FSOUND_NORMAL | FSOUND_2D | FSOUND_LOADMEMORY; int32_t iOptions = FSOUND_NORMAL | FSOUND_2D | FSOUND_LOADMEMORY;

View File

@ -13,7 +13,10 @@
* for the above references. * for the above references.
*/ */
#ifdef USE_OPEN_AL #ifndef INC_C4SoundLoaders
#define INC_C4SoundLoaders
#if AUDIO_TK == AUDIO_TK_OPENAL
#include <vorbis/codec.h> #include <vorbis/codec.h>
#include <vorbis/vorbisfile.h> #include <vorbis/vorbisfile.h>
#endif #endif
@ -29,7 +32,7 @@ namespace C4SoundLoaders
double sample_length; double sample_length;
uint32_t sample_rate; uint32_t sample_rate;
std::vector<BYTE> sound_data; std::vector<BYTE> sound_data;
#ifdef USE_OPEN_AL #if AUDIO_TK == AUDIO_TK_OPENAL
ALenum format; ALenum format;
#endif #endif
C4SoundHandle final_handle; C4SoundHandle final_handle;
@ -53,7 +56,7 @@ namespace C4SoundLoaders
virtual bool ReadInfo(SoundInfo* info, BYTE* data, size_t data_length, uint32_t options = 0) = 0; virtual bool ReadInfo(SoundInfo* info, BYTE* data, size_t data_length, uint32_t options = 0) = 0;
}; };
#if defined(USE_OPEN_AL) && defined(__APPLE__) #if AUDIO_TK == AUDIO_TK_OPENAL && defined(__APPLE__)
class AppleSoundLoader: public SoundLoader class AppleSoundLoader: public SoundLoader
{ {
public: public:
@ -64,7 +67,7 @@ namespace C4SoundLoaders
}; };
#endif #endif
#ifdef USE_OPEN_AL #if AUDIO_TK == AUDIO_TK_OPENAL
class VorbisLoader: public SoundLoader class VorbisLoader: public SoundLoader
{ {
private: private:
@ -96,18 +99,16 @@ namespace C4SoundLoaders
static WavLoader singleton; static WavLoader singleton;
}; };
#endif // apple #endif // apple
#endif // openal
#ifdef HAVE_LIBSDL_MIXER #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
class SDLMixerSoundLoader: public SoundLoader class SDLMixerSoundLoader: public SoundLoader
{ {
public: public:
static SDLMixerSoundLoader singleton; static SDLMixerSoundLoader singleton;
virtual bool ReadInfo(SoundInfo* result, BYTE* data, size_t data_length, uint32_t); virtual bool ReadInfo(SoundInfo* result, BYTE* data, size_t data_length, uint32_t);
}; };
#endif
#ifdef HAVE_FMOD #elif AUDIO_TK == AUDIO_TK_FMOD
class FMODSoundLoader: public SoundLoader class FMODSoundLoader: public SoundLoader
{ {
public: public:
@ -116,3 +117,5 @@ namespace C4SoundLoaders
}; };
#endif #endif
} }
#endif

View File

@ -28,7 +28,7 @@
#include <C4Viewport.h> #include <C4Viewport.h>
#include <C4SoundLoaders.h> #include <C4SoundLoaders.h>
#ifdef HAVE_LIBSDL_MIXER #if AUDIO_TK == AUDIO_TK_SDL_MIXER
#define USE_RWOPS #define USE_RWOPS
#include <SDL_mixer.h> #include <SDL_mixer.h>
#endif #endif
@ -52,13 +52,11 @@ C4SoundEffect::~C4SoundEffect()
void C4SoundEffect::Clear() void C4SoundEffect::Clear()
{ {
while (FirstInst) RemoveInst(FirstInst); while (FirstInst) RemoveInst(FirstInst);
#ifdef HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
if (pSample) FSOUND_Sample_Free(pSample); if (pSample) FSOUND_Sample_Free(pSample);
#endif #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
#ifdef HAVE_LIBSDL_MIXER
if (pSample) Mix_FreeChunk(pSample); if (pSample) Mix_FreeChunk(pSample);
#endif #elif AUDIO_TK == AUDIO_TK_OPENAL
#ifdef USE_OPEN_AL
if (pSample) alDeleteBuffers(1, &pSample); if (pSample) alDeleteBuffers(1, &pSample);
#endif #endif
pSample = 0; pSample = 0;
@ -98,7 +96,7 @@ bool C4SoundEffect::Load(BYTE *pData, size_t iDataLen, bool fRaw)
} }
else else
{ {
#ifdef USE_OPEN_AL #if AUDIO_TK == AUDIO_TK_OPENAL
Application.MusicSystem.SelectContext(); Application.MusicSystem.SelectContext();
alGenBuffers(1, &pSample); alGenBuffers(1, &pSample);
alBufferData(pSample, info.format, &info.sound_data[0], info.sound_data.size(), info.sample_rate); alBufferData(pSample, info.format, &info.sound_data[0], info.sound_data.size(), info.sample_rate);
@ -253,7 +251,7 @@ bool C4SoundInstance::CheckStart()
bool C4SoundInstance::Start() bool C4SoundInstance::Start()
{ {
#ifdef HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
// Start // Start
if ((iChannel = FSOUND_PlaySound(FSOUND_FREE, pEffect->pSample)) == -1) if ((iChannel = FSOUND_PlaySound(FSOUND_FREE, pEffect->pSample)) == -1)
return false; return false;
@ -266,12 +264,12 @@ bool C4SoundInstance::Start()
int32_t iTime = (C4TimeMilliseconds::Now() - tStarted) % pEffect->Length; int32_t iTime = (C4TimeMilliseconds::Now() - tStarted) % pEffect->Length;
FSOUND_SetCurrentPosition(iChannel, iTime / 10 * pEffect->SampleRate / 100); FSOUND_SetCurrentPosition(iChannel, iTime / 10 * pEffect->SampleRate / 100);
} }
#elif defined HAVE_LIBSDL_MIXER #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
// Be paranoid about SDL_Mixer initialisation // Be paranoid about SDL_Mixer initialisation
if (!Application.MusicSystem.MODInitialized) return false; if (!Application.MusicSystem.MODInitialized) return false;
if ((iChannel = Mix_PlayChannel(-1, pEffect->pSample, fLooping? -1 : 0)) == -1) if ((iChannel = Mix_PlayChannel(-1, pEffect->pSample, fLooping? -1 : 0)) == -1)
return false; return false;
#elif defined(USE_OPEN_AL) #elif AUDIO_TK == AUDIO_TK_OPENAL
Application.MusicSystem.SelectContext(); Application.MusicSystem.SelectContext();
alGenSources(1, (ALuint*)&iChannel); alGenSources(1, (ALuint*)&iChannel);
alSourcei(iChannel, AL_BUFFER, pEffect->pSample); alSourcei(iChannel, AL_BUFFER, pEffect->pSample);
@ -292,16 +290,14 @@ bool C4SoundInstance::Stop()
if (!pEffect) return false; if (!pEffect) return false;
// Stop sound // Stop sound
bool fRet = true; bool fRet = true;
#ifdef HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
if (Playing()) if (Playing())
fRet = !! FSOUND_StopSound(iChannel); fRet = !! FSOUND_StopSound(iChannel);
#endif #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
#ifdef HAVE_LIBSDL_MIXER
// iChannel == -1 will halt all channels. Is that right? // iChannel == -1 will halt all channels. Is that right?
if (Playing()) if (Playing())
Mix_HaltChannel(iChannel); Mix_HaltChannel(iChannel);
#endif #elif AUDIO_TK == AUDIO_TK_OPENAL
#ifdef USE_OPEN_AL
if (iChannel != -1) if (iChannel != -1)
{ {
if (Playing()) alSourceStop(iChannel); if (Playing()) alSourceStop(iChannel);
@ -318,15 +314,13 @@ bool C4SoundInstance::Stop()
bool C4SoundInstance::Playing() bool C4SoundInstance::Playing()
{ {
if (!pEffect) return false; if (!pEffect) return false;
#ifdef HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
if (fLooping) return true; if (fLooping) return true;
return isStarted() ? FSOUND_GetCurrentSample(iChannel) == pEffect->pSample return isStarted() ? FSOUND_GetCurrentSample(iChannel) == pEffect->pSample
: C4TimeMilliseconds::Now() < tStarted + pEffect->Length; : C4TimeMilliseconds::Now() < tStarted + pEffect->Length;
#endif #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
#ifdef HAVE_LIBSDL_MIXER
return Application.MusicSystem.MODInitialized && (iChannel != -1) && Mix_Playing(iChannel); return Application.MusicSystem.MODInitialized && (iChannel != -1) && Mix_Playing(iChannel);
#endif #elif AUDIO_TK == AUDIO_TK_OPENAL
#ifdef USE_OPEN_AL
if (iChannel == -1) if (iChannel == -1)
return false; return false;
else else
@ -363,13 +357,11 @@ void C4SoundInstance::Execute()
// stop, if started // stop, if started
if (isStarted()) if (isStarted())
{ {
#ifdef HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
FSOUND_StopSound(iChannel); FSOUND_StopSound(iChannel);
#endif #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
#ifdef HAVE_LIBSDL_MIXER
Mix_HaltChannel(iChannel); Mix_HaltChannel(iChannel);
#endif #elif AUDIO_TK == AUDIO_TK_OPENAL
#ifdef USE_OPEN_AL
alDeleteSources(1, (ALuint*)&iChannel); alDeleteSources(1, (ALuint*)&iChannel);
#endif #endif
iChannel = -1; iChannel = -1;
@ -382,16 +374,14 @@ void C4SoundInstance::Execute()
if (!CheckStart()) if (!CheckStart())
return; return;
// set volume & panning // set volume & panning
#ifdef HAVE_FMOD #if AUDIO_TK == AUDIO_TK_FMOD
FSOUND_SetVolume(iChannel, BoundBy(iVol / 100, 0, 255)); FSOUND_SetVolume(iChannel, BoundBy(iVol / 100, 0, 255));
FSOUND_SetPan(iChannel, BoundBy(256*(iPan+100)/200,0,255)); FSOUND_SetPan(iChannel, BoundBy(256*(iPan+100)/200,0,255));
#endif #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
#ifdef HAVE_LIBSDL_MIXER
Mix_Volume(iChannel, (iVol * MIX_MAX_VOLUME) / (100 * 256)); Mix_Volume(iChannel, (iVol * MIX_MAX_VOLUME) / (100 * 256));
//Mix_SetPanning(iChannel, ((100 + iPan) * 256) / 200, ((100 - iPan) * 256) / 200); //Mix_SetPanning(iChannel, ((100 + iPan) * 256) / 200, ((100 - iPan) * 256) / 200);
Mix_SetPanning(iChannel, BoundBy((100 - iPan) * 256 / 100, 0, 255), BoundBy((100 + iPan) * 256 / 100, 0, 255)); Mix_SetPanning(iChannel, BoundBy((100 - iPan) * 256 / 100, 0, 255), BoundBy((100 + iPan) * 256 / 100, 0, 255));
#endif #elif AUDIO_TK == AUDIO_TK_OPENAL
#ifdef USE_OPEN_AL
alSource3f(iChannel, AL_POSITION, 0, 0, 0); // FIXME alSource3f(iChannel, AL_POSITION, 0, 0, 0); // FIXME
alSourcef(iChannel, AL_GAIN, float(iVol) / (100.0f*256.0f)); alSourcef(iChannel, AL_GAIN, float(iVol) / (100.0f*256.0f));
#endif #endif
@ -448,7 +438,7 @@ bool C4SoundSystem::Init()
if (!Reloc.Open(SoundFile, C4CFN_Sound)) return false; if (!Reloc.Open(SoundFile, C4CFN_Sound)) return false;
// Load static sound from Sound.ocg // Load static sound from Sound.ocg
LoadEffects(SoundFile); LoadEffects(SoundFile);
#ifdef HAVE_LIBSDL_MIXER #if AUDIO_TK == AUDIO_TK_SDL_MIXER
Mix_AllocateChannels(C4MaxSoundInstances); Mix_AllocateChannels(C4MaxSoundInstances);
#endif #endif
return true; return true;
@ -475,7 +465,7 @@ void C4SoundSystem::ClearEffects()
void C4SoundSystem::Execute() void C4SoundSystem::Execute()
{ {
#ifdef USE_OPEN_AL #if AUDIO_TK == AUDIO_TK_OPENAL
Application.MusicSystem.SelectContext(); Application.MusicSystem.SelectContext();
#endif #endif
C4SoundEffect *csfx; C4SoundEffect *csfx;

View File

@ -31,17 +31,13 @@ const int32_t
class C4Object; class C4Object;
class C4SoundInstance; class C4SoundInstance;
#if defined(HAVE_FMOD) #if AUDIO_TK == AUDIO_TK_FMOD
#include <fmod.h> #include <fmod.h>
typedef FSOUND_SAMPLE* C4SoundHandle; typedef FSOUND_SAMPLE* C4SoundHandle;
#elif defined(HAVE_LIBSDL_MIXER) #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
typedef struct Mix_Chunk* C4SoundHandle; typedef struct Mix_Chunk* C4SoundHandle;
#elif defined(USE_OPEN_AL) #elif AUDIO_TK == AUDIO_TK_OPENAL
#ifdef __APPLE__ #include <al.h>
#import <OpenAL/al.h>
#else
#include <AL/al.h>
#endif
typedef ALuint C4SoundHandle; typedef ALuint C4SoundHandle;
#else #else
typedef void* C4SoundHandle; typedef void* C4SoundHandle;