Clean up trackplayer.c Hopefully this removes many of the weird crashing
issues. ZFP no longer stutter. Rewind after playing sort-of works, but still needs more work. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@689 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
Changes towards version 0.2:
|
Changes towards version 0.2:
|
||||||
|
- Fix ZFP stuttering and some other random sound issues -PBlue
|
||||||
- Correctly deal with multiply-mapped keys. This may fix some keys
|
- Correctly deal with multiply-mapped keys. This may fix some keys
|
||||||
not being detected correctly on the Mac as well - PBlue
|
not being detected correctly on the Mac as well - PBlue
|
||||||
- OpenGL mode now fully supports partial screen updates -Mika
|
- OpenGL mode now fully supports partial screen updates -Mika
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -25,7 +25,7 @@
|
|||||||
int NPCNumberPhrase (int number, UNICODE **ptrack);
|
int NPCNumberPhrase (int number, UNICODE **ptrack);
|
||||||
|
|
||||||
void
|
void
|
||||||
NPCPhrase (int index)
|
NPCPhrase_cb (int index, void (*cb) ())
|
||||||
{
|
{
|
||||||
UNICODE *pStr, numbuf[100];
|
UNICODE *pStr, numbuf[100];
|
||||||
void *pClip, *pTimeStamp;
|
void *pClip, *pTimeStamp;
|
||||||
@@ -60,6 +60,10 @@ NPCPhrase (int index)
|
|||||||
pTimeStamp = 0;
|
pTimeStamp = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
@@ -104,7 +108,7 @@ NPCPhrase (int index)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpliceTrack (pClip, pStr, pTimeStamp);
|
SpliceTrack (pClip, pStr, pTimeStamp, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ extern void DoResponsePhrase (RESPONSE_REF R, RESPONSE_FUNC
|
|||||||
response_func, UNICODE *ContstructStr);
|
response_func, UNICODE *ContstructStr);
|
||||||
extern void DoNPCPhrase (UNICODE *pStr);
|
extern void DoNPCPhrase (UNICODE *pStr);
|
||||||
|
|
||||||
extern void NPCPhrase (int index);
|
extern void NPCPhrase_cb (int index, void (*cb) ());
|
||||||
|
#define NPCPhrase(index) NPCPhrase_cb ((index), NULL)
|
||||||
|
|
||||||
extern void GetAllianceName (UNICODE *buf, RESPONSE_REF name_1);
|
extern void GetAllianceName (UNICODE *buf, RESPONSE_REF name_1);
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ typedef struct
|
|||||||
TFBSound_Object buf_name;
|
TFBSound_Object buf_name;
|
||||||
int type;
|
int type;
|
||||||
void *value;
|
void *value;
|
||||||
|
void (*callback) ();
|
||||||
} TFB_SoundTag;
|
} TFB_SoundTag;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
bool speech_advancetrack = FALSE;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlayStream (TFB_SoundSample *sample, uint32 source, bool looping, bool scope, bool rewind)
|
PlayStream (TFB_SoundSample *sample, uint32 source, bool looping, bool scope, bool rewind)
|
||||||
{
|
{
|
||||||
@@ -184,7 +182,6 @@ StreamDecoderTaskFunc (void *data)
|
|||||||
{
|
{
|
||||||
TFBSound_IntVal processed, queued;
|
TFBSound_IntVal processed, queued;
|
||||||
TFBSound_IntVal state;
|
TFBSound_IntVal state;
|
||||||
bool do_speech_advancetrack = false;
|
|
||||||
|
|
||||||
LockMutex (soundSource[i].stream_mutex);
|
LockMutex (soundSource[i].stream_mutex);
|
||||||
|
|
||||||
@@ -213,8 +210,6 @@ StreamDecoderTaskFunc (void *data)
|
|||||||
{
|
{
|
||||||
soundSource[i].sample->decoder = NULL;
|
soundSource[i].sample->decoder = NULL;
|
||||||
soundSource[i].sample->read_chain_ptr = NULL;
|
soundSource[i].sample->read_chain_ptr = NULL;
|
||||||
if (speech_advancetrack)
|
|
||||||
do_speech_advancetrack = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -404,16 +399,6 @@ StreamDecoderTaskFunc (void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
UnlockMutex (soundSource[i].stream_mutex);
|
UnlockMutex (soundSource[i].stream_mutex);
|
||||||
|
|
||||||
if (i == SPEECH_SOURCE)
|
|
||||||
{
|
|
||||||
if (do_speech_advancetrack)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "StreamDecoderTaskFunc(): calling advance_track\n");
|
|
||||||
do_speech_advancetrack = false;
|
|
||||||
advance_track (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,18 +29,21 @@ static int track_pos_changed = 0; // set whenever ff, frev is enabled
|
|||||||
|
|
||||||
|
|
||||||
#define MAX_CLIPS 50
|
#define MAX_CLIPS 50
|
||||||
|
#define is_sample_playing(samp) (((samp)->read_chain_ptr && (samp)->play_chain_ptr) ||\
|
||||||
|
(!(samp)->read_chain_ptr && (samp)->decoder))
|
||||||
static TFB_SoundSample *sound_sample = NULL;
|
static TFB_SoundSample *sound_sample = NULL;
|
||||||
static TFB_SoundChain *first_chain = NULL; //first decoder in linked list
|
static TFB_SoundChain *first_chain = NULL; //first decoder in linked list
|
||||||
static TFB_SoundChain *last_chain = NULL; //last 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 UNICODE *TrackTextArray[MAX_CLIPS]; //storage for subtitlle text
|
||||||
static Mutex track_mutex; //protects tcur and tct
|
static Mutex track_mutex; //protects tcur and tct
|
||||||
|
|
||||||
|
//JumpTrack currently aborts the current track. However, it doesn't clear the
|
||||||
|
//data-structures as StopTrack does. this allows for rewind even after the
|
||||||
|
//track has finished playing
|
||||||
|
//Question: Should 'abort' call StopTrack?
|
||||||
void
|
void
|
||||||
JumpTrack (int abort)
|
JumpTrack (int abort)
|
||||||
{
|
{
|
||||||
speech_advancetrack = FALSE;
|
|
||||||
|
|
||||||
if (sound_sample)
|
if (sound_sample)
|
||||||
{
|
{
|
||||||
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
||||||
@@ -64,51 +67,50 @@ JumpTrack (int abort)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//advance to the next track and start playing
|
||||||
|
// we no longer support advancing tracks this way. Instead this should just start playing
|
||||||
|
// a stream.
|
||||||
void
|
void
|
||||||
advance_track (int channel_finished)
|
PlayTrack (void)
|
||||||
{
|
{
|
||||||
if (channel_finished <= 0)
|
if (sound_sample && (sound_sample->read_chain_ptr || sound_sample->decoder))
|
||||||
{
|
{
|
||||||
if (sound_sample->read_chain_ptr || sound_sample->decoder)
|
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
||||||
{
|
PlayStream (sound_sample,
|
||||||
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
SPEECH_SOURCE, false,
|
||||||
PlayStream (sound_sample,
|
speechVolumeScale != 0.0f, !track_pos_changed);
|
||||||
SPEECH_SOURCE, false,
|
track_pos_changed = 0;
|
||||||
speechVolumeScale != 0.0f, !track_pos_changed);
|
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
||||||
track_pos_changed = 0;
|
}
|
||||||
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
else
|
||||||
}
|
{
|
||||||
else if (channel_finished == 0)
|
no_voice = 1;
|
||||||
{
|
|
||||||
no_voice = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResumeTrack should resume a paused track, or start a stopped track, and do nothing
|
||||||
|
// for a playing track
|
||||||
void
|
void
|
||||||
ResumeTrack ()
|
ResumeTrack ()
|
||||||
{
|
{
|
||||||
if (sound_sample && sound_sample->read_chain_ptr)
|
if (sound_sample && (sound_sample->read_chain_ptr || sound_sample->decoder))
|
||||||
{
|
{
|
||||||
|
// Only try to start the track if there is something to play
|
||||||
TFBSound_IntVal state;
|
TFBSound_IntVal state;
|
||||||
|
BOOLEAN playing;
|
||||||
|
|
||||||
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
||||||
TFBSound_GetSourcei (soundSource[SPEECH_SOURCE].handle, TFBSOUND_SOURCE_STATE, &state);
|
TFBSound_GetSourcei (soundSource[SPEECH_SOURCE].handle, TFBSOUND_SOURCE_STATE, &state);
|
||||||
|
playing = PlayingStream (SPEECH_SOURCE);
|
||||||
if (!track_pos_changed && !soundSource[SPEECH_SOURCE].stream_should_be_playing &&
|
if (!track_pos_changed && !playing && state == TFBSOUND_PAUSED)
|
||||||
state == TFBSOUND_PAUSED)
|
|
||||||
{
|
{
|
||||||
ResumeStream (SPEECH_SOURCE);
|
ResumeStream (SPEECH_SOURCE);
|
||||||
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
||||||
}
|
}
|
||||||
else if (!no_voice)
|
else if (!no_voice && ! playing)
|
||||||
{
|
{
|
||||||
if (tcur == 0)
|
|
||||||
{
|
|
||||||
speech_advancetrack = TRUE;
|
|
||||||
}
|
|
||||||
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
||||||
advance_track (-1);
|
PlayTrack ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -120,7 +122,9 @@ ResumeTrack ()
|
|||||||
COUNT
|
COUNT
|
||||||
PlayingTrack ()
|
PlayingTrack ()
|
||||||
{
|
{
|
||||||
if (sound_sample->decoder)
|
// 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 (is_sample_playing (sound_sample))
|
||||||
{
|
{
|
||||||
int last_track, last_page;
|
int last_track, last_page;
|
||||||
LockMutex (track_mutex);
|
LockMutex (track_mutex);
|
||||||
@@ -150,7 +154,6 @@ void
|
|||||||
StopTrack ()
|
StopTrack ()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
speech_advancetrack = FALSE;
|
|
||||||
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
||||||
StopStream (SPEECH_SOURCE);
|
StopStream (SPEECH_SOURCE);
|
||||||
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
|
||||||
@@ -186,6 +189,8 @@ DoTrackTag (TFB_SoundTag *tag)
|
|||||||
if (tag->type == MIX_BUFFER_TAG_TEXT)
|
if (tag->type == MIX_BUFFER_TAG_TEXT)
|
||||||
{
|
{
|
||||||
LockMutex (track_mutex);
|
LockMutex (track_mutex);
|
||||||
|
if (tag->callback)
|
||||||
|
tag->callback ();
|
||||||
tcur = ((int)tag->value) >> 8;
|
tcur = ((int)tag->value) >> 8;
|
||||||
cur_page = ((int)tag->value) & 0xFF;
|
cur_page = ((int)tag->value) & 0xFF;
|
||||||
UnlockMutex (track_mutex);
|
UnlockMutex (track_mutex);
|
||||||
@@ -308,7 +313,7 @@ SpliceMultiTrack (UNICODE *TrackNames[], UNICODE *TrackText)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SpliceTrack (UNICODE *TrackName, UNICODE *TrackText, UNICODE *TimeStamp)
|
SpliceTrack (UNICODE *TrackName, UNICODE *TrackText, UNICODE *TimeStamp, void (*cb) ())
|
||||||
{
|
{
|
||||||
unsigned long startTime;
|
unsigned long startTime;
|
||||||
if (TrackText)
|
if (TrackText)
|
||||||
@@ -372,6 +377,7 @@ SpliceTrack (UNICODE *TrackName, UNICODE *TrackText, UNICODE *TimeStamp)
|
|||||||
sound_sample->decoder = decoder;
|
sound_sample->decoder = decoder;
|
||||||
first_chain = last_chain = sound_sample->read_chain_ptr;
|
first_chain = last_chain = sound_sample->read_chain_ptr;
|
||||||
sound_sample->length = 0;
|
sound_sample->length = 0;
|
||||||
|
sound_sample->play_chain_ptr = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -395,6 +401,7 @@ SpliceTrack (UNICODE *TrackName, UNICODE *TrackText, UNICODE *TimeStamp)
|
|||||||
{
|
{
|
||||||
last_chain->tag.type = MIX_BUFFER_TAG_TEXT;
|
last_chain->tag.type = MIX_BUFFER_TAG_TEXT;
|
||||||
last_chain->tag.value = (void *)(((tct - 1) << 8) | page_counter);
|
last_chain->tag.value = (void *)(((tct - 1) << 8) | page_counter);
|
||||||
|
last_chain->tag.callback = cb;
|
||||||
}
|
}
|
||||||
no_page_break = 0;
|
no_page_break = 0;
|
||||||
}
|
}
|
||||||
@@ -428,6 +435,8 @@ void
|
|||||||
recompute_track_pos (TFB_SoundSample *sample, TFB_SoundChain *first_chain, sint32 offset)
|
recompute_track_pos (TFB_SoundSample *sample, TFB_SoundChain *first_chain, sint32 offset)
|
||||||
{
|
{
|
||||||
TFB_SoundChain *cur_chain = first_chain;
|
TFB_SoundChain *cur_chain = first_chain;
|
||||||
|
if (! sample)
|
||||||
|
return;
|
||||||
while (cur_chain->next &&
|
while (cur_chain->next &&
|
||||||
(sint32)(cur_chain->next->start_time * (float)ONE_SECOND) < offset)
|
(sint32)(cur_chain->next->start_time * (float)ONE_SECOND) < offset)
|
||||||
cur_chain = cur_chain->next;
|
cur_chain = cur_chain->next;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ void FastForward_Page();
|
|||||||
void FastReverse_Smooth();
|
void FastReverse_Smooth();
|
||||||
void FastReverse_Page();
|
void FastReverse_Page();
|
||||||
void StopTrack();
|
void StopTrack();
|
||||||
void SpliceTrack(UNICODE *filespec, UNICODE *textspec, UNICODE *TimeStamp);
|
void SpliceTrack(UNICODE *filespec, UNICODE *textspec, UNICODE *TimeStamp, void (*cb) ());
|
||||||
void SpliceMultiTrack (UNICODE *TrackNames[], UNICODE *TrackText);
|
void SpliceMultiTrack (UNICODE *TrackNames[], UNICODE *TrackText);
|
||||||
int GetSoundData (void *data);
|
int GetSoundData (void *data);
|
||||||
int GetSoundInfo (int max_len);
|
int GetSoundInfo (int max_len);
|
||||||
|
|||||||
Reference in New Issue
Block a user