31#ifdef LINK_TO_LIBVORBIS
32#define OV_EXCLUDE_STATIC_CALLBACKS
34#include <vorbis/vorbisfile.h>
36#define qov_clear ov_clear
37#define qov_info ov_info
38#define qov_comment ov_comment
39#define qov_open_callbacks ov_open_callbacks
40#define qov_pcm_seek ov_pcm_seek
41#define qov_pcm_total ov_pcm_total
42#define qov_read ov_read
43#define qvorbis_comment_query vorbis_comment_query
64 size_t (*read_func) (
void *ptr,
size_t size,
size_t nmemb,
void *datasource);
65 int (*seek_func) (
void *datasource, int64_t
offset,
int whence);
66 int (*close_func) (
void *datasource);
67 long (*tell_func) (
void *datasource);
95 unsigned char *body_data;
100 int64_t *granule_vals;
104 long lacing_returned;
105 unsigned char header[282];
175 char **user_comments;
176 int *comment_lengths;
222 char *initial,
long ibytes,
227 int bigendianp,
int word,
int sgned,
int *bitstream);
269 const char* dllnames_vo [] =
283 const char* dllnames_vf [] =
286 "libvorbisfile-3.dll",
290 "libvorbisfile.dylib",
292 "libvorbisfile.so.3",
342static size_t ovcb_read (
void *ptr,
size_t size,
size_t nb,
void *datasource)
350 len = remain - remain %
size;
352 memcpy (ptr, ov_decode->
buffer + ov_decode->
ind, len);
353 ov_decode->
ind += len;
422 int f = sfx->format.width * sfx->format.channels;
425 int newlength, done,
ret;
450 while (numsampleframes *
f > (
int)
sizeof(per_ch->
buffer))
452 done =
sizeof(per_ch->
buffer) /
f;
454 firstsampleframe += done;
455 numsampleframes -= done;
456 outsamplesfloat += done * sfx->format.channels;
483 memmove(per_ch->
buffer, per_ch->
buffer +
offset * sfx->format.width * sfx->format.channels, keeplength * sfx->format.width * sfx->format.channels);
492 if (done < newlength)
493 memset(per_ch->
buffer + done, 0, newlength - done);
500 len = numsampleframes * sfx->format.channels;
501 for (
i = 0;
i < len;
i++)
502 outsamplesfloat[
i] =
buf[
i] * (1.0f / 32768.0f);
542 const char *startcomment =
NULL, *lengthcomment =
NULL, *endcomment =
NULL, *thiscomment =
NULL;
554 *peak = atof(thiscomment);
557 *gaindb = atof(thiscomment);
583 *start = (
unsigned int)
bound(0, atof(startcomment), numsamples);
586 else if(lengthcomment)
587 *
length = (
unsigned int)
bound(0, *start + atof(lengthcomment), numsamples);
608#ifndef LINK_TO_LIBVORBIS
614 if (sfx->fetcher !=
NULL)
623 Con_Printf(
"Loading Ogg Vorbis file \"%s\"\n", filename);
631 Con_Printf(
"error while opening Ogg Vorbis file \"%s\"\n", filename);
640 Con_Printf(
"%s has an unsupported number of channels (%i)\n",
647 sfx->format.speed = vi->
rate;
648 sfx->format.channels = vi->
channels;
649 sfx->format.width = 2;
658 Con_Printf(
"Ogg sound file \"%s\" will be streamed\n", filename);
660 sfx->memsize +=
sizeof (*per_sfx);
663 sfx->memsize += filesize;
664 sfx->fetcher_data = per_sfx;
668 OGG_DecodeTags(vc, &sfx->loopstart, &sfx->total_length, sfx->total_length, &peak, &gaindb);
680 Con_Printf (
"Ogg sound file \"%s\" will be cached\n", filename);
681 len = sfx->total_length * sfx->format.channels * sfx->format.width;
682 sfx->flags &= ~SFXFLAG_STREAMED;
686 buff = (
char *)sfx->fetcher_data;
692 OGG_DecodeTags(vc, &sfx->loopstart, &sfx->total_length, sfx->total_length, &peak, &gaindb);
699 sfx->volume_mult =
min(1.0f / peak, exp(gaindb * 0.05f *
log(10.0f)));
700 sfx->volume_peak = peak;
702 Con_Printf (
"Ogg sound file \"%s\" uses ReplayGain (gain %f, peak %f)\n", filename, sfx->volume_mult, sfx->volume_peak);
706 sfx->volume_mult =
min(1.0f / peak, exp(gaindb * 0.05f *
log(10.0f)));
707 sfx->volume_peak = 1.0;
709 Con_Printf (
"Ogg sound file \"%s\" uses ReplayGain (gain %f, peak not defined and assumed to be %f)\n", filename, sfx->volume_mult, sfx->volume_peak);
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
unsigned char * FS_LoadFile(const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
static int(ZEXPORT *qz_inflate)(z_stream *strm
static int const char * version
GLenum GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLsizeiptr const GLvoid * data
GLuint GLuint GLintptr offset
GLenum GLuint GLenum GLsizei const GLchar * buf
#define bound(min, num, max)
channel_t channels[MAX_CHANNELS]
cvar_t snd_streaming_length
#define STREAM_BUFFERSIZE
in sampleframes
#define SFXFLAG_STREAMED
informative only. You shouldn't need to know that
static void OGG_StopChannel(channel_t *ch)
qbool OGG_OpenLibrary(void)
static const ov_callbacks callbacks
static long(* qov_read)(OggVorbis_File *vf, char *buffer, int length, int bigendianp, int word, int sgned, int *bitstream)
static const snd_fetcher_t ogg_fetcher
static vorbis_info *(* qov_info)(OggVorbis_File *vf, int link)
static int ovcb_seek(void *datasource, int64_t offset, int whence)
static dllhandle_t vf_dll
static int ovcb_close(void *ov_decode)
static dllfunction_t vorbisfuncs[]
static long ovcb_tell(void *ov_decode)
static char *(* qvorbis_comment_query)(vorbis_comment *vc, const char *tag, int count)
static int(* qov_clear)(OggVorbis_File *vf)
static int(* qov_open_callbacks)(void *datasource, OggVorbis_File *vf, char *initial, long ibytes, ov_callbacks callbacks)
static size_t ovcb_read(void *ptr, size_t size, size_t nb, void *datasource)
static dllhandle_t vo_dll
void OGG_CloseLibrary(void)
static void OGG_FreeSfx(sfx_t *sfx)
static dllfunction_t vorbisfilefuncs[]
static void OGG_GetSamplesFloat(channel_t *ch, sfx_t *sfx, int firstsampleframe, int numsampleframes, float *outsamplesfloat)
static void OGG_DecodeTags(vorbis_comment *vc, unsigned int *start, unsigned int *length, unsigned int numsamples, double *peak, double *gaindb)
qbool OGG_LoadVorbisFile(const char *filename, sfx_t *sfx)
static int(* qov_pcm_seek)(OggVorbis_File *vf, int64_t pos)
static int64_t(* qov_pcm_total)(OggVorbis_File *vf, int i)
static vorbis_comment *(* qov_comment)(OggVorbis_File *vf, int link)
const snd_fetcher_t wav_fetcher
void * fetcher_data
Per-channel data for the sound fetching function.
unsigned char buffer[STREAM_BUFFERSIZE *4]
qbool Sys_LoadDependency(const char **dllnames, dllhandle_t *handle, const dllfunction_t *fcts)
void Sys_FreeLibrary(dllhandle_t *handle)
int Sys_CheckParm(const char *parm)
#define Mem_Alloc(pool, size)