From cedc1e0eb287cecee295fc0db653db33ceb97c72 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 13 Jul 2019 23:25:55 +0300 Subject: [PATCH] engine: soundlib: show mpg123 errors in console --- engine/common/soundlib/libmpg/libmpg.h | 2 +- engine/common/soundlib/snd_mp3.c | 23 ++++++----------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/engine/common/soundlib/libmpg/libmpg.h b/engine/common/soundlib/libmpg/libmpg.h index 7f65a07d..34f6e23b 100644 --- a/engine/common/soundlib/libmpg/libmpg.h +++ b/engine/common/soundlib/libmpg/libmpg.h @@ -40,7 +40,7 @@ typedef long (*pfseek)( void *handle, long offset, int whence ); extern void *create_decoder( int *error ); extern int feed_mpeg_header( void *mpg, const byte *data, long bufsize, long streamsize, wavinfo_t *sc ); -extern int feed_mpeg_stream( void *mpg, const char *data, long bufsize, char *outbuf, size_t *outsize ); +extern int feed_mpeg_stream( void *mpg, const byte *data, long bufsize, byte *outbuf, size_t *outsize ); extern int open_mpeg_stream( void *mpg, void *file, pfread f_read, pfseek f_seek, wavinfo_t *sc ); extern int read_mpeg_stream(void *mpg, byte *outbuf, size_t *outsize ); extern int get_stream_pos( void *mpg ); diff --git a/engine/common/soundlib/snd_mp3.c b/engine/common/soundlib/snd_mp3.c index bf48ca25..e8f44661 100644 --- a/engine/common/soundlib/snd_mp3.c +++ b/engine/common/soundlib/snd_mp3.c @@ -14,7 +14,7 @@ GNU General Public License for more details. */ #include "soundlib.h" -#include "libmpg.h" +#include "libmpg/libmpg.h" /* ================================================================= @@ -41,18 +41,12 @@ qboolean Sound_LoadMPG( const char *name, const byte *buffer, fs_offset_t filesi if(( mpeg = create_decoder( &ret )) == NULL ) return false; -#ifdef _DEBUG if( ret ) Con_DPrintf( S_ERROR "%s\n", get_error( mpeg )); -#endif // trying to read header if( !feed_mpeg_header( mpeg, buffer, FRAME_SIZE, filesize, &sc )) { -#ifdef _DEBUG Con_DPrintf( S_ERROR "Sound_LoadMPG: failed to load (%s): %s\n", name, get_error( mpeg )); -#else - Con_DPrintf( S_ERROR "Sound_LoadMPG: (%s) is probably corrupted\n", name ); -#endif close_decoder( mpeg ); return false; } @@ -84,7 +78,7 @@ qboolean Sound_LoadMPG( const char *name, const byte *buffer, fs_offset_t filesi if( feed_mpeg_stream( mpeg, NULL, 0, out, &outsize ) != MP3_OK && outsize <= 0 ) { - char *data = (char *)buffer + pos; + const byte *data = buffer + pos; int bufsize; // if there are no bytes remainig so we can decompress the new frame @@ -135,23 +129,18 @@ stream_t *Stream_OpenMPG( const char *filename ) // couldn't create decoder if(( mpeg = create_decoder( &ret )) == NULL ) { - Con_DPrintf( S_ERROR "Stream_OpenMPG: couldn't create decoder\n" ); + Con_DPrintf( S_ERROR "Stream_OpenMPG: couldn't create decoder: %s\n", get_error( mpeg ) ); Mem_Free( stream ); FS_Close( file ); return NULL; } -#ifdef _DEBUG if( ret ) Con_DPrintf( S_ERROR "%s\n", get_error( mpeg )); -#endif + // trying to open stream and read header - if( !open_mpeg_stream( mpeg, file, FS_Read, FS_Seek, &sc )) + if( !open_mpeg_stream( mpeg, file, (void*)FS_Read, (void*)FS_Seek, &sc )) { -#ifdef _DEBUG Con_DPrintf( S_ERROR "Stream_OpenMPG: failed to load (%s): %s\n", filename, get_error( mpeg )); -#else - Con_DPrintf( S_ERROR "Stream_OpenMPG: (%s) is probably corrupted\n", filename ); -#endif close_decoder( mpeg ); Mem_Free( stream ); FS_Close( file ); @@ -191,7 +180,7 @@ int Stream_ReadMPG( stream_t *stream, int needBytes, void *buffer ) if( !stream->buffsize ) { - if( read_mpeg_stream( mpg, stream->temp, &stream->pos ) != MP3_OK ) + if( read_mpeg_stream( mpg, (byte*)stream->temp, &stream->pos ) != MP3_OK ) break; // there was end of the stream }