aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/gob/sound/adlib.cpp69
-rw-r--r--engines/gob/sound/adlib.h5
-rw-r--r--engines/gob/sound/sound.cpp26
3 files changed, 78 insertions, 22 deletions
diff --git a/engines/gob/sound/adlib.cpp b/engines/gob/sound/adlib.cpp
index a888b6ee49..32452b3d84 100644
--- a/engines/gob/sound/adlib.cpp
+++ b/engines/gob/sound/adlib.cpp
@@ -498,18 +498,13 @@ void MDYPlayer::init() {
_timbresSize = 0;
}
-bool MDYPlayer::loadMDY(const char *fileName) {
- Common::File song;
- byte mdyHeader[70];
-
- unload();
- song.open(fileName);
- if (!song.isOpen())
- return false;
+bool MDYPlayer::loadMDY(Common::SeekableReadStream &stream) {
+ unloadMDY();
_freeData = true;
- song.read(mdyHeader, 70);
+ byte mdyHeader[70];
+ stream.read(mdyHeader, 70);
_tickBeat = mdyHeader[36];
_beatMeasure = mdyHeader[37];
@@ -527,8 +522,7 @@ bool MDYPlayer::loadMDY(const char *fileName) {
_pitchBendRangeStep = 300;
_data = new byte[_dataSize];
- song.read(_data, _dataSize);
- song.close();
+ stream.read(_data, _dataSize);
reset();
_playPos = _data;
@@ -536,28 +530,63 @@ bool MDYPlayer::loadMDY(const char *fileName) {
return true;
}
+bool MDYPlayer::loadMDY(const char *fileName) {
+ Common::File song;
+
+ song.open(fileName);
+ if (!song.isOpen())
+ return false;
+
+ bool loaded = loadMDY(song);
+
+ song.close();
+
+ return loaded;
+}
+
+bool MDYPlayer::loadTBR(Common::SeekableReadStream &stream) {
+ unloadTBR();
+
+ _timbresSize = stream.size();
+
+ // FIXME: _timbresSize is smaller than setVoice() expects!
+ uint32 rSize = MAX<uint32>(_timbresSize, 810);
+
+ _timbres = new byte[rSize];
+ memset(_timbres, 0, rSize);
+
+ stream.read(_timbres, _timbresSize);
+
+ reset();
+ setVoices();
+
+ return true;
+}
+
bool MDYPlayer::loadTBR(const char *fileName) {
Common::File timbres;
- unload();
timbres.open(fileName);
if (!timbres.isOpen())
return false;
- _timbresSize = timbres.size();
- _timbres = new byte[_timbresSize];
- timbres.read(_timbres, _timbresSize);
- timbres.close();
+ bool loaded = loadTBR(timbres);
- reset();
- setVoices();
+ timbres.close();
- return true;
+ return loaded;
}
void MDYPlayer::unload() {
+ unloadTBR();
+ unloadMDY();
+}
+
+void MDYPlayer::unloadMDY() {
AdLib::unload();
+}
+void MDYPlayer::unloadTBR() {
delete[] _timbres;
_timbres = 0;
@@ -636,7 +665,7 @@ void MDYPlayer::interpret() {
setVoice(channel, timbre, false);
break;
case 0xE0:
- warning("Pitch bend not yet implemented\n");
+ warning("Pitch bend not yet implemented");
note = *(_playPos)++;
note += (unsigned)(*(_playPos++)) << 7;
diff --git a/engines/gob/sound/adlib.h b/engines/gob/sound/adlib.h
index 3772b93551..3f7b46643f 100644
--- a/engines/gob/sound/adlib.h
+++ b/engines/gob/sound/adlib.h
@@ -142,7 +142,9 @@ public:
~MDYPlayer();
bool loadMDY(const char *fileName);
+ bool loadMDY(Common::SeekableReadStream &stream);
bool loadTBR(const char *fileName);
+ bool loadTBR(Common::SeekableReadStream &stream);
void unload();
@@ -162,6 +164,9 @@ protected:
void setVoices();
void setVoice(byte voice, byte instr, bool set);
+ void unloadTBR();
+ void unloadMDY();
+
private:
void init();
};
diff --git a/engines/gob/sound/sound.cpp b/engines/gob/sound/sound.cpp
index 21e06e4700..d667a2d592 100644
--- a/engines/gob/sound/sound.cpp
+++ b/engines/gob/sound/sound.cpp
@@ -279,7 +279,18 @@ bool Sound::adlibLoadMDY(const char *fileName) {
debugC(1, kDebugSound, "Adlib: Loading MDY data (\"%s\")", fileName);
- return _mdyPlayer->loadMDY(fileName);
+ if (!_vm->_dataIO->existData(fileName)) {
+ warning("Can't open MDY file \"%s\"", fileName);
+ return false;
+ }
+
+ DataStream *stream = _vm->_dataIO->getDataStream(fileName);
+
+ bool loaded = _mdyPlayer->loadMDY(*stream);
+
+ delete stream;
+
+ return loaded;
}
bool Sound::adlibLoadTBR(const char *fileName) {
@@ -289,9 +300,20 @@ bool Sound::adlibLoadTBR(const char *fileName) {
if (!_mdyPlayer)
_mdyPlayer = new MDYPlayer(*_vm->_mixer);
+ if (!_vm->_dataIO->existData(fileName)) {
+ warning("Can't open TBR file \"%s\"", fileName);
+ return false;
+ }
+
debugC(1, kDebugSound, "Adlib: Loading MDY instruments (\"%s\")", fileName);
- return _mdyPlayer->loadTBR(fileName);
+ DataStream *stream = _vm->_dataIO->getDataStream(fileName);
+
+ bool loaded = _mdyPlayer->loadTBR(*stream);
+
+ delete stream;
+
+ return loaded;
}
void Sound::adlibPlayTrack(const char *trackname) {