From 7addbdef8f62ab1ba014c039e32d56c6c21eb652 Mon Sep 17 00:00:00 2001 From: gewlitys Date: Fri, 6 Dec 2002 02:37:01 +0000 Subject: [PATCH] Slider now moves in communications (OpenAL) git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@354 8092fc87-c524-0410-9efc-e669fe64eaf9 --- .../libs/sound/openal/decoders/decoder.c | 3 +++ .../libs/sound/openal/decoders/decoder.h | 1 + sc2/src/sc2code/libs/sound/openal/sound.h | 1 + sc2/src/sc2code/libs/sound/openal/stream.c | 3 +++ .../sc2code/libs/sound/openal/trackplayer.c | 21 ++++++++++++------- sc2/src/sc2code/oscill.c | 3 +++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/sc2/src/sc2code/libs/sound/openal/decoders/decoder.c b/sc2/src/sc2code/libs/sound/openal/decoders/decoder.c index da6916025..c684d6fd5 100644 --- a/sc2/src/sc2code/libs/sound/openal/decoders/decoder.c +++ b/sc2/src/sc2code/libs/sound/openal/decoders/decoder.c @@ -145,6 +145,7 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size) decoder->frequency = 0; decoder->looping = AL_FALSE; decoder->error = SOUNDDECODER_OK; + decoder->length = 0; // FIXME should be calculated decoder->decoder_info = decoder_info_wav; decoder->type = SOUNDDECODER_WAV; decoder->filename = (char *) malloc (strlen (filename) + 1); @@ -178,6 +179,7 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size) decoder->frequency = md_mixfreq; decoder->looping = AL_FALSE; decoder->error = SOUNDDECODER_OK; + decoder->length = 0; // FIXME way to obtain this from mikmod? decoder->decoder_info = decoder_info_mod; decoder->type = SOUNDDECODER_MOD; decoder->filename = (char *) malloc (strlen (filename) + 1); @@ -243,6 +245,7 @@ TFB_SoundDecoder* SoundDecoder_Load (char *filename, ALuint buffer_size) decoder->frequency = vinfo->rate; decoder->looping = AL_FALSE; decoder->error = SOUNDDECODER_OK; + decoder->length = (float) ov_time_total (vf, -1); decoder->decoder_info = decoder_info_ogg; decoder->type = SOUNDDECODER_OGG; decoder->filename = (char *) malloc (strlen (filename) + 1); diff --git a/sc2/src/sc2code/libs/sound/openal/decoders/decoder.h b/sc2/src/sc2code/libs/sound/openal/decoders/decoder.h index 9c38fa480..a2cbc860a 100644 --- a/sc2/src/sc2code/libs/sound/openal/decoders/decoder.h +++ b/sc2/src/sc2code/libs/sound/openal/decoders/decoder.h @@ -38,6 +38,7 @@ typedef struct tfb_sounddecoder ALuint frequency; ALboolean looping; ALint error; + float length; // total length in seconds char *decoder_info; // semi-private diff --git a/sc2/src/sc2code/libs/sound/openal/sound.h b/sc2/src/sc2code/libs/sound/openal/sound.h index 6e97d7e43..8a63b3824 100644 --- a/sc2/src/sc2code/libs/sound/openal/sound.h +++ b/sc2/src/sc2code/libs/sound/openal/sound.h @@ -55,6 +55,7 @@ typedef struct tfb_soundsource ALuint handle; BOOLEAN stream_should_be_playing; Mutex stream_mutex; + ALuint start_time; } TFB_SoundSource; diff --git a/sc2/src/sc2code/libs/sound/openal/stream.c b/sc2/src/sc2code/libs/sound/openal/stream.c index 4af6f848b..05ea2e05e 100644 --- a/sc2/src/sc2code/libs/sound/openal/stream.c +++ b/sc2/src/sc2code/libs/sound/openal/stream.c @@ -79,6 +79,7 @@ PlayStream (TFB_SoundSample *sample, ALuint source, ALboolean looping) break; } + soundSource[source].start_time = GetTimeCounter (); soundSource[source].stream_should_be_playing = TRUE; alSourcePlay (soundSource[source].handle); } @@ -108,6 +109,7 @@ StopStream (ALuint source) void PauseStream (ALuint source) { + soundSource[source].start_time = GetTimeCounter () - soundSource[source].start_time; soundSource[source].stream_should_be_playing = FALSE; alSourcePause (soundSource[source].handle); } @@ -115,6 +117,7 @@ PauseStream (ALuint source) void ResumeStream (ALuint source) { + soundSource[source].start_time = GetTimeCounter () - soundSource[source].start_time; soundSource[source].stream_should_be_playing = TRUE; alSourcePlay (soundSource[source].handle); } diff --git a/sc2/src/sc2code/libs/sound/openal/trackplayer.c b/sc2/src/sc2code/libs/sound/openal/trackplayer.c index 15fc1cb95..1284820e4 100644 --- a/sc2/src/sc2code/libs/sound/openal/trackplayer.c +++ b/sc2/src/sc2code/libs/sound/openal/trackplayer.c @@ -260,15 +260,22 @@ GetSoundData (char* data) return 0; } -// Status: Unimplemented int GetSoundInfo (int *length, int *offset) - // Umm... How does it know which sound? - // Answer: only used in oscill.c slider so sound must be current speech -{ - //fprintf (stderr, "Unimplemented function activated: GetSoundInfo()\n"); - *length = 1; - *offset = 0; +{ + LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); + if (soundSource[SPEECH_SOURCE].sample && soundSource[SPEECH_SOURCE].sample->decoder) + { + *length = (int) (soundSource[SPEECH_SOURCE].sample->decoder->length * (float)ONE_SECOND); + *offset = (int) (GetTimeCounter () - soundSource[SPEECH_SOURCE].start_time); + } + else + { + *length = 1; + *offset = 0; + } + UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); + return 1; } diff --git a/sc2/src/sc2code/oscill.c b/sc2/src/sc2code/oscill.c index 3060a6e46..ad7e43c21 100644 --- a/sc2/src/sc2code/oscill.c +++ b/sc2/src/sc2code/oscill.c @@ -17,6 +17,7 @@ */ #include "libs/graphics/gfx_common.h" +#include "libs/sound/trackplayer.h" //Added by Chris //Modified by Mika (removed use of SDL datatypes) @@ -206,6 +207,8 @@ Slider (void) { if (offs > len) offs = len; + if (len == 0) + len = 1; buttonStamp.origin.x = sliderStamp.origin.x + sliderSpace * offs / len; BatchGraphics (); DrawStamp (&sliderStamp);