some codec stuff syncing with uhexen2

git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@823 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Ozkan Sezer 2013-02-27 16:50:25 +00:00
parent 47b044893e
commit 8bfd0fe0e8
7 changed files with 56 additions and 44 deletions

View file

@ -3,7 +3,7 @@
* Handles streaming music as raw sound samples and runs the midi driver * Handles streaming music as raw sound samples and runs the midi driver
* *
* Copyright (C) 1999-2005 Id Software, Inc. * Copyright (C) 1999-2005 Id Software, Inc.
* Copyright (C) 2010-2011 O.Sezer <sezero@users.sourceforge.net> * Copyright (C) 2010-2012 O.Sezer <sezero@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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[] = 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_MP3, BGM_STREAMER, -1, "mp3", MUSIC_DIRNAME, NULL },
{ CODECTYPE_FLAC, BGM_STREAMER, -1, "flac", MUSIC_DIRNAME, NULL }, { CODECTYPE_FLAC, BGM_STREAMER, -1, "flac", MUSIC_DIRNAME, NULL },
{ CODECTYPE_WAV, BGM_STREAMER, -1, "wav", 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; static music_handler_t *music_handlers = NULL;
#define ANY_CODECTYPE 0xFFFFFFFF #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) #define CDRIPTYPE(x) (((x) & CDRIP_TYPES) != 0)
static snd_stream_t *bgmstream = NULL; static snd_stream_t *bgmstream = NULL;

View file

@ -3,7 +3,7 @@
* Handles streaming music as raw sound samples and runs the midi driver * Handles streaming music as raw sound samples and runs the midi driver
* *
* Copyright (C) 1999-2005 Id Software, Inc. * Copyright (C) 1999-2005 Id Software, Inc.
* Copyright (C) 2010-2011 O.Sezer <sezero@users.sourceforge.net> * Copyright (C) 2010-2012 O.Sezer <sezero@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -4,7 +4,7 @@
* *
* Copyright (C) 1999-2005 Id Software, Inc. * Copyright (C) 1999-2005 Id Software, Inc.
* Copyright (C) 2005 Stuart Dalton <badcdev@gmail.com> * Copyright (C) 2005 Stuart Dalton <badcdev@gmail.com>
* Copyright (C) 2010-2011 O.Sezer <sezero@users.sourceforge.net> * Copyright (C) 2010-2012 O.Sezer <sezero@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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); S_CodecRegister(&mp3_codec);
#endif #endif
#ifdef USE_CODEC_VORBIS #ifdef USE_CODEC_VORBIS
S_CodecRegister(&ogg_codec); S_CodecRegister(&vorbis_codec);
#endif #endif
codec = codecs; codec = codecs;
while (codec) while (codec)
{ {

View file

@ -4,7 +4,7 @@
* *
* Copyright (C) 1999-2005 Id Software, Inc. * Copyright (C) 1999-2005 Id Software, Inc.
* Copyright (C) 2005 Stuart Dalton <badcdev@gmail.com> * Copyright (C) 2005 Stuart Dalton <badcdev@gmail.com>
* Copyright (C) 2010-2011 O.Sezer <sezero@users.sourceforge.net> * Copyright (C) 2010-2012 O.Sezer <sezero@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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_FLAC (1U << 2)
#define CODECTYPE_WAV (1U << 3) #define CODECTYPE_WAV (1U << 3)
#define CODECTYPE_MP3 (1U << 4) #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_WAVE CODECTYPE_WAV
#define CODECTYPE_MIDI CODECTYPE_MID #define CODECTYPE_MIDI CODECTYPE_MID

View file

@ -4,7 +4,7 @@
* *
* Copyright (C) 1999-2005 Id Software, Inc. * Copyright (C) 1999-2005 Id Software, Inc.
* Copyright (C) 2005 Stuart Dalton <badcdev@gmail.com> * Copyright (C) 2005 Stuart Dalton <badcdev@gmail.com>
* Copyright (C) 2010-2011 O.Sezer <sezero@users.sourceforge.net> * Copyright (C) 2010-2012 O.Sezer <sezero@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -37,10 +37,10 @@
#include <vorbis/vorbisfile.h> #include <vorbis/vorbisfile.h>
#endif #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. */ * formats, we use the standard signed short format. */
#define OGG_SAMPLEWIDTH 2 #define VORBIS_SAMPLEWIDTH 2
#define OGG_SIGNED_DATA 1 #define VORBIS_SIGNED_DATA 1
/* CALLBACK FUNCTIONS: */ /* CALLBACK FUNCTIONS: */
@ -65,23 +65,24 @@ static const ov_callbacks ovc_qfs =
#define OV_OPEN_CALLBACKS ov_open_callbacks #define OV_OPEN_CALLBACKS ov_open_callbacks
static qboolean S_OGG_CodecInitialize (void) static qboolean S_VORBIS_CodecInitialize (void)
{ {
return true; 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; snd_stream_t *stream;
OggVorbis_File *ovFile; OggVorbis_File *ovFile;
vorbis_info *ogg_info; vorbis_info *ovf_info;
long numstreams;
int res; int res;
stream = S_CodecUtilOpen(filename, &ogg_codec); stream = S_CodecUtilOpen(filename, &vorbis_codec);
if (!stream) if (!stream)
return NULL; return NULL;
@ -98,27 +99,36 @@ static snd_stream_t *S_OGG_CodecOpenStream (const char *filename)
if (!ov_seekable(ovFile)) if (!ov_seekable(ovFile))
{ {
Con_Printf("OGG_Open: stream %s not seekable.\n", filename); Con_Printf("Stream %s not seekable.\n", filename);
goto _fail; goto _fail;
} }
ogg_info = ov_info(ovFile, 0); ovf_info = ov_info(ovFile, 0);
if (!ogg_info) 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; 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", Con_Printf("Unsupported number of channels %d in %s\n",
ogg_info->channels, filename); ovf_info->channels, filename);
goto _fail; goto _fail;
} }
stream->info.rate = ogg_info->rate; stream->info.rate = ovf_info->rate;
stream->info.channels = ogg_info->channels; stream->info.channels = ovf_info->channels;
stream->info.width = OGG_SAMPLEWIDTH; stream->info.width = VORBIS_SAMPLEWIDTH;
return stream; return stream;
_fail: _fail:
@ -129,7 +139,7 @@ _fail:
return NULL; 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 section; /* FIXME: handle section changes */
int cnt, res, rem; 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, res = ov_read( (OggVorbis_File *)stream->priv, ptr, rem,
#if !defined(VORBIS_USE_TREMOR) #if !defined(VORBIS_USE_TREMOR)
host_bigendian, host_bigendian,
OGG_SAMPLEWIDTH, VORBIS_SAMPLEWIDTH,
OGG_SIGNED_DATA, VORBIS_SIGNED_DATA,
#endif /* ! VORBIS_USE_TREMOR */ #endif /* ! VORBIS_USE_TREMOR */
&section ); &section );
if (res <= 0) if (res <= 0)
@ -161,17 +171,21 @@ static int S_OGG_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer)
break; break;
ptr += res; 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); ov_clear((OggVorbis_File *)stream->priv);
Z_Free(stream->priv); Z_Free(stream->priv);
S_CodecUtilClose(&stream); 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 /* for libvorbisfile, the ov_time_seek() position argument
* is seconds as doubles, whereas for Tremor libvorbisidec * 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); 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. */ true, /* always available. */
"ogg", "ogg",
S_OGG_CodecInitialize, S_VORBIS_CodecInitialize,
S_OGG_CodecShutdown, S_VORBIS_CodecShutdown,
S_OGG_CodecOpenStream, S_VORBIS_CodecOpenStream,
S_OGG_CodecReadStream, S_VORBIS_CodecReadStream,
S_OGG_CodecRewindStream, S_VORBIS_CodecRewindStream,
S_OGG_CodecCloseStream, S_VORBIS_CodecCloseStream,
NULL NULL
}; };

View file

@ -1,11 +1,11 @@
/* Ogg/Vorbis streaming music support. */ /* Ogg/Vorbis streaming music support. */
#if !defined(_SND_VORBIS_H_) #if !defined(_SND_VORBIS_H_)
#define _SND_VORBIS_H_ #define _SND_VORBIS_H_ 1
#if defined(USE_CODEC_VORBIS) #if defined(USE_CODEC_VORBIS)
extern snd_codec_t ogg_codec; extern snd_codec_t vorbis_codec;
#endif /* USE_CODEC_VORBIS */ #endif /* USE_CODEC_VORBIS */