From 6e1c84770db6f4fc9f000a0a7973c018bf04d26d Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sat, 27 Aug 2011 07:11:02 +0000 Subject: [PATCH] updated snd_vorbis.c from the uhexen2 project: support for Tremor (libvorbisidec) git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@482 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/snd_vorbis.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Quake/snd_vorbis.c b/Quake/snd_vorbis.c index c754eb2c..e445dd45 100644 --- a/Quake/snd_vorbis.c +++ b/Quake/snd_vorbis.c @@ -27,8 +27,15 @@ #include "snd_codec.h" #include "snd_codeci.h" #include "snd_vorbis.h" + #define OV_EXCLUDE_STATIC_CALLBACKS +#if defined(VORBIS_USE_TREMOR) +/* for Tremor / Vorbisfile api differences, + * see doc/diff.html in the Tremor package. */ +#include +#else #include +#endif /* The OGG codec can return the samples in a number of different * formats, we use the standard signed short format. */ @@ -124,8 +131,20 @@ static int S_OGG_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer) ptr = (char *) buffer; while (1) { - res = ov_read((OggVorbis_File *) stream->priv, ptr, rem, host_bigendian, - OGG_SAMPLEWIDTH, OGG_SIGNED_DATA, §ion); + /* # ov_read() from libvorbisfile returns the decoded PCM audio + * in requested endianness, signedness and word size. + * # ov_read() from Tremor (libvorbisidec) returns decoded audio + * always in host-endian, signed 16 bit PCM format. + * # For both of the libraries, if the audio is multichannel, + * the channels are interleaved in the output buffer. + */ + res = ov_read( (OggVorbis_File *)stream->priv, ptr, rem, +#if !defined(VORBIS_USE_TREMOR) + host_bigendian, + OGG_SAMPLEWIDTH, + OGG_SIGNED_DATA, +#endif /* ! VORBIS_USE_TREMOR */ + §ion ); if (res <= 0) break; rem -= res; @@ -146,7 +165,11 @@ static void S_OGG_CodecCloseStream (snd_stream_t *stream) static int S_OGG_CodecRewindStream (snd_stream_t *stream) { - return ov_time_seek ((OggVorbis_File *)stream->priv, 0.0); +/* for libvorbisfile, the ov_time_seek() position argument + * is seconds as doubles, whereas for Tremor libvorbisidec + * it is milliseconds as 64 bit integers. + */ + return ov_time_seek ((OggVorbis_File *)stream->priv, 0); } snd_codec_t ogg_codec =