Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PS2 fluidsynth #1

Open
wants to merge 27 commits into
base: ee-sans_glib
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fa5173c
Implement MSGS-style Drum Note Cut (#1199)
derselbst Dec 29, 2023
bd04f3f
Make settings more pleasing, natural and subtler (#1287)
es20490446e Jan 2, 2024
eabae3b
Merge remote-tracking branch 'origin/release/2.3' into master
derselbst Jan 3, 2024
652df6f
Fix signedness warning
derselbst Mar 25, 2024
1b40e17
Fix ISO C warning
derselbst Mar 25, 2024
0901883
Stop the pipewire loop before destroying the stream
mawe42 Mar 26, 2024
0588096
Lock thread loop before destroying stream
mawe42 Mar 26, 2024
56932cd
Deprecate LASH support
derselbst Mar 26, 2024
a3b88cc
Make it a WARNING
derselbst Mar 26, 2024
895f07d
Fix XG drum bank selection logic
derselbst Mar 26, 2024
c5ed1af
Merge branch 'release/2.3' into master
derselbst Mar 26, 2024
72cc6b3
Remove LASH
derselbst Mar 26, 2024
619fc5c
Add FLUID_HOST_COMPILER cmake variable
derselbst Mar 26, 2024
46ff5fa
Merge branch 'release/2.3' into master
derselbst Mar 26, 2024
db86c36
Remove vcpkg CI badge from README
derselbst Mar 26, 2024
e104532
add a new windows workflow based on msys2 (#1316)
pedrolcl Apr 20, 2024
f78a9db
Minor fixups for MSYS2 CI (#1317)
derselbst Apr 20, 2024
abdd098
Keep GitHub Actions up to date with GitHub's Dependabot
cclauss Apr 21, 2024
60ee179
Merge pull request #1318 from cclauss/patch-1
derselbst Apr 22, 2024
7a4f8c7
Bump the github-actions group with 2 updates
dependabot[bot] Apr 22, 2024
cb8da1e
Merge pull request #1319 from FluidSynth/dependabot/github_actions/gi…
derselbst Apr 22, 2024
af8de7b
Sloppy port to PS2
7dog123 May 6, 2024
d2100a2
Since the PS2SDK doesn't have atomic libaries use global mutex from p…
7dog123 May 7, 2024
9c72492
Update fluidsynth_priv.h
7dog123 Jul 26, 2024
f41b53c
Merge branch 'ee-sans-glib' into ee-sans_glib
Wolf3s Aug 28, 2024
0e14d79
Remove messy PS2 code.
Wolf3s Aug 28, 2024
ffa4324
Merge pull request #1 from Wolf3s/ee-sans-glib
7dog123 Sep 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 74 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,62 @@ option ( enable-portaudio "compile PortAudio support" off )
option ( enable-profiling "profile the dsp code" off )
option ( enable-trap-on-fpe "enable SIGFPE trap on Floating Point Exceptions" off )
option ( enable-ubsan "compile and link against UBSan (for debugging fluidsynth internals)" off )

# Options enabled by default
option ( enable-aufile "compile support for sound file output" on )
option ( BUILD_SHARED_LIBS "Build a shared object or DLL" on )
option ( enable-dbus "compile DBUS support (if it is available)" on )
option ( enable-ipv6 "enable IPv6 support at the cost of disabling IPv4" on )
option ( enable-jack "compile JACK support (if it is available)" on )
if ( PS2 )
option ( enable-aufile "compile support for sound file output" off )
option ( BUILD_SHARED_LIBS "Build a shared object or DLL" off )
option ( enable-dbus "compile DBUS support (if it is available)" off )
option ( enable-ipv6 "enable IPv6 support at the cost of disabling IPv4" off )
option ( enable-jack "compile JACK support (if it is available)" off )
else ()
option ( enable-aufile "compile support for sound file output" on )
option ( BUILD_SHARED_LIBS "Build a shared object or DLL" on )
option ( enable-dbus "compile DBUS support (if it is available)" on )
option ( enable-ipv6 "enable IPv6 support at the cost of disabling IPv4" on )
option ( enable-jack "compile JACK support (if it is available)" on )
endif()
option ( enable-ladspa "enable LADSPA effect units" off )
option ( enable-libinstpatch "use libinstpatch (if available) to load DLS and GIG files" on )
option ( enable-libsndfile "compile libsndfile support (if it is available)" on )
option ( enable-midishare "compile MidiShare support (if it is available)" on )

if ( PS2 )
option ( enable-libinstpatch "use libinstpatch (if available) to load DLS and GIG files" off )
option ( enable-libsndfile "compile libsndfile support (if it is available)" off )
option ( enable-midishare "compile MidiShare support (if it is available)" off )
else ()
option ( enable-libinstpatch "use libinstpatch (if available) to load DLS and GIG files" on )
option ( enable-libsndfile "compile libsndfile support (if it is available)" on )
option ( enable-midishare "compile MidiShare support (if it is available)" on )
endif()

option ( enable-opensles "compile OpenSLES support (if it is available)" off )
option ( enable-oboe "compile Oboe support (requires OpenSLES and/or AAudio)" off )
option ( enable-network "enable network support (requires BSD sockets)" on )
option ( enable-oss "compile OSS support (if it is available)" on )
option ( enable-dsound "compile DirectSound support (if it is available)" on )
option ( enable-wasapi "compile Windows WASAPI support (if it is available)" on )
option ( enable-waveout "compile Windows WaveOut support (if it is available)" on )
option ( enable-winmidi "compile Windows MIDI support (if it is available)" on )
option ( enable-sdl2 "compile SDL2 audio support (if it is available)" on )
option ( enable-pulseaudio "compile PulseAudio support (if it is available)" on )
option ( enable-pipewire "compile PipeWire support (if it is available)" on )
option ( enable-readline "compile readline lib line editing (if it is available)" on )
option ( enable-threads "enable multi-threading support (such as parallel voice synthesis)" on )
option ( enable-openmp "enable OpenMP support (parallelization of soundfont decoding, vectorization of voice mixing, etc.)" on )

if ( PS2 )
option ( enable-network "enable network support (requires BSD sockets)" off )
option ( enable-oss "compile OSS support (if it is available)" off )
option ( enable-dsound "compile DirectSound support (if it is available)" off )
option ( enable-wasapi "compile Windows WASAPI support (if it is available)" off )
option ( enable-waveout "compile Windows WaveOut support (if it is available)" off )
option ( enable-winmidi "compile Windows MIDI support (if it is available)" off )
option ( enable-sdl2 "compile SDL2 audio support (if it is available)" off )
option ( enable-pulseaudio "compile PulseAudio support (if it is available)" off )
option ( enable-pipewire "compile PipeWire support (if it is available)" off )
option ( enable-readline "compile readline lib line editing (if it is available)" off )
option ( enable-threads "enable multi-threading support (such as parallel voice synthesis)" off )
option ( enable-openmp "enable OpenMP support (parallelization of soundfont decoding, vectorization of voice mixing, etc.)" off )
else()
option ( enable-network "enable network support (requires BSD sockets)" on )
option ( enable-oss "compile OSS support (if it is available)" on )
option ( enable-dsound "compile DirectSound support (if it is available)" on )
option ( enable-wasapi "compile Windows WASAPI support (if it is available)" on )
option ( enable-waveout "compile Windows WaveOut support (if it is available)" on )
option ( enable-winmidi "compile Windows MIDI support (if it is available)" on )
option ( enable-sdl2 "compile SDL2 audio support (if it is available)" on )
option ( enable-pulseaudio "compile PulseAudio support (if it is available)" on )
option ( enable-pipewire "compile PipeWire support (if it is available)" on )
option ( enable-readline "compile readline lib line editing (if it is available)" on )
option ( enable-threads "enable multi-threading support (such as parallel voice synthesis)" on )
option ( enable-openmp "enable OpenMP support (parallelization of soundfont decoding, vectorization of voice mixing, etc.)" on )
endif()
# Platform specific options
if ( CMAKE_SYSTEM MATCHES "Linux|FreeBSD|DragonFly" )
option ( enable-lash "compile LASH support (if it is available)" on )
Expand All @@ -122,10 +152,18 @@ if ( CMAKE_SYSTEM MATCHES "OS2" )
endif ( CMAKE_SYSTEM MATCHES "OS2" )

# the default C standard to use for all targets
set(CMAKE_C_STANDARD 90)
if ( PS2 )
set(CMAKE_C_STANDARD 99)
else ()
set(CMAKE_C_STANDARD 90)
endif ()

# the default C++ standard to use for all targets
set(CMAKE_CXX_STANDARD 98)
if ( PS2 )
set(CMAKE_CXX_STANDARD 11)
else ()
set(CMAKE_CXX_STANDARD 98)
endif ()

# whether to use gnu extensions
set(CMAKE_C_EXTENSIONS ON)
Expand Down Expand Up @@ -213,13 +251,7 @@ if ( CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_C
endif ( HAVE_INCOMPATIBLE_POINTER_TYPES )

set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wpointer-arith -Wcast-qual -Wno-unused-parameter" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lpthread" )

# prepend to build type specific flags, to allow users to override
set ( CMAKE_C_FLAGS_DEBUG "-g ${CMAKE_C_FLAGS_DEBUG}" )
Expand Down Expand Up @@ -360,6 +392,10 @@ if ( WIN32 )
endif ( MINGW )
endif ( WIN32 )

if ( PS2 )
set ( LIBFLUID_CPPFLAGS "-DFLUIDSYNTH_NOT_A_DLL -DFLUID_MUTEX_INIT" )
endif ()

# Check for threads and math
find_package ( Threads REQUIRED )

Expand All @@ -370,6 +406,14 @@ endif ( HAS_LIBM )

set ( LIBFLUID_LIBS ${MATH_LIBRARY} Threads::Threads )

unset ( PS2DEV_LIBS CACHE)
if ( PS2 )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these specific changes being needed?

set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L$ENV{PS2SDK}/iop/lib")
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -Wwrite-strings -Wcast-align -Wimplicit-int -Wsequence-point -fsigned-char")
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wwrite-strings -Wcast-align -Wsequence-point -fsigned-char")
set ( PS2DEV_LIBS "${PS2DEV_LIBS};cdvd;kernel;debug;mc;c;audsrv;gskit" )
endif ()

# IBM OS/2
unset ( DART_SUPPORT CACHE )
unset ( DART_LIBS CACHE )
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ target_link_libraries ( libfluidsynth-OBJ PUBLIC
${COREMIDI_LIBS}
${WINDOWS_LIBS}
${LIBFLUID_LIBS}
${PS2DEV_LIBS}
)

if ( TARGET OpenMP::OpenMP_C AND HAVE_OPENMP )
Expand Down
70 changes: 69 additions & 1 deletion src/utils/fluid_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,78 @@
#include "fluid_rtkit.h"
#endif

#if HAVE_PTHREAD_H && !defined(_WIN32)
#if HAVE_PTHREAD_H && !defined(_WIN32) || defined(PS2)
// Do not include pthread on windows. It includes winsock.h, which collides with ws2tcpip.h from fluid_sys.h
// It isn't need on Windows anyway.
#include <pthread.h>

static pthread_mutex_t g_atomic_lock = PTHREAD_MUTEX_INITIALIZER;

int pthread_atomic_int_get(const volatile int *atomic)
{
int value;

pthread_mutex_lock (&g_atomic_lock);
value = *atomic;
pthread_mutex_unlock (&g_atomic_lock);

return value;
}

void pthread_atomic_int_inc(volatile int *atomic)
{
pthread_mutex_lock (&g_atomic_lock);
(*atomic)++;
pthread_mutex_unlock (&g_atomic_lock);
}

void pthread_atomic_int_set(volatile int *atomic,
int value)
{
pthread_mutex_lock (&g_atomic_lock);
*atomic = value;
pthread_mutex_unlock (&g_atomic_lock);
}

bool pthread_atomic_int_dec_and_test (volatile int *atomic)
{
bool is_zero;

pthread_mutex_lock (&g_atomic_lock);
is_zero = --(*atomic) == 0;
pthread_mutex_unlock (&g_atomic_lock);

return is_zero;
}

bool pthread_atomic_int_compare_and_exchange(volatile int *atomic,
int oldval,
int newval)
{
bool success;

pthread_mutex_lock (&g_atomic_lock);

if ((success = (*atomic == oldval)))
*atomic = newval;

pthread_mutex_unlock (&g_atomic_lock);

return success;
}

int pthread_atomic_int_add(volatile int *atomic,
int val)
{
int oldval;

pthread_mutex_lock (&g_atomic_lock);
oldval = *atomic;
*atomic = oldval + val;
pthread_mutex_unlock (&g_atomic_lock);

return oldval;
}
#endif

/* WIN32 HACK - Flag used to differentiate between a file descriptor and a socket.
Expand Down
25 changes: 25 additions & 0 deletions src/utils/fluid_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,29 @@ typedef _private fluid_private_t;

/* Atomic operations */

#if HAVE_PTHREAD_H

#include <stdbool.h>

int pthread_atomic_int_get(const volatile int *atomic);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that currently EE toolchain doesn't support atomic library, however, we still have the headers, can't we just keep the names and implement those methods with the same implementation you did with pthread?
It will avoid you the change in this header

void pthread_atomic_int_inc(volatile int *atomic);
void pthread_atomic_int_set(volatile int *atomic, int value);
bool pthread_atomic_int_dec_and_test (volatile int *atomic);
bool pthread_atomic_int_compare_and_exchange(volatile int *atomic, int oldval, int newval);
int pthread_atomic_int_add(volatile int *atomic, int val);

#define fluid_atomic_int_inc(_pi) pthread_atomic_int_inc(_pi)
#define fluid_atomic_int_get(_pi) pthread_atomic_int_get(_pi)
#define fluid_atomic_int_set(_pi, _val) pthread_atomic_int_set(_pi, _val)
#define fluid_atomic_int_dec_and_test(_pi) pthread_atomic_int_dec_and_test(_pi)
#define fluid_atomic_int_compare_and_exchange(_pi, _old, _new) \
pthread_atomic_int_compare_and_exchange(_pi, _old, _new)
#define fluid_atomic_int_add(_pi, _add) \
pthread_atomic_int_add(_pi, _add)
#define fluid_atomic_int_exchange_and_add(_pi, _add) \
pthread_atomic_int_add(_pi, _add)

#else
#define fluid_atomic_int_inc(_pi) atomic_fetch_add(_pi, 1)
#define fluid_atomic_int_get(_pi) atomic_load(_pi)
#define fluid_atomic_int_set(_pi, _val) atomic_store(_pi, _val)
Expand All @@ -344,6 +367,8 @@ typedef _private fluid_private_t;
#define fluid_atomic_pointer_compare_and_exchange(_pp, _old, _new) \
atomic_compare_exchange_weak(_pp, _old, _new)

#endif

static FLUID_INLINE void
fluid_atomic_float_set(fluid_atomic_float_t *fptr, float val)
{
Expand Down
11 changes: 10 additions & 1 deletion src/utils/fluidsynth_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
#include <strings.h>
#endif

#ifdef PS2
#include <tamtypes.h>
#endif

#include <assert.h>
#include <strings.h>
#include <stdatomic.h>
Expand Down Expand Up @@ -80,10 +84,15 @@ typedef double fluid_real_t;


/** Atomic types */
#if defined(PS2)
typedef int fluid_atomic_int_t;
typedef unsigned int fluid_atomic_uint_t;
typedef float fluid_atomic_float_t;
#else
typedef _Atomic int fluid_atomic_int_t;
typedef _Atomic unsigned int fluid_atomic_uint_t;
typedef _Atomic float fluid_atomic_float_t;

#endif


/***************************************************************
Expand Down