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,7 +19,7 @@ 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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -80,20 +80,22 @@ static void Sound_ScanOpusComments( const OggOpusFile *of )
|
|||
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";
|
||||
|
@ -141,13 +143,15 @@ 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;
|
||||
}
|
||||
|
@ -163,7 +167,8 @@ qboolean Sound_LoadOggOpus( const char *name, const byte *buffer, fs_offset_t fi
|
|||
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;
|
||||
}
|
||||
|
@ -191,14 +197,15 @@ stream_t *Stream_OpenOggOpus( const char *filename )
|
|||
opus_streaming_ctx_t *ctx;
|
||||
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 );
|
||||
|
@ -245,7 +254,7 @@ 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 )
|
||||
{
|
||||
|
@ -255,7 +264,7 @@ int Stream_ReadOggOpus( stream_t *stream, int needBytes, void *buffer )
|
|||
|
||||
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,7 +66,7 @@ static const ov_callbacks ov_callbacks_fs = {
|
|||
|
||||
=================================================================
|
||||
*/
|
||||
static const char* Vorbis_GetErrorDesc( int errorCode )
|
||||
static const char *Vorbis_GetErrorDesc( int errorCode )
|
||||
{
|
||||
switch( errorCode )
|
||||
{
|
||||
|
@ -107,11 +107,13 @@ static void Sound_ScanVorbisComments( OggVorbis_File *vf )
|
|||
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 );
|
||||
}
|
||||
|
@ -131,13 +133,15 @@ qboolean Sound_LoadOggVorbis( const char *name, const byte *buffer, fs_offset_t
|
|||
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;
|
||||
}
|
||||
|
@ -173,14 +178,15 @@ stream_t *Stream_OpenOggVorbis( const char *filename )
|
|||
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 );
|
||||
|
@ -216,7 +223,7 @@ 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;
|
||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t *)stream->ptr;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
|
@ -225,11 +232,13 @@ int Stream_ReadOggVorbis( stream_t *stream, int needBytes, void *buffer )
|
|||
|
||||
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