diff options
Diffstat (limited to 'sword1/sound.cpp')
-rw-r--r-- | sword1/sound.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/sword1/sound.cpp b/sword1/sound.cpp index ec5a6e2a09..e92b818f85 100644 --- a/sword1/sound.cpp +++ b/sword1/sound.cpp @@ -105,7 +105,8 @@ void SwordSound::fnStopFx(int32 fxNo) { } bool SwordSound::amISpeaking(void) { - return true; + _waveVolPos++; + return _waveVolume[_waveVolPos - 1]; } bool SwordSound::speechFinished(void) { @@ -202,6 +203,7 @@ int16 *SwordSound::uncompressSpeech(uint32 index, uint32 cSize, uint32 *size) { } free(fBuf); *size = resSize * 2; + calcWaveVolume(dstData, resSize); return dstData; } else { free(fBuf); @@ -211,6 +213,31 @@ int16 *SwordSound::uncompressSpeech(uint32 index, uint32 cSize, uint32 *size) { } } +void SwordSound::calcWaveVolume(int16 *data, uint32 length) { + int16 *blkPos = data + 918; + for (uint32 cnt = 0; cnt < WAVE_VOL_TAB_LENGTH; cnt++) + _waveVolume[cnt] = false; + _waveVolPos = 0; + for (uint32 blkCnt = 1; blkCnt < length / 918; blkCnt++) { + if (blkCnt >= WAVE_VOL_TAB_LENGTH) { + warning("Wave vol tab too small."); + return; + } + int32 average = 0; + for (uint32 cnt = 0; cnt < 918; cnt++) + average += blkPos[cnt]; + average /= 918; + uint32 diff = 0; + for (uint32 cnt = 0; cnt < 918; cnt++) { + int16 smpDiff = *blkPos - average; + diff += (uint32)ABS(smpDiff); + blkPos++; + } + if (diff > WAVE_VOL_THRESHOLD) + _waveVolume[blkCnt - 1] = true; + } +} + void SwordSound::stopSpeech(void) { _mixer->stopID(SOUND_SPEECH_ID); } |