[sdlsound] [patch] ogg: handle S32/F32 gracefully

Jonas Kulla nyocurio at gmail.com
Sun Dec 1 09:43:20 EST 2013


Hello,

with the release of SDL2, a couple new sound sample format definitions have
been added to SDL_audio.h that the ogg decoder in SDL_sound is not prepared
to handle (because it only expects 8 and 16 bit formats). Attached is a
patch to
fall back to signed 16 bit in case of formats that ov_read from
libvorbisfile can't
handle.

diff -r 36048b57f6f4 decoders/ogg.c
--- a/decoders/ogg.c Sun Dec 01 14:00:35 2013 +0100
+++ b/decoders/ogg.c Sun Dec 01 15:33:34 2013 +0100
@@ -230,8 +230,13 @@
      *  necessary, and SDL_sound will not. If the user didn't specify a
      *  desired format, then we pretend the "actual" format is something
that
      *  OGG files are apparently commonly encoded in.
+     * Exceptions: if the desired sample size is over 2 bytes (either float
+     *  or int32), we default to S16 because ov_read can't handle it.
      */
-    sample->actual.format = (sample->desired.format == 0) ?
+
+    int vf_can_convert = ((sample->desired.format & 0xFF) / 8) <= 2;
+
+    sample->actual.format = (sample->desired.format == 0 ||
!vf_can_convert) ?
                              AUDIO_S16SYS : sample->desired.format;
     return(1);
 } /* OGG_open */
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://icculus.org/pipermail/sdlsound/attachments/20131201/65baa157/attachment.html>


More information about the sdlsound mailing list