game-music-emu: Merged master into new-repo

From 1f651e0361c04a3b87dc51b7de1127002b96c4eb Mon Sep 17 00:00:00 2001
From: Wohlstand <[EMAIL REDACTED]>
Date: Tue, 20 Jun 2023 23:25:37 +0300
Subject: [PATCH 01/17] Fixed build on the MSVC 2015

The static_assert() breaks the build on the MSVC 2015, so, use a condition to use the static_assert at newer MSVC only, and stay with the regular assert on the older MSVC versions.
---
 gme/Ay_Emu.cpp         | 4 ++--
 gme/Classic_Emu.cpp    | 6 +++---
 gme/Effects_Buffer.cpp | 2 +-
 gme/Gbs_Emu.cpp        | 2 +-
 gme/Gym_Emu.cpp        | 2 +-
 gme/Hes_Emu.cpp        | 4 ++--
 gme/Kss_Emu.cpp        | 4 ++--
 gme/Nes_Cpu.cpp        | 2 +-
 gme/Nes_Vrc6_Apu.cpp   | 2 +-
 gme/Nsf_Emu.cpp        | 2 +-
 gme/Nsfe_Emu.cpp       | 2 +-
 gme/Snes_Spc.cpp       | 2 +-
 gme/Spc_Dsp.cpp        | 4 ++--
 gme/Spc_Emu.cpp        | 2 +-
 gme/Vgm_Emu.cpp        | 4 ++--
 gme/blargg_common.h    | 6 ++++++
 16 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/gme/Ay_Emu.cpp b/gme/Ay_Emu.cpp
index cd88fcc..bf55fdc 100644
--- a/gme/Ay_Emu.cpp
+++ b/gme/Ay_Emu.cpp
@@ -128,8 +128,8 @@ extern gme_type_t const gme_ay_type = &gme_ay_type_;
 
 blargg_err_t Ay_Emu::load_mem_( byte const* in, long size )
 {
-	static_assert( offsetof (header_t,track_info [2]) == header_size, "AY Header layout incorrect!" );
-	
+	blaarg_static_assert( offsetof (header_t,track_info [2]) == header_size, "AY Header layout incorrect!" );
+
 	RETURN_ERR( parse_header( in, size, &file ) );
 	set_track_count( file.header->max_track + 1 );
 	
diff --git a/gme/Classic_Emu.cpp b/gme/Classic_Emu.cpp
index cf1a43b..f2d351d 100644
--- a/gme/Classic_Emu.cpp
+++ b/gme/Classic_Emu.cpp
@@ -25,9 +25,9 @@ Classic_Emu::Classic_Emu()
 	voice_types   = 0;
 	
 	// avoid inconsistency in our duplicated constants
-	static_assert( (int) wave_type  == (int) Multi_Buffer::wave_type, "wave_type inconsistent across two classes using it" );
-	static_assert( (int) noise_type == (int) Multi_Buffer::noise_type, "noise_type inconsistent across two classes using it"  );
-	static_assert( (int) mixed_type == (int) Multi_Buffer::mixed_type, "mixed_type inconsistent across two classes using it"  );
+	blaarg_static_assert( (int) wave_type  == (int) Multi_Buffer::wave_type, "wave_type inconsistent across two classes using it" );
+	blaarg_static_assert( (int) noise_type == (int) Multi_Buffer::noise_type, "noise_type inconsistent across two classes using it"  );
+	blaarg_static_assert( (int) mixed_type == (int) Multi_Buffer::mixed_type, "mixed_type inconsistent across two classes using it"  );
 }
 
 Classic_Emu::~Classic_Emu()
diff --git a/gme/Effects_Buffer.cpp b/gme/Effects_Buffer.cpp
index 75e7bfe..d3afeff 100644
--- a/gme/Effects_Buffer.cpp
+++ b/gme/Effects_Buffer.cpp
@@ -217,7 +217,7 @@ void Effects_Buffer::config( const config_t& cfg )
 			chan_types [i*chan_types_count+2].left   = &bufs [i*max_buf_count+5];
 			chan_types [i*chan_types_count+2].right  = &bufs [i*max_buf_count+6];
 		}
