From 26fd76c1fea263700aaf6bbfe9cd8561a57db273 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 27 Aug 2023 20:48:09 +0200 Subject: [PATCH 1/9] fixes + improvements --- apps/decoder.c | 231 +++++++++++++++++----------------------------- lib_com/options.h | 2 +- lib_dec/lib_dec.c | 195 ++++++++++++++++++++++++-------------- lib_dec/lib_dec.h | 76 +++++++-------- 4 files changed, 249 insertions(+), 255 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index a63d8e9f4b..c112fac320 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -176,9 +176,11 @@ static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotF static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec ); #ifdef DEBUGGING +#ifndef API_5MS #ifdef VARIABLE_SPEED_DECODING static ivas_error decodeVariableSpeed( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); #endif +#endif static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec ); static int16_t app_own_random( int16_t *seed ); static IVAS_DEC_FORCED_REND_MODE parseForcedRendModeDec( char *forcedRendModeChar ); @@ -439,74 +441,10 @@ int main( } } -#ifdef API_5MS - /*-------------------------------------------------------------------* - * Load renderer configuration from file - *--------------------------------------------------------------------*/ - - IVAS_RENDER_CONFIG_DATA renderConfigSplit; - if ( ( error = IVAS_DEC_GetDefaultRenderConfig( &renderConfigSplit ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_GetDefaultRenderConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - if ( arg.renderConfigEnabled ) - { - /* sanity check */ -#ifdef SPLIT_REND_WITH_HEAD_ROT - if ( arg.outputConfig != AUDIO_CONFIG_BINAURAL && - arg.outputConfig != AUDIO_CONFIG_BINAURAL_ROOM_IR && - arg.outputConfig != AUDIO_CONFIG_BINAURAL_ROOM_REVERB && - arg.outputConfig != AUDIO_CONFIG_BINAURAL_SPLIT_CODED && - arg.outputConfig != AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) - { - fprintf( stderr, "\nExternal Renderer Config is supported only when binaural output configurations is used as output OR when Split rendering mode is enabled. Exiting. \n" ); - exit( -1 ); - } -#else - if ( arg.outputConfig != AUDIO_CONFIG_BINAURAL && arg.outputConfig != AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - { - fprintf( stderr, "\nExternal Renderer Config is supported only for binaural output configurations. Exiting. \n\n" ); - goto cleanup; - } -#endif - if ( RenderConfigReader_read( renderConfigReader, - arg.renderConfigFilename, - &renderConfigSplit ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Failed to read renderer configuration from file %s\n\n", arg.renderConfigFilename ); - goto cleanup; - } - } -#endif - /*------------------------------------------------------------------------------------------* * Configure the decoder *------------------------------------------------------------------------------------------*/ -/*------------------------------------------------------------------------------------------* - * Configure the decoder - *------------------------------------------------------------------------------------------*/ -#ifdef SPLIT_REND_WITH_HEAD_ROT - if ( arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) - { - arg.enableHeadRotation = true; -#ifdef API_5MS_BASELINE - if ( arg.enable5ms && - ( renderConfigSplit.split_rend_config.poseCorrectionMode == IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE || - renderConfigSplit.split_rend_config.dof == 0 ) ) - { - /*TODO : needs to be refined as this wont work with LCLD codec*/ - arg.enable5ms = true; - } - else - { - arg.enable5ms = false; - } -#endif - } -#endif - if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, #ifdef API_5MS_BASELINE arg.tsmEnabled, arg.enable5ms, @@ -517,9 +455,8 @@ int main( goto cleanup; } - /*------------------------------------------------------------------------------------------* - * Configure VoIP mode + * Configure Split rendering *------------------------------------------------------------------------------------------*/ #ifdef API_5MS @@ -531,6 +468,8 @@ int main( fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } + + arg.enableHeadRotation = true; } #endif #endif @@ -707,6 +646,22 @@ int main( goto cleanup; } +#ifdef SPLIT_REND_WITH_HEAD_ROT +#ifdef API_5MS_BASELINE + if ( arg.enable5ms && + ( renderConfig.split_rend_config.poseCorrectionMode == IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE || + renderConfig.split_rend_config.dof == 0 ) ) + { + /*TODO : needs to be refined as this wont work with LCLD codec*/ + arg.enable5ms = true; + } + else + { + arg.enable5ms = false; + } +#endif +#endif + if ( RenderConfigReader_read( renderConfigReader, arg.renderConfigFilename, &renderConfig ) != IVAS_ERR_OK ) { fprintf( stderr, "Failed to read renderer configuration from file %s\n\n", arg.renderConfigFilename ); @@ -743,6 +698,7 @@ int main( goto cleanup; } } + /*------------------------------------------------------------------------------------------* * Load custom loudspeaker layout data *------------------------------------------------------------------------------------------*/ @@ -1758,7 +1714,7 @@ static ivas_error initOnFirstGoodFrame( uint16_t *pNumObj /* o : */ #ifdef SPLIT_REND_WITH_HEAD_ROT , - SplitFileReadWrite **hSplitRendFileReadWrite + SplitFileReadWrite **splitRendWriter #endif ) { @@ -1813,7 +1769,7 @@ static ivas_error initOnFirstGoodFrame( if ( arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) { - if ( ( error = split_rend_writer_open( hSplitRendFileReadWrite, arg.outputWavFilename, delayNumSamples_temp[0], delayTimeScale_temp ) ) != IVAS_ERR_OK ) + if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputWavFilename, delayNumSamples_temp[0], delayTimeScale_temp ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nUnable to open output split rendering metadata file %s\n", arg.outputWavFilename ); return error; @@ -1821,7 +1777,7 @@ static ivas_error initOnFirstGoodFrame( } else { - if ( ( error = split_rend_writer_open( hSplitRendFileReadWrite, arg.outputMdFilename, delayNumSamples_temp[0], delayTimeScale_temp ) ) != IVAS_ERR_OK ) + if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputMdFilename, delayNumSamples_temp[0], delayTimeScale_temp ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nUnable to open output split rendering metadata file %s\n", arg.outputWavFilename ); return error; @@ -1848,7 +1804,7 @@ static ivas_error initOnFirstGoodFrame( for ( int16_t i = 0; i < numInitialBadFrames; ++i ) { #ifdef SPLIT_REND_WITH_HEAD_ROT - if ( *hSplitRendFileReadWrite != NULL ) + if ( *splitRendWriter != NULL ) { IVAS_SPLIT_REND_BITS_DATA splitRendBitsZero; splitRendBitsZero.bits_buf = NULL; @@ -1860,7 +1816,7 @@ static ivas_error initOnFirstGoodFrame( #ifdef API_5MS splitRendBitsZero.codec_frame_size_ms = 20; #endif - if ( split_rend_write_bitstream_to_file( *hSplitRendFileReadWrite, splitRendBitsZero.bits_buf, &splitRendBitsZero.bits_read, &splitRendBitsZero.bits_written, + if ( split_rend_write_bitstream_to_file( *splitRendWriter, splitRendBitsZero.bits_buf, &splitRendBitsZero.bits_read, &splitRendBitsZero.bits_written, -1, IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE #ifdef API_5MS , @@ -1869,7 +1825,7 @@ static ivas_error initOnFirstGoodFrame( ) != IVAS_ERR_OK ) { fprintf( stderr, "\nUnable to write to bitstream file!\n" ); - exit( -1 ); + return error; } } else @@ -1996,9 +1952,8 @@ static ivas_error initOnFirstGoodFrame( } #if defined( SPLIT_REND_WITH_HEAD_ROT ) && defined( API_5MS ) - if ( *hSplitRendFileReadWrite != NULL ) + if ( *splitRendWriter != NULL ) { - int16_t enable5ms; if ( numOutSamples == NULL || vec_pos_len == NULL ) @@ -2006,7 +1961,10 @@ static ivas_error initOnFirstGoodFrame( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - IVAS_DEC_Get5msFlag( hIvasDec, &enable5ms ); + if ( ( error = IVAS_DEC_Get5msFlag( hIvasDec, &enable5ms ) ) != IVAS_ERR_OK ) + { + return error; + } /* real setting of the 5ms mode for split rendering is only known after the decoded first good frame, reset the variables needed in the main decoding loop accordingly here*/ if ( enable5ms ) @@ -2083,7 +2041,7 @@ static ivas_error decodeG192( #ifdef SPLIT_REND_WITH_HEAD_ROT IVAS_SPLIT_REND_BITS_DATA splitRendBits; - SplitFileReadWrite *hSplitRendFileReadWrite; + SplitFileReadWrite *splitRendWriter; #endif for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) @@ -2137,7 +2095,7 @@ static ivas_error decodeG192( nSamplesAvailableNext = 0; vec_pos_update = 0; - if ( arg.enableHeadRotation + if ( ( arg.enableHeadRotation || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) #ifdef API_5MS_BASELINE && arg.enable5ms #endif @@ -2160,7 +2118,7 @@ static ivas_error decodeG192( splitRendBits.codec = IVAS_SPLIT_REND_CODEC_DEFAULT; splitRendBits.pose_correction = IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE; splitRendBits.codec_frame_size_ms = 0; - hSplitRendFileReadWrite = NULL; + splitRendWriter = NULL; #endif /*------------------------------------------------------------------------------------------* @@ -2209,7 +2167,10 @@ static ivas_error decodeG192( } #ifdef API_5MS int16_t enable5ms, num_subframes; - IVAS_DEC_Get5msFlag( hIvasDec, &enable5ms ); + if ( ( error = IVAS_DEC_Get5msFlag( hIvasDec, &enable5ms ) ) != IVAS_ERR_OK ) + { + return error; + } arg.enable5ms = enable5ms; num_subframes = ( arg.enable5ms ) ? 1 : IVAS_MAX_PARAM_SPATIAL_SUBFRAMES; #else @@ -2290,11 +2251,9 @@ static ivas_error decodeG192( for ( i = 0; i < num_subframes; i++ ) { - if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &Quaternions[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError %s while reading external orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), - RotationFileReader_getFilePath( externalOrientationFileReader ) ); + fprintf( stderr, "\nError %s while reading external orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( externalOrientationFileReader ) ); goto cleanup; } } @@ -2374,11 +2333,8 @@ static ivas_error decodeG192( #ifdef SPLIT_REND_WITH_HEAD_ROT if ( arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { - error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, - (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), - &splitRendBits, - &nSamplesRendered_loop, - &needNewFrame ); + error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), + &splitRendBits, &nSamplesRendered_loop, &needNewFrame ); nSamplesRendered += nSamplesRendered_loop; nSamplesToRender -= nSamplesRendered_loop; if ( error != IVAS_ERR_OK ) @@ -2392,12 +2348,10 @@ static ivas_error decodeG192( #endif error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, #if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT - IVAS_DEC_PCM_INT16, - (void *) + IVAS_DEC_PCM_INT16, (void *) #endif - ( pcmBuf + nOutChannels * nSamplesRendered ), - &nSamplesRendered_loop, - &needNewFrame ); + ( pcmBuf + nOutChannels * nSamplesRendered ), + &nSamplesRendered_loop, &needNewFrame ); nSamplesRendered += nSamplesRendered_loop; nSamplesToRender -= nSamplesRendered_loop; if ( error != IVAS_ERR_OK ) @@ -2429,28 +2383,16 @@ static ivas_error decodeG192( /* Once good frame decoded, catch up */ if ( decodedGoodFrame ) { - error = initOnFirstGoodFrame( - hIvasDec, - arg, - numInitialBadFrames, + error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, #if defined( SPLIT_REND_WITH_HEAD_ROT ) && defined( API_5MS ) - &nOutSamples, - &vec_pos_len, + &nOutSamples, &vec_pos_len, #else - nOutSamples, + nOutSamples, #endif - delayNumSamples_orig, - &delayNumSamples, - &delayTimeScale, - &bsFormat, - &afWriter, - &masaWriter, - ismWriters, - &nOutChannels, - &numObj + delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj #ifdef SPLIT_REND_WITH_HEAD_ROT - , - &hSplitRendFileReadWrite + , + &splitRendWriter #endif ); if ( error != IVAS_ERR_OK ) @@ -2468,10 +2410,19 @@ static ivas_error decodeG192( if ( decodedGoodFrame ) { #ifdef SPLIT_REND_WITH_HEAD_ROT - if ( ( hSplitRendFileReadWrite != NULL ) && ( arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) + if ( arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { - if ( split_rend_write_bitstream_to_file( hSplitRendFileReadWrite, splitRendBits.bits_buf, &splitRendBits.bits_read, &splitRendBits.bits_written, - splitRendBits.codec, splitRendBits.pose_correction +#if 0 + IVAS_SPLIT_REND_BITS_DATA splitRendBits; + + if ( ( error = IVAS_DEC_GetSplitRendBits( hIvasDec, &splitRendBits ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_SplitRendBits: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } +#endif + + if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits.bits_buf, &splitRendBits.bits_read, &splitRendBits.bits_written, splitRendBits.codec, splitRendBits.pose_correction #ifdef API_5MS , splitRendBits.codec_frame_size_ms @@ -2482,22 +2433,9 @@ static ivas_error decodeG192( goto cleanup; } } - else + + if ( arg.outputConfig != AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) { - if ( ( hSplitRendFileReadWrite != NULL ) && ( arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - if ( split_rend_write_bitstream_to_file( hSplitRendFileReadWrite, splitRendBits.bits_buf, &splitRendBits.bits_read, &splitRendBits.bits_written, - splitRendBits.codec, splitRendBits.pose_correction -#ifdef API_5MS - , - splitRendBits.codec_frame_size_ms -#endif - ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nUnable to write to bitstream file!\n" ); - goto cleanup; - } - } #endif if ( delayNumSamples < nOutSamples ) { @@ -2520,7 +2458,7 @@ static ivas_error decodeG192( /* Write ISm metadata to external file(s) */ if ( decodedGoodFrame && arg.outputConfig == AUDIO_CONFIG_EXTERNAL ) { - if ( bsFormat == IVAS_DEC_BS_OBJ ) + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) { @@ -2545,7 +2483,8 @@ static ivas_error decodeG192( } } } - else if ( bsFormat == IVAS_DEC_BS_MASA ) + + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) { MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) @@ -2583,6 +2522,7 @@ static ivas_error decodeG192( #ifdef WMOPS if ( vec_pos_update == 0 ) { + // update_mem(); TODO: verify this update_wmops(); } #ifdef MEM_COUNT_DETAILS @@ -2591,7 +2531,6 @@ static ivas_error decodeG192( #endif } - /*------------------------------------------------------------------------------------------* * Flush what is still left in the VoIP Buffers.... *------------------------------------------------------------------------------------------*/ @@ -2638,15 +2577,12 @@ static ivas_error decodeG192( if ( arg.enableHeadRotation ) { IVAS_QUATERNION Quaternion; - - if ( ( error = HeadRotationFileReading( headRotReader, &Quaternion, &Pos[0] ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( headRotReader ) ); goto cleanup; } - if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternion, Pos[0], 0 #ifdef SPLIT_REND_WITH_HEAD_ROT , @@ -2662,10 +2598,9 @@ static ivas_error decodeG192( /* decode and get samples */ if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, #if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT - IVAS_DEC_PCM_INT16, - (void *) + IVAS_DEC_PCM_INT16, (void *) #endif - pcmBuf, + pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -2682,7 +2617,7 @@ static ivas_error decodeG192( /* Write ISm metadata to external file(s) */ if ( decodedGoodFrame && arg.outputConfig == AUDIO_CONFIG_EXTERNAL ) { - if ( bsFormat == IVAS_DEC_BS_OBJ ) + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) { @@ -2707,7 +2642,8 @@ static ivas_error decodeG192( } } } - else if ( bsFormat == IVAS_DEC_BS_MASA ) + + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) { MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) @@ -2755,7 +2691,7 @@ static ivas_error decodeG192( /* Print output metadata file name(s) */ if ( arg.outputConfig == AUDIO_CONFIG_EXTERNAL ) { - if ( bsFormat == IVAS_DEC_BS_OBJ ) + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) { for ( i = 0; i < numObj; i++ ) { @@ -2763,7 +2699,8 @@ static ivas_error decodeG192( } fprintf( stdout, "\n" ); } - else if ( bsFormat == IVAS_DEC_BS_MASA ) + + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) { fprintf( stdout, "\nOutput metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); } @@ -2793,7 +2730,7 @@ static ivas_error decodeG192( cleanup: #ifdef SPLIT_REND_WITH_HEAD_ROT - split_rend_reader_writer_close( &hSplitRendFileReadWrite ); + split_rend_reader_writer_close( &splitRendWriter ); #endif AudioFileWriter_close( &afWriter ); MasaFileWriter_close( &masaWriter ); @@ -3654,7 +3591,7 @@ static ivas_error decodeVoIP( { #ifdef SPLIT_REND_WITH_HEAD_ROT - SplitFileReadWrite *hSplitRendFileReadWrite = NULL; + SplitFileReadWrite *splitRendWriter = NULL; #endif error = initOnFirstGoodFrame( hIvasDec, @@ -3677,7 +3614,7 @@ static ivas_error decodeVoIP( &numObj #ifdef SPLIT_REND_WITH_HEAD_ROT , - &hSplitRendFileReadWrite + &splitRendWriter #endif ); if ( error != IVAS_ERR_OK ) @@ -3718,7 +3655,7 @@ static ivas_error decodeVoIP( { int16_t i; - if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) { @@ -4100,7 +4037,7 @@ static ivas_error decodeVariableSpeed( if ( decodedGoodFrame ) { #ifdef SPLIT_REND_WITH_HEAD_ROT - SplitFileReadWrite *hSplitRendFileReadWrite = NULL; + SplitFileReadWrite *splitRendWriter = NULL; #endif error = initOnFirstGoodFrame( hIvasDec, @@ -4118,7 +4055,7 @@ static ivas_error decodeVariableSpeed( &numObj #ifdef SPLIT_REND_WITH_HEAD_ROT , - &hSplitRendFileReadWrite + &splitRendWriter #endif ); if ( error != IVAS_ERR_OK ) diff --git a/lib_com/options.h b/lib_com/options.h index be3261f808..aba784c745 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -150,7 +150,7 @@ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ -/*#define SPLIT_REND_WITH_HEAD_ROT*/ /* Dlb,FhG: Split Rendering contributions 21 and 35 */ +#define SPLIT_REND_WITH_HEAD_ROT /* Dlb,FhG: Split Rendering contributions 21 and 35 */ #ifdef SPLIT_REND_WITH_HEAD_ROT #define SPLIT_REND_PRED_QUANT_63_PNTS #define SPLIT_REND_WITH_HEAD_ROT_PARAMBIN /* Nokia: Issue 623: Split rendering support for parambin renderer */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index b0d224b9c4..89caf11d48 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -139,7 +139,7 @@ static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, float *pcmBuf static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const int16_t nSamplesForRendering, int16_t *nSamplesResidual, float *pcmBuf ); static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const uint16_t nSamplesForRendering, uint16_t *nSamplesRendered, uint16_t *nSamplesAvailableNext, #if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT - IVAS_DEC_PCM_TYPE pcmType, + const IVAS_DEC_PCM_TYPE pcmType, void *pcmBuf #else @@ -149,8 +149,8 @@ static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const u static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( IVAS_DEC_HANDLE hIvasDec, int16_t *nSamplesBuffered ); #if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT static PCM_RESOLUTION pcm_type_API_to_internal( const IVAS_DEC_PCM_TYPE pcmType ); -static void *pcm_buffer_offset( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, int32_t offset ); -static ivas_error set_pcm_buffer_to_zero( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, int16_t nZeroSamples ); +static void *pcm_buffer_offset( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, const int32_t offset ); +static ivas_error set_pcm_buffer_to_zero( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, const int16_t nZeroSamples ); #endif /*---------------------------------------------------------------------* * IVAS_DEC_Open() @@ -401,8 +401,8 @@ ivas_error IVAS_DEC_Configure( const uint32_t sampleRate, /* i : output sampling frequency */ const AUDIO_CONFIG outputConfig, /* i : output configuration */ #ifdef API_5MS - const int16_t tsmEnabled, /* i : enable TSM */ - const int16_t enable5ms, + const bool tsmEnabled, /* i : enable TSM */ + const bool enable5ms, /* i : enable 5ms rendering path */ #endif const int16_t customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ const int16_t hrtfReaderEnabled, /* i : enable HRTF binary file input */ @@ -459,6 +459,12 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config ); } +#ifdef API_5MS + hDecoderConfig->Opt_tsm = (int16_t) tsmEnabled; +#ifdef API_5MS_BASELINE + hDecoderConfig->Opt_5ms = (int16_t) enable5ms; +#endif +#endif hDecoderConfig->Opt_LsCustom = customLsOutputEnabled; hDecoderConfig->Opt_Headrotation = enableHeadRotation; hDecoderConfig->orientation_tracking = orientation_tracking; @@ -469,6 +475,14 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->Opt_delay_comp = delayCompensationEnabled; hDecoderConfig->Opt_ExternalOrientation = enableExternalOrientation; + +#ifdef SPLIT_REND_WITH_HEAD_ROT + if ( hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + { + hDecoderConfig->Opt_Headrotation = TRUE; + } +#endif + /* Set decoder parameters to initial values */ if ( ( error = ivas_init_decoder_front( st_ivas ) ) != IVAS_ERR_OK ) { @@ -481,10 +495,6 @@ ivas_error IVAS_DEC_Configure( } #ifdef API_5MS - hDecoderConfig->Opt_tsm = tsmEnabled; -#ifdef API_5MS_BASELINE - hDecoderConfig->Opt_5ms = enable5ms; -#endif hIvasDec->nSamplesFrame = (uint16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); hIvasDec->nSamplesAvailableNext = 0; hIvasDec->nSamplesRendered = 0; @@ -495,6 +505,7 @@ ivas_error IVAS_DEC_Configure( return error; } + #if defined( SPLIT_REND_WITH_HEAD_ROT ) && defined( API_5MS ) /*---------------------------------------------------------------------* * IVAS_DEC_EnableSplitRendering( ) @@ -524,13 +535,13 @@ ivas_error IVAS_DEC_EnableSplitRendering( hDecoderConfig->Opt_5ms = false; #endif - hDecoderConfig->Opt_Limiter = 0; return error; } #endif + #ifdef API_5MS /*---------------------------------------------------------------------* * IVAS_DEC_Get5msFlag( ) @@ -539,8 +550,8 @@ ivas_error IVAS_DEC_EnableSplitRendering( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_Get5msFlag( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - int16_t *enable5ms /* o : 5ms flag */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + int16_t *enable5ms /* o : 5ms flag */ ) { if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || enable5ms == NULL ) @@ -554,6 +565,7 @@ ivas_error IVAS_DEC_Get5msFlag( } #endif + /*---------------------------------------------------------------------* * IVAS_DEC_EnableVoIP( ) * @@ -877,7 +889,7 @@ ivas_error IVAS_DEC_GetSamples( #ifdef API_5MS ivas_error IVAS_DEC_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const int16_t nSamplesAsked, /* i: number of samples wanted by the caller */ + const int16_t nSamplesAsked, /* i : number of samples wanted by the caller */ #if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ void *pcmBuf, /* o : output synthesis signal */ @@ -885,7 +897,7 @@ ivas_error IVAS_DEC_GetSamples( int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ #endif int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ - bool *needNewFrame /* indication that the decoder needs a new frame */ + bool *needNewFrame /* o :indication that the decoder needs a new frame */ #if defined SPLIT_REND_WITH_HEAD_ROT && !defined API_5MS , IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits /* o : bitstream output for split rendering mode*/ @@ -1005,7 +1017,10 @@ ivas_error IVAS_DEC_GetSamples( nSamplesRendered += nSamplesRendered_loop; if ( nTransportChannels != hIvasDec->nTransportChannelsOld ) { - IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ); + if ( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ) != IVAS_ERR_OK ) + { + return error; + } } /* decode TCs only */ if ( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, &nOutSamplesElse ) ) != IVAS_ERR_OK ) @@ -1033,8 +1048,6 @@ ivas_error IVAS_DEC_GetSamples( nSamplesTcsScaled = nTimeScalerOutSamples / nTransportChannels; /* render IVAS frames */ - - if ( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK ) { return error; @@ -1050,6 +1063,7 @@ ivas_error IVAS_DEC_GetSamples( } hIvasDec->hasBeenFedFrame = false; } + /* render IVAS frames directly to the output buffer */ nSamplesToRender = nSamplesAsked - nSamplesRendered; if ( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, @@ -1086,13 +1100,20 @@ ivas_error IVAS_DEC_GetSamples( } #endif + #if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT +/*---------------------------------------------------------------------* + * IVAS_DEC_GetSplitBinauralBitstream( ) + * + * + *---------------------------------------------------------------------*/ + ivas_error IVAS_DEC_GetSplitBinauralBitstream( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - void *pcmBuf_out, /* o : output synthesis signal for BINAURAL_SPLIT_PCM */ - IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits, /* o : bitstream output for split rendering mode*/ - int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ - bool *needNewFrame /* indication that the decoder needs a new frame */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + void *pcmBuf_out, /* o : output synthesis signal for BINAURAL_SPLIT_PCM */ + IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits, /* o : bitstream output for split rendering mode */ + int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ + bool *needNewFrame /* o : indication that the decoder needs a new frame */ ) { Decoder_Struct *st_ivas; @@ -1157,14 +1178,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( if ( numSamplesPerChannelToDecode == numSamplesPerChannelToSplitEncode || hSplitBinRend->numTdSamplesPerChannelCached == 0 ) { /* Decode and render */ - error = IVAS_DEC_GetSamples( - hIvasDec, - numSamplesPerChannelToDecode, - IVAS_DEC_PCM_FLOAT, - pcmBuf, - nOutSamples, - needNewFrame ); - if ( error != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetSamples( hIvasDec, numSamplesPerChannelToDecode, IVAS_DEC_PCM_FLOAT, pcmBuf, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK ) { return error; } @@ -1218,22 +1232,12 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( pcm_out = ( output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0; td_input = st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC; - error = ivas_renderMultiBinToSplitBinaural( &hSplitBinRend->splitrend, - st_ivas->hHeadTrackData->Quaternions[0], - st_ivas->hRenderConfig->split_rend_config.splitRendBitRate, - st_ivas->hRenderConfig->split_rend_config.codec, + error = ivas_renderMultiBinToSplitBinaural( &hSplitBinRend->splitrend, st_ivas->hHeadTrackData->Quaternions[0], st_ivas->hRenderConfig->split_rend_config.splitRendBitRate, st_ivas->hRenderConfig->split_rend_config.codec, #ifdef API_5MS st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms, #endif - hSplitBinRend->hSplitRendBits, - hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural, - hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural, - max_band, - pOutput, - - 1, - td_input, - pcm_out ); + hSplitBinRend->hSplitRendBits, hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural, + hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural, max_band, pOutput, 1, td_input, pcm_out ); if ( error != IVAS_ERR_OK ) { return error; @@ -1245,25 +1249,19 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( if ( st_ivas->hDecoderConfig->Opt_5ms ) { #ifndef DISABLE_LIMITER - ivas_limiter_dec( st_ivas->hLimiter, pOutput, - st_ivas->hDecoderConfig->nchan_out, - numSamplesPerChannelToSplitEncode, st_ivas->BER_detect ); + ivas_limiter_dec( st_ivas->hLimiter, pOutput, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToSplitEncode, st_ivas->BER_detect ); #endif } else { - ivas_limiter_dec( st_ivas->hLimiter, pOutput, - st_ivas->hDecoderConfig->nchan_out, - numSamplesPerChannelToSplitEncode, st_ivas->BER_detect ); + ivas_limiter_dec( st_ivas->hLimiter, pOutput, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToSplitEncode, st_ivas->BER_detect ); } #ifdef DEBUGGING st_ivas->noClipping += #endif - ivas_syn_output( pOutput, numSamplesPerChannelToSplitEncode, - st_ivas->hDecoderConfig->nchan_out, - (int16_t *) pcmBuf_out ); + ivas_syn_output( pOutput, numSamplesPerChannelToSplitEncode, st_ivas->hDecoderConfig->nchan_out, (int16_t *) pcmBuf_out ); } free( st_ivas->hSplitBinRend.hMultiBinCldfbData ); @@ -1703,6 +1701,7 @@ ivas_error IVAS_DEC_FeedHeadTrackData( ) { HEAD_TRACK_DATA_HANDLE hHeadTrackData; + ivas_error error; #ifndef API_5MS int16_t i; #endif @@ -1731,7 +1730,11 @@ ivas_error IVAS_DEC_FeedHeadTrackData( Euler2Quat( deg2rad( orientation.x ), deg2rad( orientation.y ), deg2rad( orientation.z ), &orientation ); } - ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, orientation, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &hHeadTrackData->Quaternions[subframe_idx] ); + if ( ( error = ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, orientation, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &hHeadTrackData->Quaternions[subframe_idx] ) ) != IVAS_ERR_OK ) + { + return error; + } + hHeadTrackData->Pos[subframe_idx].x = Pos.x; hHeadTrackData->Pos[subframe_idx].y = Pos.y; hHeadTrackData->Pos[subframe_idx].z = Pos.z; @@ -1759,7 +1762,6 @@ ivas_error IVAS_DEC_FeedHeadTrackData( hIvasDec->st_ivas->hHeadTrackData->num_quaternions = 0; #endif #endif - #ifdef SPLIT_REND_WITH_HEAD_ROT hHeadTrackData->sr_pose_pred_axis = rot_axis; #endif @@ -2034,8 +2036,17 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( return IVAS_ERR_OK; } + #ifdef API_5MS -static ivas_error copyRendererConfigStruct( RENDER_CONFIG_HANDLE hRCin, IVAS_RENDER_CONFIG_HANDLE hRCout ) +/*---------------------------------------------------------------------* + * copyRendererConfigStruct( ) + * + * + *---------------------------------------------------------------------*/ + +static ivas_error copyRendererConfigStruct( + RENDER_CONFIG_HANDLE hRCin, + IVAS_RENDER_CONFIG_HANDLE hRCout ) { if ( hRCin == NULL || hRCout == NULL ) { @@ -2082,6 +2093,7 @@ static ivas_error copyRendererConfigStruct( RENDER_CONFIG_HANDLE hRCin, IVAS_REN } #endif + /*---------------------------------------------------------------------* * IVAS_DEC_GetRenderConfig( ) * @@ -2574,24 +2586,24 @@ ivas_error IVAS_DEC_VoIP_GetSamples( nSamplesBuffered = 0; if ( hIvasDec->hasBeenFedFirstGoodFrame ) { - IVAS_DEC_GetBufferedNumberOfSamples( hIvasDec, &nSamplesBuffered ); + if ( ( error = IVAS_DEC_GetBufferedNumberOfSamples( hIvasDec, &nSamplesBuffered ) ) != IVAS_ERR_OK ) + { + return error; + } } - extBufferedSamples = nSamplesRendered + nSamplesBuffered; + extBufferedSamples = nSamplesRendered + nSamplesBuffered; extBufferedTime_ms = extBufferedSamples * 1000 / hDecoderConfig->output_Fs; - dataUnit = NULL; - /* pop one access unit from the jitter buffer */ result = JB4_PopDataUnit( hVoIP->hJBM, systemTimestamp_ms, extBufferedTime_ms, &dataUnit, &scale, &maxScaling ); if ( result != 0 ) { return IVAS_ERR_UNKNOWN; } - - maxScaling = maxScaling * hDecoderConfig->output_Fs / 1000; + /* avoid time scaling multiple times in one sound card slot */ if ( scale != 100U ) { @@ -2615,7 +2627,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( scale = APA_MAX_SCALE; } - IVAS_DEC_VoIP_SetScale( hIvasDec, (int16_t) maxScaling, (int16_t) scale ); + if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, (int16_t) maxScaling, (int16_t) scale ) ) != IVAS_ERR_OK ) + { + return error; + } /* copy bitstream into decoder state */ if ( dataUnit ) @@ -2623,12 +2638,20 @@ ivas_error IVAS_DEC_VoIP_GetSamples( hIvasDec->hVoIP->hCurrentDataUnit = dataUnit; bsCompactToSerial( dataUnit->data, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize ); - IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 ); + + + if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } } else if ( hIvasDec->hasDecodedFirstGoodFrame ) { /* Decoder has been initialized with first good frame - do PLC */ - IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1 ); + if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } } #ifdef SUPPORT_JBM_TRACEFILE @@ -2654,15 +2677,18 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { hVoIP->lastDecodedWasActive = !dataUnit->silenceIndicator; } + /* data unit memory is no longer used */ JB4_FreeDataUnit( hVoIP->hJBM, dataUnit ); } + if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; hIvasDec->nSamplesRendered = 0; } } + /* decode */ if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { @@ -2687,8 +2713,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( /* render IVAS frames directly to the output buffer */ if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, #if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT - pcmType, - pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), + pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), #else pcmBuf + nSamplesRendered * nOutChannels, #endif @@ -4063,6 +4088,7 @@ static JBM_RENDERER_TYPE IVAS_DEC_VoIP_GetRendererConfig( * * *---------------------------------------------------------------------*/ + static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const uint16_t nTransportChannels, @@ -4363,8 +4389,18 @@ ivas_error IVAS_DEC_GetCldfbSamples( } #endif + #if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT -void *pcm_buffer_offset( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, int32_t offset ) +/*---------------------------------------------------------------------* + * pcm_buffer_offset() + * + * + *---------------------------------------------------------------------*/ + +static void *pcm_buffer_offset( + void *buffer, + const IVAS_DEC_PCM_TYPE pcmType, + const int32_t offset ) { switch ( pcmType ) { @@ -4385,7 +4421,17 @@ void *pcm_buffer_offset( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, int32_t } } -ivas_error set_pcm_buffer_to_zero( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, int16_t nZeroSamples ) + +/*---------------------------------------------------------------------* + * set_pcm_buffer_to_zero() + * + * + *---------------------------------------------------------------------*/ + +static ivas_error set_pcm_buffer_to_zero( + void *buffer, + const IVAS_DEC_PCM_TYPE pcmType, + const int16_t nZeroSamples ) { ivas_error error; error = IVAS_ERR_OK; @@ -4401,13 +4447,23 @@ ivas_error set_pcm_buffer_to_zero( void *buffer, const IVAS_DEC_PCM_TYPE pcmType default: error = IVAS_ERR_INTERNAL; } + return error; } -PCM_RESOLUTION pcm_type_API_to_internal( const IVAS_DEC_PCM_TYPE pcmType ) + +/*---------------------------------------------------------------------* + * pcm_type_API_to_internal() + * + * + *---------------------------------------------------------------------*/ + +PCM_RESOLUTION pcm_type_API_to_internal( + const IVAS_DEC_PCM_TYPE pcmType ) { PCM_RESOLUTION pcm_resolution; pcm_resolution = PCM_NOT_KNOW; + switch ( pcmType ) { case IVAS_DEC_PCM_FLOAT: @@ -4419,6 +4475,7 @@ PCM_RESOLUTION pcm_type_API_to_internal( const IVAS_DEC_PCM_TYPE pcmType ) default: pcm_resolution = PCM_NOT_KNOW; } + return pcm_resolution; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index fa76331d7d..02c2ff50c8 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -134,8 +134,8 @@ ivas_error IVAS_DEC_Configure( const uint32_t sampleRate, /* i : output sampling frequency */ const AUDIO_CONFIG outputConfig, /* i : audio configuration */ #ifdef API_5MS - const int16_t tsmEnabled, /* i : enable TSM */ - const int16_t enable5ms, /* i : enable 5ms rendering path */ + const bool tsmEnabled, /* i : enable TSM */ + const bool enable5ms, /* i : enable 5ms rendering path */ #endif const int16_t customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ const int16_t hrtfReaderEnabled, /* i : enable HRTF binary file input */ @@ -166,16 +166,16 @@ ivas_error IVAS_DEC_FeedFrame_Serial( /*! r: decoder error code */ ivas_error IVAS_DEC_GetSamples( #ifdef API_5MS - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const int16_t nSamplesAsked, /* i: number of samples wanted by the caller */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const int16_t nSamplesAsked, /* i : number of samples wanted by the caller */ #if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT - const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ - void *pcmBuf, /* o : output synthesis signal */ + const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ + void *pcmBuf, /* o : output synthesis signal */ #else - int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ #endif - int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ - bool *needNewFrame /* indication that the decoder needs a new frame */ + int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ + bool *needNewFrame /* o : indication that the decoder needs a new frame */ #else IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ @@ -189,11 +189,11 @@ ivas_error IVAS_DEC_GetSamples( #if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT ivas_error IVAS_DEC_GetSplitBinauralBitstream( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - void *pcmBuf_out, /* o : output synthesis signal for BINAURAL_SPLIT_PCM */ - IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits, /* o : bitstream output for split rendering mode */ - int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ - bool *needNewFrame /* indication that the decoder needs a new frame */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + void *pcmBuf_out, /* o : output synthesis signal for BINAURAL_SPLIT_PCM */ + IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits, /* o : bitstream output for split rendering mode */ + int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ + bool *needNewFrame /* o :indication that the decoder needs a new frame */ ); #endif @@ -233,12 +233,12 @@ ivas_error IVAS_DEC_GetMasaMetadata( ivas_error IVAS_DEC_FeedHeadTrackData( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ #ifdef API_5MS - IVAS_QUATERNION orientation, /* i : head-tracking data, listener orientation */ - IVAS_VECTOR3 Pos, /* i : listener position */ - const int16_t subframe_idx /*subframe index*/ + IVAS_QUATERNION orientation, /* i : head-tracking data, listener orientation */ + IVAS_VECTOR3 Pos, /* i : listener position */ + const int16_t subframe_idx /* o : subframe index */ #else - IVAS_QUATERNION *orientation, /* i : head-tracking data, listener orientation */ - IVAS_VECTOR3 *Pos /* i : listener position */ + IVAS_QUATERNION *orientation, /* i : head-tracking data, listener orientation */ + IVAS_VECTOR3 *Pos /* i : listener position */ #endif #ifdef SPLIT_REND_WITH_HEAD_ROT , @@ -262,18 +262,18 @@ ivas_error IVAS_DEC_FeedRefVectorData( ivas_error IVAS_DEC_FeedExternalOrientationData( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ #ifdef API_5MS - IVAS_QUATERNION orientation, /* i : external orientation data */ - int8_t enableHeadRotation, /* i : flag to enable head rotation for this frame */ - int8_t enableExternalOrientation, /* i : flag to enable external orientation for this frame */ - int8_t enableRotationInterpolation, /* i : flag to interpolate rotations from current and previous frames */ - int16_t numFramesToTargetOrientation, /* i : number of frames until target orientation is reached */ - const int16_t subframe_idx /*i : subframe index*/ + IVAS_QUATERNION orientation, /* i : external orientation data */ + int8_t enableHeadRotation, /* i : flag to enable head rotation for this frame */ + int8_t enableExternalOrientation, /* i : flag to enable external orientation for this frame */ + int8_t enableRotationInterpolation, /* i : flag to interpolate rotations from current and previous frames */ + int16_t numFramesToTargetOrientation, /* i : number of frames until target orientation is reached */ + const int16_t subframe_idx /* i : subframe index */ #else - IVAS_QUATERNION *orientation, /* i : external orientation data */ - int8_t *enableHeadRotation, /* i : flag to enable head rotation for this frame */ - int8_t *enableExternalOrientation, /* i : flag to enable external orientation for this frame */ - int8_t *enableRotationInterpolation, /* i : flag to interpolate rotations from current and previous frames */ - int16_t *numFramesToTargetOrientation /* i : number of frames until target orientation is reached */ + IVAS_QUATERNION *orientation, /* i : external orientation data */ + int8_t *enableHeadRotation, /* i : flag to enable head rotation for this frame */ + int8_t *enableExternalOrientation, /* i : flag to enable external orientation for this frame */ + int8_t *enableRotationInterpolation, /* i : flag to interpolate rotations from current and previous frames */ + int16_t *numFramesToTargetOrientation /* i : number of frames until target orientation is reached */ #endif ); @@ -314,7 +314,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_PCM_TYPE pcmType, void *pcmBuf, #else - int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ #endif const uint32_t systemTimestamp_ms /* i : current system timestamp */ #ifndef API_5MS @@ -334,10 +334,10 @@ ivas_error IVAS_DEC_Flush( const IVAS_DEC_PCM_TYPE pcmType, void *pcmBuf, #else - int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ #endif #ifndef API_5MS - uint16_t *nSamplesAvailableNext, /* o : number of samples still available */ + uint16_t *nSamplesAvailableNext, /* o : number of samples still available */ #endif int16_t *nSamplesFlushed /* o : number of samples flushed */ ); @@ -362,14 +362,14 @@ ivas_error IVAS_DEC_EnableVoIP( /*! r: error code */ ivas_error IVAS_DEC_EnableSplitRendering( - IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ + IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ ); #endif + ivas_error IVAS_DEC_Get5msFlag( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - int16_t *enable5ms /* o : 5ms flag */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + int16_t *enable5ms /* o : 5ms flag */ ); - #endif #ifdef DEBUGGING @@ -459,7 +459,7 @@ ivas_error IVAS_DEC_GetRenderConfig( #ifdef API_5MS /*! r: error code*/ ivas_error IVAS_DEC_GetDefaultRenderConfig( - IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render config handle */ + IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render config handle */ ); #endif -- GitLab From 53ab50dfab710ab4ebacd9f876bda227fa12065b Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 27 Aug 2023 21:19:25 +0200 Subject: [PATCH 2/9] allocate IVAS_SPLIT_REND_BITS_DATA as part of st_ivas --- apps/decoder.c | 43 ++++++++++---------------------- lib_dec/lib_dec.c | 26 ++++++++++--------- lib_dec/lib_dec.h | 2 +- lib_rend/ivas_prot_rend.h | 13 +++++----- lib_rend/ivas_splitRendererPre.c | 42 ++++++++++++++++--------------- 5 files changed, 56 insertions(+), 70 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index c112fac320..fe8e1f9ddc 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1983,11 +1983,13 @@ static ivas_error initOnFirstGoodFrame( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * decodeG192() * * Read G.192 bitstream and decode in regular decoder *---------------------------------------------------------------------*/ + #ifdef API_5MS static ivas_error decodeG192( DecArguments arg, @@ -2038,10 +2040,8 @@ static ivas_error decodeG192( IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; int16_t vec_pos_update, vec_pos_len; - #ifdef SPLIT_REND_WITH_HEAD_ROT - IVAS_SPLIT_REND_BITS_DATA splitRendBits; - SplitFileReadWrite *splitRendWriter; + SplitFileReadWrite *splitRendWriter = NULL; #endif for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) @@ -2110,17 +2110,6 @@ static ivas_error decodeG192( vec_pos_len = 1; } -#ifdef SPLIT_REND_WITH_HEAD_ROT - splitRendBits.bits_buf = splitRendBitsBuf; - splitRendBits.bits_read = 0; - splitRendBits.bits_written = 0; - splitRendBits.buf_len = IVAS_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES; - splitRendBits.codec = IVAS_SPLIT_REND_CODEC_DEFAULT; - splitRendBits.pose_correction = IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE; - splitRendBits.codec_frame_size_ms = 0; - splitRendWriter = NULL; -#endif - /*------------------------------------------------------------------------------------------* * Loop for every packet (frame) of bitstream data * - Read the bitstream packet @@ -2204,8 +2193,7 @@ static ivas_error decodeG192( { if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), - RotationFileReader_getFilePath( headRotReader ) ); + fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( headRotReader ) ); goto cleanup; } } @@ -2333,32 +2321,29 @@ static ivas_error decodeG192( #ifdef SPLIT_REND_WITH_HEAD_ROT if ( arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { - error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), - &splitRendBits, &nSamplesRendered_loop, &needNewFrame ); - nSamplesRendered += nSamplesRendered_loop; - nSamplesToRender -= nSamplesRendered_loop; - if ( error != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), splitRendBitsBuf, &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_GetSplitBinauralBitstream: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } + nSamplesRendered += nSamplesRendered_loop; + nSamplesToRender -= nSamplesRendered_loop; } else { #endif - error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, + if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, #if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT - IVAS_DEC_PCM_INT16, (void *) + IVAS_DEC_PCM_INT16, (void *) #endif - ( pcmBuf + nOutChannels * nSamplesRendered ), - &nSamplesRendered_loop, &needNewFrame ); - nSamplesRendered += nSamplesRendered_loop; - nSamplesToRender -= nSamplesRendered_loop; - if ( error != IVAS_ERR_OK ) + ( pcmBuf + nOutChannels * nSamplesRendered ), + &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } + nSamplesRendered += nSamplesRendered_loop; + nSamplesToRender -= nSamplesRendered_loop; #ifdef SPLIT_REND_WITH_HEAD_ROT } #endif @@ -2412,7 +2397,6 @@ static ivas_error decodeG192( #ifdef SPLIT_REND_WITH_HEAD_ROT if ( arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { -#if 0 IVAS_SPLIT_REND_BITS_DATA splitRendBits; if ( ( error = IVAS_DEC_GetSplitRendBits( hIvasDec, &splitRendBits ) ) != IVAS_ERR_OK ) @@ -2420,7 +2404,6 @@ static ivas_error decodeG192( fprintf( stderr, "\nError in IVAS_DEC_SplitRendBits: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } -#endif if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits.bits_buf, &splitRendBits.bits_read, &splitRendBits.bits_written, splitRendBits.codec, splitRendBits.pose_correction #ifdef API_5MS diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 89caf11d48..512aa388ea 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1109,11 +1109,11 @@ ivas_error IVAS_DEC_GetSamples( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetSplitBinauralBitstream( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - void *pcmBuf_out, /* o : output synthesis signal for BINAURAL_SPLIT_PCM */ - IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits, /* o : bitstream output for split rendering mode */ - int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ - bool *needNewFrame /* o : indication that the decoder needs a new frame */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + void *pcmBuf_out, /* o : output synthesis signal for BINAURAL_SPLIT_PCM */ + uint8_t *splitRendBitsBuf, /* o : output split rendering bits */ + int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ + bool *needNewFrame /* o : indication that the decoder needs a new frame */ ) { Decoder_Struct *st_ivas; @@ -1141,9 +1141,12 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( output_Fs = st_ivas->hDecoderConfig->output_Fs; numSamplesPerChannelToDecode = (int16_t) ( output_Fs / FRAMES_PER_SEC ); - *needNewFrame = FALSE; + *needNewFrame = false; hSplitBinRend = &st_ivas->hSplitBinRend; - ivas_set_split_rend_setup( hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, hSplitRendBits ); + if ( ( error = ivas_set_split_rend_setup( hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBitsBuf ) ) != IVAS_ERR_OK ) + { + return error; + } numPoses = hSplitBinRend->splitrend.multiBinPoseData.num_poses; if ( st_ivas->hDecoderConfig->Opt_5ms && @@ -1232,13 +1235,11 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( pcm_out = ( output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0; td_input = st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC; - error = ivas_renderMultiBinToSplitBinaural( &hSplitBinRend->splitrend, st_ivas->hHeadTrackData->Quaternions[0], st_ivas->hRenderConfig->split_rend_config.splitRendBitRate, st_ivas->hRenderConfig->split_rend_config.codec, + if ( ( error = ivas_renderMultiBinToSplitBinaural( &hSplitBinRend->splitrend, st_ivas->hHeadTrackData->Quaternions[0], st_ivas->hRenderConfig->split_rend_config.splitRendBitRate, st_ivas->hRenderConfig->split_rend_config.codec, #ifdef API_5MS - st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms, + st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms, #endif - hSplitBinRend->hSplitRendBits, hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural, - hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural, max_band, pOutput, 1, td_input, pcm_out ); - if ( error != IVAS_ERR_OK ) + hSplitBinRend->hSplitRendBits, hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural, hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural, max_band, pOutput, 1, td_input, pcm_out ) ) != IVAS_ERR_OK ) { return error; } @@ -4322,6 +4323,7 @@ ivas_error IVAS_DEC_GetSplitRendBits( splitRendBits->buf_len = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->buf_len; splitRendBits->codec = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->codec; splitRendBits->pose_correction = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->pose_correction; + splitRendBits->codec_frame_size_ms = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->codec_frame_size_ms; return IVAS_ERR_OK; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 02c2ff50c8..53d78ee03a 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -191,7 +191,7 @@ ivas_error IVAS_DEC_GetSamples( ivas_error IVAS_DEC_GetSplitBinauralBitstream( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ void *pcmBuf_out, /* o : output synthesis signal for BINAURAL_SPLIT_PCM */ - IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits, /* o : bitstream output for split rendering mode */ + uint8_t *splitRendBitsBuf, /* o : output split rendering bits */ int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ bool *needNewFrame /* o :indication that the decoder needs a new frame */ ); diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 578bac9dee..5f689191af 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1377,8 +1377,10 @@ ivas_error ivas_orient_trk_Process( #ifdef API_5MS void ivas_set_split_rend_ht_setup( IVAS_DEC_SPLIT_REND_WRAPPER *hSplitBinRend, - COMBINED_ORIENTATION_HANDLE hCombinedOrientationData ); + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData +); #endif + /*----------------------------------------------------------------------------------* * Split binaural renderer prototypes *----------------------------------------------------------------------------------*/ @@ -1387,11 +1389,7 @@ ivas_error ivas_set_split_rend_setup( IVAS_DEC_SPLIT_REND_WRAPPER *hSplitBinRend, IVAS_SPLIT_REND_CONFIG_DATA *hSplitBinConfig, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ -#ifdef API_5MS - IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits -#else uint8_t *splitRendBitsBuf -#endif ); void ivas_init_split_rend_handles( @@ -1404,7 +1402,7 @@ void ivas_init_split_post_rend_handles( ivas_error ivas_split_renderer_open( SPLIT_REND_WRAPPER *hSplitBinRend, - const IVAS_SPLIT_REND_CONFIG_DATA *pSplitRendConfig, + const IVAS_SPLIT_REND_CONFIG_DATA *pSplitRendConfig, const int32_t output_Fs, const int16_t is_cldfb_in, const int16_t is_pcm_out @@ -1422,7 +1420,8 @@ ivas_error ivas_splitBinLCLDEncOpen( BIN_HR_SPLIT_LCLD_ENC_HANDLE *hSplitBinLCLDEnc, const int32_t iSampleRate, const int16_t iChannels, - const int32_t iDataRate ); + const int32_t iDataRate +); void ivas_splitBinLCLDEncClose( BIN_HR_SPLIT_LCLD_ENC_HANDLE *hSplitBinLCLDEnc diff --git a/lib_rend/ivas_splitRendererPre.c b/lib_rend/ivas_splitRendererPre.c index 67c02ae608..e925ae29ba 100644 --- a/lib_rend/ivas_splitRendererPre.c +++ b/lib_rend/ivas_splitRendererPre.c @@ -1822,6 +1822,8 @@ void ivas_set_split_rend_ht_setup( return; } #endif + + /*-------------------------------------------------------------------------* * ivas_set_split_rend_setup() * @@ -1832,21 +1834,27 @@ ivas_error ivas_set_split_rend_setup( IVAS_DEC_SPLIT_REND_WRAPPER *hSplitBinRend, IVAS_SPLIT_REND_CONFIG_DATA *hSplitBinConfig, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, -#ifdef API_5MS - IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits -#else - uint8_t *splitRendBitsBuf -#endif -) + uint8_t *splitRendBitsBuf ) { int16_t sf, i, j; -#ifndef API_5MS + +#ifdef API_5MS +#ifdef SPLIT_REND_WITH_HEAD_ROT + if ( ( hSplitBinRend->hSplitRendBits = (IVAS_SPLIT_REND_BITS_HANDLE) malloc( sizeof( IVAS_SPLIT_REND_BITS_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for split renderer Bits buffer\n" ) ); + } +#endif + hSplitBinRend->hSplitRendBits->bits_buf = splitRendBitsBuf; - hSplitBinRend->hSplitRendBits->bits_written = 0; hSplitBinRend->hSplitRendBits->bits_read = 0; -#else - hSplitBinRend->hSplitRendBits = hSplitRendBits; + hSplitBinRend->hSplitRendBits->bits_written = 0; + hSplitBinRend->hSplitRendBits->buf_len = IVAS_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES; + hSplitBinRend->hSplitRendBits->codec = IVAS_SPLIT_REND_CODEC_DEFAULT; + hSplitBinRend->hSplitRendBits->pose_correction = IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE; + hSplitBinRend->hSplitRendBits->codec_frame_size_ms = 0; #endif + if ( ( hSplitBinRend->hMultiBinCldfbData = (IVAS_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE) malloc( sizeof( IVAS_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" ); @@ -2609,19 +2617,13 @@ ivas_error ivas_renderMultiBinToSplitBinaural( target_md_bits = ivas_get_split_rend_md_target_brate( SplitRendBitRate, pcm_out ) * L_FRAME48k / 48000; actual_md_bits = pBits->bits_written; - ivas_rend_CldfbSplitPreRendProcess( - hSplitBin->hBinHrSplitPreRend, + ivas_rend_CldfbSplitPreRendProcess( hSplitBin->hBinHrSplitPreRend, #ifdef API_5MS - headPosition, + headPosition, #else - headPositions, + headPositions, #endif - &hSplitBin->multiBinPoseData, - Cldfb_In_BinReal, - Cldfb_In_BinImag, - pBits, - target_md_bits, - low_res_pre_rend_rot ); + &hSplitBin->multiBinPoseData, Cldfb_In_BinReal, Cldfb_In_BinImag, pBits, target_md_bits, low_res_pre_rend_rot ); } if ( pcm_out == 0 ) -- GitLab From 1c43b769383959186260500a78a46e48720f5acc Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 27 Aug 2023 21:21:43 +0200 Subject: [PATCH 3/9] disable SPLIT_REND_WITH_HEAD_ROT --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index aba784c745..be3261f808 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -150,7 +150,7 @@ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ -#define SPLIT_REND_WITH_HEAD_ROT /* Dlb,FhG: Split Rendering contributions 21 and 35 */ +/*#define SPLIT_REND_WITH_HEAD_ROT*/ /* Dlb,FhG: Split Rendering contributions 21 and 35 */ #ifdef SPLIT_REND_WITH_HEAD_ROT #define SPLIT_REND_PRED_QUANT_63_PNTS #define SPLIT_REND_WITH_HEAD_ROT_PARAMBIN /* Nokia: Issue 623: Split rendering support for parambin renderer */ -- GitLab From fdf15d90ec215ae001989a8a016694f26d0ba405 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 27 Aug 2023 21:32:01 +0200 Subject: [PATCH 4/9] fix EXT output --- apps/decoder.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index fe8e1f9ddc..483922ba37 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2467,7 +2467,7 @@ static ivas_error decodeG192( } } - if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) { MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) @@ -2626,7 +2626,7 @@ static ivas_error decodeG192( } } - if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) { MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) @@ -2683,7 +2683,7 @@ static ivas_error decodeG192( fprintf( stdout, "\n" ); } - if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) { fprintf( stdout, "\nOutput metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); } -- GitLab From c503c914017adbe541c292bb5ae8ee3d5b844dd8 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 29 Aug 2023 08:49:30 +0200 Subject: [PATCH 5/9] revert unnecessary changes --- apps/decoder.c | 2 +- lib_dec/lib_dec.c | 8 ++++---- lib_dec/lib_dec.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 483922ba37..f6ac50e752 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2095,7 +2095,7 @@ static ivas_error decodeG192( nSamplesAvailableNext = 0; vec_pos_update = 0; - if ( ( arg.enableHeadRotation || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + if ( arg.enableHeadRotation #ifdef API_5MS_BASELINE && arg.enable5ms #endif diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 512aa388ea..5f4dd2cfd1 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -401,8 +401,8 @@ ivas_error IVAS_DEC_Configure( const uint32_t sampleRate, /* i : output sampling frequency */ const AUDIO_CONFIG outputConfig, /* i : output configuration */ #ifdef API_5MS - const bool tsmEnabled, /* i : enable TSM */ - const bool enable5ms, /* i : enable 5ms rendering path */ + const int16_t tsmEnabled, /* i : enable TSM */ + const int16_t enable5ms, /* i : enable 5ms rendering path */ #endif const int16_t customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ const int16_t hrtfReaderEnabled, /* i : enable HRTF binary file input */ @@ -460,9 +460,9 @@ ivas_error IVAS_DEC_Configure( } #ifdef API_5MS - hDecoderConfig->Opt_tsm = (int16_t) tsmEnabled; + hDecoderConfig->Opt_tsm = tsmEnabled; #ifdef API_5MS_BASELINE - hDecoderConfig->Opt_5ms = (int16_t) enable5ms; + hDecoderConfig->Opt_5ms = enable5ms; #endif #endif hDecoderConfig->Opt_LsCustom = customLsOutputEnabled; diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 53d78ee03a..07639a3fde 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -134,8 +134,8 @@ ivas_error IVAS_DEC_Configure( const uint32_t sampleRate, /* i : output sampling frequency */ const AUDIO_CONFIG outputConfig, /* i : audio configuration */ #ifdef API_5MS - const bool tsmEnabled, /* i : enable TSM */ - const bool enable5ms, /* i : enable 5ms rendering path */ + const int16_t tsmEnabled, /* i : enable TSM */ + const int16_t enable5ms, /* i : enable 5ms rendering path */ #endif const int16_t customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ const int16_t hrtfReaderEnabled, /* i : enable HRTF binary file input */ -- GitLab From bae3ae779717cd0e40bebe87e2604354bfe1a4cc Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 29 Aug 2023 09:07:03 +0200 Subject: [PATCH 6/9] add IVAS_DEC_Set5msFlag() --- apps/decoder.c | 5 +++++ lib_dec/lib_dec.c | 22 ++++++++++++++++++++++ lib_dec/lib_dec.h | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/apps/decoder.c b/apps/decoder.c index f6ac50e752..d4b8523363 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -659,6 +659,11 @@ int main( { arg.enable5ms = false; } + + if ( ( error = IVAS_DEC_Set5msFlag( hIvasDec, arg.enable5ms ) ) != IVAS_ERR_OK ) + { + return error; + } #endif #endif diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 5f4dd2cfd1..4dc122edcb 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -543,6 +543,28 @@ ivas_error IVAS_DEC_EnableSplitRendering( #ifdef API_5MS +/*---------------------------------------------------------------------* + * IVAS_DEC_Set5msFlag( ) + * + * Get the 5ms flag + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_Set5msFlag( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const int16_t enable5ms /* i : 5ms flag */ +) +{ + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hDecoderConfig == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + hIvasDec->st_ivas->hDecoderConfig->Opt_5ms = enable5ms; + + return IVAS_ERR_OK; +} + + /*---------------------------------------------------------------------* * IVAS_DEC_Get5msFlag( ) * diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 07639a3fde..8bf6ebe947 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -366,6 +366,11 @@ ivas_error IVAS_DEC_EnableSplitRendering( ); #endif +ivas_error IVAS_DEC_Set5msFlag( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const int16_t enable5ms /* i : 5ms flag */ +); + ivas_error IVAS_DEC_Get5msFlag( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ int16_t *enable5ms /* o : 5ms flag */ -- GitLab From 1d1fe057d209adbc8906329211e7f884617f7ea7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 13 Sep 2023 17:05:32 +0200 Subject: [PATCH 7/9] Add MD output file names printout for JBM --- apps/decoder.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index ec7e1a9c68..8542a0c02a 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2694,14 +2694,14 @@ static ivas_error decodeG192( { for ( i = 0; i < numObj; i++ ) { - fprintf( stdout, "\nOutput metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); + fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); } fprintf( stdout, "\n" ); } if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) { - fprintf( stdout, "\nOutput metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); + fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); } } @@ -2906,7 +2906,7 @@ static ivas_error decodeVoIP( int16_t delayNumSamples_orig[3]; /* stores: overall delay, dec+rend delay, and binauralization delay */ int16_t delayNumSamples = -1; int32_t delayTimeScale = -1; - + int16_t i; FILE *f_rtpstream = NULL; EVS_RTPDUMP_DEPACKER rtpdumpDepacker; EVS_RTPDUMP_DEPACKER_ERROR rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_NO_ERROR; @@ -2918,7 +2918,7 @@ static ivas_error decodeVoIP( IVAS_DEC_BS_FORMAT bsFormat = IVAS_DEC_BS_UNKOWN; IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; - for ( int16_t i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) + for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) { ismWriters[i] = NULL; } @@ -3197,8 +3197,6 @@ static ivas_error decodeVoIP( /* Write ISM metadata to external file(s) */ if ( decodedGoodFrame && arg.outputConfig == AUDIO_CONFIG_EXTERNAL ) { - int16_t i; - if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) @@ -3283,6 +3281,24 @@ static ivas_error decodeVoIP( } } + /* Print output metadata file name(s) */ + if ( arg.outputConfig == AUDIO_CONFIG_EXTERNAL ) + { + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) + { + for ( i = 0; i < numObj; i++ ) + { + fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); + } + fprintf( stdout, "\n" ); + } + + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) + { + fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); + } + } + /*------------------------------------------------------------------------------------------* * Close files and deallocate resources *------------------------------------------------------------------------------------------*/ @@ -3298,7 +3314,7 @@ cleanup: JbmTraceFileWriter_close( &jbmTraceWriter ); #endif MasaFileWriter_close( &masaWriter ); - for ( int16_t i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) + for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) { IsmFileWriter_close( &ismWriters[i] ); } -- GitLab From 2ee4ffe574a9f24bc53cb8418ce0c6e14556cbbb Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 13 Sep 2023 17:46:08 +0200 Subject: [PATCH 8/9] fix merge issue --- apps/decoder.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 8542a0c02a..8779df5ffc 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -434,24 +434,6 @@ int main( * Configure the decoder *------------------------------------------------------------------------------------------*/ -#ifdef SPLIT_REND_WITH_HEAD_ROT - if ( arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) - { - arg.enableHeadRotation = true; - if ( arg.enable5ms && - ( renderConfigSplit.split_rend_config.poseCorrectionMode == IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE || - renderConfigSplit.split_rend_config.dof == 0 ) ) - { - /*TODO : needs to be refined as this wont work with LCLD codec*/ - arg.enable5ms = true; - } - else - { - arg.enable5ms = false; - } - } -#endif - if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.tsmEnabled, arg.enable5ms, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.Opt_non_diegetic_pan, arg.non_diegetic_pan_gain, #ifdef FIX_708_DPID_COMMAND_LINE -- GitLab From e9f150f4ee2cc6b174964bb54c9fbae2cbdf24a8 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 18 Sep 2023 12:46:41 +0200 Subject: [PATCH 9/9] alignment of print-out --- apps/decoder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index dbe34539d7..de8e7eb991 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2676,7 +2676,7 @@ static ivas_error decodeG192( { for ( i = 0; i < numObj; i++ ) { - fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); + fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); } fprintf( stdout, "\n" ); } @@ -3270,7 +3270,7 @@ static ivas_error decodeVoIP( { for ( i = 0; i < numObj; i++ ) { - fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); + fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); } fprintf( stdout, "\n" ); } -- GitLab