From b4acbace786cd3b5a559f1a1de232701a1feec27 Mon Sep 17 00:00:00 2001 From: gewlitys Date: Thu, 24 Oct 2002 20:33:59 +0000 Subject: [PATCH] Commandline switch between PC and 3DO musics, OpenAL code fixes git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@145 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/TODO | 1 - sc2/src/Makefile.am | 4 +-- sc2/src/msvc++/Starcon2.dsp | 8 +++++ sc2/src/sc2code/libs/sound/openal/music.c | 36 ++++++++++++++++--- sc2/src/sc2code/libs/sound/openal/sfx.c | 3 +- sc2/src/sc2code/libs/sound/openal/sound.c | 1 + sc2/src/sc2code/libs/sound/openal/sound.h | 2 +- sc2/src/sc2code/libs/sound/openal/stream.c | 28 ++++++++++++--- sc2/src/sc2code/libs/sound/openal/stream.h | 4 +-- .../sc2code/libs/sound/openal/trackplayer.c | 21 +++++++---- sc2/src/starcon2.c | 22 ++++++------ 11 files changed, 96 insertions(+), 34 deletions(-) diff --git a/sc2/TODO b/sc2/TODO index d32283188..c08517d57 100644 --- a/sc2/TODO +++ b/sc2/TODO @@ -72,7 +72,6 @@ Glitches (don't crash the game, medium priority): - Occasional clipping/popping/etc artifacts - Maybe caused by buggy soundcard drivers also - Some unimplemented functions (for oscilloscope and dialogue seeking) - - Occasionally some speech oggs don't play - When mod music is looping, there's some volume fade at the end of tune, then it starts playing again. This shouldn't happen? (modplug only?) - Stock SDL_sound package for VC is outdated and win32 users have to get diff --git a/sc2/src/Makefile.am b/sc2/src/Makefile.am index 7bce3b199..db57b2072 100644 --- a/sc2/src/Makefile.am +++ b/sc2/src/Makefile.am @@ -9,7 +9,7 @@ INCLUDES = @SDL_CFLAGS@ \ bin_PROGRAMS = sc2 -sc2_SOURCES = port.c starcon2.c +sc2_SOURCES = port.c starcon2.c options.c sc2_LDADD = sc2code/libsc2.la @SDL_LIBS@ @GL_LIBS@ -noinst_HEADERS = port.h +noinst_HEADERS = port.h options.h diff --git a/sc2/src/msvc++/Starcon2.dsp b/sc2/src/msvc++/Starcon2.dsp index f556fee65..144b5ff88 100644 --- a/sc2/src/msvc++/Starcon2.dsp +++ b/sc2/src/msvc++/Starcon2.dsp @@ -3092,6 +3092,14 @@ SOURCE=..\port.h # End Source File # Begin Source File +SOURCE=..\options.c +# End Source File +# Begin Source File + +SOURCE=..\options.h +# End Source File +# Begin Source File + SOURCE=..\starcon2.c # End Source File # End Group diff --git a/sc2/src/sc2code/libs/sound/openal/music.c b/sc2/src/sc2code/libs/sound/openal/music.c index aee085ce8..73f39999a 100644 --- a/sc2/src/sc2code/libs/sound/openal/music.c +++ b/sc2/src/sc2code/libs/sound/openal/music.c @@ -20,6 +20,7 @@ #ifdef SOUNDMODULE_OPENAL #include "sound.h" +#include "options.h" static MUSIC_REF curMusicRef; @@ -102,7 +103,7 @@ DestroyMusic (MUSIC_REF MusicRef) void SetMusicVolume (COUNT Volume) -{ +{ float f = (Volume / (ALfloat)MAX_VOLUME) * musicVolumeScale; musicVolume = Volume; alSourcef (soundSource[MUSIC_SOURCE].handle, AL_GAIN, f); @@ -128,11 +129,36 @@ _GetMusicData (FILE *fp, DWORD length) } else { - *pmus = (TFB_SoundSample *) HMalloc (sizeof (TFB_SoundSample)); - - if (((*pmus)->decoder = Sound_NewSampleFromFile (_cur_resfile_name, NULL, 4096)) == 0) + char filename[1000]; + + *pmus = (TFB_SoundSample *) HMalloc (sizeof (TFB_SoundSample)); + strcpy (filename, _cur_resfile_name); + + switch (optWhichMusic) + { + default: + case MUSIC_3DO: + { + char threedoname[1000]; + + strcpy (threedoname, filename); + strcpy (&threedoname[strlen (threedoname)-3], "ogg"); + if (FileExists (threedoname)) + { + strcpy (filename, threedoname); + } + break; + } + case MUSIC_PC: + { + break; + } + } + + fprintf (stderr, "_GetMusicData(): loading %s\n", filename); + if (((*pmus)->decoder = Sound_NewSampleFromFile (filename, NULL, 4096)) == 0) { - fprintf (stderr, "_GetMusicData(): couldn't load %s\n", _cur_resfile_name); + fprintf (stderr, "_GetMusicData(): couldn't load %s\n", filename); UnlockMusicData (h); mem_release (h); diff --git a/sc2/src/sc2code/libs/sound/openal/sfx.c b/sc2/src/sc2code/libs/sound/openal/sfx.c index adad7caab..bb19b8af8 100644 --- a/sc2/src/sc2code/libs/sound/openal/sfx.c +++ b/sc2/src/sc2code/libs/sound/openal/sfx.c @@ -235,7 +235,8 @@ _ReleaseSoundBankData (MEM_HANDLE Snd) sptr = (TFB_SoundSample **)((BYTE *)fxTab + fxTab->StringOffsets[0]); while (snd_ct--) { - Sound_FreeSample ((*sptr)->decoder); + if ((*sptr)->decoder) + Sound_FreeSample ((*sptr)->decoder); alDeleteBuffers (NUM_SOUNDBUFFERS, (*sptr)->buffer); HFree (*sptr); *sptr++ = 0; diff --git a/sc2/src/sc2code/libs/sound/openal/sound.c b/sc2/src/sc2code/libs/sound/openal/sound.c index 01f88045c..ae64762df 100644 --- a/sc2/src/sc2code/libs/sound/openal/sound.c +++ b/sc2/src/sc2code/libs/sound/openal/sound.c @@ -64,6 +64,7 @@ TFB_InitSound (int driver, int flags, int frequency) fprintf (stderr, " renderer: %s\n", alGetString (AL_RENDERER)); fprintf (stderr, " device: %s\n", alcGetString (alcDevice, ALC_DEFAULT_DEVICE_SPECIFIER)); + fprintf (stderr, " extensions: %s\n", alGetString (AL_EXTENSIONS)); fprintf (stderr, "Initializing SDL_sound.\n"); if (!Sound_Init()) diff --git a/sc2/src/sc2code/libs/sound/openal/sound.h b/sc2/src/sc2code/libs/sound/openal/sound.h index 48ec240b1..10026f773 100644 --- a/sc2/src/sc2code/libs/sound/openal/sound.h +++ b/sc2/src/sc2code/libs/sound/openal/sound.h @@ -33,7 +33,7 @@ #endif -#define NUM_SOUNDBUFFERS 8 +#define NUM_SOUNDBUFFERS 10 #define FIRST_SFX_SOURCE 0 #define LAST_SFX_SOURCE 4 #define MUSIC_SOURCE (LAST_SFX_SOURCE + 1) diff --git a/sc2/src/sc2code/libs/sound/openal/stream.c b/sc2/src/sc2code/libs/sound/openal/stream.c index 35e88374f..ff0975bd2 100644 --- a/sc2/src/sc2code/libs/sound/openal/stream.c +++ b/sc2/src/sc2code/libs/sound/openal/stream.c @@ -21,7 +21,7 @@ #include "sound.h" -BOOLEAN speech_callback = FALSE; +BOOLEAN speech_advancetrack = FALSE; void @@ -115,9 +115,10 @@ StreamDecoderTaskFunc (void *data) for (i = MUSIC_SOURCE; i < NUM_SOUNDSOURCES; ++i) { ALuint processed; - //ALuint queued; + ALuint queued; ALint state; ALboolean finished = AL_FALSE; + ALboolean do_speech_advancetrack = AL_FALSE; LockMutex (soundSource[i].stream_mutex); @@ -142,7 +143,13 @@ StreamDecoderTaskFunc (void *data) } } - //alGetSourcei (soundSource[i].handle, AL_BUFFERS_QUEUED, &queued); + alGetSourcei (soundSource[i].handle, AL_BUFFERS_QUEUED, &queued); + if (queued != NUM_SOUNDBUFFERS) + { + fprintf (stderr, "StreamDecoderTaskFunc(): warning, queued %d != NUM_SOUNDBUFFERS %d\n", + queued, NUM_SOUNDBUFFERS); + } + //fprintf (stderr, "StreamDecoderTaskFunc(): source %d, processed %d queued %d\n", i, processed, queued); while (processed && !finished) @@ -161,14 +168,15 @@ StreamDecoderTaskFunc (void *data) } decoded_bytes = Sound_Decode (soundSource[i].sample->decoder); + //fprintf (stderr, "StreamDecoderTaskFunc(): decoded_bytes %d, source %d\n", decoded_bytes, i); if (soundSource[i].sample->decoder->flags & SOUND_SAMPLEFLAG_EOF) { - if (i == SPEECH_SOURCE && speech_callback) + if (i == SPEECH_SOURCE && speech_advancetrack) { - advance_track (0); finished = AL_TRUE; soundSource[i].stream_should_be_playing = FALSE; + do_speech_advancetrack = AL_TRUE; } else { @@ -228,6 +236,16 @@ StreamDecoderTaskFunc (void *data) } UnlockMutex (soundSource[i].stream_mutex); + + if (i == SPEECH_SOURCE) + { + if (do_speech_advancetrack) + { + //fprintf (stderr, "StreamDecoderTaskFunc(): calling advance_track\n"); + do_speech_advancetrack = AL_FALSE; + advance_track (0); + } + } } } diff --git a/sc2/src/sc2code/libs/sound/openal/stream.h b/sc2/src/sc2code/libs/sound/openal/stream.h index 6260a39d6..fa978419b 100644 --- a/sc2/src/sc2code/libs/sound/openal/stream.h +++ b/sc2/src/sc2code/libs/sound/openal/stream.h @@ -14,7 +14,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* OpenAL specific code by Mika Kolehmainen, 2002-10-23 +/* By Mika Kolehmainen, 2002-10-23 */ #ifndef STREAM_H @@ -27,7 +27,7 @@ void ResumeStream (ALuint source); BOOLEAN PlayingStream (ALuint source); int StreamDecoderTaskFunc (void *data); -extern BOOLEAN speech_callback; +extern BOOLEAN speech_advancetrack; void advance_track (int channel_finished); #endif diff --git a/sc2/src/sc2code/libs/sound/openal/trackplayer.c b/sc2/src/sc2code/libs/sound/openal/trackplayer.c index a72367a27..9a718cb41 100644 --- a/sc2/src/sc2code/libs/sound/openal/trackplayer.c +++ b/sc2/src/sc2code/libs/sound/openal/trackplayer.c @@ -38,7 +38,7 @@ static struct void JumpTrack (int abort) { - speech_callback = FALSE; + speech_advancetrack = FALSE; if (track_clip[tcur].sample) { @@ -85,12 +85,10 @@ ResumeTrack () LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); alGetSourcei (soundSource[SPEECH_SOURCE].handle, AL_SOURCE_STATE, &state); - UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); if (!soundSource[SPEECH_SOURCE].stream_should_be_playing && state == AL_PAUSED) { - LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); ResumeStream (SPEECH_SOURCE); UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); } @@ -98,10 +96,15 @@ ResumeTrack () { if (tcur == 0) { - speech_callback = TRUE; + speech_advancetrack = TRUE; } + UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); advance_track (-1); } + else + { + UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); + } } } @@ -133,7 +136,7 @@ PlayingTrack () void StopTrack () { - speech_callback = FALSE; + speech_advancetrack = FALSE; LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); StopStream (SPEECH_SOURCE); UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); @@ -223,8 +226,12 @@ SpliceTrack (UNICODE *TrackName, UNICODE *TrackText) void PauseTrack () { - /*if (tcur < tct && track_clip[tcur].chunk) - Mix_Pause (VOICE_CHANNEL);*/ + if (tcur < tct && track_clip[tcur].sample) + { + LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); + PauseStream (SPEECH_SOURCE); + UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); + } } void diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index 8042f399f..9231ef19e 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -28,16 +28,8 @@ #include "libs/sound/sound_common.h" #include "libs/input/input_common.h" #include "libs/tasklib.h" +#include "options.h" -BOOLEAN FileExists (char *filename) -{ - FILE *fp; - if ((fp = fopen(filename, "rb")) == NULL) - return FALSE; - - fclose (fp); - return TRUE; -} void CDToContentDir (char *contentdir) @@ -80,6 +72,8 @@ main (int argc, char *argv[]) {"musicvol", 1, NULL, 'M'}, {"sfxvol", 1, NULL, 'S'}, {"speechvol", 1, NULL, 'T'}, + {"3domusic", 0, NULL, 'e'}, + {"pcmusic", 0, NULL, 'm'}, {0, 0, 0, 0} }; @@ -89,7 +83,7 @@ main (int argc, char *argv[]) strcpy (contentdir, "../../content"); #endif - while ((c = getopt_long(argc, argv, "r:d:fobq:ptc:?hM:S:T:", long_options, &option_index)) != -1) + while ((c = getopt_long(argc, argv, "r:d:fobq:ptc:?hM:S:T:em", long_options, &option_index)) != -1) { switch (c) { case 'r': @@ -143,6 +137,12 @@ main (int argc, char *argv[]) vol = 100; speechVolumeScale = vol / 100.0f; break; + case 'e': + optWhichMusic = MUSIC_3DO; + break; + case 'm': + optWhichMusic = MUSIC_PC; + break; default: printf ("\nOption %s not found!\n", long_options[option_index].name); case '?': @@ -161,6 +161,8 @@ main (int argc, char *argv[]) printf(" -M, --musicvol=VOLUME (0-100)\n"); printf(" -S, --sfxvol=VOLUME (0-100)\n"); printf(" -T, --speechvol=VOLUME (0-100)\n"); + printf(" -e, --3domusic\n"); + printf(" -m, --pcmusic\n"); return 0; break; }