From 13ee099090f45a1e9383d71d3481247f669d984c Mon Sep 17 00:00:00 2001 From: Martin Kiewitz Date: Thu, 29 Apr 2010 15:54:59 +0000 Subject: SCI: audio compression support svn-id: r48856 --- engines/sci/sound/audio.cpp | 82 +++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 25 deletions(-) (limited to 'engines/sci/sound/audio.cpp') diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp index 935427c51a..96a3f1c577 100644 --- a/engines/sci/sound/audio.cpp +++ b/engines/sci/sound/audio.cpp @@ -36,6 +36,9 @@ #include "sound/audiocd.h" #include "sound/decoders/raw.h" #include "sound/decoders/wave.h" +#include "sound/decoders/flac.h" +#include "sound/decoders/mp3.h" +#include "sound/decoders/vorbis.h" namespace Sci { @@ -224,36 +227,65 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 } byte audioFlags; - - if (audioRes->_headerSize > 0) { - // SCI1.1 - Common::MemoryReadStream headerStream(audioRes->_header, audioRes->_headerSize, DisposeAfterUse::NO); - - if (readSOLHeader(&headerStream, audioRes->_headerSize, size, _audioRate, audioFlags)) { - Common::MemoryReadStream dataStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); - data = readSOLAudio(&dataStream, size, audioFlags, flags); + uint32 audioCompressionType = audioRes->getAudioCompressionType(); + + if (audioCompressionType) { + // Compressed audio made by our tool + Common::MemoryReadStream *compressedStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::YES); + + switch (audioCompressionType) { + case MKID_BE('MP3 '): +#ifdef USE_MAD + audioStream = Audio::makeMP3Stream(compressedStream, DisposeAfterUse::YES); +#endif + break; + case MKID_BE('OGG '): +#ifdef USE_VORBIS + audioStream = Audio::makeVorbisStream(compressedStream, DisposeAfterUse::YES); +#endif + break; + case MKID_BE('FLAC'): +#ifdef USE_FLAC + audioStream = Audio::makeFLACStream(compressedStream, DisposeAfterUse::YES); +#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 { - // SCI1 or WAVE file - if (audioRes->size > 4) { - if (memcmp(audioRes->data, "RIFF", 4) == 0) { - // WAVE detected - Common::MemoryReadStream *waveStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); - audioStream = Audio::makeWAVStream(waveStream, DisposeAfterUse::YES); + // Original source file + if (audioRes->_headerSize > 0) { + // SCI1.1 + Common::MemoryReadStream headerStream(audioRes->_header, audioRes->_headerSize, DisposeAfterUse::NO); + + if (readSOLHeader(&headerStream, audioRes->_headerSize, size, _audioRate, audioFlags)) { + Common::MemoryReadStream dataStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); + data = readSOLAudio(&dataStream, size, audioFlags, flags); + } + } else { + // SCI1 or WAVE file + if (audioRes->size > 4) { + if (memcmp(audioRes->data, "RIFF", 4) == 0) { + // WAVE detected + Common::MemoryReadStream *waveStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); + audioStream = Audio::makeWAVStream(waveStream, DisposeAfterUse::YES); + } + } + if (!audioStream) { + // SCI1 raw audio + size = audioRes->size; + data = (byte *)malloc(size); + assert(data); + memcpy(data, audioRes->data, size); + flags = Audio::FLAG_UNSIGNED; } } - if (!audioStream) { - // SCI1 raw audio - size = audioRes->size; - data = (byte *)malloc(size); - assert(data); - memcpy(data, audioRes->data, size); - flags = Audio::FLAG_UNSIGNED; - } - } - if (data) - audioStream = Audio::makeRawStream(data, size, _audioRate, flags); + if (data) + audioStream = Audio::makeRawStream(data, size, _audioRate, flags); + } if (audioStream) { *sampleLen = (flags & Audio::FLAG_16BITS ? size >> 1 : size) * 60 / _audioRate; -- cgit v1.2.3