16-bit sound output is garbled
When I try to play back 16-bit sound with the default mac sound output set to 16-bit mode it's garbled; since it works with the mac sound output set to an 8-bit mode in the Sound control panel I'm guessing this is an endianness issue.
Testing note: If you have yourself a 16-bit .wav file, you can install system 7.5 and quicktime 2.5 and play it in MoviePlayer (and you can bring it in through extfs and get the right Type since it's on the big hardcoded list in extfs_unix.cpp)
Ok, so...
https://github.com/pelya/BasiliskII-android/blob/06a7bb327cea0de0265b98d16807ab679a2e6433/src/SDL/audio_sdl.cpp#L92
The point of the original line
audio_spec.format = (audio_sample_sizes[audio_sample_size_index] == 8) ? AUDIO_U8 : AUDIO_S16MSB;
is to set SDL to the same format that we know the Mac audio is going to be in. If you specify a different format you have to somehow convert the audio to that format.
So there are two problems really:
-
The 16-bit format just has the problem that it's the wrong endianness; we can use sdl-1.2's conversion capabilities to convert the data.
-
The 8-bit format I think you are only just specifying incorrectly -- you have your sdl-1.2 set up to say it wants
AUDIO_S8format but it's going to deliver the bytes as-is to Android and what Android 8-bit audio actually wants is data in the format used withAUDIO_U8. So when you deliver at most a single stream at a time of data suitable forAUDIO_U8and incorrectly call itAUDIO_S8everywhere in the existing code it mostly works, because it mostly just passes the bytes through, with a lot of extra clicking at the stops and starts because of the wrong silence value.
Note that there's an unrelated sound format bug there I fixed at the same time: sometimes the individual SoundComponentData records that the mac outputs have a different number of channels than the output is configured for (e.g. when the output is set to 8-bit stereo and there's only a mono 8-bit alert sound playing -- where we have configured SDL for stereo, we need to be able to convert mono audio data from the SCD to stereo data for output for this case.)