aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorFilippos Karapetis2016-01-14 00:35:44 +0200
committerFilippos Karapetis2016-01-14 23:41:29 +0200
commitcb0f7e8a92f35b161f9f54f5d3e9705e9c9a1831 (patch)
treeafbfbd3d9ac67a62459b0c3e303e66adf9f88dcc /engines
parent7aafcaca1a5df7e63795e0e6e72f06452490992e (diff)
downloadscummvm-rg350-cb0f7e8a92f35b161f9f54f5d3e9705e9c9a1831.tar.gz
scummvm-rg350-cb0f7e8a92f35b161f9f54f5d3e9705e9c9a1831.tar.bz2
scummvm-rg350-cb0f7e8a92f35b161f9f54f5d3e9705e9c9a1831.zip
LAB: Cleanup and reorder the music code
Diffstat (limited to 'engines')
-rw-r--r--engines/lab/music.cpp131
-rw-r--r--engines/lab/music.h3
2 files changed, 65 insertions, 69 deletions
diff --git a/engines/lab/music.cpp b/engines/lab/music.cpp
index 9f9d8eab8f..396aacf103 100644
--- a/engines/lab/music.cpp
+++ b/engines/lab/music.cpp
@@ -59,75 +59,15 @@ byte Music::getSoundFlags() {
return soundFlags;
}
-void Music::changeMusic(const Common::String filename, bool storeCurPos, bool seektoStoredPos) {
- if (storeCurPos)
- _storedPos = _musicFile->pos();
-
- stopSoundEffect();
- freeMusic();
- _musicFile = _vm->_resource->openDataFile(filename);
- if (seektoStoredPos)
- _musicFile->seek(_storedPos);
-
- Audio::SeekableAudioStream *audioStream = Audio::makeRawStream(_musicFile, SAMPLESPEED, getSoundFlags());
- _vm->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, new Audio::LoopingAudioStream(audioStream, 0));
-}
-
-void Music::playSoundEffect(uint16 sampleSpeed, uint32 length, bool loop, Common::File *dataFile) {
+void Music::loadSoundEffect(const Common::String filename, bool loop, bool waitTillFinished) {
stopSoundEffect();
- // NOTE: We need to use malloc(), cause this will be freed with free()
- // by the music code
- byte *soundData = (byte *)malloc(length);
- dataFile->read(soundData, length);
-
- Audio::SeekableAudioStream *audioStream = Audio::makeRawStream((const byte *)soundData, length, MAX<uint16>(sampleSpeed, 4000), getSoundFlags());
- _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, new Audio::LoopingAudioStream(audioStream, (loop) ? 0 : 1));
-}
-
-void Music::stopSoundEffect() {
- if (isSoundEffectActive())
- _vm->_mixer->stopHandle(_sfxHandle);
-}
-
-bool Music::isSoundEffectActive() const {
- return _vm->_mixer->isSoundHandleActive(_sfxHandle);
-}
-
-void Music::freeMusic() {
- _vm->_mixer->stopHandle(_musicHandle);
- _vm->_mixer->stopHandle(_sfxHandle);
- _musicFile = nullptr;
-}
-
-void Music::checkRoomMusic() {
- if ((_curRoomMusic == _vm->_roomNum) || !_musicFile)
- return;
-
- if (_vm->_roomNum == CLOWNROOM)
- changeMusic("Music:Laugh", true, false);
- else if (_vm->_roomNum == DIMROOM)
- changeMusic("Music:Rm81", true, false);
- else if (_curRoomMusic == CLOWNROOM || _curRoomMusic == DIMROOM)
- resetMusic(true);
-
- _curRoomMusic = _vm->_roomNum;
-}
-
-bool Music::loadSoundEffect(const Common::String filename, bool loop, bool waitTillFinished) {
Common::File *file = _vm->_resource->openDataFile(filename, MKTAG('D', 'I', 'F', 'F'));
- stopSoundEffect();
-
if (!file)
- return false;
+ return;
_vm->_anim->_doBlack = false;
- readSound(waitTillFinished, loop, file);
-
- return true;
-}
-void Music::readSound(bool waitTillFinished, bool loop, Common::File *file) {
uint32 magicBytes = file->readUint32LE();
if (magicBytes != 1219009121) {
warning("readSound: Bad signature, skipping");
@@ -136,11 +76,11 @@ void Music::readSound(bool waitTillFinished, bool loop, Common::File *file) {
uint32 soundTag = file->readUint32LE();
uint32 soundSize = file->readUint32LE();
- if (soundTag == 0)
- file->skip(soundSize); // skip the header
- else
+ if (soundTag != 0)
return;
+ file->skip(soundSize); // skip the header
+
while (soundTag != 65535) {
_vm->updateEvents();
soundTag = file->readUint32LE();
@@ -159,18 +99,55 @@ void Music::readSound(bool waitTillFinished, bool loop, Common::File *file) {
uint16 sampleRate = file->readUint16LE();
file->skip(2);
playSoundEffect(sampleRate, soundSize, loop, file);
- } else if (soundTag == 65535) {
+ }
+ else if (soundTag == 65535) {
if (waitTillFinished) {
while (isSoundEffectActive()) {
_vm->updateEvents();
_vm->waitTOF();
}
}
- } else
+ }
+ else
file->skip(soundSize);
}
}
+void Music::playSoundEffect(uint16 sampleSpeed, uint32 length, bool loop, Common::File *dataFile) {
+ stopSoundEffect();
+
+ // NOTE: We need to use malloc(), cause this will be freed with free()
+ // by the music code
+ byte *soundData = (byte *)malloc(length);
+ dataFile->read(soundData, length);
+
+ Audio::SeekableAudioStream *audioStream = Audio::makeRawStream((const byte *)soundData, length, MAX<uint16>(sampleSpeed, 4000), getSoundFlags());
+ _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, new Audio::LoopingAudioStream(audioStream, (loop) ? 0 : 1));
+}
+
+void Music::stopSoundEffect() {
+ if (isSoundEffectActive())
+ _vm->_mixer->stopHandle(_sfxHandle);
+}
+
+bool Music::isSoundEffectActive() const {
+ return _vm->_mixer->isSoundHandleActive(_sfxHandle);
+}
+
+void Music::changeMusic(const Common::String filename, bool storeCurPos, bool seektoStoredPos) {
+ if (storeCurPos)
+ _storedPos = _musicFile->pos();
+
+ stopSoundEffect();
+ freeMusic();
+ _musicFile = _vm->_resource->openDataFile(filename);
+ if (seektoStoredPos)
+ _musicFile->seek(_storedPos);
+
+ Audio::SeekableAudioStream *audioStream = Audio::makeRawStream(_musicFile, SAMPLESPEED, getSoundFlags());
+ _vm->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, new Audio::LoopingAudioStream(audioStream, 0));
+}
+
void Music::resetMusic(bool seektoStoredPos) {
if (_vm->getPlatform() != Common::kPlatformAmiga)
changeMusic("Music:BackGrou", false, seektoStoredPos);
@@ -178,4 +155,24 @@ void Music::resetMusic(bool seektoStoredPos) {
changeMusic("Music:BackGround", false, seektoStoredPos);
}
+void Music::checkRoomMusic() {
+ if ((_curRoomMusic == _vm->_roomNum) || !_musicFile)
+ return;
+
+ if (_vm->_roomNum == CLOWNROOM)
+ changeMusic("Music:Laugh", true, false);
+ else if (_vm->_roomNum == DIMROOM)
+ changeMusic("Music:Rm81", true, false);
+ else if (_curRoomMusic == CLOWNROOM || _curRoomMusic == DIMROOM)
+ resetMusic(true);
+
+ _curRoomMusic = _vm->_roomNum;
+}
+
+void Music::freeMusic() {
+ _vm->_mixer->stopHandle(_musicHandle);
+ _vm->_mixer->stopHandle(_sfxHandle);
+ _musicFile = nullptr;
+}
+
} // End of namespace Lab
diff --git a/engines/lab/music.h b/engines/lab/music.h
index 45eb217550..86ebeef880 100644
--- a/engines/lab/music.h
+++ b/engines/lab/music.h
@@ -57,7 +57,6 @@ private:
Audio::SoundHandle _sfxHandle;
private:
- void readSound(bool waitTillFinished, bool loop, Common::File *file);
byte getSoundFlags();
public:
@@ -86,7 +85,7 @@ public:
/**
* Reads in a sound effect file. Ignores any graphics.
*/
- bool loadSoundEffect(const Common::String filename, bool loop, bool waitTillFinished);
+ void loadSoundEffect(const Common::String filename, bool loop, bool waitTillFinished);
void stopSoundEffect();
};