From 84dd0f5787cacb0f8dc72794886c771a4ce3663f Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 14 May 2024 09:07:11 +0530 Subject: [PATCH] ASAN_MSAN_USAN_Warnings_LTV_Fixes [x] Few ASAN errors fixed. [x] Few MSAN errors for SBA path fixed. [x] Corrected Q factor in non_linearity_ivas_fx. [x] Warnings fixes. [x] Clean up of lib_rend.c. --- lib_com/arith_coder_fx.c | 2 +- lib_com/fd_cng_com.c | 4 +- lib_com/float_to_fix_ops.c | 29 +- lib_com/prot.h | 4 +- lib_com/swb_bwe_com_fx.c | 4 +- lib_com/swb_tbe_com_fx.c | 4 +- lib_com/window_ola_fx.c | 10 +- lib_com/wtda_fx.c | 8 +- lib_dec/ACcontextMapping_dec_fx.c | 4 +- lib_dec/FEC_HQ_phase_ecu_fx.c | 2 +- lib_dec/acelp_core_dec_ivas_fx.c | 16 +- lib_dec/core_dec_init_fx.c | 13 +- lib_dec/dec_tcx_fx.c | 2 +- lib_dec/hq_core_dec_fx.c | 4 +- lib_dec/ivas_core_dec.c | 26 +- lib_dec/ivas_init_dec.c | 10 + lib_dec/ivas_ism_dec.c | 2 + lib_dec/ivas_jbm_dec.c | 2 + lib_dec/ivas_sba_dec.c | 2 + lib_dec/jbm_pcmdsp_apa.c | 92 +- lib_dec/tonalMDCTconcealment_fx.c | 6 +- lib_rend/ivas_masa_merge.c | 12 +- lib_rend/ivas_objectRenderer.c | 9 +- lib_rend/ivas_omasa_ana.c | 19 +- lib_rend/ivas_prot_rend.h | 1 - lib_rend/ivas_stat_rend.h | 5 +- lib_rend/lib_rend.c | 3176 ++++++++++++++--------------- lib_util/hrtf_file_reader.c | 8 +- 28 files changed, 1814 insertions(+), 1662 deletions(-) diff --git a/lib_com/arith_coder_fx.c b/lib_com/arith_coder_fx.c index ceb9b07de..efcc4b731 100644 --- a/lib_com/arith_coder_fx.c +++ b/lib_com/arith_coder_fx.c @@ -260,7 +260,7 @@ void tcx_arith_scale_envelope( b_e = add(b_e, mean_e); /* scale = (-b + (float)sqrt(b*b - 4.0f*a*0.035f)) / (2.0f * a); */ - tmp = round_fx(BASOP_Util_Add_Mant32Exp(L_mult(b, b), shl(b_e, 1), Mpy_32_16_1(a, -4588/*-4.0f*0.035f Q15*/), a_e, &tmp2)); + tmp = round_fx_o(BASOP_Util_Add_Mant32Exp(L_mult(b, b), shl(b_e, 1), Mpy_32_16_1(a, -4588/*-4.0f*0.035f Q15*/), a_e, &tmp2), &Overflow); IF( tmp <= 0 ) { diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 7ebf70ec8..c99088fcd 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -88,7 +88,8 @@ ivas_error createFdCngCom_flt( void initFdCngCom_flt( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const float scale ) + const float scale +) { #ifndef IVAS_FLOAT_FIXED /* Calculate FFT scaling factor */ @@ -102,6 +103,7 @@ void initFdCngCom_flt( /* Initialize the comfort noise generation */ set_f( hFdCngCom->fftBuffer_flt, 0.0f, FFTLEN ); #endif + UNUSED_PARAM(scale); set_f( hFdCngCom->cngNoiseLevel_flt, 0.0f, FFTCLDFBLEN ); set_f( hFdCngCom->olapBufferSynth2_flt, 0.0f, FFTLEN ); diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index dc7a3a9f9..780f87270 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -844,10 +844,20 @@ void fixed_to_float_stereo_tcx_core_dec( //st->hTcxDec->syn_Overl_TDACFB_float[p] = (float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * (float) pow( 2, st->Q_syn ); //st->hTcxDec->syn_Overl_TDAC_float[p] = (float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * (float) pow( 2, st->Q_syn ); } - for ( int p = 0; p < st->L_frame; p++ ) + if (st->hHQ_core->Q_old_wtda >= 0) { - st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->hHQ_core->Q_old_wtda ); - st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] / ( 1u << st->hHQ_core->Q_old_wtda ); + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->hHQ_core->Q_old_wtda ); + st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] / ( 1u << st->hHQ_core->Q_old_wtda ); + } + } + else{ + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] * ( 1u << (-st->hHQ_core->Q_old_wtda) ); + st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] * ( 1u << (-st->hHQ_core->Q_old_wtda) ); + } } //for ( int p = 0; p < st->L_frame; p++ ) //{ @@ -903,9 +913,18 @@ void fixed_to_float_stereo_tcx_core_dec( //{ // st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); //} - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) + if(( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) >= 0) { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) + { + st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + } + } + else{ + for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) + { + st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] * ( 1u << ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - 31) ) ); + } } for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) { diff --git a/lib_com/prot.h b/lib_com/prot.h index bc84c7a92..d55404f79 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -8796,7 +8796,9 @@ void deleteFdCngCom_flt( void initFdCngCom_flt( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const float scale ); + const float scale +); + void initPartitions_flt( const int16_t *part_in, diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 8c7d50656..f1cae97fe 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -1057,8 +1057,8 @@ void WB_BWE_decoding_fx( energy = L_deposit_l(0); FOR(n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++) { - L_tmp = L_mult(WB_signal[n_freq],WB_signal[n_freq]); /*Q31 */ - energy = L_add(energy,L_shr(L_tmp,6)); /*Q25 */ + L_tmp = L_mult0(WB_signal[n_freq],WB_signal[n_freq]); /*Q30 */ + energy = L_add(energy,L_shr(L_tmp,5)); /*Q25 */ } tmp = sub(swb_bwe_subband[n_band + L] , swb_bwe_subband[n_band]); diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 72f498925..ea5cbcd09 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -4559,7 +4559,7 @@ void non_linearity_ivas_fx( } test(); - IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale )) + IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 64 ) /*Q30 -> Q31*/, scale/*Q31*/ )) { scale_step = 16384; move16(); /* Q14 */ @@ -4645,7 +4645,7 @@ void non_linearity_ivas_fx( } test(); - IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale )) + IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 64 ), scale )) { scale_step = 16384; move16(); /*Q14 */ diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index a9b11c5b3..26066ca46 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -351,8 +351,8 @@ void window_ola_fx( p1=paout+n; pa=ImdctOut+add(shr(L,1),n); /*p3=win_right+ sub(sub(sub(i_mult2(sub(shl(L,1),n),decimate),1),decay),WINDECAY48); */ - p3=win_right+ (2*L_FRAME16k-N16_CORE_SW)*3-1-1-WINDECAY48; - p5=win_int_right+ (2*L_FRAME16k-N16_CORE_SW)-1-WINDECAY16; + p3=win_right+ ((2*L_FRAME16k-N16_CORE_SW)*3-1-1-WINDECAY48); + p5=win_int_right+ ((2*L_FRAME16k-N16_CORE_SW)-1-WINDECAY16); p4=OldauOut+n; temp_len = sub(shr(L,1),n); @@ -372,8 +372,8 @@ void window_ola_fx( } pa=ImdctOut+sub(L,1); - p3=win_right+ (3*L_FRAME16k/2-1)*3+1-WINDECAY48; - p5=win_int_right+ (3*L_FRAME16k/2)-1-WINDECAY16; + p3=win_right+ ((3*L_FRAME16k/2-1)*3+1-WINDECAY48); + p5=win_int_right+ ((3*L_FRAME16k/2)-1-WINDECAY16); temp_len = sub(shr(L,1),n); FOR (i = 0; i < temp_len; i+=2) @@ -417,7 +417,7 @@ void window_ola_fx( p1=OldauOut+n; pa=ImdctOut+sub(sub(shr(L,1),1),n); p2=win_left+(L_FRAME16k-N16_CORE_SW)*3-1-1; - p3=win_int_left+L_FRAME16k-N16_CORE_SW-1; + p3=win_int_left+(L_FRAME16k-N16_CORE_SW-1); temp_len = sub(shr(L,1),n); FOR (i = 0; i < temp_len; i+=2) { diff --git a/lib_com/wtda_fx.c b/lib_com/wtda_fx.c index 32518c177..16a5aaa1a 100644 --- a/lib_com/wtda_fx.c +++ b/lib_com/wtda_fx.c @@ -299,12 +299,12 @@ void wtda_fx( pa=wtda_audio; p1=allsig_r+L_FRAME16k-1; - p2=win_int_right+ 3*L_FRAME16k/2-1-WINDECAY16; /* 3*L/2*decimate-decimate+decay-windecay48;*/ + p2=win_int_right+ (3*L_FRAME16k/2-1-WINDECAY16); /* 3*L/2*decimate-decimate+decay-windecay48;*/ p3=p1+1; p4=p2+1; - p5=win_right+(3*L_FRAME16k/2-1)*3+1-WINDECAY48; - p6=win_right+(3*L_FRAME16k/2+1)*3-1-1-WINDECAY48; + p5=win_right+((3*L_FRAME16k/2-1)*3+1-WINDECAY48); + p6=win_right+((3*L_FRAME16k/2+1)*3-1-1-WINDECAY48); FOR (i=0; ihMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, st->L_frame* HIBND_ACB_L_FAC, 0, &(st->Q_exc), st->Q_subfr, NULL, 0, INACTIVE); } - Rescale_mem(st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, - &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 0, 0, NULL); + IF(st->hPFstat != NULL) + { + Rescale_mem(st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, + &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 0, 0, NULL); + } + ELSE + { + Rescale_mem(st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, + &st->mem_deemph_fx, NULL, NULL, &st->agc_mem_fx[1], NULL, 0, 0, NULL); + } Copy_Scale_sig(exc2_fx, exc2_fx, st->L_frame, sub(st->Q_exc, i)); /* update past excitation signals for LD music post-filter */ @@ -1535,7 +1543,11 @@ ivas_error acelp_core_dec_ivas_fx( Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); } +#ifdef MSAN_FIX + FOR( i = 0; i < st->L_frame; i++ ) +#else for (i = 0; i < L_FRAME16k; i++) +#endif { syn_32_fx[i] = L_shr(L_deposit_h(psyn_fx[i]), 4 + st->Q_syn); //Q12 } diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index d720137be..c6baf3efd 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -256,11 +256,14 @@ void open_decoder_LPD_fx( if (1)//st->element_mode == EVS_MONO) { - if ((st->hTECDec = (TEC_DEC_HANDLE)malloc(sizeof(TEC_DEC_DATA))) == NULL) - { - //return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); - assert(0); - } + if(st->hTECDec == NULL) + { + if ((st->hTECDec = (TEC_DEC_HANDLE)malloc(sizeof(TEC_DEC_DATA))) == NULL) + { + //return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); + assert(0); + } + } } else { diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 2c596d0af..9544cd186 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3927,7 +3927,7 @@ void decoder_tcx_invQ_fx( tmp32 = L_shl( L_mult0( index, 0x797D ), 7 ); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ *gain_tcx_e = add( extract_l( L_shr( tmp32, 25 ) ), 1 ); /* get exponent */ - *gain_tcx = round_fx( BASOP_Util_InvLog2( L_or( tmp32, 0xFE000000 ) ) ); + *gain_tcx = round_fx( BASOP_Util_InvLog2( L_or( tmp32, (Word32)0xFE000000 ) ) ); #ifdef BASOP_NOGLOB tmp1 = mult_r( shl_sat( L_spec, 5 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index ffcbef512..f1d5e40cb 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -843,9 +843,9 @@ void ivas_hq_core_dec_fx( /*t_audio_q[i] *= ener_match;*/ Mpy_32_16_ss( t_audio_q[i], ener_match, &L_tmp, &lsb ); /*12+13-15=10 */ #ifdef BASOP_NOGLOB - t_audio_q[i] = L_add_sat( L_shl_sat( L_tmp, 2 ), lshr( lsb, 14 ) ); + t_audio_q[i] = L_add_sat( L_shl_sat( L_tmp, 2 ), lshr( (Word16)lsb, 14 ) ); #else - t_audio_q[i] = L_add( L_shl( L_tmp, 2 ), lshr( lsb, 14 ) ); + t_audio_q[i] = L_add( L_shl( L_tmp, 2 ), lshr( (Word16)lsb, 14 ) ); #endif move16(); /* Q12 */ } diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 672dab774..8826be540 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -690,14 +690,26 @@ ivas_error ivas_core_dec( } } - for ( int p = 0; p < 640; p++ ) - { - st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->Q_syn ); - } + if(st->Q_syn >= 0){ + for ( int p = 0; p < 640; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->Q_syn ); + } - for ( int p = 0; p < 960; p++ ) - { - st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] / ( 1u << st->Q_syn ); + for ( int p = 0; p < 960; p++ ) + { + st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] / ( 1u << st->Q_syn ); + } + }else{ + for ( int p = 0; p < 640; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] * ( 1u << (-st->Q_syn) ); + } + + for ( int p = 0; p < 960; p++ ) + { + st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] * ( 1u << (-st->Q_syn) ); + } } } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 54156a695..7023c3741 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -386,10 +386,12 @@ ivas_error ivas_dec_setup( fixedToFloat_arrL( Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3 ); fixedToFloat_arrL( Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3 ); } + Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; fixedToFloat_arrL( SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3 ); fixedToFloat_arrL( SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3 ); + SrcSpatial_p->q_Pos_p = Q31; } } // Cleanup changes for ivas_cldfb_dec_reconfig_fx: fixed to float @@ -492,10 +494,12 @@ ivas_error ivas_dec_setup( fixedToFloat_arrL( Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3 ); fixedToFloat_arrL( Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3 ); } + Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; fixedToFloat_arrL( SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3 ); fixedToFloat_arrL( SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3 ); + SrcSpatial_p->q_Pos_p = Q31; } } // Cleanup changes for ivas_cldfb_dec_reconfig_fx: fixed to float @@ -2206,10 +2210,12 @@ ivas_error ivas_init_decoder_fx( fixedToFloat_arrL( Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3 ); fixedToFloat_arrL( Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3 ); } + Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; fixedToFloat_arrL( SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3 ); fixedToFloat_arrL( SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3 ); + SrcSpatial_p->q_Pos_p = Q31; } #endif #else @@ -2322,10 +2328,12 @@ ivas_error ivas_init_decoder_fx( fixedToFloat_arrL(Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3); fixedToFloat_arrL(Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3); } + Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; fixedToFloat_arrL(SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3); fixedToFloat_arrL(SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3); + SrcSpatial_p->q_Pos_p = Q31; } #endif #else @@ -2398,10 +2406,12 @@ ivas_error ivas_init_decoder_fx( fixedToFloat_arrL(Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3); fixedToFloat_arrL(Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3); } + Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; fixedToFloat_arrL(SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3); fixedToFloat_arrL(SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3); + SrcSpatial_p->q_Pos_p = Q31; } #endif #else diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 4df423d75..338314583 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -641,10 +641,12 @@ static ivas_error ivas_ism_bitrate_switching_dec( fixedToFloat_arrL( Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3 ); fixedToFloat_arrL( Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3 ); } + Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; fixedToFloat_arrL( SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3 ); fixedToFloat_arrL( SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3 ); + SrcSpatial_p->q_Pos_p = Q31; } #endif diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 25a296bc4..339d4009d 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -152,7 +152,9 @@ ivas_error ivas_jbm_dec_tc( st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; #if 1 // TODO: To be removed later st_ivas->hTcBuffer->tc[n] = st_ivas->p_output_f[n]; +#ifndef MSAN_FIX floatToFixed_arrL( st_ivas->hTcBuffer->tc[n], st_ivas->hTcBuffer->tc_fx[n], Q11, L_FRAME48k ); +#endif #endif } } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 5d06f0bfa..af261f85e 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -1501,10 +1501,12 @@ ivas_error ivas_sba_dec_reconfigure_fx( fixedToFloat_arrL(Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3); fixedToFloat_arrL(Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3); } + Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; fixedToFloat_arrL(SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3); fixedToFloat_arrL(SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3); + SrcSpatial_p->q_Pos_p = Q31; } #endif #else diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index f2dc98789..21d4ec3fa 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -55,9 +55,9 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx2.h" +#define IVAS_FLOAT_FIXED_TO_BE_REMOVED #endif -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED /*---------------------------------------------------------------------* * Local state structure @@ -364,6 +364,7 @@ void apa_reset( } #endif +#ifdef IVAS_FLOAT_FIXED uint8_t apa_reconfigure( apa_state_t *ps, uint16_t num_channels, @@ -371,15 +372,25 @@ uint8_t apa_reconfigure( { /* realloc buffer */ - free( ps->buf_out ); ps->num_channels = (uint16_t) num_channels; ps->buf_out_capacity = (uint16_t) ( APA_BUF_PER_CHANNEL * num_channels ); + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + free( ps->buf_out ); ps->buf_out = (float *) malloc( sizeof( float ) * ps->buf_out_capacity ); + IF ( !ps->buf_out ) + { + return 2; + } +#endif + + free( ps->buf_out_fx ); ps->buf_out_fx = (Word16 *)malloc(sizeof(float) * ps->buf_out_capacity); - if ( !ps->buf_out || !ps->buf_out_fx ) + IF ( !ps->buf_out_fx ) { return 2; } + ps->l_buf_out = 0; ps->l_in_total = 0; ps->l_ts = ps->num_channels * l_ts; @@ -407,7 +418,50 @@ uint8_t apa_reconfigure( return 0; } +#else +uint8_t apa_reconfigure( + apa_state_t *ps, + uint16_t num_channels, + uint16_t l_ts ) +{ + + /* realloc buffer */ + free( ps->buf_out ); + ps->num_channels = (uint16_t) num_channels; + ps->buf_out_capacity = (uint16_t) ( APA_BUF_PER_CHANNEL * num_channels ); + ps->buf_out = (float *) malloc( sizeof( float ) * ps->buf_out_capacity ); + if ( !ps->buf_out ) + { + return 2; + } + ps->l_buf_out = 0; + ps->l_in_total = 0; + ps->l_ts = ps->num_channels * l_ts; + + /* set everything else dependent on the number of channels */ + /* set segment size */ + /* in the order of a pitch, set to 160 samples at 16 kHz */ + /* used for windowing and as the correlation length, i.e., */ + /* the size of the template segment. */ + ps->l_seg = ( ps->rate / 100 ) * ps->num_channels; + + /* set frame size */ + /* set to 320 samples at 16 kHz */ + ps->l_frm = ( ps->rate / FRAMES_PER_SEC ) * ps->num_channels; + + /* set minimum pitch */ + /* set to 40 samples at 16 kHz */ + /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ + ps->p_min = ( ps->rate / 400 ) * ps->num_channels; + + /* set search length */ + /* must cover one pitch, set to 200 samples at 16 kHz */ + /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ + ps->l_search = ( ps->rate / 80 ) * ps->num_channels; + return 0; +} +#endif /* Sets the audio configuration. */ bool apa_set_rate( @@ -474,7 +528,7 @@ bool apa_set_rate( ps->l_search = ( ps->rate / 80 ) * ps->num_channels; #ifdef IVAS_FLOAT_FIXED - ps->win_fx = pcmdsp_window_hann_640; + ps->win_fx = (Word16 *)pcmdsp_window_hann_640; move16(); ps->l_halfwin = 320; move16(); @@ -482,14 +536,14 @@ bool apa_set_rate( move16(); IF( EQ_32( ps->rate, 48000 ) ) { - ps->win_fx = pcmdsp_window_hann_960; + ps->win_fx = (Word16 *)pcmdsp_window_hann_960; move16(); ps->l_halfwin = 480; move16(); } IF( EQ_32( ps->rate, 24000 ) ) { - ps->win_fx = pcmdsp_window_hann_960; + ps->win_fx = (Word16 *)pcmdsp_window_hann_960; move16(); ps->l_halfwin = 480; move16(); @@ -817,6 +871,31 @@ bool apa_set_complexity_options( * ******************************************************************************** */ +#ifdef IVAS_FLOAT_FIXED +bool apa_exit( + apa_state_t **pps ) +{ + /* ignore NULL pointer input */ + if ( *pps == NULL ) + { + return 0; + } + + /* deallocate state struct members */ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + free( ( *pps )->buf_out ); +#endif + free( ( *pps )->buf_out_fx ); + + /* deallocate state struct */ + free( *pps ); + + /* set pointer to NULL */ + *pps = NULL; + + return 0; +} +#else bool apa_exit( apa_state_t **pps ) { @@ -837,6 +916,7 @@ bool apa_exit( return 0; } +#endif /* ******************************************************************************** diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 5f29ce870..3fc81c1b1 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -466,11 +466,11 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( move16(); hTonalMDCTConc->secondLastBlockData.nSamples = nOldSamples; move16(); - nOldSamples = hTonalMDCTConc->lastBlockData.nSamplesCore; + nOldSamples = (Word16)hTonalMDCTConc->lastBlockData.nSamplesCore; move16(); - hTonalMDCTConc->lastBlockData.nSamplesCore = nNewSamplesCore; + hTonalMDCTConc->lastBlockData.nSamplesCore = (UWord16)nNewSamplesCore; move16(); - hTonalMDCTConc->secondLastBlockData.nSamplesCore = nOldSamples; + hTonalMDCTConc->secondLastBlockData.nSamplesCore = (UWord16)nOldSamples; move16(); } diff --git a/lib_rend/ivas_masa_merge.c b/lib_rend/ivas_masa_merge.c index 527e19bbd..43bead2e1 100644 --- a/lib_rend/ivas_masa_merge.c +++ b/lib_rend/ivas_masa_merge.c @@ -219,16 +219,16 @@ void diffuse_meta_merge_1x1_fx( ) { Word8 sf, band; - Word16 i,j, max_e, in1_e[MASA_FREQUENCY_BANDS]; + Word16 i, max_e, in1_e[MASA_FREQUENCY_BANDS]; FOR ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { FOR ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) { - Word32 energyTimesRatio_fx, energyTimesRatioISM_fx, total_diff_nrg_fx, dir_nrg_ratio_fx, total_nrg_fx; + Word32 energyTimesRatio_fx, energyTimesRatioISM_fx, total_diff_nrg_fx = 0, dir_nrg_ratio_fx, total_nrg_fx = 0; Word32 dir_ratio_ism_fx, L_tmp1,L_tmp2; - Word16 scale, energyTimesRatio_e, tmp, total_nrg_e, total_diff_nrg_e, dir_ratio_ism_e, energyTimesRatioISM_e, dir_nrg_ratio_e ; + Word16 scale, energyTimesRatio_e, tmp, total_nrg_e = 0, total_diff_nrg_e, dir_ratio_ism_e, energyTimesRatioISM_e, dir_nrg_ratio_e ; tmp = BASOP_Util_Divide1616_Scale((Word16)inMeta->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &scale); energyTimesRatio_fx = Mpy_32_16_r( inEne_fx[sf][band], tmp); @@ -277,7 +277,7 @@ void diffuse_meta_merge_1x1_fx( outMeta->directToTotalRatio[0][sf][band] = (uint8_t) ( L_shr( new_dir_ratio_fx, 31 - new_dir_ratio_e ) * UINT8_MAX ); new_diff_ratio_fx = L_shl( 1, 31 - new_dir_ratio_e ) - new_dir_ratio_fx; - outMeta->diffuseToTotalRatio[sf][band] = (uint8_t) floorf( L_shr( new_diff_ratio_fx, new_dir_ratio_e) * UINT8_MAX ); + outMeta->diffuseToTotalRatio[sf][band] = (uint8_t) ( L_shr( new_diff_ratio_fx, new_dir_ratio_e) * UINT8_MAX ); } ELSE { @@ -297,13 +297,13 @@ void diffuse_meta_merge_1x1_fx( } max_e = in1_e[0]; - FOR(Word16 i = 1; i < MASA_FREQUENCY_BANDS; i++) + FOR( i = 1; i < MASA_FREQUENCY_BANDS; i++) { IF(max_e < in1_e[i]) max_e = in1_e[i]; } - FOR(Word16 i = 0; i < MASA_FREQUENCY_BANDS; i++) + FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++) { inEne_fx[sf][i] = L_shr(inEne_fx[sf][i], max_e - in1_e[i]); } diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 545fddc1b..a8bf2de31 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -899,12 +899,15 @@ ivas_error ivas_td_binaural_renderer_unwrap( /* Render subframe */ #ifdef IVAS_FLOAT_FIXED ////// Float to fix ///// - FOR(Word16 i = 0; i < hBinRendererTd->NumOfSrcs; i++) + FOR( Word16 i = 0; i < hBinRendererTd->NumOfSrcs; i++ ) { - FOR (int j = 0; j < 3; j++) + FOR( int j = 0; j < 3; j++ ) { - hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j] = float_to_fix(hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p[j], Q25); + hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j] = float_to_fix( hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p[j], Q25 ); + + //hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j] = L_shr( hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j], hBinRendererTd->Sources[i]->SrcSpatial_p->q_Pos_p - Q25 ); } + hBinRendererTd->Sources[i]->SrcSpatial_p->q_Pos_p = 25; } IF ( ( error = TDREND_GetMix_fx( hBinRendererTd, output_fx, subframe_length, subframe_idx, ism_md_subframe_update ) ) != IVAS_ERR_OK ) { diff --git a/lib_rend/ivas_omasa_ana.c b/lib_rend/ivas_omasa_ana.c index e7165ed25..d04bcf475 100644 --- a/lib_rend/ivas_omasa_ana.c +++ b/lib_rend/ivas_omasa_ana.c @@ -494,7 +494,6 @@ void ivas_omasa_ana( #ifdef IVAS_FLOAT_FIXED void ivas_omasa_ana_fx( OMASA_ANA_HANDLE hOMasa, /* i/o: OMASA analysis handle */ - float data_in_f[][L_FRAME48k], /* i/o: Input / transport audio signals */ Word32 data_in_f_fx[][L_FRAME48k], /* i/o: Input / transport audio signals */ Word16 *data_in_q, const Word16 input_frame, /* i : Input frame size */ @@ -741,19 +740,23 @@ static void ivas_omasa_param_est_ana_fx( Word32 reference_power_fx[MASA_FREQUENCY_BANDS]; Word32 Chnl_RealBuffer_fx[MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; - Word16 Chnl_RealBuffer_q; - Word16 Chnl_ImagBuffer_q; + Word16 Chnl_RealBuffer_q = 0; + move16(); + Word16 Chnl_ImagBuffer_q = 0; + move16(); Word32 Chnl_ImagBuffer_fx[MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; Word32 Foa_RealBuffer_fx[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX]; Word32 Foa_ImagBuffer_fx[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX]; Word32 intensity_real_fx[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; Word32 direction_vector_fx[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; Word32 diffuseness_vector_fx[MASA_FREQUENCY_BANDS]; - Word16 diffuseness_q; + Word16 diffuseness_q = 0; + move16(); Word32 diffuseness_m_fx[MASA_FREQUENCY_BANDS]; - Word16 diffuseness_m_q; + Word16 diffuseness_m_q = 0; Word32 renormalization_factor_diff_fx[MASA_FREQUENCY_BANDS]; - Word16 renormalization_factor_diff_q; + Word16 renormalization_factor_diff_q = 0; + move16(); Word32 norm_tmp_fx; Word16 scale; @@ -779,7 +782,7 @@ static void ivas_omasa_param_est_ana_fx( /* Compute ISM to FOA matrices */ FOR ( i = 0; i < nchan_ism; i++ ) { - Word16 tmp, tmp1, scale; + Word16 tmp, tmp1; // 180 in Q22 754974720 hOMasa->chnlToFoaMtx_fx[0][i] = 32767; // 1 in Q15 move16(); @@ -986,7 +989,7 @@ static void ivas_omasa_param_est_ana_fx( } dir_v_q = hOMasa->direction_vector_m_q; - FOR (Word16 i = 0; i < DIRAC_NUM_DIMS; i++) + FOR ( i = 0; i < DIRAC_NUM_DIMS; i++) { dir_v_fx[i] = L_shr(dir_v_fx[i], 1); } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 727326b40..a3e349c7b 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -2671,7 +2671,6 @@ void ivas_omasa_ana( #ifdef IVAS_FLOAT_FIXED void ivas_omasa_ana_fx( OMASA_ANA_HANDLE hOMasa, /* i/o: OMASA analysis handle */ - float data_in_f[][L_FRAME48k], /* i/o: Input / transport audio signals */ Word32 data_in_f_fx[][L_FRAME48k], /* i/o: Input / transport audio signals */ Word16 *q, const Word16 input_frame, /* i : Input frame size */ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 731afcdd0..aec0c3ebc 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1802,6 +1802,7 @@ typedef struct float Front_p[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; #ifdef IVAS_FLOAT_FIXED Word32 Pos_p_fx[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; // Q25 + Word16 q_Pos_p; Word32 Front_p_fx[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; // Q30 #endif // IVAS_FLOAT_FIXED int16_t DirAttenEnabled; @@ -2310,6 +2311,7 @@ typedef struct ivas_mcmasa_ana_data_structure Word16 interpolator_fx[L_FRAME48k]; Word32 energy_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 energy_exp[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 chnlToFoaMtx_e; Word16 prevMultiChEne_e; Word16 prevDownmixEne_e; @@ -2403,7 +2405,7 @@ typedef struct ivas_omasa_ana_data_structure Word32 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; Word32 buffer_energy_fx[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; Word16 buffer_intensity_real_q[DIRAC_NO_COL_AVG_DIFF]; - Word32 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF]; + Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF]; Word16 chnlToFoaMtx_fx[FOA_CHANNELS][MCMASA_MAX_ANA_CHANS]; // Q15 #endif @@ -2450,6 +2452,7 @@ typedef struct ivas_dirac_ana_data_structure #ifdef IVAS_FLOAT_FIXED Word32 energy_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 energy_exp[MAX_PARAM_SPATIAL_SUBFRAMES]; #endif } DIRAC_ANA_DATA, *DIRAC_ANA_HANDLE; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index a1f9b9954..9c1d72b5a 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1628,7 +1628,7 @@ static ivas_error initEfap( IF( outConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { - IF ( ( error = efap_init_data_fx( &pEfapWrapper->hEfap, pCustomLsOut->ls_azimuth_fx, pCustomLsOut->ls_elevation_fx, pCustomLsOut->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( ( error = efap_init_data_fx( &pEfapWrapper->hEfap, pCustomLsOut->ls_azimuth_fx, pCustomLsOut->ls_elevation_fx, pCustomLsOut->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } @@ -1658,71 +1658,71 @@ static ivas_error initEfap( return IVAS_ERR_OK; } #else - static ivas_error initEfap( - EFAP_WRAPPER * pEfapWrapper, - AUDIO_CONFIG outConfig, - const LSSETUP_CUSTOM_STRUCT *pCustomLsOut ) - { - ivas_error error; - const float *azimuths; - const float *elevations; - int16_t numNonLfeChannels; - - if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - { - pEfapWrapper->speakerConfig = IVAS_AUDIO_CONFIG_7_1_4; - } - else - { - pEfapWrapper->speakerConfig = outConfig; - } - pEfapWrapper->pCustomLsSetup = pCustomLsOut; +static ivas_error initEfap( + EFAP_WRAPPER *pEfapWrapper, + AUDIO_CONFIG outConfig, + const LSSETUP_CUSTOM_STRUCT *pCustomLsOut ) +{ + ivas_error error; + const float *azimuths; + const float *elevations; + int16_t numNonLfeChannels; - /* If re-initializing, free existing EFAP handle. */ - if ( pEfapWrapper->hEfap != NULL ) - { - efap_free_data( &pEfapWrapper->hEfap ); - } + if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + pEfapWrapper->speakerConfig = IVAS_AUDIO_CONFIG_7_1_4; + } + else + { + pEfapWrapper->speakerConfig = outConfig; + } + pEfapWrapper->pCustomLsSetup = pCustomLsOut; - /* Only initialize EFAP handle if output config is channel-based */ - if ( getAudioConfigType( pEfapWrapper->speakerConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) - { - pEfapWrapper->hEfap = NULL; - return IVAS_ERR_OK; - } + /* If re-initializing, free existing EFAP handle. */ + if ( pEfapWrapper->hEfap != NULL ) + { + efap_free_data( &pEfapWrapper->hEfap ); + } - if ( outConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) - { - if ( ( error = efap_init_data( &pEfapWrapper->hEfap, pCustomLsOut->ls_azimuth, pCustomLsOut->ls_elevation, pCustomLsOut->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else - { - if ( ( error = getSpeakerAzimuths( pEfapWrapper->speakerConfig, &azimuths ) ) != IVAS_ERR_OK ) - { - return error; - } + /* Only initialize EFAP handle if output config is channel-based */ + if ( getAudioConfigType( pEfapWrapper->speakerConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) + { + pEfapWrapper->hEfap = NULL; + return IVAS_ERR_OK; + } - if ( ( error = getSpeakerElevations( pEfapWrapper->speakerConfig, &elevations ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( outConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + if ( ( error = efap_init_data( &pEfapWrapper->hEfap, pCustomLsOut->ls_azimuth, pCustomLsOut->ls_elevation, pCustomLsOut->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = getSpeakerAzimuths( pEfapWrapper->speakerConfig, &azimuths ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = getNumNonLfeChannelsInSpeakerLayout( pEfapWrapper->speakerConfig, &numNonLfeChannels ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getSpeakerElevations( pEfapWrapper->speakerConfig, &elevations ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = efap_init_data( &pEfapWrapper->hEfap, azimuths, elevations, numNonLfeChannels, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) - { - return error; - } - } + if ( ( error = getNumNonLfeChannelsInSpeakerLayout( pEfapWrapper->speakerConfig, &numNonLfeChannels ) ) != IVAS_ERR_OK ) + { + return error; + } - return IVAS_ERR_OK; + if ( ( error = efap_init_data( &pEfapWrapper->hEfap, azimuths, elevations, numNonLfeChannels, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + { + return error; } + } + + return IVAS_ERR_OK; +} #endif #ifdef IVAS_FLOAT_FIXED @@ -1794,67 +1794,67 @@ static ivas_error getEfapGains_fx( return IVAS_ERR_OK; } #else - static ivas_error getEfapGains( - EFAP_WRAPPER efapWrapper, - const float azi, - const float ele, - pan_vector panGains ) - { - pan_vector tmpPanGains; /* tmp pan gain buffer without LFE channels */ - float *readPtr; - int16_t i; - int16_t lfeCount; - int16_t numChannels; - ivas_error error; +static ivas_error getEfapGains( + EFAP_WRAPPER efapWrapper, + const float azi, + const float ele, + pan_vector panGains ) +{ + pan_vector tmpPanGains; /* tmp pan gain buffer without LFE channels */ + float *readPtr; + int16_t i; + int16_t lfeCount; + int16_t numChannels; + ivas_error error; - /* EFAP returns an array of gains only for non-LFE speakers */ - efap_determine_gains( efapWrapper.hEfap, tmpPanGains, azi, ele, EFAP_MODE_EFAP ); + /* EFAP returns an array of gains only for non-LFE speakers */ + efap_determine_gains( efapWrapper.hEfap, tmpPanGains, azi, ele, EFAP_MODE_EFAP ); - /* Now copy to buffer that includes LFE channels */ - if ( efapWrapper.speakerConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) - { - numChannels = efapWrapper.pCustomLsSetup->num_spk + efapWrapper.pCustomLsSetup->num_lfe; - readPtr = tmpPanGains; + /* Now copy to buffer that includes LFE channels */ + if ( efapWrapper.speakerConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + numChannels = efapWrapper.pCustomLsSetup->num_spk + efapWrapper.pCustomLsSetup->num_lfe; + readPtr = tmpPanGains; - for ( i = 0, lfeCount = 0; i < numChannels; ++i ) - { - if ( lfeCount < efapWrapper.pCustomLsSetup->num_lfe && i == efapWrapper.pCustomLsSetup->lfe_idx[lfeCount] ) - { - panGains[i] = 0.0f; - ++lfeCount; - } - else - { - panGains[i] = *readPtr; - ++readPtr; - } - } + for ( i = 0, lfeCount = 0; i < numChannels; ++i ) + { + if ( lfeCount < efapWrapper.pCustomLsSetup->num_lfe && i == efapWrapper.pCustomLsSetup->lfe_idx[lfeCount] ) + { + panGains[i] = 0.0f; + ++lfeCount; } else { - if ( ( error = getAudioConfigNumChannels( efapWrapper.speakerConfig, &numChannels ) ) != IVAS_ERR_OK ) - { - return error; - } + panGains[i] = *readPtr; + ++readPtr; + } + } + } + else + { + if ( ( error = getAudioConfigNumChannels( efapWrapper.speakerConfig, &numChannels ) ) != IVAS_ERR_OK ) + { + return error; + } - readPtr = tmpPanGains; + readPtr = tmpPanGains; - for ( i = 0; i < numChannels; ++i ) - { - if ( i == LFE_CHANNEL ) - { - panGains[i] = 0.0f; - } - else - { - panGains[i] = *readPtr; - ++readPtr; - } - } + for ( i = 0; i < numChannels; ++i ) + { + if ( i == LFE_CHANNEL ) + { + panGains[i] = 0.0f; + } + else + { + panGains[i] = *readPtr; + ++readPtr; } - - return IVAS_ERR_OK; } + } + + return IVAS_ERR_OK; +} #endif #ifdef IVAS_FLOAT_FIXED @@ -1900,43 +1900,43 @@ static ivas_error initHeadRotation_fx( return IVAS_ERR_OK; } #else - static ivas_error initHeadRotation( - IVAS_REND_HANDLE hIvasRend ) - { - int16_t i, crossfade_len; - float tmp; - ivas_error error; +static ivas_error initHeadRotation( + IVAS_REND_HANDLE hIvasRend ) +{ + int16_t i, crossfade_len; + float tmp; + ivas_error error; - /* Head rotation is enabled by default */ - hIvasRend->headRotData.headRotEnabled = 1; + /* Head rotation is enabled by default */ + hIvasRend->headRotData.headRotEnabled = 1; - /* Initialize 5ms crossfade */ - crossfade_len = L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES; - tmp = 1.f / ( crossfade_len - 1 ); - for ( i = 0; i < crossfade_len; i++ ) - { - hIvasRend->headRotData.crossfade[i] = i * tmp; - } + /* Initialize 5ms crossfade */ + crossfade_len = L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES; + tmp = 1.f / ( crossfade_len - 1 ); + for ( i = 0; i < crossfade_len; i++ ) + { + hIvasRend->headRotData.crossfade[i] = i * tmp; + } - /* Initialize with unit quaternions */ - for ( i = 0; i < hIvasRend->num_subframes; ++i ) - { - hIvasRend->headRotData.headPositions[i] = quaternionInit(); - } + /* Initialize with unit quaternions */ + 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 ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Orientation tracking" ); - } + 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 ) - { - return error; - } + if ( ( error = ivas_orient_trk_Init( hIvasRend->headRotData.hOrientationTracker ) ) != IVAS_ERR_OK ) + { + return error; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif @@ -1953,16 +1953,16 @@ static void closeHeadRotation( return; } #else - static void closeHeadRotation( - IVAS_REND_HANDLE hIvasRend ) - { - if ( ( hIvasRend != NULL ) && ( hIvasRend->headRotData.hOrientationTracker != NULL ) ) - { - free( hIvasRend->headRotData.hOrientationTracker ); - } +static void closeHeadRotation( + IVAS_REND_HANDLE hIvasRend ) +{ + if ( ( hIvasRend != NULL ) && ( hIvasRend->headRotData.hOrientationTracker != NULL ) ) + { + free( hIvasRend->headRotData.hOrientationTracker ); + } - return; - } + return; +} #endif @@ -2138,17 +2138,17 @@ static TDREND_WRAPPER defaultTdRendWrapper( return w; } #else - static TDREND_WRAPPER defaultTdRendWrapper( - void ) - { - TDREND_WRAPPER w; +static TDREND_WRAPPER defaultTdRendWrapper( + void ) +{ + TDREND_WRAPPER w; - w.binaural_latency_ns = 0; - w.hBinRendererTd = NULL; - w.hHrtfTD = NULL; + w.binaural_latency_ns = 0; + w.hBinRendererTd = NULL; + w.hHrtfTD = NULL; - return w; - } + return w; +} #endif @@ -2169,19 +2169,19 @@ static bool isIoConfigPairSupported( return true; } #else - static bool isIoConfigPairSupported( - const AUDIO_CONFIG inConfig, - const AUDIO_CONFIG outConfig ) - { - /* Rendering mono or stereo to binaural is not supported */ - if ( ( inConfig == IVAS_AUDIO_CONFIG_MONO || inConfig == IVAS_AUDIO_CONFIG_STEREO ) && getAudioConfigType( outConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) - { - return false; - } +static bool isIoConfigPairSupported( + const AUDIO_CONFIG inConfig, + const AUDIO_CONFIG outConfig ) +{ + /* Rendering mono or stereo to binaural is not supported */ + if ( ( inConfig == IVAS_AUDIO_CONFIG_MONO || inConfig == IVAS_AUDIO_CONFIG_STEREO ) && getAudioConfigType( outConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) + { + return false; + } - /* If not returned so far, config pair is supported */ - return true; - } + /* If not returned so far, config pair is supported */ + return true; +} #endif @@ -2196,7 +2196,7 @@ static ivas_error initIsmMasaRendering( #ifdef IVAS_FLOAT_FIXED ivas_td_binaural_close_fx( &inputIsm->tdRendWrapper.hBinRendererTd ); #else - ivas_td_binaural_close( &inputIsm->tdRendWrapper.hBinRendererTd ); + ivas_td_binaural_close( &inputIsm->tdRendWrapper.hBinRendererTd ); #endif // IVAS_FLOAT_FIXED inputIsm->tdRendWrapper.hHrtfTD = NULL; } @@ -2297,14 +2297,16 @@ static ivas_error setRendInputActiveIsm( fixedToFloat_arrL( Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3 ); fixedToFloat_arrL( Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3 ); } + Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = inputIsm->tdRendWrapper.hBinRendererTd->Sources[nS]->SrcSpatial_p; fixedToFloat_arrL( SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3 ); fixedToFloat_arrL( SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3 ); + SrcSpatial_p->q_Pos_p = Q31; } } #else - if ((error = ivas_td_binaural_open_ext(&inputIsm->tdRendWrapper, inConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate)) != IVAS_ERR_OK) + if ( ( error = ivas_td_binaural_open_ext( &inputIsm->tdRendWrapper, inConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -2319,10 +2321,10 @@ static ivas_error setRendInputActiveIsm( return error; } #else - if ( ( error = ivas_reverb_open( &( inputIsm->hReverb ), outConfig, NULL, inputIsm->tdRendWrapper.hBinRendererTd->HrFiltSet_p->lr_energy_and_iac, hRendCfg, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_reverb_open( &( inputIsm->hReverb ), outConfig, NULL, inputIsm->tdRendWrapper.hBinRendererTd->HrFiltSet_p->lr_energy_and_iac, hRendCfg, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } #endif // IVAS_FLOAT_FIXED } } @@ -2351,7 +2353,7 @@ static void clearInputIsm( #ifdef IVAS_FLOAT_FIXED ivas_td_binaural_close_fx( &inputIsm->tdRendWrapper.hBinRendererTd ); #else - ivas_td_binaural_close( &inputIsm->tdRendWrapper.hBinRendererTd ); + ivas_td_binaural_close( &inputIsm->tdRendWrapper.hBinRendererTd ); #endif inputIsm->tdRendWrapper.hHrtfTD = NULL; } @@ -2397,29 +2399,29 @@ static void copyLsConversionMatrixToPanMatrix_fx( } #else - static void copyLsConversionMatrixToPanMatrix( - const LS_CONVERSION_MATRIX *lsConvMatrix, - pan_matrix panMatrix ) - { - int16_t i; - int16_t inCh, outCh; - int16_t numNonZeroGains; - int16_t numColumns; +static void copyLsConversionMatrixToPanMatrix( + const LS_CONVERSION_MATRIX *lsConvMatrix, + pan_matrix panMatrix ) +{ + int16_t i; + int16_t inCh, outCh; + int16_t numNonZeroGains; + int16_t numColumns; - /* Index 0 is special and describes the following values */ - numNonZeroGains = lsConvMatrix[0].index; - numColumns = (int16_t) lsConvMatrix[0].value; + /* Index 0 is special and describes the following values */ + numNonZeroGains = lsConvMatrix[0].index; + numColumns = (int16_t) lsConvMatrix[0].value; - for ( i = 1; i < numNonZeroGains + 1; ++i ) - { - inCh = lsConvMatrix[i].index / numColumns; - outCh = lsConvMatrix[i].index % numColumns; + for ( i = 1; i < numNonZeroGains + 1; ++i ) + { + inCh = lsConvMatrix[i].index / numColumns; + outCh = lsConvMatrix[i].index % numColumns; - panMatrix[inCh][outCh] = lsConvMatrix[i].value; - } + panMatrix[inCh][outCh] = lsConvMatrix[i].value; + } - return; - } + return; +} #endif static void setZeroPanMatrix( pan_matrix panMatrix ) @@ -2463,19 +2465,19 @@ static void fillIdentityPanMatrix_fx( return; } #else - /* Note: this only sets non-zero elements, call setZeroPanMatrix() to init first. */ - static void fillIdentityPanMatrix( - pan_matrix panMatrix ) - { - int16_t i; +/* Note: this only sets non-zero elements, call setZeroPanMatrix() to init first. */ +static void fillIdentityPanMatrix( + pan_matrix panMatrix ) +{ + int16_t i; - for ( i = 0; i < min( MAX_INPUT_CHANNELS, MAX_OUTPUT_CHANNELS ); ++i ) - { - panMatrix[i][i] = 1.0f; - } + for ( i = 0; i < min( MAX_INPUT_CHANNELS, MAX_OUTPUT_CHANNELS ); ++i ) + { + panMatrix[i][i] = 1.0f; + } - return; - } + return; +} #endif #ifdef IVAS_FLOAT_FIXED static ivas_error initMcPanGainsWithIdentMatrix( @@ -2486,13 +2488,13 @@ static ivas_error initMcPanGainsWithIdentMatrix( return IVAS_ERR_OK; } #else - static ivas_error initMcPanGainsWithIdentMatrix( - input_mc * inputMc ) - { - fillIdentityPanMatrix( inputMc->panGains ); +static ivas_error initMcPanGainsWithIdentMatrix( + input_mc *inputMc ) +{ + fillIdentityPanMatrix( inputMc->panGains ); - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif #ifdef IVAS_FLOAT_FIXED @@ -2534,39 +2536,39 @@ static ivas_error initMcPanGainsWithConversionMapping_fx( } #else - static ivas_error initMcPanGainsWithConversionMapping( - input_mc * inputMc, - const AUDIO_CONFIG outConfig ) - { - AUDIO_CONFIG ivasConfigIn, ivasConfigOut; - int16_t i; +static ivas_error initMcPanGainsWithConversionMapping( + input_mc *inputMc, + const AUDIO_CONFIG outConfig ) +{ + AUDIO_CONFIG ivasConfigIn, ivasConfigOut; + int16_t i; - ivasConfigIn = inputMc->base.inConfig; - ivasConfigOut = outConfig; + ivasConfigIn = inputMc->base.inConfig; + ivasConfigOut = outConfig; - /* Find conversion mapping for current I/O config pair. - * Stay with default panning matrix if conversion_matrix is NULL */ - for ( i = 0; i < LS_SETUP_CONVERSION_NUM_MAPPINGS; ++i ) + /* Find conversion mapping for current I/O config pair. + * Stay with default panning matrix if conversion_matrix is NULL */ + for ( i = 0; i < LS_SETUP_CONVERSION_NUM_MAPPINGS; ++i ) + { + if ( ls_conversion_mapping[i].input_config == ivasConfigIn && ls_conversion_mapping[i].output_config == ivasConfigOut ) + { + /* Mapping found with valid matrix - copy */ + if ( ls_conversion_mapping[i].conversion_matrix != NULL ) { - if ( ls_conversion_mapping[i].input_config == ivasConfigIn && ls_conversion_mapping[i].output_config == ivasConfigOut ) - { - /* Mapping found with valid matrix - copy */ - if ( ls_conversion_mapping[i].conversion_matrix != NULL ) - { - copyLsConversionMatrixToPanMatrix( ls_conversion_mapping[i].conversion_matrix, inputMc->panGains ); - } - /* Mapping found with NULL matrix - use identity matrix */ - else - { - fillIdentityPanMatrix( inputMc->panGains ); - } - - return IVAS_ERR_OK; - } + copyLsConversionMatrixToPanMatrix( ls_conversion_mapping[i].conversion_matrix, inputMc->panGains ); + } + /* Mapping found with NULL matrix - use identity matrix */ + else + { + fillIdentityPanMatrix( inputMc->panGains ); } - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Missing multichannel conversion mapping" ); + return IVAS_ERR_OK; } + } + + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Missing multichannel conversion mapping" ); +} #endif #ifdef IVAS_FLOAT_FIXED static ivas_error initMcPanGainsWithEfap_fx( @@ -2645,71 +2647,71 @@ static ivas_error initMcPanGainsWithEfap_fx( return IVAS_ERR_OK; } #else - static ivas_error initMcPanGainsWithEfap( - input_mc * inputMc, - const AUDIO_CONFIG outConfig ) - { - int16_t i; - int16_t numNonLfeInChannels; - int16_t inLfeChIdx, outChIdx; - const float *spkAzi, *spkEle; - ivas_error error; +static ivas_error initMcPanGainsWithEfap( + input_mc *inputMc, + const AUDIO_CONFIG outConfig ) +{ + int16_t i; + int16_t numNonLfeInChannels; + int16_t inLfeChIdx, outChIdx; + const float *spkAzi, *spkEle; + ivas_error error; - if ( inputMc->base.inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM ) - { - if ( ( error = getNumNonLfeChannelsInSpeakerLayout( inputMc->base.inConfig, &numNonLfeInChannels ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( inputMc->base.inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + if ( ( error = getNumNonLfeChannelsInSpeakerLayout( inputMc->base.inConfig, &numNonLfeInChannels ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = getSpeakerAzimuths( inputMc->base.inConfig, &spkAzi ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getSpeakerAzimuths( inputMc->base.inConfig, &spkAzi ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = getSpeakerElevations( inputMc->base.inConfig, &spkEle ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getSpeakerElevations( inputMc->base.inConfig, &spkEle ) ) != IVAS_ERR_OK ) + { + return error; + } - inLfeChIdx = LFE_CHANNEL; - } - else - { - numNonLfeInChannels = inputMc->customLsInput.num_spk; - spkAzi = inputMc->customLsInput.ls_azimuth; - spkEle = inputMc->customLsInput.ls_elevation; - inLfeChIdx = -1; - if ( inputMc->customLsInput.num_lfe > 0 ) - { - inLfeChIdx = inputMc->customLsInput.lfe_idx[0]; - } - } + inLfeChIdx = LFE_CHANNEL; + } + else + { + numNonLfeInChannels = inputMc->customLsInput.num_spk; + spkAzi = inputMc->customLsInput.ls_azimuth; + spkEle = inputMc->customLsInput.ls_elevation; + inLfeChIdx = -1; + if ( inputMc->customLsInput.num_lfe > 0 ) + { + inLfeChIdx = inputMc->customLsInput.lfe_idx[0]; + } + } - for ( i = 0, outChIdx = 0; i < numNonLfeInChannels; ++i, ++outChIdx ) - { - if ( i == inLfeChIdx ) - { - ++outChIdx; - } + for ( i = 0, outChIdx = 0; i < numNonLfeInChannels; ++i, ++outChIdx ) + { + if ( i == inLfeChIdx ) + { + ++outChIdx; + } - if ( ( error = getEfapGains( *inputMc->base.ctx.pEfapOutWrapper, spkAzi[i], spkEle[i], inputMc->panGains[outChIdx] ) ) != IVAS_ERR_OK ) - { - return error; - } - } + if ( ( error = getEfapGains( *inputMc->base.ctx.pEfapOutWrapper, spkAzi[i], spkEle[i], inputMc->panGains[outChIdx] ) ) != IVAS_ERR_OK ) + { + return error; + } + } - if ( outConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM && inLfeChIdx >= 0 ) - { - inputMc->panGains[inLfeChIdx][LFE_CHANNEL] = 1; - } - else if ( inputMc->base.ctx.pCustomLsOut->num_lfe > 0 && inLfeChIdx >= 0 ) - { - inputMc->panGains[inLfeChIdx][inputMc->base.ctx.pCustomLsOut->lfe_idx[0]] = 1; - } + if ( outConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM && inLfeChIdx >= 0 ) + { + inputMc->panGains[inLfeChIdx][LFE_CHANNEL] = 1; + } + else if ( inputMc->base.ctx.pCustomLsOut->num_lfe > 0 && inLfeChIdx >= 0 ) + { + inputMc->panGains[inLfeChIdx][inputMc->base.ctx.pCustomLsOut->lfe_idx[0]] = 1; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif #ifdef IVAS_FLOAT_FIXED static ivas_error getRendInputNumChannels( @@ -2741,34 +2743,34 @@ static ivas_error getRendInputNumChannels( return IVAS_ERR_OK; } #else - static ivas_error getRendInputNumChannels( - const void *rendInput, - int16_t *numInChannels ) - { - /* Using a void pointer for this function to be reusable for any input type (input_ism, input_mc, input_sba). - Assumptions: - input_base is always the first member in the input struct */ - - ivas_error error; - const input_base *pInputBase; - const input_mc *pInputMc; +static ivas_error getRendInputNumChannels( + const void *rendInput, + int16_t *numInChannels ) +{ + /* Using a void pointer for this function to be reusable for any input type (input_ism, input_mc, input_sba). + Assumptions: - input_base is always the first member in the input struct */ - pInputBase = (const input_base *) rendInput; + ivas_error error; + const input_base *pInputBase; + const input_mc *pInputMc; - if ( pInputBase->inConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) - { - pInputMc = (const input_mc *) rendInput; - *numInChannels = pInputMc->customLsInput.num_spk + pInputMc->customLsInput.num_lfe; - } - else - { - if ( ( error = getAudioConfigNumChannels( pInputBase->inConfig, numInChannels ) ) != IVAS_ERR_OK ) - { - return error; - } - } + pInputBase = (const input_base *) rendInput; - return IVAS_ERR_OK; + if ( pInputBase->inConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + pInputMc = (const input_mc *) rendInput; + *numInChannels = pInputMc->customLsInput.num_spk + pInputMc->customLsInput.num_lfe; + } + else + { + if ( ( error = getAudioConfigNumChannels( pInputBase->inConfig, numInChannels ) ) != IVAS_ERR_OK ) + { + return error; } + } + + return IVAS_ERR_OK; +} #endif #ifdef IVAS_FLOAT_FIXED static ivas_error initMcPanGainsWithMonoOut_fx( @@ -3046,55 +3048,55 @@ static bool configsAreEqual( return configA == configB; } #else - static bool configsAreEqual( - const AUDIO_CONFIG configA, - const LSSETUP_CUSTOM_STRUCT customLsA, - const AUDIO_CONFIG configB, - const LSSETUP_CUSTOM_STRUCT customLsB ) - { - int16_t i; - - /* Both input and output are custom LS - compare structs */ - if ( configA == IVAS_AUDIO_CONFIG_LS_CUSTOM && configB == IVAS_AUDIO_CONFIG_LS_CUSTOM ) - { - if ( customLsA.num_spk != customLsB.num_spk ) - { - return false; - } +static bool configsAreEqual( + const AUDIO_CONFIG configA, + const LSSETUP_CUSTOM_STRUCT customLsA, + const AUDIO_CONFIG configB, + const LSSETUP_CUSTOM_STRUCT customLsB ) +{ + int16_t i; - if ( customLsA.num_lfe != customLsB.num_lfe ) - { - return false; - } + /* Both input and output are custom LS - compare structs */ + if ( configA == IVAS_AUDIO_CONFIG_LS_CUSTOM && configB == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + if ( customLsA.num_spk != customLsB.num_spk ) + { + return false; + } - if ( customLsA.is_planar_setup != customLsB.is_planar_setup ) - { - return false; - } + if ( customLsA.num_lfe != customLsB.num_lfe ) + { + return false; + } - for ( i = 0; i < customLsA.num_spk; ++i ) - { - /* Compare to nearest degree (hence the int16_t cast) */ - if ( (int16_t) customLsA.ls_azimuth[i] != (int16_t) customLsB.ls_azimuth[i] || - (int16_t) customLsA.ls_elevation[i] != (int16_t) customLsB.ls_elevation[i] ) - { - return false; - } - } - for ( i = 0; i < customLsA.num_lfe; ++i ) - { - if ( customLsA.lfe_idx[i] != customLsB.lfe_idx[i] ) - { - return false; - } - } + if ( customLsA.is_planar_setup != customLsB.is_planar_setup ) + { + return false; + } - return true; + for ( i = 0; i < customLsA.num_spk; ++i ) + { + /* Compare to nearest degree (hence the int16_t cast) */ + if ( (int16_t) customLsA.ls_azimuth[i] != (int16_t) customLsB.ls_azimuth[i] || + (int16_t) customLsA.ls_elevation[i] != (int16_t) customLsB.ls_elevation[i] ) + { + return false; + } + } + for ( i = 0; i < customLsA.num_lfe; ++i ) + { + if ( customLsA.lfe_idx[i] != customLsB.lfe_idx[i] ) + { + return false; } - - /* Otherwise it's enough to compare config enums */ - return configA == configB; } + + return true; + } + + /* Otherwise it's enough to compare config enums */ + return configA == configB; +} #endif #ifdef IVAS_FLOAT_FIXED static ivas_error updateLfePanGainsForMcOut( @@ -3140,48 +3142,48 @@ static ivas_error updateLfePanGainsForMcOut( return error; } #else - static ivas_error updateLfePanGainsForMcOut( - input_mc * inputMc, - const AUDIO_CONFIG outConfig ) - { - int16_t i, numLfeIn, numOutChannels; - ivas_error error; - error = IVAS_ERR_OK; - - /* If panning is not required, simply return */ - if ( !inputMc->lfeRouting.pan_lfe ) - { - return error; - } - - numLfeIn = getNumLfeChannels( inputMc ); +static ivas_error updateLfePanGainsForMcOut( + input_mc *inputMc, + const AUDIO_CONFIG outConfig ) +{ + int16_t i, numLfeIn, numOutChannels; + ivas_error error; + error = IVAS_ERR_OK; - if ( outConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) - { - numOutChannels = inputMc->base.ctx.pCustomLsOut->num_spk + inputMc->base.ctx.pCustomLsOut->num_lfe; - } - else - { - if ( ( error = getAudioConfigNumChannels( outConfig, &numOutChannels ) ) != IVAS_ERR_OK ) - { - return error; - } - } + /* If panning is not required, simply return */ + if ( !inputMc->lfeRouting.pan_lfe ) + { + return error; + } - for ( i = 0; i < numLfeIn; i++ ) - { - /* panning gains */ - if ( ( error = getEfapGains( *inputMc->base.ctx.pEfapOutWrapper, inputMc->lfeRouting.lfeOutputAzimuth, inputMc->lfeRouting.lfeOutputElevation, inputMc->lfeRouting.lfePanMtx[i] ) ) != IVAS_ERR_OK ) - { - return error; - } + numLfeIn = getNumLfeChannels( inputMc ); - /* linear input gain */ - v_multc( inputMc->lfeRouting.lfePanMtx[i], inputMc->lfeRouting.lfeInputGain, inputMc->lfeRouting.lfePanMtx[i], numOutChannels ); - } + if ( outConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + numOutChannels = inputMc->base.ctx.pCustomLsOut->num_spk + inputMc->base.ctx.pCustomLsOut->num_lfe; + } + else + { + if ( ( error = getAudioConfigNumChannels( outConfig, &numOutChannels ) ) != IVAS_ERR_OK ) + { + return error; + } + } + for ( i = 0; i < numLfeIn; i++ ) + { + /* panning gains */ + if ( ( error = getEfapGains( *inputMc->base.ctx.pEfapOutWrapper, inputMc->lfeRouting.lfeOutputAzimuth, inputMc->lfeRouting.lfeOutputElevation, inputMc->lfeRouting.lfePanMtx[i] ) ) != IVAS_ERR_OK ) + { return error; } + + /* linear input gain */ + v_multc( inputMc->lfeRouting.lfePanMtx[i], inputMc->lfeRouting.lfeInputGain, inputMc->lfeRouting.lfePanMtx[i], numOutChannels ); + } + + return error; +} #endif #ifdef IVAS_FLOAT_FIXED static ivas_error updateLfePanGainsForAmbiOut( @@ -3218,39 +3220,39 @@ static ivas_error updateLfePanGainsForAmbiOut( return error; } #else - static ivas_error updateLfePanGainsForAmbiOut( - input_mc * inputMc, - const AUDIO_CONFIG outConfig ) - { - int16_t i; - int16_t numLfeIn, outAmbiOrder; - ivas_error error; - error = IVAS_ERR_OK; +static ivas_error updateLfePanGainsForAmbiOut( + input_mc *inputMc, + const AUDIO_CONFIG outConfig ) +{ + int16_t i; + int16_t numLfeIn, outAmbiOrder; + ivas_error error; + error = IVAS_ERR_OK; - /* If panning is not required, simply return */ - if ( !inputMc->lfeRouting.pan_lfe ) - { - return error; - } + /* If panning is not required, simply return */ + if ( !inputMc->lfeRouting.pan_lfe ) + { + return error; + } - if ( ( error = getAmbisonicsOrder( outConfig, &outAmbiOrder ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getAmbisonicsOrder( outConfig, &outAmbiOrder ) ) != IVAS_ERR_OK ) + { + return error; + } - numLfeIn = getNumLfeChannels( inputMc ); + numLfeIn = getNumLfeChannels( inputMc ); - for ( i = 0; i < numLfeIn; i++ ) - { - /* panning gains */ - ivas_dirac_dec_get_response( (int16_t) inputMc->lfeRouting.lfeOutputAzimuth, (int16_t) inputMc->lfeRouting.lfeOutputElevation, inputMc->lfeRouting.lfePanMtx[i], outAmbiOrder ); + for ( i = 0; i < numLfeIn; i++ ) + { + /* panning gains */ + ivas_dirac_dec_get_response( (int16_t) inputMc->lfeRouting.lfeOutputAzimuth, (int16_t) inputMc->lfeRouting.lfeOutputElevation, inputMc->lfeRouting.lfePanMtx[i], outAmbiOrder ); - /* linear input gain */ - v_multc( inputMc->lfeRouting.lfePanMtx[i], inputMc->lfeRouting.lfeInputGain, inputMc->lfeRouting.lfePanMtx[i], IVAS_MAX_OUTPUT_CHANNELS ); - } + /* linear input gain */ + v_multc( inputMc->lfeRouting.lfePanMtx[i], inputMc->lfeRouting.lfeInputGain, inputMc->lfeRouting.lfePanMtx[i], IVAS_MAX_OUTPUT_CHANNELS ); + } - return error; - } + return error; +} #endif #ifdef IVAS_FLOAT_FIXED static ivas_error updateMcPanGainsForMcOut( @@ -3320,67 +3322,67 @@ static ivas_error updateMcPanGainsForMcOut( return error; } #else - static ivas_error updateMcPanGainsForMcOut( - input_mc * inputMc, - const AUDIO_CONFIG outConfig ) - { - ivas_error error; - - /* "if" conditions below realize the following mapping: +static ivas_error updateMcPanGainsForMcOut( + input_mc *inputMc, + const AUDIO_CONFIG outConfig ) +{ + ivas_error error; - If in == out, use identity matrix, otherwise follow the table: - +-----------+-------------+---------------+-----------+--------------------+ - | in\out | MONO | STEREO | custom LS | other | - +-----------+-------------+---------------+-----------+--------------------+ - | MONO | mono out | EFAP | EFAP | EFAP | - | custom LS | mono out | EFAP | EFAP | EFAP | - | other | mono lookup | stereo lookup | EFAP | conversion mapping | - +-----------+-------------+---------------+-----------+--------------------+ - */ + /* "if" conditions below realize the following mapping: - if ( configsAreEqual( inputMc->base.inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ) ) - { - error = initMcPanGainsWithIdentMatrix( inputMc ); - } - else if ( outConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM || - inputMc->base.inConfig == IVAS_AUDIO_CONFIG_MONO || - inputMc->base.inConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) - { - if ( ( inputMc->base.inConfig == IVAS_AUDIO_CONFIG_MONO ) && ( inputMc->nonDiegeticPan ) ) - { - inputMc->panGains[0][0] = ( inputMc->nonDiegeticPanGain + 1.f ) * 0.5f; - inputMc->panGains[0][1] = 1.f - inputMc->panGains[0][0]; - error = IVAS_ERR_OK; - } - else - { - error = initMcPanGainsWithEfap( inputMc, outConfig ); - } - } - else if ( outConfig == IVAS_AUDIO_CONFIG_MONO ) - { - error = initMcPanGainsWithMonoOut( inputMc ); - } - else if ( outConfig == IVAS_AUDIO_CONFIG_STEREO ) - { - error = initMcPanGainsWithStereoLookup( inputMc ); - } - else /* default */ - { - error = initMcPanGainsWithConversionMapping( inputMc, outConfig ); - } + If in == out, use identity matrix, otherwise follow the table: + +-----------+-------------+---------------+-----------+--------------------+ + | in\out | MONO | STEREO | custom LS | other | + +-----------+-------------+---------------+-----------+--------------------+ + | MONO | mono out | EFAP | EFAP | EFAP | + | custom LS | mono out | EFAP | EFAP | EFAP | + | other | mono lookup | stereo lookup | EFAP | conversion mapping | + +-----------+-------------+---------------+-----------+--------------------+ + */ - /* check for errors from above block */ - if ( error != IVAS_ERR_OK ) - { - return error; - } + if ( configsAreEqual( inputMc->base.inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ) ) + { + error = initMcPanGainsWithIdentMatrix( inputMc ); + } + else if ( outConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM || + inputMc->base.inConfig == IVAS_AUDIO_CONFIG_MONO || + inputMc->base.inConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + if ( ( inputMc->base.inConfig == IVAS_AUDIO_CONFIG_MONO ) && ( inputMc->nonDiegeticPan ) ) + { + inputMc->panGains[0][0] = ( inputMc->nonDiegeticPanGain + 1.f ) * 0.5f; + inputMc->panGains[0][1] = 1.f - inputMc->panGains[0][0]; + error = IVAS_ERR_OK; + } + else + { + error = initMcPanGainsWithEfap( inputMc, outConfig ); + } + } + else if ( outConfig == IVAS_AUDIO_CONFIG_MONO ) + { + error = initMcPanGainsWithMonoOut( inputMc ); + } + else if ( outConfig == IVAS_AUDIO_CONFIG_STEREO ) + { + error = initMcPanGainsWithStereoLookup( inputMc ); + } + else /* default */ + { + error = initMcPanGainsWithConversionMapping( inputMc, outConfig ); + } + + /* check for errors from above block */ + if ( error != IVAS_ERR_OK ) + { + return error; + } - /* update LFE panning */ - error = updateLfePanGainsForMcOut( inputMc, outConfig ); + /* update LFE panning */ + error = updateLfePanGainsForMcOut( inputMc, outConfig ); - return error; - } + return error; +} #endif #ifdef IVAS_FLOAT_FIXED static ivas_error updateMcPanGainsForAmbiOut( @@ -3476,75 +3478,75 @@ static ivas_error updateMcPanGainsForAmbiOut( return IVAS_ERR_OK; } #else - static ivas_error updateMcPanGainsForAmbiOut( - input_mc * inputMc, - const AUDIO_CONFIG outConfig ) - { - int16_t ch_in, ch_out, lfeIdx; - int16_t numNonLfeInChannels, outAmbiOrder; - const float *spkAzi, *spkEle; - ivas_error error; +static ivas_error updateMcPanGainsForAmbiOut( + input_mc *inputMc, + const AUDIO_CONFIG outConfig ) +{ + int16_t ch_in, ch_out, lfeIdx; + int16_t numNonLfeInChannels, outAmbiOrder; + const float *spkAzi, *spkEle; + ivas_error error; - if ( ( error = getAmbisonicsOrder( outConfig, &outAmbiOrder ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getAmbisonicsOrder( outConfig, &outAmbiOrder ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( inputMc->base.inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM ) - { - if ( ( error = getNumNonLfeChannelsInSpeakerLayout( inputMc->base.inConfig, &numNonLfeInChannels ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( inputMc->base.inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + if ( ( error = getNumNonLfeChannelsInSpeakerLayout( inputMc->base.inConfig, &numNonLfeInChannels ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = getSpeakerAzimuths( inputMc->base.inConfig, &spkAzi ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getSpeakerAzimuths( inputMc->base.inConfig, &spkAzi ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = getSpeakerElevations( inputMc->base.inConfig, &spkEle ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getSpeakerElevations( inputMc->base.inConfig, &spkEle ) ) != IVAS_ERR_OK ) + { + return error; + } - for ( ch_in = 0, ch_out = 0; ch_in < numNonLfeInChannels; ++ch_in, ++ch_out ) - { - if ( ch_in == LFE_CHANNEL ) - { - ++ch_out; - } - ivas_dirac_dec_get_response( (int16_t) spkAzi[ch_in], (int16_t) spkEle[ch_in], inputMc->panGains[ch_out], outAmbiOrder ); - } - } - else + for ( ch_in = 0, ch_out = 0; ch_in < numNonLfeInChannels; ++ch_in, ++ch_out ) + { + if ( ch_in == LFE_CHANNEL ) { - numNonLfeInChannels = inputMc->customLsInput.num_spk; - spkAzi = inputMc->customLsInput.ls_azimuth; - spkEle = inputMc->customLsInput.ls_elevation; - - for ( ch_in = 0, ch_out = 0; ch_in < numNonLfeInChannels; ++ch_in, ++ch_out ) - { - for ( lfeIdx = 0; lfeIdx < inputMc->customLsInput.num_lfe; ++lfeIdx ) - { - if ( inputMc->customLsInput.lfe_idx[lfeIdx] == ch_in ) - { - ++ch_out; - break; - } - } - - ivas_dirac_dec_get_response( (int16_t) spkAzi[ch_in], (int16_t) spkEle[ch_in], inputMc->panGains[ch_out], outAmbiOrder ); - } + ++ch_out; } + ivas_dirac_dec_get_response( (int16_t) spkAzi[ch_in], (int16_t) spkEle[ch_in], inputMc->panGains[ch_out], outAmbiOrder ); + } + } + else + { + numNonLfeInChannels = inputMc->customLsInput.num_spk; + spkAzi = inputMc->customLsInput.ls_azimuth; + spkEle = inputMc->customLsInput.ls_elevation; - /* update LFE panning */ - if ( ( error = updateLfePanGainsForAmbiOut( inputMc, outConfig ) ) != IVAS_ERR_OK ) + for ( ch_in = 0, ch_out = 0; ch_in < numNonLfeInChannels; ++ch_in, ++ch_out ) + { + for ( lfeIdx = 0; lfeIdx < inputMc->customLsInput.num_lfe; ++lfeIdx ) { - return error; + if ( inputMc->customLsInput.lfe_idx[lfeIdx] == ch_in ) + { + ++ch_out; + break; + } } - return IVAS_ERR_OK; + ivas_dirac_dec_get_response( (int16_t) spkAzi[ch_in], (int16_t) spkEle[ch_in], inputMc->panGains[ch_out], outAmbiOrder ); } + } + + /* update LFE panning */ + if ( ( error = updateLfePanGainsForAmbiOut( inputMc, outConfig ) ) != IVAS_ERR_OK ) + { + return error; + } + + return IVAS_ERR_OK; +} #endif #ifdef IVAS_FLOAT_FIXED static ivas_error updateMcPanGains( @@ -3608,66 +3610,66 @@ static ivas_error updateMcPanGains( return IVAS_ERR_OK; } #else - static ivas_error updateMcPanGains( - input_mc * inputMc, - const AUDIO_CONFIG outConfig ) - { - int16_t i; - ivas_error error; +static ivas_error updateMcPanGains( + input_mc *inputMc, + const AUDIO_CONFIG outConfig ) +{ + int16_t i; + ivas_error error; - /* Reset to all zeros - some functions below only write non-zero elements. */ - setZeroPanMatrix( inputMc->panGains ); + /* Reset to all zeros - some functions below only write non-zero elements. */ + setZeroPanMatrix( inputMc->panGains ); - error = IVAS_ERR_OK; - switch ( getAudioConfigType( outConfig ) ) + error = IVAS_ERR_OK; + switch ( getAudioConfigType( outConfig ) ) + { + case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: + error = updateMcPanGainsForMcOut( inputMc, outConfig ); + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: + error = updateMcPanGainsForAmbiOut( inputMc, outConfig ); + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL: + switch ( outConfig ) { - case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: - error = updateMcPanGainsForMcOut( inputMc, outConfig ); - break; - case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: - error = updateMcPanGainsForAmbiOut( inputMc, outConfig ); - break; - case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL: - switch ( outConfig ) - { - case IVAS_AUDIO_CONFIG_BINAURAL: - break; /* Do nothing */ - case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR: - case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB: - /* Prepare rendering to intermediate format */ - error = updateMcPanGainsForMcOut( inputMc, IVAS_AUDIO_CONFIG_7_1_4 ); - break; - default: - return IVAS_ERR_INVALID_OUTPUT_FORMAT; - } - break; - case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: + case IVAS_AUDIO_CONFIG_BINAURAL: break; /* Do nothing */ + case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR: + case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB: + /* Prepare rendering to intermediate format */ + error = updateMcPanGainsForMcOut( inputMc, IVAS_AUDIO_CONFIG_7_1_4 ); + break; default: return IVAS_ERR_INVALID_OUTPUT_FORMAT; } - /* Check error here to keep switch statement more compact */ - if ( error != IVAS_ERR_OK ) - { - return error; - } - - /* Copy LFE routing to pan gains array */ - if ( inputMc->base.inConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) - { - for ( i = 0; i < inputMc->customLsInput.num_lfe; ++i ) - { - mvr2r( inputMc->lfeRouting.lfePanMtx[i], inputMc->panGains[inputMc->customLsInput.lfe_idx[i]], IVAS_MAX_OUTPUT_CHANNELS ); - } - } - else - { - /* For code simplicity, always copy LFE gains. If config has no LFE, gains will be zero anyway. */ - mvr2r( inputMc->lfeRouting.lfePanMtx[0], inputMc->panGains[LFE_CHANNEL], IVAS_MAX_OUTPUT_CHANNELS ); - } + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: + 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; + /* Copy LFE routing to pan gains array */ + if ( inputMc->base.inConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + for ( i = 0; i < inputMc->customLsInput.num_lfe; ++i ) + { + mvr2r( inputMc->lfeRouting.lfePanMtx[i], inputMc->panGains[inputMc->customLsInput.lfe_idx[i]], IVAS_MAX_OUTPUT_CHANNELS ); } + } + else + { + /* For code simplicity, always copy LFE gains. If config has no LFE, gains will be zero anyway. */ + mvr2r( inputMc->lfeRouting.lfePanMtx[0], inputMc->panGains[LFE_CHANNEL], IVAS_MAX_OUTPUT_CHANNELS ); + } + + return IVAS_ERR_OK; +} #endif static ivas_error initMcBinauralRendering( @@ -3704,7 +3706,7 @@ static ivas_error initMcBinauralRendering( #ifdef IVAS_FLOAT_FIXED ivas_td_binaural_close_fx( &inputMc->tdRendWrapper.hBinRendererTd ); #else - ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd ); + ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd ); #endif inputMc->tdRendWrapper.hHrtfTD = NULL; } @@ -3741,7 +3743,7 @@ static ivas_error initMcBinauralRendering( { return error; } - +#if 1 Word16 nchan_rend = num_src; IF( EQ_16( ivas_format, MC_FORMAT ) && NE_16( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { @@ -3757,14 +3759,16 @@ static ivas_error initMcBinauralRendering( FOR( Word16 nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { fixedToFloat_arrL( Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3 ); - fixedToFloat_arrL( Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3 ); + } + Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = inputMc->tdRendWrapper.hBinRendererTd->Sources[nS]->SrcSpatial_p; fixedToFloat_arrL( SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3 ); - fixedToFloat_arrL( SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3 ); + SrcSpatial_p->q_Pos_p = Q31; } } +#endif #else if ( ( error = ivas_td_binaural_open_ext( &inputMc->tdRendWrapper, inConfig, hRendCfg, &inputMc->customLsInput, outSampleRate ) ) != IVAS_ERR_OK ) { @@ -3781,7 +3785,7 @@ static ivas_error initMcBinauralRendering( return error; } -#if 1 /*Fixed to float conversions */ +#if 0 /*Fixed to float conversions */ FOR( Word16 k = 0; k < add( extract_l( L_shr( inputMc->hReverb->fft_size, 1 ) ), 1 ); k++ ) { ( inputMc->hReverb )->fft_filter_correl_0.fft_spectrum[k] = (float) ( inputMc->hReverb )->fft_filter_correl_0.fft_spectrum_fx[k] / ONE_IN_Q31; @@ -3791,10 +3795,10 @@ static ivas_error initMcBinauralRendering( } #endif #else - if ( ( error = ivas_reverb_open( &( inputMc->hReverb ), outConfig, NULL, inputMc->tdRendWrapper.hBinRendererTd->HrFiltSet_p->lr_energy_and_iac, hRendCfg, outSampleRate ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_reverb_open( &( inputMc->hReverb ), outConfig, NULL, inputMc->tdRendWrapper.hBinRendererTd->HrFiltSet_p->lr_energy_and_iac, hRendCfg, outSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } #endif } } @@ -3841,7 +3845,7 @@ static ivas_error initMcMasaRendering( #ifdef IVAS_FLOAT_FIXED ivas_td_binaural_close_fx( &inputMc->tdRendWrapper.hBinRendererTd ); #else - ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd ); + ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd ); #endif inputMc->tdRendWrapper.hHrtfTD = NULL; } @@ -3944,89 +3948,89 @@ static lfe_routing defaultLfeRouting( return routing; } #else - static lfe_routing defaultLfeRouting( - const AUDIO_CONFIG inConfig, - const LSSETUP_CUSTOM_STRUCT customLsIn, - const AUDIO_CONFIG outConfig, - const LSSETUP_CUSTOM_STRUCT customLsOut ) - { - int16_t i; - lfe_routing routing; - - /* Set all output gains to zero, then route each input LFE consecutively to the next available output LFE. */ - - for ( i = 0; i < RENDERER_MAX_INPUT_LFE_CHANNELS; ++i ) - { - set_zero( routing.lfePanMtx[i], IVAS_MAX_OUTPUT_CHANNELS ); - } - - routing.pan_lfe = false; - routing.lfeInputGain = 1.0f; - - switch ( inConfig ) - { - case IVAS_AUDIO_CONFIG_5_1: - case IVAS_AUDIO_CONFIG_5_1_2: - case IVAS_AUDIO_CONFIG_5_1_4: - case IVAS_AUDIO_CONFIG_7_1: - case IVAS_AUDIO_CONFIG_7_1_4: - routing.numLfeChannels = 1; - break; - case IVAS_AUDIO_CONFIG_LS_CUSTOM: - routing.numLfeChannels = customLsIn.num_lfe; - break; - default: - routing.numLfeChannels = 0; - } - - switch ( outConfig ) - { - case IVAS_AUDIO_CONFIG_5_1: - case IVAS_AUDIO_CONFIG_5_1_2: - case IVAS_AUDIO_CONFIG_5_1_4: - case IVAS_AUDIO_CONFIG_7_1: - case IVAS_AUDIO_CONFIG_7_1_4: - routing.lfePanMtx[0][LFE_CHANNEL] = 1.0f; - break; - case IVAS_AUDIO_CONFIG_LS_CUSTOM: - for ( i = 0; i < routing.numLfeChannels && i < customLsOut.num_lfe; ++i ) - { - routing.lfePanMtx[i][customLsOut.lfe_idx[i]] = 1.0f; - } - break; - default: - /* Do nothing */ - break; - } - - return routing; - } -#endif -#ifdef IVAS_FLOAT_FIXED -static ivas_error setRendInputActiveMc( - void *input, +static lfe_routing defaultLfeRouting( const AUDIO_CONFIG inConfig, - const IVAS_REND_InputId id, - RENDER_CONFIG_DATA *hRendCfg ) + const LSSETUP_CUSTOM_STRUCT customLsIn, + const AUDIO_CONFIG outConfig, + const LSSETUP_CUSTOM_STRUCT customLsOut ) { - ivas_error error; - rendering_context rendCtx; - AUDIO_CONFIG outConfig; - input_mc *inputMc; + int16_t i; + lfe_routing routing; - inputMc = (input_mc *) input; - rendCtx = inputMc->base.ctx; - outConfig = *rendCtx.pOutConfig; + /* Set all output gains to zero, then route each input LFE consecutively to the next available output LFE. */ - if ( !isIoConfigPairSupported( inConfig, outConfig ) ) + for ( i = 0; i < RENDERER_MAX_INPUT_LFE_CHANNELS; ++i ) { - return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED; + set_zero( routing.lfePanMtx[i], IVAS_MAX_OUTPUT_CHANNELS ); } - if ( ( error = allocateMcLfeDelayBuffer( &inputMc->lfeDelayBuffer, MAX_BIN_DELAY_SAMPLES ) ) != IVAS_ERR_OK ) + routing.pan_lfe = false; + routing.lfeInputGain = 1.0f; + + switch ( inConfig ) { - return error; - } + case IVAS_AUDIO_CONFIG_5_1: + case IVAS_AUDIO_CONFIG_5_1_2: + case IVAS_AUDIO_CONFIG_5_1_4: + case IVAS_AUDIO_CONFIG_7_1: + case IVAS_AUDIO_CONFIG_7_1_4: + routing.numLfeChannels = 1; + break; + case IVAS_AUDIO_CONFIG_LS_CUSTOM: + routing.numLfeChannels = customLsIn.num_lfe; + break; + default: + routing.numLfeChannels = 0; + } + + switch ( outConfig ) + { + case IVAS_AUDIO_CONFIG_5_1: + case IVAS_AUDIO_CONFIG_5_1_2: + case IVAS_AUDIO_CONFIG_5_1_4: + case IVAS_AUDIO_CONFIG_7_1: + case IVAS_AUDIO_CONFIG_7_1_4: + routing.lfePanMtx[0][LFE_CHANNEL] = 1.0f; + break; + case IVAS_AUDIO_CONFIG_LS_CUSTOM: + for ( i = 0; i < routing.numLfeChannels && i < customLsOut.num_lfe; ++i ) + { + routing.lfePanMtx[i][customLsOut.lfe_idx[i]] = 1.0f; + } + break; + default: + /* Do nothing */ + break; + } + + return routing; +} +#endif +#ifdef IVAS_FLOAT_FIXED +static ivas_error setRendInputActiveMc( + void *input, + const AUDIO_CONFIG inConfig, + const IVAS_REND_InputId id, + RENDER_CONFIG_DATA *hRendCfg ) +{ + ivas_error error; + rendering_context rendCtx; + AUDIO_CONFIG outConfig; + input_mc *inputMc; + + inputMc = (input_mc *) input; + rendCtx = inputMc->base.ctx; + outConfig = *rendCtx.pOutConfig; + + if ( !isIoConfigPairSupported( inConfig, outConfig ) ) + { + return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED; + } + + if ( ( error = allocateMcLfeDelayBuffer( &inputMc->lfeDelayBuffer, MAX_BIN_DELAY_SAMPLES ) ) != IVAS_ERR_OK ) + { + return error; + } if ( ( error = allocateMcLfeDelayBuffer_fx( &inputMc->lfeDelayBuffer_fx, MAX_BIN_DELAY_SAMPLES ) ) != IVAS_ERR_OK ) { return error; @@ -4082,72 +4086,72 @@ static ivas_error setRendInputActiveMc( return IVAS_ERR_OK; } #else - static ivas_error setRendInputActiveMc( - void *input, - const AUDIO_CONFIG inConfig, - const IVAS_REND_InputId id, - RENDER_CONFIG_DATA *hRendCfg ) - { - ivas_error error; - rendering_context rendCtx; - AUDIO_CONFIG outConfig; - input_mc *inputMc; +static ivas_error setRendInputActiveMc( + void *input, + const AUDIO_CONFIG inConfig, + const IVAS_REND_InputId id, + RENDER_CONFIG_DATA *hRendCfg ) +{ + ivas_error error; + rendering_context rendCtx; + AUDIO_CONFIG outConfig; + input_mc *inputMc; - inputMc = (input_mc *) input; - rendCtx = inputMc->base.ctx; - outConfig = *rendCtx.pOutConfig; + inputMc = (input_mc *) input; + rendCtx = inputMc->base.ctx; + outConfig = *rendCtx.pOutConfig; - if ( !isIoConfigPairSupported( inConfig, outConfig ) ) - { - return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED; - } + if ( !isIoConfigPairSupported( inConfig, outConfig ) ) + { + return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED; + } - if ( ( error = allocateMcLfeDelayBuffer( &inputMc->lfeDelayBuffer, MAX_BIN_DELAY_SAMPLES ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = allocateMcLfeDelayBuffer( &inputMc->lfeDelayBuffer, MAX_BIN_DELAY_SAMPLES ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = allocateInputBaseBufferData( &inputMc->bufferData, MAX_BUFFER_LENGTH ) ) != IVAS_ERR_OK ) - { - return error; - } - initRendInputBase( &inputMc->base, inConfig, id, rendCtx, inputMc->bufferData, MAX_BUFFER_LENGTH ); + if ( ( error = allocateInputBaseBufferData( &inputMc->bufferData, MAX_BUFFER_LENGTH ) ) != IVAS_ERR_OK ) + { + return error; + } + initRendInputBase( &inputMc->base, inConfig, id, rendCtx, inputMc->bufferData, MAX_BUFFER_LENGTH ); - setZeroPanMatrix( inputMc->panGains ); - inputMc->customLsInput = defaultCustomLs(); - inputMc->tdRendWrapper = defaultTdRendWrapper(); - inputMc->crendWrapper = NULL; - inputMc->hReverb = NULL; - inputMc->hMcMasa = NULL; + setZeroPanMatrix( inputMc->panGains ); + inputMc->customLsInput = defaultCustomLs(); + inputMc->tdRendWrapper = defaultTdRendWrapper(); + inputMc->crendWrapper = NULL; + inputMc->hReverb = NULL; + inputMc->hMcMasa = NULL; - initRotGains( inputMc->rot_gains_prev ); - inputMc->lfeRouting = defaultLfeRouting( inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ); - set_zero( inputMc->lfeDelayBuffer, MAX_BIN_DELAY_SAMPLES ); - inputMc->binauralDelaySmp = 0; + initRotGains( inputMc->rot_gains_prev ); + inputMc->lfeRouting = defaultLfeRouting( inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ); + set_zero( inputMc->lfeDelayBuffer, MAX_BIN_DELAY_SAMPLES ); + inputMc->binauralDelaySmp = 0; - if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL || outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - { - if ( ( error = initMcBinauralRendering( inputMc, inConfig, outConfig, hRendCfg, FALSE ) ) != IVAS_ERR_OK ) - { - return error; - } - } + if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL || outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + if ( ( error = initMcBinauralRendering( inputMc, inConfig, outConfig, hRendCfg, FALSE ) ) != IVAS_ERR_OK ) + { + return error; + } + } - if ( outConfig == IVAS_AUDIO_CONFIG_MASA1 || outConfig == IVAS_AUDIO_CONFIG_MASA2 ) - { - if ( ( error = initMcMasaRendering( inputMc, inConfig, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) - { - return error; - } - } + if ( outConfig == IVAS_AUDIO_CONFIG_MASA1 || outConfig == IVAS_AUDIO_CONFIG_MASA2 ) + { + if ( ( error = initMcMasaRendering( inputMc, inConfig, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } + } - if ( ( error = updateMcPanGains( inputMc, outConfig ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = updateMcPanGains( inputMc, outConfig ) ) != IVAS_ERR_OK ) + { + return error; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif #ifdef IVAS_FLOAT_FIXED static void clearInputMc( @@ -4190,38 +4194,38 @@ static void clearInputMc( return; } #else - static void clearInputMc( - input_mc * inputMc ) - { - rendering_context rendCtx; +static void clearInputMc( + input_mc *inputMc ) +{ + rendering_context rendCtx; - rendCtx = inputMc->base.ctx; + rendCtx = inputMc->base.ctx; - freeMcLfeDelayBuffer( &inputMc->lfeDelayBuffer ); - freeInputBaseBufferData( &inputMc->bufferData ); - initRendInputBase( &inputMc->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); + freeMcLfeDelayBuffer( &inputMc->lfeDelayBuffer ); + freeInputBaseBufferData( &inputMc->bufferData ); + initRendInputBase( &inputMc->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); - /* Free input's internal handles */ - if ( inputMc->efapInWrapper.hEfap != NULL ) - { - efap_free_data( &inputMc->efapInWrapper.hEfap ); - } + /* Free input's internal handles */ + if ( inputMc->efapInWrapper.hEfap != NULL ) + { + efap_free_data( &inputMc->efapInWrapper.hEfap ); + } - ivas_rend_closeCrend( &inputMc->crendWrapper ); + ivas_rend_closeCrend( &inputMc->crendWrapper ); - ivas_reverb_close( &inputMc->hReverb ); + ivas_reverb_close( &inputMc->hReverb ); - if ( inputMc->tdRendWrapper.hBinRendererTd != NULL ) - { - ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd ); - inputMc->tdRendWrapper.hHrtfTD = NULL; - } + if ( inputMc->tdRendWrapper.hBinRendererTd != NULL ) + { + ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd ); + inputMc->tdRendWrapper.hHrtfTD = NULL; + } - ivas_mcmasa_ana_close( &( inputMc->hMcMasa ) ); + ivas_mcmasa_ana_close( &( inputMc->hMcMasa ) ); - return; - } + return; +} #endif #ifdef IVAS_FLOAT_FIXED static ivas_error initSbaPanGainsForMcOut( @@ -4297,75 +4301,75 @@ static ivas_error initSbaPanGainsForMcOut( return IVAS_ERR_OK; } #else - static ivas_error initSbaPanGainsForMcOut( - input_sba * inputSba, - const AUDIO_CONFIG outConfig, - const LSSETUP_CUSTOM_STRUCT *outSetupCustom ) - { - int16_t ambiOrderIn; - int16_t chInIdx, chOutIdx; - float *tmpDecMtx, *readPtr; - IVAS_OUTPUT_SETUP hOutSetup; - ivas_error error; +static ivas_error initSbaPanGainsForMcOut( + input_sba *inputSba, + const AUDIO_CONFIG outConfig, + const LSSETUP_CUSTOM_STRUCT *outSetupCustom ) +{ + int16_t ambiOrderIn; + int16_t chInIdx, chOutIdx; + float *tmpDecMtx, *readPtr; + IVAS_OUTPUT_SETUP hOutSetup; + ivas_error error; - if ( ( error = getAmbisonicsOrder( inputSba->base.inConfig, &ambiOrderIn ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getAmbisonicsOrder( inputSba->base.inConfig, &ambiOrderIn ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( getAudioConfigType( outConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) - { - assert( !"Invalid configuration" ); - return IVAS_ERR_WRONG_PARAMS; - } + if ( getAudioConfigType( outConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) + { + assert( !"Invalid configuration" ); + return IVAS_ERR_WRONG_PARAMS; + } - switch ( outConfig ) - { - case IVAS_AUDIO_CONFIG_MONO: - hOutSetup.ls_azimuth = ls_azimuth_CICP1; - hOutSetup.ls_elevation = ls_elevation_CICP1; - ivas_output_init( &hOutSetup, outConfig ); - break; - 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: - ivas_output_init( &hOutSetup, outConfig ); - break; - case IVAS_AUDIO_CONFIG_LS_CUSTOM: - ivas_ls_custom_setup( &hOutSetup, outSetupCustom ); - break; - default: - assert( !"Invalid speaker config" ); - return IVAS_ERR_WRONG_PARAMS; - } + switch ( outConfig ) + { + case IVAS_AUDIO_CONFIG_MONO: + hOutSetup.ls_azimuth = ls_azimuth_CICP1; + hOutSetup.ls_elevation = ls_elevation_CICP1; + ivas_output_init( &hOutSetup, outConfig ); + break; + 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: + ivas_output_init( &hOutSetup, outConfig ); + break; + case IVAS_AUDIO_CONFIG_LS_CUSTOM: + ivas_ls_custom_setup( &hOutSetup, outSetupCustom ); + break; + default: + assert( !"Invalid speaker config" ); + return IVAS_ERR_WRONG_PARAMS; + } - /* obtain and copy over HOA decoding matrix */ - tmpDecMtx = NULL; - if ( ( error = ivas_sba_get_hoa_dec_matrix( hOutSetup, &tmpDecMtx, ambiOrderIn ) ) != IVAS_ERR_OK ) - { - return error; - } + /* obtain and copy over HOA decoding matrix */ + tmpDecMtx = NULL; + if ( ( error = ivas_sba_get_hoa_dec_matrix( hOutSetup, &tmpDecMtx, ambiOrderIn ) ) != IVAS_ERR_OK ) + { + return error; + } - readPtr = &tmpDecMtx[0]; - for ( chOutIdx = 0; chOutIdx < hOutSetup.nchan_out_woLFE + hOutSetup.num_lfe; ++chOutIdx ) + readPtr = &tmpDecMtx[0]; + for ( chOutIdx = 0; chOutIdx < hOutSetup.nchan_out_woLFE + hOutSetup.num_lfe; ++chOutIdx ) + { + for ( chInIdx = 0; chInIdx < SBA_NHARM_HOA3; ++chInIdx ) + { + if ( hOutSetup.num_lfe > 0 && chOutIdx == hOutSetup.index_lfe[0] ) { - for ( chInIdx = 0; chInIdx < SBA_NHARM_HOA3; ++chInIdx ) - { - if ( hOutSetup.num_lfe > 0 && chOutIdx == hOutSetup.index_lfe[0] ) - { - continue; /* nothing to be rendered to LFE */ - } - inputSba->hoaDecMtx[chInIdx][chOutIdx] = *readPtr++; - } + continue; /* nothing to be rendered to LFE */ } + inputSba->hoaDecMtx[chInIdx][chOutIdx] = *readPtr++; + } + } - free( tmpDecMtx ); + free( tmpDecMtx ); - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif #ifdef IVAS_FLOAT_FIXED @@ -4387,23 +4391,23 @@ static ivas_error initSbaPanGainsForSbaOut( return error; } #else - static ivas_error initSbaPanGainsForSbaOut( - input_sba * inputSba, - const AUDIO_CONFIG outConfig ) - { - ivas_error error; - error = IVAS_ERR_OK; +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; - } + if ( getAudioConfigType( outConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) + { + assert( !"Invalid configuration" ); + return IVAS_ERR_WRONG_PARAMS; + } - fillIdentityPanMatrix( inputSba->hoaDecMtx ); + fillIdentityPanMatrix( inputSba->hoaDecMtx ); - return error; - } + return error; +} #endif #ifdef IVAS_FLOAT_FIXED static ivas_error updateSbaPanGains( @@ -4474,72 +4478,72 @@ static ivas_error updateSbaPanGains( return IVAS_ERR_OK; } #else - static ivas_error updateSbaPanGains( - input_sba * inputSba, - const AUDIO_CONFIG outConfig, - RENDER_CONFIG_DATA *hRendCfg ) - { - ivas_error error; - AUDIO_CONFIG inConfig; - rendering_context rendCtx; +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 ); + /* Reset to all zeros - some functions below only write non-zero elements. */ + setZeroPanMatrix( inputSba->hoaDecMtx ); - inConfig = inputSba->base.inConfig; - rendCtx = inputSba->base.ctx; + inConfig = inputSba->base.inConfig; + rendCtx = inputSba->base.ctx; - switch ( getAudioConfigType( outConfig ) ) + 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_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 ) + { - 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; + } - { - 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; + if ( ( error = ivas_rend_openCrend( &inputSba->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; } break; - case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: - error = IVAS_ERR_OK; - break; /* Do nothing */ 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; - } + /* Check error here to keep switch statement more compact */ + if ( error != IVAS_ERR_OK ) + { + return error; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif @@ -4557,10 +4561,10 @@ static ivas_error initSbaMasaRendering( return error; } #else - if ( ( error = ivas_dirac_ana_open( &inputSba->hDirAC, inSampleRate ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_dirac_ana_open( &inputSba->hDirAC, inSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } #endif return IVAS_ERR_OK; @@ -4583,7 +4587,55 @@ static ivas_error setRendInputActiveSba( rendCtx = inputSba->base.ctx; outConfig = *rendCtx.pOutConfig; - IF( !isIoConfigPairSupported( inConfig, outConfig ) ) + IF( !isIoConfigPairSupported( inConfig, outConfig ) ) + { + return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED; + } + + IF( ( error = allocateInputBaseBufferData_fx( &inputSba->bufferData_fx, MAX_BUFFER_LENGTH ) ) != IVAS_ERR_OK ) + { + return error; + } + initRendInputBase_fx( &inputSba->base, inConfig, id, rendCtx, inputSba->bufferData_fx, MAX_BUFFER_LENGTH ); + + setZeroPanMatrix_fx( inputSba->hoaDecMtx_fx ); + + inputSba->crendWrapper = NULL; + inputSba->hDirAC = NULL; + initRotGains_fx( inputSba->rot_gains_prev_fx ); + + IF( outConfig == IVAS_AUDIO_CONFIG_MASA1 || outConfig == IVAS_AUDIO_CONFIG_MASA2 ) + { + IF( ( error = initSbaMasaRendering( inputSba, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + IF( ( error = updateSbaPanGains( inputSba, outConfig, hRendCfg ) ) != IVAS_ERR_OK ) + { + return error; + } + + return error; +} +#else +static ivas_error setRendInputActiveSba( + void *input, + const AUDIO_CONFIG inConfig, + const IVAS_REND_InputId id, + RENDER_CONFIG_DATA *hRendCfg ) +{ + ivas_error error; + rendering_context rendCtx; + AUDIO_CONFIG outConfig; + input_sba *inputSba; + + inputSba = (input_sba *) input; + rendCtx = inputSba->base.ctx; + outConfig = *rendCtx.pOutConfig; + + if ( !isIoConfigPairSupported( inConfig, outConfig ) ) { return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED; } @@ -4592,83 +4644,30 @@ static ivas_error setRendInputActiveSba( { return error; } - IF( ( error = allocateInputBaseBufferData_fx( &inputSba->bufferData_fx, MAX_BUFFER_LENGTH ) ) != IVAS_ERR_OK ) - { - return error; - } + initRendInputBase( &inputSba->base, inConfig, id, rendCtx, inputSba->bufferData, MAX_BUFFER_LENGTH ); - initRendInputBase_fx( &inputSba->base, inConfig, id, rendCtx, inputSba->bufferData_fx, MAX_BUFFER_LENGTH ); - setZeroPanMatrix_fx( inputSba->hoaDecMtx_fx ); + setZeroPanMatrix( inputSba->hoaDecMtx ); inputSba->crendWrapper = NULL; inputSba->hDirAC = NULL; - initRotGains_fx( inputSba->rot_gains_prev_fx ); + initRotGains( inputSba->rot_gains_prev ); - IF( outConfig == IVAS_AUDIO_CONFIG_MASA1 || outConfig == IVAS_AUDIO_CONFIG_MASA2 ) + if ( outConfig == IVAS_AUDIO_CONFIG_MASA1 || outConfig == IVAS_AUDIO_CONFIG_MASA2 ) { - IF( ( error = initSbaMasaRendering( inputSba, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = initSbaMasaRendering( inputSba, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } } - IF( ( error = updateSbaPanGains( inputSba, outConfig, hRendCfg ) ) != IVAS_ERR_OK ) + if ( ( error = updateSbaPanGains( inputSba, outConfig, hRendCfg ) ) != IVAS_ERR_OK ) { return error; } return error; } -#else - static ivas_error setRendInputActiveSba( - void *input, - const AUDIO_CONFIG inConfig, - const IVAS_REND_InputId id, - RENDER_CONFIG_DATA *hRendCfg ) - { - ivas_error error; - rendering_context rendCtx; - AUDIO_CONFIG outConfig; - input_sba *inputSba; - - inputSba = (input_sba *) input; - rendCtx = inputSba->base.ctx; - outConfig = *rendCtx.pOutConfig; - - if ( !isIoConfigPairSupported( inConfig, outConfig ) ) - { - return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED; - } - - if ( ( error = allocateInputBaseBufferData( &inputSba->bufferData, MAX_BUFFER_LENGTH ) ) != IVAS_ERR_OK ) - { - return error; - } - - initRendInputBase( &inputSba->base, inConfig, id, rendCtx, inputSba->bufferData, MAX_BUFFER_LENGTH ); - - setZeroPanMatrix( inputSba->hoaDecMtx ); - - inputSba->crendWrapper = NULL; - inputSba->hDirAC = NULL; - initRotGains( inputSba->rot_gains_prev ); - - if ( outConfig == IVAS_AUDIO_CONFIG_MASA1 || outConfig == IVAS_AUDIO_CONFIG_MASA2 ) - { - if ( ( error = initSbaMasaRendering( inputSba, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - if ( ( error = updateSbaPanGains( inputSba, outConfig, hRendCfg ) ) != IVAS_ERR_OK ) - { - return error; - } - - return error; - } #endif #ifdef IVAS_FLOAT_FIXED static void clearInputSba( @@ -4678,10 +4677,8 @@ static void clearInputSba( rendCtx = inputSba->base.ctx; - freeInputBaseBufferData( &inputSba->bufferData ); freeInputBaseBufferData_fx( &inputSba->bufferData_fx ); - initRendInputBase( &inputSba->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); initRendInputBase_fx( &inputSba->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); /* Free input's internal handles */ @@ -4692,24 +4689,24 @@ static void clearInputSba( return; } #else - static void clearInputSba( - input_sba * inputSba ) - { - rendering_context rendCtx; +static void clearInputSba( + input_sba *inputSba ) +{ + rendering_context rendCtx; - rendCtx = inputSba->base.ctx; + rendCtx = inputSba->base.ctx; - freeInputBaseBufferData( &inputSba->bufferData ); + freeInputBaseBufferData( &inputSba->bufferData ); - initRendInputBase( &inputSba->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); + initRendInputBase( &inputSba->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); - /* Free input's internal handles */ - ivas_rend_closeCrend( &inputSba->crendWrapper ); + /* Free input's internal handles */ + ivas_rend_closeCrend( &inputSba->crendWrapper ); - ivas_dirac_ana_close( &( inputSba->hDirAC ) ); + ivas_dirac_ana_close( &( inputSba->hDirAC ) ); - return; - } + return; +} #endif #ifndef IVAS_FLOAT_FIXED @@ -5007,143 +5004,143 @@ ivas_error IVAS_REND_Open( return IVAS_ERR_OK; } #else - /*------------------------------------------------------------------------- - * IVAS_REND_Open() - * - * - *------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- + * IVAS_REND_Open() + * + * + *------------------------------------------------------------------------*/ - ivas_error IVAS_REND_Open( - IVAS_REND_HANDLE * phIvasRend, - const int32_t outputSampleRate, - const AUDIO_CONFIG outConfig, - const int16_t nonDiegeticPan, - const float nonDiegeticPanGain, - const int16_t num_subframes ) - { - int16_t i; - IVAS_REND_HANDLE hIvasRend; - ivas_error error; - int16_t numOutChannels; +ivas_error IVAS_REND_Open( + IVAS_REND_HANDLE *phIvasRend, + const int32_t outputSampleRate, + const AUDIO_CONFIG outConfig, + const int16_t nonDiegeticPan, + const float nonDiegeticPanGain, + const int16_t num_subframes ) +{ + int16_t i; + IVAS_REND_HANDLE hIvasRend; + ivas_error error; + int16_t numOutChannels; - /* Validate function arguments */ - if ( phIvasRend == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } + /* Validate function arguments */ + if ( phIvasRend == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } - if ( ( error = validateOutputAudioConfig( outConfig ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = validateOutputAudioConfig( outConfig ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = validateOutputSampleRate( outputSampleRate, outConfig ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = validateOutputSampleRate( outputSampleRate, outConfig ) ) != IVAS_ERR_OK ) + { + return error; + } - *phIvasRend = (IVAS_REND_HANDLE) malloc( sizeof( struct IVAS_REND ) ); - if ( *phIvasRend == NULL ) - { - return IVAS_ERR_FAILED_ALLOC; - } + *phIvasRend = (IVAS_REND_HANDLE) malloc( sizeof( struct IVAS_REND ) ); + if ( *phIvasRend == NULL ) + { + return IVAS_ERR_FAILED_ALLOC; + } - hIvasRend = *phIvasRend; - hIvasRend->sampleRateOut = outputSampleRate; - hIvasRend->outputConfig = outConfig; - hIvasRend->customLsOut = defaultCustomLs(); - hIvasRend->hLimiter = NULL; - hIvasRend->efapOutWrapper.hEfap = NULL; - hIvasRend->efapOutWrapper.pCustomLsSetup = NULL; - hIvasRend->num_subframes = num_subframes; + hIvasRend = *phIvasRend; + hIvasRend->sampleRateOut = outputSampleRate; + hIvasRend->outputConfig = outConfig; + hIvasRend->customLsOut = defaultCustomLs(); + hIvasRend->hLimiter = NULL; + hIvasRend->efapOutWrapper.hEfap = NULL; + hIvasRend->efapOutWrapper.pCustomLsSetup = NULL; + hIvasRend->num_subframes = num_subframes; - /* Initialize limiter */ - if ( ( error = IVAS_REND_NumOutChannels( hIvasRend, &numOutChannels ) ) != IVAS_ERR_OK ) - { - return error; - } + /* Initialize limiter */ + if ( ( error = IVAS_REND_NumOutChannels( hIvasRend, &numOutChannels ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = initLimiter( &hIvasRend->hLimiter, numOutChannels, outputSampleRate ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = initLimiter( &hIvasRend->hLimiter, numOutChannels, outputSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } - /* Initialize headrotation data */ - if ( ( error = initHeadRotation( hIvasRend ) ) != IVAS_ERR_OK ) - { - return error; - } + /* Initialize headrotation data */ + if ( ( error = initHeadRotation( hIvasRend ) ) != IVAS_ERR_OK ) + { + return error; + } - /* Initialize external orientation data */ - if ( ( error = ivas_external_orientation_open( &( hIvasRend->hExternalOrientationData ), num_subframes ) ) != IVAS_ERR_OK ) - { - return error; - } + /* Initialize external orientation data */ + if ( ( error = ivas_external_orientation_open( &( hIvasRend->hExternalOrientationData ), num_subframes ) ) != IVAS_ERR_OK ) + { + return error; + } - /* Initilize combined orientation data */ - if ( ( error = ivas_combined_orientation_open( &( hIvasRend->hCombinedOrientationData ), outputSampleRate, num_subframes ) ) != IVAS_ERR_OK ) - { - return error; - } + /* Initilize combined orientation data */ + if ( ( error = ivas_combined_orientation_open( &( hIvasRend->hCombinedOrientationData ), outputSampleRate, num_subframes ) ) != IVAS_ERR_OK ) + { + return error; + } - /* Initialize EFAP */ - if ( ( error = initEfap( &hIvasRend->efapOutWrapper, outConfig, &hIvasRend->customLsOut ) ) != IVAS_ERR_OK ) - { - return error; - } + /* Initialize EFAP */ + if ( ( error = initEfap( &hIvasRend->efapOutWrapper, outConfig, &hIvasRend->customLsOut ) ) != IVAS_ERR_OK ) + { + return error; + } - /* Initialize inputs */ + /* Initialize inputs */ - for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) - { - initRendInputBase( &hIvasRend->inputsIsm[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); + for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) + { + initRendInputBase( &hIvasRend->inputsIsm[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); - hIvasRend->inputsIsm[i].crendWrapper = NULL; - hIvasRend->inputsIsm[i].hReverb = NULL; - hIvasRend->inputsIsm[i].tdRendWrapper.hBinRendererTd = NULL; - hIvasRend->inputsIsm[i].bufferData = NULL; - hIvasRend->inputsIsm[i].nonDiegeticPan = nonDiegeticPan; - hIvasRend->inputsIsm[i].nonDiegeticPanGain = nonDiegeticPanGain; - hIvasRend->inputsIsm[i].hOMasa = NULL; - } + hIvasRend->inputsIsm[i].crendWrapper = NULL; + hIvasRend->inputsIsm[i].hReverb = NULL; + hIvasRend->inputsIsm[i].tdRendWrapper.hBinRendererTd = NULL; + hIvasRend->inputsIsm[i].bufferData = NULL; + hIvasRend->inputsIsm[i].nonDiegeticPan = nonDiegeticPan; + hIvasRend->inputsIsm[i].nonDiegeticPanGain = nonDiegeticPanGain; + hIvasRend->inputsIsm[i].hOMasa = NULL; + } - for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) - { - initRendInputBase( &hIvasRend->inputsMc[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); + for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) + { + initRendInputBase( &hIvasRend->inputsMc[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); - hIvasRend->inputsMc[i].efapInWrapper.hEfap = NULL; - hIvasRend->inputsMc[i].crendWrapper = NULL; - hIvasRend->inputsMc[i].hReverb = NULL; - hIvasRend->inputsMc[i].tdRendWrapper.hBinRendererTd = NULL; - hIvasRend->inputsMc[i].bufferData = NULL; - hIvasRend->inputsMc[i].lfeDelayBuffer = NULL; - hIvasRend->inputsMc[i].nonDiegeticPan = nonDiegeticPan; - hIvasRend->inputsMc[i].nonDiegeticPanGain = nonDiegeticPanGain; - hIvasRend->inputsMc[i].hMcMasa = NULL; - } + hIvasRend->inputsMc[i].efapInWrapper.hEfap = NULL; + hIvasRend->inputsMc[i].crendWrapper = NULL; + hIvasRend->inputsMc[i].hReverb = NULL; + hIvasRend->inputsMc[i].tdRendWrapper.hBinRendererTd = NULL; + hIvasRend->inputsMc[i].bufferData = NULL; + hIvasRend->inputsMc[i].lfeDelayBuffer = NULL; + hIvasRend->inputsMc[i].nonDiegeticPan = nonDiegeticPan; + hIvasRend->inputsMc[i].nonDiegeticPanGain = nonDiegeticPanGain; + hIvasRend->inputsMc[i].hMcMasa = NULL; + } - for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) - { - initRendInputBase( &hIvasRend->inputsSba[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); + for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) + { + initRendInputBase( &hIvasRend->inputsSba[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); - hIvasRend->inputsSba[i].crendWrapper = NULL; - hIvasRend->inputsSba[i].bufferData = NULL; - hIvasRend->inputsSba[i].hDirAC = NULL; - } + hIvasRend->inputsSba[i].crendWrapper = NULL; + hIvasRend->inputsSba[i].bufferData = NULL; + hIvasRend->inputsSba[i].hDirAC = NULL; + } - for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) - { - initRendInputBase( &hIvasRend->inputsMasa[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); + for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) + { + initRendInputBase( &hIvasRend->inputsMasa[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); - hIvasRend->inputsMasa[i].metadataHasBeenFed = false; - hIvasRend->inputsMasa[i].bufferData = NULL; - hIvasRend->inputsMasa[i].hMasaPrerend = NULL; - hIvasRend->inputsMasa[i].hMasaExtRend = NULL; - } + hIvasRend->inputsMasa[i].metadataHasBeenFed = false; + hIvasRend->inputsMasa[i].bufferData = NULL; + hIvasRend->inputsMasa[i].hMasaPrerend = NULL; + hIvasRend->inputsMasa[i].hMasaExtRend = NULL; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif #ifdef IVAS_FLOAT_FIXED static LSSETUP_CUSTOM_STRUCT makeCustomLsSetup( @@ -5178,32 +5175,32 @@ static LSSETUP_CUSTOM_STRUCT makeCustomLsSetup( return customLs; } #else - static LSSETUP_CUSTOM_STRUCT makeCustomLsSetup( - const IVAS_CUSTOM_LS_DATA rendCustomLsLayout ) - { - int16_t i; - LSSETUP_CUSTOM_STRUCT customLs; +static LSSETUP_CUSTOM_STRUCT makeCustomLsSetup( + const IVAS_CUSTOM_LS_DATA rendCustomLsLayout ) +{ + int16_t i; + LSSETUP_CUSTOM_STRUCT customLs; - /* Copy layout description */ - customLs.num_spk = rendCustomLsLayout.num_spk; - mvr2r( rendCustomLsLayout.azimuth, customLs.ls_azimuth, rendCustomLsLayout.num_spk ); - mvr2r( rendCustomLsLayout.elevation, customLs.ls_elevation, rendCustomLsLayout.num_spk ); + /* Copy layout description */ + customLs.num_spk = rendCustomLsLayout.num_spk; + mvr2r( rendCustomLsLayout.azimuth, customLs.ls_azimuth, rendCustomLsLayout.num_spk ); + mvr2r( rendCustomLsLayout.elevation, customLs.ls_elevation, rendCustomLsLayout.num_spk ); - customLs.is_planar_setup = 1; - for ( i = 0; i < rendCustomLsLayout.num_spk; ++i ) - { - if ( fabsf( rendCustomLsLayout.elevation[i] ) > EPSILON ) - { - customLs.is_planar_setup = 0; - break; - } - } + customLs.is_planar_setup = 1; + for ( i = 0; i < rendCustomLsLayout.num_spk; ++i ) + { + if ( fabsf( rendCustomLsLayout.elevation[i] ) > EPSILON ) + { + customLs.is_planar_setup = 0; + break; + } + } - customLs.num_lfe = rendCustomLsLayout.num_lfe; - mvs2s( rendCustomLsLayout.lfe_idx, customLs.lfe_idx, rendCustomLsLayout.num_lfe ); + customLs.num_lfe = rendCustomLsLayout.num_lfe; + mvs2s( rendCustomLsLayout.lfe_idx, customLs.lfe_idx, rendCustomLsLayout.num_lfe ); - return customLs; - } + return customLs; +} #endif @@ -5238,34 +5235,34 @@ static ivas_error validateCustomLsLayout_fx( return IVAS_ERR_OK; } #else - static ivas_error validateCustomLsLayout( - const IVAS_CUSTOM_LS_DATA layout ) - { - int16_t i; - - /* Negative number of speakers or LFEs makes no sense */ - if ( layout.num_spk < 0 || layout.num_lfe < 0 ) - { - return IVAS_ERR_INVALID_CUSTOM_LS_LAYOUT; - } +static ivas_error validateCustomLsLayout( + const IVAS_CUSTOM_LS_DATA layout ) +{ + int16_t i; - /* There must be at least one speaker or LFE in the layout */ - if ( layout.num_spk + layout.num_lfe <= 0 ) - { - return IVAS_ERR_INVALID_CUSTOM_LS_LAYOUT; - } + /* Negative number of speakers or LFEs makes no sense */ + if ( layout.num_spk < 0 || layout.num_lfe < 0 ) + { + return IVAS_ERR_INVALID_CUSTOM_LS_LAYOUT; + } - /* LFE indices must be positive */ - for ( i = 0; i < layout.num_lfe; ++i ) - { - if ( layout.lfe_idx[i] < 0 ) - { - return IVAS_ERR_INVALID_CUSTOM_LS_LAYOUT; - } - } + /* There must be at least one speaker or LFE in the layout */ + if ( layout.num_spk + layout.num_lfe <= 0 ) + { + return IVAS_ERR_INVALID_CUSTOM_LS_LAYOUT; + } - return IVAS_ERR_OK; + /* LFE indices must be positive */ + for ( i = 0; i < layout.num_lfe; ++i ) + { + if ( layout.lfe_idx[i] < 0 ) + { + return IVAS_ERR_INVALID_CUSTOM_LS_LAYOUT; } + } + + return IVAS_ERR_OK; +} #endif @@ -5302,10 +5299,10 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( return error; } #else - if ( ( error = validateCustomLsLayout( layout ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = validateCustomLsLayout( layout ) ) != IVAS_ERR_OK ) + { + return error; + } #endif hIvasRend->customLsOut = makeCustomLsSetup( layout ); @@ -5403,40 +5400,40 @@ ivas_error IVAS_REND_NumOutChannels( return IVAS_ERR_OK; } #else - /*-------------------------------------------------------------------* - * IVAS_REND_NumOutChannels() - * - * - *-------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * IVAS_REND_NumOutChannels() + * + * + *-------------------------------------------------------------------*/ - ivas_error IVAS_REND_NumOutChannels( - IVAS_REND_CONST_HANDLE hIvasRend, - int16_t * numOutChannels ) - { - ivas_error error; +ivas_error IVAS_REND_NumOutChannels( + IVAS_REND_CONST_HANDLE hIvasRend, + int16_t *numOutChannels ) +{ + ivas_error error; - /* Validate function arguments */ - if ( hIvasRend == NULL || numOutChannels == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } + /* 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 ) + /* 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 ) { - 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 error; } + break; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif @@ -5451,15 +5448,15 @@ static IVAS_REND_InputId makeInputId( return (IVAS_REND_InputId) UL_or( UL_lshl( ( (UWord32) getAudioConfigType( config ) ), 8 ), L_add( inputIndex, 1 ) ); } #else - static IVAS_REND_InputId makeInputId( - AUDIO_CONFIG config, - const int32_t inputIndex ) - { - /* Put config type in second byte (from LSB), put index + 1 in first byte - * - * Index is incremented here so that a valid ID can never be 0. */ - return (IVAS_REND_InputId) ( ( ( (uint32_t) getAudioConfigType( config ) ) << 8 ) | ( inputIndex + 1 ) ); - } +static IVAS_REND_InputId makeInputId( + AUDIO_CONFIG config, + const int32_t inputIndex ) +{ + /* Put config type in second byte (from LSB), put index + 1 in first byte + * + * Index is incremented here so that a valid ID can never be 0. */ + return (IVAS_REND_InputId) ( ( ( (uint32_t) getAudioConfigType( config ) ) << 8 ) | ( inputIndex + 1 ) ); +} #endif @@ -5529,69 +5526,69 @@ static ivas_error getInputById( return IVAS_ERR_OK; } #else - static ivas_error getInputById( - IVAS_REND_HANDLE hIvasRend, - IVAS_REND_InputId inputId, - void **ppInput ) - { - int32_t inputIndex; - IVAS_REND_AudioConfigType configType; - input_base *pInputBase; +static ivas_error getInputById( + IVAS_REND_HANDLE hIvasRend, + IVAS_REND_InputId inputId, + void **ppInput ) +{ + int32_t inputIndex; + IVAS_REND_AudioConfigType configType; + input_base *pInputBase; - /* Reverse makeInputId() */ - inputIndex = ( inputId & 0xFF ) - 1; - configType = ( inputId & 0xFF00 ) >> 8; + /* Reverse makeInputId() */ + inputIndex = ( inputId & 0xFF ) - 1; + configType = ( inputId & 0xFF00 ) >> 8; - /* Validate values derived from input ID */ - if ( inputIndex < 0 ) + /* Validate values derived from input ID */ + if ( inputIndex < 0 ) + { + return IVAS_ERR_INVALID_INPUT_ID; + } + switch ( configType ) + { + case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: + if ( inputIndex > RENDERER_MAX_ISM_INPUTS ) { return IVAS_ERR_INVALID_INPUT_ID; } - switch ( configType ) + pInputBase = &hIvasRend->inputsIsm[inputIndex].base; + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: + if ( inputIndex > RENDERER_MAX_MC_INPUTS ) { - case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: - if ( inputIndex > RENDERER_MAX_ISM_INPUTS ) - { - return IVAS_ERR_INVALID_INPUT_ID; - } - pInputBase = &hIvasRend->inputsIsm[inputIndex].base; - break; - case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: - if ( inputIndex > RENDERER_MAX_MC_INPUTS ) - { - return IVAS_ERR_INVALID_INPUT_ID; - } - pInputBase = &hIvasRend->inputsMc[inputIndex].base; - break; - case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: - if ( inputIndex > RENDERER_MAX_SBA_INPUTS ) - { - return IVAS_ERR_INVALID_INPUT_ID; - } - pInputBase = &hIvasRend->inputsSba[inputIndex].base; - break; - case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: - if ( inputIndex > RENDERER_MAX_MASA_INPUTS ) - { - return IVAS_ERR_INVALID_INPUT_ID; - } - pInputBase = &hIvasRend->inputsMasa[inputIndex].base; - break; - default: - return IVAS_ERR_INVALID_INPUT_ID; + return IVAS_ERR_INVALID_INPUT_ID; } - - /* Ensure input ID matches and that input is active */ - if ( pInputBase->id != inputId || pInputBase->inConfig == IVAS_AUDIO_CONFIG_INVALID ) + pInputBase = &hIvasRend->inputsMc[inputIndex].base; + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: + if ( inputIndex > RENDERER_MAX_SBA_INPUTS ) + { + return IVAS_ERR_INVALID_INPUT_ID; + } + pInputBase = &hIvasRend->inputsSba[inputIndex].base; + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: + if ( inputIndex > RENDERER_MAX_MASA_INPUTS ) { return IVAS_ERR_INVALID_INPUT_ID; } + pInputBase = &hIvasRend->inputsMasa[inputIndex].base; + break; + default: + return IVAS_ERR_INVALID_INPUT_ID; + } - /* Validation done, set value via output parameter */ - *ppInput = pInputBase; + /* Ensure input ID matches and that input is active */ + if ( pInputBase->id != inputId || pInputBase->inConfig == IVAS_AUDIO_CONFIG_INVALID ) + { + return IVAS_ERR_INVALID_INPUT_ID; + } - return IVAS_ERR_OK; - } + /* Validation done, set value via output parameter */ + *ppInput = pInputBase; + + return IVAS_ERR_OK; +} #endif @@ -5661,69 +5658,69 @@ static ivas_error getConstInputById( return IVAS_ERR_OK; } #else - static ivas_error getConstInputById( - IVAS_REND_CONST_HANDLE hIvasRend, - const IVAS_REND_InputId inputId, - const void **ppInput ) - { - int32_t inputIndex; - IVAS_REND_AudioConfigType configType; - const input_base *pInputBase; +static ivas_error getConstInputById( + IVAS_REND_CONST_HANDLE hIvasRend, + const IVAS_REND_InputId inputId, + const void **ppInput ) +{ + int32_t inputIndex; + IVAS_REND_AudioConfigType configType; + const input_base *pInputBase; - /* Reverse makeInputId() */ - inputIndex = ( inputId & 0xFF ) - 1; - configType = ( inputId & 0xFF00 ) >> 8; + /* Reverse makeInputId() */ + inputIndex = ( inputId & 0xFF ) - 1; + configType = ( inputId & 0xFF00 ) >> 8; - /* Validate values derived from input ID */ - if ( inputIndex < 0 ) + /* Validate values derived from input ID */ + if ( inputIndex < 0 ) + { + return IVAS_ERR_INVALID_INPUT_ID; + } + switch ( configType ) + { + case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: + if ( inputIndex > RENDERER_MAX_ISM_INPUTS ) { return IVAS_ERR_INVALID_INPUT_ID; } - switch ( configType ) + pInputBase = &hIvasRend->inputsIsm[inputIndex].base; + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: + if ( inputIndex > RENDERER_MAX_MC_INPUTS ) { - case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: - if ( inputIndex > RENDERER_MAX_ISM_INPUTS ) - { - return IVAS_ERR_INVALID_INPUT_ID; - } - pInputBase = &hIvasRend->inputsIsm[inputIndex].base; - break; - case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: - if ( inputIndex > RENDERER_MAX_MC_INPUTS ) - { - return IVAS_ERR_INVALID_INPUT_ID; - } - pInputBase = &hIvasRend->inputsMc[inputIndex].base; - break; - case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: - if ( inputIndex > RENDERER_MAX_SBA_INPUTS ) - { - return IVAS_ERR_INVALID_INPUT_ID; - } - pInputBase = &hIvasRend->inputsSba[inputIndex].base; - break; - case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: - if ( inputIndex > RENDERER_MAX_MASA_INPUTS ) - { - return IVAS_ERR_INVALID_INPUT_ID; - } - pInputBase = &hIvasRend->inputsMasa[inputIndex].base; - break; - default: - return IVAS_ERR_INVALID_INPUT_ID; + return IVAS_ERR_INVALID_INPUT_ID; } - - /* Ensure input ID matches and that input is active */ - if ( pInputBase->id != inputId || pInputBase->inConfig == IVAS_AUDIO_CONFIG_INVALID ) + pInputBase = &hIvasRend->inputsMc[inputIndex].base; + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: + if ( inputIndex > RENDERER_MAX_SBA_INPUTS ) { return IVAS_ERR_INVALID_INPUT_ID; } + pInputBase = &hIvasRend->inputsSba[inputIndex].base; + break; + case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: + if ( inputIndex > RENDERER_MAX_MASA_INPUTS ) + { + return IVAS_ERR_INVALID_INPUT_ID; + } + pInputBase = &hIvasRend->inputsMasa[inputIndex].base; + break; + default: + return IVAS_ERR_INVALID_INPUT_ID; + } - /* Validation done, set value via output parameter */ - *ppInput = pInputBase; + /* Ensure input ID matches and that input is active */ + if ( pInputBase->id != inputId || pInputBase->inConfig == IVAS_AUDIO_CONFIG_INVALID ) + { + return IVAS_ERR_INVALID_INPUT_ID; + } - return IVAS_ERR_OK; - } + /* Validation done, set value via output parameter */ + *ppInput = pInputBase; + + return IVAS_ERR_OK; +} #endif #ifndef IVAS_FLOAT_FIXED @@ -5768,46 +5765,46 @@ static ivas_error findFreeInputSlot( return IVAS_ERR_OK; } #else - static ivas_error findFreeInputSlot_fx( - const void *inputs, - const Word32 inputStructSize, - const Word32 maxInputs, - Word32 *inputIndex ) - { - /* Using a void pointer and a separately provided size is a hack for this function - to be reusable for arrays of any input type (input_ism, input_mc, input_sba, input_masa). - Assumptions: - - input_base is always the first member in the input struct - - provided size is correct - */ +static ivas_error findFreeInputSlot_fx( + const void *inputs, + const Word32 inputStructSize, + const Word32 maxInputs, + Word32 *inputIndex ) +{ + /* Using a void pointer and a separately provided size is a hack for this function + to be reusable for arrays of any input type (input_ism, input_mc, input_sba, input_masa). + Assumptions: + - input_base is always the first member in the input struct + - provided size is correct + */ - Word32 i; - bool canAddInput; - const UWord8 *pByte; - const input_base *pInputBase; + Word32 i; + bool canAddInput; + const UWord8 *pByte; + const input_base *pInputBase; - canAddInput = false; + canAddInput = false; - /* Find first unused input in array */ - FOR( ( i = 0, pByte = inputs ); i < maxInputs; ( ++i, pByte += inputStructSize ) ) - { - pInputBase = (const input_base *) pByte; + /* Find first unused input in array */ + FOR( ( i = 0, pByte = inputs ); i < maxInputs; ( ++i, pByte += inputStructSize ) ) + { + pInputBase = (const input_base *) pByte; - IF( EQ_32( pInputBase->inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) - { - *inputIndex = i; - canAddInput = true; - BREAK; - } - } + IF( EQ_32( pInputBase->inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) + { + *inputIndex = i; + canAddInput = true; + BREAK; + } + } - IF( !canAddInput ) - { - return IVAS_ERR_TOO_MANY_INPUTS; - } + IF( !canAddInput ) + { + return IVAS_ERR_TOO_MANY_INPUTS; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif @@ -5883,71 +5880,71 @@ ivas_error IVAS_REND_AddInput( return IVAS_ERR_OK; } #else - ivas_error IVAS_REND_AddInput_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const AUDIO_CONFIG inConfig, /* i : audio config for a new input */ - IVAS_REND_InputId *inputId /* o : ID of the new input */ - ) - { - ivas_error error; - Word32 maxNumInputsOfType; - void *inputsArray; - Word32 inputStructSize; - ivas_error ( *activateInput )( void *, AUDIO_CONFIG, IVAS_REND_InputId, RENDER_CONFIG_DATA * ); - Word32 inputIndex; +ivas_error IVAS_REND_AddInput_fx( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const AUDIO_CONFIG inConfig, /* i : audio config for a new input */ + IVAS_REND_InputId *inputId /* o : ID of the new input */ +) +{ + ivas_error error; + Word32 maxNumInputsOfType; + void *inputsArray; + Word32 inputStructSize; + ivas_error ( *activateInput )( void *, AUDIO_CONFIG, IVAS_REND_InputId, RENDER_CONFIG_DATA * ); + Word32 inputIndex; - /* Validate function arguments */ - IF( hIvasRend == NULL || inputId == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } + /* Validate function arguments */ + IF( hIvasRend == NULL || inputId == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } - SWITCH( getAudioConfigType( inConfig ) ) - { - case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: - maxNumInputsOfType = RENDERER_MAX_ISM_INPUTS; - inputsArray = hIvasRend->inputsIsm; - inputStructSize = sizeof( *hIvasRend->inputsIsm ); - activateInput = setRendInputActiveIsm; - BREAK; - case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: - maxNumInputsOfType = RENDERER_MAX_MC_INPUTS; - inputsArray = hIvasRend->inputsMc; - inputStructSize = sizeof( *hIvasRend->inputsMc ); - activateInput = setRendInputActiveMc; - BREAK; - case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: - maxNumInputsOfType = RENDERER_MAX_SBA_INPUTS; - inputsArray = hIvasRend->inputsSba; - inputStructSize = sizeof( *hIvasRend->inputsSba ); - activateInput = setRendInputActiveSba; - BREAK; - case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: - maxNumInputsOfType = RENDERER_MAX_MASA_INPUTS; - inputsArray = hIvasRend->inputsMasa; - inputStructSize = sizeof( *hIvasRend->inputsMasa ); - activateInput = setRendInputActiveMasa; - BREAK; - default: - return IVAS_ERR_INVALID_INPUT_FORMAT; - } + SWITCH( getAudioConfigType( inConfig ) ) + { + case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: + maxNumInputsOfType = RENDERER_MAX_ISM_INPUTS; + inputsArray = hIvasRend->inputsIsm; + inputStructSize = sizeof( *hIvasRend->inputsIsm ); + activateInput = setRendInputActiveIsm; + BREAK; + case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: + maxNumInputsOfType = RENDERER_MAX_MC_INPUTS; + inputsArray = hIvasRend->inputsMc; + inputStructSize = sizeof( *hIvasRend->inputsMc ); + activateInput = setRendInputActiveMc; + BREAK; + case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: + maxNumInputsOfType = RENDERER_MAX_SBA_INPUTS; + inputsArray = hIvasRend->inputsSba; + inputStructSize = sizeof( *hIvasRend->inputsSba ); + activateInput = setRendInputActiveSba; + BREAK; + case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: + maxNumInputsOfType = RENDERER_MAX_MASA_INPUTS; + inputsArray = hIvasRend->inputsMasa; + inputStructSize = sizeof( *hIvasRend->inputsMasa ); + activateInput = setRendInputActiveMasa; + BREAK; + default: + return IVAS_ERR_INVALID_INPUT_FORMAT; + } - /* Find first free input in array corresponding to input type */ - IF( ( error = findFreeInputSlot_fx( inputsArray, inputStructSize, maxNumInputsOfType, &inputIndex ) ) != IVAS_ERR_OK ) - { - return error; - } + /* Find first free input in array corresponding to input type */ + IF( ( error = findFreeInputSlot_fx( inputsArray, inputStructSize, maxNumInputsOfType, &inputIndex ) ) != IVAS_ERR_OK ) + { + return error; + } - *inputId = makeInputId( inConfig, inputIndex ); + *inputId = makeInputId( inConfig, inputIndex ); - IF( ( error = activateInput( (uint8_t *) inputsArray + inputStructSize * inputIndex, inConfig, *inputId, hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) - { - return error; - } + IF( ( error = activateInput( (uint8_t *) inputsArray + inputStructSize * inputIndex, inConfig, *inputId, hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) + { + return error; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif @@ -5979,10 +5976,10 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( return error; } #else - if ( ( error = validateCustomLsLayout( layout ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = validateCustomLsLayout( layout ) ) != IVAS_ERR_OK ) + { + return error; + } #endif if ( ( error = getInputById( hIvasRend, inputId, (void **) &inputMc ) ) != IVAS_ERR_OK ) @@ -6056,30 +6053,30 @@ ivas_error IVAS_REND_SetInputGain( return IVAS_ERR_OK; } #else - ivas_error IVAS_REND_SetInputGain_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 gain /* i : linear gain (not in dB) */ - ) - { - input_base *inputBase; - ivas_error error; +ivas_error IVAS_REND_SetInputGain_fx( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 gain /* i : linear gain (not in dB) */ +) +{ + input_base *inputBase; + ivas_error error; - /* Validate function arguments */ - IF( hIvasRend == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } + /* Validate function arguments */ + IF( hIvasRend == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } - IF( ( error = getInputById( hIvasRend, inputId, (void **) &inputBase ) ) != IVAS_ERR_OK ) - { - return error; - } + IF( ( error = getInputById( hIvasRend, inputId, (void **) &inputBase ) ) != IVAS_ERR_OK ) + { + return error; + } - inputBase->gain_fx = gain; + inputBase->gain_fx = gain; - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif /*-------------------------------------------------------------------* @@ -6131,48 +6128,48 @@ ivas_error IVAS_REND_SetInputLfeMtx( return IVAS_ERR_OK; } #else - ivas_error IVAS_REND_SetInputLfeMtx_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const IVAS_REND_LfePanMtx_fx *lfePanMtx /* i : LFE panning matrix */ - ) - { - Word16 i; - input_base *pInputBase; - input_mc *pInputMc; - ivas_error error; +ivas_error IVAS_REND_SetInputLfeMtx_fx( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_REND_LfePanMtx_fx *lfePanMtx /* i : LFE panning matrix */ +) +{ + Word16 i; + input_base *pInputBase; + input_mc *pInputMc; + ivas_error error; - /* Validate function arguments */ - IF( hIvasRend == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } + /* Validate function arguments */ + IF( hIvasRend == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } - IF( ( error = getInputById( hIvasRend, inputId, (void **) &pInputBase ) ) != IVAS_ERR_OK ) - { - return error; - } + IF( ( error = getInputById( hIvasRend, inputId, (void **) &pInputBase ) ) != IVAS_ERR_OK ) + { + return error; + } - IF( getAudioConfigType( pInputBase->inConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) - { - /* Custom LFE panning matrix only makes sense with channel-based input */ - return IVAS_ERR_INVALID_INPUT_FORMAT; - } - pInputMc = (input_mc *) pInputBase; + IF( getAudioConfigType( pInputBase->inConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) + { + /* Custom LFE panning matrix only makes sense with channel-based input */ + return IVAS_ERR_INVALID_INPUT_FORMAT; + } + pInputMc = (input_mc *) pInputBase; - /* copy LFE panning matrix */ - FOR( i = 0; i < RENDERER_MAX_INPUT_LFE_CHANNELS; i++ ) - { - Copy32( ( *lfePanMtx )[i], pInputMc->lfeRouting.lfePanMtx_fx[i], IVAS_MAX_OUTPUT_CHANNELS ); - } + /* copy LFE panning matrix */ + FOR( i = 0; i < RENDERER_MAX_INPUT_LFE_CHANNELS; i++ ) + { + Copy32( ( *lfePanMtx )[i], pInputMc->lfeRouting.lfePanMtx_fx[i], IVAS_MAX_OUTPUT_CHANNELS ); + } - IF( ( error = updateMcPanGains( pInputMc, hIvasRend->outputConfig ) ) != IVAS_ERR_OK ) - { - return error; - } + IF( ( error = updateMcPanGains( pInputMc, hIvasRend->outputConfig ) ) != IVAS_ERR_OK ) + { + return error; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif #ifdef IVAS_FLOAT_FIXED @@ -6225,48 +6222,48 @@ ivas_error IVAS_REND_SetInputLfePos_fx( return IVAS_ERR_OK; } #else - ivas_error IVAS_REND_SetInputLfePos( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const float inputGain, /* i : Input gain to be applied to the LFE channel(s) */ - const float outputAzimuth, /* i : Output azimuth position */ - const float outputElevation /* i : Output elevation position */ - ) - { - input_base *pInputBase; - input_mc *pInputMc; - ivas_error error; +ivas_error IVAS_REND_SetInputLfePos( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const float inputGain, /* i : Input gain to be applied to the LFE channel(s) */ + const float outputAzimuth, /* i : Output azimuth position */ + const float outputElevation /* i : Output elevation position */ +) +{ + input_base *pInputBase; + input_mc *pInputMc; + ivas_error error; - /* Validate function arguments */ - if ( hIvasRend == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } + /* Validate function arguments */ + if ( hIvasRend == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } - if ( ( error = getInputById( hIvasRend, inputId, (void **) &pInputBase ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getInputById( hIvasRend, inputId, (void **) &pInputBase ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( getAudioConfigType( pInputBase->inConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) - { - /* Custom LFE routing only makes sense with channel-based input */ - return IVAS_ERR_INVALID_INPUT_FORMAT; - } - pInputMc = (input_mc *) pInputBase; + if ( getAudioConfigType( pInputBase->inConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) + { + /* Custom LFE routing only makes sense with channel-based input */ + return IVAS_ERR_INVALID_INPUT_FORMAT; + } + pInputMc = (input_mc *) pInputBase; - pInputMc->lfeRouting.pan_lfe = true; - pInputMc->lfeRouting.lfeInputGain = inputGain; - pInputMc->lfeRouting.lfeOutputAzimuth = outputAzimuth; - pInputMc->lfeRouting.lfeOutputElevation = outputElevation; + pInputMc->lfeRouting.pan_lfe = true; + pInputMc->lfeRouting.lfeInputGain = inputGain; + pInputMc->lfeRouting.lfeOutputAzimuth = outputAzimuth; + pInputMc->lfeRouting.lfeOutputElevation = outputElevation; - if ( ( error = updateMcPanGains( pInputMc, hIvasRend->outputConfig ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = updateMcPanGains( pInputMc, hIvasRend->outputConfig ) ) != IVAS_ERR_OK ) + { + return error; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif /*-------------------------------------------------------------------* @@ -6350,33 +6347,33 @@ ivas_error IVAS_REND_GetInputNumChannels( return IVAS_ERR_OK; } #else - ivas_error IVAS_REND_GetInputNumChannels( - IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - Word16 *numChannels /* o : number of channels of the input */ - ) - { - ivas_error error; - const input_base *pInput; +ivas_error IVAS_REND_GetInputNumChannels( + IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + Word16 *numChannels /* o : number of channels of the input */ +) +{ + ivas_error error; + const input_base *pInput; - /* Validate function arguments */ - IF( hIvasRend == NULL || numChannels == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } + /* Validate function arguments */ + IF( hIvasRend == NULL || numChannels == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } - IF( ( error = getConstInputById( hIvasRend, inputId, (const void **) &pInput ) ) != IVAS_ERR_OK ) - { - return error; - } + IF( ( error = getConstInputById( hIvasRend, inputId, (const void **) &pInput ) ) != IVAS_ERR_OK ) + { + return error; + } - IF( ( error = getRendInputNumChannels( pInput, numChannels ) ) != IVAS_ERR_OK ) - { - return error; - } + IF( ( error = getRendInputNumChannels( pInput, numChannels ) ) != IVAS_ERR_OK ) + { + return error; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif /*-------------------------------------------------------------------* @@ -6403,23 +6400,23 @@ ivas_error IVAS_REND_GetNumAllObjects( return IVAS_ERR_OK; } #else - ivas_error IVAS_REND_GetNumAllObjects( - IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - Word16 * numChannels /* o : number of all objects */ - ) - { - IF( hIvasRend == NULL || numChannels == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } +ivas_error IVAS_REND_GetNumAllObjects( + IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ + Word16 *numChannels /* o : number of all objects */ +) +{ + IF( hIvasRend == NULL || numChannels == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } - IF( EQ_32( hIvasRend->outputConfig, IVAS_AUDIO_CONFIG_MASA1 ) || EQ_32( hIvasRend->outputConfig, IVAS_AUDIO_CONFIG_MASA2 ) ) - { - *numChannels = (Word16) hIvasRend->inputsIsm[0].total_num_objects; - } + IF( EQ_32( hIvasRend->outputConfig, IVAS_AUDIO_CONFIG_MASA1 ) || EQ_32( hIvasRend->outputConfig, IVAS_AUDIO_CONFIG_MASA2 ) ) + { + *numChannels = (Word16) hIvasRend->inputsIsm[0].total_num_objects; + } - return IVAS_ERR_OK; - } + return IVAS_ERR_OK; +} #endif /*-------------------------------------------------------------------* @@ -6498,76 +6495,76 @@ ivas_error IVAS_REND_GetDelay( return IVAS_ERR_OK; } #else - ivas_error IVAS_REND_GetDelay_fx( - IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer state */ - Word16 * nSamples, /* o : Renderer delay in samples */ - Word32 * timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ - ) - { - /* TODO tmu : this function only returns the maximum delay across all inputs - * Ideally each input has its own delay buffer and everything is aligned (binaural and LFE filtering delays are nonuniform) - */ - Word16 i; - Word32 latency_ns; - Word32 max_latency_ns; +ivas_error IVAS_REND_GetDelay_fx( + IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer state */ + Word16 *nSamples, /* o : Renderer delay in samples */ + Word32 *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ +) +{ + /* TODO tmu : this function only returns the maximum delay across all inputs + * Ideally each input has its own delay buffer and everything is aligned (binaural and LFE filtering delays are nonuniform) + */ + Word16 i; + Word32 latency_ns; + Word32 max_latency_ns; - Word32 timescale_by_ns[7] = { 0, 17180, 34360, 0, 68719, 0, 103079 }; + Word32 timescale_by_ns[7] = { 0, 17180, 34360, 0, 68719, 0, 103079 }; - /* Validate function arguments */ - IF( hIvasRend == NULL || nSamples == NULL || timeScale == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } + /* Validate function arguments */ + IF( hIvasRend == NULL || nSamples == NULL || timeScale == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } - *timeScale = hIvasRend->sampleRateOut; - assert( *timeScale == 8000 || *timeScale == 16000 || *timeScale == 32000 || *timeScale == 48000 ); - *nSamples = 0; - max_latency_ns = 0; + *timeScale = hIvasRend->sampleRateOut; + assert( *timeScale == 8000 || *timeScale == 16000 || *timeScale == 32000 || *timeScale == 48000 ); + *nSamples = 0; + max_latency_ns = 0; - /* Compute the maximum delay across all inputs */ - FOR( i = 0; i < RENDERER_MAX_ISM_INPUTS; i++ ) - { - IF( NE_32( hIvasRend->inputsIsm[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) - { - latency_ns = L_max( ( hIvasRend->inputsIsm[i].crendWrapper != NULL ) ? hIvasRend->inputsIsm[i].crendWrapper->binaural_latency_ns : 0, - hIvasRend->inputsIsm[i].tdRendWrapper.binaural_latency_ns ); - max_latency_ns = L_max( max_latency_ns, latency_ns ); - } - } + /* Compute the maximum delay across all inputs */ + FOR( i = 0; i < RENDERER_MAX_ISM_INPUTS; i++ ) + { + IF( NE_32( hIvasRend->inputsIsm[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) + { + latency_ns = L_max( ( hIvasRend->inputsIsm[i].crendWrapper != NULL ) ? hIvasRend->inputsIsm[i].crendWrapper->binaural_latency_ns : 0, + hIvasRend->inputsIsm[i].tdRendWrapper.binaural_latency_ns ); + max_latency_ns = L_max( max_latency_ns, latency_ns ); + } + } - FOR( i = 0; i < RENDERER_MAX_MC_INPUTS; i++ ) - { - IF( NE_32( hIvasRend->inputsMc[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) - { - latency_ns = L_max( ( hIvasRend->inputsMc[i].crendWrapper != NULL ) ? hIvasRend->inputsMc[i].crendWrapper->binaural_latency_ns : 0, - hIvasRend->inputsMc[i].tdRendWrapper.binaural_latency_ns ); - max_latency_ns = L_max( max_latency_ns, latency_ns ); - } - } + FOR( i = 0; i < RENDERER_MAX_MC_INPUTS; i++ ) + { + IF( NE_32( hIvasRend->inputsMc[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) + { + latency_ns = L_max( ( hIvasRend->inputsMc[i].crendWrapper != NULL ) ? hIvasRend->inputsMc[i].crendWrapper->binaural_latency_ns : 0, + hIvasRend->inputsMc[i].tdRendWrapper.binaural_latency_ns ); + max_latency_ns = L_max( max_latency_ns, latency_ns ); + } + } - FOR( i = 0; i < RENDERER_MAX_SBA_INPUTS; i++ ) + FOR( i = 0; i < RENDERER_MAX_SBA_INPUTS; i++ ) + { + IF( NE_32( hIvasRend->inputsSba[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) + { { - IF( NE_32( hIvasRend->inputsSba[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) - { - { - latency_ns = ( hIvasRend->inputsSba[i].crendWrapper != NULL ) ? hIvasRend->inputsSba[i].crendWrapper->binaural_latency_ns : 0; - max_latency_ns = L_max( max_latency_ns, latency_ns ); - } - } + latency_ns = ( hIvasRend->inputsSba[i].crendWrapper != NULL ) ? hIvasRend->inputsSba[i].crendWrapper->binaural_latency_ns : 0; + max_latency_ns = L_max( max_latency_ns, latency_ns ); } - - - FOR( i = 0; i < RENDERER_MAX_MASA_INPUTS; i++ ){ - IF( NE_32( hIvasRend->inputsMasa[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ){ - latency_ns = (Word32) ( IVAS_FB_DEC_DELAY_NS ); - max_latency_ns = L_max( max_latency_ns, latency_ns ); } } - //*nSamples = (Word16) roundf( (float) max_latency_ns * *timeScale / 1000000000.f ); - *nSamples = extract_l( Mpy_32_32_r( max_latency_ns, timescale_by_ns[*timeScale / 8000] ) ); - return IVAS_ERR_OK; + FOR( i = 0; i < RENDERER_MAX_MASA_INPUTS; i++ ){ + IF( NE_32( hIvasRend->inputsMasa[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ){ + latency_ns = (Word32) ( IVAS_FB_DEC_DELAY_NS ); + max_latency_ns = L_max( max_latency_ns, latency_ns ); +} +} + +//*nSamples = (Word16) roundf( (float) max_latency_ns * *timeScale / 1000000000.f ); +*nSamples = extract_l( Mpy_32_32_r( max_latency_ns, timescale_by_ns[*timeScale / 8000] ) ); + +return IVAS_ERR_OK; } #endif @@ -6586,53 +6583,52 @@ ivas_error IVAS_REND_FeedInputAudio_fx( { ivas_error error; input_base *inputBase; - int16_t numInputChannels; + Word16 numInputChannels; /* Validate function arguments */ - if ( hIvasRend == NULL || inputAudio.data == NULL ) + IF ( hIvasRend == NULL || inputAudio.data == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - if ( inputAudio.config.numSamplesPerChannel <= 0 || MAX_BUFFER_LENGTH_PER_CHANNEL < inputAudio.config.numSamplesPerChannel ) + IF (LE_16( inputAudio.config.numSamplesPerChannel , 0 )|| LT_16(MAX_BUFFER_LENGTH_PER_CHANNEL , inputAudio.config.numSamplesPerChannel) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BUFFER_SIZE, "Buffer size outside of supported range" ); } - if ( inputAudio.config.numChannels <= 0 || MAX_INPUT_CHANNELS < inputAudio.config.numChannels ) + IF ( LE_16(inputAudio.config.numChannels , 0) ||LT_16( MAX_INPUT_CHANNELS , inputAudio.config.numChannels) ) { return IVAS_ERR_WRONG_NUM_CHANNELS; } - if ( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL && + IF ( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL && inputAudio.config.numSamplesPerChannel * 1000 != ( BINAURAL_RENDERING_FRAME_SIZE_MS * hIvasRend->num_subframes ) * hIvasRend->sampleRateOut ) { return IVAS_ERROR( IVAS_ERR_INVALID_BUFFER_SIZE, "Binaural rendering requires specific frame size" ); } - if ( ( error = getInputById( hIvasRend, inputId, (void **) &inputBase ) ) != IVAS_ERR_OK ) + IF ( ( error = getInputById( hIvasRend, inputId, (void **) &inputBase ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = getRendInputNumChannels( inputBase, &numInputChannels ) ) != IVAS_ERR_OK ) + IF ( ( error = getRendInputNumChannels( inputBase, &numInputChannels ) ) != IVAS_ERR_OK ) { return error; } - if ( ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_MASA1 || hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_MASA2 ) && inputBase->inConfig == IVAS_AUDIO_CONFIG_OBA ) + IF ( ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_MASA1 || hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_MASA2 ) && inputBase->inConfig == IVAS_AUDIO_CONFIG_OBA ) { - numInputChannels = (int16_t) hIvasRend->inputsIsm[0].total_num_objects; + numInputChannels = (Word16) hIvasRend->inputsIsm[0].total_num_objects; } - if ( numInputChannels != inputAudio.config.numChannels ) + IF (NE_16( numInputChannels , inputAudio.config.numChannels )) { return IVAS_ERR_WRONG_NUM_CHANNELS; } inputBase->inputBuffer.config = inputAudio.config; - mvr2r( inputAudio.data, inputBase->inputBuffer.data, inputAudio.config.numSamplesPerChannel * inputAudio.config.numChannels ); mvr2r_Word32( inputAudio.data_fx, inputBase->inputBuffer.data_fx, inputAudio.config.numSamplesPerChannel * inputAudio.config.numChannels ); inputBase->numNewSamplesPerChannel = inputAudio.config.numSamplesPerChannel; @@ -6805,8 +6801,8 @@ ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( /* Set position to OMasa struct */ #ifdef IVAS_FLOAT_FIXED - hIvasRend->inputsIsm->hOMasa->ism_azimuth_fx[inputIndex] = floatToFixed(objectPosition.azimuth, Q22); - hIvasRend->inputsIsm->hOMasa->ism_elevation_fx[inputIndex] = floatToFixed(objectPosition.elevation, Q22); + hIvasRend->inputsIsm->hOMasa->ism_azimuth_fx[inputIndex] = floatToFixed( objectPosition.azimuth, Q22 ); + hIvasRend->inputsIsm->hOMasa->ism_elevation_fx[inputIndex] = floatToFixed( objectPosition.elevation, Q22 ); #else hIvasRend->inputsIsm->hOMasa->ism_azimuth[inputIndex] = objectPosition.azimuth; hIvasRend->inputsIsm->hOMasa->ism_elevation[inputIndex] = objectPosition.elevation; @@ -7269,7 +7265,7 @@ ivas_error IVAS_REND_SetReferenceRotation( ivas_error error; /* Validate function arguments */ - if ( hIvasRend == NULL ) + IF ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } @@ -7278,7 +7274,7 @@ ivas_error IVAS_REND_SetReferenceRotation( error = ivas_orient_trk_SetReferenceRotation_fx( hIvasRend->headRotData.hOrientationTracker, refRot ); - if ( error != IVAS_ERR_OK ) + IF ( error != IVAS_ERR_OK ) { return error; @@ -7424,7 +7420,7 @@ ivas_error IVAS_REND_CombineHeadAndExternalOrientation( IVAS_REND_HANDLE hIvasRend /* i/o: Renderer handle */ ) { - if ( hIvasRend == NULL ) + IF ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } @@ -8923,24 +8919,24 @@ static void renderIsmToMasa( copyBufferTo2dArray( ismInput->base.inputBuffer, tmpRendBuffer ); #ifdef IVAS_FLOAT_FIXED Word16 input_e[MAX_NUM_OBJECTS], max_e; - FOR(i = 0; i < MAX_NUM_OBJECTS; i++) + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { - f2me_buf(tmpRendBuffer[i], tmpRendBuffer_fx[i], &input_e[i], L_FRAME48k); + f2me_buf( tmpRendBuffer[i], tmpRendBuffer_fx[i], &input_e[i], L_FRAME48k ); } - Word16 guard_bits = find_guarded_bits_fx(L_FRAME48k); + Word16 guard_bits = find_guarded_bits_fx( L_FRAME48k ); max_e = input_e[0]; - FOR (Word16 i = 1; i < MAX_NUM_OBJECTS; i++) + FOR ( i = 1; i < MAX_NUM_OBJECTS; i++) { - IF (max_e < input_e[0]) - max_e = input_e[i]; + IF( max_e < input_e[0] ) + max_e = input_e[i]; } - FOR(i = 0; i < MAX_NUM_OBJECTS; i++) + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { - FOR (j = 0; j < L_FRAME48k; j++) + FOR( j = 0; j < L_FRAME48k; j++ ) { - tmpRendBuffer_fx[i][j] = L_shr(tmpRendBuffer_fx[i][j], max_e - input_e[i] + guard_bits); + tmpRendBuffer_fx[i][j] = L_shr( tmpRendBuffer_fx[i][j], max_e - input_e[i] + guard_bits ); } } max_e += guard_bits; @@ -8948,14 +8944,16 @@ static void renderIsmToMasa( #endif #ifdef IVAS_FLOAT_FIXED - ivas_omasa_ana_fx(ismInput->hOMasa, tmpRendBuffer, tmpRendBuffer_fx, &q_fact, ismInput->base.inputBuffer.config.numSamplesPerChannel, outAudio.config.numChannels, ismInput->base.inputBuffer.config.numChannels); + ivas_omasa_ana_fx(ismInput->hOMasa, tmpRendBuffer_fx, &q_fact, ismInput->base.inputBuffer.config.numSamplesPerChannel, outAudio.config.numChannels, ismInput->base.inputBuffer.config.numChannels); - FOR (Word16 block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) { - FOR (Word16 band_m_idx = 0; band_m_idx < ismInput->hOMasa->nbands; band_m_idx++) { - ismInput->hOMasa->energy[block_m_idx][band_m_idx] = fixedToFloat(ismInput->hOMasa->energy_fx[block_m_idx][band_m_idx], ismInput->hOMasa->energy_q); + FOR( Word16 block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + FOR( Word16 band_m_idx = 0; band_m_idx < ismInput->hOMasa->nbands; band_m_idx++ ) + { + ismInput->hOMasa->energy[block_m_idx][band_m_idx] = fixedToFloat( ismInput->hOMasa->energy_fx[block_m_idx][band_m_idx], ismInput->hOMasa->energy_q ); } } - FOR(Word16 i = 0; i < ismInput->base.inputBuffer.config.numChannels; i++) { + FOR( i = 0; i < ismInput->base.inputBuffer.config.numChannels; i++) { fixedToFloat_arrL(tmpRendBuffer_fx[i], tmpRendBuffer[i], q_fact, L_FRAME48k ); } @@ -11238,7 +11236,7 @@ ivas_error IVAS_REND_MergeMasaMetadata( inEne1 = &( hIvasRend->inputsIsm->hOMasa->energy ); #ifdef IVAS_FLOAT_FIXED inEne1_fx = &(hIvasRend->inputsIsm->hOMasa->energy_fx); - inEne1_e = &(hIvasRend->inputsIsm->hOMasa->energy_e); + inEne1_e = (hIvasRend->inputsIsm->hOMasa->energy_e); for (Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++) @@ -11253,11 +11251,11 @@ ivas_error IVAS_REND_MergeMasaMetadata( inEne1 = &( hIvasRend->inputsMc->hMcMasa->energy ); #ifdef IVAS_FLOAT_FIXED inEne1_fx = &( hIvasRend->inputsMc->hMcMasa->energy_fx ); - inEne1_e = &(hIvasRend->inputsMc->hMcMasa->energy_e); + inEne1_e = (hIvasRend->inputsMc->hMcMasa->energy_exp); for (Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++) { - f2me_buf(hIvasRend->inputsMc->hMcMasa->energy[i], hIvasRend->inputsMc->hMcMasa->energy_fx[i], &hIvasRend->inputsMc->hMcMasa->energy_e[i], MASA_FREQUENCY_BANDS); + f2me_buf(hIvasRend->inputsMc->hMcMasa->energy[i], hIvasRend->inputsMc->hMcMasa->energy_fx[i], &hIvasRend->inputsMc->hMcMasa->energy_exp[i], MASA_FREQUENCY_BANDS); } #endif } @@ -11267,10 +11265,10 @@ ivas_error IVAS_REND_MergeMasaMetadata( inEne1 = &( hIvasRend->inputsSba->hDirAC->energy ); #ifdef IVAS_FLOAT_FIXED inEne1_fx = &(hIvasRend->inputsSba->hDirAC->energy_fx); - inEne1_e = &(hIvasRend->inputsSba->hDirAC->energy_e); + inEne1_e = (hIvasRend->inputsSba->hDirAC->energy_exp); for (Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++) { - f2me_buf(hIvasRend->inputsSba->hDirAC->energy[i], hIvasRend->inputsSba->hDirAC->energy_fx[i], &hIvasRend->inputsSba->hDirAC->energy_e[i], MASA_FREQUENCY_BANDS); + f2me_buf(hIvasRend->inputsSba->hDirAC->energy[i], hIvasRend->inputsSba->hDirAC->energy_fx[i], &hIvasRend->inputsSba->hDirAC->energy_exp[i], MASA_FREQUENCY_BANDS); } #endif @@ -11281,7 +11279,7 @@ ivas_error IVAS_REND_MergeMasaMetadata( inEne1 = &( hIvasRend->inputsMasa->hMasaPrerend->energy ); #ifdef IVAS_FLOAT_FIXED inEne1_fx = &( hIvasRend->inputsMasa->hMasaPrerend->energy_fx ); - inEne1_e = &(hIvasRend->inputsMasa->hMasaPrerend->energy_e); + inEne1_e = (hIvasRend->inputsMasa->hMasaPrerend->energy_e); for (Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++) { f2me_buf(hIvasRend->inputsMasa->hMasaPrerend->energy[i], hIvasRend->inputsMasa->hMasaPrerend->energy_fx[i], &hIvasRend->inputsMasa->hMasaPrerend->energy_e[i], MASA_FREQUENCY_BANDS); @@ -11300,7 +11298,7 @@ ivas_error IVAS_REND_MergeMasaMetadata( inEne2 = &( hIvasRend->inputsIsm->hOMasa->energy ); #ifdef IVAS_FLOAT_FIXED inEne2_fx = &(hIvasRend->inputsIsm->hOMasa->energy_fx); - inEne2_e = &(hIvasRend->inputsIsm->hOMasa->energy_e); + inEne2_e = (hIvasRend->inputsIsm->hOMasa->energy_e); for (Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++) { @@ -11315,10 +11313,10 @@ ivas_error IVAS_REND_MergeMasaMetadata( inEne2 = &( hIvasRend->inputsMc->hMcMasa->energy ); #ifdef IVAS_FLOAT_FIXED inEne2_fx = &( hIvasRend->inputsMc->hMcMasa->energy_fx ); - inEne2_e = &(hIvasRend->inputsMc->hMcMasa->energy_e); + inEne2_e = (hIvasRend->inputsMc->hMcMasa->energy_exp); for (Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++) { - f2me_buf(hIvasRend->inputsMc->hMcMasa->energy[i], hIvasRend->inputsMc->hMcMasa->energy_fx[i], &hIvasRend->inputsMc->hMcMasa->energy_e[i], MASA_FREQUENCY_BANDS); + f2me_buf(hIvasRend->inputsMc->hMcMasa->energy[i], hIvasRend->inputsMc->hMcMasa->energy_fx[i], &hIvasRend->inputsMc->hMcMasa->energy_exp[i], MASA_FREQUENCY_BANDS); } #endif } @@ -11328,10 +11326,10 @@ ivas_error IVAS_REND_MergeMasaMetadata( inEne2 = &( hIvasRend->inputsSba->hDirAC->energy ); #ifdef IVAS_FLOAT_FIXED inEne2_fx = &( hIvasRend->inputsSba->hDirAC->energy_fx ); - inEne2_e = &(hIvasRend->inputsSba->hDirAC->energy_e); + inEne2_e = (hIvasRend->inputsSba->hDirAC->energy_exp); for (Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++) { - f2me_buf(hIvasRend->inputsSba->hDirAC->energy[i], hIvasRend->inputsSba->hDirAC->energy_fx[i], &hIvasRend->inputsSba->hDirAC->energy_e[i], MASA_FREQUENCY_BANDS); + f2me_buf(hIvasRend->inputsSba->hDirAC->energy[i], hIvasRend->inputsSba->hDirAC->energy_fx[i], &hIvasRend->inputsSba->hDirAC->energy_exp[i], MASA_FREQUENCY_BANDS); } #endif } @@ -11341,7 +11339,7 @@ ivas_error IVAS_REND_MergeMasaMetadata( inEne2 = &( hIvasRend->inputsMasa->hMasaPrerend->energy ); #ifdef IVAS_FLOAT_FIXED inEne2_fx = &( hIvasRend->inputsMasa->hMasaPrerend->energy_fx ); - inEne2_e = &(hIvasRend->inputsMasa->hMasaPrerend->energy_e); + inEne2_e = (hIvasRend->inputsMasa->hMasaPrerend->energy_e); for (Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++) { f2me_buf(hIvasRend->inputsMasa->hMasaPrerend->energy[i], hIvasRend->inputsMasa->hMasaPrerend->energy_fx[i], &hIvasRend->inputsMasa->hMasaPrerend->energy_e[i], MASA_FREQUENCY_BANDS); @@ -11356,7 +11354,7 @@ ivas_error IVAS_REND_MergeMasaMetadata( /* Merge metadata */ #ifdef IVAS_FLOAT_FIXED - ivas_prerend_merge_masa_metadata_fx( *hMasaExtOutMeta, *hMasaExtOutMeta, inputType1, *inEne1_fx, inEne1_e, inMeta2, inputType2, inEne2_fx, inEne2_e ); + ivas_prerend_merge_masa_metadata_fx( *hMasaExtOutMeta, *hMasaExtOutMeta, inputType1, *inEne1_fx, inEne1_e, inMeta2, inputType2, *inEne2_fx, inEne2_e ); FOR(Word32 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++) { diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index c8b7643c1..a6267035c 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -1066,7 +1066,6 @@ static ivas_error create_HRTF_from_rawdata( float *tmp, temp_buf[1]; tmp = temp_buf; memcpy( tmp, hrtf_data_rptr, sizeof( float ) ); - pOut_to_bin_wptr_fx[l] = (Word32) ( (float) hrtf_data_rptr[l] * ONE_IN_Q29 ); pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } @@ -1099,7 +1098,6 @@ static ivas_error create_HRTF_from_rawdata( float *tmp, temp_buf[1]; tmp = temp_buf; memcpy( tmp, hrtf_data_rptr, sizeof( float ) ); - pOut_to_bin_wptr_fx[l] = (Word32) ( (float) hrtf_data_rptr[l] * ONE_IN_Q29 ); pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } @@ -1137,7 +1135,6 @@ static ivas_error create_HRTF_from_rawdata( float *tmp, temp_buf[1]; tmp = temp_buf; memcpy( tmp, hrtf_data_rptr, sizeof( float ) ); - pOut_to_bin_wptr_fx[l] = (Word32) ( (float) hrtf_data_rptr[l] * ONE_IN_Q29 ); pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } @@ -1168,7 +1165,6 @@ static ivas_error create_HRTF_from_rawdata( float *tmp, temp_buf[1]; tmp = temp_buf; memcpy( tmp, hrtf_data_rptr, sizeof( float ) ); - pOut_to_bin_wptr_fx[l] = (Word32) ( (float) hrtf_data_rptr[l] * ONE_IN_Q29 ); pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } @@ -1542,7 +1538,11 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { memcpy( f_tmp_ntaps_sba, hrtf_data_rptr, BINAURAL_NTAPS_SBA * sizeof( float ) ); hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( float ); +#ifdef MSAN_FIX + floatToFixed_arrL( f_tmp_ntaps_sba, ( *hHRTF )->rightHRIRImag_HOA3_fx[i][j], Q29, BINAURAL_NTAPS_SBA ); +#else floatToFixed_arrL( f_tmp_ntaps_sba, ( *hHRTF )->rightHRIRReal_HOA3_fx[i][j], Q29, BINAURAL_NTAPS_SBA ); +#endif } } } -- GitLab