diff --git a/apps/renderer.c b/apps/renderer.c index 6084b9f46a2fa15c99bb6dff7712e878c1f63410..77f25ba0b3995317e632e32935dc97063718516b 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -1041,6 +1041,22 @@ 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 ) +{ + for ( int32_t i = 0; i < numCliOptions; ++i ) + { + if ( cliOptions[i].id == id ) + { + return &cliOptions[i]; + } + } + + return NULL; +} +#endif + static bool parseInConfig( const char *inFormatStr, InputConfig *inConfig, @@ -1128,8 +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 ) @@ -1144,10 +1165,20 @@ 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 */ + 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; + } +#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; @@ -1285,7 +1316,20 @@ 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] ) + { + case '1': + case '2': + case '3': + case '4': + return IVAS_REND_AUDIO_CONFIG_OBJECT; + } +#else return IVAS_REND_AUDIO_CONFIG_OBJECT; +#endif } if ( strncmp( charBuf, "MASA", 4 ) == 0 ) { @@ -1313,6 +1357,7 @@ 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 ) { @@ -1326,6 +1371,7 @@ static const CmdLnParser_Option *findOptionById( return NULL; } +#endif static bool checkRequiredArgs( CmdlnArgs args ) @@ -1619,6 +1665,24 @@ 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 ) + { + getMetadataFromFileReader( positionProvider->ismReaders[objIdx], objectMetadataBuffer, objIdx ); + } + /* 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; + } +#else if ( positionProvider->ismReaders[objIdx] != NULL ) { getMetadataFromFileReader( positionProvider->ismReaders[objIdx], objectMetadataBuffer, objIdx ); @@ -1627,6 +1691,7 @@ void IsmPositionProvider_getNextFrame( { readFromShorthandMetadata( positionProvider, objectMetadataBuffer, objIdx ); } +#endif /* Wrap azimuth to lie within (-180, 180] range */ while ( objectMetadataBuffer->positions[objIdx].azimuth < 0.0f ) @@ -2014,7 +2079,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 09e29ce40bc35e30d7acb2d761a74a835bbe962f..b974000782006a643ef24a5efd5322c2dfad3027 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 028b0f62740ece10b78b6dd79e2d07bd8746f1c6..5e59d8586129bb45d2e0c4d6a41a2f95e448b4f1 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 ac90e7b1ebcb0f43275df3b725f21a53df88ebe4..e0a910d5db5f39ede867a54b70c9779bdb38b1ff 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 e8f9a09c68d812dfa9f3f4059932c1d4046cb90b..3cfb25b494b62285cf33c5fea17a21efa6e12e54 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 );