-		static_assert( chan_types_count >= 3, "Need at least three audio channels for effects processing" );
+		blaarg_static_assert( chan_types_count >= 3, "Need at least three audio channels for effects processing" );
 	}
 	else
 	{
diff --git a/gme/Gbs_Emu.cpp b/gme/Gbs_Emu.cpp
index 2af6d1a..8b89efe 100644
--- a/gme/Gbs_Emu.cpp
+++ b/gme/Gbs_Emu.cpp
@@ -107,7 +107,7 @@ extern gme_type_t const gme_gbs_type = &gme_gbs_type_;
 
 blargg_err_t Gbs_Emu::load_( Data_Reader& in )
 {
-	static_assert( offsetof (header_t,copyright [32]) == header_size, "GBS Header layout incorrect!" );
+	blaarg_static_assert( offsetof (header_t,copyright [32]) == header_size, "GBS Header layout incorrect!" );
 	RETURN_ERR( rom.load( in, header_size, &header_, 0 ) );
 	
 	set_track_count( header_.track_count );
diff --git a/gme/Gym_Emu.cpp b/gme/Gym_Emu.cpp
index a3bc4ed..9448936 100644
--- a/gme/Gym_Emu.cpp
+++ b/gme/Gym_Emu.cpp
@@ -210,7 +210,7 @@ void Gym_Emu::mute_voices_( int mask )
 
 blargg_err_t Gym_Emu::load_mem_( byte const* in, long size )
 {
-	static_assert( offsetof (header_t,packed [4]) == header_size, "GYM Header layout incorrect!" );
+	blaarg_static_assert( offsetof (header_t,packed [4]) == header_size, "GYM Header layout incorrect!" );
 	int offset = 0;
 	RETURN_ERR( check_header( in, size, &offset ) );
 	set_voice_count( 8 );
diff --git a/gme/Hes_Emu.cpp b/gme/Hes_Emu.cpp
index fedc678..27e506e 100644
--- a/gme/Hes_Emu.cpp
+++ b/gme/Hes_Emu.cpp
@@ -119,7 +119,7 @@ struct Hes_File : Gme_Info_
 	
 	blargg_err_t load_( Data_Reader& in )
 	{
-		static_assert( offsetof (header_t,fields) == Hes_Emu::header_size + 0x20, "HES header layout is incorrect!" );
+		blaarg_static_assert( offsetof (header_t,fields) == Hes_Emu::header_size + 0x20, "HES header layout is incorrect!" );
 		blargg_err_t err = in.read( &h, sizeof h );
 		if ( err )
 			return (err == in.eof_error ? gme_wrong_file_type : err);
@@ -144,7 +144,7 @@ extern gme_type_t const gme_hes_type = &gme_hes_type_;
 
 blargg_err_t Hes_Emu::load_( Data_Reader& in )
 {
-	static_assert( offsetof (header_t,unused [4]) == header_size, "HES header layout is incorrect!" );
+	blaarg_static_assert( offsetof (header_t,unused [4]) == header_size, "HES header layout is incorrect!" );
 	RETURN_ERR( rom.load( in, header_size, &header_, unmapped ) );
 	
 	RETURN_ERR( check_hes_header( header_.tag ) );
diff --git a/gme/Kss_Emu.cpp b/gme/Kss_Emu.cpp
index 960f31f..8e0f528 100644
--- a/gme/Kss_Emu.cpp
+++ b/gme/Kss_Emu.cpp
@@ -125,8 +125,8 @@ void Kss_Emu::update_gain()
 blargg_err_t Kss_Emu::load_( Data_Reader& in )
 {
 	memset( &header_, 0, sizeof header_ );
-	static_assert( offsetof (header_t,device_flags) == header_size - 1, "KSS Header layout incorrect!" );
-	static_assert( offsetof (ext_header_t,msx_audio_vol) == ext_header_size - 1, "KSS Extended Header layout incorrect!" );
+	blaarg_static_assert( offsetof (header_t,device_flags) == header_size - 1, "KSS Header layout incorrect!" );
+	blaarg_static_assert( offsetof (ext_header_t,msx_audio_vol) == ext_header_size - 1, "KSS Extended Header layout incorrect!" );
 	RETURN_ERR( rom.load( in, header_size, STATIC_CAST(header_t*,&header_), 0 ) );
 	
 	RETURN_ERR( check_kss_header( header_.tag ) );
diff --git a/gme/Nes_Cpu.cpp b/gme/Nes_Cpu.cpp
index aa59967..f9e1214 100644
--- a/gme/Nes_Cpu.cpp
+++ b/gme/Nes_Cpu.cpp
@@ -78,7 +78,7 @@ void Nes_Cpu::reset( void const* unmapped_page )
 	end_time_ = future_nes_time;
 	error_count_ = 0;
 	
-	static_assert( page_size == 0x800, "NES set to use unhandled page size" ); // assumes this
+	blaarg_static_assert( page_size == 0x800, "NES set to use unhandled page size" ); // assumes this
 	set_code_page( page_count, unmapped_page );
 	map_code( 0x2000, 0xE000, unmapped_page, true );
 	map_code( 0x0000, 0x2000, low_mem, true );
diff --git a/gme/Nes_Vrc6_Apu.cpp b/gme/Nes_Vrc6_Apu.cpp
index 4c4023f..0f230fb 100644
--- a/gme/Nes_Vrc6_Apu.cpp
+++ b/gme/Nes_Vrc6_Apu.cpp
@@ -72,7 +72,7 @@ void Nes_Vrc6_Apu::end_frame( blip_time_t time )
 
 void Nes_Vrc6_Apu::save_state( vrc6_apu_state_t* out ) const
 {
-	static_assert( sizeof (vrc6_apu_state_t) == 20, "VRC APU State layout incorrect!" );
+	blaarg_static_assert( sizeof (vrc6_apu_state_t) == 20, "VRC APU State layout incorrect!" );
 	out->saw_amp = oscs [2].amp;
 	for ( int i = 0; i < osc_count; i++ )
 	{
diff --git a/gme/Nsf_Emu.cpp b/gme/Nsf_Emu.cpp
index ce55db4..ed7f0ad 100644
--- a/gme/Nsf_Emu.cpp
+++ b/gme/Nsf_Emu.cpp
@@ -330,7 +330,7 @@ blargg_err_t Nsf_Emu::init_sound()
 
 blargg_err_t Nsf_Emu::load_( Data_Reader& in )
 {
-	static_assert( offsetof (header_t,unused [4]) == header_size, "NSF Header layout incorrect!" );
+	blaarg_static_assert( offsetof (header_t,unused [4]) == header_size, "NSF Header layout incorrect!" );
 	RETURN_ERR( rom.load( in, header_size, &header_, 0 ) );
 
 	set_track_count( header_.track_count );
diff --git a/gme/Nsfe_Emu.cpp b/gme/Nsfe_Emu.cpp
index 6a75420..381a89e 100644
--- a/gme/Nsfe_Emu.cpp
+++ b/gme/Nsfe_Emu.cpp
@@ -96,7 +96,7 @@ struct nsfe_info_t
 blargg_err_t Nsfe_Info::load( Data_Reader& in, Nsf_Emu* nsf_emu )
 {
 	int const nsfe_info_size = 16;
-	static_assert( offsetof (nsfe_info_t,unused [6]) == nsfe_info_size, "NSFE Info header layout incorrect!" );
+	blaarg_static_assert( offsetof (nsfe_info_t,unused [6]) == nsfe_info_size, "NSFE Info header layout incorrect!" );
 	
 	// check header
 	byte signature [4];
diff --git a/gme/Snes_Spc.cpp b/gme/Snes_Spc.cpp
index 6b67f95..305fe2c 100644
--- a/gme/Snes_Spc.cpp
+++ b/gme/Snes_Spc.cpp
@@ -217,7 +217,7 @@ blargg_err_t Snes_Spc::load_spc( void const* data, long size )
 	spc_file_t const* const spc = (spc_file_t const*) data;
 	
 	// be sure compiler didn't insert any padding into fle_t
-	static_assert( sizeof (spc_file_t) == spc_min_file_size + 0x80, "SPC File header layout incorrect!" );
+	blaarg_static_assert( sizeof (spc_file_t) == spc_min_file_size + 0x80, "SPC File header layout incorrect!" );
 	
 	// Check signature and file size
 	if ( size < signature_size || memcmp( spc, signature, 27 ) )
diff --git a/gme/Spc_Dsp.cpp b/gme/Spc_Dsp.cpp
index 17b0edd..34ac057 100644
--- a/gme/Spc_Dsp.cpp
+++ b/gme/Spc_Dsp.cpp
@@ -668,10 +668,10 @@ void Spc_Dsp::init( void* ram_64k )
 	reset();
 	
 	// be sure this sign-extends
-	static_assert( (int16_t) 0x8000 == -0x8000, "This compiler doesn't sign-extend during integer promotion" );
+	blaarg_static_assert( (int16_t) 0x8000 == -0x8000, "This compiler doesn't sign-extend during integer promotion" );
 
 	// be sure right shift preserves sign
-	static_assert( (-1 >> 1) == -1, "This compiler doesn't preserve sign on right-shift" );
+	blaarg_static_assert( (-1 >> 1) == -1, "This compiler doesn't preserve sign on right-shift" );
 		
 	#ifndef NDEBUG
 		// check clamp macro
diff --git a/gme/Spc_Emu.cpp b/gme/Spc_Emu.cpp
index d9d3d50..39c8a05 100644
--- a/gme/Spc_Emu.cpp
+++ b/gme/Spc_Emu.cpp
@@ -416,7 +416,7 @@ void Spc_Emu::disable_echo_( bool disable )
 
 blargg_err_t Spc_Emu::load_mem_( byte const* in, long size )
 {
-	static_assert( offsetof (header_t,unused2 [46]) == header_size, "SPC Header layout incorrect!" );
+	blaarg_static_assert( offsetof (header_t,unused2 [46]) == header_size, "SPC Header layout incorrect!" );
 	file_data = in;
 	file_size = size;
 	set_voice_count( Snes_Spc::voice_count );
diff --git a/gme/Vgm_Emu.cpp b/gme/Vgm_Emu.cpp
index c62aa82..b20387b 100644
--- a/gme/Vgm_Emu.cpp
+++ b/gme/Vgm_Emu.cpp
@@ -324,8 +324,8 @@ void Vgm_Emu::mute_voices_( int mask )
 
 blargg_err_t Vgm_Emu::load_mem_( byte const* new_data, long new_size )
 {
-	static_assert( offsetof (header_t,unused2 [8]) == header_size, "VGM Header layout incorrect!" );
-	
+	blaarg_static_assert( offsetof (header_t,unused2 [8]) == header_size, "VGM Header layout incorrect!" );
+
 	if ( new_size <= header_size )
 		return gme_wrong_file_type;
 	
diff --git a/gme/blargg_common.h b/gme/blargg_common.h
index 11b86ce..a67753f 100644
--- a/gme/blargg_common.h
+++ b/gme/blargg_common.h
@@ -27,6 +27,12 @@
 	#define STATIC_CAST(T,expr) ((T) (expr))
 #endif
 
+#if !defined(_MSC_VER) || _MSC_VER > 1910
+	#define blaarg_static_assert(cond, msg) static_assert(cond, msg)
+#else
+	#define blaarg_static_assert(cond, msg) assert(cond)
+#endif
+
 // blargg_err_t (0 on success, otherwise error string)
 #ifndef blargg_err_t
 	typedef const char* blargg_err_t;

From 65d238684960ac08174682eea93b4fb391cfe84c Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <sezeroz@gmail.com>
Date: Tue, 3 Oct 2023 14:25:56 +0300
Subject: [PATCH 02/17] add gme_set_fade_msecs to avoid gme_set_fade abi
 change,

and revert SOVERSION bump, change version down to 0.6.4.
---
 CMakeLists.txt          |  2 +-
 gme.txt                 |  2 +-
 gme/CMakeLists.txt      |  2 +-
 gme/gme.cpp             |  3 ++-
 gme/gme.h               | 13 +++++++++----
 player/Music_Player.cpp |  4 ++--
 readme.txt              |  2 +-
 7 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4dc8582..6e0e288 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,7 +6,7 @@ include (CheckCXXCompilerFlag)
 include (CTest)
 
 # When version is changed, also change the one in gme/gme.h to match
-set(GME_VERSION 0.7.0 CACHE INTERNAL "libgme Version")
+set(GME_VERSION 0.6.4 CACHE INTERNAL "libgme Version")
 
 # Default emulators to build (all of them! ;)
 if (NOT DEFINED USE_GME_AY)
diff --git a/gme.txt b/gme.txt
index cbddf7f..30615b2 100644
--- a/gme.txt
+++ b/gme.txt
@@ -1,4 +1,4 @@
-Game_Music_Emu 0.7.0
+Game_Music_Emu 0.6.4
 --------------------
 Author     : Shay Green <gblargg@gmail.com>
 Maintainer : Michael Pyne <mpyne@purinchu.net>
diff --git a/gme/CMakeLists.txt b/gme/CMakeLists.txt
index f6399c3..46a58bd 100644
--- a/gme/CMakeLists.txt
+++ b/gme/CMakeLists.txt
@@ -201,7 +201,7 @@ endif()
 # Hopefully the API can stay compatible with old versions.
 set_target_properties(gme
     PROPERTIES VERSION ${GME_VERSION}
-               SOVERSION 1)
+               SOVERSION 0)
 
 # macOS framework build
 if(BUILD_FRAMEWORK)
diff --git a/gme/gme.cpp b/gme/gme.cpp
index 72741da..57ccdf7 100644
--- a/gme/gme.cpp
+++ b/gme/gme.cpp
@@ -380,7 +380,8 @@ void      gme_set_user_cleanup(Music_Emu* me, gme_user_cleanup_t func ) { me->se
 
 gme_err_t gme_start_track    ( Music_Emu* me, int index )           { return me->start_track( index ); }
 gme_err_t gme_play           ( Music_Emu* me, int n, short* p )     { return me->play( n, p ); }
-void      gme_set_fade       ( Music_Emu* me, int start_msec, int fade_msec ) { me->set_fade( start_msec, fade_msec ); }
+void      gme_set_fade       ( Music_Emu* me, int start_msec )      { me->set_fade( start_msec ); }
+void      gme_set_fade_msecs ( Music_Emu* me, int start_msec, int fade_msec ) { me->set_fade( start_msec, fade_msec ); }
 int       gme_track_ended    ( Music_Emu const* me )                { return me->track_ended(); }
 int       gme_tell           ( Music_Emu const* me )                { return me->tell(); }
 int       gme_tell_samples   ( Music_Emu const* me )                { return me->tell_samples(); }
diff --git a/gme/gme.h b/gme/gme.h
index ef1d851..6920c73 100644
--- a/gme/gme.h
+++ b/gme/gme.h
@@ -1,6 +1,6 @@
 /* Game music emulator library C interface (also usable from C++) */
 
-/* Game_Music_Emu 0.7.0 */
+/* Game_Music_Emu 0.6.4 */
 #ifndef GME_H
 #define GME_H
 
@@ -8,7 +8,7 @@
 	extern "C" {
 #endif
 
-#define GME_VERSION 0x000700 /* 1 byte major, 1 byte minor, 1 byte patch-level */
+#define GME_VERSION 0x000604 /* 1 byte major, 1 byte minor, 1 byte patch-level */
 
 /* Error string returned by library functions, or NULL if no error (success) */
 typedef const char* gme_err_t;
@@ -55,7 +55,12 @@ BLARGG_EXPORT void gme_delete( Music_Emu* );
 
 /* Set time to start fading track out. Once fade ends track_ended() returns true.
 Fade time can be changed while track is playing. */
-BLARGG_EXPORT void gme_set_fade( Music_Emu*, int start_msec, int length_msec );
+BLARGG_EXPORT void gme_set_fade( Music_Emu*, int start_msec );
+
+/** See gme_set_fade.
+ * @since 0.6.4
+ */
+BLARGG_EXPORT void gme_set_fade_msecs( Music_Emu*, int start_msec, int length_msecs );
 
 /**
  * If do_autoload_limit is nonzero, then automatically load track length
@@ -174,7 +179,7 @@ voices, 0 unmutes them all, 0x01 mutes just the first voice, etc. */
 BLARGG_EXPORT void gme_mute_voices( Music_Emu*, int muting_mask );
 
 /* Disable/Enable echo effect for SPC files */
-/* Available since 0.7.0 */
+/* Available since 0.6.4 */
 BLARGG_EXPORT void gme_disable_echo( Music_Emu*, int disable );
 
 /* Frequency equalizer parameters (see gme.txt) */
diff --git a/player/Music_Player.cpp b/player/Music_Player.cpp
index 4430c3c..5df7e61 100644
--- a/player/Music_Player.cpp
+++ b/player/Music_Player.cpp
@@ -151,7 +151,7 @@ gme_err_t Music_Player::start_track( int track )
 		
 		if ( track_info_->length <= 0 )
 			track_info_->length = (long) (2.5 * 60 * 1000);
-		gme_set_fade( emu_, track_info_->length, 8000 );
+		gme_set_fade_msecs( emu_, track_info_->length, 8000 );
 		
 		paused = false;
 		sound_start();
@@ -223,7 +223,7 @@ void Music_Player::mute_voices( int mask )
 
 void Music_Player::set_fadeout( bool fade )
 {
-	gme_set_fade( emu_, fade ? track_info_->length : -1, 8000 );
+	gme_set_fade_msecs( emu_, fade ? track_info_->length : -1, 8000 );
 }
 
 void Music_Player::fill_buffer( void* data, sample_t* out, int count )
diff --git a/readme.txt b/readme.txt
index ab599df..eb3b560 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,4 +1,4 @@
-Game_Music_Emu 0.7.0: Game Music Emulators
+Game_Music_Emu 0.6.4: Game Music Emulators
 ------------------------------------------
 Game_Music_Emu is a collection of video game music file emulators that
 support the following formats and systems:

From 1b8166c25a98386dee942467d71c5865980798b3 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <sezeroz@gmail.com>
Date: Wed, 4 Oct 2023 14:24:40 +0300
Subject: [PATCH 03/17] fix gme_autoload_playback_limit so it's actually
 exported in shared libs

---
 gme/gme.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gme/gme.cpp b/gme/gme.cpp
index 57ccdf7..9c22ec8 100644
--- a/gme/gme.cpp
+++ b/gme/gme.cpp
@@ -207,7 +207,7 @@ void gme_set_autoload_playback_limit( Music_Emu *emu, int do_autoload_limit )
 	emu->set_autoload_playback_limit( do_autoload_limit != 0 );
 }
 
-int gme_autoload_playback_limit( Music_Emu *const emu )
+int gme_autoload_playback_limit( Music_Emu const* emu )
 {
 	return emu->autoload_playback_limit();
 }

From 8387fede7aa9c111584fb5bbffc0d66364a7cc47 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <sezeroz@gmail.com>
Date: Wed, 4 Oct 2023 14:50:00 +0300
Subject: [PATCH 04/17] do not export symbols from C sources, i.e.: gme/ext/*.c

---
 CMakeLists.txt | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6e0e288..1644db3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,15 +77,14 @@ if(NOT BUILD_SHARED_LIBS)
 endif()
 
 # Check for GCC/Clang "visibility" support.
-if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
-    OR
-    CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
 
     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wextra")
     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 
     # Assume we have visibility support on any compiler that supports C++11
     add_definitions (-DLIBGME_VISIBILITY)
+    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
 
     # Try to protect against undefined behavior from signed integer overflow

From a53553adef6b9d54d302273f239d52286ef2adc0 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <sezeroz@gmail.com>
Date: Wed, 4 Oct 2023 15:51:56 +0300
Subject: [PATCH 05/17] remove __cplusplus condition from BLARGG_EXPORT
 visibility defininion.

This cannot lead to problems, because:
(1) blargg_source.h is not a public header anymore, and
(2) the definition is additionally guarded by `LIBGME_VISIBILITY`, which
is a private libgme symbol only defined during build of libgme itself.
---
 gme/blargg_source.h | 2 +-
 gme/gme.h           | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gme/blargg_source.h b/gme/blargg_source.h
index deea918..acf9204 100644
--- a/gme/blargg_source.h
+++ b/gme/blargg_source.h
@@ -70,7 +70,7 @@ typedef unsigned char byte;
         #else
             #define BLARGG_EXPORT /* Leave blank: friendly with both static and shared linking */
         #endif
-    #elif defined (LIBGME_VISIBILITY) && defined(__cplusplus)
+    #elif defined (LIBGME_VISIBILITY)
         #define BLARGG_EXPORT __attribute__((visibility ("default")))
     #else
         #define BLARGG_EXPORT
diff --git a/gme/gme.h b/gme/gme.h
index 6920c73..25ffa54 100644
--- a/gme/gme.h
+++ b/gme/gme.h
@@ -23,9 +23,9 @@ typedef struct Music_Emu Music_Emu;
         #if defined(BLARGG_BUILD_DLL)
             #define BLARGG_EXPORT __declspec(dllexport)
         #else
-            #define BLARGG_EXPORT /* Leave blank: friendly with both static and shared linking */
+            #define BLARGG_EXPORT /* Leave blank: friendly with both static and shared linking. */
         #endif
-    #elif defined (LIBGME_VISIBILITY) && defined(__cplusplus)
+    #elif defined (LIBGME_VISIBILITY)
         #define BLARGG_EXPORT __attribute__((visibility ("default")))
     #else
         #define BLARGG_EXPORT

From 635661b6a51eea3bfd7e49c4cbfabbfee61b162a Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <sezeroz@gmail.com>
Date: Wed, 4 Oct 2023 15:56:50 +0300
Subject: [PATCH 06/17] blargg_source.h: remove duplicated BLARGG_EXPORT
 defines

they are only needed in gme.cpp/gme.h, and aren't needed
here anymore.
---
 gme/blargg_source.h | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/gme/blargg_source.h b/gme/blargg_source.h
index acf9204..d03b094 100644
--- a/gme/blargg_source.h
+++ b/gme/blargg_source.h
@@ -62,21 +62,6 @@
 #define byte byte_
 typedef unsigned char byte;
 
-/* Setup compiler defines useful for exporting required public API symbols in gme.cpp */
-#ifndef BLARGG_EXPORT
-    #if defined (_WIN32)
-        #if defined(BLARGG_BUILD_DLL)
-            #define BLARGG_EXPORT __declspec(dllexport)
-        #else
-            #define BLARGG_EXPORT /* Leave blank: friendly with both static and shared linking */
-        #endif
-    #elif defined (LIBGME_VISIBILITY)
-        #define BLARGG_EXPORT __attribute__((visibility ("default")))
-    #else
-        #define BLARGG_EXPORT
-    #endif
-#endif
-
 /* deprecated */
 #define BLARGG_CHECK_ALLOC CHECK_ALLOC
 #define BLARGG_RETURN_ERR RETURN_ERR

From df1ac5053371445be96e0f923f0c40d5dc748d29 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <sezeroz@gmail.com>
Date: Wed, 4 Oct 2023 17:50:40 +0300
Subject: [PATCH 07/17] gme.h: fix wrong 'since' version documentations

---
 gme/gme.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/gme/gme.h b/gme/gme.h
index 6920c73..2256e76 100644
--- a/gme/gme.h
+++ b/gme/gme.h
@@ -72,12 +72,13 @@ BLARGG_EXPORT void gme_set_fade_msecs( Music_Emu*, int start_msec, int length_ms
  *
  * By default, playback limits are loaded and applied.
  *
- * @since 0.6.2
+ * @since 0.6.3
  */
 BLARGG_EXPORT void gme_set_autoload_playback_limit( Music_Emu *, int do_autoload_limit );
 
 /** See gme_set_autoload_playback_limit.
- * @since 0.6.2
+ * (This was actually added in 0.6.3, but wasn't exported because of a typo.)
+ * @since 0.6.4
  */
 BLARGG_EXPORT int gme_autoload_playback_limit( Music_Emu const* );
 
@@ -237,7 +238,7 @@ BLARGG_EXPORT int gme_type_multitrack( gme_type_t );
 
 /* whether the pcm output retrieved by gme_play() will have all 8 voices rendered to their
  * individual stereo channel or (if false) these voices get mixed into one single stereo channel
- * @since 0.6.2 */
+ * @since 0.6.3 */
 BLARGG_EXPORT int gme_multi_channel( Music_Emu const* );
 
 /******** Advanced file loading ********/
@@ -261,7 +262,7 @@ BLARGG_EXPORT gme_type_t gme_identify_extension( const char path_or_extension []
  * Get typical file extension for a given music type.  This is not a replacement
  * for a file content identification library (but see gme_identify_header).
  *
- * @since 0.6.2
+ * @since 0.6.3
  */
 BLARGG_EXPORT const char* gme_type_extension( gme_type_t music_type );
 
@@ -276,7 +277,7 @@ BLARGG_EXPORT Music_Emu* gme_new_emu( gme_type_t, int sample_rate );
 /* Create new multichannel emulator and set sample rate. Returns NULL if out of memory.
  * If you only need track information, pass gme_info_only for sample_rate.
  * (see gme_multi_channel for more information on multichannel support)
- * @since 0.6.2
+ * @since 0.6.3
  */
 BLARGG_EXPORT Music_Emu* gme_new_emu_multi_channel( gme_type_t, int sample_rate );
 

From 3542bc465f326a7cc58d95543bcb666e952267a7 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <sezeroz@gmail.com>
Date: Wed, 4 Oct 2023 17:56:56 +0300
Subject: [PATCH 08/17] gme/ext: remove unnecessary mamedef.h, add missing
 newlines at end.

---
 gme/ext/2413tone.h |  2 +-
 gme/ext/emu2413.c  |  2 --
 gme/ext/mamedef.h  | 62 ----------------------------------------------
 gme/ext/panning.h  |  2 +-
 4 files changed, 2 insertions(+), 66 deletions(-)
 delete mode 100644 gme/ext/mamedef.h

diff --git a/gme/ext/2413tone.h b/gme/ext/2413tone.h
index fb42e3f..c041dc9 100644
--- a/gme/ext/2413tone.h
+++ b/gme/ext/2413tone.h
@@ -17,4 +17,4 @@
 0x21,0x01,0x89,0x03,0xf1,0xe4,0xf0,0x23,
 0x07,0x21,0x14,0x00,0xee,0xf8,0xff,0xf8,
 0x01,0x31,0x00,0x00,0xf8,0xf7,0xf8,0xf7,
-0x25,0x11,0x00,0x00,0xf8,0xfa,0xf8,0x55,
\ No newline at end of file
+0x25,0x11,0x00,0x00,0xf8,0xfa,0xf8,0x55,
diff --git a/gme/ext/emu2413.c b/gme/ext/emu2413.c
index e41753f..701dbde 100644
--- a/gme/ext/emu2413.c
+++ b/gme/ext/emu2413.c
@@ -55,8 +55,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
-#include "mamedef.h"
-#undef INLINE
 #include "emu2413.h"
 #include "panning.h" // Maxim
 
diff --git a/gme/ext/mamedef.h b/gme/ext/mamedef.h
deleted file mode 100644
index bc6cfbf..0000000
--- a/gme/ext/mamedef.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#ifndef __MAMEDEF_H__
-#define __MAMEDEF_H__
-
-// typedefs to use MAME's (U)INTxx types (copied from MAME\src\ods\odscomm.h)
-/* 8-bit values */
-typedef unsigned char						UINT8;
-typedef signed char 						INT8;
-
-/* 16-bit values */
-typedef unsigned short						UINT16;
-typedef signed short						INT16;
-
-/* 32-bit values */
-#ifndef _WINDOWS_H
-typedef unsigned int						UINT32;
-typedef signed int							INT32;
-#endif
-
-/* 64-bit values */
-#ifndef _WINDOWS_H
-#ifdef _MSC_VER
-typedef signed __int64						INT64;
-typedef unsigned __int64					UINT64;
-#else
-__extension__ typedef unsigned long long	UINT64;
-__extension__ typedef signed long long		INT64;
-#endif
-#endif
-
-/* offsets and addresses are 32-bit (for now...) */
-typedef UINT32	offs_t;
-
-/* stream_sample_t is used to represent a single sample in a sound stream */
-typedef INT32 stream_sample_t;
-
-#ifdef VGM_BIG_ENDIAN
-#define BYTE_XOR_BE(x)	 (x)
-#else
-#define BYTE_XOR_BE(x)	((x) ^ 0x01)
-#endif
-
-#if defined(_MSC_VER)
-//#define INLINE	static __forceinline
-#define INLINE	static __inline
-#elif defined(__GNUC__)
-#define INLINE	static __inline__
-#else
-#define INLINE	static inline
-#endif
-#ifndef M_PI
-#define M_PI	3.14159265358979323846
-#endif
-
-#ifdef _DEBUG
-#define logerror	printf
-#else
-#define logerror
-#endif
-
-typedef void (*SRATE_CALLBACK)(void*, UINT32);
-
-#endif	// __MAMEDEF_H__
diff --git a/gme/ext/panning.h b/gme/ext/panning.h
index b6bab25..59a33d3 100644
--- a/gme/ext/panning.h
+++ b/gme/ext/panning.h
@@ -10,4 +10,4 @@
 void calc_panning(float channels[2], int position);
 void centre_panning(float channels[2]);
 
-#endif
\ No newline at end of file
+#endif

From f8b277220069cf605e947a91604bab433f51dbeb Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <sezeroz@gmail.com>
Date: Thu, 5 Oct 2023 00:04:56 +0300
Subject: [PATCH 09/17] blargg_endian.h: fix GET_LE32 inline asm for gcc
 powerpc

---
 gme/blargg_endian.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gme/blargg_endian.h b/gme/blargg_endian.h
index 46e58e2..0f1e7a6 100644
--- a/gme/blargg_endian.h
+++ b/gme/blargg_endian.h
@@ -142,7 +142,7 @@ inline void set_be32( void* p, blargg_ulong n )
 				#define SET_LE32( addr, in )    (__stwbrx( in, addr, 0 ))
 			#elif defined (__GNUC__)
 				#define GET_LE16( addr )        ({unsigned short ppc_lhbrx_; __asm__ volatile( "lhbrx %0,0,%1" : "=r" (ppc_lhbrx_) : "r" (addr) : "memory" ); ppc_lhbrx_;})
-				#define GET_LE32( addr )        ({unsigned short ppc_lwbrx_; __asm__ volatile( "lwbrx %0,0,%1" : "=r" (ppc_lwbrx_) : "r" (addr) : "memory" ); ppc_lwbrx_;})
+				#define GET_LE32( addr )        ({unsigned int ppc_lwbrx_; __asm__ volatile( "lwbrx %0,0,%1" : "=r" (ppc_lwbrx_) : "r" (addr) : "memory" ); ppc_lwbrx_;})
 				#define SET_LE16( addr, in )    ({__asm__ volatile( "sthbrx %0,0,%1" : : "r" (in), "r" (addr) : "memory" );})
 				#define SET_LE32( addr, in )    ({__asm__ volatile( "stwbrx %0,0,%1" : : "r" (in), "r" (addr) : "memory" );})
 			#endif

From 3a3d103cdaafade43d638579db541fef800dea57 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <sezeroz@gmail.com>
Date: Thu, 5 Oct 2023 01:28:04 +0300
Subject: [PATCH 10/17] blargg_endian.h: rewritten byte order detection

---
 gme/blargg_endian.h | 60 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 43 insertions(+), 17 deletions(-)

diff --git a/gme/blargg_endian.h b/gme/blargg_endian.h
index 46e58e2..6fb2c61 100644
--- a/gme/blargg_endian.h
+++ b/gme/blargg_endian.h
@@ -20,35 +20,61 @@
 // BLARGG_BIG_ENDIAN, BLARGG_LITTLE_ENDIAN: Determined automatically, otherwise only
 // one may be #defined to 1. Only needed if something actually depends on byte order.
 #if !defined (BLARGG_BIG_ENDIAN) && !defined (BLARGG_LITTLE_ENDIAN)
-#ifdef __GLIBC__
-	// GCC handles this for us
+#if defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__) && defined(__BYTE_ORDER__)
+	#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+		#define BLARGG_LITTLE_ENDIAN 1
+	#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+		#define BLARGG_BIG_ENDIAN 1
+	#endif
+#elif defined(__linux__)
 	#include <endian.h>
 	#if __BYTE_ORDER == __LITTLE_ENDIAN
 		#define BLARGG_LITTLE_ENDIAN 1
 	#elif __BYTE_ORDER == __BIG_ENDIAN
 		#define BLARGG_BIG_ENDIAN 1
 	#endif
-#else
-
-#if defined (LSB_FIRST) || defined (__LITTLE_ENDIAN__) || BLARGG_CPU_X86 || \
-		(defined (LITTLE_ENDIAN) && LITTLE_ENDIAN+0 != 1234)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || \
+	defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+	#include <machine/endian.h>
+	#if BYTE_ORDER == LITTLE_ENDIAN
+		#define BLARGG_LITTLE_ENDIAN 1
+	#elif BYTE_ORDER == BIG_ENDIAN
+		#define BLARGG_BIG_ENDIAN 1
+	#endif
+#elif defined(BLARGG_CPU_X86) || defined(_WIN32)
 	#define BLARGG_LITTLE_ENDIAN 1
-#endif
-
-#if defined (MSB_FIRST)     || defined (__BIG_ENDIAN__) || defined (WORDS_BIGENDIAN) || \
-	defined (__sparc__)     ||  BLARGG_CPU_POWERPC || \
-	(defined (BIG_ENDIAN) && BIG_ENDIAN+0 != 4321)
+#elif defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
+	defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
 	#define BLARGG_BIG_ENDIAN 1
-#elif !defined (__mips__)
-	// No endian specified; assume little-endian, since it's most common
+#elif defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
+	defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
 	#define BLARGG_LITTLE_ENDIAN 1
-#endif
+#elif defined(__MORPHOS__) || (defined(__amigaos__) && (defined(__NEWLIB__)))
+	#include <machine/endian.h>
+	#if (BYTE_ORDER == LITTLE_ENDIAN)
+		#define BLARGG_LITTLE_ENDIAN 1
+	#elif (BYTE_ORDER == BIG_ENDIAN)
+		#define BLARGG_BIG_ENDIAN 1
+	#endif
+#elif defined(__amigaos__) && defined(__CLIB2__)
+	#include <unistd.h>
+	#if (BYTE_ORDER == LITTLE_ENDIAN)
+		#define BLARGG_LITTLE_ENDIAN 1
+	#elif (BYTE_ORDER == BIG_ENDIAN)
+		#define BLARGG_BIG_ENDIAN 1
+	#endif
+#elif defined(__mc68000__) || defined(__M68K__) || defined(__m68k__) || defined(__MC68K__)
+	#define BLARGG_BIG_ENDIAN 1
+#elif defined(__hppa) || defined(__hppa__)
+	#define BLARGG_BIG_ENDIAN 1
 #endif
 #endif
 
-#if BLARGG_LITTLE_ENDIAN && BLARGG_BIG_ENDIAN
-	#undef BLARGG_LITTLE_ENDIAN
-	#undef BLARGG_BIG_ENDIAN
+#if !defined(BLARGG_BIG_ENDIAN) && !defined(BLARGG_LITTLE_ENDIAN)
+	#error Unspecified endianness.
+#endif
+#if defined(BLARGG_BIG_ENDIAN) && defined(BLARGG_LITTLE_ENDIAN)
+	#error BLARGG_LITTLE_ENDIAN and BLARGG_BIG_ENDIAN are both defined.
 #endif
 
 inline void blargg_verify_byte

(Patch may be truncated, please check the link at the top of this post.)