Skip to content

Commit

Permalink
AudioClip: Basically ignore incoming media types.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AShiningRay committed Dec 5, 2024
1 parent 9aef335 commit f294a95
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/com/samsung/util/AudioClip.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)");

Expand Down

0 comments on commit f294a95

Please sign in to comment.