From 6e56a74c15cd9756ce2f2e82192e15f91191a6f6 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 18 Feb 2024 10:21:16 +0530 Subject: [PATCH] renderSbaToSba and renderSbaToMC functions converted to fxd --- apps/renderer.c | 6 + lib_rend/ivas_rotation.c | 4 +- lib_rend/lib_rend.c | 351 ++++++++++++++++++++++++++++++--------- 3 files changed, 283 insertions(+), 78 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index 61c989524..ac591bbde 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -1373,6 +1373,12 @@ int main( fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } +#else + if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, sbaIds[i], tmpBuffer ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); + exit( -1 ); + } #endif } diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 8d48b7964..c95674277 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -775,7 +775,7 @@ void rotateFrame_sd( /* output channel index without LFE */ ch_out_woLFE = ( ch_out >= index_lfe ) ? ch_out - 1 : ch_out; - gains_prev_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Adjusting Q30 -> Q28 + gains_prev_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Q30 } } @@ -800,7 +800,7 @@ void rotateFrame_sd( /* output channel index without LFE */ ch_out_woLFE = ( ch_out >= index_lfe ) ? ch_out - 1 : ch_out; - gains_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Adjusting Q30 -> Q28 + gains_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Q30 } } } diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 8757e84a9..1079b7c2c 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1387,9 +1387,9 @@ static ivas_error initHeadRotation( } #ifdef IVAS_FLOAT_FIXED - IF((hIvasRend->headRotData.hOrientationTracker_fx = (ivas_orient_trk_state_t_fx *)malloc(sizeof(ivas_orient_trk_state_t_fx))) == NULL) + IF( ( hIvasRend->headRotData.hOrientationTracker_fx = (ivas_orient_trk_state_t_fx *) malloc( sizeof( ivas_orient_trk_state_t_fx ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Orientation tracking"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Orientation tracking" ); } IF((error = ivas_orient_trk_Init_fx(hIvasRend->headRotData.hOrientationTracker)) != IVAS_ERR_OK) @@ -1786,7 +1786,6 @@ static void copyLsConversionMatrixToPanMatrix( return; } - static void setZeroPanMatrix( pan_matrix panMatrix ) { @@ -1799,8 +1798,35 @@ static void setZeroPanMatrix( return; } +#ifdef IVAS_FLOAT_FIXED +static void setZeroPanMatrix_fx( + pan_matrix_fx panMatrix ) +{ + Word16 i; + + FOR( i = 0; i < MAX_INPUT_CHANNELS; ++i ) + { + set_val_Word32( panMatrix[i], 0, MAX_OUTPUT_CHANNELS ); + } + + return; +} +#endif +#ifdef IVAS_FLOAT_FIXED +/* Note: this only sets non-zero elements, call setZeroPanMatrix() to init first. */ +static void fillIdentityPanMatrix_fx( + pan_matrix_fx panMatrix ) +{ + Word16 i; + FOR( i = 0; i < min( MAX_INPUT_CHANNELS, MAX_OUTPUT_CHANNELS ); ++i ) + { + panMatrix[i][i] = ONE_IN_Q31; + } + return; +} +#endif /* Note: this only sets non-zero elements, call setZeroPanMatrix() to init first. */ static void fillIdentityPanMatrix( pan_matrix panMatrix ) @@ -2750,25 +2776,35 @@ static ivas_error initSbaPanGainsForMcOut( #ifndef IVAS_FLOAT_FIXED inputSba->hoaDecMtx[chInIdx][chOutIdx] = *readPtr++; #else + inputSba->hoaDecMtx_fx[chInIdx][chOutIdx] = ( ( *readPtr ) == ONE_IN_Q29 ) ? ONE_IN_Q31 : *readPtr << 2; inputSba->hoaDecMtx[chInIdx][chOutIdx] = ( (float) *readPtr++ ) / ONE_IN_Q29; #endif } } -#ifdef IVAS_FLOAT_FIXED - for ( chOutIdx = 0; chOutIdx < MAX_OUTPUT_CHANNELS; ++chOutIdx ) - { - for ( chInIdx = 0; chInIdx < MAX_INPUT_CHANNELS; ++chInIdx ) - { - inputSba->hoaDecMtx_fx[chInIdx][chOutIdx] = (Word32)(inputSba->hoaDecMtx[chInIdx][chOutIdx] * ONE_IN_Q31); - } - } -#endif free( tmpDecMtx ); return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +static ivas_error initSbaPanGainsForSbaOut( + input_sba *inputSba, + const AUDIO_CONFIG outConfig ) +{ + ivas_error error; + error = IVAS_ERR_OK; + + if ( getAudioConfigType( outConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) + { + assert( !"Invalid configuration" ); + return IVAS_ERR_WRONG_PARAMS; + } + + fillIdentityPanMatrix_fx( inputSba->hoaDecMtx_fx ); + return error; +} +#else static ivas_error initSbaPanGainsForSbaOut( input_sba *inputSba, const AUDIO_CONFIG outConfig ) @@ -2786,8 +2822,76 @@ static ivas_error initSbaPanGainsForSbaOut( return error; } +#endif +#ifdef IVAS_FLOAT_FIXED +static ivas_error updateSbaPanGains( + input_sba *inputSba, + const AUDIO_CONFIG outConfig, + RENDER_CONFIG_DATA *hRendCfg ) +{ + ivas_error error; + AUDIO_CONFIG inConfig; + rendering_context rendCtx; + + /* Reset to all zeros - some functions below only write non-zero elements. */ + setZeroPanMatrix( inputSba->hoaDecMtx ); + setZeroPanMatrix_fx( inputSba->hoaDecMtx_fx ); + inConfig = inputSba->base.inConfig; + rendCtx = inputSba->base.ctx; + + switch ( getAudioConfigType( outConfig ) ) + { + case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: + error = initSbaPanGainsForMcOut( inputSba, outConfig, inputSba->base.ctx.pCustomLsOut ); + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: + error = initSbaPanGainsForSbaOut( inputSba, outConfig ); + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL: + switch ( outConfig ) + { + case IVAS_AUDIO_CONFIG_BINAURAL: + { + if ( ( error = ivas_rend_openCrend( &inputSba->crendWrapper, inConfig, outConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } + } + break; + case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR: + case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB: + if ( ( error = initSbaPanGainsForMcOut( inputSba, IVAS_AUDIO_CONFIG_7_1_4, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_rend_openCrend( &inputSba->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } + break; + default: + return IVAS_ERR_INVALID_OUTPUT_FORMAT; + } + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: + error = IVAS_ERR_OK; + break; /* Do nothing */ + default: + return IVAS_ERR_INVALID_OUTPUT_FORMAT; + } + + /* Check error here to keep switch statement more compact */ + if ( error != IVAS_ERR_OK ) + { + return error; + } + + return IVAS_ERR_OK; +} +#else static ivas_error updateSbaPanGains( input_sba *inputSba, const AUDIO_CONFIG outConfig, @@ -2854,7 +2958,7 @@ static ivas_error updateSbaPanGains( return IVAS_ERR_OK; } - +#endif static ivas_error initSbaMasaRendering( input_sba *inputSba, @@ -4804,17 +4908,17 @@ ivas_error IVAS_REND_GetMainOrientation( #ifdef IVAS_FLOAT_FIXED IVAS_QUATERNION_FX *pOrientation_fx = malloc( sizeof( IVAS_QUATERNION_FX ) ); Word16 q_fact = hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.w_qfact = hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.x_qfact = - hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.y_qfact = hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.z_qfact = Q29; - hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.w_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.w, q_fact); - hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.x_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.x, q_fact); - hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.y_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.y, q_fact); - hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.z_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.z, q_fact); + hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.y_qfact = hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.z_qfact = Q29; + hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.w_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.w, q_fact ); + hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.x_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.x, q_fact ); + hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.y_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.y, q_fact ); + hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.z_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.z, q_fact ); - hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.w_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.w, Q29 ); - hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.x_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.x, Q29 ); - hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.y_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.y, Q29 ); - hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.z_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.z, Q29 ); + hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.w_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.w, Q29 ); + hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.x_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.x, Q29 ); + hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.y_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.y, Q29 ); + hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.z_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.z, Q29 ); hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.w_qfact = hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.x_qfact = hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.y_qfact = hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.z_qfact = Q29; @@ -4823,10 +4927,10 @@ ivas_error IVAS_REND_GetMainOrientation( pOrientation->x = fix_to_float( pOrientation_fx->x_fx, pOrientation_fx->x_qfact ); pOrientation->y = fix_to_float( pOrientation_fx->y_fx, pOrientation_fx->y_qfact ); pOrientation->z = fix_to_float( pOrientation_fx->z_fx, pOrientation_fx->z_qfact ); - free(pOrientation_fx); - IF(error != IVAS_ERR_OK) + free( pOrientation_fx ); + IF( error != IVAS_ERR_OK ) { - return error; + return error; } #else if ( ( error = ivas_orient_trk_GetMainOrientation( hIvasRend->headRotData.hOrientationTracker, pOrientation ) ) != IVAS_ERR_OK ) @@ -4858,22 +4962,22 @@ ivas_error IVAS_REND_GetTrackedRotation( } #ifdef IVAS_FLOAT_FIXED - IVAS_QUATERNION_FX *pRotation_fx = malloc(sizeof(IVAS_QUATERNION_FX)); - hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.w_fx = (Word32)float_to_fix(hIvasRend->headRotData.hOrientationTracker->trkRot.w, Q29); - hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.x_fx = (Word32)float_to_fix(hIvasRend->headRotData.hOrientationTracker->trkRot.x, Q29); - hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.y_fx = (Word32)float_to_fix(hIvasRend->headRotData.hOrientationTracker->trkRot.y, Q29); - hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.z_fx = (Word32)float_to_fix(hIvasRend->headRotData.hOrientationTracker->trkRot.z, Q29); + IVAS_QUATERNION_FX *pRotation_fx = malloc( sizeof( IVAS_QUATERNION_FX ) ); + hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.w_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->trkRot.w, Q29 ); + hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.x_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->trkRot.x, Q29 ); + hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.y_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->trkRot.y, Q29 ); + hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.z_fx = (Word32) float_to_fix( hIvasRend->headRotData.hOrientationTracker->trkRot.z, Q29 ); hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.w_qfact = hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.x_qfact = - hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.y_qfact = hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.z_qfact = Q29; - error = ivas_orient_trk_GetTrackedRotation_fx(hIvasRend->headRotData.hOrientationTracker_fx, pRotation_fx); - pRotation->w = fix_to_float(pRotation_fx->w_fx, pRotation_fx->w_qfact); - pRotation->x = fix_to_float(pRotation_fx->x_fx, pRotation_fx->x_qfact); - pRotation->y = fix_to_float(pRotation_fx->y_fx, pRotation_fx->y_qfact); - pRotation->z = fix_to_float(pRotation_fx->z_fx, pRotation_fx->z_qfact); - free(pRotation_fx); - IF(error != IVAS_ERR_OK) + hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.y_qfact = hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.z_qfact = Q29; + error = ivas_orient_trk_GetTrackedRotation_fx( hIvasRend->headRotData.hOrientationTracker_fx, pRotation_fx ); + pRotation->w = fix_to_float( pRotation_fx->w_fx, pRotation_fx->w_qfact ); + pRotation->x = fix_to_float( pRotation_fx->x_fx, pRotation_fx->x_qfact ); + pRotation->y = fix_to_float( pRotation_fx->y_fx, pRotation_fx->y_qfact ); + pRotation->z = fix_to_float( pRotation_fx->z_fx, pRotation_fx->z_qfact ); + free( pRotation_fx ); + IF( error != IVAS_ERR_OK ) { - return error; + return error; } #else if ( ( error = ivas_orient_trk_GetTrackedRotation( hIvasRend->headRotData.hOrientationTracker, pRotation ) ) != IVAS_ERR_OK ) @@ -5097,13 +5201,13 @@ static void renderBufferChannelLerp_fx( /* Pointer to behind last input sample */ lastInSmpl = getSmplPtr_fx( inAudio, inChannelIdx, inAudio.config.numSamplesPerChannel ); - FOR ( outChnlIdx = 0; outChnlIdx < outAudio.config.numChannels; ++outChnlIdx ) + FOR( outChnlIdx = 0; outChnlIdx < outAudio.config.numChannels; ++outChnlIdx ) { currentGain = gainsCurrent[outChnlIdx]; previousGain = gainsPrev == NULL ? 0 : gainsPrev[outChnlIdx]; /* Process current output channel only if applying non-zero gains */ - IF ( GT_32(abs( currentGain ) , EPSILON_FX) || ( gainsPrev != NULL && GT_32(abs( previousGain ) , EPSILON_FX ) )) + IF( GT_32( abs( currentGain ), EPSILON_FX ) || ( gainsPrev != NULL && GT_32( abs( previousGain ), EPSILON_FX ) ) ) { /* Reset input pointer to the beginning of input channel */ inSmpl = getSmplPtr_fx( inAudio, inChannelIdx, 0 ); @@ -5111,16 +5215,16 @@ static void renderBufferChannelLerp_fx( /* Set output pointer to first output channel sample */ outSmpl = getSmplPtr_fx( outAudio, outChnlIdx, 0 ); - IF ( gainsPrev == NULL || LE_32(abs( L_sub(previousGain , currentGain )) , EPSILON_FX )) + IF( gainsPrev == NULL || LE_32( abs( L_sub( previousGain, currentGain ) ), EPSILON_FX ) ) { /* If no interpolation from previous frame, apply current gain */ DO { - *outSmpl = L_add(Mpy_32_32(currentGain , ( *inSmpl )),*outSmpl); + *outSmpl = L_add( Mpy_32_32( currentGain, ( *inSmpl ) ), *outSmpl ); ++outSmpl; ++inSmpl; - - } WHILE ( inSmpl != lastInSmpl ); + } + WHILE( inSmpl != lastInSmpl ); } ELSE { @@ -5147,13 +5251,14 @@ static void renderBufferChannelLerp_fx( DO { fadeIn = UL_Mpy_32_32( i, tmp ); - fadeOut = ONE_IN_Q31- fadeIn; + fadeOut = ONE_IN_Q31 - fadeIn; - *outSmpl = L_add(Mpy_32_32(L_add ( Mpy_32_32(fadeIn , currentGain) , Mpy_32_32(fadeOut , previousGain )) , ( *inSmpl )), *outSmpl ); + *outSmpl = L_add( Mpy_32_32( L_add( Mpy_32_32( fadeIn, currentGain ), Mpy_32_32( fadeOut, previousGain ) ), ( *inSmpl ) ), *outSmpl ); ++outSmpl; ++inSmpl; ++i; - } WHILE ( inSmpl != lastInSmpl ); + } + WHILE( inSmpl != lastInSmpl ); } } } @@ -6045,19 +6150,19 @@ static ivas_error renderIsmToMc( set_zero( currentPanGains, MAX_OUTPUT_CHANNELS ); #ifdef IVAS_FLOAT_FIXED - Word16 gains_fx[2]; - ivas_ism_get_stereo_gains_fx( (Word16)ismInput->currentPos.azimuth, (Word16)ismInput->currentPos.elevation, &gains_fx[0], &gains_fx[1] ); - currentPanGains[0] = (float)gains_fx[0] / 32768.f; - currentPanGains[1] = (float)gains_fx[1] / 32768.f; + Word16 gains_fx[2]; + ivas_ism_get_stereo_gains_fx( (Word16) ismInput->currentPos.azimuth, (Word16) ismInput->currentPos.elevation, &gains_fx[0], &gains_fx[1] ); + currentPanGains[0] = (float) gains_fx[0] / 32768.f; + currentPanGains[1] = (float) gains_fx[1] / 32768.f; #else ivas_ism_get_stereo_gains( ismInput->currentPos.azimuth, ismInput->currentPos.elevation, ¤tPanGains[0], ¤tPanGains[1] ); #endif set_zero( ismInput->prev_pan_gains, MAX_OUTPUT_CHANNELS ); #ifdef IVAS_FLOAT_FIXED - ivas_ism_get_stereo_gains_fx( (Word16)ismInput->previousPos.azimuth, (Word16)ismInput->previousPos.elevation, &gains_fx[0], &gains_fx[1] ); - ismInput->prev_pan_gains[0] = (float)gains_fx[0] / 32768.f; - ismInput->prev_pan_gains[1] = (float)gains_fx[1] / 32768.f; + ivas_ism_get_stereo_gains_fx( (Word16) ismInput->previousPos.azimuth, (Word16) ismInput->previousPos.elevation, &gains_fx[0], &gains_fx[1] ); + ismInput->prev_pan_gains[0] = (float) gains_fx[0] / 32768.f; + ismInput->prev_pan_gains[1] = (float) gains_fx[1] / 32768.f; #else ivas_ism_get_stereo_gains( ismInput->previousPos.azimuth, ismInput->previousPos.elevation, &ismInput->prev_pan_gains[0], &ismInput->prev_pan_gains[1] ); #endif @@ -6258,7 +6363,35 @@ static ivas_error renderInputIsm( return error; } +#ifdef IVAS_FLOAT_FIXED +static ivas_error renderActiveInputsIsm( + IVAS_REND_HANDLE hIvasRend, + IVAS_REND_AudioBuffer outAudio ) +{ + int16_t i; + input_ism *pCurrentInput; + ivas_error error; + + for ( i = 0, pCurrentInput = hIvasRend->inputsIsm; i < RENDERER_MAX_ISM_INPUTS; ++i, ++pCurrentInput ) + { + if ( pCurrentInput->base.inConfig == IVAS_AUDIO_CONFIG_INVALID ) + { + /* Skip inactive inputs */ + continue; + } + if ( ( error = renderInputIsm( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) + { + return error; + } + } + for ( i = 0; i < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++i ) + { + outAudio.data_fx[i] = (Word32) ( outAudio.data[i] * ( 1 << (*outAudio.pq_fact-1) ) ); + } + return IVAS_ERR_OK; +} +#else static ivas_error renderActiveInputsIsm( IVAS_REND_HANDLE hIvasRend, IVAS_REND_AudioBuffer outAudio ) @@ -6283,7 +6416,7 @@ static ivas_error renderActiveInputsIsm( return IVAS_ERR_OK; } - +#endif static ivas_error renderLfeToBinaural( const input_mc *mcInput, @@ -7208,7 +7341,35 @@ static ivas_error renderInputMc( return error; } +#ifdef IVAS_FLOAT_FIXED +static ivas_error renderActiveInputsMc( + IVAS_REND_HANDLE hIvasRend, + IVAS_REND_AudioBuffer outAudio ) +{ + int16_t i; + input_mc *pCurrentInput; + ivas_error error; + for ( i = 0, pCurrentInput = hIvasRend->inputsMc; i < RENDERER_MAX_MC_INPUTS; ++i, ++pCurrentInput ) + { + if ( pCurrentInput->base.inConfig == IVAS_AUDIO_CONFIG_INVALID ) + { + /* Skip inactive inputs */ + continue; + } + + if ( ( error = renderInputMc( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) + { + return error; + } + } + for ( i = 0; i < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++i ) + { + outAudio.data_fx[i] = (Word32) ( outAudio.data[i] * ( 1 << ( *outAudio.pq_fact - 1 ) ) );// to make the output buffer Q same as input when it reaches renderActiveInputsSba + } + return IVAS_ERR_OK; +} +#else static ivas_error renderActiveInputsMc( IVAS_REND_HANDLE hIvasRend, IVAS_REND_AudioBuffer outAudio ) @@ -7233,8 +7394,47 @@ static ivas_error renderActiveInputsMc( return IVAS_ERR_OK; } +#endif +#ifdef IVAS_FLOAT_FIXED +static void renderSbaToMc( + const input_sba *sbaInput, + IVAS_REND_AudioBuffer outAudio ) +{ + Word16 i; + IVAS_REND_AudioBuffer inAudio; + + push_wmops( "renderSbaToMc" ); + inAudio = sbaInput->base.inputBuffer; + + FOR ( i = 0; i < inAudio.config.numChannels; ++i ) + { + renderBufferChannel_fx( inAudio, i, sbaInput->hoaDecMtx_fx[i], outAudio ); + } + + pop_wmops(); + return; +} +static void renderSbaToSba( + const input_sba *sbaInput, + IVAS_REND_AudioBuffer outAudio ) +{ + Word16 i; + IVAS_REND_AudioBuffer inAudio; + + push_wmops( "renderSbaToSba" ); + inAudio = sbaInput->base.inputBuffer; + + FOR ( i = 0; i < inAudio.config.numChannels; ++i ) + { + renderBufferChannel_fx( inAudio, i, sbaInput->hoaDecMtx_fx[i], outAudio ); + } + + pop_wmops(); + return; +} +#else static void renderSbaToMc( const input_sba *sbaInput, IVAS_REND_AudioBuffer outAudio ) @@ -7273,7 +7473,7 @@ static void renderSbaToSba( pop_wmops(); return; } - +#endif #ifdef IVAS_FLOAT_FIXED static ivas_error renderSbaToBinaural( input_sba *sbaInput, @@ -7451,10 +7651,10 @@ static ivas_error renderSbaToBinauralRoom( push_wmops( "renderSbaToBinauralRoom" ); Word16 nchan_out; CREND_HANDLE hCrend; - + hCrend = sbaInput->crendWrapper->hCrend; - IF ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK ) + IF( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK ) { return error; } @@ -7486,21 +7686,20 @@ static ivas_error renderSbaToBinauralRoom( /* copy input for in-place rotation */ mvr2r_Word32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); - + IF( ( error = rotateFrameSba_fx( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, - sbaInput->base.ctx.pCombinedOrientationData, - sbaInput->rot_gains_prev_fx, - tmpRotBuffer ) ) != IVAS_ERR_OK ) + sbaInput->base.ctx.pCombinedOrientationData, + sbaInput->rot_gains_prev_fx, + tmpRotBuffer ) ) != IVAS_ERR_OK ) { return error; } - } /* intermediate rendering to 7_1_4 */ tmpMcBuffer = sbaInput->base.inputBuffer; - IF ( ( error = getAudioConfigNumChannels( IVAS_AUDIO_CONFIG_7_1_4, &tmp ) ) != IVAS_ERR_OK ) + IF( ( error = getAudioConfigNumChannels( IVAS_AUDIO_CONFIG_7_1_4, &tmp ) ) != IVAS_ERR_OK ) { return error; } @@ -7510,25 +7709,25 @@ static ivas_error renderSbaToBinauralRoom( set_val_Word32( tmpMcBuffer.data_fx, 0, tmpMcBuffer.config.numChannels * tmpMcBuffer.config.numSamplesPerChannel ); tmpBufPtr = ( combinedOrientationEnabled ) ? &tmpRotBuffer : &sbaInput->base.inputBuffer; - FOR ( i = 0; i < sbaInput->base.inputBuffer.config.numChannels; i++ ) + FOR( i = 0; i < sbaInput->base.inputBuffer.config.numChannels; i++ ) { renderBufferChannel_fx( *tmpBufPtr, i, sbaInput->hoaDecMtx_fx[i], tmpMcBuffer ); } copyBufferTo2dArray_fx( tmpMcBuffer, tmpCrendBuffer ); // Porting Crend_process function - + /* call CREND */ - IF ( ( error = ivas_rend_crendProcess( sbaInput->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, - NULL, NULL, NULL, NULL, p_tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate, - getNumSubframesInBuffer( &outAudio, *sbaInput->base.ctx.pOutSampleRate ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_crendProcess( sbaInput->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, + NULL, NULL, NULL, NULL, p_tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate, + getNumSubframesInBuffer( &outAudio, *sbaInput->base.ctx.pOutSampleRate ) ) ) != IVAS_ERR_OK ) { return error; } - IF ( hCrend->hReverb != NULL ) + IF( hCrend->hReverb != NULL ) { *outAudio.pq_fact -= 2; } - + accumulate2dArrayToBuffer_fx( tmpCrendBuffer, &outAudio ); if ( combinedOrientationEnabled ) @@ -8339,7 +8538,6 @@ static ivas_error getSamplesInternal( { return error; } - if ( ( error = renderActiveInputsMc( hIvasRend, outAudio ) ) != IVAS_ERR_OK ) { return error; @@ -8353,7 +8551,7 @@ static ivas_error getSamplesInternal( return error; } - if ( ( hIvasRend->inputsSba[0].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) && ( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) ) + if ( ( ( hIvasRend->inputsSba[0].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) && ( ( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) || ( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || ( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) ) ) ) { #ifndef DISABLE_LIMITER @@ -8670,7 +8868,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( set_f( hDirACRend->frequency_axis, 0.0f, hSpatParamRendCom->num_freq_bands ); #ifdef IVAS_FLOAT_FIXED - Word16 *frequency_axis_fx = ( Word16 * ) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ); + Word16 *frequency_axis_fx = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ); ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hSpatParamRendCom->num_freq_bands ); FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++) { @@ -9040,7 +9238,8 @@ static ivas_error ivas_masa_ext_rend_parambin_init( Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, nBins ); - for (int i = 0; i < nBins; i++) { + for ( int i = 0; i < nBins; i++ ) + { frequency_axis[i] = frequency_axis_fx[i]; } #else -- GitLab