engine: common: soundlib: reformat everything using uncrustify

This commit is contained in:
Alibek Omarov 2024-12-02 18:58:50 +03:00
parent eb64ffcec9
commit 2d52dae69c
4 changed files with 156 additions and 134 deletions

View file

@ -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 ) 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 remain = filestream->filesize - filestream->position;
size_t dataSize = blockSize * nmemb; 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 ) int OggFilestream_Seek( void *datasource, int64_t offset, int whence )
{ {
int64_t position; int64_t position;
ogg_filestream_t *filestream = (ogg_filestream_t*)datasource; ogg_filestream_t *filestream = (ogg_filestream_t *)datasource;
if( whence == SEEK_SET ) if( whence == SEEK_SET )
position = offset; position = offset;
@ -55,6 +55,6 @@ int OggFilestream_Seek( void *datasource, int64_t offset, int whence )
long OggFilestream_Tell( void *datasource ) long OggFilestream_Tell( void *datasource )
{ {
ogg_filestream_t *filestream = (ogg_filestream_t*)datasource; ogg_filestream_t *filestream = (ogg_filestream_t *)datasource;
return filestream->position; return filestream->position;
} }

View file

@ -37,19 +37,19 @@ static opus_int64 OpusCallback_Tell( void *datasource )
static int FS_ReadOggOpus( void *datasource, byte *ptr, int nbytes ) 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 ); return g_fsapi.Read( ctx->file, ptr, nbytes );
} }
static int FS_SeekOggOpus( void *datasource, int64_t offset, int whence ) 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 ); return g_fsapi.Seek( ctx->file, offset, whence );
} }
static opus_int64 FS_TellOggOpus( void *datasource ) 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 ); return g_fsapi.Tell( ctx->file );
} }
@ -80,20 +80,22 @@ static void Sound_ScanOpusComments( const OggOpusFile *of )
const OpusTags *tags = op_tags( of, -1 ); const OpusTags *tags = op_tags( of, -1 );
if( tags ) if( tags )
{ {
if(( value = opus_tags_query( tags, "LOOPSTART", 0 ))) { if(( value = opus_tags_query( tags, "LOOPSTART", 0 )))
{
sound.loopstart = Q_atoi( value ); sound.loopstart = Q_atoi( value );
SetBits( sound.flags, SOUND_LOOPED ); 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 ); sound.loopstart = Q_atoi( value );
SetBits( sound.flags, SOUND_LOOPED ); 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: case OP_FALSE:
return "request failed"; 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 ); OggFilestream_Init( &file, name, buffer, filesize );
of = op_open_callbacks( &file, &op_callbacks_membuf, NULL, 0, &ret ); 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 )); Con_DPrintf( S_ERROR "%s: failed to load (%s): %s\n", __func__, file.name, Opus_GetErrorDesc( ret ));
return false; return false;
} }
opusHead = op_head( of, -1 ); 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 ); Con_DPrintf( S_ERROR "%s: failed to load (%s): unsuppored channels count\n", __func__, file.name );
return false; 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 ); sound.wav = (byte *)Mem_Calloc( host.soundpool, sound.size );
// skip undesired samples before playing sound // 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 )); Con_DPrintf( S_ERROR "%s: failed to pre-skip (%s): %s\n", __func__, file.name, Opus_GetErrorDesc( ret ));
return false; return false;
} }
@ -171,9 +176,10 @@ qboolean Sound_LoadOggOpus( const char *name, const byte *buffer, fs_offset_t fi
SetBits( sound.flags, SOUND_RESAMPLE ); SetBits( sound.flags, SOUND_RESAMPLE );
Sound_ScanOpusComments( of ); 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 )); Con_DPrintf( S_ERROR "%s: failed to read (%s): %s\n", __func__, file.name, Opus_GetErrorDesc( ret ));
return false; return false;
} }
@ -191,14 +197,15 @@ stream_t *Stream_OpenOggOpus( const char *filename )
opus_streaming_ctx_t *ctx; 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 ); ctx->file = FS_Open( filename, "rb", false );
if( !ctx->file ) { if( !ctx->file )
{
Mem_Free( ctx ); Mem_Free( ctx );
return NULL; 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->file = ctx->file;
stream->pos = 0; stream->pos = 0;
@ -213,7 +220,8 @@ stream_t *Stream_OpenOggOpus( const char *filename )
} }
opusHead = op_head( ctx->of, -1 ); 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 ); Con_DPrintf( S_ERROR "%s: failed to load (%s): unsuppored channels count\n", __func__, filename );
op_free( ctx->of ); op_free( ctx->of );
FS_Close( ctx->file ); FS_Close( ctx->file );
@ -223,7 +231,8 @@ stream_t *Stream_OpenOggOpus( const char *filename )
} }
// skip undesired samples before playing sound // 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 )); Con_DPrintf( S_ERROR "%s: failed to pre-skip (%s): %s\n", __func__, filename, Opus_GetErrorDesc( ret ));
op_free( ctx->of ); op_free( ctx->of );
FS_Close( ctx->file ); 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 Stream_ReadOggOpus( stream_t *stream, int needBytes, void *buffer )
{ {
int bytesWritten = 0; 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 ) while( 1 )
{ {
@ -255,7 +264,7 @@ int Stream_ReadOggOpus( stream_t *stream, int needBytes, void *buffer )
if( !stream->buffsize ) 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 ) if( ret == 0 )
break; // end of file break; // end of file
else if( ret < 0 ) else if( ret < 0 )
@ -267,7 +276,8 @@ int Stream_ReadOggOpus( stream_t *stream, int needBytes, void *buffer )
// check remaining size // check remaining size
if( bytesWritten + stream->pos > needBytes ) if( bytesWritten + stream->pos > needBytes )
outsize = ( needBytes - bytesWritten ); outsize = ( needBytes - bytesWritten );
else outsize = stream->pos; else
outsize = stream->pos;
// copy raw sample to output buffer // copy raw sample to output buffer
data = (byte *)buffer + bytesWritten; 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 Stream_SetPosOggOpus( stream_t *stream, int newpos )
{ {
int ret; int ret;
opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t*)stream->ptr; opus_streaming_ctx_t *ctx = (opus_streaming_ctx_t *)stream->ptr;
if(( ret = op_raw_seek( ctx->of, newpos )) == 0 ) { if(( ret = op_raw_seek( ctx->of, newpos )) == 0 )
{
stream->buffsize = 0; // flush any previous data stream->buffsize = 0; // flush any previous data
return true; return true;
} }
@ -300,7 +311,7 @@ int Stream_SetPosOggOpus( stream_t *stream, int newpos )
int Stream_GetPosOggOpus( stream_t *stream ) 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 ); return op_raw_tell( ctx->of );
} }
@ -308,7 +319,7 @@ void Stream_FreeOggOpus( stream_t *stream )
{ {
if( stream->ptr ) 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 ); op_free( ctx->of );
Mem_Free( stream->ptr ); Mem_Free( stream->ptr );
stream->ptr = NULL; stream->ptr = NULL;

View file

@ -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 ) 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 ); return g_fsapi.Read( ctx->file, ptr, blockSize * nmemb );
} }
static int FS_SeekOggVorbis( void *datasource, int64_t offset, int whence ) 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 ); return g_fsapi.Seek( ctx->file, offset, whence );
} }
static long FS_TellOggVorbis( void *datasource ) 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 ); 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 ) switch( errorCode )
{ {
@ -107,11 +107,13 @@ static void Sound_ScanVorbisComments( OggVorbis_File *vf )
vorbis_comment *vc = ov_comment( vf, -1 ); vorbis_comment *vc = ov_comment( vf, -1 );
if( vc ) if( vc )
{ {
if(( value = vorbis_comment_query( vc, "LOOPSTART", 0 ))) { if(( value = vorbis_comment_query( vc, "LOOPSTART", 0 )))
{
sound.loopstart = Q_atoi( value ); sound.loopstart = Q_atoi( value );
SetBits( sound.flags, SOUND_LOOPED ); 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 ); sound.loopstart = Q_atoi( value );
SetBits( sound.flags, SOUND_LOOPED ); SetBits( sound.flags, SOUND_LOOPED );
} }
@ -131,13 +133,15 @@ qboolean Sound_LoadOggVorbis( const char *name, const byte *buffer, fs_offset_t
return false; return false;
OggFilestream_Init( &file, name, buffer, filesize ); 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 )); Con_DPrintf( S_ERROR "%s: failed to load (%s): %s\n", __func__, file.name, Vorbis_GetErrorDesc( ret ));
return false; return false;
} }
info = ov_info( &vorbisFile, -1 ); 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 ); Con_DPrintf( S_ERROR "%s: failed to load (%s): unsuppored channels count\n", __func__, file.name );
return false; return false;
} }
@ -153,9 +157,10 @@ qboolean Sound_LoadOggVorbis( const char *name, const byte *buffer, fs_offset_t
SetBits( sound.flags, SOUND_RESAMPLE ); SetBits( sound.flags, SOUND_RESAMPLE );
Sound_ScanVorbisComments( &vorbisFile ); Sound_ScanVorbisComments( &vorbisFile );
while(( ret = ov_read( &vorbisFile, (char*)sound.wav + written, sound.size - written, 0, sound.width, 1, &section )) != 0 ) while(( ret = ov_read( &vorbisFile, (char *)sound.wav + written, sound.size - written, 0, sound.width, 1, &section )) != 0 )
{
if( ret < 0 )
{ {
if( ret < 0 ) {
Con_DPrintf( S_ERROR "%s: failed to load (%s): %s\n", __func__, file.name, Vorbis_GetErrorDesc( ret )); Con_DPrintf( S_ERROR "%s: failed to load (%s): %s\n", __func__, file.name, Vorbis_GetErrorDesc( ret ));
return false; return false;
} }
@ -173,14 +178,15 @@ stream_t *Stream_OpenOggVorbis( const char *filename )
vorbis_info *info; vorbis_info *info;
vorbis_streaming_ctx_t *ctx; 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 ); ctx->file = FS_Open( filename, "rb", false );
if (!ctx->file) { if( !ctx->file )
{
Mem_Free( ctx ); Mem_Free( ctx );
return NULL; 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->file = ctx->file;
stream->pos = 0; stream->pos = 0;
@ -194,7 +200,8 @@ stream_t *Stream_OpenOggVorbis( const char *filename )
} }
info = ov_info( &ctx->vf, -1 ); 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 ); Con_DPrintf( S_ERROR "%s: failed to load (%s): unsuppored channels count\n", __func__, filename );
FS_Close( ctx->file ); FS_Close( ctx->file );
Mem_Free( stream ); Mem_Free( stream );
@ -216,7 +223,7 @@ int Stream_ReadOggVorbis( stream_t *stream, int needBytes, void *buffer )
{ {
int section; int section;
int bytesWritten = 0; 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 ) while( 1 )
{ {
@ -225,11 +232,13 @@ int Stream_ReadOggVorbis( stream_t *stream, int needBytes, void *buffer )
if( !stream->buffsize ) if( !stream->buffsize )
{ {
stream->pos = ov_read( &ctx->vf, (char*)stream->temp, OUTBUF_SIZE, 0, stream->width, 1, &section ); stream->pos = ov_read( &ctx->vf, (char *)stream->temp, OUTBUF_SIZE, 0, stream->width, 1, &section );
if( stream->pos == 0 ) { if( stream->pos == 0 )
{
break; // end of file 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 )); 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 // check remaining size
if( bytesWritten + stream->pos > needBytes ) if( bytesWritten + stream->pos > needBytes )
outsize = ( needBytes - bytesWritten ); outsize = ( needBytes - bytesWritten );
else outsize = stream->pos; else
outsize = stream->pos;
// copy raw sample to output buffer // copy raw sample to output buffer
data = (byte *)buffer + bytesWritten; 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 Stream_SetPosOggVorbis( stream_t *stream, int newpos )
{ {
int ret; int ret;
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t*)stream->ptr; vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t *)stream->ptr;
if(( ret = ov_raw_seek_lap( &ctx->vf, newpos )) == 0 ) { if(( ret = ov_raw_seek_lap( &ctx->vf, newpos )) == 0 )
{
stream->buffsize = 0; // flush any previous data stream->buffsize = 0; // flush any previous data
return true; return true;
} }
@ -270,7 +281,7 @@ int Stream_SetPosOggVorbis( stream_t *stream, int newpos )
int Stream_GetPosOggVorbis( stream_t *stream ) 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 ); return ov_raw_tell( &ctx->vf );
} }
@ -278,7 +289,7 @@ void Stream_FreeOggVorbis( stream_t *stream )
{ {
if( stream->ptr ) 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 ); ov_clear( &ctx->vf );
Mem_Free( stream->ptr ); Mem_Free( stream->ptr );
stream->ptr = NULL; stream->ptr = NULL;