Removed alut dependency.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1977 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
cosmosninja 2008-05-22 06:45:02 +00:00
parent b04d57330d
commit 1a8ec5578f
5 changed files with 60 additions and 73 deletions

View File

@ -10,7 +10,6 @@ First, make sure that you have the following packages installed:
* PLIB version 1.8.4 or later * PLIB version 1.8.4 or later
* SDL 1.2 or later * SDL 1.2 or later
* OpenAL * OpenAL
* freealut
Unpack the files from the tarball like this: Unpack the files from the tarball like this:
@ -43,7 +42,7 @@ Here are the compilation instructions for the current svn(05 oct. 2006) of
Super Tux Kart on Ubuntu Edgy, contributed by Damien: Super Tux Kart on Ubuntu Edgy, contributed by Damien:
install following packages: install following packages:
# apt-get install libopenal-dev libalut-dev libmikmod2-dev plib1.8.4-dev # apt-get install libopenal-dev libmikmod2-dev plib1.8.4-dev
libglu1-mesa-dev subversion autoconf automake1.9 g++ gcc libglu1-mesa-dev subversion autoconf automake1.9 g++ gcc
do a: do a:

View File

@ -94,10 +94,6 @@ dnl Add special compiler flags for certain platforms
dnl ================================================ dnl ================================================
case "${host}" in case "${host}" in
*darwin*|*macosx*) *darwin*|*macosx*)
AC_CHECK_PROGS(have_pkg_config,[pkg-config],"no")
if test x$have_pkg_config != xno; then
LDFLAGS="$LDFLAGS `pkg-config --libs freealut`"
fi
LDFLAGS="$LDFLAGS -lintl" LDFLAGS="$LDFLAGS -lintl"
esac esac
@ -142,14 +138,14 @@ case "${host}" in
esac esac
dnl ======================================== dnl ========================================
dnl check for OpenAL (al and alut) libraries dnl check for OpenAL libraries
dnl ======================================== dnl ========================================
dnl FIXME: this all appears too complicated, doing unnecesary dnl FIXME: this all appears too complicated, doing unnecesary
dnl tests etc --> needs cleanup dnl tests etc --> needs cleanup
dnl The check for OpenAL headers depends on the OS, since dnl The check for OpenAL headers depends on the OS, since
dnl Apple has the headers in OpenAL/al.h instead of AL/al.h dnl Apple has the headers in OpenAL/al.h instead of AL/al.h
AC_SEARCH_LIBS(alGenBuffers, [openal alut], have_al_lib=yes) AC_SEARCH_LIBS(alGenBuffers, [openal], have_al_lib=yes)
dnl We also check for ogg vorbis support now. dnl We also check for ogg vorbis support now.
dnl we have 4 sound libraries to check, first we check for OpenAL dnl we have 4 sound libraries to check, first we check for OpenAL
@ -171,33 +167,6 @@ case "${host}" in
dnl check for libraries dnl check for libraries
save_LIBS=$LIBS save_LIBS=$LIBS
dnl AL/al.h is checked before, since Macs need a different path
dnl check for freealut
AC_SEARCH_LIBS(alutInit, alut, have_alut_lib=yes)
if test x$have_alut_lib = xyes; then
AC_CHECK_HEADER(AL/alut.h, have_alut_hdr=yes)
if test x$have_alut_hdr = xyes; then
AC_MSG_CHECKING([for alut version 1.0.0 or later ])
dnl check for right version of alut, must be at least 1.0
AC_RUN_IFELSE([
# include <AL/alut.h>
# define MIN_ALUT_VERSION 1
int main() {
/* if(alutGetMajorVersion()<MIN_ALUT_VERSION) return -1;*/
return 0; }
],
alut_version_ok=yes
[ AC_MSG_RESULT(yes)],
AC_MSG_FAILURE(too old alut version - using plib instead),
alut_version_ok=yes
[ AC_MSG_RESULT(yes)])
fi
fi
dnl search for the libraries needed to use ogg vorbis dnl search for the libraries needed to use ogg vorbis
AC_SEARCH_LIBS(ov_open, vorbisfile, have_vorbisfile_lib=yes) AC_SEARCH_LIBS(ov_open, vorbisfile, have_vorbisfile_lib=yes)
@ -213,15 +182,7 @@ case "${host}" in
SUMMARY="$SUMMARY You DO NOT have OpenAL." SUMMARY="$SUMMARY You DO NOT have OpenAL."
fi fi
if test x$have_alut_hdr = xyes; then if test x$have_al_hdr = xyes ; then
if test x$alut_version_ok != xyes; then
SUMMARY="$SUMMARY You need to update freealut."
fi
else
SUMMARY="$SUMMARY You DO NOT have freealut."
fi
if test x$have_al_hdr = xyes -a x$alut_version_ok = xyes; then
openal_LIBS="$LIBS" openal_LIBS="$LIBS"
AC_DEFINE([HAVE_OPENAL], 1, [Defined when OpenAL is available]) AC_DEFINE([HAVE_OPENAL], 1, [Defined when OpenAL is available])
SUMMARY="$SUMMARY\nUsing OpenAL for sound." SUMMARY="$SUMMARY\nUsing OpenAL for sound."
@ -237,7 +198,7 @@ case "${host}" in
SUMMARY="$SUMMARY\nPlease install ogg vorbis!" SUMMARY="$SUMMARY\nPlease install ogg vorbis!"
fi fi
else else
SUMMARY="$SUMMARY\nInstall OpenAL and freealut for music!" SUMMARY="$SUMMARY\nInstall OpenAL for music!"
fi fi
LIBS=$save_LIBS LIBS=$save_LIBS

