From 64a13900789645141c4de6226702f0cd88f313b9 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 31 Jan 2024 08:56:00 +0530 Subject: [PATCH] Added basop changes for few of the lib_rend functions Changes will not affect any outputs. --- lib_rend/ivas_limiter.c | 25 ++++- lib_rend/ivas_stat_rend.h | 2 +- lib_rend/lib_rend.c | 187 ++++++++++++++++++++++++++++++++------ 3 files changed, 183 insertions(+), 31 deletions(-) diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index 269311ffd..3cc50fffa 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -280,7 +280,30 @@ ivas_error ivas_limiter_open( return IVAS_ERR_OK; } #endif +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * ivas_limiter_close() + * + * Deallocate limiter struct + *-------------------------------------------------------------------*/ +void ivas_limiter_close( + IVAS_LIMITER_HANDLE *phLimiter /* i/o: pointer to limiter handle, can be NULL */ +) +{ + IF ( phLimiter == NULL || *phLimiter == NULL ) + { + return; + } + + free( ( *phLimiter )->channel_ptrs ); + free( ( *phLimiter )->channel_ptrs_fx ); + free( *phLimiter ); + *phLimiter = NULL; + + return; +} +#else /*-------------------------------------------------------------------* * ivas_limiter_close() * @@ -302,7 +325,7 @@ void ivas_limiter_close( return; } - +#endif /*-------------------------------------------------------------------* * ivas_limiter_dec() diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index b8c5ee81e..de84dd633 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -770,7 +770,7 @@ typedef struct IVAS_QUATERNION headPositions[MAX_PARAM_SPATIAL_SUBFRAMES]; IVAS_VECTOR3 Pos[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifdef IVAS_FLOAT_FIXED - Word16 crossfade_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 crossfade_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; #endif float crossfade[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; ivas_orient_trk_state_t *hOrientationTracker; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 4ab880f61..5379d6449 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -561,7 +561,42 @@ static int32_t limitRendererOutput( return numClipping; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * validateOutputAudioConfig() + * + * + *-------------------------------------------------------------------*/ +static ivas_error validateOutputAudioConfig( + const AUDIO_CONFIG outConfig ) +{ + SWITCH( outConfig ) + { + case IVAS_AUDIO_CONFIG_MONO: + case IVAS_AUDIO_CONFIG_STEREO: + case IVAS_AUDIO_CONFIG_5_1: + case IVAS_AUDIO_CONFIG_7_1: + case IVAS_AUDIO_CONFIG_5_1_2: + case IVAS_AUDIO_CONFIG_5_1_4: + case IVAS_AUDIO_CONFIG_7_1_4: + case IVAS_AUDIO_CONFIG_LS_CUSTOM: + case IVAS_AUDIO_CONFIG_FOA: + case IVAS_AUDIO_CONFIG_HOA2: + case IVAS_AUDIO_CONFIG_HOA3: + case IVAS_AUDIO_CONFIG_BINAURAL: + case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR: + case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB: + case IVAS_AUDIO_CONFIG_MASA1: + case IVAS_AUDIO_CONFIG_MASA2: + return IVAS_ERR_OK; + default: + BREAK; + } + + return IVAS_ERR_INVALID_OUTPUT_FORMAT; +} +#else /*-------------------------------------------------------------------* * validateOutputAudioConfig() * @@ -596,7 +631,7 @@ static ivas_error validateOutputAudioConfig( return IVAS_ERR_INVALID_OUTPUT_FORMAT; } - +#endif /*-------------------------------------------------------------------* * getAudioConfigType() @@ -610,7 +645,7 @@ IVAS_REND_AudioConfigType getAudioConfigType( { IVAS_REND_AudioConfigType type; - SWITCH ( config ) + SWITCH( config ) { case IVAS_AUDIO_CONFIG_MONO: case IVAS_AUDIO_CONFIG_STEREO: @@ -698,7 +733,36 @@ IVAS_REND_AudioConfigType getAudioConfigType( } #endif +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * validateOutputSampleRate() + * + * + *-------------------------------------------------------------------*/ + +static ivas_error validateOutputSampleRate( + const Word32 sampleRate, + const AUDIO_CONFIG outConfig ) +{ + IF( getAudioConfigType( outConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) + { + /* If no binaural rendering, any sampling rate is supported */ + return IVAS_ERR_OK; + } + /* Otherwise rendering to binaural, support the same set as IVAS decoder */ + SWITCH( sampleRate ) + { + case 8000: + case 16000: + case 32000: + case 48000: + return IVAS_ERR_OK; + } + + return IVAS_ERR_INVALID_SAMPLING_RATE; +} +#else /*-------------------------------------------------------------------* * validateOutputSampleRate() * @@ -728,6 +792,7 @@ static ivas_error validateOutputSampleRate( return IVAS_ERR_INVALID_SAMPLING_RATE; } +#endif #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * getAudioConfigNumChannels() @@ -835,7 +900,38 @@ ivas_error getAudioConfigNumChannels( return IVAS_ERR_OK; } #endif +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static ivas_error initLimiter( + IVAS_LIMITER_HANDLE *phLimiter, + const Word16 numChannels, + const Word32 sampleRate ) +{ + ivas_error error; + + /* If re-initializing with unchanged values, return early */ + IF ( *phLimiter != NULL && ( *phLimiter )->num_channels == numChannels && ( *phLimiter )->sampling_rate == sampleRate ) + { + return IVAS_ERR_OK; + } + + /* Support re-init: close if already allocated */ + IF ( *phLimiter != NULL ) + { + ivas_limiter_close( phLimiter ); + } + IF ( ( error = ivas_limiter_open( phLimiter, numChannels, sampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } + + return IVAS_ERR_OK; +} +#else /*-------------------------------------------------------------------* * Local functions *-------------------------------------------------------------------*/ @@ -866,7 +962,7 @@ static ivas_error initLimiter( return IVAS_ERR_OK; } - +#endif static LSSETUP_CUSTOM_STRUCT defaultCustomLs( void ) @@ -1255,7 +1351,8 @@ static ivas_error getEfapGains( static ivas_error initHeadRotation( IVAS_REND_HANDLE hIvasRend ) { - int16_t i, crossfade_len; + Word16 i, crossfade_len; + Word32 tmp_fx; float tmp; ivas_error error; @@ -1265,25 +1362,27 @@ static ivas_error initHeadRotation( /* Initialize 5ms crossfade */ crossfade_len = L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES; tmp = 1.f / ( crossfade_len - 1 ); + tmp_fx = Q31_BY_SUB_FRAME_240; + for ( i = 0; i < crossfade_len; i++ ) { hIvasRend->headRotData.crossfade[i] = i * tmp; - hIvasRend->headRotData.crossfade_fx[i] = (Word16) float_to_fix( hIvasRend->headRotData.crossfade[i], 14 ); + hIvasRend->headRotData.crossfade_fx[i] = UL_Mpy_32_32( i, tmp_fx ); } /* Initialize with unit quaternions */ - for ( i = 0; i < hIvasRend->num_subframes; ++i ) + FOR ( i = 0; i < hIvasRend->num_subframes; ++i ) { hIvasRend->headRotData.headPositions[i] = quaternionInit(); } - if ( ( hIvasRend->headRotData.hOrientationTracker = (ivas_orient_trk_state_t *) malloc( sizeof( ivas_orient_trk_state_t ) ) ) == NULL ) + IF ( ( hIvasRend->headRotData.hOrientationTracker = (ivas_orient_trk_state_t *) malloc( sizeof( ivas_orient_trk_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Orientation tracking" ); } - if ( ( error = ivas_orient_trk_Init( hIvasRend->headRotData.hOrientationTracker ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_orient_trk_Init( hIvasRend->headRotData.hOrientationTracker ) ) != IVAS_ERR_OK ) { return error; } @@ -2961,29 +3060,29 @@ static void clearInputMasa( ivas_error IVAS_REND_Open( IVAS_REND_HANDLE *phIvasRend, - const int32_t outputSampleRate, + const Word32 outputSampleRate, const AUDIO_CONFIG outConfig, - const int16_t nonDiegeticPan, + const Word16 nonDiegeticPan, const float nonDiegeticPanGain, - const int16_t num_subframes ) + const Word16 num_subframes ) { - int16_t i; + Word16 i; IVAS_REND_HANDLE hIvasRend; ivas_error error; - int16_t numOutChannels; + Word16 numOutChannels; /* Validate function arguments */ - if ( phIvasRend == NULL ) + IF( phIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - if ( ( error = validateOutputAudioConfig( outConfig ) ) != IVAS_ERR_OK ) + IF( ( error = validateOutputAudioConfig( outConfig ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = validateOutputSampleRate( outputSampleRate, outConfig ) ) != IVAS_ERR_OK ) + IF( ( error = validateOutputSampleRate( outputSampleRate, outConfig ) ) != IVAS_ERR_OK ) { return error; } @@ -3004,7 +3103,7 @@ ivas_error IVAS_REND_Open( hIvasRend->num_subframes = num_subframes; /* Initialize limiter */ - if ( ( error = IVAS_REND_NumOutChannels( hIvasRend, &numOutChannels ) ) != IVAS_ERR_OK ) + IF( ( error = IVAS_REND_NumOutChannels( hIvasRend, &numOutChannels ) ) != IVAS_ERR_OK ) { return error; } @@ -3380,7 +3479,42 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * IVAS_REND_NumOutChannels() + * + * + *-------------------------------------------------------------------*/ + +ivas_error IVAS_REND_NumOutChannels( + IVAS_REND_CONST_HANDLE hIvasRend, + Word16 *numOutChannels ) +{ + ivas_error error; + /* Validate function arguments */ + IF( hIvasRend == NULL || numOutChannels == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + /* Handle special cases where additional info is needed from the renderer, otherwise use getAudioConfigNumChannels() */ + SWITCH( hIvasRend->outputConfig ) + { + case IVAS_AUDIO_CONFIG_LS_CUSTOM: + *numOutChannels = hIvasRend->customLsOut.num_spk + hIvasRend->customLsOut.num_lfe; + BREAK; + default: + IF( ( error = getAudioConfigNumChannels( hIvasRend->outputConfig, numOutChannels ) ) != IVAS_ERR_OK ) + { + return error; + } + BREAK; + } + + return IVAS_ERR_OK; +} +#else /*-------------------------------------------------------------------* * IVAS_REND_NumOutChannels() * @@ -3415,7 +3549,7 @@ ivas_error IVAS_REND_NumOutChannels( return IVAS_ERR_OK; } - +#endif static IVAS_REND_InputId makeInputId( AUDIO_CONFIG config, @@ -4842,7 +4976,7 @@ static ivas_error chooseCrossfade( #ifdef IVAS_FLOAT_FIXED static ivas_error chooseCrossfade_fx( const IVAS_REND_HeadRotData *headRotData, - const Word16 **pCrossfade ) + const Word32 **pCrossfade ) { *pCrossfade = headRotData->crossfade_fx; @@ -5007,7 +5141,7 @@ static ivas_error rotateFrameSba_fx( Word16 i, l, n, m; Word16 m1, m2; Word16 shd_rot_max_order; - const Word16 *crossfade; + const Word32 *crossfade; Word16 num_subframes; Word16 subframe_idx, subframe_len; Word32 *writePtr; @@ -5017,7 +5151,7 @@ static ivas_error rotateFrameSba_fx( Word32 Rmat[3][3]; ivas_error error; Word16 idx; - Word16 cf, oneminuscf; + Word32 cf, oneminuscf; Word32 val; push_wmops( "rotateFrameSba" ); @@ -5070,7 +5204,7 @@ static ivas_error rotateFrameSba_fx( idx = subframe_idx * subframe_len + i; // cf = crossfade[i]; cf = crossfade[i]; - oneminuscf = ONE_IN_Q14 - cf; + oneminuscf = ONE_IN_Q31 - cf; /* As the rotation matrix becomes block diagonal in a SH basis, we can*/ /* apply each angular-momentum block individually to save complexity. */ @@ -5087,8 +5221,8 @@ static ivas_error rotateFrameSba_fx( { val = inAudio.data_fx[m * inAudio.config.numSamplesPerChannel + idx]; /* crossfade with previous rotation gains */ - temp = Mpy_32_32( L_add( L_mult0( cf, gains[n][m] ), ( L_mult0( oneminuscf, gains_prev[n][m] ) ) ), val ); - tmpRot[n - m1] = L_add( temp << 3, tmpRot[n - m1] ); // Qexp + temp = Mpy_32_32( L_add( Mpy_32_16_r( cf, gains[n][m] ), ( Mpy_32_16_r( oneminuscf, gains_prev[n][m] ) ) ), val ); + tmpRot[n - m1] = L_add( L_shl(temp , 1), tmpRot[n - m1] ); // Qexp } } /* write back the result */ @@ -8030,11 +8164,6 @@ static ivas_error getSamplesInternal( #ifndef DISABLE_LIMITER Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); limitRendererOutput_fx( hIvasRend->hLimiter, outAudio.data_fx, outAudio.config.numSamplesPerChannel, limiter_thresold, *outAudio.pq_fact ); - /* for ( j = 0; j < outAudio.config.numChannels * outAudio.config.numSamplesPerChannel; j++ ) - { - outAudio.data[j] = fix_to_float( outAudio.data_fx[j], *outAudio.q_fact ); - } -*/ #endif } else -- GitLab