aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2015-10-13 07:40:24 +0300
committerWillem Jan Palenstijn2015-12-23 21:33:40 +0100
commita6805e884d812e974832160311543ac1048a9f0e (patch)
treef91c645ec25441aa525f4ca41b539c22c050b53a
parent1bdf07c7acd209f3ca5ca792a6ddfe51e5e712b5 (diff)
downloadscummvm-rg350-a6805e884d812e974832160311543ac1048a9f0e.tar.gz
scummvm-rg350-a6805e884d812e974832160311543ac1048a9f0e.tar.bz2
scummvm-rg350-a6805e884d812e974832160311543ac1048a9f0e.zip
LAB: Rewrite readSound() to use Common::File
-rw-r--r--engines/lab/diff.h3
-rw-r--r--engines/lab/graphics.cpp7
-rw-r--r--engines/lab/readdiff.cpp67
3 files changed, 26 insertions, 51 deletions
diff --git a/engines/lab/diff.h b/engines/lab/diff.h
index 614148e0de..b4436b8f3f 100644
--- a/engines/lab/diff.h
+++ b/engines/lab/diff.h
@@ -32,6 +32,7 @@
#define LAB_DIFF_H
#include "lab/stddefines.h"
+#include "common/file.h"
namespace Lab {
@@ -74,7 +75,7 @@ void blackAllScreen();
void whiteScreen();
bool readDiff(bool playonce);
void diffNextFrame();
-void readSound(bool waitTillFinished);
+void readSound(bool waitTillFinished, Common::File *file);
void stopDiff();
void stopDiffEnd();
void stopSound();
diff --git a/engines/lab/graphics.cpp b/engines/lab/graphics.cpp
index c8d23e97ce..bc10e8fcb9 100644
--- a/engines/lab/graphics.cpp
+++ b/engines/lab/graphics.cpp
@@ -97,12 +97,15 @@ bool readPict(const char *filename, bool PlayOnce) {
/* Reads in a music file. Ignores any graphics. */
/*****************************************************************************/
bool readMusic(const char *filename, bool waitTillFinished) {
- byte **file = g_music->newOpen(filename);
+ Common::File *file = g_resource->openDataFile(filename, MKTAG('D', 'I', 'F', 'F'));
+ g_music->updateMusic();
+ if (!g_music->_doNotFilestopSoundEffect)
+ g_music->stopSoundEffect();
if (!file)
return false;
DoBlack = false;
- readSound(waitTillFinished);
+ readSound(waitTillFinished, file);
return true;
}
diff --git a/engines/lab/readdiff.cpp b/engines/lab/readdiff.cpp
index dacd4fbe36..e75d08e3f3 100644
--- a/engines/lab/readdiff.cpp
+++ b/engines/lab/readdiff.cpp
@@ -434,48 +434,25 @@ bool readDiff(bool playonce) {
}
-void readSound(bool waitTillFinished) {
- uint32 header_ = 0, size_;
- uint16 samplespeed_;
- char temp_[5];
- byte *storagefordifffile_, **difffile_ = &storagefordifffile_;
-
- byte *mstart = *startoffile; /* Make a copy of the pointer to the start of the file */
- *difffile_ = mstart; /* Now can modify the file without modifying the original */
-
- if (mstart == NULL)
- return;
-
- readBlock(temp_, 4L, difffile_);
- temp_[4] = '\0';
- readBlock(&header_, 4L, difffile_);
- swapULong(&header_);
-
- processed += 8L;
-
- if (!((strcmp(temp_, "DIFF") == 0) && (header_ == 1219009121L)))
+void readSound(bool waitTillFinished, Common::File *file) {
+ uint32 magicBytes = file->readUint32LE();
+ if (magicBytes != 1219009121L)
return;
- readBlock(&header_, 4L, difffile_);
- swapULong(&header_);
-
- readBlock(&size_, 4L, difffile_);
- swapULong(&size_);
+ uint32 soundTag = file->readUint32LE();
+ uint32 soundSize = file->readUint32LE();
- if (header_ == 0)
- (*difffile_) += size_;
+ if (soundTag == 0)
+ file->skip(soundSize); // skip the header
else
return;
- while (header_ != 65535) {
+ while (soundTag != 65535) {
g_music->updateMusic();
- readBlock(&header_, 4L, difffile_);
- swapULong(&header_);
-
- readBlock(&size_, 4L, difffile_);
- swapULong(&size_);
+ soundTag = file->readUint32LE();
+ soundSize = file->readUint32LE() - 8;
- if ((header_ == 30) || (header_ == 31)) {
+ if ((soundTag == 30) || (soundTag == 31)) {
if (waitTillFinished) {
while (g_music->isSoundEffectActive()) {
g_music->updateMusic();
@@ -483,20 +460,14 @@ void readSound(bool waitTillFinished) {
}
}
- size_ -= 8L;
-
- (*difffile_) += 4;
- readBlock(&samplespeed_, 2L, difffile_);
- swapUShortPtr(&samplespeed_, 1);
-
- (*difffile_) += 2;
-
- byte *music = *difffile_;
- uint32 musicsize = size_;
- (*difffile_) += size_;
+ file->skip(4);
- g_music->playSoundEffect(samplespeed_, musicsize, music);
- } else if (header_ == 65535L) {
+ uint16 sampleRate = file->readUint16LE();
+ file->skip(2);
+ byte *soundData = (byte *)malloc(soundSize);
+ file->read(soundData, soundSize);
+ g_music->playSoundEffect(sampleRate, soundSize, soundData);
+ } else if (soundTag == 65535L) {
if (waitTillFinished) {
while (g_music->isSoundEffectActive()) {
g_music->updateMusic();
@@ -504,7 +475,7 @@ void readSound(bool waitTillFinished) {
}
}
} else
- (*difffile_) += size_;
+ file->skip(soundSize);
}
}