From 9622db8e44ed6a49af77b643a9d700212ba95a7b Mon Sep 17 00:00:00 2001 From: ghaushe Date: Thu, 6 Feb 2003 18:38:07 +0000 Subject: [PATCH] Slider and ff/frew should now behave well when track ends git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@704 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 1 + sc2/src/sc2code/comm.c | 12 +++--- sc2/src/sc2code/libs/sound/trackplayer.c | 47 ++++++++++++++++++------ sc2/src/sc2code/oscill.c | 5 ++- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 4db8dae6a..f424fafe9 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.2: +- Slider should now work correctly everywhere -PhracturedBlue - Added 'nosound' driver and --sound=openal|mixsdl|none option; -a option has been removed -fOSSiL - Fix ZFP stuttering and some other random sound issues -PBlue diff --git a/sc2/src/sc2code/comm.c b/sc2/src/sc2code/comm.c index cd8179e84..0b313ac39 100644 --- a/sc2/src/sc2code/comm.c +++ b/sc2/src/sc2code/comm.c @@ -1164,6 +1164,7 @@ SpewPhrases (COUNT wait_track) COUNT which_track; INPUT_STATE InputState, LastInputState = (INPUT_STATE)~0; FRAME F; + BOOLEAN passed = TRUE; TimeIn = GetTimeCounter (); @@ -1252,11 +1253,9 @@ Rewind: } else { - CommData.AlienFrame = F; - if (! which_track) - return (FALSE); - else - return (TRUE); + ContinuityBreak = FALSE; + passed = (which_track != 0); + break; } ContinuityBreak = FALSE; } @@ -1272,8 +1271,7 @@ Rewind: if (wait_track == (COUNT)~0) SetSliderImage (SetAbsFrameIndex (ActivityFrame, 8)); - - return (TRUE); + return (passed); } void diff --git a/sc2/src/sc2code/libs/sound/trackplayer.c b/sc2/src/sc2code/libs/sound/trackplayer.c index 6ccd06eb8..e7f4f9e3f 100644 --- a/sc2/src/sc2code/libs/sound/trackplayer.c +++ b/sc2/src/sc2code/libs/sound/trackplayer.c @@ -36,6 +36,8 @@ static TFB_SoundChain *first_chain = NULL; //first decoder in linked list static TFB_SoundChain *last_chain = NULL; //last decoder in linked list static UNICODE *TrackTextArray[MAX_CLIPS]; //storage for subtitlle text static Mutex track_mutex; //protects tcur and tct +void recompute_track_pos (TFB_SoundSample *sample, + TFB_SoundChain *first_chain, sint32 offset); //JumpTrack currently aborts the current track. However, it doesn't clear the //data-structures as StopTrack does. this allows for rewind even after the @@ -46,14 +48,20 @@ JumpTrack (int abort) { if (sound_sample) { + uint32 cur_time; + sint32 total_length = (sint32)((last_chain->start_time + + last_chain->decoder->length) * (float)ONE_SECOND); LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); - StopStream (SPEECH_SOURCE); - if (abort) - { - sound_sample->read_chain_ptr = NULL; - sound_sample->decoder = NULL; - } + PauseStream (SPEECH_SOURCE); + cur_time = GetTimeCounter(); + soundSource[SPEECH_SOURCE].start_time = + (sint32)cur_time - total_length;; + track_pos_changed = 1; + sound_sample->play_chain_ptr = last_chain; + recompute_track_pos(sound_sample, first_chain, total_length); UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); + PlayingTrack(); + return; } no_voice = 1; @@ -124,6 +132,8 @@ PlayingTrack () { // this is not a great way to detect whether the track is playing, // but as it should work during fast-forward/rewind, 'PlayingStream' can't be used +// if (tct == 0) +// return ((COUNT)~0); if (sound_sample && is_sample_playing (sound_sample)) { int last_track, last_page; @@ -461,18 +471,26 @@ FastReverse_Smooth () if (sound_sample) { sint32 offset; + uint32 cur_time; + sint32 total_length = (sint32)((last_chain->start_time + + last_chain->decoder->length) * (float)ONE_SECOND); LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); PauseStream (SPEECH_SOURCE); + cur_time = GetTimeCounter(); track_pos_changed = 1; + if ((sint32)cur_time - soundSource[SPEECH_SOURCE].start_time > total_length) + soundSource[SPEECH_SOURCE].start_time = + (sint32)cur_time - total_length; + soundSource[SPEECH_SOURCE].start_time += ACCEL_SCROLL_SPEED; - if (soundSource[SPEECH_SOURCE].start_time > (sint32)GetTimeCounter()) + if (soundSource[SPEECH_SOURCE].start_time > (sint32)cur_time) { - soundSource[SPEECH_SOURCE].start_time = GetTimeCounter(); + soundSource[SPEECH_SOURCE].start_time = cur_time; offset = 0; } else - offset = GetTimeCounter() - soundSource[SPEECH_SOURCE].start_time; - recompute_track_pos(soundSource[SPEECH_SOURCE].sample, first_chain, offset); + offset = cur_time - soundSource[SPEECH_SOURCE].start_time; + recompute_track_pos(sound_sample, first_chain, offset); UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); PlayingTrack(); @@ -504,10 +522,17 @@ FastForward_Smooth () if (sound_sample) { sint32 offset; + uint32 cur_time; + sint32 total_length = (sint32)((last_chain->start_time + + last_chain->decoder->length) * (float)ONE_SECOND); LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); PauseStream (SPEECH_SOURCE); + cur_time = GetTimeCounter(); soundSource[SPEECH_SOURCE].start_time -= ACCEL_SCROLL_SPEED; - offset = GetTimeCounter() - soundSource[SPEECH_SOURCE].start_time; + if ((sint32)cur_time - soundSource[SPEECH_SOURCE].start_time > total_length) + soundSource[SPEECH_SOURCE].start_time = + (sint32)cur_time - total_length; + offset = cur_time - soundSource[SPEECH_SOURCE].start_time; track_pos_changed = 1; recompute_track_pos(sound_sample, first_chain, offset); UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); diff --git a/sc2/src/sc2code/oscill.c b/sc2/src/sc2code/oscill.c index edfe88f61..3f24bb7ea 100644 --- a/sc2/src/sc2code/oscill.c +++ b/sc2/src/sc2code/oscill.c @@ -21,6 +21,7 @@ static STAMP sliderStamp; static STAMP buttonStamp; +static BOOLEAN sliderChanged = FALSE; int sliderSpace; // slider width - button width @@ -50,6 +51,7 @@ InitSlider (int x, int y, int width, int height, void SetSliderImage (FRAME f) { + sliderChanged = TRUE; buttonStamp.frame = f; } @@ -59,8 +61,9 @@ Slider (void) int offs; static int last_offs = -1; - if ((offs = GetSoundInfo (sliderSpace)) != last_offs) + if ((offs = GetSoundInfo (sliderSpace)) != last_offs ||sliderChanged) { + sliderChanged = FALSE; last_offs = offs; buttonStamp.origin.x = sliderStamp.origin.x + offs; BatchGraphics ();