diff --git a/Quake/bgmusic.c b/Quake/bgmusic.c index e99da2ae..bc28cf96 100644 --- a/Quake/bgmusic.c +++ b/Quake/bgmusic.c @@ -3,7 +3,7 @@ * Handles streaming music as raw sound samples and runs the midi driver * * Copyright (C) 1999-2005 Id Software, Inc. - * Copyright (C) 2010-2011 O.Sezer + * Copyright (C) 2010-2012 O.Sezer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -53,7 +53,7 @@ typedef struct music_handler_s static music_handler_t wanted_handlers[] = { - { CODECTYPE_OGG, BGM_STREAMER, -1, "ogg", MUSIC_DIRNAME, NULL }, + { CODECTYPE_VORBIS,BGM_STREAMER,-1, "ogg", MUSIC_DIRNAME, NULL }, { CODECTYPE_MP3, BGM_STREAMER, -1, "mp3", MUSIC_DIRNAME, NULL }, { CODECTYPE_FLAC, BGM_STREAMER, -1, "flac", MUSIC_DIRNAME, NULL }, { CODECTYPE_WAV, BGM_STREAMER, -1, "wav", MUSIC_DIRNAME, NULL }, @@ -63,7 +63,7 @@ static music_handler_t wanted_handlers[] = static music_handler_t *music_handlers = NULL; #define ANY_CODECTYPE 0xFFFFFFFF -#define CDRIP_TYPES (CODECTYPE_OGG | CODECTYPE_MP3 | CODECTYPE_FLAC | CODECTYPE_WAV) +#define CDRIP_TYPES (CODECTYPE_VORBIS | CODECTYPE_MP3 | CODECTYPE_FLAC | CODECTYPE_WAV) #define CDRIPTYPE(x) (((x) & CDRIP_TYPES) != 0) static snd_stream_t *bgmstream = NULL; diff --git a/Quake/bgmusic.h b/Quake/bgmusic.h index b3f98934..ec308208 100644 --- a/Quake/bgmusic.h +++ b/Quake/bgmusic.h @@ -3,7 +3,7 @@ * Handles streaming music as raw sound samples and runs the midi driver * * Copyright (C) 1999-2005 Id Software, Inc. - * Copyright (C) 2010-2011 O.Sezer + * Copyright (C) 2010-2012 O.Sezer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/Quake/snd_codec.c b/Quake/snd_codec.c index e9f7b8f8..00beca11 100644 --- a/Quake/snd_codec.c +++ b/Quake/snd_codec.c @@ -4,7 +4,7 @@ * * Copyright (C) 1999-2005 Id Software, Inc. * Copyright (C) 2005 Stuart Dalton - * Copyright (C) 2010-2011 O.Sezer + * Copyright (C) 2010-2012 O.Sezer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -65,9 +65,8 @@ void S_CodecInit (void) S_CodecRegister(&mp3_codec); #endif #ifdef USE_CODEC_VORBIS - S_CodecRegister(&ogg_codec); + S_CodecRegister(&vorbis_codec); #endif - codec = codecs; while (codec) { diff --git a/Quake/snd_codec.h b/Quake/snd_codec.h index 0157ef1c..1cab64a1 100644 --- a/Quake/snd_codec.h +++ b/Quake/snd_codec.h @@ -4,7 +4,7 @@ * * Copyright (C) 1999-2005 Id Software, Inc. * Copyright (C) 2005 Stuart Dalton - * Copyright (C) 2010-2011 O.Sezer + * Copyright (C) 2010-2012 O.Sezer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -87,9 +87,8 @@ void S_CodecUtilClose(snd_stream_t **stream); #define CODECTYPE_FLAC (1U << 2) #define CODECTYPE_WAV (1U << 3) #define CODECTYPE_MP3 (1U << 4) -#define CODECTYPE_OGG (1U << 5) +#define CODECTYPE_VORBIS (1U << 5) -#define CODECTYPE_VORBIS CODECTYPE_OGG #define CODECTYPE_WAVE CODECTYPE_WAV #define CODECTYPE_MIDI CODECTYPE_MID diff --git a/Quake/snd_codeci.h b/Quake/snd_codeci.h index 306c49d6..32bf666a 100644 --- a/Quake/snd_codeci.h +++ b/Quake/snd_codeci.h @@ -4,7 +4,7 @@ * * Copyright (C) 1999-2005 Id Software, Inc. * Copyright (C) 2005 Stuart Dalton - * Copyright (C) 2010-2011 O.Sezer + * Copyright (C) 2010-2012 O.Sezer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/Quake/snd_vorbis.c b/Quake/snd_vorbis.c index bbc94bd8..e7017e69 100644 --- a/Quake/snd_vorbis.c +++ b/Quake/snd_vorbis.c @@ -37,10 +37,10 @@ #include #endif -/* The OGG codec can return the samples in a number of different +/* Vorbis codec can return the samples in a number of different * formats, we use the standard signed short format. */ -#define OGG_SAMPLEWIDTH 2 -#define OGG_SIGNED_DATA 1 +#define VORBIS_SAMPLEWIDTH 2 +#define VORBIS_SIGNED_DATA 1 /* CALLBACK FUNCTIONS: */ @@ -65,23 +65,24 @@ static const ov_callbacks ovc_qfs = #define OV_OPEN_CALLBACKS ov_open_callbacks -static qboolean S_OGG_CodecInitialize (void) +static qboolean S_VORBIS_CodecInitialize (void) { return true; } -static void S_OGG_CodecShutdown (void) +static void S_VORBIS_CodecShutdown (void) { } -static snd_stream_t *S_OGG_CodecOpenStream (const char *filename) +static snd_stream_t *S_VORBIS_CodecOpenStream (const char *filename) { snd_stream_t *stream; OggVorbis_File *ovFile; - vorbis_info *ogg_info; + vorbis_info *ovf_info; + long numstreams; int res; - stream = S_CodecUtilOpen(filename, &ogg_codec); + stream = S_CodecUtilOpen(filename, &vorbis_codec); if (!stream) return NULL; @@ -98,27 +99,36 @@ static snd_stream_t *S_OGG_CodecOpenStream (const char *filename) if (!ov_seekable(ovFile)) { - Con_Printf("OGG_Open: stream %s not seekable.\n", filename); + Con_Printf("Stream %s not seekable.\n", filename); goto _fail; } - ogg_info = ov_info(ovFile, 0); - if (!ogg_info) + ovf_info = ov_info(ovFile, 0); + if (!ovf_info) { - Con_Printf("Unable to get stream information for %s.\n", filename); + Con_Printf("Unable to get stream info for %s.\n", filename); goto _fail; } - if (ogg_info->channels != 1 && ogg_info->channels != 2) + /* FIXME: handle section changes */ + numstreams = ov_streams(ovFile); + if (numstreams != 1) + { + Con_Printf("More than one (%ld) stream in %s.\n", + numstreams, filename); + goto _fail; + } + + if (ovf_info->channels != 1 && ovf_info->channels != 2) { Con_Printf("Unsupported number of channels %d in %s\n", - ogg_info->channels, filename); + ovf_info->channels, filename); goto _fail; } - stream->info.rate = ogg_info->rate; - stream->info.channels = ogg_info->channels; - stream->info.width = OGG_SAMPLEWIDTH; + stream->info.rate = ovf_info->rate; + stream->info.channels = ovf_info->channels; + stream->info.width = VORBIS_SAMPLEWIDTH; return stream; _fail: @@ -129,7 +139,7 @@ _fail: return NULL; } -static int S_OGG_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer) +static int S_VORBIS_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer) { int section; /* FIXME: handle section changes */ int cnt, res, rem; @@ -149,8 +159,8 @@ static int S_OGG_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer) res = ov_read( (OggVorbis_File *)stream->priv, ptr, rem, #if !defined(VORBIS_USE_TREMOR) host_bigendian, - OGG_SAMPLEWIDTH, - OGG_SIGNED_DATA, + VORBIS_SAMPLEWIDTH, + VORBIS_SIGNED_DATA, #endif /* ! VORBIS_USE_TREMOR */ §ion ); if (res <= 0) @@ -161,17 +171,21 @@ static int S_OGG_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer) break; ptr += res; } - return (res >= 0) ? cnt : res; + + if (res < 0) + return res; + + return cnt; } -static void S_OGG_CodecCloseStream (snd_stream_t *stream) +static void S_VORBIS_CodecCloseStream (snd_stream_t *stream) { ov_clear((OggVorbis_File *)stream->priv); Z_Free(stream->priv); S_CodecUtilClose(&stream); } -static int S_OGG_CodecRewindStream (snd_stream_t *stream) +static int S_VORBIS_CodecRewindStream (snd_stream_t *stream) { /* for libvorbisfile, the ov_time_seek() position argument * is seconds as doubles, whereas for Tremor libvorbisidec @@ -180,17 +194,17 @@ static int S_OGG_CodecRewindStream (snd_stream_t *stream) return ov_time_seek ((OggVorbis_File *)stream->priv, 0); } -snd_codec_t ogg_codec = +snd_codec_t vorbis_codec = { - CODECTYPE_OGG, + CODECTYPE_VORBIS, true, /* always available. */ "ogg", - S_OGG_CodecInitialize, - S_OGG_CodecShutdown, - S_OGG_CodecOpenStream, - S_OGG_CodecReadStream, - S_OGG_CodecRewindStream, - S_OGG_CodecCloseStream, + S_VORBIS_CodecInitialize, + S_VORBIS_CodecShutdown, + S_VORBIS_CodecOpenStream, + S_VORBIS_CodecReadStream, + S_VORBIS_CodecRewindStream, + S_VORBIS_CodecCloseStream, NULL }; diff --git a/Quake/snd_vorbis.h b/Quake/snd_vorbis.h index 7efe615c..0f1cc9e0 100644 --- a/Quake/snd_vorbis.h +++ b/Quake/snd_vorbis.h @@ -1,11 +1,11 @@ /* Ogg/Vorbis streaming music support. */ #if !defined(_SND_VORBIS_H_) -#define _SND_VORBIS_H_ +#define _SND_VORBIS_H_ 1 #if defined(USE_CODEC_VORBIS) -extern snd_codec_t ogg_codec; +extern snd_codec_t vorbis_codec; #endif /* USE_CODEC_VORBIS */