SCI: calculate sampleLen for WAVEs as well

svn-id: r48906
This commit is contained in:
Martin Kiewitz 2010-05-03 13:30:09 +00:00
parent 990f633b00
commit b4d35b3279
2 changed files with 12 additions and 7 deletions

View File

@ -1263,6 +1263,8 @@ void ResourceManager::readWaveAudioPatches() {
ResourceSource *psrcPatch = new ResourceSource;
psrcPatch->source_type = kSourceWave;
psrcPatch->location_name = name;
psrcPatch->volume_number = 0;
psrcPatch->audioCompressionType = 0;
ResourceId resId = ResourceId(kResourceTypeAudio, number);

View File

@ -212,6 +212,8 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32
byte flags = 0;
Sci::Resource *audioRes;
*sampleLen = 0;
if (volume == 65535) {
audioRes = _resMan->findResource(ResourceId(kResourceTypeAudio, number), false);
if (!audioRes) {
@ -251,10 +253,6 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32
#endif
break;
}
// Hopefully FLAC/OGG/MP3 are always 16-bit, otherwise we will get inaccuracies during sampleLen calculation
// TODO: Check if this is true, otherwise implement support for getting 8-bit/16-bit from stream in common
flags = Audio::FLAG_16BITS;
} else {
// Original source file
if (audioRes->_headerSize > 0) {
@ -271,6 +269,14 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32
if (memcmp(audioRes->data, "RIFF", 4) == 0) {
// WAVE detected
Common::MemoryReadStream *waveStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::NO);
// Calculate samplelen from WAVE header
int waveSize = 0, waveRate = 0;
byte waveFlags = 0;
Audio::loadWAVFromStream(*waveStream, waveSize, waveRate, waveFlags);
*sampleLen = (waveFlags & Audio::FLAG_16BITS ? waveSize >> 1 : waveSize) * 60 / waveRate;
waveStream->seek(0, SEEK_SET);
audioStream = Audio::makeWAVStream(waveStream, DisposeAfterUse::YES);
}
}
@ -293,9 +299,6 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32
// Original code
//*sampleLen = (flags & Audio::FLAG_16BITS ? size >> 1 : size) * 60 / _audioRate;
audioStream = audioSeekStream;
} else {
// TODO: if possible make makeWAVStream() return seekableAudioStream as well, so we will be able to calculate sampleLen
*sampleLen = 0;
}
if (audioStream)
return audioStream;