DRAGONS: Only load SF2 if using fluidsynth driver.

This commit is contained in:
Eric Fry 2020-08-07 23:31:15 +10:00
parent c2831cccf8
commit 0354a6981f
4 changed files with 40 additions and 40 deletions

View File

@ -19,19 +19,24 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "common/debug.h"
#include "common/memstream.h"
#include "common/stream.h"
#include "audio/midiparser.h"
#include "audio/soundfont/rawfile.h"
#include "audio/soundfont/vab/vab.h"
#include "audio/soundfont/vgmcoll.h"
#include "midimusicplayer.h"
namespace Dragons {
MidiMusicPlayer::MidiMusicPlayer(VabSound *musicVab, Common::SeekableReadStream *soundFont): _musicVab(musicVab), _midiDataSize(0) {
MidiMusicPlayer::MidiMusicPlayer(BigfileArchive *bigFileArchive, VabSound *musicVab): _musicVab(musicVab), _midiDataSize(0) {
_midiData = nullptr;
MidiPlayer::createDriver(MDT_PREFER_FLUID | MDT_MIDI);
if (_driver->acceptsSoundFontData()) {
_driver->setEngineSoundFont(soundFont);
_driver->setEngineSoundFont(loadSoundFont(bigFileArchive));
}
int ret = _driver->open();
@ -132,4 +137,33 @@ void MidiMusicPlayer::setVolume(int volume) {
MidiPlayer::setVolume(volume);
}
Common::SeekableReadStream *MidiMusicPlayer::loadSoundFont(BigfileArchive *bigFileArchive) {
uint32 headSize, bodySize;
byte *headData = bigFileArchive->load("musx.vh", headSize);
byte *bodyData = bigFileArchive->load("musx.vb", bodySize);
byte *vabData = (byte *)malloc(headSize + bodySize);
memcpy(vabData, headData, headSize);
memcpy(vabData + headSize, bodyData, bodySize);
free(headData);
free(bodyData);
MemFile *memFile = new MemFile(vabData, headSize + bodySize);
debug("Loading soundfont2 from musx vab file.");
Vab *vab = new Vab(memFile, 0);
vab->LoadVGMFile();
VGMColl vabCollection;
SF2File *file = vabCollection.CreateSF2File(vab);
const byte *bytes = (const byte *)file->SaveToMem();
uint32 size = file->GetSize();
delete file;
delete vab;
delete memFile;
return new Common::MemoryReadStream(bytes, size, DisposeAfterUse::YES);
}
} // End of namespace Dragons

View File

@ -24,6 +24,7 @@
#include "audio/midiplayer.h"
#include "vabsound.h"
#include "bigfile.h"
namespace Dragons {
@ -32,7 +33,7 @@ private:
VabSound *_musicVab;
uint32 _midiDataSize;
public:
MidiMusicPlayer(VabSound *musicVab, Common::SeekableReadStream *soundFont);
MidiMusicPlayer(BigfileArchive *bigFileArchive, VabSound *musicVab);
~MidiMusicPlayer();
void setVolume(int volume) override;
@ -44,6 +45,7 @@ public:
uint32 getBaseTempo() { return _driver ? (109 * _driver->getBaseTempo()) / 120 : 0; }
private:
byte *resizeMidiBuffer(uint32 desiredSize);
Common::SeekableReadStream *loadSoundFont(BigfileArchive *bigFileArchive);
};
} // End of namespace Dragons

View File

@ -294,7 +294,7 @@ SoundManager::SoundManager(DragonsEngine *vm, BigfileArchive *bigFileArchive, Dr
SomeInitSound_FUN_8003f64c();
initVabData();
_midiPlayer = new MidiMusicPlayer(_vabMusx, loadSoundFont());
_midiPlayer = new MidiMusicPlayer(_bigFileArchive, _vabMusx);
_midiPlayer->setVolume(_musicVolume);
}
@ -528,38 +528,4 @@ void SoundManager::playMusic(int16 song) {
delete seq;
}
Common::SeekableReadStream *SoundManager::loadSoundFont() {
uint32 headSize, bodySize;
byte *headData = _bigFileArchive->load("musx.vh", headSize);
byte *bodyData = _bigFileArchive->load("musx.vb", bodySize);
byte *vabData = (byte *)malloc(headSize + bodySize);
memcpy(vabData, headData, headSize);
memcpy(vabData + headSize, bodyData, bodySize);
free(headData);
free(bodyData);
MemFile *memFile = new MemFile(vabData, headSize + bodySize);
debug("Loaded vab file size: %lu", memFile->size());
Vab *vab = new Vab(memFile, 0);
vab->LoadVGMFile();
VGMColl vabCollection;
SF2File *file = vabCollection.CreateSF2File(vab);
const byte *bytes = (const byte *)file->SaveToMem();
uint32 size = file->GetSize();
delete file;
delete vab;
delete memFile;
Common::DumpFile *dumpFile = new Common::DumpFile();
dumpFile->open("testing.sf2");
dumpFile->write(bytes, size);
dumpFile->close();
delete dumpFile;
return new Common::MemoryReadStream(bytes, size, DisposeAfterUse::YES);
}
} // End of namespace Dragons

View File

@ -90,8 +90,6 @@ private:
void initVabData();
Common::SeekableReadStream *loadSoundFont();
void playSound(uint16 soundId, uint16 i);
void stopSound(uint16 id, uint16 i);