Skip to content

Commit

Permalink
Windows|Audio: FluidSynth on Windows using MinGW GLib
Browse files Browse the repository at this point in the history
The FluidSynth plugin synthesizes MIDI music using SF2 soundfonts.
  • Loading branch information
skyjake committed Sep 9, 2017
1 parent b99e95d commit 973879d
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 33 deletions.
2 changes: 0 additions & 2 deletions doomsday/apps/client/src/ui/dialogs/audiosettingsdialog.cpp
Expand Up @@ -117,9 +117,7 @@ DENG_GUI_PIMPL(AudioSettingsDialog)
<< new ChoiceItem(tr("Disabled"), "dummy");

musicPlugin->items()
#if defined (UNIX)
<< new ChoiceItem(tr("Fluidsynth"), "fluidsynth")
#endif
<< new ChoiceItem(tr("FMOD"), "fmod")
#if !defined (DENG_DISABLE_SDLMIXER)
<< new ChoiceItem(tr("SDL_mixer"), "sdlmixer")
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/plugins/CMakeLists.txt
Expand Up @@ -31,7 +31,7 @@ add_subdirectory (fmod)
if (NOT TARGET audio_fmod)
add_subdirectory (openal)
endif ()
if (NOT (WIN32 OR IOS))
if (NOT IOS)
add_subdirectory (fluidsynth)
endif ()
if (WIN32)
Expand Down
32 changes: 14 additions & 18 deletions doomsday/apps/plugins/fluidsynth/CMakeLists.txt
Expand Up @@ -5,16 +5,18 @@ cmake_minimum_required (VERSION 3.1)
project (DENG_FLUIDSYNTH)
include (../PluginConfig.cmake)

find_package (PkgConfig)

set (tgt audio_fluidsynth)

# Make an embedded build by default?
if (APPLE)
if (APPLE OR MINGW_GLIB_DIR)
set (embed ON)
elseif (UNIX)
set (embed OFF)
endif ()
if (WIN32 AND NOT MINGW_GLIB_DIR)
message (STATUS "Not building ${tgt} because the MinGW version of GLib is required on Windows (set MINGW_GLIB_DIR)")
return ()
endif ()

