From f429aa5775cb36b794e720c114aa4f771638587c Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Tue, 10 Jan 2023 09:30:44 +0100 Subject: [PATCH 1/5] Fall back to default position if none given for ISM inputs --- apps/renderer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/renderer.c b/apps/renderer.c index 6084b9f46a..c7607c7ea4 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -1619,14 +1619,21 @@ void IsmPositionProvider_getNextFrame( for ( objIdx = 0; objIdx < positionProvider->numObjects; ++objIdx ) { + /* If ISM metadata reader is open, read from metadata file */ if ( positionProvider->ismReaders[objIdx] != NULL ) { getMetadataFromFileReader( positionProvider->ismReaders[objIdx], objectMetadataBuffer, objIdx ); } - else + /* Otherwise, if positions were provided in a scene description file, use them */ + else if ( positionProvider->positions[objIdx] != NULL ) { readFromShorthandMetadata( positionProvider, objectMetadataBuffer, objIdx ); } + /* Otherwise fall back to default position */ + else { + objectMetadataBuffer->positions[objIdx].azimuth = 0.0f; + objectMetadataBuffer->positions[objIdx].elevation = 0.0f; + } /* Wrap azimuth to lie within (-180, 180] range */ while ( objectMetadataBuffer->positions[objIdx].azimuth < 0.0f ) -- GitLab From 2df7539307dedbcffb8f2a85045d71acbb1f385e Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Tue, 17 Jan 2023 10:53:30 +0100 Subject: [PATCH 2/5] Fix confusing error message when ism format is incorrectly specified on command line. --- apps/renderer.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index c7607c7ea4..3fd7748ada 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -1041,6 +1041,20 @@ static IVAS_REND_AudioConfig ambisonicsOrderToEnum( return IVAS_REND_AUDIO_CONFIG_UNKNOWN; } +static const CmdLnParser_Option *findOptionById( + const int32_t id ) +{ + for ( int32_t i = 0; i < numCliOptions; ++i ) + { + if ( cliOptions[i].id == id ) + { + return &cliOptions[i]; + } + } + + return NULL; +} + static bool parseInConfig( const char *inFormatStr, InputConfig *inConfig, @@ -1129,7 +1143,8 @@ static bool parseInConfig( if ( error == IVAS_ERR_FAILED_FILE_OPEN ) { /* Failed to open with given string - most likely wasn't a file path */ - fprintf( stderr, "Unsupported input format: %s\n", inFormatStr ); + const CmdLnParser_Option *listOption = findOptionById( CmdLnOptionId_listFormats ); + fprintf( stderr, "Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match ); return false; } if ( error != IVAS_ERR_OK ) @@ -1144,10 +1159,13 @@ static bool parseInConfig( } break; default: + { /* Default case covers formats that are defined in the IVAS_REND_AudioConfig enum, * but cannot be used at input, e.g. BINAURAL */ - fprintf( stderr, "Unsupported input format: %s\n", inFormatStr ); + const CmdLnParser_Option *listOption = findOptionById( CmdLnOptionId_listFormats ); + fprintf( stderr, "Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match ); return false; + } } return true; @@ -1285,7 +1303,16 @@ static IVAS_REND_AudioConfig parseAudioConfig( } if ( strncmp( charBuf, "ISM", 3 ) == 0 ) { - return IVAS_REND_AUDIO_CONFIG_OBJECT; + /* Accept input config as ISM only if the 4th character is a number from 1 to 4. + * Otherwise, do nothing. Unknown audio config will be returned. */ + switch ( charBuf[3] ) + { + case '1': + case '2': + case '3': + case '4': + return IVAS_REND_AUDIO_CONFIG_OBJECT; + } } if ( strncmp( charBuf, "MASA", 4 ) == 0 ) { @@ -1313,20 +1340,6 @@ static IVAS_REND_AudioConfig parseAudioConfig( return IVAS_REND_AUDIO_CONFIG_UNKNOWN; } -static const CmdLnParser_Option *findOptionById( - const int32_t id ) -{ - for ( int32_t i = 0; i < numCliOptions; ++i ) - { - if ( cliOptions[i].id == id ) - { - return &cliOptions[i]; - } - } - - return NULL; -} - static bool checkRequiredArgs( CmdlnArgs args ) { -- GitLab From ba0be6996c50dcd4881dcfd9a201f8776e792b1c Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Tue, 17 Jan 2023 11:15:57 +0100 Subject: [PATCH 3/5] Fix warnings on MacOS + AppleClang --- apps/renderer.c | 2 +- lib_rend/lib_rend.c | 2 +- lib_util/ism_file_writer.c | 4 ++-- lib_util/masa_file_writer.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index 3fd7748ada..e38f523680 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -2034,7 +2034,7 @@ static void parseMasa( if ( strncmp( line, "MASA", 4 ) != 0 ) { char numTcs = *line; - sprintf( line, "MASA%c", numTcs ); + snprintf( line, 6 /* write at most 6 characters: MASAx + null termination */, "MASA%c", numTcs ); } inConfig->masaBuses[idx].audioConfig = parseAudioConfig( line ); diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 028b0f6274..3303556258 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2563,7 +2563,7 @@ static IVAS_REND_InputId makeInputId( /* Put config type in second byte (from LSB), put index + 1 in first byte * * Index is incremented here so that a valid ID can never be 0. */ - return (IVAS_REND_InputId) ( ( getAudioConfigType( config ) << 8 ) | ( inputIndex + 1 ) ); + return (IVAS_REND_InputId) ( ( ( (uint32_t) getAudioConfigType( config ) ) << 8 ) | ( inputIndex + 1 ) ); } static ivas_error getInputById( diff --git a/lib_util/ism_file_writer.c b/lib_util/ism_file_writer.c index ac90e7b1eb..63e5ce5c46 100644 --- a/lib_util/ism_file_writer.c +++ b/lib_util/ism_file_writer.c @@ -64,7 +64,7 @@ ivas_error IsmFileWriter_open( FILE *file; strncpy( metadata_filename_loc, filePathWav, sizeof( metadata_filename_loc ) - 1 ); - sprintf( ext_meta, ".%d.csv", obj_num ); + snprintf( ext_meta, sizeof( ext_meta ), ".%d.csv", obj_num ); const int32_t maxNumCharactersToAppend = (int32_t) sizeof( metadata_filename_loc ) - strlen( metadata_filename_loc ) - 1; strncat( metadata_filename_loc, ext_meta, maxNumCharactersToAppend ); @@ -116,7 +116,7 @@ ivas_error IsmFileWriter_writeFrame( file = ismWriter->file; /* IVAS_fmToDo: work in progress; currently position_azimuth, position_elevation, position_radius, spread, gain_factor */ - sprintf( char_buff, "%+07.2f,%+06.2f,%05.2f,%06.2f,%04.2f\n", ismMetadata.azimuth, ismMetadata.elevation, ismMetadata.radius, ismMetadata.spread, ismMetadata.gainFactor ); + snprintf( char_buff, sizeof( char_buff ), "%+07.2f,%+06.2f,%05.2f,%06.2f,%04.2f\n", ismMetadata.azimuth, ismMetadata.elevation, ismMetadata.radius, ismMetadata.spread, ismMetadata.gainFactor ); if ( file ) { diff --git a/lib_util/masa_file_writer.c b/lib_util/masa_file_writer.c index e8f9a09c68..1532f62dda 100644 --- a/lib_util/masa_file_writer.c +++ b/lib_util/masa_file_writer.c @@ -66,7 +66,7 @@ static void getExtMasaMetadataFileName( /* sizeof( ext_meta ) accounts for terminating NULL, don't subtract extra 1 */ const int32_t maxNameLenWithoutExt = sizeof( metadata_filename[0] ) - sizeof( ext_meta ); strncpy( metadata_filename[0], outputWavFilename, maxNameLenWithoutExt ); - sprintf( ext_meta, ".met" ); + snprintf( ext_meta, sizeof(ext_meta), ".met" ); /* strlen( metadata_filename[0] ) doesn't account for terminating NULL, subtract extra 1 */ const int32_t maxNumCharactersToAppend = (int32_t) ( sizeof( metadata_filename[0] ) - strlen( metadata_filename[0] ) - 1 ); -- GitLab From 89f671f924d7414b8ceb1cf6956b19c7365c445a Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Tue, 17 Jan 2023 11:46:12 +0100 Subject: [PATCH 4/5] Wrap changes in switch --- apps/renderer.c | 48 +++++++++++++++++++++++++++++++++++++ lib_com/options.h | 1 + lib_rend/lib_rend.c | 4 ++++ lib_util/ism_file_writer.c | 8 +++++++ lib_util/masa_file_writer.c | 4 ++++ 5 files changed, 65 insertions(+) diff --git a/apps/renderer.c b/apps/renderer.c index e38f523680..da232385db 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -1041,6 +1041,7 @@ static IVAS_REND_AudioConfig ambisonicsOrderToEnum( return IVAS_REND_AUDIO_CONFIG_UNKNOWN; } +#ifdef FIX_293_EXT_RENDERER_CLI static const CmdLnParser_Option *findOptionById( const int32_t id ) { @@ -1054,6 +1055,7 @@ static const CmdLnParser_Option *findOptionById( return NULL; } +#endif static bool parseInConfig( const char *inFormatStr, @@ -1142,9 +1144,13 @@ static bool parseInConfig( if ( error == IVAS_ERR_FAILED_FILE_OPEN ) { +#ifdef FIX_293_EXT_RENDERER_CLI /* Failed to open with given string - most likely wasn't a file path */ const CmdLnParser_Option *listOption = findOptionById( CmdLnOptionId_listFormats ); fprintf( stderr, "Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match ); +#else + fprintf( stderr, "Unsupported input format: %s\n", inFormatStr ); +#endif return false; } if ( error != IVAS_ERR_OK ) @@ -1159,6 +1165,7 @@ static bool parseInConfig( } break; default: +#ifdef FIX_293_EXT_RENDERER_CLI { /* Default case covers formats that are defined in the IVAS_REND_AudioConfig enum, * but cannot be used at input, e.g. BINAURAL */ @@ -1166,6 +1173,12 @@ static bool parseInConfig( fprintf( stderr, "Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match ); return false; } +#else + /* Default case covers formats that are defined in the IVAS_REND_AudioConfig enum, + * but cannot be used at input, e.g. BINAURAL */ + fprintf( stderr, "Unsupported input format: %s\n", inFormatStr ); + return false; +#endif } return true; @@ -1303,6 +1316,7 @@ static IVAS_REND_AudioConfig parseAudioConfig( } if ( strncmp( charBuf, "ISM", 3 ) == 0 ) { +#ifdef FIX_293_EXT_RENDERER_CLI /* Accept input config as ISM only if the 4th character is a number from 1 to 4. * Otherwise, do nothing. Unknown audio config will be returned. */ switch ( charBuf[3] ) @@ -1313,6 +1327,9 @@ static IVAS_REND_AudioConfig parseAudioConfig( case '4': return IVAS_REND_AUDIO_CONFIG_OBJECT; } +#else + return IVAS_REND_AUDIO_CONFIG_OBJECT; +#endif } if ( strncmp( charBuf, "MASA", 4 ) == 0 ) { @@ -1340,6 +1357,22 @@ static IVAS_REND_AudioConfig parseAudioConfig( return IVAS_REND_AUDIO_CONFIG_UNKNOWN; } +#ifndef FIX_293_EXT_RENDERER_CLI +static const CmdLnParser_Option *findOptionById( + const int32_t id ) +{ + for ( int32_t i = 0; i < numCliOptions; ++i ) + { + if ( cliOptions[i].id == id ) + { + return &cliOptions[i]; + } + } + + return NULL; +} +#endif + static bool checkRequiredArgs( CmdlnArgs args ) { @@ -1632,6 +1665,7 @@ void IsmPositionProvider_getNextFrame( for ( objIdx = 0; objIdx < positionProvider->numObjects; ++objIdx ) { +#ifdef FIX_293_EXT_RENDERER_CLI /* If ISM metadata reader is open, read from metadata file */ if ( positionProvider->ismReaders[objIdx] != NULL ) { @@ -1647,6 +1681,16 @@ void IsmPositionProvider_getNextFrame( objectMetadataBuffer->positions[objIdx].azimuth = 0.0f; objectMetadataBuffer->positions[objIdx].elevation = 0.0f; } +#else + if ( positionProvider->ismReaders[objIdx] != NULL ) + { + getMetadataFromFileReader( positionProvider->ismReaders[objIdx], objectMetadataBuffer, objIdx ); + } + else + { + readFromShorthandMetadata( positionProvider, objectMetadataBuffer, objIdx ); + } +#endif /* Wrap azimuth to lie within (-180, 180] range */ while ( objectMetadataBuffer->positions[objIdx].azimuth < 0.0f ) @@ -2034,7 +2078,11 @@ static void parseMasa( if ( strncmp( line, "MASA", 4 ) != 0 ) { char numTcs = *line; +#ifdef FIX_293_EXT_RENDERER_CLI snprintf( line, 6 /* write at most 6 characters: MASAx + null termination */, "MASA%c", numTcs ); +#else + sprintf( line, "MASA%c", numTcs ); +#endif } inConfig->masaBuses[idx].audioConfig = parseAudioConfig( line ); diff --git a/lib_com/options.h b/lib_com/options.h index 09e29ce40b..b974000782 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -152,6 +152,7 @@ #define ENV_STAB_FIX /* Contribution 23: HQ envelope stability memory fix */ #define STABILIZE_GIPD /* FhG: Contribution 22: gIPD stabilization */ #define FIX_292_VBAP_CALLOC_REMOVAL /* Nokia: Fixes issue 292 by removing the remnant callocs */ +#define FIX_293_EXT_RENDERER_CLI /* FhG: Fix bugs in external renderer CLI */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 3303556258..5e59d85861 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2563,7 +2563,11 @@ static IVAS_REND_InputId makeInputId( /* Put config type in second byte (from LSB), put index + 1 in first byte * * Index is incremented here so that a valid ID can never be 0. */ +#ifdef FIX_293_EXT_RENDERER_CLI return (IVAS_REND_InputId) ( ( ( (uint32_t) getAudioConfigType( config ) ) << 8 ) | ( inputIndex + 1 ) ); +#else + return (IVAS_REND_InputId) ( ( getAudioConfigType( config ) << 8 ) | ( inputIndex + 1 ) ); +#endif } static ivas_error getInputById( diff --git a/lib_util/ism_file_writer.c b/lib_util/ism_file_writer.c index 63e5ce5c46..e0a910d5db 100644 --- a/lib_util/ism_file_writer.c +++ b/lib_util/ism_file_writer.c @@ -64,7 +64,11 @@ ivas_error IsmFileWriter_open( FILE *file; strncpy( metadata_filename_loc, filePathWav, sizeof( metadata_filename_loc ) - 1 ); +#ifdef FIX_293_EXT_RENDERER_CLI snprintf( ext_meta, sizeof( ext_meta ), ".%d.csv", obj_num ); +#else + sprintf( ext_meta, ".%d.csv", obj_num ); +#endif const int32_t maxNumCharactersToAppend = (int32_t) sizeof( metadata_filename_loc ) - strlen( metadata_filename_loc ) - 1; strncat( metadata_filename_loc, ext_meta, maxNumCharactersToAppend ); @@ -116,7 +120,11 @@ ivas_error IsmFileWriter_writeFrame( file = ismWriter->file; /* IVAS_fmToDo: work in progress; currently position_azimuth, position_elevation, position_radius, spread, gain_factor */ +#ifdef FIX_293_EXT_RENDERER_CLI snprintf( char_buff, sizeof( char_buff ), "%+07.2f,%+06.2f,%05.2f,%06.2f,%04.2f\n", ismMetadata.azimuth, ismMetadata.elevation, ismMetadata.radius, ismMetadata.spread, ismMetadata.gainFactor ); +#else + sprintf( char_buff, "%+07.2f,%+06.2f,%05.2f,%06.2f,%04.2f\n", ismMetadata.azimuth, ismMetadata.elevation, ismMetadata.radius, ismMetadata.spread, ismMetadata.gainFactor ); +#endif if ( file ) { diff --git a/lib_util/masa_file_writer.c b/lib_util/masa_file_writer.c index 1532f62dda..bb0af4b8c3 100644 --- a/lib_util/masa_file_writer.c +++ b/lib_util/masa_file_writer.c @@ -66,7 +66,11 @@ static void getExtMasaMetadataFileName( /* sizeof( ext_meta ) accounts for terminating NULL, don't subtract extra 1 */ const int32_t maxNameLenWithoutExt = sizeof( metadata_filename[0] ) - sizeof( ext_meta ); strncpy( metadata_filename[0], outputWavFilename, maxNameLenWithoutExt ); +#ifdef FIX_293_EXT_RENDERER_CLI snprintf( ext_meta, sizeof(ext_meta), ".met" ); +#else + sprintf( ext_meta, ".met" ); +#endif /* strlen( metadata_filename[0] ) doesn't account for terminating NULL, subtract extra 1 */ const int32_t maxNumCharactersToAppend = (int32_t) ( sizeof( metadata_filename[0] ) - strlen( metadata_filename[0] ) - 1 ); -- GitLab From 951bdab91c0942ffddc6036893639d8e2cc23ff1 Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Tue, 17 Jan 2023 12:21:23 +0100 Subject: [PATCH 5/5] Fix formatting --- apps/renderer.c | 3 ++- lib_util/masa_file_writer.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index da232385db..77f25ba0b3 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -1677,7 +1677,8 @@ void IsmPositionProvider_getNextFrame( readFromShorthandMetadata( positionProvider, objectMetadataBuffer, objIdx ); } /* Otherwise fall back to default position */ - else { + else + { objectMetadataBuffer->positions[objIdx].azimuth = 0.0f; objectMetadataBuffer->positions[objIdx].elevation = 0.0f; } diff --git a/lib_util/masa_file_writer.c b/lib_util/masa_file_writer.c index bb0af4b8c3..3cfb25b494 100644 --- a/lib_util/masa_file_writer.c +++ b/lib_util/masa_file_writer.c @@ -67,7 +67,7 @@ static void getExtMasaMetadataFileName( const int32_t maxNameLenWithoutExt = sizeof( metadata_filename[0] ) - sizeof( ext_meta ); strncpy( metadata_filename[0], outputWavFilename, maxNameLenWithoutExt ); #ifdef FIX_293_EXT_RENDERER_CLI - snprintf( ext_meta, sizeof(ext_meta), ".met" ); + snprintf( ext_meta, sizeof( ext_meta ), ".met" ); #else sprintf( ext_meta, ".met" ); #endif -- GitLab