From fde47c9869e0e1915fda0a9bd3689a54343d0a6b Mon Sep 17 00:00:00 2001 From: avolkov Date: Tue, 3 Jul 2007 21:24:12 +0000 Subject: [PATCH] Fixed audio track seek truncation; scope supports higher rates for speech; bug 999 git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2794 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 2 ++ sc2/src/sc2code/libs/sound/decoders/decoder.c | 4 ++-- sc2/src/sc2code/libs/sound/trackplayer.c | 12 ++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 6cd3ef73d..12723d882 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,6 @@ Changes towards version 0.7: +- Fixed speech looping with long tracks at high sampling rates; + scope supports higher rates for speech now; bug 999 - Alex - Basic support for .ani-based shipspin animations - Michael - Fixed some Melnorme history info timestamps - Alex - Fixed Ur-Quan story timestamps, from Vlad-Ceru Opran diff --git a/sc2/src/sc2code/libs/sound/decoders/decoder.c b/sc2/src/sc2code/libs/sound/decoders/decoder.c index 898dea43e..d3b6c8947 100644 --- a/sc2/src/sc2code/libs/sound/decoders/decoder.c +++ b/sc2/src/sc2code/libs/sound/decoders/decoder.c @@ -403,7 +403,7 @@ SoundDecoder_Load (uio_DirHandle *dir, char *filename, if (runTime > 0 && runTime / 1000.0 < decoder->length) decoder->length = (float)(runTime / 1000.0); - decoder->start_sample = decoder->frequency * startTime / 1000; + decoder->start_sample = (uint32)(startTime / 1000.0f * decoder->frequency); decoder->end_sample = decoder->start_sample + (unsigned long)(decoder->length * decoder->frequency); if (decoder->start_sample != 0) @@ -606,7 +606,7 @@ SoundDecoder_Seek (TFB_SoundDecoder *decoder, uint32 seekTime) return; } - pcm_pos = seekTime * decoder->frequency / 1000; + pcm_pos = (uint32) (seekTime / 1000.0f * decoder->frequency); pcm_pos = decoder->funcs->Seek (decoder, decoder->start_sample + pcm_pos); decoder->pos = pcm_pos * decoder->bytes_per_samp; diff --git a/sc2/src/sc2code/libs/sound/trackplayer.c b/sc2/src/sc2code/libs/sound/trackplayer.c index 5e1fe370c..6c40014fe 100644 --- a/sc2/src/sc2code/libs/sound/trackplayer.c +++ b/sc2/src/sc2code/libs/sound/trackplayer.c @@ -825,6 +825,7 @@ FastForward_Page () int GetSoundData (void *data) { + // XXX: These two variants are begging to be merged if (speechVolumeScale != 0.0f) { // speech is enabled @@ -840,12 +841,18 @@ GetSoundData (void *data) sample->decoder->frequency * 2.0f); unsigned long pos; int i; + int step; UBYTE *scopedata = (UBYTE *) data; UBYTE *sbuffer = soundSource[SPEECH_SOURCE].sbuffer; - assert (soundSource[SPEECH_SOURCE].sample->decoder->frequency == 11025); + assert (soundSource[SPEECH_SOURCE].sample->decoder->frequency >= 11025); assert (soundSource[SPEECH_SOURCE].sample->decoder->format == audio_FORMAT_MONO16); + // Using step of 1 sample at 11025Hz, because the human speech + // is mostly in the low frequencies + step = soundSource[MUSIC_SOURCE].sample->decoder->frequency * 2 / 11025; + step = (step + 1) & ~1; + if (delta < 0) { log_add (log_Debug, "GetSoundData(): something's messed" @@ -892,7 +899,7 @@ GetSoundData (void *data) s = RADAR_HEIGHT - 2; scopedata[i] = (UBYTE) s; - pos += 2; + pos += step; } UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); @@ -921,6 +928,7 @@ GetSoundData (void *data) assert (soundSource[MUSIC_SOURCE].sample->decoder->frequency >= 11025); assert (soundSource[MUSIC_SOURCE].sample->decoder->format == audio_FORMAT_STEREO16); + // Using step of 4 samples at 11025Hz for the music step = soundSource[MUSIC_SOURCE].sample->decoder->frequency / 11025 * 16; if (step % 2 == 1) step++;