From f294a9529c50be17fb7abf5a0700709a45791610 Mon Sep 17 00:00:00 2001 From: AShiningRay Date: Thu, 5 Dec 2024 17:21:42 -0300 Subject: [PATCH] AudioClip: Basically ignore incoming media types. This is too unreliable. Sonic 2 Crash is passing mmf streams as mp3 in some of its samsung versions, and now Spyro: The Eternal Night has been found to be passing MIDI files as MMF. So instead of using whatever the jar is passing as type, ignore it entirely for all cases and parse the data's first bytes (often the header, accounting for the possible audioOffset) to find out what kind of data it actually is. --- src/com/samsung/util/AudioClip.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/com/samsung/util/AudioClip.java b/src/com/samsung/util/AudioClip.java index a933d230..a8233abe 100644 --- a/src/com/samsung/util/AudioClip.java +++ b/src/com/samsung/util/AudioClip.java @@ -47,8 +47,10 @@ public AudioClip(int clipType, byte[] audioData, int audioOffset, int audioLengt throw new ArrayIndexOutOfBoundsException("AudioClip: Cannot create player, tried to access audioData at an invalid position"); } - /* Some jars actually try to pass MMF streams with a different type, so check its header to see if this needs to be handled. */ - if(audioData[0] == 'M' && audioData[1] == 'M' && audioData[2] == 'M' && audioData[3] == 'D') { clipType = TYPE_MMF; } + /* Some jars actually try to pass streams with a different clip type from what they should be, so check their header and ignore whatever the jar is passing here. */ + if(audioData[audioOffset+0] == 'M' && audioData[audioOffset+1] == 'M' && audioData[audioOffset+2] == 'M' && audioData[audioOffset+3] == 'D') { clipType = TYPE_MMF; } + else if(audioData[audioOffset+0] == 'M' && audioData[audioOffset+1] == 'T' && audioData[audioOffset+2] == 'h' && audioData[audioOffset+3] == 'd') { clipType = TYPE_MIDI; } + else if(audioData[audioOffset+0] == 'I' && audioData[audioOffset+1] == 'D' && audioData[audioOffset+2] == '3' || ((audioData[audioOffset+0] == (byte) 0xFF) && (audioData[audioOffset+1] & 0xE0) == 0xE0)) { clipType = TYPE_MP3; } Mobile.log(Mobile.LOG_WARNING, AudioClip.class.getPackage().getName() + "." + AudioClip.class.getSimpleName() + ": " + "Samsung AudioClip (ByteArray)");