* fix o-scope problems with ff/frev and the streaming code
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@604 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -93,7 +93,7 @@ TFB_InitSound (int driver, int flags)
|
||||
soundSource[i].sbuffer = NULL;
|
||||
soundSource[i].sbuf_start = 0;
|
||||
soundSource[i].sbuf_size = 0;
|
||||
soundSource[i].total_decoded = 0;
|
||||
soundSource[i].sbuf_offset = 0;
|
||||
}
|
||||
|
||||
SetSFXVolume (sfxVolumeScale);
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#define MUSIC_SOURCE (LAST_SFX_SOURCE + 1)
|
||||
#define SPEECH_SOURCE (MUSIC_SOURCE + 1)
|
||||
#define NUM_SOUNDSOURCES (SPEECH_SOURCE + 1)
|
||||
#define PAD_SCOPE_BYTES 8096
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -78,7 +79,8 @@ typedef struct tfb_soundsource
|
||||
void *sbuffer;
|
||||
uint32 sbuf_start;
|
||||
uint32 sbuf_size;
|
||||
uint32 total_decoded;
|
||||
uint32 sbuf_offset;
|
||||
uint32 sbuf_lasttime;
|
||||
} TFB_SoundSource;
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +53,8 @@ PlayStream (TFB_SoundSample *sample, uint32 source, bool looping, bool scope, bo
|
||||
|
||||
if (scope)
|
||||
{
|
||||
soundSource[source].sbuffer = NULL;
|
||||
pos = PAD_SCOPE_BYTES;
|
||||
soundSource[source].sbuffer = HMalloc (pos);
|
||||
}
|
||||
|
||||
if (sample->read_chain_ptr && sample->read_chain_ptr->tag.type)
|
||||
@@ -79,11 +80,8 @@ PlayStream (TFB_SoundSample *sample, uint32 source, bool looping, bool scope, bo
|
||||
if (scope)
|
||||
{
|
||||
UBYTE *p;
|
||||
if (! soundSource[source].sbuffer)
|
||||
soundSource[source].sbuffer = HMalloc (decoded_bytes);
|
||||
else
|
||||
soundSource[source].sbuffer = HRealloc (soundSource[source].sbuffer,
|
||||
pos + decoded_bytes);
|
||||
soundSource[source].sbuffer = HRealloc (soundSource[source].sbuffer,
|
||||
pos + decoded_bytes);
|
||||
p = (UBYTE *)soundSource[source].sbuffer;
|
||||
memcpy (&p[pos], sample->decoder->buffer, decoded_bytes);
|
||||
pos += decoded_bytes;
|
||||
@@ -112,6 +110,8 @@ PlayStream (TFB_SoundSample *sample, uint32 source, bool looping, bool scope, bo
|
||||
for ( ; i <sample->num_buffers; ++i)
|
||||
sample->buffer_tag[i] = 0;
|
||||
soundSource[source].sbuf_size = pos;
|
||||
soundSource[source].sbuf_start = pos - PAD_SCOPE_BYTES;
|
||||
soundSource[source].sbuf_lasttime = GetTimeCounter ();
|
||||
soundSource[source].start_time = (sint32)GetTimeCounter () - offset;
|
||||
soundSource[source].stream_should_be_playing = TRUE;
|
||||
mixSDL_SourcePlay (soundSource[source].handle);
|
||||
@@ -134,7 +134,7 @@ StopStream (uint32 source)
|
||||
}
|
||||
soundSource[source].sbuf_start = 0;
|
||||
soundSource[source].sbuf_size = 0;
|
||||
soundSource[source].total_decoded = 0;
|
||||
soundSource[source].sbuf_offset = 0;
|
||||
|
||||
mixSDL_SourceStop (soundSource[source].handle);
|
||||
mixSDL_GetSourcei (soundSource[source].handle, MIX_BUFFERS_PROCESSED, &processed);
|
||||
@@ -268,8 +268,15 @@ StreamDecoderTaskFunc (void *data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
soundSource[i].total_decoded += soundSource[i].sample->decoder->buffer_size;
|
||||
{
|
||||
uint32 buf_size;
|
||||
soundSource[i].sbuf_lasttime = GetTimeCounter ();
|
||||
mixSDL_GetBufferi(buffer, MIX_SIZE, &buf_size);
|
||||
soundSource[i].sbuf_offset += buf_size;
|
||||
if (soundSource[i].sbuf_offset > soundSource[i].sbuf_size)
|
||||
soundSource[i].sbuf_offset -= soundSource[i].sbuf_size;
|
||||
}
|
||||
//soundSource[i].total_decoded += soundSource[i].sample->decoder->buffer_size;
|
||||
|
||||
if (soundSource[i].sample->decoder->error)
|
||||
{
|
||||
|
||||
@@ -544,12 +544,12 @@ GetSoundData (void *data)
|
||||
PlayingStream (SPEECH_SOURCE) && soundSource[SPEECH_SOURCE].sbuffer &&
|
||||
soundSource[SPEECH_SOURCE].sbuf_size > 0)
|
||||
{
|
||||
float played_time = (GetTimeCounter () - soundSource[SPEECH_SOURCE].start_time) /
|
||||
float played_time = (GetTimeCounter () - soundSource[SPEECH_SOURCE].sbuf_lasttime) /
|
||||
(float)ONE_SECOND;
|
||||
int played_data = (int) (played_time * (float)soundSource[SPEECH_SOURCE].
|
||||
long delta = (int) (played_time * (float)soundSource[SPEECH_SOURCE].
|
||||
sample->decoder->frequency * 2.0f);
|
||||
int delta = played_data - soundSource[SPEECH_SOURCE].total_decoded;
|
||||
unsigned int pos, i;
|
||||
unsigned long pos;
|
||||
int i;
|
||||
UBYTE *scopedata = (UBYTE *) data;
|
||||
UBYTE *sbuffer = soundSource[SPEECH_SOURCE].sbuffer;
|
||||
|
||||
@@ -569,7 +569,7 @@ GetSoundData (void *data)
|
||||
|
||||
//fprintf (stderr, "played_data %d total_decoded %d delta %d\n", played_data, soundSource[SPEECH_SOURCE].total_decoded, delta);
|
||||
|
||||
pos = soundSource[SPEECH_SOURCE].sbuf_start + delta;
|
||||
pos = soundSource[SPEECH_SOURCE].sbuf_offset + delta;
|
||||
if (pos % 2 == 1)
|
||||
pos++;
|
||||
|
||||
@@ -612,12 +612,12 @@ GetSoundData (void *data)
|
||||
PlayingStream (MUSIC_SOURCE) && soundSource[MUSIC_SOURCE].sbuffer &&
|
||||
soundSource[MUSIC_SOURCE].sbuf_size > 0)
|
||||
{
|
||||
float played_time = (GetTimeCounter () - soundSource[MUSIC_SOURCE].start_time) /
|
||||
float played_time = (GetTimeCounter () - soundSource[MUSIC_SOURCE].sbuf_lasttime) /
|
||||
(float)ONE_SECOND;
|
||||
int played_data = (int) (played_time * (float)soundSource[MUSIC_SOURCE].
|
||||
int delta = (int) (played_time * (float)soundSource[MUSIC_SOURCE].
|
||||
sample->decoder->frequency * 4.0f);
|
||||
int delta = played_data - soundSource[MUSIC_SOURCE].total_decoded;
|
||||
unsigned int pos, i, step;
|
||||
unsigned long pos;
|
||||
int i, step;
|
||||
UBYTE *scopedata = (UBYTE *) data;
|
||||
UBYTE *sbuffer = soundSource[MUSIC_SOURCE].sbuffer;
|
||||
|
||||
@@ -641,7 +641,7 @@ GetSoundData (void *data)
|
||||
|
||||
//fprintf (stderr, "played_data %d total_decoded %d delta %d\n", played_data, soundSource[MUSIC_SOURCE].total_decoded, delta);
|
||||
|
||||
pos = soundSource[MUSIC_SOURCE].sbuf_start + delta;
|
||||
pos = soundSource[SPEECH_SOURCE].sbuf_offset + delta;
|
||||
if (pos % 2 == 1)
|
||||
pos++;
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ TFB_InitSound (int driver, int flags)
|
||||
soundSource[i].sbuffer = NULL;
|
||||
soundSource[i].sbuf_start = 0;
|
||||
soundSource[i].sbuf_size = 0;
|
||||
soundSource[i].total_decoded = 0;
|
||||
soundSource[i].sbuf_offset = 0;
|
||||
}
|
||||
|
||||
SetSFXVolume (sfxVolumeScale);
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#define MUSIC_SOURCE (LAST_SFX_SOURCE + 1)
|
||||
#define SPEECH_SOURCE (MUSIC_SOURCE + 1)
|
||||
#define NUM_SOUNDSOURCES (SPEECH_SOURCE + 1)
|
||||
#define PAD_SCOPE_BYTES 8096
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -88,7 +89,8 @@ typedef struct tfb_soundsource
|
||||
void *sbuffer;
|
||||
ALuint sbuf_start;
|
||||
ALuint sbuf_size;
|
||||
ALuint total_decoded;
|
||||
ALuint sbuf_offset;
|
||||
ALuint sbuf_lasttime;
|
||||
} TFB_SoundSource;
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,8 @@ PlayStream (TFB_SoundSample *sample, ALuint source, ALboolean looping,
|
||||
|
||||
if (scope)
|
||||
{
|
||||
soundSource[source].sbuffer = NULL;
|
||||
pos = PAD_SCOPE_BYTES;
|
||||
soundSource[source].sbuffer = HMalloc (pos);
|
||||
}
|
||||
|
||||
if (sample->read_chain_ptr && sample->read_chain_ptr->tag.type)
|
||||
@@ -98,11 +99,8 @@ PlayStream (TFB_SoundSample *sample, ALuint source, ALboolean looping,
|
||||
if (scope)
|
||||
{
|
||||
UBYTE *p;
|
||||
if (! soundSource[source].sbuffer)
|
||||
soundSource[source].sbuffer = HMalloc (decoded_bytes);
|
||||
else
|
||||
soundSource[source].sbuffer = HRealloc (soundSource[source].sbuffer,
|
||||
pos + decoded_bytes);
|
||||
soundSource[source].sbuffer = HRealloc (soundSource[source].sbuffer,
|
||||
pos + decoded_bytes);
|
||||
p = (UBYTE *)soundSource[source].sbuffer;
|
||||
memcpy (&p[pos], sample->decoder->buffer, decoded_bytes);
|
||||
pos += decoded_bytes;
|
||||
@@ -131,6 +129,8 @@ PlayStream (TFB_SoundSample *sample, ALuint source, ALboolean looping,
|
||||
for ( ; i <sample->num_buffers; ++i)
|
||||
sample->buffer_tag[i] = 0;
|
||||
soundSource[source].sbuf_size = pos;
|
||||
soundSource[source].sbuf_start = pos - PAD_SCOPE_BYTES;
|
||||
soundSource[source].sbuf_lasttime = GetTimeCounter ();
|
||||
soundSource[source].start_time = (ALint)GetTimeCounter () - offset;
|
||||
soundSource[source].stream_should_be_playing = TRUE;
|
||||
alSourcePlay (soundSource[source].handle);
|
||||
@@ -153,7 +153,7 @@ StopStream (ALuint source)
|
||||
}
|
||||
soundSource[source].sbuf_start = 0;
|
||||
soundSource[source].sbuf_size = 0;
|
||||
soundSource[source].total_decoded = 0;
|
||||
soundSource[source].sbuf_offset = 0;
|
||||
|
||||
alSourceStop (soundSource[source].handle);
|
||||
alGetSourcei (soundSource[source].handle, AL_BUFFERS_PROCESSED, &processed);
|
||||
@@ -288,7 +288,14 @@ StreamDecoderTaskFunc (void *data)
|
||||
}
|
||||
}
|
||||
|
||||
soundSource[i].total_decoded += soundSource[i].sample->decoder->buffer_size;
|
||||
{
|
||||
ALuint buf_size;
|
||||
soundSource[i].sbuf_lasttime = GetTimeCounter ();
|
||||
alGetBufferi(buffer, AL_SIZE, &buf_size);
|
||||
soundSource[i].sbuf_offset += buf_size;
|
||||
if (soundSource[i].sbuf_offset > soundSource[i].sbuf_size)
|
||||
soundSource[i].sbuf_offset -= soundSource[i].sbuf_size;
|
||||
}
|
||||
|
||||
if (soundSource[i].sample->decoder->error)
|
||||
{
|
||||
|
||||
@@ -544,12 +544,11 @@ GetSoundData (void *data)
|
||||
PlayingStream (SPEECH_SOURCE) && soundSource[SPEECH_SOURCE].sbuffer &&
|
||||
soundSource[SPEECH_SOURCE].sbuf_size > 0)
|
||||
{
|
||||
float played_time = (GetTimeCounter () - soundSource[SPEECH_SOURCE].start_time) /
|
||||
float played_time = (GetTimeCounter () - soundSource[SPEECH_SOURCE].sbuf_lasttime) /
|
||||
(float)ONE_SECOND;
|
||||
int played_data = (int) (played_time * (float)soundSource[SPEECH_SOURCE].
|
||||
int delta = (int) (played_time * (float)soundSource[SPEECH_SOURCE].
|
||||
sample->decoder->frequency * 2.0f);
|
||||
int delta = played_data - soundSource[SPEECH_SOURCE].total_decoded;
|
||||
unsigned int pos, i;
|
||||
unsigned long pos, i;
|
||||
UBYTE *scopedata = (UBYTE *) data;
|
||||
UBYTE *sbuffer = soundSource[SPEECH_SOURCE].sbuffer;
|
||||
|
||||
@@ -569,7 +568,7 @@ GetSoundData (void *data)
|
||||
|
||||
//fprintf (stderr, "played_data %d total_decoded %d delta %d\n", played_data, soundSource[SPEECH_SOURCE].total_decoded, delta);
|
||||
|
||||
pos = soundSource[SPEECH_SOURCE].sbuf_start + delta;
|
||||
pos = soundSource[SPEECH_SOURCE].sbuf_offset + delta;
|
||||
if (pos % 2 == 1)
|
||||
pos++;
|
||||
|
||||
@@ -612,12 +611,11 @@ GetSoundData (void *data)
|
||||
PlayingStream (MUSIC_SOURCE) && soundSource[MUSIC_SOURCE].sbuffer &&
|
||||
soundSource[MUSIC_SOURCE].sbuf_size > 0)
|
||||
{
|
||||
float played_time = (GetTimeCounter () - soundSource[MUSIC_SOURCE].start_time) /
|
||||
float played_time = (GetTimeCounter () - soundSource[MUSIC_SOURCE].sbuf_lasttime) /
|
||||
(float)ONE_SECOND;
|
||||
int played_data = (int) (played_time * (float)soundSource[MUSIC_SOURCE].
|
||||
int delta = (int) (played_time * (float)soundSource[MUSIC_SOURCE].
|
||||
sample->decoder->frequency * 4.0f);
|
||||
int delta = played_data - soundSource[MUSIC_SOURCE].total_decoded;
|
||||
unsigned int pos, i, step;
|
||||
unsigned long pos, i, step;
|
||||
UBYTE *scopedata = (UBYTE *) data;
|
||||
UBYTE *sbuffer = soundSource[MUSIC_SOURCE].sbuffer;
|
||||
|
||||
@@ -641,7 +639,7 @@ GetSoundData (void *data)
|
||||
|
||||
//fprintf (stderr, "played_data %d total_decoded %d delta %d\n", played_data, soundSource[MUSIC_SOURCE].total_decoded, delta);
|
||||
|
||||
pos = soundSource[MUSIC_SOURCE].sbuf_start + delta;
|
||||
pos = soundSource[MUSIC_SOURCE].sbuf_offset + delta;
|
||||
if (pos % 2 == 1)
|
||||
pos++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user