[Scummvm-git-logs] scummvm master -> 66f880812a4853d4c48fa5693e5fb12d46c2497d

yuv422 yuv422 at users.noreply.github.com
Fri Jun 5 10:58:00 UTC 2020


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
d18f9734a1 AUDIO: Add ability for engine to supply its own soundfont data.
66f880812a AUDIO: Fixed formatting for sf loader functions.


Commit: d18f9734a19561a0be6713037f779f540dc1ad3a
    https://github.com/scummvm/scummvm/commit/d18f9734a19561a0be6713037f779f540dc1ad3a
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-06-05T20:57:54+10:00

Commit Message:
AUDIO: Add ability for engine to supply its own soundfont data.

Add MDT_PREFER_FLUID to allow engines to indicate they prefer the fluidsynth driver.

Changed paths:
    audio/mididrv.cpp
    audio/mididrv.h
    audio/softsynth/fluidsynth.cpp


diff --git a/audio/mididrv.cpp b/audio/mididrv.cpp
index 005fb9f06d..39b876b9c2 100644
--- a/audio/mididrv.cpp
+++ b/audio/mididrv.cpp
@@ -173,6 +173,9 @@ Common::String MidiDriver::getDeviceString(DeviceHandle handle, DeviceStringType
 MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {
 	// Query the selected music device (defaults to MT_AUTO device).
 	Common::String selDevStr = ConfMan.hasKey("music_driver") ? ConfMan.get("music_driver") : Common::String("auto");
+	if ((flags & MDT_PREFER_FLUID) && selDevStr == "auto") {
+		selDevStr = "fluidsynth";
+	}
 	DeviceHandle hdl = getDeviceHandle(selDevStr.empty() ? Common::String("auto") : selDevStr);
 	DeviceHandle reslt = 0;
 
diff --git a/audio/mididrv.h b/audio/mididrv.h
index 9f7383e3ab..b8d78d6359 100644
--- a/audio/mididrv.h
+++ b/audio/mididrv.h
@@ -25,6 +25,7 @@
 
 #include "common/scummsys.h"
 #include "common/str.h"
+#include "common/stream.h"
 #include "common/timer.h"
 #include "common/array.h"
 
@@ -79,7 +80,8 @@ enum MidiDriverFlags {
 	MDT_PC98        = 1 << 8,		// FM-TOWNS: Maps to MT_PC98
 	MDT_MIDI        = 1 << 9,		// Real MIDI
 	MDT_PREFER_MT32 = 1 << 10,		// MT-32 output is preferred
-	MDT_PREFER_GM   = 1 << 11		// GM output is preferred
+	MDT_PREFER_GM   = 1 << 11,		// GM output is preferred
+	MDT_PREFER_FLUID= 1 << 12		// FluidSynth driver is preferred
 };
 
 /**
@@ -339,6 +341,12 @@ public:
 	// Channel allocation functions
 	virtual MidiChannel *allocateChannel() = 0;
 	virtual MidiChannel *getPercussionChannel() = 0;
+
+	// Allow an engine to supply its own soundFont data. This stream will be destroyed after use.
+	virtual void setEngineSoundFont(Common::SeekableReadStream *soundFontData) { }
+
+	// Does this driver accept soundFont data?
+	virtual bool acceptsSoundFontData() { return false; }
 };
 
 class MidiChannel {
diff --git a/audio/softsynth/fluidsynth.cpp b/audio/softsynth/fluidsynth.cpp
index c61983e6b9..46961a0886 100644
--- a/audio/softsynth/fluidsynth.cpp
+++ b/audio/softsynth/fluidsynth.cpp
@@ -34,6 +34,7 @@
 #include "common/scummsys.h"
 #include "common/config-manager.h"
 #include "common/error.h"
+#include "common/stream.h"
 #include "common/system.h"
 #include "common/textconsole.h"
 #include "audio/musicplugin.h"
@@ -50,6 +51,7 @@ private:
 	fluid_synth_t *_synth;
 	int _soundFont;
 	int _outputRate;
+	Common::SeekableReadStream *_engineSoundFontData;
 
 protected:
 	// Because GCC complains about casting from const to non-const...
@@ -69,6 +71,9 @@ public:
 	MidiChannel *allocateChannel() override;
 	MidiChannel *getPercussionChannel() override;
 
+	void setEngineSoundFont(Common::SeekableReadStream *soundFontData) override;
+	bool acceptsSoundFontData() override { return true; }
+
 	// AudioStream API
 	bool isStereo() const override { return true; }
 	int getRate() const override { return _outputRate; }
@@ -77,7 +82,7 @@ public:
 // MidiDriver method implementations
 
 MidiDriver_FluidSynth::MidiDriver_FluidSynth(Audio::Mixer *mixer)
-	: MidiDriver_Emulated(mixer) {
+	: MidiDriver_Emulated(mixer), _engineSoundFontData(NULL) {
 
 	for (int i = 0; i < ARRAYSIZE(_midiChannels); i++) {
 		_midiChannels[i].init(this, i);
@@ -119,13 +124,49 @@ void MidiDriver_FluidSynth::setStr(const char *name, const char *val) {
 	free(val2);
 }
 
+// Soundfont memory loader callback functions.
+
+static void *SoundFontMemLoader_open(const char *filename)
+{
+	void *p;
+	if(filename[0] != '&')
+	{
+		return NULL;
+	}
+	sscanf(filename, "&%p", &p);
+	return p;
+}
+
+static int SoundFontMemLoader_read(void *buf, int count, void *handle)
+{
+	return ((Common::SeekableReadStream *)handle)->read(buf, count) == count ? FLUID_OK : FLUID_FAILED;
+}
+
+static int SoundFontMemLoader_seek(void *handle, long offset, int origin)
+{
+	return ((Common::SeekableReadStream *)handle)->seek(offset, origin) ? FLUID_OK : FLUID_FAILED;
+}
+
+static int SoundFontMemLoader_close(void *handle)
+{
+	delete (Common::SeekableReadStream *)handle;
+	return FLUID_OK;
+}
+
+static long SoundFontMemLoader_tell(void *handle)
+{
+	return ((Common::SeekableReadStream *)handle)->pos();
+}
+
 int MidiDriver_FluidSynth::open() {
 	if (_isOpen)
 		return MERR_ALREADY_OPEN;
 
-	if (!ConfMan.hasKey("soundfont"))
+	if (_engineSoundFontData == NULL && !ConfMan.hasKey("soundfont"))
 		error("FluidSynth requires a 'soundfont' setting");
 
+	bool isUsingInMemorySoundFontData = _engineSoundFontData && !ConfMan.hasKey("soundfont");
+
 	_settings = new_fluid_settings();
 
 	// The default gain setting is ridiculously low - at least for me. This
@@ -189,16 +230,32 @@ int MidiDriver_FluidSynth::open() {
 
 	fluid_synth_set_interp_method(_synth, -1, interpMethod);
 
-	const char *soundfont = ConfMan.get("soundfont").c_str();
+	const char *soundfont = ConfMan.hasKey("soundfont") ?
+			ConfMan.get("soundfont").c_str() : Common::String::format("&%p", _engineSoundFontData).c_str();
+
+	if (isUsingInMemorySoundFontData) {
+		fluid_sfloader_t *soundFontMemoryLoader = new_fluid_defsfloader(_settings);
+		fluid_sfloader_set_callbacks(soundFontMemoryLoader,
+									 SoundFontMemLoader_open,
+									 SoundFontMemLoader_read,
+									 SoundFontMemLoader_seek,
+									 SoundFontMemLoader_tell,
+									 SoundFontMemLoader_close);
+		fluid_synth_add_sfloader(_synth, soundFontMemoryLoader);
+	}
 
 #if defined(IPHONE_IOS7) && defined(IPHONE_SANDBOXED)
-	// HACK: Due to the sandbox on non-jailbroken iOS devices, we need to deal
-	// with the chroot filesystem. All the path selected by the user are
-	// relative to the Document directory. So, we need to adjust the path to
-	// reflect that.
-	Common::String soundfont_fullpath = iOS7_getDocumentsDir();
-	soundfont_fullpath += soundfont;
-	_soundFont = fluid_synth_sfload(_synth, soundfont_fullpath.c_str(), 1);
+	if (!isUsingInMemorySoundFontData) {
+		// HACK: Due to the sandbox on non-jailbroken iOS devices, we need to deal
+		// with the chroot filesystem. All the path selected by the user are
+		// relative to the Document directory. So, we need to adjust the path to
+		// reflect that.
+		Common::String soundfont_fullpath = iOS7_getDocumentsDir();
+		soundfont_fullpath += soundfont;
+		_soundFont = fluid_synth_sfload(_synth, soundfont_fullpath.c_str(), 1);
+	} else {
+		_soundFont = fluid_synth_sfload(_synth, soundfont, 1);
+	}
 #else
 	_soundFont = fluid_synth_sfload(_synth, soundfont, 1);
 #endif
@@ -282,6 +339,10 @@ void MidiDriver_FluidSynth::generateSamples(int16 *data, int len) {
 	fluid_synth_write_s16(_synth, len, data, 0, 2, data, 1, 2);
 }
 
+void MidiDriver_FluidSynth::setEngineSoundFont(Common::SeekableReadStream *soundFontData) {
+	_engineSoundFontData = soundFontData;
+}
+
 
 // Plugin interface
 


Commit: 66f880812a4853d4c48fa5693e5fb12d46c2497d
    https://github.com/scummvm/scummvm/commit/66f880812a4853d4c48fa5693e5fb12d46c2497d
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-06-05T20:57:54+10:00

Commit Message:
AUDIO: Fixed formatting for sf loader functions.
Don't include sf loader support if compiling with fluidsynth 1.x

Changed paths:
    audio/softsynth/fluidsynth.cpp


diff --git a/audio/softsynth/fluidsynth.cpp b/audio/softsynth/fluidsynth.cpp
index 46961a0886..3360748a77 100644
--- a/audio/softsynth/fluidsynth.cpp
+++ b/audio/softsynth/fluidsynth.cpp
@@ -82,7 +82,7 @@ public:
 // MidiDriver method implementations
 
 MidiDriver_FluidSynth::MidiDriver_FluidSynth(Audio::Mixer *mixer)
-	: MidiDriver_Emulated(mixer), _engineSoundFontData(NULL) {
+	: MidiDriver_Emulated(mixer), _engineSoundFontData(nullptr) {
 
 	for (int i = 0; i < ARRAYSIZE(_midiChannels); i++) {
 		_midiChannels[i].init(this, i);
@@ -126,46 +126,45 @@ void MidiDriver_FluidSynth::setStr(const char *name, const char *val) {
 
 // Soundfont memory loader callback functions.
 
-static void *SoundFontMemLoader_open(const char *filename)
-{
+static void *SoundFontMemLoader_open(const char *filename) {
 	void *p;
-	if(filename[0] != '&')
-	{
-		return NULL;
+	if (filename[0] != '&') {
+		return nullptr;
 	}
 	sscanf(filename, "&%p", &p);
 	return p;
 }
 
-static int SoundFontMemLoader_read(void *buf, int count, void *handle)
-{
-	return ((Common::SeekableReadStream *)handle)->read(buf, count) == count ? FLUID_OK : FLUID_FAILED;
+static int SoundFontMemLoader_read(void *buf, int count, void *handle) {
+	return ((Common::SeekableReadStream *) handle)->read(buf, count) == count ? FLUID_OK : FLUID_FAILED;
 }
 
-static int SoundFontMemLoader_seek(void *handle, long offset, int origin)
-{
-	return ((Common::SeekableReadStream *)handle)->seek(offset, origin) ? FLUID_OK : FLUID_FAILED;
+static int SoundFontMemLoader_seek(void *handle, long offset, int origin) {
+	return ((Common::SeekableReadStream *) handle)->seek(offset, origin) ? FLUID_OK : FLUID_FAILED;
 }
 
-static int SoundFontMemLoader_close(void *handle)
-{
-	delete (Common::SeekableReadStream *)handle;
+static int SoundFontMemLoader_close(void *handle) {
+	delete (Common::SeekableReadStream *) handle;
 	return FLUID_OK;
 }
 
-static long SoundFontMemLoader_tell(void *handle)
-{
-	return ((Common::SeekableReadStream *)handle)->pos();
+static long SoundFontMemLoader_tell(void *handle) {
+	return ((Common::SeekableReadStream *) handle)->pos();
 }
 
 int MidiDriver_FluidSynth::open() {
 	if (_isOpen)
 		return MERR_ALREADY_OPEN;
 
-	if (_engineSoundFontData == NULL && !ConfMan.hasKey("soundfont"))
+#if defined(FLUIDSYNTH_VERSION_MAJOR) && FLUIDSYNTH_VERSION_MAJOR > 1
+	bool isUsingInMemorySoundFontData = _engineSoundFontData && !ConfMan.hasKey("soundfont");
+#else
+	bool isUsingInMemorySoundFontData = false;
+#endif
+
+	if (!isUsingInMemorySoundFontData && !ConfMan.hasKey("soundfont"))
 		error("FluidSynth requires a 'soundfont' setting");
 
-	bool isUsingInMemorySoundFontData = _engineSoundFontData && !ConfMan.hasKey("soundfont");
 
 	_settings = new_fluid_settings();
 
@@ -231,8 +230,9 @@ int MidiDriver_FluidSynth::open() {
 	fluid_synth_set_interp_method(_synth, -1, interpMethod);
 
 	const char *soundfont = ConfMan.hasKey("soundfont") ?
-			ConfMan.get("soundfont").c_str() : Common::String::format("&%p", _engineSoundFontData).c_str();
+			ConfMan.get("soundfont").c_str() : Common::String::format("&%p", (void *)_engineSoundFontData).c_str();
 
+#if defined(FLUIDSYNTH_VERSION_MAJOR) && FLUIDSYNTH_VERSION_MAJOR > 1
 	if (isUsingInMemorySoundFontData) {
 		fluid_sfloader_t *soundFontMemoryLoader = new_fluid_defsfloader(_settings);
 		fluid_sfloader_set_callbacks(soundFontMemoryLoader,
@@ -243,6 +243,7 @@ int MidiDriver_FluidSynth::open() {
 									 SoundFontMemLoader_close);
 		fluid_synth_add_sfloader(_synth, soundFontMemoryLoader);
 	}
+#endif
 
 #if defined(IPHONE_IOS7) && defined(IPHONE_SANDBOXED)
 	if (!isUsingInMemorySoundFontData) {




More information about the Scummvm-git-logs mailing list