LAB: Move readSound() into the Music class

This commit is contained in:
Filippos Karapetis 2015-12-07 10:44:54 +02:00 committed by Willem Jan Palenstijn
parent 6bba608fc0
commit 156ad539ff
4 changed files with 51 additions and 47 deletions

View File

@ -668,48 +668,4 @@ bool Anim::readDiff(byte *buffer, bool playOnce) {
return true;
}
void Anim::readSound(bool waitTillFinished, Common::File *file) {
uint32 magicBytes = file->readUint32LE();
if (magicBytes != 1219009121L)
return;
uint32 soundTag = file->readUint32LE();
uint32 soundSize = file->readUint32LE();
if (soundTag == 0)
file->skip(soundSize); // skip the header
else
return;
while (soundTag != 65535) {
_vm->_music->updateMusic();
soundTag = file->readUint32LE();
soundSize = file->readUint32LE() - 8;
if ((soundTag == 30) || (soundTag == 31)) {
if (waitTillFinished) {
while (_vm->_music->isSoundEffectActive()) {
_vm->_music->updateMusic();
_vm->waitTOF();
}
}
file->skip(4);
uint16 sampleRate = file->readUint16LE();
file->skip(2);
byte *soundData = (byte *)malloc(soundSize);
file->read(soundData, soundSize);
_vm->_music->playSoundEffect(sampleRate, soundSize, soundData);
} else if (soundTag == 65535L) {
if (waitTillFinished) {
while (_vm->_music->isSoundEffectActive()) {
_vm->_music->updateMusic();
_vm->waitTOF();
}
}
} else
file->skip(soundSize);
}
}
} // End of namespace Lab

View File

@ -111,7 +111,6 @@ public:
void unDiff(byte *newBuf, byte *oldBuf, byte *diffData, uint16 bytesperrow, bool isV);
bool readDiff(byte *buffer, bool playOnce);
void diffNextFrame();
void readSound(bool waitTillFinished, Common::File *file);
void stopDiff();
void stopDiffEnd();
};

View File

@ -321,9 +321,56 @@ bool Music::readMusic(const char *filename, bool waitTillFinished) {
return false;
_vm->_anim->_doBlack = false;
_vm->_anim->readSound(waitTillFinished, file);
readSound(waitTillFinished, file);
return true;
}
void Music::readSound(bool waitTillFinished, Common::File *file) {
uint32 magicBytes = file->readUint32LE();
if (magicBytes != 1219009121L)
return;
uint32 soundTag = file->readUint32LE();
uint32 soundSize = file->readUint32LE();
if (soundTag == 0)
file->skip(soundSize); // skip the header
else
return;
while (soundTag != 65535) {
updateMusic();
soundTag = file->readUint32LE();
soundSize = file->readUint32LE() - 8;
if ((soundTag == 30) || (soundTag == 31)) {
if (waitTillFinished) {
while (isSoundEffectActive()) {
updateMusic();
_vm->waitTOF();
}
}
file->skip(4);
uint16 sampleRate = file->readUint16LE();
file->skip(2);
byte *soundData = (byte *)malloc(soundSize);
file->read(soundData, soundSize);
playSoundEffect(sampleRate, soundSize, soundData);
}
else if (soundTag == 65535L) {
if (waitTillFinished) {
while (isSoundEffectActive()) {
updateMusic();
_vm->waitTOF();
}
}
}
else
file->skip(soundSize);
}
}
} // End of namespace Lab

View File

@ -77,9 +77,11 @@ public:
bool _doReset;
private:
LabEngine *_vm;
void fillbuffer(byte *musicBuffer);
void startMusic(bool restartFl);
void readSound(bool waitTillFinished, Common::File *file);
LabEngine *_vm;
Common::File *_file;
Common::File *_tFile;