diff --git a/sc2/build/build.config b/sc2/build/build.config index 5024e2c4d..492853c6d 100644 --- a/sc2/build/build.config +++ b/sc2/build/build.config @@ -107,26 +107,26 @@ graphics_opengl_action() { } CHOICE_graphics_DEFAULT=opengl -CHOICE_sound_OPTIONS="openal mixsdl" +CHOICE_sound_OPTIONS="mixsdl openal" CHOICE_sound_TITLE="Sound backend" -CHOICE_sound_OPTION_openal_TITLE="Use OpenAL for sound (experimental)" -CHOICE_sound_OPTION_openal_PRECOND="have_library openal" -CHOICE_sound_OPTION_openal_ACTION=sound_openal_action -sound_openal_action() { - CFLAGS="$CFLAGS -DSOUNDMODULE_OPENAL" - SOUNDMODULE=openal - use_library openal - use_library vorbisfile -# use_library vorbis -} CHOICE_sound_OPTION_mixsdl_TITLE="Use MixSDL for sound" CHOICE_sound_OPTION_mixsdl_ACTION=sound_mixsdl_action sound_mixsdl_action() { - CFLAGS="$CFLAGS -DSOUNDMODULE_MIXSDL" + CFLAGS="$CFLAGS -DSOUNDMODULE_SDL" SOUNDMODULE=mixsdl use_library vorbisfile # use_library vorbis } +CHOICE_sound_OPTION_openal_TITLE="Include OpenAL support (experimental)" +CHOICE_sound_OPTION_openal_PRECOND="have_library openal" +CHOICE_sound_OPTION_openal_ACTION=sound_openal_action +sound_openal_action() { + CFLAGS="$CFLAGS -DHAVE_OPENAL -DSOUNDMODULE_SDL" + SOUNDMODULE=openal + use_library openal + use_library vorbisfile +# use_library vorbis +} CHOICE_sound_DEFAULT=mixsdl CHOICE_link_OPTIONS="static dynamic" diff --git a/sc2/src/sc2code/libs/sound/Makeinfo b/sc2/src/sc2code/libs/sound/Makeinfo index e95bc1ab7..c48404281 100644 --- a/sc2/src/sc2code/libs/sound/Makeinfo +++ b/sc2/src/sc2code/libs/sound/Makeinfo @@ -1,10 +1,10 @@ if [ "$uqm_SOUNDMODULE" = openal ]; then - uqm_SUBDIRS="openal decoders" - uqm_CFLAGS="$uqm_CFLAGS -DSOUNDMODULE_OPENAL" + uqm_SUBDIRS="openal mixsdl decoders" + uqm_CFLAGS="$uqm_CFLAGS -DHAVE_OPENAL" else # mixsdl uqm_SUBDIRS="mixsdl decoders" uqm_CFLAGS="$uqm_CFLAGS -DSOUNDMODULE_MIXSDL" fi -uqm_CFILES="fileinst.c resinst.c sound_common.c sound.c sfx.c music.c stream.c trackplayer.c" +uqm_CFILES="fileinst.c resinst.c sound_common.c sound.c sfx.c music.c stream.c trackplayer.c sound_chooser.c" diff --git a/sc2/src/sc2code/libs/sound/mixsdl/mixer.c b/sc2/src/sc2code/libs/sound/mixsdl/mixer.c index 347d81f33..329fe7a4c 100644 --- a/sc2/src/sc2code/libs/sound/mixsdl/mixer.c +++ b/sc2/src/sc2code/libs/sound/mixsdl/mixer.c @@ -19,8 +19,6 @@ * from SDL_mixer */ -#ifdef SOUNDMODULE_MIXSDL - #include "starcon.h" #include "mixer.h" #include "libs/misc.h" @@ -1933,4 +1931,3 @@ void mixSDL_mix_channels (void *userdata, uint8 *stream, sint32 len) (void)userdata; // satisfying compiler } -#endif diff --git a/sc2/src/sc2code/libs/sound/mixsdl/sound_mixsdl.c b/sc2/src/sc2code/libs/sound/mixsdl/sound_mixsdl.c index 523421255..94c99a032 100644 --- a/sc2/src/sc2code/libs/sound/mixsdl/sound_mixsdl.c +++ b/sc2/src/sc2code/libs/sound/mixsdl/sound_mixsdl.c @@ -16,13 +16,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef SOUNDMODULE_MIXSDL #include "libs/graphics/sdl/sdl_common.h" #include "libs/sound/sound.h" static Task StreamDecoderTask; int -TFB_InitSound (int driver, int flags) +TFB_mixSDL_InitSound (int driver, int flags) { int i; char SoundcardName[256]; @@ -103,7 +102,7 @@ TFB_InitSound (int driver, int flags) } void -TFB_UninitSound (void) +TFB_mixSDL_UninitSound (void) { int i; @@ -129,5 +128,3 @@ TFB_UninitSound (void) SoundDecoder_Uninit (); mixSDL_CloseAudio (); } - -#endif diff --git a/sc2/src/sc2code/libs/sound/music.c b/sc2/src/sc2code/libs/sound/music.c index b06b5054d..789d3b867 100644 --- a/sc2/src/sc2code/libs/sound/music.c +++ b/sc2/src/sc2code/libs/sound/music.c @@ -14,8 +14,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if defined SOUNDMODULE_MIXSDL || defined SOUNDMODULE_OPENAL - #include "sound.h" #include "options.h" #include "file.h" @@ -216,4 +214,3 @@ _ReleaseMusicData (MEM_HANDLE handle) return (TRUE); } -#endif diff --git a/sc2/src/sc2code/libs/sound/openal/sound_openal.c b/sc2/src/sc2code/libs/sound/openal/sound_openal.c index 99e5206dd..e6835215e 100644 --- a/sc2/src/sc2code/libs/sound/openal/sound_openal.c +++ b/sc2/src/sc2code/libs/sound/openal/sound_openal.c @@ -14,7 +14,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef SOUNDMODULE_OPENAL +#ifdef HAVE_OPENAL #include "libs/sound/sound.h" @@ -27,7 +27,7 @@ static Task StreamDecoderTask; int -TFB_InitSound (int driver, int flags) +TFB_alInitSound (int driver, int flags) { int i; TFB_DecoderFormats formats = @@ -109,7 +109,7 @@ TFB_InitSound (int driver, int flags) } void -TFB_UninitSound (void) +TFB_alUninitSound (void) { int i; @@ -139,4 +139,4 @@ TFB_UninitSound (void) SoundDecoder_Uninit (); } -#endif \ No newline at end of file +#endif diff --git a/sc2/src/sc2code/libs/sound/sfx.c b/sc2/src/sc2code/libs/sound/sfx.c index 2ad1c6378..10bd80eb9 100644 --- a/sc2/src/sc2code/libs/sound/sfx.c +++ b/sc2/src/sc2code/libs/sound/sfx.c @@ -14,8 +14,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if defined SOUNDMODULE_MIXSDL || defined SOUNDMODULE_OPENAL - #ifdef WIN32 #include #endif @@ -262,5 +260,3 @@ DestroySound(SOUND_REF target) { return _ReleaseSoundBankData ((MEM_HANDLE) target); } - -#endif diff --git a/sc2/src/sc2code/libs/sound/sound.c b/sc2/src/sc2code/libs/sound/sound.c index faacfbdc2..07d9208a8 100644 --- a/sc2/src/sc2code/libs/sound/sound.c +++ b/sc2/src/sc2code/libs/sound/sound.c @@ -16,13 +16,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if defined SOUNDMODULE_MIXSDL || defined SOUNDMODULE_OPENAL - #include "libs/sound/sound_common.h" #include "sound.h" TFB_SoundSource soundSource[NUM_SOUNDSOURCES]; -static Task StreamDecoderTask; void @@ -137,4 +134,3 @@ void SetSpeechVolume (float volume) TFBSound_Sourcef (soundSource[SPEECH_SOURCE].handle, TFBSOUND_GAIN, volume); } -#endif diff --git a/sc2/src/sc2code/libs/sound/sound.h b/sc2/src/sc2code/libs/sound/sound.h index f332af98f..5c69c3b71 100644 --- a/sc2/src/sc2code/libs/sound/sound.h +++ b/sc2/src/sc2code/libs/sound/sound.h @@ -19,10 +19,10 @@ #include "libs/strings/strintrn.h" #include "libs/sound/sndintrn.h" #include "libs/sound/sound_common.h" -#if defined SOUNDMODULE_MIXSDL +#ifdef HAVE_OPENAL +#include "libs/sound/sound_chooser.h" +#else #include "mixsdl/sound_mixsdl.h" -#elif defined SOUNDMODULE_OPENAL -#include "openal/sound_openal.h" #endif #include "decoders/decoder.h" diff --git a/sc2/src/sc2code/libs/sound/sound_chooser.c b/sc2/src/sc2code/libs/sound/sound_chooser.c new file mode 100644 index 000000000..b2b5e2040 --- /dev/null +++ b/sc2/src/sc2code/libs/sound/sound_chooser.c @@ -0,0 +1,317 @@ +/* + * 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 + * (at your option) 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/* Mixer abstraction layer for MixSDL + */ + +#ifdef HAVE_OPENAL + +#include "libs/sound/sound_common.h" +#include "libs/sound/sound_chooser.h" +#include + +static unsigned int tfb_enum_lookup[TFBSOUND_ENUMSIZE]; +unsigned int TFBSOUND_NO_ERROR; +int TFBSOUND_PAUSED; +int TFBSOUND_PLAYING; +unsigned int TFBSOUND_FORMAT_MONO16; +unsigned int TFBSOUND_FORMAT_STEREO16; +unsigned int TFBSOUND_FORMAT_STEREO8; +unsigned int TFBSOUND_FORMAT_MONO8; + +/************************************************* + * General interface + */ +uint32 +TFBSound_GetError (void) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + return (alGetError ()); + else + return (mixSDL_GetError ()); +} + +bool +TFBSound_OpenAudio (uint32 freq, uint32 format, uint32 chunksize) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + { + fprintf (stderr, "OpenAudio is not supported for openAL\n"); + return (0); + } + else + return (mixSDL_OpenAudio (freq, format, chunksize)); +} + +void +TFBSound_CloseAudio (void) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + fprintf (stderr, "CloseAudio is not supported for openAL\n"); + else + mixSDL_CloseAudio (); +} + +bool +TFBSound_QuerySpec (uint32 *freq, uint32 *format, uint32 *channels) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + { + fprintf (stderr, "QuerySpec is not supported for openAL\n"); + return (0); + } + else + return (mixSDL_QuerySpec (freq, format, channels)); +} + +/************************************************* + * Sources + */ + +void +TFBSound_GenSources (uint32 n, mixSDL_Object *psrcobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alGenSources (n, (ALuint *)psrcobj); + else + mixSDL_GenSources (n, (TFBSound_Object *)psrcobj); +} + +void TFBSound_DeleteSources (uint32 n, TFBSound_Object *psrcobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alDeleteSources (n, (ALuint *)psrcobj); + else + mixSDL_DeleteSources (n, (mixSDL_Object *)psrcobj); +} + +bool +TFBSound_IsSource (TFBSound_Object srcobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + return (alIsSource ((ALuint)srcobj)); + else + return (mixSDL_IsSource ((mixSDL_Object)srcobj)); +} + +void +TFBSound_Sourcei (TFBSound_Object srcobj, TFBSound_SourceProp pname, + TFBSound_IntVal value) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alSourcei ((ALuint) srcobj, (ALenum) tfb_enum_lookup[pname], (ALint) value); + else + mixSDL_Sourcei ((mixSDL_Object) srcobj, + (mixSDL_SourceProp) tfb_enum_lookup[pname], (mixSDL_IntVal) value); +} + +void +TFBSound_Sourcef (TFBSound_Object srcobj, TFBSound_SourceProp pname, float value) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alSourcef ((ALuint) srcobj, (ALenum) tfb_enum_lookup[pname], value); + else + mixSDL_Sourcef ((mixSDL_Object) srcobj, + (mixSDL_SourceProp) tfb_enum_lookup[pname], value); +} + +void +TFBSound_GetSourcei (TFBSound_Object srcobj, TFBSound_SourceProp pname, + TFBSound_IntVal *value) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alGetSourcei ((ALuint) srcobj, (ALenum) tfb_enum_lookup[pname], (ALint *)value); + else + mixSDL_GetSourcei ((mixSDL_Object) srcobj, + (mixSDL_SourceProp) tfb_enum_lookup[pname], (mixSDL_IntVal *)value); +} + +void +TFBSound_GetSourcef (TFBSound_Object srcobj, TFBSound_SourceProp pname, + float *value) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alGetSourcef ((ALuint) srcobj, (ALenum) tfb_enum_lookup[pname], value); + else + mixSDL_GetSourcef ((mixSDL_Object) srcobj, + (mixSDL_SourceProp) tfb_enum_lookup[pname], value); +} + +void +TFBSound_SourceRewind (TFBSound_Object srcobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alSourceRewind ((ALuint) srcobj); + else + mixSDL_SourceRewind ((mixSDL_Object) srcobj); +} + +void +TFBSound_SourcePlay (TFBSound_Object srcobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alSourcePlay ((ALuint) srcobj); + else + mixSDL_SourcePlay ((mixSDL_Object) srcobj); +} + +void +TFBSound_SourcePause (TFBSound_Object srcobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alSourcePause ((ALuint) srcobj); + else + mixSDL_SourcePause ((mixSDL_Object) srcobj); +} + +void +TFBSound_SourceStop (TFBSound_Object srcobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alSourceStop ((ALuint) srcobj); + else + mixSDL_SourceStop ((mixSDL_Object) srcobj); +} + +void +TFBSound_SourceQueueBuffers (TFBSound_Object srcobj, uint32 n, + TFBSound_Object* pbufobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alSourceQueueBuffers ((ALuint) srcobj, n,(ALuint *) pbufobj); + else + mixSDL_SourceQueueBuffers ((mixSDL_Object) srcobj, n, + (mixSDL_Object*) pbufobj); +} + +void +TFBSound_SourceUnqueueBuffers (TFBSound_Object srcobj, uint32 n, + TFBSound_Object* pbufobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alSourceUnqueueBuffers ((ALuint) srcobj, n, (ALuint *) pbufobj); + else + mixSDL_SourceUnqueueBuffers ((mixSDL_Object) srcobj, n, + (mixSDL_Object*) pbufobj); +} + +/************************************************* + * Buffers + */ +void +TFBSound_GenBuffers (uint32 n, TFBSound_Object *pbufobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alGenBuffers (n, (ALuint *)pbufobj); + else + mixSDL_GenBuffers (n, (mixSDL_Object *)pbufobj); +} + +void +TFBSound_DeleteBuffers (uint32 n, TFBSound_Object *pbufobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alDeleteBuffers (n, (ALuint *)pbufobj); + else + mixSDL_DeleteBuffers (n, (mixSDL_Object *)pbufobj); +} + +bool +TFBSound_IsBuffer (TFBSound_Object bufobj) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + return (alIsBuffer ((ALuint) bufobj)); + else + return (mixSDL_IsBuffer ((mixSDL_Object) bufobj)); +} + +void +TFBSound_GetBufferi (TFBSound_Object bufobj, TFBSound_BufferProp pname, + TFBSound_IntVal *value) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alGetBufferi ((ALuint) bufobj, (ALenum) tfb_enum_lookup[pname], (ALint *)value); + else + mixSDL_GetBufferi ((mixSDL_Object) bufobj, + (mixSDL_BufferProp) tfb_enum_lookup[pname], (mixSDL_IntVal *)value); +} + +void +TFBSound_BufferData (TFBSound_Object bufobj, uint32 format, void* data, + uint32 size, uint32 freq) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + alBufferData ((ALuint) bufobj, (ALenum) format, data, size, freq); + else + mixSDL_BufferData ((mixSDL_Object) bufobj, format, data, size, freq); +} + +void +TFBSound_ConvertBuffer (uint32 srcfmt, void* srcdata, uint32 srcsize, + uint32 srcfreq, uint32 dstfmt, void* dstdata, + uint32 dstsize, uint32 dstfreq) +{ + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + fprintf (stderr, "ConvertBuffer is not supported bu openAL\n"); + else + mixSDL_ConvertBuffer (srcfmt, srcdata, srcsize, srcfreq, dstfmt, dstdata, + dstsize, dstfreq); +} + +int +TFB_choose_InitSound (int driver, int flags) +{ + if (driver == TFB_SOUNDDRIVER_OPENAL) + { + SoundDriver = driver; + tfb_enum_lookup[TFBSOUND_GAIN] = AL_GAIN; + tfb_enum_lookup[TFBSOUND_BUFFER] = AL_BUFFER; + tfb_enum_lookup[TFBSOUND_SOURCE_STATE] = AL_SOURCE_STATE; + tfb_enum_lookup[TFBSOUND_LOOPING] = AL_LOOPING; + tfb_enum_lookup[TFBSOUND_BUFFERS_PROCESSED] = AL_BUFFERS_PROCESSED; + tfb_enum_lookup[TFBSOUND_BUFFERS_QUEUED] = AL_BUFFERS_QUEUED; + tfb_enum_lookup[TFBSOUND_SIZE] = AL_SIZE; + TFBSOUND_NO_ERROR = AL_NO_ERROR; + TFBSOUND_PAUSED = AL_PAUSED; + TFBSOUND_PLAYING = AL_PLAYING; + TFBSOUND_FORMAT_MONO16 = AL_FORMAT_MONO16; + TFBSOUND_FORMAT_STEREO16 = AL_FORMAT_STEREO16; + TFBSOUND_FORMAT_MONO8 = AL_FORMAT_MONO8; + TFBSOUND_FORMAT_STEREO8 = AL_FORMAT_STEREO8; + return (TFB_alInitSound (driver, flags)); + } + else + { + SoundDriver = driver; + tfb_enum_lookup[TFBSOUND_GAIN] = MIX_GAIN; + tfb_enum_lookup[TFBSOUND_BUFFER] = MIX_BUFFER; + tfb_enum_lookup[TFBSOUND_SOURCE_STATE] = MIX_SOURCE_STATE; + tfb_enum_lookup[TFBSOUND_LOOPING] = MIX_LOOPING; + tfb_enum_lookup[TFBSOUND_BUFFERS_PROCESSED] = MIX_BUFFERS_PROCESSED; + tfb_enum_lookup[TFBSOUND_BUFFERS_QUEUED] = MIX_BUFFERS_QUEUED; + tfb_enum_lookup[TFBSOUND_SIZE] = MIX_SIZE; + TFBSOUND_NO_ERROR = MIX_NO_ERROR; + TFBSOUND_PAUSED = MIX_PAUSED; + TFBSOUND_PLAYING = MIX_PLAYING; + TFBSOUND_FORMAT_MONO16 = MIX_FORMAT_MONO16; + TFBSOUND_FORMAT_STEREO16 = MIX_FORMAT_STEREO16; + TFBSOUND_FORMAT_MONO8 = MIX_FORMAT_MONO8; + TFBSOUND_FORMAT_STEREO8 = MIX_FORMAT_STEREO8; + return (TFB_mixSDL_InitSound (driver, flags)); + } +} + +#endif diff --git a/sc2/src/sc2code/libs/sound/sound_chooser.h b/sc2/src/sc2code/libs/sound/sound_chooser.h new file mode 100644 index 000000000..723bc6cb4 --- /dev/null +++ b/sc2/src/sc2code/libs/sound/sound_chooser.h @@ -0,0 +1,126 @@ +/* + * 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 + * (at your option) 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/* Simple mixer for use with SDL_audio + */ + +#ifndef SOUNDCHOOSER_H +#define SOUNDCHOOSER_H +#ifdef WIN32 +#include +#include +#pragma comment (lib, "OpenAL32.lib") +#else +#include +#include +#endif + +#include "mixsdl/mixer.h" +#include "openal/mixer.h" +#include "types.h" + + +int TFB_mixSDL_InitSound (int driver, int flags); +#ifdef HAVE_OPENAL +int TFB_choose_InitSound (int driver, int flags); +int TFB_alInitSound (int driver, int flags); +#endif + +void TFB_mixSDL_UninitSound (void); +#ifdef HAVE_OPENAL +void TFB_alUninitSound (void); +#endif + + + /************************************************* + * Interface Types + */ + +typedef unsigned int TFBSound_Object; +typedef int TFBSound_IntVal; +typedef const int TFBSound_SourceProp; +typedef const int TFBSound_BufferProp; + +/************************************************* + * General interface + */ +uint32 TFBSound_GetError (void); + +bool TFBSound_OpenAudio (uint32 freq, uint32 format, uint32 chunksize); +void TFBSound_CloseAudio (void); +bool TFBSound_QuerySpec (uint32 *freq, uint32 *format, uint32 *channels); + +/************************************************* + * Sources + */ +void TFBSound_GenSources (uint32 n, TFBSound_Object *psrcobj); +void TFBSound_DeleteSources (uint32 n, TFBSound_Object *psrcobj); +bool TFBSound_IsSource (TFBSound_Object srcobj); +void TFBSound_Sourcei (TFBSound_Object srcobj, TFBSound_SourceProp pname, + TFBSound_IntVal value); +void TFBSound_Sourcef (TFBSound_Object srcobj, TFBSound_SourceProp pname, + float value); +void TFBSound_GetSourcei (TFBSound_Object srcobj, TFBSound_SourceProp pname, + TFBSound_IntVal *value); +void TFBSound_GetSourcef (TFBSound_Object srcobj, TFBSound_SourceProp pname, + float *value); +void TFBSound_SourceRewind (TFBSound_Object srcobj); +void TFBSound_SourcePlay (TFBSound_Object srcobj); +void TFBSound_SourcePause (TFBSound_Object srcobj); +void TFBSound_SourceStop (TFBSound_Object srcobj); +void TFBSound_SourceQueueBuffers (TFBSound_Object srcobj, uint32 n, + TFBSound_Object* pbufobj); +void TFBSound_SourceUnqueueBuffers (TFBSound_Object srcobj, uint32 n, + TFBSound_Object* pbufobj); + +/************************************************* + * Buffers + */ +void TFBSound_GenBuffers (uint32 n, TFBSound_Object *pbufobj); +void TFBSound_DeleteBuffers (uint32 n, TFBSound_Object *pbufobj); +bool TFBSound_IsBuffer (TFBSound_Object bufobj); +void TFBSound_GetBufferi (TFBSound_Object bufobj, TFBSound_BufferProp pname, + TFBSound_IntVal *value); +void TFBSound_BufferData (TFBSound_Object bufobj, uint32 format, void* data, + uint32 size, uint32 freq); + +void TFBSound_ConvertBuffer (uint32 srcfmt, void* srcdata, uint32 srcsize, + uint32 srcfreq, uint32 dstfmt, void* dstdata, + uint32 dstsize, uint32 dstfreq); + +#define TFBSound_BufferData_Linux alBufferWriteData_LOKI +enum +{ + + TFBSOUND_GAIN = 0, + TFBSOUND_BUFFER, + TFBSOUND_SOURCE_STATE, + TFBSOUND_LOOPING, + TFBSOUND_BUFFERS_PROCESSED, + TFBSOUND_BUFFERS_QUEUED, + TFBSOUND_SIZE, + TFBSOUND_ENUMSIZE +}; + +extern int TFBSOUND_PAUSED; +extern int TFBSOUND_PLAYING; +extern unsigned int TFBSOUND_NO_ERROR; +extern unsigned int TFBSOUND_FORMAT_MONO16; +extern unsigned int TFBSOUND_FORMAT_STEREO16; +extern unsigned int TFBSOUND_FORMAT_MONO8; +extern unsigned int TFBSOUND_FORMAT_STEREO8; + +#endif /* SOUNDCHOOSER_H */ diff --git a/sc2/src/sc2code/libs/sound/sound_common.c b/sc2/src/sc2code/libs/sound/sound_common.c index 75fe35d12..2dc7711a9 100644 --- a/sc2/src/sc2code/libs/sound/sound_common.c +++ b/sc2/src/sc2code/libs/sound/sound_common.c @@ -18,8 +18,11 @@ #include "libs/graphics/gfx_common.h" #include "libs/sound/sound_common.h" +#include "libs/sound/sound.h" #include "libs/tasklib.h" +int SoundDriver = TFB_SOUNDDRIVER_MIXSDL; + int musicVolume = (MAX_VOLUME >> 1); float musicVolumeScale = 1.0f; float sfxVolumeScale = 1.0f; @@ -86,3 +89,32 @@ FadeMusic (BYTE end_vol, SIZE TimeInterval) return (TimeOut); } + +int +TFB_InitSound (int driver, int flags) +{ +#ifdef HAVE_OPENAL + return (TFB_choose_InitSound (driver, flags)); +#else + if (driver == TFB_SOUNDDRIVER_OPENAL) + { + fprintf (stderr, "OpenAL driver not compiled in, so using MixSDL\n"); + driver = TFB_SOUNDDRIVER_MIXSDL; + } + return (TFB_mixSDL_InitSound (driver, flags)); +#endif +} + +void +TFB_UninitSound (void) +{ +#ifdef HAVE_OPENAL + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) + TFB_alUninitSound (); + else + TFB_mixSDL_UninitSound (); +#else + TFB_mixSDL_UninitSound (); +#endif +} + diff --git a/sc2/src/sc2code/libs/sound/sound_common.h b/sc2/src/sc2code/libs/sound/sound_common.h index ebb876011..27e9913e1 100644 --- a/sc2/src/sc2code/libs/sound/sound_common.h +++ b/sc2/src/sc2code/libs/sound/sound_common.h @@ -22,8 +22,10 @@ // driver for TFB_InitSound enum { - TFB_SOUNDDRIVER_SDL + TFB_SOUNDDRIVER_MIXSDL, + TFB_SOUNDDRIVER_OPENAL }; +extern int SoundDriver; // flags for TFB_InitSound #define TFB_SOUNDFLAGS_HQAUDIO (1<<0) // high quality audio diff --git a/sc2/src/sc2code/libs/sound/stream.c b/sc2/src/sc2code/libs/sound/stream.c index 1980d47e9..3d63c4ad1 100644 --- a/sc2/src/sc2code/libs/sound/stream.c +++ b/sc2/src/sc2code/libs/sound/stream.c @@ -14,8 +14,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if defined SOUNDMODULE_MIXSDL || defined SOUNDMODULE_OPENAL - #include #include "sound.h" @@ -325,11 +323,11 @@ StreamDecoderTaskFunc (void *data) if (decoded_bytes > 0) { -#if defined SOUNDMODULE_OPENAL && !defined (WIN32) // && !defined (MacOS and BeOS too) +#if defined HAVE_OPENAL && !defined (WIN32) // && !defined (MacOS and BeOS too) // *nix OpenAL implementation has to handle stereo data differently to avoid mixing it to mono - - if (soundSource[i].sample->decoder->format == TFBSOUND_FORMAT_STEREO8 || - soundSource[i].sample->decoder->format == TFBSOUND_FORMAT_STEREO16) + if (SoundDriver == TFB_SOUNDDRIVER_OPENAL && + (soundSource[i].sample->decoder->format == TFBSOUND_FORMAT_STEREO8 || + soundSource[i].sample->decoder->format == TFBSOUND_FORMAT_STEREO16)) { TFBSound_BufferData_Linux (buffer, soundSource[i].sample->decoder->format, soundSource[i].sample->decoder->buffer, decoded_bytes, @@ -423,4 +421,3 @@ StreamDecoderTaskFunc (void *data) return 0; } -#endif diff --git a/sc2/src/sc2code/libs/sound/trackplayer.c b/sc2/src/sc2code/libs/sound/trackplayer.c index 86cca356c..ec3656998 100644 --- a/sc2/src/sc2code/libs/sound/trackplayer.c +++ b/sc2/src/sc2code/libs/sound/trackplayer.c @@ -14,8 +14,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if defined SOUNDMODULE_MIXSDL || defined SOUNDMODULE_OPENAL - #include #include "sound.h" #include "libs/sound/trackplayer.h" @@ -699,5 +697,3 @@ GetSoundInfo (int max_len) return max_len; return (int)(max_len * offset / length); } - -#endif diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index 4ce197eb7..d66bb74c6 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -80,6 +80,7 @@ int main (int argc, char *argv[]) { int gfxdriver = TFB_GFXDRIVER_SDL_PURE; + int snddriver = TFB_SOUNDDRIVER_MIXSDL; int gfxflags = 0; int soundflags = TFB_SOUNDFLAGS_MQAUDIO; int width = 640, height = 480, bpp = 16; @@ -102,6 +103,7 @@ main (int argc, char *argv[]) {"bpp", 1, NULL, 'd'}, {"fullscreen", 0, NULL, 'f'}, {"opengl", 0, NULL, 'o'}, + {"openal", 0, NULL, 'a'}, {"scale", 1, NULL, 'c'}, {"scanlines", 0, NULL, 's'}, {"fps", 0, NULL, 'p'}, @@ -131,7 +133,7 @@ main (int argc, char *argv[]) strcpy (contentdir, "content"); #endif - while ((c = getopt_long(argc, argv, "r:d:foc:spn:?hM:S:T:m:q:ua:", long_options, &option_index)) != -1) + while ((c = getopt_long(argc, argv, "r:d:foac:spn:?hM:S:T:m:q:u", long_options, &option_index)) != -1) { switch (c) { case 'r': @@ -146,6 +148,9 @@ main (int argc, char *argv[]) case 'o': gfxdriver = TFB_GFXDRIVER_SDL_OPENGL; break; + case 'a': + snddriver = TFB_SOUNDDRIVER_OPENAL; + break; case 'c': if (!strcmp (optarg, "bilinear")) { @@ -252,6 +257,7 @@ main (int argc, char *argv[]) printf(" -d, --bpp=BITSPERPIXEL (default 16)\n"); printf(" -f, --fullscreen (default off)\n"); printf(" -o, --opengl (default off)\n"); + printf(" -a, --openal (default off)\n"); printf(" -c, --scale=mode (bilinear, biadapt or biadv, default is none)\n"); printf(" -s, --scanlines (default off)\n"); printf(" -p, --fps (default off)\n"); @@ -293,7 +299,7 @@ main (int argc, char *argv[]) init_xform_control (); TFB_InitGraphics (gfxdriver, gfxflags, width, height, bpp); - TFB_InitSound (TFB_SOUNDDRIVER_SDL, soundflags); + TFB_InitSound (snddriver, soundflags); TFB_InitInput (TFB_INPUTDRIVER_SDL, 0); AssignTask (Starcon2Main, 1024, "Starcon2Main"); diff --git a/sc2/subst b/sc2/subst index 88fbf9c1f..d8615ba63 100755 --- a/sc2/subst +++ b/sc2/subst @@ -1,3 +1,4 @@ +#!/bin/bash #!/usr/bin/bash # Substitute a string in many files. By Serge van den Boom, 20020826