aboutsummaryrefslogtreecommitdiff
path: root/engines/saga
diff options
context:
space:
mode:
Diffstat (limited to 'engines/saga')
-rw-r--r--engines/saga/sndres.cpp53
-rw-r--r--engines/saga/sound.cpp31
-rw-r--r--engines/saga/sound.h5
3 files changed, 35 insertions, 54 deletions
diff --git a/engines/saga/sndres.cpp b/engines/saga/sndres.cpp
index b2ffe55e5b..eddd35300e 100644
--- a/engines/saga/sndres.cpp
+++ b/engines/saga/sndres.cpp
@@ -192,7 +192,6 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
GameSoundTypes resourceType = kSoundPCM;
byte *data = 0;
int rate = 0, size = 0;
- byte flags = 0;
Common::File* file;
if (resourceId == (uint32)-1) {
@@ -269,21 +268,17 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
}
- // Default sound type is 16-bit PCM (used in ITE)
- buffer.isBigEndian = context->isBigEndian;
- if ((context->fileType & GAME_VOICEFILE) && (_vm->getFeatures() & GF_LE_VOICES))
- buffer.isBigEndian = false;
+ // Default sound type is 16-bit signed PCM, used in ITE by PCM and VOX files
buffer.isCompressed = context->isCompressed;
buffer.soundType = resourceType;
buffer.originalSize = 0;
- buffer.stereo = false;
- buffer.isSigned = true; // default for PCM and VOX
- buffer.frequency = 22050; // default for PCM and VOX
- buffer.sampleBits = 16; // default for PCM and VOX
+ // Set default flags and frequency for PCM, VOC and VOX files, which got no header
+ buffer.flags = Audio::Mixer::FLAG_16BITS;
+ buffer.frequency = 22050;
if (_vm->getGameId() == GID_ITE) {
if (_vm->getFeatures() & GF_8BIT_UNSIGNED_PCM) { // older ITE demos
- buffer.isSigned = false;
- buffer.sampleBits = 8;
+ buffer.flags |= Audio::Mixer::FLAG_UNSIGNED;
+ buffer.flags &= ~Audio::Mixer::FLAG_16BITS;
} else {
// Voice files in newer ITE demo versions are OKI ADPCM (VOX) encoded
if (!scumm_stricmp(context->fileName, "voicesd.rsc"))
@@ -292,6 +287,12 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
}
buffer.buffer = NULL;
+ // Check for LE sounds
+ if (!context->isBigEndian)
+ buffer.flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
+ if ((context->fileType & GAME_VOICEFILE) && (_vm->getFeatures() & GF_LE_VOICES))
+ buffer.flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
+
// Older Mac versions of ITE were Macbinary packed
int soundOffset = (context->fileType & GAME_MACBINARY) ? 36 : 0;
@@ -321,25 +322,23 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
case kSoundShorten:
case kSoundVOC:
if (resourceType == kSoundWAV) {
- result = Audio::loadWAVFromStream(readS, size, rate, flags);
+ result = Audio::loadWAVFromStream(readS, size, rate, buffer.flags);
} else if (resourceType == kSoundAIFF) {
- result = Audio::loadAIFFFromStream(readS, size, rate, flags);
+ result = Audio::loadAIFFFromStream(readS, size, rate, buffer.flags);
+#ifdef ENABLE_SAGA2
+ } else if (resourceType == kSoundShorten) {
+ result = Audio::loadShortenFromStream(readS, size, rate, buffer.flags);
+#endif
} else if (resourceType == kSoundVOC) {
data = Audio::loadVOCFromStream(readS, size, rate);
result = (data != 0);
if (onlyHeader)
free(data);
-#ifdef ENABLE_SAGA2
- } else if (resourceType == kSoundShorten) {
- result = Audio::loadShortenFromStream(readS, size, rate, flags);
-#endif
+ buffer.flags |= Audio::Mixer::FLAG_UNSIGNED;
}
if (result) {
buffer.frequency = rate;
- buffer.sampleBits = (flags & Audio::Mixer::FLAG_16BITS) ? 16 : 8;
- buffer.stereo = flags & Audio::Mixer::FLAG_STEREO;
- buffer.isSigned = (resourceType == kSoundVOC) ? false : !(flags & Audio::Mixer::FLAG_UNSIGNED);
buffer.size = size;
if (!onlyHeader && resourceType != kSoundVOC) {
@@ -360,8 +359,10 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
readS.readByte(); // Skip compression identifier byte
buffer.frequency = readS.readUint16LE();
buffer.originalSize = readS.readUint32LE();
- buffer.sampleBits = readS.readByte();
- buffer.stereo = (readS.readByte() == char(0)) ? false : true;
+ if (readS.readByte() == 8) // read sample bits
+ buffer.flags &= ~Audio::Mixer::FLAG_16BITS;
+ if (readS.readByte() != 0) // read stereo flag
+ buffer.flags |= Audio::Mixer::FLAG_STEREO;
buffer.size = soundResourceLength;
buffer.soundType = resourceType;
@@ -407,12 +408,12 @@ int SndRes::getVoiceLength(uint32 resourceId) {
msDouble = (double)buffer.size;
else
msDouble = (double)buffer.originalSize;
- if (buffer.sampleBits == 16) {
+
+ if (buffer.flags & Audio::Mixer::FLAG_16BITS)
msDouble /= 2.0;
- }
- if (buffer.stereo) {
+
+ if (buffer.flags & Audio::Mixer::FLAG_STEREO)
msDouble /= 2.0;
- }
msDouble = msDouble / buffer.frequency * 1000.0;
return (int)msDouble;
diff --git a/engines/saga/sound.cpp b/engines/saga/sound.cpp
index 58dc96a785..14e5492a48 100644
--- a/engines/saga/sound.cpp
+++ b/engines/saga/sound.cpp
@@ -65,29 +65,18 @@ SndHandle *Sound::getHandle() {
void Sound::playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int volume,
sndHandleType handleType, bool loop) {
- byte flags;
- flags = Audio::Mixer::FLAG_AUTOFREE;
+ buffer.flags |= Audio::Mixer::FLAG_AUTOFREE;
if (loop)
- flags |= Audio::Mixer::FLAG_LOOP;
+ buffer.flags |= Audio::Mixer::FLAG_LOOP;
- if (buffer.sampleBits == 16) {
- flags |= Audio::Mixer::FLAG_16BITS;
-
- if (!buffer.isBigEndian)
- flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
- }
- if (buffer.stereo)
- flags |= Audio::Mixer::FLAG_STEREO;
- if (!buffer.isSigned)
- flags |= Audio::Mixer::FLAG_UNSIGNED;
+ Audio::Mixer::SoundType soundType = (handleType == kVoiceHandle) ?
+ Audio::Mixer::kSpeechSoundType : Audio::Mixer::kSFXSoundType;
if (!buffer.isCompressed) {
- Audio::Mixer::SoundType soundType = (handleType == kVoiceHandle) ?
- Audio::Mixer::kSpeechSoundType : Audio::Mixer::kSFXSoundType;
_mixer->playRaw(soundType, handle, buffer.buffer,
- buffer.size, buffer.frequency, flags, -1, volume);
+ buffer.size, buffer.frequency, buffer.flags, -1, volume);
} else {
Audio::AudioStream *stream = 0;
@@ -113,14 +102,8 @@ void Sound::playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int
break;
}
- if (stream != NULL) {
- if (handleType == kVoiceHandle)
- _mixer->playInputStream(Audio::Mixer::kSpeechSoundType, handle, stream, -1,
- volume, 0, true, false);
- else
- _mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, stream, -1,
- volume, 0, true, false);
- }
+ if (stream != NULL)
+ _mixer->playInputStream(soundType, handle, stream, -1, volume, 0, true, false);
}
}
diff --git a/engines/saga/sound.h b/engines/saga/sound.h
index 7650357a78..0aeb54a55f 100644
--- a/engines/saga/sound.h
+++ b/engines/saga/sound.h
@@ -44,15 +44,12 @@ enum SOUND_FLAGS {
struct SoundBuffer {
uint16 frequency;
- int sampleBits;
- bool stereo;
- bool isSigned;
bool isCompressed;
+ byte flags;
byte *buffer;
size_t size;
size_t originalSize;
- bool isBigEndian;
GameSoundTypes soundType;
size_t fileOffset;
};