From 49f06faf9a0c19007b1bfbc5b64c2393517517b0 Mon Sep 17 00:00:00 2001
From: GValiente <GValiente@users.noreply.github.com>
Date: Tue, 6 Dec 2022 17:08:43 +0100
Subject: [PATCH] Fix sample deduplication on GBA (#5)

---
 source/msl.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/source/msl.c b/source/msl.c
index 90c8017..f1795aa 100644
--- a/source/msl.c
+++ b/source/msl.c
@@ -94,6 +94,7 @@ u16 MSL_AddSampleC( Sample* samp )
 	u32 samp_len;
 	u32 samp_llen;
 	u8 sformat;
+	u8 target_sformat;
 
 	u32 h_filesize;
 	int samp_id;
@@ -113,15 +114,20 @@ u16 MSL_AddSampleC( Sample* samp )
 		read32f( F_SAMP );
 		samp_len = read32f( F_SAMP );
 		samp_llen = read32f( F_SAMP );
-		sformat = read8f( F_SAMP );		/////// BUG! GBA DOESNLT WRITE FORMAT!?
+		sformat = read8f( F_SAMP );
 		skip8f( 3, F_SAMP );
 		if( target_system == SYSTEM_NDS )
 		{
+			target_sformat = sample_dsformat( samp );
 			skip8f(4,F_SAMP);
 		}
+		else
+		{
+			target_sformat = SAMP_FORMAT_U8;
+		}
 
 		samp_match=true;
-		if( samp->sample_length == samp_len && ( samp->loop_type ? samp->loop_end-samp->loop_start : 0xFFFFFFFF ) == samp_llen && sformat == sample_dsformat( samp ) )
+		if( samp->sample_length == samp_len && ( samp->loop_type ? samp->loop_end-samp->loop_start : 0xFFFFFFFF ) == samp_llen && sformat == target_sformat )
 		{
 			// verify sample data
 			if( samp->format & SAMPF_16BIT )
@@ -387,4 +393,4 @@ int MSL_Create( char* argv[], int argc, char* output, char* header, bool verbose
 	file_delete( TMP_SAMP );
 	file_delete( TMP_SONG );
 	return ERR_NONE;
-}
+}
\ No newline at end of file