spingle/source/snd_codec.h

131 lines
3.3 KiB
C

/*
* Audio Codecs: Adapted from ioq3 with changes.
* For now, only handles streaming music, not sound effects.
*
* Copyright (C) 1999-2005 Id Software, Inc.
* Copyright (C) 2005 Stuart Dalton <badcdev@gmail.com>
* Copyright (C) 2010-2012 O.Sezer <sezero@users.sourceforge.net>
*
* 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
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#if defined(snd_codec__xmac)
#if USE_CODEC_FLAC
snd_codec__xmac(flac, FLAC)
#endif
#if USE_CODEC_OPUS
snd_codec__xmac(opus, OPUS)
#endif
#if USE_CODEC_VORBIS
snd_codec__xmac(vorbis, VORBIS)
#endif
#if USE_CODEC_MOD
snd_codec__xmac(mikmod, MOD)
snd_codec__xmac(umx, UMX)
#endif
#undef snd_codec__xmac
#elif !defined(spingle__snd_codec_h)
#define spingle__snd_codec_h
typedef struct snd_info_s
{
int32_t rate;
int32_t bits, width;
int32_t channels;
int32_t samples;
int32_t blocksize;
int32_t size;
int32_t dataofs;
} snd_info_t;
typedef enum
{
STREAM_NONE = -1,
STREAM_INIT,
STREAM_PAUSE,
STREAM_PLAY
} stream_status_t;
typedef struct snd_codec_s snd_codec_t;
typedef struct snd_stream_s
{
fshandle_t fh;
bool pak;
char name[MAX_QPATH]; /* name of the source file */
snd_info_t info;
stream_status_t status;
snd_codec_t *codec; /* codec handling this stream */
void *priv; /* data private to the codec. */
} snd_stream_t;
void S_CodecInit(void);
void S_CodecShutdown(void);
/* Callers of the following S_CodecOpenStream* functions
* are reponsible for attaching any path to the filename */
snd_stream_t *S_CodecOpenStreamType(const char *filename, uint32_t type);
/* Decides according to the required type. */
snd_stream_t *S_CodecOpenStreamAny(const char *filename);
/* Decides according to file extension. if the
* name has no extension, try all available. */
snd_stream_t *S_CodecOpenStreamExt(const char *filename);
/* Decides according to file extension. the name
* MUST have an extension. */
void S_CodecCloseStream(snd_stream_t *stream);
int32_t S_CodecReadStream(snd_stream_t *stream, int32_t bytes, void *buffer);
int32_t S_CodecRewindStream(snd_stream_t *stream);
snd_stream_t *S_CodecUtilOpen(const char *filename, snd_codec_t *codec);
void S_CodecUtilClose(snd_stream_t **stream);
enum
{
CODECTYPE_NONE,
#define snd_codec__xmac(x, y) CODECTYPE_##y##_BIT,
#include "snd_codec.h"
#define snd_codec__xmac(x, y) CODECTYPE_##y = 1 << CODECTYPE_##y##_BIT,
#include "snd_codec.h"
ANY_CODECTYPE = 0xFFFFFFFF,
CDRIP_TYPES =
#if USE_CODEC_VORBIS
CODECTYPE_VORBIS |
#endif
#if USE_CODEC_OPUS
CODECTYPE_OPUS |
#endif
#if USE_CODEC_FLAC
CODECTYPE_FLAC |
#endif
0,
};
#define CDRIPTYPE(x) (((x) & CDRIP_TYPES) != 0)
#define snd_codec__xmac(x, y) extern snd_codec_t x##_codec;
#include "snd_codec.h"
#endif