diff --git a/apps/renderer.c b/apps/renderer.c index c02785a616ebd600a33cd617656261f23f3da3b1..84d616af1e1a50f77a3735a7ced9c6c408329bd6 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -88,6 +88,15 @@ typedef struct uint16_t durationCounters[RENDERER_MAX_ISM_INPUTS]; /* Number of frames spent at current position */ } IsmPositionProvider; +#ifdef FIX_296_CFG_LFE_SCENE_DESC +typedef struct +{ + float lfe_azi; + float lfe_ele; + float lfe_gain_dB; + char lfe_routing_mtx[FILENAME_MAX]; +} LfeRoutingConfig; +#endif typedef struct { IVAS_REND_AudioConfig audioConfig; @@ -305,7 +314,11 @@ static const int32_t numCliOptions = sizeof( cliOptions ) / sizeof( CmdLnParser_ static IVAS_REND_AudioConfig ambisonicsOrderToEnum( const int16_t order ); +#ifdef FIX_296_CFG_LFE_SCENE_DESC +static void parseSceneDescriptionFile( char *path, char *audioFilePath, InputConfig *inConfig, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders, LfeRoutingConfig **lfeRoutingConfigs ); +#else static void parseSceneDescriptionFile( char *path, char *audioFilePath, InputConfig *inConfig, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders ); +#endif static ivas_error parseCustomLayoutFile( const char *filePath, IVAS_CUSTOM_LS_DATA *pLsSetupCustom ); @@ -317,6 +330,11 @@ static void IsmPositionProvider_getNextFrame( IsmPositionProvider *positionProvi static void IsmPositionProvider_close( IsmPositionProvider *positionProvider ); +#ifdef FIX_296_CFG_LFE_SCENE_DESC +static LfeRoutingConfig *LfeRoutingConfig_open( void ); +static void LfeRoutingConfig_close( LfeRoutingConfig *lfeRoutingCfg ); +#endif + static void readFromShorthandMetadata( IsmPositionProvider *positionProvider, ObjectPositionBuffer *objectMetadataBuffer, const uint32_t objIdx ); void getMetadataFromFileReader( IsmFileReader *ismReader, ObjectPositionBuffer *objectMetadataBuffer, const uint32_t objIdx ); @@ -335,7 +353,11 @@ static int8_t parseInt32( const char *line, int32_t *ret ); static void parseObjectPosition( char *line, IVAS_REND_AudioObjectPosition *position, uint16_t *positionDuration ); +#ifdef FIX_296_CFG_LFE_SCENE_DESC +static void parseMetadata( char *metadataString, char *inDir, InputConfig *inConfig, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders, LfeRoutingConfig **lfeRoutingConfigs ); +#else static void parseMetadata( char *metadataString, char *inDir, InputConfig *inConfig, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders ); +#endif static ivas_error parseLfePanMtxFile( const char *lfeRoutingMatrixFilePath, IVAS_REND_LfePanMtx *lfePanMtx ); @@ -524,6 +546,9 @@ int main( HeadRotFileReader *referenceRotReader = NULL; hrtfFileReader *hrtfFileReader = NULL; IsmPositionProvider *positionProvider; +#ifdef FIX_296_CFG_LFE_SCENE_DESC + LfeRoutingConfig *lfeRoutingConfigs[RENDERER_MAX_MC_INPUTS]; +#endif RenderConfigReader *renderConfigReader = NULL; MasaFileReader *masaReaders[RENDERER_MAX_MASA_INPUTS]; IVAS_MASA_METADATA_HANDLE hMasaMetadata[RENDERER_MAX_MASA_INPUTS]; @@ -558,6 +583,13 @@ int main( hMasaMetadata[i] = NULL; } +#ifdef FIX_296_CFG_LFE_SCENE_DESC + for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) + { + lfeRoutingConfigs[i] = NULL; + } +#endif + CmdlnArgs args = parseCmdlnArgs( argc, argv ); if ( args.nonDiegeticPan && !( ( args.inConfig.numAudioObjects == 0 && args.inConfig.multiChannelBuses[0].audioConfig == IVAS_REND_AUDIO_CONFIG_MONO ) || @@ -630,7 +662,16 @@ int main( if ( args.sceneDescriptionInput ) { /* With scene description input, inputFilePath is the path to the scene description file. Parse it. */ +#ifdef FIX_296_CFG_LFE_SCENE_DESC + parseSceneDescriptionFile( args.inputFilePath, + audioFilePath, + &args.inConfig, + positionProvider, + masaReaders, + lfeRoutingConfigs ); +#else parseSceneDescriptionFile( args.inputFilePath, audioFilePath, &args.inConfig, positionProvider, masaReaders ); +#endif } else { @@ -753,7 +794,6 @@ int main( /* parse input LFE panning matrix */ if ( args.lfeCustomRoutingEnabled && !isEmptyString( args.inLfePanningMatrixFile ) ) { - /* TODO tmu: how should we handle this on CLI for multiple MC inputs? */ if ( ( error = parseLfePanMtxFile( args.inLfePanningMatrixFile, &lfePanMatrix ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); @@ -775,7 +815,6 @@ int main( exit( -1 ); } - /* TODO(sgi): Command line only supports one custom LS input for now, extend */ if ( args.inConfig.multiChannelBuses[i].audioConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) { if ( ( error = IVAS_REND_ConfigureCustomInputLoudspeakerLayout( hIvasRend, mcIds[i], args.inConfig.inSetupCustom ) ) != IVAS_ERR_OK ) @@ -789,7 +828,11 @@ int main( { if ( args.lfePanningEnabled ) { +#ifdef FIX_296_CFG_LFE_SCENE_DESC + fprintf( stderr, "Warning: LFE position specified as well as panning matrix! Ignoring position and using gains from panning matrix\n" ); +#else fprintf( stdout, "Warning LFE position specified as well as panning matrix! Ignoring position and using gains from panning matrix\n" ); +#endif args.lfePanningEnabled = false; } @@ -808,6 +851,39 @@ int main( exit( -1 ); } } +#ifdef FIX_296_CFG_LFE_SCENE_DESC + else + { + /* check for configuration from scene description file */ + if ( lfeRoutingConfigs[i] != NULL ) + { + /* prioritise panning matrix if configured */ + if ( !isEmptyString( lfeRoutingConfigs[i]->lfe_routing_mtx ) ) + { + if ( ( error = parseLfePanMtxFile( lfeRoutingConfigs[i]->lfe_routing_mtx, &lfePanMatrix ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); + exit( -1 ); + } + + if ( ( error = IVAS_REND_SetInputLfeMtx( hIvasRend, mcIds[i], (const IVAS_REND_LfePanMtx *) &lfePanMatrix ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); + exit( -1 ); + } + } + /* set position based gains */ + else + { + if ( ( error = IVAS_REND_SetInputLfePos( hIvasRend, mcIds[i], lfeRoutingConfigs[i]->lfe_gain_dB, lfeRoutingConfigs[i]->lfe_azi, lfeRoutingConfigs[i]->lfe_ele ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); + exit( -1 ); + } + } + } + } +#endif } for ( i = 0; i < args.inConfig.numAudioObjects; ++i ) @@ -1168,6 +1244,12 @@ int main( { MasaFileReader_close( &masaReaders[i] ); } +#ifdef FIX_296_CFG_LFE_SCENE_DESC + for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) + { + LfeRoutingConfig_close( lfeRoutingConfigs[i] ); + } +#endif AudioFileReader_close( &audioReader ); AudioFileWriter_close( &audioWriter ); HeadRotationFileReader_close( &headRotReader ); @@ -1679,8 +1761,13 @@ static CmdlnArgs defaultArgs( args.lfePanningEnabled = false; args.lfeConfigGain = 1.0f; +#ifdef FIX_296_CFG_LFE_SCENE_DESC + args.lfeConfigAzimuth = 0.f; + args.lfeConfigElevation = 0.f; +#else args.lfeConfigAzimuth = 0; args.lfeConfigElevation = 0; +#endif args.lfeCustomRoutingEnabled = false; clearString( args.inLfePanningMatrixFile ); @@ -1863,6 +1950,34 @@ IsmPositionProvider *IsmPositionProvider_open( return ipp; } +#ifdef FIX_296_CFG_LFE_SCENE_DESC +LfeRoutingConfig *LfeRoutingConfig_open( + void ) +{ + LfeRoutingConfig *lrc; + + lrc = (LfeRoutingConfig *) malloc( sizeof( LfeRoutingConfig ) ); + lrc->lfe_azi = 0.f; + lrc->lfe_ele = 0.f; + lrc->lfe_gain_dB = 0.f; + lrc->lfe_routing_mtx[0] = '\0'; + + return lrc; +} + +void LfeRoutingConfig_close( + LfeRoutingConfig *lfeRoutingCfg ) +{ + if ( lfeRoutingCfg != NULL ) + { + + free( lfeRoutingCfg ); + } + + return; +} +#endif + void getMetadataFromFileReader( IsmFileReader *ismReader, ObjectPositionBuffer *objectMetadataBuffer, @@ -2152,6 +2267,12 @@ static int8_t parseInt32( static void parseOptionalInputValues( char *line, +#ifdef FIX_296_CFG_LFE_SCENE_DESC + float *lfe_gain_dB, + float *lfe_pos_azi, + float *lfe_pos_ele, + char *lfe_pan_mtx_filename, +#endif float *gain_dB ) { char *parse_pos; @@ -2163,6 +2284,24 @@ static void parseOptionalInputValues( /* Set default values, in case some values are not specified */ *gain_dB = 0.f; +#ifdef FIX_296_CFG_LFE_SCENE_DESC + if ( lfe_gain_dB != NULL ) + { + *lfe_gain_dB = 0.f; + } + if ( lfe_pos_azi != NULL ) + { + *lfe_pos_azi = 0.f; + } + if ( lfe_pos_ele != NULL ) + { + *lfe_pos_ele = 0.f; + } + if ( lfe_pan_mtx_filename != NULL ) + { + *lfe_pan_mtx_filename = '\0'; + } +#endif /* Save parsing position - will have to be passed to strtok to resume parsing after using strtok with non-NULL value below */ parse_pos = readNextMetadataChunk( line, "\n" ); @@ -2179,10 +2318,50 @@ static void parseOptionalInputValues( if ( *endptr != '\0' ) { +#ifdef FIX_296_CFG_LFE_SCENE_DESC + fprintf( stderr, "Cannot parse string \"%s\" as a float value\n", value ); +#else fprintf( stderr, "Cannot parse string string \"%s\" as a float value\n", value ); +#endif + exit( -1 ); + } + } +#ifdef FIX_296_CFG_LFE_SCENE_DESC + else if ( ( strcmp( key, "lfe_gain_dB" ) == 0 ) && lfe_gain_dB != NULL ) + { + *lfe_gain_dB = (float) strtod( value, &endptr ); + + if ( *endptr != '\0' ) + { + fprintf( stderr, "Cannot parse string \"%s\" as a float value\n", value ); + exit( -1 ); + } + } + else if ( ( strcmp( key, "lfe_azi" ) == 0 ) && lfe_pos_azi != NULL ) + { + *lfe_pos_azi = (float) strtod( value, &endptr ); + + if ( *endptr != '\0' ) + { + fprintf( stderr, "Cannot parse string \"%s\" as a float value\n", value ); + exit( -1 ); + } + } + else if ( ( strcmp( key, "lfe_ele" ) == 0 ) && lfe_pos_ele != NULL ) + { + *lfe_pos_ele = (float) strtod( value, &endptr ); + + if ( *endptr != '\0' ) + { + fprintf( stderr, "Cannot parse string \"%s\" as a float value\n", value ); exit( -1 ); } } + else if ( strcmp( key, "lfe_matrix" ) == 0 ) + { + strncpy( lfe_pan_mtx_filename, value, FILENAME_MAX - 1 ); + } +#endif else { fprintf( stderr, "Unsupported optional key: %s\n", key ); @@ -2268,7 +2447,11 @@ static void parseIsm( } /* Read optional values */ +#ifdef FIX_296_CFG_LFE_SCENE_DESC + parseOptionalInputValues( line, NULL, NULL, NULL, NULL, &inConfig->audioObjects[idx].gain_dB ); +#else parseOptionalInputValues( line, &inConfig->audioObjects[idx].gain_dB ); +#endif return; } @@ -2289,7 +2472,11 @@ static void parseSba( inConfig->ambisonicsBuses[idx].audioConfig = ambisonicsOrderToEnum( ambiOrder ); /* Read optional values */ +#ifdef FIX_296_CFG_LFE_SCENE_DESC + parseOptionalInputValues( line, NULL, NULL, NULL, NULL, &inConfig->ambisonicsBuses[idx].gain_dB ); +#else parseOptionalInputValues( line, &inConfig->ambisonicsBuses[idx].gain_dB ); +#endif return; } @@ -2297,6 +2484,9 @@ static void parseSba( static void parseMc( char *line, InputConfig *inConfig, +#ifdef FIX_296_CFG_LFE_SCENE_DESC + LfeRoutingConfig **lfeRoutingConfigs, +#endif const int32_t idx ) { readNextMetadataChunk( line, "\n" ); @@ -2305,17 +2495,70 @@ static void parseMc( readNextMetadataChunk( line, "\n" ); IVAS_REND_AudioConfig cfg = parseAudioConfig( line ); +#ifdef FIX_296_CFG_LFE_SCENE_DESC + /* Try to use the given string as a path to a custom loudspeaker layout file. */ + if ( cfg == IVAS_REND_AUDIO_CONFIG_UNKNOWN ) + { + ivas_error error = parseCustomLayoutFile( line, &inConfig->inSetupCustom ); + + if ( error != IVAS_ERR_OK ) + { + fprintf( stderr, "Error while parsing input format %s\n", line ); + exit( -1 ); + } + inConfig->numMultiChannelBuses = 1; + inConfig->multiChannelBuses[idx].audioConfig = IVAS_REND_AUDIO_CONFIG_LS_CUSTOM; + inConfig->multiChannelBuses[idx].inputChannelIndex = 0; + inConfig->multiChannelBuses[idx].gain_dB = 0.0f; + } +#else if ( cfg == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) { parseCustomLayoutFile( line, &inConfig->inSetupCustom ); } +#endif else { inConfig->multiChannelBuses[idx].audioConfig = cfg; } /* Read optional values */ +#ifdef FIX_296_CFG_LFE_SCENE_DESC + bool lfe_panningEnabled; + float lfe_gain_dB, lfe_azi, lfe_ele; + char lfe_routing_mtx[FILENAME_MAX]; + + parseOptionalInputValues( line, &lfe_gain_dB, &lfe_azi, &lfe_ele, lfe_routing_mtx, &inConfig->multiChannelBuses[idx].gain_dB ); + + lfe_panningEnabled = ( lfe_gain_dB != 0.f || lfe_azi != 0.f || lfe_ele != 0.f ) ? true : false; + + if ( lfe_panningEnabled && !isEmptyString( lfe_routing_mtx ) ) + { + fprintf( stderr, "Warning: LFE position specified as well as panning matrix! Ignoring position and using gains from panning matrix\n" ); + lfe_panningEnabled = false; + } + + if ( lfe_panningEnabled || !isEmptyString( lfe_routing_mtx ) ) + { + /* a configuration was specified, set the values */ + lfeRoutingConfigs[idx] = LfeRoutingConfig_open(); + + if ( lfe_panningEnabled ) + { + lfeRoutingConfigs[idx]->lfe_gain_dB = lfe_gain_dB; + lfeRoutingConfigs[idx]->lfe_azi = lfe_azi; + lfeRoutingConfigs[idx]->lfe_ele = lfe_ele; + } + + if ( !isEmptyString( lfe_routing_mtx ) ) + { + strncpy( lfeRoutingConfigs[idx]->lfe_routing_mtx, lfe_routing_mtx, FILENAME_MAX ); + convert_backslash( lfeRoutingConfigs[idx]->lfe_routing_mtx ); + } + } +#else parseOptionalInputValues( line, &inConfig->multiChannelBuses[idx].gain_dB ); +#endif return; } @@ -2356,7 +2599,11 @@ static void parseMasa( } /* Read optional values */ +#ifdef FIX_296_CFG_LFE_SCENE_DESC + parseOptionalInputValues( line, NULL, NULL, NULL, NULL, &inConfig->masaBuses[idx].gain_dB ); +#else parseOptionalInputValues( line, &inConfig->masaBuses[idx].gain_dB ); +#endif return; } @@ -2397,7 +2644,12 @@ static void parseMetadata( char *inDir, InputConfig *inConfig, IsmPositionProvider *positionProvider, +#ifdef FIX_296_CFG_LFE_SCENE_DESC + MasaFileReader **masaReaders, + LfeRoutingConfig **lfeRoutingConfigs ) +#else MasaFileReader **masaReaders ) +#endif { char line[RENDERER_MAX_METADATA_LINE_LENGTH]; char *delimiter; @@ -2449,7 +2701,11 @@ static void parseMetadata( fprintf( stderr, "Metadata exceeds the supported number of MC inputs\n" ); exit( -1 ); } +#ifdef FIX_296_CFG_LFE_SCENE_DESC + parseMc( line, inConfig, lfeRoutingConfigs, counterChannelAudioObjects - 1 ); +#else parseMc( line, inConfig, counterChannelAudioObjects - 1 ); +#endif } else if ( strcmp( line, "SBA" ) == 0 ) { @@ -2517,7 +2773,12 @@ static void parseSceneDescriptionFile( char *audioFilePath, InputConfig *inConfig, IsmPositionProvider *positionProvider, +#ifdef FIX_296_CFG_LFE_SCENE_DESC + MasaFileReader **masaReaders, + LfeRoutingConfig **lfeRoutingConfigs ) +#else MasaFileReader **masaReaders ) +#endif { uint32_t inAudioFilePathLen; char inAudioFilePath[FILENAME_MAX]; @@ -2546,7 +2807,11 @@ static void parseSceneDescriptionFile( strcpy( audioFilePath, inDir ); strncat( audioFilePath, inAudioFilePath, inAudioFilePathLen ); +#ifdef FIX_296_CFG_LFE_SCENE_DESC + parseMetadata( mtdStr, inDir, inConfig, positionProvider, masaReaders, lfeRoutingConfigs ); +#else parseMetadata( mtdStr, inDir, inConfig, positionProvider, masaReaders ); +#endif return; } @@ -2609,8 +2874,16 @@ static ivas_error parseLfePanMtxFile( set_zero( ( *lfePanMtx )[lfe_in], IVAS_MAX_OUTPUT_CHANNELS ); } +#ifdef FIX_296_CFG_LFE_SCENE_DESC + for ( lfe_in = 0; lfe_in < IVAS_MAX_INPUT_LFE_CHANNELS; lfe_in++ ) +#else for ( lfe_in = 0, ch_out = 0; lfe_in < IVAS_MAX_INPUT_LFE_CHANNELS; lfe_in++ ) +#endif { +#ifdef FIX_296_CFG_LFE_SCENE_DESC + ch_out = 0; + +#endif /* if EOF or a blank line is encountered, simply return */ if ( ( fgets( line, 200, mtxFile ) == NULL ) && ( strcmp( line, "\n" ) == 0 ) && ( strcmp( line, "\r\n" ) == 0 ) ) { diff --git a/lib_com/options.h b/lib_com/options.h index d8428a0810a3860eaff781509a6a48c99dab5982..c215b53875ac89eb100fefe51be0261ff84ee41b 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -227,6 +227,7 @@ #define FIX_483 /* FhG: fix issue 483, division by zero in nois_est */ #define FIX_483b /* FhG: fix issue 483, uninitialized values in ivas_mct_core_enc */ #define FIX_170_DTX_MASA /* Nokia: Fix issue 170, relaxing the use of DTX in MASA format */ +#define FIX_296_CFG_LFE_SCENE_DESC /* FhG: Fix issue 296 - add configurable LFE handling to the scene description file */ #define FIX_510 /* FhG: fix issue 510, misleading error message for invalid input format */ #define FIX_509 /* FhG: fix issue 509, too low number of bitsream indices in SBA */ #define FIX_519_JBM_ACCESS_NULL_TC_BUFFER /* FhG: fix issue 519, accessing a yet uninitialized TC Buffer in frame 0*/ diff --git a/tests/renderer/data/renderer_config_format_readme.txt b/tests/renderer/data/renderer_config_format_readme.txt index 1fe493b279511f0ba4a733a95b7568e8e6e09ae7..dffb6c63175898183457a9bae152279b2905c9c2 100644 --- a/tests/renderer/data/renderer_config_format_readme.txt +++ b/tests/renderer/data/renderer_config_format_readme.txt @@ -109,6 +109,10 @@ Currently the following key-value pairs are supported: | key | value type | |---------------------|--------------------------------------| | gain_dB | float | +| lfe_matrix | str | +| lfe_gain_dB | float | +| lfe_azi | float | +| lfe_ele | float | ================================ Example config =================================