engine: common: soundlib: reformat everything using uncrustify
This commit is contained in:
parent
eb64ffcec9
commit
2d52dae69c
4 changed files with 156 additions and 134 deletions
|
@ -19,13 +19,13 @@ GNU General Public License for more details.
|
|||
|
||||
size_t OggFilestream_Read( void *ptr, size_t blockSize, size_t nmemb, void *datasource )
|
||||
{
|
||||
ogg_filestream_t *filestream = (ogg_filestream_t*)datasource;
|
||||
ogg_filestream_t *filestream = (ogg_filestream_t *)datasource;
|
||||
size_t remain = filestream->filesize - filestream->position;
|
||||
size_t dataSize = blockSize * nmemb;
|
||||
|
||||
// reads as many blocks as fits in remaining memory
|
||||
if( dataSize > remain )
|
||||
dataSize = remain - remain % blockSize;
|
||||
dataSize = remain - remain % blockSize;
|
||||
|
||||
memcpy( ptr, filestream->buffer + filestream->position, dataSize );
|
||||
filestream->position += dataSize;
|
||||
|
@ -35,7 +35,7 @@ size_t OggFilestream_Read( void *ptr, size_t blockSize, size_t nmemb, void *data
|
|||
int OggFilestream_Seek( void *datasource, int64_t offset, int whence )
|
||||
{
|
||||
int64_t position;
|
||||
ogg_filestream_t *filestream = (ogg_filestream_t*)datasource;
|
||||
ogg_filestream_t *filestream = (ogg_filestream_t *)datasource;
|
||||
|
||||
if( whence == SEEK_SET )
|
||||
position = offset;
|
||||
|
@ -55,6 +55,6 @@ int OggFilestream_Seek( void *datasource, int64_t offset, int whence )
|
|||
|
||||
long OggFilestream_Tell( void *datasource )
|
||||
{
|
||||
ogg_filestream_t *filestream = (ogg_filestream_t*)datasource;
|
||||
ogg_filestream_t *filestream = (ogg_filestream_t *)datasource;
|
||||
return filestream->position;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ typedef struct ogg_filestream_s
|
|||
{
|
||||
const char *name;
|
||||
const byte *buffer;
|
||||
size_t filesize;
|
||||
size_t position;
|
||||
size_t filesize;
|
||||
size_t position;
|
||||
} ogg_filestream_t;
|
||||
|
||||
size_t OggFilestream_Read( void *ptr, size_t blockSize, size_t nmemb, void *datasource );
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
|
||||
typedef struct opus_streaming_ctx_s
|
||||
{
|
||||
file_t *file;
|
||||
file_t *file;
|
||||
OggOpusFile *of;
|
||||
} opus_streaming_ctx_t;
|
||||
|
||||
|
@ -37,19 +37,19 @@ static opus_int64 OpusCallback_Tell( void *datasource )
|
|||
|
||||
static int FS_ReadOggOpus( void *datasource, byte *ptr, int nbytes )
|
||||
{
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t*)datasource;
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t *)datasource;
|
||||
return g_fsapi.Read( ctx->file, ptr, nbytes );
|
||||
}
|
||||
|
||||
static int FS_SeekOggOpus( void *datasource, int64_t offset, int whence )
|
||||
{
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t*)datasource;
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t *)datasource;
|
||||
return g_fsapi.Seek( ctx->file, offset, whence );
|
||||
}
|
||||
|
||||
static opus_int64 FS_TellOggOpus( void *datasource )
|
||||
{
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t*)datasource;
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t *)datasource;
|
||||
return g_fsapi.Tell( ctx->file );
|
||||
}
|
||||
|
||||
|
@ -76,55 +76,57 @@ static const OpusFileCallbacks op_callbacks_fs = {
|
|||
*/
|
||||
static void Sound_ScanOpusComments( const OggOpusFile *of )
|
||||
{
|
||||
const char *value;
|
||||
const char *value;
|
||||
const OpusTags *tags = op_tags( of, -1 );
|
||||
if( tags )
|
||||
{
|
||||
if(( value = opus_tags_query( tags, "LOOPSTART", 0 ))) {
|
||||
{
|
||||
if(( value = opus_tags_query( tags, "LOOPSTART", 0 )))
|
||||
{
|
||||
sound.loopstart = Q_atoi( value );
|
||||
SetBits( sound.flags, SOUND_LOOPED );
|
||||
}
|
||||
else if(( value = opus_tags_query( tags, "LOOP_START", 0 ))) {
|
||||
else if(( value = opus_tags_query( tags, "LOOP_START", 0 )))
|
||||
{
|
||||
sound.loopstart = Q_atoi( value );
|
||||
SetBits( sound.flags, SOUND_LOOPED );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char* Opus_GetErrorDesc( int errorCode )
|
||||
static const char *Opus_GetErrorDesc( int errorCode )
|
||||
{
|
||||
switch (errorCode)
|
||||
switch( errorCode )
|
||||
{
|
||||
case OP_FALSE:
|
||||
return "request failed";
|
||||
case OP_EOF:
|
||||
return "end of file reached";
|
||||
case OP_HOLE:
|
||||
return "there was a hole in the stream";
|
||||
case OP_EREAD:
|
||||
return "read error occurred";
|
||||
case OP_EFAULT:
|
||||
return "fault issue occurred";
|
||||
case OP_EIMPL:
|
||||
return "feature not implemented";
|
||||
case OP_EINVAL:
|
||||
return "invalid argument";
|
||||
case OP_ENOTFORMAT:
|
||||
return "not a valid file format";
|
||||
case OP_EBADHEADER:
|
||||
return "bad header";
|
||||
case OP_EVERSION:
|
||||
return "version mismatch";
|
||||
case OP_EBADPACKET:
|
||||
return "bad packet";
|
||||
case OP_EBADLINK:
|
||||
return "bad link found";
|
||||
case OP_ENOSEEK:
|
||||
return "bitstream not seekable";
|
||||
case OP_EBADTIMESTAMP:
|
||||
return "invalid timestamp";
|
||||
default:
|
||||
return "unknown error";
|
||||
case OP_FALSE:
|
||||
return "request failed";
|
||||
case OP_EOF:
|
||||
return "end of file reached";
|
||||
case OP_HOLE:
|
||||
return "there was a hole in the stream";
|
||||
case OP_EREAD:
|
||||
return "read error occurred";
|
||||
case OP_EFAULT:
|
||||
return "fault issue occurred";
|
||||
case OP_EIMPL:
|
||||
return "feature not implemented";
|
||||
case OP_EINVAL:
|
||||
return "invalid argument";
|
||||
case OP_ENOTFORMAT:
|
||||
return "not a valid file format";
|
||||
case OP_EBADHEADER:
|
||||
return "bad header";
|
||||
case OP_EVERSION:
|
||||
return "version mismatch";
|
||||
case OP_EBADPACKET:
|
||||
return "bad packet";
|
||||
case OP_EBADLINK:
|
||||
return "bad link found";
|
||||
case OP_ENOSEEK:
|
||||
return "bitstream not seekable";
|
||||
case OP_EBADTIMESTAMP:
|
||||
return "invalid timestamp";
|
||||
default:
|
||||
return "unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,8 +134,8 @@ qboolean Sound_LoadOggOpus( const char *name, const byte *buffer, fs_offset_t fi
|
|||
{
|
||||
int ret;
|
||||
ogg_filestream_t file;
|
||||
OggOpusFile *of;
|
||||
const OpusHead *opusHead;
|
||||
OggOpusFile *of;
|
||||
const OpusHead *opusHead;
|
||||
size_t written = 0;
|
||||
|
||||
if( !buffer )
|
||||
|
@ -141,19 +143,21 @@ qboolean Sound_LoadOggOpus( const char *name, const byte *buffer, fs_offset_t fi
|
|||
|
||||
OggFilestream_Init( &file, name, buffer, filesize );
|
||||
of = op_open_callbacks( &file, &op_callbacks_membuf, NULL, 0, &ret );
|
||||
if( !of ) {
|
||||
if( !of )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: failed to load (%s): %s\n", __func__, file.name, Opus_GetErrorDesc( ret ));
|
||||
return false;
|
||||
}
|
||||
|
||||
opusHead = op_head( of, -1 );
|
||||
if( opusHead->channel_count < 1 || opusHead->channel_count > 2 ) {
|
||||
if( opusHead->channel_count < 1 || opusHead->channel_count > 2 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: failed to load (%s): unsuppored channels count\n", __func__, file.name );
|
||||
return false;
|
||||
}
|
||||
|
||||
// according to OggOpus specification, sound always encoded at 48kHz sample rate
|
||||
// but this isn't a problem, engine can do resampling
|
||||
// but this isn't a problem, engine can do resampling
|
||||
sound.channels = opusHead->channel_count;
|
||||
sound.rate = 48000;
|
||||
sound.width = 2; // always 16-bit PCM
|
||||
|
@ -161,9 +165,10 @@ qboolean Sound_LoadOggOpus( const char *name, const byte *buffer, fs_offset_t fi
|
|||
sound.samples = op_pcm_total( of, -1 );
|
||||
sound.size = sound.samples * sound.width * sound.channels;
|
||||
sound.wav = (byte *)Mem_Calloc( host.soundpool, sound.size );
|
||||
|
||||
|
||||
// skip undesired samples before playing sound
|
||||
if(( ret = op_pcm_seek( of, opusHead->pre_skip )) < 0 ) {
|
||||
if(( ret = op_pcm_seek( of, opusHead->pre_skip )) < 0 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: failed to pre-skip (%s): %s\n", __func__, file.name, Opus_GetErrorDesc( ret ));
|
||||
return false;
|
||||
}
|
||||
|
@ -171,9 +176,10 @@ qboolean Sound_LoadOggOpus( const char *name, const byte *buffer, fs_offset_t fi
|
|||
SetBits( sound.flags, SOUND_RESAMPLE );
|
||||
Sound_ScanOpusComments( of );
|
||||
|
||||
while(( ret = op_read( of, (opus_int16*)(sound.wav + written), (sound.size - written) / sound.width, NULL )) != 0 )
|
||||
while(( ret = op_read( of, (opus_int16 *)( sound.wav + written ), ( sound.size - written ) / sound.width, NULL )) != 0 )
|
||||
{
|
||||
if( ret < 0 ) {
|
||||
if( ret < 0 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: failed to read (%s): %s\n", __func__, file.name, Opus_GetErrorDesc( ret ));
|
||||
return false;
|
||||
}
|
||||
|
@ -189,16 +195,17 @@ stream_t *Stream_OpenOggOpus( const char *filename )
|
|||
int ret;
|
||||
stream_t *stream;
|
||||
opus_streaming_ctx_t *ctx;
|
||||
const OpusHead *opusHead;
|
||||
const OpusHead *opusHead;
|
||||
|
||||
ctx = (opus_streaming_ctx_t*)Mem_Calloc( host.soundpool, sizeof( opus_streaming_ctx_t ));
|
||||
ctx = (opus_streaming_ctx_t *)Mem_Calloc( host.soundpool, sizeof( opus_streaming_ctx_t ));
|
||||
ctx->file = FS_Open( filename, "rb", false );
|
||||
if( !ctx->file ) {
|
||||
if( !ctx->file )
|
||||
{
|
||||
Mem_Free( ctx );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stream = (stream_t*)Mem_Calloc( host.soundpool, sizeof( stream_t ));
|
||||
stream = (stream_t *)Mem_Calloc( host.soundpool, sizeof( stream_t ));
|
||||
stream->file = ctx->file;
|
||||
stream->pos = 0;
|
||||
|
||||
|
@ -213,7 +220,8 @@ stream_t *Stream_OpenOggOpus( const char *filename )
|
|||
}
|
||||
|
||||
opusHead = op_head( ctx->of, -1 );
|
||||
if( opusHead->channel_count < 1 || opusHead->channel_count > 2 ) {
|
||||
if( opusHead->channel_count < 1 || opusHead->channel_count > 2 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: failed to load (%s): unsuppored channels count\n", __func__, filename );
|
||||
op_free( ctx->of );
|
||||
FS_Close( ctx->file );
|
||||
|
@ -223,7 +231,8 @@ stream_t *Stream_OpenOggOpus( const char *filename )
|
|||
}
|
||||
|
||||
// skip undesired samples before playing sound
|
||||
if(( ret = op_pcm_seek( ctx->of, opusHead->pre_skip )) < 0 ) {
|
||||
if(( ret = op_pcm_seek( ctx->of, opusHead->pre_skip )) < 0 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: failed to pre-skip (%s): %s\n", __func__, filename, Opus_GetErrorDesc( ret ));
|
||||
op_free( ctx->of );
|
||||
FS_Close( ctx->file );
|
||||
|
@ -235,7 +244,7 @@ stream_t *Stream_OpenOggOpus( const char *filename )
|
|||
stream->buffsize = 0; // how many samples left from previous frame
|
||||
stream->channels = opusHead->channel_count;
|
||||
stream->rate = 48000; // that's fixed at 48kHz for Opus format
|
||||
stream->width = 2; // always 16 bit
|
||||
stream->width = 2; // always 16 bit
|
||||
stream->ptr = ctx;
|
||||
stream->type = WF_OPUSDATA;
|
||||
|
||||
|
@ -245,17 +254,17 @@ stream_t *Stream_OpenOggOpus( const char *filename )
|
|||
int Stream_ReadOggOpus( stream_t *stream, int needBytes, void *buffer )
|
||||
{
|
||||
int bytesWritten = 0;
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t*)stream->ptr;
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t *)stream->ptr;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
byte *data;
|
||||
int outsize;
|
||||
int outsize;
|
||||
|
||||
if( !stream->buffsize )
|
||||
{
|
||||
ret = op_read( ctx->of, (opus_int16*)stream->temp, OUTBUF_SIZE / stream->width, NULL );
|
||||
ret = op_read( ctx->of, (opus_int16 *)stream->temp, OUTBUF_SIZE / stream->width, NULL );
|
||||
if( ret == 0 )
|
||||
break; // end of file
|
||||
else if( ret < 0 )
|
||||
|
@ -267,7 +276,8 @@ int Stream_ReadOggOpus( stream_t *stream, int needBytes, void *buffer )
|
|||
// check remaining size
|
||||
if( bytesWritten + stream->pos > needBytes )
|
||||
outsize = ( needBytes - bytesWritten );
|
||||
else outsize = stream->pos;
|
||||
else
|
||||
outsize = stream->pos;
|
||||
|
||||
// copy raw sample to output buffer
|
||||
data = (byte *)buffer + bytesWritten;
|
||||
|
@ -289,8 +299,9 @@ int Stream_ReadOggOpus( stream_t *stream, int needBytes, void *buffer )
|
|||
int Stream_SetPosOggOpus( stream_t *stream, int newpos )
|
||||
{
|
||||
int ret;
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t*)stream->ptr;
|
||||
if(( ret = op_raw_seek( ctx->of, newpos )) == 0 ) {
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t *)stream->ptr;
|
||||
if(( ret = op_raw_seek( ctx->of, newpos )) == 0 )
|
||||
{
|
||||
stream->buffsize = 0; // flush any previous data
|
||||
return true;
|
||||
}
|
||||
|
@ -300,7 +311,7 @@ int Stream_SetPosOggOpus( stream_t *stream, int newpos )
|
|||
|
||||
int Stream_GetPosOggOpus( stream_t *stream )
|
||||
{
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t*)stream->ptr;
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t *)stream->ptr;
|
||||
return op_raw_tell( ctx->of );
|
||||
}
|
||||
|
||||
|
@ -308,7 +319,7 @@ void Stream_FreeOggOpus( stream_t *stream )
|
|||
{
|
||||
if( stream->ptr )
|
||||
{
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t*)stream->ptr;
|
||||
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t *)stream->ptr;
|
||||
op_free( ctx->of );
|
||||
Mem_Free( stream->ptr );
|
||||
stream->ptr = NULL;
|
||||
|
|
|
@ -29,19 +29,19 @@ typedef struct vorbis_streaming_ctx_s
|
|||
|
||||
static size_t FS_ReadOggVorbis( void *ptr, size_t blockSize, size_t nmemb, void *datasource )
|
||||
{
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t*)datasource;
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t *)datasource;
|
||||
return g_fsapi.Read( ctx->file, ptr, blockSize * nmemb );
|
||||
}
|
||||
|
||||
static int FS_SeekOggVorbis( void *datasource, int64_t offset, int whence )
|
||||
{
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t*)datasource;
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t *)datasource;
|
||||
return g_fsapi.Seek( ctx->file, offset, whence );
|
||||
}
|
||||
|
||||
static long FS_TellOggVorbis( void *datasource )
|
||||
{
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t*)datasource;
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t *)datasource;
|
||||
return g_fsapi.Tell( ctx->file );
|
||||
}
|
||||
|
||||
|
@ -66,52 +66,54 @@ static const ov_callbacks ov_callbacks_fs = {
|
|||
|
||||
=================================================================
|
||||
*/
|
||||
static const char* Vorbis_GetErrorDesc( int errorCode )
|
||||
static const char *Vorbis_GetErrorDesc( int errorCode )
|
||||
{
|
||||
switch( errorCode )
|
||||
{
|
||||
case OV_EOF:
|
||||
return "end of file";
|
||||
case OV_HOLE:
|
||||
return "compressed data sync lost";
|
||||
case OV_EBADHEADER:
|
||||
return "invalid header";
|
||||
case OV_EINVAL:
|
||||
return "invalid argument";
|
||||
case OV_ENOTVORBIS:
|
||||
return "not a Vorbis data";
|
||||
case OV_EBADLINK:
|
||||
return "link corrupted";
|
||||
case OV_EFAULT:
|
||||
return "internal error";
|
||||
case OV_EIMPL:
|
||||
return "not implemented";
|
||||
case OV_EBADPACKET:
|
||||
return "invalid packet";
|
||||
case OV_EVERSION:
|
||||
return "version mismatch";
|
||||
case OV_ENOSEEK:
|
||||
return "bitstream not seekable";
|
||||
case OV_ENOTAUDIO:
|
||||
return "not an audio data";
|
||||
case OV_EREAD:
|
||||
return "read error";
|
||||
default:
|
||||
return "unknown error";
|
||||
case OV_EOF:
|
||||
return "end of file";
|
||||
case OV_HOLE:
|
||||
return "compressed data sync lost";
|
||||
case OV_EBADHEADER:
|
||||
return "invalid header";
|
||||
case OV_EINVAL:
|
||||
return "invalid argument";
|
||||
case OV_ENOTVORBIS:
|
||||
return "not a Vorbis data";
|
||||
case OV_EBADLINK:
|
||||
return "link corrupted";
|
||||
case OV_EFAULT:
|
||||
return "internal error";
|
||||
case OV_EIMPL:
|
||||
return "not implemented";
|
||||
case OV_EBADPACKET:
|
||||
return "invalid packet";
|
||||
case OV_EVERSION:
|
||||
return "version mismatch";
|
||||
case OV_ENOSEEK:
|
||||
return "bitstream not seekable";
|
||||
case OV_ENOTAUDIO:
|
||||
return "not an audio data";
|
||||
case OV_EREAD:
|
||||
return "read error";
|
||||
default:
|
||||
return "unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
static void Sound_ScanVorbisComments( OggVorbis_File *vf )
|
||||
{
|
||||
const char *value;
|
||||
const char *value;
|
||||
vorbis_comment *vc = ov_comment( vf, -1 );
|
||||
if( vc )
|
||||
{
|
||||
if(( value = vorbis_comment_query( vc, "LOOPSTART", 0 ))) {
|
||||
{
|
||||
if(( value = vorbis_comment_query( vc, "LOOPSTART", 0 )))
|
||||
{
|
||||
sound.loopstart = Q_atoi( value );
|
||||
SetBits( sound.flags, SOUND_LOOPED );
|
||||
}
|
||||
else if(( value = vorbis_comment_query( vc, "LOOP_START", 0 ))) {
|
||||
else if(( value = vorbis_comment_query( vc, "LOOP_START", 0 )))
|
||||
{
|
||||
sound.loopstart = Q_atoi( value );
|
||||
SetBits( sound.flags, SOUND_LOOPED );
|
||||
}
|
||||
|
@ -120,24 +122,26 @@ static void Sound_ScanVorbisComments( OggVorbis_File *vf )
|
|||
|
||||
qboolean Sound_LoadOggVorbis( const char *name, const byte *buffer, fs_offset_t filesize )
|
||||
{
|
||||
long ret;
|
||||
int section;
|
||||
long ret;
|
||||
int section;
|
||||
size_t written = 0;
|
||||
vorbis_info *info;
|
||||
vorbis_info *info;
|
||||
ogg_filestream_t file;
|
||||
OggVorbis_File vorbisFile;
|
||||
|
||||
OggVorbis_File vorbisFile;
|
||||
|
||||
if( !buffer )
|
||||
return false;
|
||||
|
||||
OggFilestream_Init( &file, name, buffer, filesize );
|
||||
if(( ret = ov_open_callbacks( &file, &vorbisFile, NULL, 0, ov_callbacks_membuf )) < 0 ) {
|
||||
if(( ret = ov_open_callbacks( &file, &vorbisFile, NULL, 0, ov_callbacks_membuf )) < 0 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: failed to load (%s): %s\n", __func__, file.name, Vorbis_GetErrorDesc( ret ));
|
||||
return false;
|
||||
}
|
||||
|
||||
info = ov_info( &vorbisFile, -1 );
|
||||
if( info->channels < 1 || info->channels > 2 ) {
|
||||
if( info->channels < 1 || info->channels > 2 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: failed to load (%s): unsuppored channels count\n", __func__, file.name );
|
||||
return false;
|
||||
}
|
||||
|
@ -153,9 +157,10 @@ qboolean Sound_LoadOggVorbis( const char *name, const byte *buffer, fs_offset_t
|
|||
SetBits( sound.flags, SOUND_RESAMPLE );
|
||||
Sound_ScanVorbisComments( &vorbisFile );
|
||||
|
||||
while(( ret = ov_read( &vorbisFile, (char*)sound.wav + written, sound.size - written, 0, sound.width, 1, §ion )) != 0 )
|
||||
while(( ret = ov_read( &vorbisFile, (char *)sound.wav + written, sound.size - written, 0, sound.width, 1, §ion )) != 0 )
|
||||
{
|
||||
if( ret < 0 ) {
|
||||
if( ret < 0 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: failed to load (%s): %s\n", __func__, file.name, Vorbis_GetErrorDesc( ret ));
|
||||
return false;
|
||||
}
|
||||
|
@ -169,18 +174,19 @@ qboolean Sound_LoadOggVorbis( const char *name, const byte *buffer, fs_offset_t
|
|||
stream_t *Stream_OpenOggVorbis( const char *filename )
|
||||
{
|
||||
int ret;
|
||||
stream_t *stream;
|
||||
stream_t *stream;
|
||||
vorbis_info *info;
|
||||
vorbis_streaming_ctx_t *ctx;
|
||||
|
||||
ctx = (vorbis_streaming_ctx_t*)Mem_Calloc( host.soundpool, sizeof( vorbis_streaming_ctx_t ));
|
||||
ctx = (vorbis_streaming_ctx_t *)Mem_Calloc( host.soundpool, sizeof( vorbis_streaming_ctx_t ));
|
||||
ctx->file = FS_Open( filename, "rb", false );
|
||||
if (!ctx->file) {
|
||||
if( !ctx->file )
|
||||
{
|
||||
Mem_Free( ctx );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stream = (stream_t*)Mem_Calloc( host.soundpool, sizeof( stream_t ));
|
||||
stream = (stream_t *)Mem_Calloc( host.soundpool, sizeof( stream_t ));
|
||||
stream->file = ctx->file;
|
||||
stream->pos = 0;
|
||||
|
||||
|
@ -194,7 +200,8 @@ stream_t *Stream_OpenOggVorbis( const char *filename )
|
|||
}
|
||||
|
||||
info = ov_info( &ctx->vf, -1 );
|
||||
if( info->channels < 1 || info->channels > 2 ) {
|
||||
if( info->channels < 1 || info->channels > 2 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: failed to load (%s): unsuppored channels count\n", __func__, filename );
|
||||
FS_Close( ctx->file );
|
||||
Mem_Free( stream );
|
||||
|
@ -205,7 +212,7 @@ stream_t *Stream_OpenOggVorbis( const char *filename )
|
|||
stream->buffsize = 0; // how many samples left from previous frame
|
||||
stream->channels = info->channels;
|
||||
stream->rate = info->rate;
|
||||
stream->width = 2; // always 16 bit
|
||||
stream->width = 2; // always 16 bit
|
||||
stream->ptr = ctx;
|
||||
stream->type = WF_VORBISDATA;
|
||||
|
||||
|
@ -215,21 +222,23 @@ stream_t *Stream_OpenOggVorbis( const char *filename )
|
|||
int Stream_ReadOggVorbis( stream_t *stream, int needBytes, void *buffer )
|
||||
{
|
||||
int section;
|
||||
int bytesWritten = 0;
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t*)stream->ptr;
|
||||
|
||||
int bytesWritten = 0;
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t *)stream->ptr;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
byte *data;
|
||||
int outsize;
|
||||
int outsize;
|
||||
|
||||
if( !stream->buffsize )
|
||||
{
|
||||
stream->pos = ov_read( &ctx->vf, (char*)stream->temp, OUTBUF_SIZE, 0, stream->width, 1, §ion );
|
||||
if( stream->pos == 0 ) {
|
||||
stream->pos = ov_read( &ctx->vf, (char *)stream->temp, OUTBUF_SIZE, 0, stream->width, 1, §ion );
|
||||
if( stream->pos == 0 )
|
||||
{
|
||||
break; // end of file
|
||||
}
|
||||
else if( stream->pos < 0 ) {
|
||||
else if( stream->pos < 0 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: error during read: %s\n", __func__, Vorbis_GetErrorDesc( stream->pos ));
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +246,8 @@ int Stream_ReadOggVorbis( stream_t *stream, int needBytes, void *buffer )
|
|||
// check remaining size
|
||||
if( bytesWritten + stream->pos > needBytes )
|
||||
outsize = ( needBytes - bytesWritten );
|
||||
else outsize = stream->pos;
|
||||
else
|
||||
outsize = stream->pos;
|
||||
|
||||
// copy raw sample to output buffer
|
||||
data = (byte *)buffer + bytesWritten;
|
||||
|
@ -259,8 +269,9 @@ int Stream_ReadOggVorbis( stream_t *stream, int needBytes, void *buffer )
|
|||
int Stream_SetPosOggVorbis( stream_t *stream, int newpos )
|
||||
{
|
||||
int ret;
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t*)stream->ptr;
|
||||
if(( ret = ov_raw_seek_lap( &ctx->vf, newpos )) == 0 ) {
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t *)stream->ptr;
|
||||
if(( ret = ov_raw_seek_lap( &ctx->vf, newpos )) == 0 )
|
||||
{
|
||||
stream->buffsize = 0; // flush any previous data
|
||||
return true;
|
||||
}
|
||||
|
@ -270,7 +281,7 @@ int Stream_SetPosOggVorbis( stream_t *stream, int newpos )
|
|||
|
||||
int Stream_GetPosOggVorbis( stream_t *stream )
|
||||
{
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t*)stream->ptr;
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t *)stream->ptr;
|
||||
return ov_raw_tell( &ctx->vf );
|
||||
}
|
||||
|
||||
|
@ -278,7 +289,7 @@ void Stream_FreeOggVorbis( stream_t *stream )
|
|||
{
|
||||
if( stream->ptr )
|
||||
{
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t*)stream->ptr;
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t *)stream->ptr;
|
||||
ov_clear( &ctx->vf );
|
||||
Mem_Free( stream->ptr );
|
||||
stream->ptr = NULL;
|
||||
|
|
Loading…
Add table
Reference in a new issue