aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/sound.cpp
diff options
context:
space:
mode:
authorMatthew Hoops2010-02-26 08:11:45 +0000
committerMatthew Hoops2010-02-26 08:11:45 +0000
commit08d3c24c12953c0c99286dac94486507f8deae6d (patch)
tree601540faff31d93179fa2344df6e0f2533ffbf07 /engines/mohawk/sound.cpp
parenta8a327616b3f6bb50fb374d5e1d5c37c1c9f3c67 (diff)
downloadscummvm-rg350-08d3c24c12953c0c99286dac94486507f8deae6d.tar.gz
scummvm-rg350-08d3c24c12953c0c99286dac94486507f8deae6d.tar.bz2
scummvm-rg350-08d3c24c12953c0c99286dac94486507f8deae6d.zip
Cleanup the sound code a bit.
svn-id: r48133
Diffstat (limited to 'engines/mohawk/sound.cpp')
-rw-r--r--engines/mohawk/sound.cpp32
1 files changed, 11 insertions, 21 deletions
diff --git a/engines/mohawk/sound.cpp b/engines/mohawk/sound.cpp
index 4d0a26847a..d6582f62a1 100644
--- a/engines/mohawk/sound.cpp
+++ b/engines/mohawk/sound.cpp
@@ -338,27 +338,23 @@ Audio::AudioStream *Sound::getCSAmtrakMusic(uint16 id) {
}
Audio::AudioStream *Sound::makeMohawkWaveStream(Common::SeekableReadStream *stream) {
- bool foundData = false;
uint32 tag = 0;
ADPC_Chunk adpc;
Cue_Chunk cue;
Data_Chunk data_chunk;
+ uint32 dataSize = 0;
memset(&data_chunk, 0, sizeof(Data_Chunk));
- if (stream->readUint32BE() == ID_MHWK) // MHWK tag again
- debug(2, "Found Tag MHWK");
- else
+ if (stream->readUint32BE() != ID_MHWK) // MHWK tag again
error ("Could not find tag \'MHWK\'");
stream->readUint32BE(); // Skip size
- if (stream->readUint32BE() == ID_WAVE)
- debug(2, "Found Tag WAVE");
- else
+ if (stream->readUint32BE() != ID_WAVE)
error ("Could not find tag \'WAVE\'");
- while (!foundData) {
+ while (!data_chunk.audio_data) {
tag = stream->readUint32BE();
switch (tag) {
@@ -424,7 +420,7 @@ Audio::AudioStream *Sound::makeMohawkWaveStream(Common::SeekableReadStream *stre
debug(2, "Found Tag DATA");
// We subtract 20 from the actual chunk size, which is the total size
// of the chunk's header
- data_chunk.size = stream->readUint32BE() - 20;
+ dataSize = stream->readUint32BE() - 20;
data_chunk.sample_rate = stream->readUint16BE();
data_chunk.sample_count = stream->readUint32BE();
data_chunk.bitsPerSample = stream->readByte();
@@ -440,9 +436,7 @@ Audio::AudioStream *Sound::makeMohawkWaveStream(Common::SeekableReadStream *stre
// therefore does not contain any of this metadata and we have to specify whether
// or not to loop elsewhere.
- data_chunk.audio_data = (byte *)malloc(data_chunk.size);
- stream->read(data_chunk.audio_data, data_chunk.size);
- foundData = true;
+ data_chunk.audio_data = stream->readStream(dataSize);
break;
default:
error ("Unknown tag found in 'tWAV' chunk -- \'%s\'", tag2str(tag));
@@ -461,15 +455,13 @@ Audio::AudioStream *Sound::makeMohawkWaveStream(Common::SeekableReadStream *stre
if (data_chunk.channels == 2)
flags |= Audio::FLAG_STEREO;
- return Audio::makeRawStream(data_chunk.audio_data, data_chunk.size, data_chunk.sample_rate, flags);
+ return Audio::makeRawStream(data_chunk.audio_data, data_chunk.sample_rate, flags);
} else if (data_chunk.encoding == kCodecADPCM) {
- Common::MemoryReadStream *dataStream = new Common::MemoryReadStream(data_chunk.audio_data, data_chunk.size, DisposeAfterUse::YES);
uint32 blockAlign = data_chunk.channels * data_chunk.bitsPerSample / 8;
- return Audio::makeADPCMStream(dataStream, DisposeAfterUse::YES, data_chunk.size, Audio::kADPCMIma, data_chunk.sample_rate, data_chunk.channels, blockAlign);
+ return Audio::makeADPCMStream(data_chunk.audio_data, DisposeAfterUse::YES, dataSize, Audio::kADPCMIma, data_chunk.sample_rate, data_chunk.channels, blockAlign);
} else if (data_chunk.encoding == kCodecMPEG2) {
#ifdef USE_MAD
- Common::MemoryReadStream *dataStream = new Common::MemoryReadStream(data_chunk.audio_data, data_chunk.size, DisposeAfterUse::YES);
- return Audio::makeMP3Stream(dataStream, DisposeAfterUse::YES);
+ return Audio::makeMP3Stream(data_chunk.audio_data, DisposeAfterUse::YES);
#else
warning ("MAD library not included - unable to play MP2 audio");
#endif
@@ -496,12 +488,10 @@ Audio::AudioStream *Sound::makeOldMohawkWaveStream(Common::SeekableReadStream *s
} else
error("Could not find Old Mohawk Sound header");
- assert(size);
- byte *data = (byte *)malloc(size);
- stream->read(data, size);
+ Common::SeekableReadStream *dataStream = stream->readStream(size);
delete stream;
- return Audio::makeRawStream(data, size, rate, Audio::FLAG_UNSIGNED);
+ return Audio::makeRawStream(dataStream, rate, Audio::FLAG_UNSIGNED);
}
SndHandle *Sound::getHandle() {