option (DENG_FLUIDSYNTH_EMBEDDED
"Compile FluidSynth as part of the ${tgt} plugin" ${embed}
Expand All @@ -23,11 +25,14 @@ option (DENG_FLUIDSYNTH_EMBEDDED
if (DENG_FLUIDSYNTH_EMBEDDED)
find_package (Glib)

# Bundle library dependencies on macOS.
foreach (fn ${GLIB_LIBRARIES})
list (APPEND macRes ${fn},Frameworks)
endforeach ()
deng_find_resources (${macRes})
if (APPLE)
# Bundle library dependencies on macOS.
foreach (fn ${GLIB_LIBRARIES})
list (APPEND macRes ${fn},Frameworks)
endforeach ()
deng_find_resources (${macRes})
add_definitions (-DDARWIN=1)
endif ()

add_definitions (
-D_BSD_SOURCE -DFLUIDSYNTH_NOT_A_DLL -DWITH_FLOAT
Expand All @@ -41,9 +46,6 @@ if (DENG_FLUIDSYNTH_EMBEDDED)
-DHAVE_FCNTL_H -DHAVE_ERRNO_H
)
endif ()
if (APPLE)
add_definitions (-DDARWIN=1)
endif ()

set (FS_DIR ${DENG_EXTERNAL_SOURCE_DIR}/fluidsynth)
include_directories (
Expand Down Expand Up @@ -95,6 +97,7 @@ if (DENG_FLUIDSYNTH_EMBEDDED)

else ()
# We will use the libfluidsynth installed on the system.
find_package (PkgConfig)
pkg_check_modules (FLUIDSYNTH fluidsynth)
if (NOT FLUIDSYNTH_FOUND)
message (STATUS "Not building ${tgt} because \"fluidsynth\" not found (using pkg-config).\n\
Expand Down Expand Up @@ -133,10 +136,3 @@ if (DENG_FLUIDSYNTH_EMBEDDED)
else ()
target_link_libraries (${tgt} PRIVATE ${FLUIDSYNTH_LIBRARIES})
endif ()

# win32 {
# RC_FILE = res/fluidsynth.rc
#
# QMAKE_LFLAGS += /DEF:\"$$PWD/api/dsfluidsynth.def\"
# OTHER_FILES += api/dsfluidsynth.def
# }
6 changes: 3 additions & 3 deletions doomsday/apps/plugins/fluidsynth/api/audio_fluidsynth.def
@@ -1,6 +1,6 @@
LIBRARY AUDIO_FLUIDSYNTH

; All exports should be prefixed DS_.
; All exports should be prefixed DS_ or DM_.

EXPORTS

Expand All @@ -19,6 +19,6 @@ DM_Music_Get
DM_Music_Set
DM_Music_Pause
DM_Music_Stop
DM_Music_SongBuffer
DM_Music_Play
; DM_Music_SongBuffer
; DM_Music_Play
DM_Music_PlayFile
15 changes: 15 additions & 0 deletions doomsday/apps/plugins/fluidsynth/res/resource.h
@@ -0,0 +1,15 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by fluidsynth.rc
//

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
25 changes: 17 additions & 8 deletions doomsday/apps/plugins/fluidsynth/src/fluidsynth_music.cpp
Expand Up @@ -460,18 +460,27 @@ void DM_Music_Pause(int setPause)

int DM_Music_PlayFile(const char *filename, int looped)
{
if(!filename) return false;

if(!fluid_is_midifile(filename))
if (!filename) return false;

#if defined (WIN32)
// Using MinGW.
QString pathStr = filename;
pathStr.replace("\\", "/");
QByteArray const path = pathStr.toUtf8();
#else
QByteArray const path = filename;
#endif

if (!fluid_is_midifile(path))
{
// It doesn't look like MIDI.
App_Log(DE2_LOG_VERBOSE, "[FluidSynth] Cannot play \"%s\": not a MIDI file", filename);
App_Log(DE2_LOG_VERBOSE, "[FluidSynth] Cannot play \"%s\": not a MIDI file", path.constData());
return false;
}

if(sfontId < 0)
if (sfontId < 0)
{
App_Log(DE2_LOG_VERBOSE, "[FluidSynth] Cannot play \"%s\" without an SF2 soundfont", filename);
App_Log(DE2_LOG_VERBOSE, "[FluidSynth] Cannot play \"%s\" without an SF2 soundfont", path.constData());
return false;
}

Expand All @@ -482,13 +491,13 @@ int DM_Music_PlayFile(const char *filename, int looped)

// Create a new player.
fsPlayer = new_fluid_player(DMFluid_Synth());
fluid_player_add(fsPlayer, filename);
fluid_player_add(fsPlayer, path);
fluid_player_set_loop(fsPlayer, looped? -1 /*infinite times*/ : 1);
fluid_player_play(fsPlayer);

startPlayer();

DSFLUIDSYNTH_TRACE("PlayFile: playing '" << filename << "' using player "
DSFLUIDSYNTH_TRACE("PlayFile: playing '" << path.constData() << "' using player "
<< fsPlayer << " looped:" << looped << " sfont:" << sfontId);
return true;
}
23 changes: 22 additions & 1 deletion doomsday/cmake/FindGlib.cmake
@@ -1,3 +1,7 @@
if (WIN32)
set (MINGW_GLIB_DIR "" CACHE PATH "GLib 2.0 SDK directory (mingw)")
endif ()

if (APPLE AND GLIB_STATIC_DIR AND GETTEXT_STATIC_DIR)
# Use the static versions of GLib and its dependencies.
add_library (glib INTERFACE)
Expand All @@ -14,6 +18,23 @@ if (APPLE AND GLIB_STATIC_DIR AND GETTEXT_STATIC_DIR)
)
link_framework (glib INTERFACE CoreFoundation)
link_framework (glib INTERFACE CoreServices)
elseif (MINGW_GLIB_DIR)
add_library (glib INTERFACE)
target_link_libraries (glib INTERFACE
${MINGW_GLIB_DIR}/${DENG_ARCH}/lib/libglib-2.0-0.lib
${MINGW_GLIB_DIR}/${DENG_ARCH}/lib/libgthread-2.0-0.lib
ws2_32.lib
)
target_include_directories (glib INTERFACE
${MINGW_GLIB_DIR}/${DENG_ARCH}/include/glib-2.0
${MINGW_GLIB_DIR}/${DENG_ARCH}/lib/glib-2.0/include
)
deng_install_library (${MINGW_GLIB_DIR}/${DENG_ARCH}/bin/libglib-2.0-0.dll)
deng_install_library (${MINGW_GLIB_DIR}/${DENG_ARCH}/bin/libgthread-2.0-0.dll)
deng_install_library (${MINGW_GLIB_DIR}/${DENG_ARCH}/bin/libintl-8.dll)
deng_install_library (${MINGW_GLIB_DIR}/${DENG_ARCH}/bin/libiconv-2.dll)
deng_install_library (${MINGW_GLIB_DIR}/${DENG_ARCH}/bin/libpcre-1.dll)
deng_install_library (${MINGW_GLIB_DIR}/${DENG_ARCH}/bin/libwinpthread-1.dll)
else ()
# Find GLib via pkg-config.
find_package (PkgConfig)
Expand All @@ -23,4 +44,4 @@ else ()
get_property (GLIB_LIBRARIES TARGET glib
PROPERTY INTERFACE_LINK_LIBRARIES
)
endif ()
endif ()
45 changes: 45 additions & 0 deletions doomsday/external/fluidsynth/src/config_win32.h
@@ -0,0 +1,45 @@
#define VERSION FLUIDSYNTH_VERSION

#define HAVE_STRING_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STDIO_H 1
#define HAVE_MATH_H 1
#define HAVE_STDARG_H 1
#define HAVE_FCNTL_H 1
#define HAVE_LIMITS_H 1
#define HAVE_IO_H 1
#define HAVE_WINDOWS_H 1

#define DSOUND_SUPPORT 0
#define WINMIDI_SUPPORT 0
#define WITH_FLOAT 1

//#define snprintf _snprintf
#define strcasecmp _stricmp

#if _MSC_VER < 1500
#define vsnprintf _vsnprintf
#endif

#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2


#define WITH_PROFILING 0

#pragma warning(disable : 4244)
#pragma warning(disable : 4101)
#pragma warning(disable : 4305)
#pragma warning(disable : 4996)

#ifndef inline
#define inline __inline
#endif

typedef int socklen_t;

#include <stdint.h>

typedef uint8_t u_int8_t;
typedef uint32_t u_int32_t;

0 comments on commit 973879d

Please sign in to comment.