View File

@ -25,7 +25,6 @@
#else #else
# include <AL/al.h> # include <AL/al.h>
#endif #endif
#include <AL/alut.h>
#include "music_ogg.hpp" #include "music_ogg.hpp"
#include "file_manager.hpp" #include "file_manager.hpp"

View File

@ -28,7 +28,8 @@
#else #else
# include <AL/al.h> # include <AL/al.h>
#endif #endif
#include <AL/alut.h>
#include <SDL/SDL.h>
#include "sfx_openal.hpp" #include "sfx_openal.hpp"
#include "file_manager.hpp" #include "file_manager.hpp"
@ -77,41 +78,45 @@ bool SFXImpl::load(const char* filename)
return false; return false;
} }
ALenum format = 0; ALenum format = 0;
ALsizei size = 0, freq = 0; Uint32 size = 0;
ALvoid* data = NULL; Uint8* data = NULL;
ALboolean loop = AL_FALSE; SDL_AudioSpec spec;
#ifdef __APPLE__ if( SDL_LoadWAV( path.c_str(), &spec, &data, &size ) == NULL)
alutLoadWAVFile((ALbyte*)path.c_str(), &format, &data, &size, &freq);
#else
alutLoadWAVFile((ALbyte*)path.c_str(), &format, &data, &size, &freq, &loop);
#endif
if (data == NULL)
{ {
const int ALUT_ERROR = alutGetError(); fprintf(stderr, "Error 1 loading SFX: with file %s, SDL_LoadWAV() failed\n", path.c_str());
fprintf(stderr, "Error 1 loading SFX: %s failed because %s \n", path.c_str(), alutGetErrorString(ALUT_ERROR));
return false; return false;
} }
alBufferData(m_soundBuffer, format, data, size, freq); switch( spec.format )
{
case AUDIO_U8:
case AUDIO_S8:
if( spec.channels == 2 ) format = AL_FORMAT_STEREO8;
else format = AL_FORMAT_MONO8;
break;
case AUDIO_U16LSB:
case AUDIO_S16LSB:
case AUDIO_U16MSB:
case AUDIO_S16MSB:
if( spec.channels == 2 ) format = AL_FORMAT_STEREO16;
else format = AL_FORMAT_MONO16;
break;
}
alBufferData(m_soundBuffer, format, data, size, spec.freq);
if (alGetError() != AL_NO_ERROR) if (alGetError() != AL_NO_ERROR)
{ {
fprintf(stderr, "Error 2 loading SFX: %s failed\n", path.c_str()); fprintf(stderr, "Error 2 loading SFX: %s failed\n", path.c_str());
return false; return false;
} }
alutUnloadWAV(format, data, size, freq); SDL_FreeWAV(data);
if (alGetError() != AL_NO_ERROR)
{
fprintf(stderr, "Error 3 loading SFX: %s failed\n", path.c_str());
return false;
}
alGenSources(1, &m_soundSource ); alGenSources(1, &m_soundSource );
if (alGetError() != AL_NO_ERROR) if (alGetError() != AL_NO_ERROR)
{ {
fprintf(stderr, "Error 4 loading SFX: %s failed\n", path.c_str()); fprintf(stderr, "Error 3 loading SFX: %s failed\n", path.c_str());
return false; return false;
} }

View File

@ -29,10 +29,11 @@
#ifdef __APPLE__ #ifdef __APPLE__
# include <OpenAL/al.h> # include <OpenAL/al.h>
# include <OpenAL/alc.h>
#else #else
# include <AL/al.h> # include <AL/al.h>
# include <AL/alc.h>
#endif #endif
#include <AL/alut.h>
#include "music_ogg.hpp" #include "music_ogg.hpp"
#include "sfx_openal.hpp" #include "sfx_openal.hpp"
@ -46,12 +47,28 @@ SoundManager* sound_manager= NULL;
SoundManager::SoundManager() : m_sfxs(NUM_SOUNDS) SoundManager::SoundManager() : m_sfxs(NUM_SOUNDS)
{ {
m_current_music= NULL; m_current_music= NULL;
if(alutInit(0, NULL) == AL_TRUE) // init OpenAL sound system
m_initialized = true; ALCdevice* device = alcOpenDevice ( NULL ); //The default sound device
if( device == NULL )
{
fprintf(stderr, "WARNING: Could open the default sound device.\n");
m_initialized = false;
}
else else
{ {
fprintf(stderr, "WARNING: Could not initialize the ALUT based sound.\n");
m_initialized = false; ALCcontext* context = alcCreateContext( device, NULL );
if( context == NULL )
{
fprintf(stderr, "WARNING: Could create a sound context.\n");
m_initialized = false;
}
else
{
alcMakeContextCurrent( context );
m_initialized = true;
}
} }
alGetError(); //Called here to clear any non-important errors found alGetError(); //Called here to clear any non-important errors found
@ -94,7 +111,13 @@ SoundManager::~SoundManager()
if(m_initialized) if(m_initialized)
{ {
alutExit(); ALCcontext* context = alcGetCurrentContext();
ALCdevice* device = alcGetContextsDevice( context );
alcMakeContextCurrent( NULL );
alcDestroyContext( context );
alcCloseDevice( device );
} }
} // ~SoundManager } // ~SoundManager