mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 21:59:17 +00:00
DRAGONS: Only load SF2 if using fluidsynth driver.
This commit is contained in:
parent
c2831cccf8
commit
0354a6981f
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -90,8 +90,6 @@ private:
|
||||
|
||||
void initVabData();
|
||||
|
||||
Common::SeekableReadStream *loadSoundFont();
|
||||
|
||||
void playSound(uint16 soundId, uint16 i);
|
||||
|
||||
void stopSound(uint16 id, uint16 i);
|
||||
|
Loading…
Reference in New Issue
Block a user