Added stream-reading loading wrappers to MDYPlayer and added a workaround to fix TBR reading for the moment

svn-id: r41781
This commit is contained in:
Sven Hesse 2009-06-22 20:27:47 +00:00
parent e9ffb84179
commit 4ab4517016
3 changed files with 81 additions and 25 deletions

View file

@ -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,18 +530,32 @@ bool MDYPlayer::loadMDY(const char *fileName) {
return true;
}
bool MDYPlayer::loadTBR(const char *fileName) {
Common::File timbres;
bool MDYPlayer::loadMDY(const char *fileName) {
Common::File song;
unload();
timbres.open(fileName);
if (!timbres.isOpen())
song.open(fileName);
if (!song.isOpen())
return false;
_timbresSize = timbres.size();
_timbres = new byte[_timbresSize];
timbres.read(_timbres, _timbresSize);
timbres.close();
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();
@ -555,9 +563,30 @@ bool MDYPlayer::loadTBR(const char *fileName) {
return true;
}
void MDYPlayer::unload() {
AdLib::unload();
bool MDYPlayer::loadTBR(const char *fileName) {
Common::File timbres;
timbres.open(fileName);
if (!timbres.isOpen())
return false;
bool loaded = loadTBR(timbres);
timbres.close();
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;

View file

@ -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();
};

View file

@ -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) {