diff --git a/lib_com/cnst.h b/lib_com/cnst.h index f3b76347673632d17c6a200543f0afaa97cb54a5..637fdea38c2f0eceee1072a6c50d0cd367d360fd 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -1967,7 +1967,7 @@ typedef enum _DCTTYPE #define INV_PREECHO_SMOOTH_LENP1 ( 1 / ( PREECHO_SMOOTH_LEN + 1.0 ) ); #define EPSILON 0.000000000000001f -#define EPSILON_fx 0 +#define EPSILON_FX 0 #define MAX_SEGMENT_LENGTH 480 #define NUM_TIME_SWITCHING_BLOCKS 4 diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 662aa3e5898d180a0bedcea8a82be7f0e891a4b9..3abfd355068da3c02b0094db677b1076f49c0d97 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -48,9 +48,10 @@ #endif // DUMPS_ENABLED #include "prot_fx1.h" #include "prot_fx2.h" +#define float_to_fixed( n, factor ) ( round( n * ( 1 << factor ) ) ) +#define fixed_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) #include "debug.h" - /*-----------------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------------*/ @@ -138,12 +139,12 @@ ivas_error ivas_jbm_dec_tc( #ifdef IVAS_FLOAT_FIXED Word32 *output_fx[2]; Word16 q_output = 11; - output_fx[0] = malloc(sizeof(Word32) * L_FRAME48k); - output_fx[1] = malloc(sizeof(Word32) * L_FRAME48k); - set32_fx(&output_fx[0][0], 0, L_FRAME48k); - set32_fx(&output_fx[1][0], 0, L_FRAME48k); + output_fx[0] = malloc( sizeof( Word32 ) * L_FRAME48k ); + output_fx[1] = malloc( sizeof( Word32 ) * L_FRAME48k ); + set32_fx( &output_fx[0][0], 0, L_FRAME48k ); + set32_fx( &output_fx[1][0], 0, L_FRAME48k ); - IF ( ( error = ivas_cpe_dec_fx( st_ivas, 0, &output_fx[0], output_frame, 0, &q_output ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &output_fx[0], output_frame, 0, &q_output ) ) != IVAS_ERR_OK ) { return error; } @@ -210,7 +211,7 @@ ivas_error ivas_jbm_dec_tc( set32_fx( output_fx[0], 0, L_FRAME48k ); for ( int k = 0; k < 45; k++ ) { - st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth[k] * ONE_IN_Q11 ); + st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth_fx[k] = (Word32) ( st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->prev_hb_synth[k] * ONE_IN_Q11 ); } IF( ( error = ivas_sce_dec_fx( st_ivas, st_ivas->hISMDTX.sce_id_dtx, &output_fx[0], output_frame, nb_bits_metadata[st_ivas->hISMDTX.sce_id_dtx] ) ) != IVAS_ERR_OK ) @@ -242,31 +243,33 @@ ivas_error ivas_jbm_dec_tc( { #ifdef IVAS_FLOAT_FIXED - FOR (Word16 ind = 0; ind < st_ivas->nchan_ism; ind++) { - st_ivas->hIsmMetaData[ind]->azimuth_fx = (Word32)(st_ivas->hIsmMetaData[ind]->azimuth * (1 << 22)); - st_ivas->hIsmMetaData[ind]->elevation_fx = (Word32)(st_ivas->hIsmMetaData[ind]->elevation * (1 << 22)); - st_ivas->hIsmMetaData[ind]->last_azimuth_fx = (Word32)(st_ivas->hIsmMetaData[ind]->last_azimuth * (1 << 22)); - st_ivas->hIsmMetaData[ind]->last_elevation_fx = (Word32)(st_ivas->hIsmMetaData[ind]->last_elevation * (1 << 22)); - st_ivas->hIsmMetaData[ind]->last_true_azimuth_fx = (Word32)(st_ivas->hIsmMetaData[ind]->last_true_azimuth * (1 << 22)); - st_ivas->hIsmMetaData[ind]->last_true_elevation_fx = (Word32)(st_ivas->hIsmMetaData[ind]->last_true_elevation * (1 << 22)); - st_ivas->hIsmMetaData[ind]->radius_fx = (Word16)(st_ivas->hIsmMetaData[ind]->radius * (1 << 9)); - st_ivas->hIsmMetaData[ind]->yaw_fx = (Word32)(st_ivas->hIsmMetaData[ind]->yaw * (1 << 22)); - st_ivas->hIsmMetaData[ind]->pitch_fx = (Word32)(st_ivas->hIsmMetaData[ind]->pitch * (1 << 22)); - } - IF ( ( error = ivas_ism_metadata_dec_fx( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) + FOR( Word16 ind = 0; ind < st_ivas->nchan_ism; ind++ ) + { + st_ivas->hIsmMetaData[ind]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->elevation * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind]->last_azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->last_azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind]->last_elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->last_elevation * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind]->last_true_azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->last_true_azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind]->last_true_elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->last_true_elevation * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind]->radius_fx = (Word16) ( st_ivas->hIsmMetaData[ind]->radius * ( 1 << 9 ) ); + st_ivas->hIsmMetaData[ind]->yaw_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->yaw * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind]->pitch_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->pitch * ( 1 << 22 ) ); + } + IF( ( error = ivas_ism_metadata_dec_fx( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) { return error; } - FOR (Word16 ind = 0; ind < st_ivas->nchan_ism; ind++) { - st_ivas->hIsmMetaData[ind]->azimuth = (float)(st_ivas->hIsmMetaData[ind]->azimuth_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->elevation = (float)(st_ivas->hIsmMetaData[ind]->elevation_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->last_azimuth = (float)(st_ivas->hIsmMetaData[ind]->last_azimuth_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->last_elevation = (float)(st_ivas->hIsmMetaData[ind]->last_elevation_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->last_true_azimuth = (float)(st_ivas->hIsmMetaData[ind]->last_true_azimuth_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->last_true_elevation = (float)(st_ivas->hIsmMetaData[ind]->last_true_elevation_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->radius = (float)(st_ivas->hIsmMetaData[ind]->radius_fx) / (float)(1 << 9); - st_ivas->hIsmMetaData[ind]->yaw = (float)(st_ivas->hIsmMetaData[ind]->yaw_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind]->pitch = (float)(st_ivas->hIsmMetaData[ind]->pitch_fx) / (float)(1 << 22); + FOR( Word16 ind = 0; ind < st_ivas->nchan_ism; ind++ ) + { + st_ivas->hIsmMetaData[ind]->azimuth = (float) ( st_ivas->hIsmMetaData[ind]->azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind]->elevation = (float) ( st_ivas->hIsmMetaData[ind]->elevation_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind]->last_azimuth = (float) ( st_ivas->hIsmMetaData[ind]->last_azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind]->last_elevation = (float) ( st_ivas->hIsmMetaData[ind]->last_elevation_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind]->last_true_azimuth = (float) ( st_ivas->hIsmMetaData[ind]->last_true_azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind]->last_true_elevation = (float) ( st_ivas->hIsmMetaData[ind]->last_true_elevation_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind]->radius = (float) ( st_ivas->hIsmMetaData[ind]->radius_fx ) / (float) ( 1 << 9 ); + st_ivas->hIsmMetaData[ind]->yaw = (float) ( st_ivas->hIsmMetaData[ind]->yaw_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind]->pitch = (float) ( st_ivas->hIsmMetaData[ind]->pitch_fx ) / (float) ( 1 << 22 ); } #else if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) @@ -669,22 +672,22 @@ ivas_error ivas_jbm_dec_tc( { #ifdef IVAS_FLOAT_FIXED Word16 q_shift = 0; - FOR(Word16 i = 0; i < 2; i++) + FOR( Word16 i = 0; i < 2; i++ ) { - output_fx[i] = (Word32 *)malloc(output_frame * sizeof(Word32)); - FOR(Word16 j = 0; j < output_frame; j++) + output_fx[i] = (Word32 *) malloc( output_frame * sizeof( Word32 ) ); + FOR( Word16 j = 0; j < output_frame; j++ ) { - output_fx[i][j] = float_to_fix(p_output[i][j], Q11); + output_fx[i][j] = float_to_fix( p_output[i][j], Q11 ); } } ivas_masa_prerender_fx( st_ivas, output_fx, &q_shift, output_frame, nchan_remapped ); - FOR(Word16 i = 0; i < 2; i++) + FOR( Word16 i = 0; i < 2; i++ ) { - FOR(Word16 j = 0; j < output_frame; j++) + FOR( Word16 j = 0; j < output_frame; j++ ) { - p_output[i][j] = fix_to_float(output_fx[i][j], Q11 + q_shift); + p_output[i][j] = fix_to_float( output_fx[i][j], Q11 + q_shift ); } - free(output_fx[i]); + free( output_fx[i] ); } #else ivas_masa_prerender( st_ivas, p_output, output_frame, nchan_remapped ); @@ -1854,7 +1857,12 @@ ivas_error ivas_jbm_dec_render( ivas_error error; float *p_output[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; float *p_tc[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS]; +#ifdef IVAS_FLOAT_FIXED Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; + Word32 tmp_buffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; + Word32 *p_temp_fx[MAX_OUTPUT_CHANNELS]; + Word16 subframe_len, gd_bits, exp, nchan_in, i, j; +#endif SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; push_wmops( "ivas_dec_render" ); @@ -1876,7 +1884,12 @@ ivas_error ivas_jbm_dec_render( p_output_fx[n] = st_ivas->p_output_fx[n]; #endif } - +#ifdef IVAS_FLOAT_FIXED + for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + { + p_temp_fx[i] = tmp_buffer_fx[i]; + } +#endif if ( !st_ivas->hDecoderConfig->Opt_tsm ) { for ( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ ) @@ -2021,71 +2034,74 @@ ivas_error ivas_jbm_dec_render( /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ #ifdef IVAS_FLOAT_FIXED Word16 q = 11; - FOR(Word16 ind1 = 0; ind1 < s_max(st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max(st_ivas->nchan_transport, st_ivas->nchan_ism)); ind1++) + FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) { - p_output_fx[ind1][ind2] = (Word16)(p_output[ind1][ind2] * (1 << q)); + p_output_fx[ind1][ind2] = (Word16) ( p_output[ind1][ind2] * ( 1 << q ) ); } - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) { - st_ivas->hTcBuffer->tc_fx[ind1][ind2] = (Word32)(st_ivas->hTcBuffer->tc[ind1][ind2] * (1 << q)); + st_ivas->hTcBuffer->tc_fx[ind1][ind2] = (Word32) ( st_ivas->hTcBuffer->tc[ind1][ind2] * ( 1 << q ) ); } } - FOR(Word16 ind1 = 0; ind1 < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ind1++) + FOR( Word16 ind1 = 0; ind1 < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) { } } - FOR(Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++) + FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) { - st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16)(st_ivas->hIsmRendererData->interpolator[ind1] * (32767)); + st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) ( st_ivas->hIsmRendererData->interpolator[ind1] * ( 32767 ) ); } - FOR(Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++) + FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) + FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) { - st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32)(st_ivas->hIsmRendererData->gains[ind1][ind2] * (1 << 30)); - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32)(st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * (1 << 30)); + st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->gains[ind1][ind2] * ( 1 << 30 ) ); + st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * ( 1 << 30 ) ); } } - FOR(Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++) { - st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32)(st_ivas->hIsmMetaData[ind1]->azimuth * (1 << 22)); - st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32)(st_ivas->hIsmMetaData[ind1]->elevation * (1 << 22)); + FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) + { + st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->elevation * ( 1 << 22 ) ); } - IF(st_ivas->hCombinedOrientationData) FOR(Word16 ind1 = 0; ind1 < 3; ind1++) + IF( st_ivas->hCombinedOrientationData ) + FOR( Word16 ind1 = 0; ind1 < 3; ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < 3; ind2++) + FOR( Word16 ind2 = 0; ind2 < 3; ind2++ ) { - st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32)(st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * (1 << 15)); + st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32) ( st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * ( 1 << 15 ) ); } } ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ); - FOR(Word16 ind1 = 0; ind1 < s_max(st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max(st_ivas->nchan_transport, st_ivas->nchan_ism)); ind1++) + FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) { - p_output[ind1][ind2] = (float)(p_output_fx[ind1][ind2]) / (float)(1 << q); + p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); } } - FOR(Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++) + FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) { - st_ivas->hIsmRendererData->interpolator[ind1] = (float)(st_ivas->hIsmRendererData->interpolator_fx[ind1]) / (float)(1 << 15); + st_ivas->hIsmRendererData->interpolator[ind1] = (float) ( st_ivas->hIsmRendererData->interpolator_fx[ind1] ) / (float) ( 1 << 15 ); } - FOR(Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++) + FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) + FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) { - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->gains_fx[ind1][ind2]) / (1 << 30); - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2]) / (1 << 30); + st_ivas->hIsmRendererData->gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->gains_fx[ind1][ind2] ) / ( 1 << 30 ); + st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] ) / ( 1 << 30 ); } } - FOR(Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++) { - st_ivas->hIsmMetaData[ind1]->azimuth = (float)(st_ivas->hIsmMetaData[ind1]->azimuth_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind1]->elevation = (float)(st_ivas->hIsmMetaData[ind1]->elevation_fx) / (float)(1 << 22); + FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) + { + st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind1]->elevation = (float) ( st_ivas->hIsmMetaData[ind1]->elevation_fx ) / (float) ( 1 << 22 ); } #else @@ -2132,10 +2148,41 @@ ivas_error ivas_jbm_dec_render( } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { +#ifdef IVAS_FLOAT_FIXED + st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; + subframe_len = st_ivas->hTcBuffer->subframe_nbslots[0] * st_ivas->hTcBuffer->n_samples_granularity; + gd_bits = find_guarded_bits_fx( subframe_len ); + exp = 13; + nchan_in = 12; + nchan_out = 2; + exp -= gd_bits; + *st_ivas->hCrendWrapper->p_io_qfactor = exp; + for ( i = 0; i < nchan_in; i++ ) + { + for ( j = 0; j < *nSamplesRendered; j++ ) + { + + p_temp_fx[i][j] = (Word32)float_to_fixed( p_output[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); + } + } + if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_temp_fx, p_temp_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + for ( i = 0; i < nchan_out; i++ ) + { + for ( j = 0; j < *nSamplesRendered; j++ ) + { + + p_output[i][j] = fixed_to_float( p_temp_fx[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); + } + } +#else if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output, p_output, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) { return error; } +#endif } } } @@ -2229,71 +2276,75 @@ ivas_error ivas_jbm_dec_render( /* render objects */ #ifdef IVAS_FLOAT_FIXED Word16 q = 15; - FOR(Word16 ind1 = 0; ind1 < s_max(st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max(st_ivas->nchan_transport, st_ivas->nchan_ism)); ind1++) + FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) { - p_output_fx[ind1][ind2] = (Word16)(p_output[ind1][ind2] * (1 << q)); + p_output_fx[ind1][ind2] = (Word16) ( p_output[ind1][ind2] * ( 1 << q ) ); } - IF(st_ivas->hTcBuffer->tc) FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + IF( st_ivas->hTcBuffer->tc ) + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) { - st_ivas->hTcBuffer->tc_fx[ind1][ind2] = (Word32)(st_ivas->hTcBuffer->tc[ind1][ind2] * (1 << q)); + st_ivas->hTcBuffer->tc_fx[ind1][ind2] = (Word32) ( st_ivas->hTcBuffer->tc[ind1][ind2] * ( 1 << q ) ); } } - FOR(Word16 ind1 = 0; ind1 < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ind1++) + FOR( Word16 ind1 = 0; ind1 < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) { } } - FOR(Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++) + FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) { - st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16)(st_ivas->hIsmRendererData->interpolator[ind1] * (32767)); + st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) ( st_ivas->hIsmRendererData->interpolator[ind1] * ( 32767 ) ); } - FOR(Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++) + FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) + FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) { - st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32)(st_ivas->hIsmRendererData->gains[ind1][ind2] * (1 << 30)); - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32)(st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * (1 << 30)); + st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->gains[ind1][ind2] * ( 1 << 30 ) ); + st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * ( 1 << 30 ) ); } } - FOR(Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++) { - st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32)(st_ivas->hIsmMetaData[ind1]->azimuth * (1 << 22)); - st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32)(st_ivas->hIsmMetaData[ind1]->elevation * (1 << 22)); + FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) + { + st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->elevation * ( 1 << 22 ) ); } - IF(st_ivas->hCombinedOrientationData) FOR(Word16 ind1 = 0; ind1 < 3; ind1++) + IF( st_ivas->hCombinedOrientationData ) + FOR( Word16 ind1 = 0; ind1 < 3; ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < 3; ind2++) + FOR( Word16 ind2 = 0; ind2 < 3; ind2++ ) { - st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32)(st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * (1 << 15)); + st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32) ( st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * ( 1 << 15 ) ); } } ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ); - FOR(Word16 ind1 = 0; ind1 < s_max(st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max(st_ivas->nchan_transport, st_ivas->nchan_ism)); ind1++) + FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) { - p_output[ind1][ind2] = (float)(p_output_fx[ind1][ind2]) / (float)(1 << q); + p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); } } - FOR(Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++) + FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) { - st_ivas->hIsmRendererData->interpolator[ind1] = (float)(st_ivas->hIsmRendererData->interpolator_fx[ind1]) / (float)(1 << 15); + st_ivas->hIsmRendererData->interpolator[ind1] = (float) ( st_ivas->hIsmRendererData->interpolator_fx[ind1] ) / (float) ( 1 << 15 ); } - FOR(Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++) + FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) { - FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) + FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) { - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->gains_fx[ind1][ind2]) / (1 << 30); - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2]) / (1 << 30); + st_ivas->hIsmRendererData->gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->gains_fx[ind1][ind2] ) / ( 1 << 30 ); + st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] ) / ( 1 << 30 ); } } - FOR(Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++) { - st_ivas->hIsmMetaData[ind1]->azimuth = (float)(st_ivas->hIsmMetaData[ind1]->azimuth_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind1]->elevation = (float)(st_ivas->hIsmMetaData[ind1]->elevation_fx) / (float)(1 << 22); + FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) + { + st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind1]->elevation = (float) ( st_ivas->hIsmMetaData[ind1]->elevation_fx ) / (float) ( 1 << 22 ); } #else @@ -2375,15 +2426,67 @@ ivas_error ivas_jbm_dec_render( /* Rendering */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { +#ifdef IVAS_FLOAT_FIXED + st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; + subframe_len = st_ivas->hTcBuffer->subframe_nbslots[0] * st_ivas->hTcBuffer->n_samples_granularity; + gd_bits = find_guarded_bits_fx( subframe_len ); + exp = 13; + if ( ( error = getAudioConfigNumChannels( st_ivas->intern_config, &nchan_in ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ) != IVAS_ERR_OK ) + { + return error; + } + exp -= gd_bits; + *st_ivas->hCrendWrapper->p_io_qfactor = exp; + if ( crendInPlaceRotation ) + { + for ( i = 0; i < nchan_in; i++ ) + { + for ( j = 0; j < *nSamplesRendered; j++ ) + { + p_temp_fx[i][j] = (Word32) float_to_fixed( p_output[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); + } + } + } + else + { + for ( i = 0; i < nchan_in; i++ ) + { + for ( j = 0; j < *nSamplesRendered; j++ ) + { + + p_temp_fx[i][j] = (Word32) float_to_fixed( p_tc[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); + } + } + } if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, - &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output : p_tc, p_output, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) + &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, p_temp_fx, p_temp_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) { return error; } + for ( i = 0; i < nchan_out; i++ ) + { + for ( j = 0; j < *nSamplesRendered; j++ ) + { + + p_output[i][j] = fixed_to_float( p_temp_fx[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); + } + } +#else + if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, + &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output : p_tc, p_output, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) + + { + return error; + } +#endif ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output ); } else if ( st_ivas->renderer_type == RENDERER_MC ) @@ -2612,10 +2715,20 @@ ivas_error ivas_jbm_dec_flush_renderer( int16_t n_samples_to_render; DECODER_TC_BUFFER_HANDLE hTcBuffer; float output[MAX_CICP_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; - Word32 output_fx[MAX_CICP_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; float *p_output[MAX_CICP_CHANNELS]; +#ifdef IVAS_FLOAT_FIXED + Word32 output_fx[MAX_CICP_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 *p_output_fx[MAX_CICP_CHANNELS]; - + Word32 tmp_buffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; + Word32 *p_temp_fx[MAX_OUTPUT_CHANNELS]; + Word16 subframe_len, gd_bits, exp, nchan_in, i, j, nchan_out; +#endif +#ifdef IVAS_FLOAT_FIXED + for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + { + p_temp_fx[i] = tmp_buffer_fx[i]; + } +#endif if ( !st_ivas->hDecoderConfig->Opt_tsm ) { return IVAS_ERR_OK; @@ -2689,83 +2802,118 @@ ivas_error ivas_jbm_dec_flush_renderer( set_f( st_ivas->hIsmRendererData->interpolator, 1.0f, hTcBuffer->n_samples_granularity ); #ifdef IVAS_FLOAT_FIXED - Word16 q = 15; - FOR(Word16 ind1 = 0; ind1 < s_max(st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max(st_ivas->nchan_transport, st_ivas->nchan_ism)); ind1++) - { - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + Word16 q = 15; + FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) { - p_output_fx[ind1][ind2] = (Word16)(p_output[ind1][ind2] * (1 << q)); + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) + { + p_output_fx[ind1][ind2] = (Word16) ( p_output[ind1][ind2] * ( 1 << q ) ); + } + IF( st_ivas->hTcBuffer->tc ) + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) + { + st_ivas->hTcBuffer->tc_fx[ind1][ind2] = (Word32) ( st_ivas->hTcBuffer->tc[ind1][ind2] * ( 1 << q ) ); + } } - IF(st_ivas->hTcBuffer->tc) FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + + FOR( Word16 ind1 = 0; ind1 < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ind1++ ) { - st_ivas->hTcBuffer->tc_fx[ind1][ind2] = (Word32)(st_ivas->hTcBuffer->tc[ind1][ind2] * (1 << q)); + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) + { + } } - } - - FOR(Word16 ind1 = 0; ind1 < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ind1++) - { - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) { + st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) ( st_ivas->hIsmRendererData->interpolator[ind1] * ( 32767 ) ); } - } - FOR(Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++) - { - st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16)(st_ivas->hIsmRendererData->interpolator[ind1] * (32767)); - } - FOR(Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++) - { - FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) + FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) { - st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32)(st_ivas->hIsmRendererData->gains[ind1][ind2] * (1 << 30)); - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32)(st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * (1 << 30)); + FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) + { + st_ivas->hIsmRendererData->gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->gains[ind1][ind2] * ( 1 << 30 ) ); + st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = (Word32) ( st_ivas->hIsmRendererData->prev_gains[ind1][ind2] * ( 1 << 30 ) ); + } } - } - FOR(Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++) { - st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32)(st_ivas->hIsmMetaData[ind1]->azimuth * (1 << 22)); - st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32)(st_ivas->hIsmMetaData[ind1]->elevation * (1 << 22)); - } - IF(st_ivas->hCombinedOrientationData) FOR(Word16 ind1 = 0; ind1 < 3; ind1++) - { - FOR(Word16 ind2 = 0; ind2 < 3; ind2++) + FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { - st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32)(st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * (1 << 15)); + st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->elevation * ( 1 << 22 ) ); + } + IF( st_ivas->hCombinedOrientationData ) + FOR( Word16 ind1 = 0; ind1 < 3; ind1++ ) + { + FOR( Word16 ind2 = 0; ind2 < 3; ind2++ ) + { + st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32) ( st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * ( 1 << 15 ) ); + } } - } - ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ); - FOR(Word16 ind1 = 0; ind1 < s_max(st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max(st_ivas->nchan_transport, st_ivas->nchan_ism)); ind1++) - { - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ); + FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) + { + FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) + { + p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); + } + } + FOR( Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++ ) { - p_output[ind1][ind2] = (float)(p_output_fx[ind1][ind2]) / (float)(1 << q); + st_ivas->hIsmRendererData->interpolator[ind1] = (float) ( st_ivas->hIsmRendererData->interpolator_fx[ind1] ) / (float) ( 1 << 15 ); } - } - FOR(Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind1++) - { - st_ivas->hIsmRendererData->interpolator[ind1] = (float)(st_ivas->hIsmRendererData->interpolator_fx[ind1]) / (float)(1 << 15); - } - FOR(Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++) - { - FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) + FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) { - st_ivas->hIsmRendererData->gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->gains_fx[ind1][ind2]) / (1 << 30); - st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2]) / (1 << 30); + FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) + { + st_ivas->hIsmRendererData->gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->gains_fx[ind1][ind2] ) / ( 1 << 30 ); + st_ivas->hIsmRendererData->prev_gains[ind1][ind2] = (float) ( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] ) / ( 1 << 30 ); + } + } + FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) + { + st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind1]->elevation = (float) ( st_ivas->hIsmMetaData[ind1]->elevation_fx ) / (float) ( 1 << 22 ); } - } - FOR(Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++) { - st_ivas->hIsmMetaData[ind1]->azimuth = (float)(st_ivas->hIsmMetaData[ind1]->azimuth_fx) / (float)(1 << 22); - st_ivas->hIsmMetaData[ind1]->elevation = (float)(st_ivas->hIsmMetaData[ind1]->elevation_fx) / (float)(1 << 22); - } #else ivas_ism_render_sf( st_ivas, p_output, hTcBuffer->n_samples_granularity ); #endif +#ifdef IVAS_FLOAT_FIXED + st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; + subframe_len = st_ivas->hTcBuffer->subframe_nbslots[0] * st_ivas->hTcBuffer->n_samples_granularity; + gd_bits = find_guarded_bits_fx( subframe_len ); + exp = 13; + nchan_in = 12; + nchan_out = 2; + exp -= gd_bits; + *st_ivas->hCrendWrapper->p_io_qfactor = exp; + for ( i = 0; i < nchan_in; i++ ) + { + for ( j = 0; j < hTcBuffer->n_samples_granularity; j++ ) + { + + p_temp_fx[i][j] = (Word32) float_to_fixed( p_output[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); + } + } + if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, + NULL, NULL, st_ivas->hTcBuffer, p_temp_fx, p_temp_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + for ( i = 0; i < nchan_out; i++ ) + { + for ( j = 0; j < hTcBuffer->n_samples_granularity; j++ ) + { + p_output[i][j] = fixed_to_float( p_temp_fx[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); + } + } +#else if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output, p_output, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } +#endif } } else @@ -2779,12 +2927,49 @@ ivas_error ivas_jbm_dec_flush_renderer( { if ( renderer_type_old == RENDERER_BINAURAL_MIXER_CONV || renderer_type_old == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { +#ifdef IVAS_FLOAT_FIXED + st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; + subframe_len = st_ivas->hTcBuffer->subframe_nbslots[0] * st_ivas->hTcBuffer->n_samples_granularity; + gd_bits = find_guarded_bits_fx( subframe_len ); + exp = 13; + if ( ( error = getAudioConfigNumChannels( intern_config_old, &nchan_in ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ) != IVAS_ERR_OK ) + { + return error; + } + exp -= gd_bits; + *st_ivas->hCrendWrapper->p_io_qfactor = exp; + for ( i = 0; i < nchan_in; i++ ) + { + for ( j = 0; j < hTcBuffer->n_samples_granularity; j++ ) + { + + p_temp_fx[i][j] = (Word32) float_to_fixed( hTcBuffer->tc[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); + } + } if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, intern_config_old, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, - hIntSetupOld, st_ivas->hEFAPdata, st_ivas->hTcBuffer, hTcBuffer->tc, p_output, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + hIntSetupOld, st_ivas->hEFAPdata, st_ivas->hTcBuffer, p_temp_fx, p_temp_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } + for ( i = 0; i < nchan_out; i++ ) + { + for ( j = 0; j < hTcBuffer->n_samples_granularity; j++ ) + { + p_output[i][j] = fixed_to_float( p_temp_fx[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); + } + } +#else + if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, intern_config_old, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, + hIntSetupOld, st_ivas->hEFAPdata, st_ivas->hTcBuffer, hTcBuffer->tc, p_output, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif ivas_binaural_add_LFE( st_ivas, hTcBuffer->n_samples_granularity, st_ivas->hTcBuffer->tc, p_output ); } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) @@ -2918,7 +3103,7 @@ ivas_error ivas_jbm_dec_set_discard_samples( /* render first frame with front zero padding and discarding those samples */ nMaxSlotsPerSubframe = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity; nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] ); - IF ( GT_16( nSlotsInFirstSubframe, 0 ) ) + IF( GT_16( nSlotsInFirstSubframe, 0 ) ) { st_ivas->hTcBuffer->n_samples_discard = sub( nMaxSlotsPerSubframe, nSlotsInFirstSubframe ) * st_ivas->hTcBuffer->n_samples_granularity; /* set last subframes number to max to ensure correct continuation */ @@ -2989,7 +3174,7 @@ void ivas_jbm_dec_get_adapted_linear_interpolator( void ivas_jbm_dec_get_adapted_linear_interpolator_fx( const Word16 default_interp_length, /* i : default length of the (full-frame) interpolator */ const Word16 interp_length, /* i : length of the interpolator to be created */ - Word16 *interpolator_fx /* o : the interpolator */ + Word16 *interpolator_fx /* o : the interpolator */ ) { Word16 jbm_segment_len, idx; @@ -3000,18 +3185,18 @@ void ivas_jbm_dec_get_adapted_linear_interpolator_fx( move16(); interpolator_fx[interp_length - 1] = 32767; - FOR ( idx = interp_length - 2; idx >= jbm_segment_len; idx-- ) + FOR( idx = interp_length - 2; idx >= jbm_segment_len; idx-- ) { - interpolator_fx[idx] = s_max( 0, sub(interpolator_fx[idx + 1], dec_fx) ); + interpolator_fx[idx] = s_max( 0, sub( interpolator_fx[idx + 1], dec_fx ) ); } - IF ( GT_16(interpolator_fx[idx + 1], 0 ) ) + IF( GT_16( interpolator_fx[idx + 1], 0 ) ) { dec_fx = interpolator_fx[idx + 1] / ( jbm_segment_len + 1 ); move16(); - FOR ( ; idx >= 0; idx-- ) + FOR( ; idx >= 0; idx-- ) { - interpolator_fx[idx] = sub(interpolator_fx[idx + 1], dec_fx); + interpolator_fx[idx] = sub( interpolator_fx[idx + 1], dec_fx ); } } ELSE @@ -3044,26 +3229,26 @@ void ivas_jbm_dec_get_adapted_subframes( nSlotsInFirstSubframe = ( sub( PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, subframe_nbslots[*nb_subframes - 1] ) ); *nb_subframes = 0; move16(); - IF ( GT_16( nSlotsInFirstSubframe, 0 ) ) + IF( GT_16( nSlotsInFirstSubframe, 0 ) ) { *nb_subframes = 1; move16(); nCldfbSlotsLocal = sub( nCldfbSlotsLocal, nSlotsInFirstSubframe ); } - *nb_subframes = add( *nb_subframes, ( nCldfbSlotsLocal + PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - 1) / PARAM_MC_MAX_NSLOTS_IN_SUBFRAME ); + *nb_subframes = add( *nb_subframes, ( nCldfbSlotsLocal + PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - 1 ) / PARAM_MC_MAX_NSLOTS_IN_SUBFRAME ); nSlotsInLastSubframe = nCldfbSlotsLocal % PARAM_MC_MAX_NSLOTS_IN_SUBFRAME; set_s( subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); set_s( subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, *nb_subframes ); - IF ( GT_16( nSlotsInFirstSubframe, 0 ) ) + IF( GT_16( nSlotsInFirstSubframe, 0 ) ) { subframe_nbslots[0] = nSlotsInFirstSubframe; move16(); } - IF ( GT_16( nSlotsInLastSubframe, 0 ) ) + IF( GT_16( nSlotsInLastSubframe, 0 ) ) { subframe_nbslots[*nb_subframes - 1] = nSlotsInLastSubframe; move16(); @@ -3132,7 +3317,7 @@ void ivas_jbm_dec_get_md_map( jbm_segment_len = ( default_len >> 1 ); // dec = 1.0f / default_len; - FOR ( (map_idx = len - 1, src_idx = default_len - 1); map_idx >= jbm_segment_len; (map_idx--, src_idx--) ) + FOR( ( map_idx = len - 1, src_idx = default_len - 1 ); map_idx >= jbm_segment_len; ( map_idx--, src_idx-- ) ) { src_idx_map = max( 0, src_idx / subframe_len ); map[map_idx] = ( offset + src_idx_map ) % buf_len; @@ -3140,11 +3325,11 @@ void ivas_jbm_dec_get_md_map( /* changed part (first segment), interpolate index to parameters (we do not want to interpolate and smooth acutal direction/diffuseness values even more) */ - IF ( src_idx >= 0 ) + IF( src_idx >= 0 ) { - dec_fx = L_shl(src_idx + 1, 16) / jbm_segment_len; - src_idx_fx = L_shl(src_idx + 1, 16) - dec_fx; - FOR ( ; map_idx >= 0; map_idx-- ) + dec_fx = L_shl( src_idx + 1, 16 ) / jbm_segment_len; + src_idx_fx = L_shl( src_idx + 1, 16 ) - dec_fx; + FOR( ; map_idx >= 0; map_idx-- ) { src_idx = max( 0, round_fx( src_idx_fx ) / subframe_len ); map[map_idx] = ( offset + src_idx ) % buf_len; @@ -3223,10 +3408,10 @@ void ivas_jbm_dec_get_md_map_even_spacing( /* subframe map length */ sf_length = len / subframe_len; - IF ( len % subframe_len == 0 ) + IF( len % subframe_len == 0 ) { /* even subframes */ - FOR ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) { subframe_map_length[sf_idx] = sf_length; } @@ -3234,16 +3419,16 @@ void ivas_jbm_dec_get_md_map_even_spacing( ELSE { /* uneven subframes */ - decimal_fx = ( L_shl(len, 16) / subframe_len ) - L_shl(sf_length, 16); + decimal_fx = ( L_shl( len, 16 ) / subframe_len ) - L_shl( sf_length, 16 ); decimal_sum_fx = decimal_fx; eps_fx = 65; - FOR ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) { - increment = (Word16)L_shr(decimal_sum_fx + eps_fx, 16); + increment = (Word16) L_shr( decimal_sum_fx + eps_fx, 16 ); subframe_map_length[sf_idx] = sf_length + increment; - IF ( increment > 0 ) + IF( increment > 0 ) { - decimal_sum_fx -= (1 << 16); + decimal_sum_fx -= ( 1 << 16 ); } decimal_sum_fx += decimal_fx; } @@ -3252,10 +3437,10 @@ void ivas_jbm_dec_get_md_map_even_spacing( /* map slots to subframes */ sf_idx = 0; subframes_written = 0; - FOR ( map_idx = 0; map_idx < len; map_idx++ ) + FOR( map_idx = 0; map_idx < len; map_idx++ ) { map[map_idx] = ( offset + sf_idx ) % buf_len; - IF ( map_idx - subframes_written >= subframe_map_length[sf_idx] - 1 ) + IF( map_idx - subframes_written >= subframe_map_length[sf_idx] - 1 ) { subframes_written += subframe_map_length[sf_idx]; ++sf_idx; @@ -3480,7 +3665,7 @@ Word16 ivas_jbm_dec_get_num_tc_channels_fx( AUDIO_CONFIG output_config; - IF ( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) { num_tc = st_ivas->hDecoderConfig->nchan_out; move16(); @@ -3496,48 +3681,58 @@ Word16 ivas_jbm_dec_get_num_tc_channels_fx( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); - test(); test(); test(); - IF ( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) ) + test(); + test(); + test(); + IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) ) { num_tc = st_ivas->hDecoderConfig->nchan_out; move16(); } - ELSE IF ( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) ) + ELSE IF( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) ) { num_tc = 1; move16(); } - ELSE IF ( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) ) + ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) ) { - IF ( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) { num_tc = 1; move16(); } } - ELSE IF ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) { - test(); test(); test(); test(); test(); - IF ( st_ivas->sba_dirac_stereo_flag ) + test(); + test(); + test(); + test(); + test(); + IF( st_ivas->sba_dirac_stereo_flag ) { num_tc = CPE_CHANNELS; move16(); } - ELSE IF ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && GT_16( st_ivas->nCPE, 0 ) && st_ivas->hCPE[0] != NULL && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) ) + ELSE IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && GT_16( st_ivas->nCPE, 0 ) && st_ivas->hCPE[0] != NULL && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) ) { num_tc = 1; /* Only one channel transported */ move16(); } - test(); test(); test(); test(); test(); - IF ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_16( st_ivas->nchan_transport, 2 ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_16( st_ivas->nchan_transport, 2 ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) { num_tc = CPE_CHANNELS; move16(); } - IF ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) { - IF ( EQ_16( num_tc, 3 ) ) + IF( EQ_16( num_tc, 3 ) ) { num_tc = add( num_tc, 1 ); } @@ -3558,72 +3753,77 @@ Word16 ivas_jbm_dec_get_num_tc_channels_fx( } } } - ELSE IF ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - test(); test(); - IF ( st_ivas->sba_dirac_stereo_flag ) + test(); + test(); + IF( st_ivas->sba_dirac_stereo_flag ) { num_tc = CPE_CHANNELS; move16(); } - IF ( ( st_ivas->sba_planar && GE_16( num_tc, 3 ) ) || EQ_16( num_tc, 3 ) ) + IF( ( st_ivas->sba_planar && GE_16( num_tc, 3 ) ) || EQ_16( num_tc, 3 ) ) { num_tc = add( num_tc, 1 ); } - IF ( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { num_tc = add( num_tc, st_ivas->nchan_ism ); } } - ELSE IF ( EQ_16( st_ivas->ivas_format, MC_FORMAT ) ) + ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) ) { - IF ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) + IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) { num_tc = 1; move16(); } - ELSE IF ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + ELSE IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { num_tc = 2; move16(); } - ELSE IF ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) { /* do all static dmx already in the TC decoder if less channels than transported... */ - test(); test(); test(); test(); test(); - IF ( NE_16( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) + test(); + test(); + test(); + test(); + test(); + IF( NE_16( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) { - IF ( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) + IF( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) { num_tc = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); } } - ELSE IF ( ( EQ_16( st_ivas->renderer_type, RENDERER_MC ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( add(st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe), add(st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe))) + ELSE IF( ( EQ_16( st_ivas->renderer_type, RENDERER_MC ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) ) { num_tc = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); } } - ELSE IF ( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { num_tc = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; move16(); } - ELSE IF ( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - IF ( st_ivas->hOutSetup.separateChannelEnabled ) + IF( st_ivas->hOutSetup.separateChannelEnabled ) { num_tc = add( num_tc, st_ivas->nchan_ism ); } - IF ( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || - EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || - EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) ) ) + IF( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || + EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || + EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) ) ) { /* LFE is synthesized in TD with the TCs*/ num_tc = add( num_tc, st_ivas->nchan_ism ); } } } - ELSE IF ( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) + ELSE IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { num_tc = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; move16(); @@ -3732,16 +3932,17 @@ Word16 ivas_jbm_dec_get_render_granularity( const RENDERER_TYPE rendererType, /* i : renderer type */ const IVAS_FORMAT ivas_format, /* i : ivas format */ const MC_MODE mc_mode, /* i : MC mode */ - const Word32 output_Fs /* i : sampling rate */ + const Word32 output_Fs /* i : sampling rate */ ) { Word16 render_granularity; - test(); test(); - IF ( EQ_32( rendererType, RENDERER_BINAURAL_OBJECTS_TD ) || EQ_32( rendererType, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( rendererType, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + test(); + test(); + IF( EQ_32( rendererType, RENDERER_BINAURAL_OBJECTS_TD ) || EQ_32( rendererType, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( rendererType, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { test(); - IF ( ( EQ_32( ivas_format, MC_FORMAT ) ) && ( EQ_32( mc_mode, MC_MODE_PARAMUPMIX ) ) ) + IF( ( EQ_32( ivas_format, MC_FORMAT ) ) && ( EQ_32( mc_mode, MC_MODE_PARAMUPMIX ) ) ) { render_granularity = NS2SA( output_Fs, CLDFB_SLOT_NS ); } @@ -3821,7 +4022,7 @@ ivas_error ivas_jbm_dec_tc_buffer_open( #ifdef IVAS_FLOAT_FIXED hTcBuffer->tc_buffer_fx = NULL; - FOR ( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { hTcBuffer->tc_fx[ch_idx] = NULL; } @@ -3850,7 +4051,7 @@ ivas_error ivas_jbm_dec_tc_buffer_open( #ifdef IVAS_FLOAT_FIXED hTcBuffer->tc_buffer_fx = NULL; - FOR ( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { hTcBuffer->tc_fx[ch_idx] = NULL; } @@ -3872,7 +4073,7 @@ ivas_error ivas_jbm_dec_tc_buffer_open( } set_zero( hTcBuffer->tc_buffer, nsamp_to_allocate ); #ifdef IVAS_FLOAT_FIXED - IF ( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL ) + IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) ); } @@ -3921,8 +4122,8 @@ ivas_error ivas_jbm_dec_tc_buffer_open( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_tc_buffer_open_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const TC_BUFFER_MODE tc_buffer_mode, /* i : buffer mode */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const TC_BUFFER_MODE tc_buffer_mode, /* i : buffer mode */ const Word16 nchan_transport_jbm, /* i : number of real transport channels */ const Word16 nchan_transport_internal, /* i : number of totally buffered channels */ const Word16 nchan_full, /* i : number of channels to fully store */ @@ -3941,7 +4142,7 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( * prepare library opening *-----------------------------------------------------------------*/ - IF ( ( hTcBuffer = (DECODER_TC_BUFFER_HANDLE) malloc( sizeof( DECODER_TC_BUFFER ) ) ) == NULL ) + IF( ( hTcBuffer = (DECODER_TC_BUFFER_HANDLE) malloc( sizeof( DECODER_TC_BUFFER ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) ); } @@ -3953,7 +4154,7 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( move16(); hTcBuffer->nchan_buffer_full = nchan_full; move16(); - nchan_residual = sub(nchan_transport_internal, nchan_full); + nchan_residual = sub( nchan_transport_internal, nchan_full ); hTcBuffer->n_samples_granularity = n_samples_granularity; move16(); hTcBuffer->n_samples_available = 0; @@ -3975,28 +4176,28 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( nsamp_to_allocate = 0; move16(); - tmp32 = L_mult0(FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hTcBuffer->n_samples_granularity); - tmp = BASOP_Util_Divide3232_Scale(st_ivas->hDecoderConfig->output_Fs, tmp32, &tmp_e); - nMaxSlotsPerSubframe = shr(tmp, sub(15, tmp_e)); // Q0 + tmp32 = L_mult0( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hTcBuffer->n_samples_granularity ); + tmp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, tmp32, &tmp_e ); + nMaxSlotsPerSubframe = shr( tmp, sub( 15, tmp_e ) ); // Q0 - hTcBuffer->num_slots = mult0(nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES); + hTcBuffer->num_slots = mult0( nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES ); set16_fx( hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); set16_fx( hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES ); - IF ( EQ_16( hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_NONE ) ) + IF( EQ_16( hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_NONE ) ) { #if 1 /* TODO: remove float code */ hTcBuffer->tc_buffer = NULL; - FOR(ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++) + FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { hTcBuffer->tc[ch_idx] = NULL; } #endif hTcBuffer->tc_buffer_fx = NULL; - FOR ( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { hTcBuffer->tc_fx[ch_idx] = NULL; } @@ -4005,15 +4206,15 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( { Word16 n_samp_full, n_samp_residual; Word32 offset; - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { n_samp_full = ( NS2SA( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ) + hTcBuffer->n_samples_granularity - 1 ); - n_samp_residual = sub(hTcBuffer->n_samples_granularity, 1); + n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 ); } ELSE { - tmp = BASOP_Util_Divide3232_Scale(st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &tmp_e); - n_samp_full = shr(tmp, sub(15, tmp_e)); // Q0 + tmp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &tmp_e ); + n_samp_full = shr( tmp, sub( 15, tmp_e ) ); // Q0 n_samp_residual = 0; move16(); } @@ -4021,35 +4222,35 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( nsamp_to_allocate = mult0( hTcBuffer->nchan_buffer_full, n_samp_full ); nsamp_to_allocate = add( nsamp_to_allocate, mult0( nchan_residual, n_samp_residual ) ); - IF ( EQ_16( nsamp_to_allocate, 0 ) ) + IF( EQ_16( nsamp_to_allocate, 0 ) ) { #if 1 /* TODO: remove float code */ hTcBuffer->tc_buffer = NULL; - FOR ( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { hTcBuffer->tc[ch_idx] = NULL; } #endif hTcBuffer->tc_buffer_fx = NULL; - FOR ( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { hTcBuffer->tc_fx[ch_idx] = NULL; } } ELSE { - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { #if 1 /* TODO: remove float memory allocation */ - IF ( ( hTcBuffer->tc_buffer = (float *) malloc( nsamp_to_allocate * sizeof( float ) ) ) == NULL ) + IF( ( hTcBuffer->tc_buffer = (float *) malloc( nsamp_to_allocate * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) ); } set_zero( hTcBuffer->tc_buffer, nsamp_to_allocate ); #endif - IF ( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL ) + IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) ); } @@ -4057,23 +4258,23 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( offset = 0; move16(); - FOR ( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ ) { #if 1 /* TODO: remove float code */ hTcBuffer->tc[ch_idx] = &hTcBuffer->tc_buffer[offset]; #endif hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset]; - offset = L_add(offset, n_samp_full); + offset = L_add( offset, n_samp_full ); } - FOR ( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ ) + FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ ) { #if 1 /* TODO: remove float code */ hTcBuffer->tc[ch_idx] = &hTcBuffer->tc_buffer[offset]; #endif hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset]; - offset = L_add(offset, n_samp_residual); + offset = L_add( offset, n_samp_residual ); } - FOR ( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) + FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { #if 1 /* TODO: remove float code */ hTcBuffer->tc[ch_idx] = NULL; @@ -4181,7 +4382,7 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure( } #ifdef IVAS_FLOAT_FIXED hTcBuffer->tc_buffer_fx = NULL; - FOR ( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { hTcBuffer->tc_fx[ch_idx] = NULL; } @@ -4209,7 +4410,7 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure( { hTcBuffer->tc[ch_idx] = &hTcBuffer->tc_buffer[offset]; #ifdef IVAS_FLOAT_FIXED - hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset]; + hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset]; #endif offset += n_samp_full; } @@ -4243,8 +4444,8 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const TC_BUFFER_MODE tc_buffer_mode, /* i : new buffer mode */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const TC_BUFFER_MODE tc_buffer_mode, /* i : new buffer mode */ const Word16 nchan_transport_jbm, /* i : new number of real transport channels */ const Word16 nchan_transport_internal, /* i : new number of totally buffered channels */ const Word16 nchan_full, /* i : new number of channels to fully store */ @@ -4260,14 +4461,14 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( /* if granularity changes, adapt subframe_nb_slots */ - IF ( NE_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) ) + IF( NE_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) ) { Word16 nMaxSlotsPerSubframeNew; nMaxSlotsPerSubframeNew = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / n_samples_granularity; /* if samples were flushed, take that into account here */ test(); - IF ( LT_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) && GT_16( hTcBuffer->n_samples_flushed, 0 ) ) + IF( LT_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) && GT_16( hTcBuffer->n_samples_flushed, 0 ) ) { hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = hTcBuffer->n_samples_flushed / n_samples_granularity; hTcBuffer->n_samples_flushed = 0; @@ -4291,13 +4492,13 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( move16(); /* realloc buffers */ - IF ( hTcBuffer->tc_buffer != NULL ) + IF( hTcBuffer->tc_buffer != NULL ) { free( hTcBuffer->tc_buffer ); hTcBuffer->tc_buffer = NULL; } - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { n_samp_full = ( add( NS2SA( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ), sub( hTcBuffer->n_samples_granularity, 1 ) ) ); n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 ); @@ -4311,20 +4512,20 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( nsamp_to_allocate = hTcBuffer->nchan_buffer_full * n_samp_full; nsamp_to_allocate = add( nsamp_to_allocate, nchan_residual * n_samp_residual ); - IF ( EQ_16( nsamp_to_allocate, 0 ) ) + IF( EQ_16( nsamp_to_allocate, 0 ) ) { hTcBuffer->tc_buffer = NULL; - FOR ( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { hTcBuffer->tc[ch_idx] = NULL; } } ELSE { - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { - IF ( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL ) + IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory FOR JBM TC Buffer\n" ) ); } @@ -4332,23 +4533,23 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( offset = 0; move16(); - FOR ( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ ) { hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset]; offset = add( offset, n_samp_full ); } - FOR ( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ ) + FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ ) { hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset]; offset = add( offset, n_samp_residual ); } - FOR ( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) + FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { hTcBuffer->tc_fx[ch_idx] = NULL; } /* TODO: remove the floating point dependency */ - IF ( ( hTcBuffer->tc_buffer = (float *) malloc( nsamp_to_allocate * sizeof( float ) ) ) == NULL ) + IF( ( hTcBuffer->tc_buffer = (float *) malloc( nsamp_to_allocate * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory FOR JBM TC Buffer\n" ) ); } @@ -4356,17 +4557,17 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( offset = 0; move16(); - FOR ( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ ) { hTcBuffer->tc[ch_idx] = &hTcBuffer->tc_buffer[offset]; offset = add( offset, n_samp_full ); } - FOR ( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ ) + FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ ) { hTcBuffer->tc[ch_idx] = &hTcBuffer->tc_buffer[offset]; offset = add( offset, n_samp_residual ); } - FOR ( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) + FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { hTcBuffer->tc[ch_idx] = NULL; } @@ -4377,7 +4578,6 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( /* TODO: remove floating point dependency */ hTcBuffer->tc_buffer = NULL; - } } @@ -4529,7 +4729,7 @@ TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode( buffer_mode = TC_BUFFER_MODE_BUFFER; move16(); - SWITCH ( st_ivas->renderer_type ) + SWITCH( st_ivas->renderer_type ) { /* all renderers where we are done after TC decoding (might include DMX to mono/stereo */ case RENDERER_DISABLE: @@ -4556,7 +4756,7 @@ TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode( move16(); BREAK; case RENDERER_NON_DIEGETIC_DOWNMIX: - IF ( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) { buffer_mode = TC_BUFFER_MODE_BUFFER; move16(); @@ -4564,11 +4764,11 @@ TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode( ELSE { buffer_mode = TC_BUFFER_MODE_RENDERER; - move16(); + move16(); } break; case RENDERER_MC_PARAMMC: - IF ( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) + IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { buffer_mode = TC_BUFFER_MODE_BUFFER; /* TCs are already the DMX to mono or stereo */ move16(); @@ -4580,15 +4780,18 @@ TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode( } BREAK; case RENDERER_MC: - IF ( NE_16( ivas_jbm_dec_get_num_tc_channels( st_ivas ), st_ivas->hDecoderConfig->nchan_out ) ) + IF( NE_16( ivas_jbm_dec_get_num_tc_channels( st_ivas ), st_ivas->hDecoderConfig->nchan_out ) ) { buffer_mode = TC_BUFFER_MODE_RENDERER; move16(); } BREAK; case RENDERER_SBA_LINEAR_ENC: - test(); test(); test(); test(); - IF ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) && ( EQ_32( st_ivas->renderer_type, RENDERER_MC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( ( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ) ), ( add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) ) ) + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) && ( EQ_32( st_ivas->renderer_type, RENDERER_MC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( ( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ) ), ( add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) ) ) { buffer_mode = TC_BUFFER_MODE_BUFFER; move16(); @@ -4600,8 +4803,9 @@ TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode( } BREAK; case RENDERER_SBA_LINEAR_DEC: - test(); test(); - IF ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { buffer_mode = TC_BUFFER_MODE_BUFFER; move16(); diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 9046678379bcacdb3085184a20f3c73c1fd37877..ff0e7d700f4eb3283caa5938c3cf85d54bbda834 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -3350,31 +3350,25 @@ ivas_error ivas_rend_crendProcessSubframe( const IVAS_OUTPUT_SETUP_HANDLE hIntSetup, /* i : internal setup handle */ const EFAP_HANDLE hEFAPdata, /* i : EFAP handle */ DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM handle */ - float *input_f[], /* i : transport channels */ - float *output[], /* i/o: input/output audio channels */ - const int16_t n_samples_to_render, /* i : output frame length per channel */ - const int32_t output_Fs /* i : output sampling rate */ + Word32 *input_f[], /* i : transport channels */ + Word32 *output[], /* i/o: input/output audio channels */ + const Word16 n_samples_to_render, /* i : output frame length per channel */ + const Word32 output_Fs /* i : output sampling rate */ ) { - int16_t subframe_idx, subframe_len, n; - Word16 i, j; - int16_t nchan_out, nchan_in, ch, first_sf, last_sf, slot_size, slots_to_render; - float *tc_local[MAX_OUTPUT_CHANNELS]; - Word32 tc_local_buffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; + Word16 subframe_idx, subframe_len; + Word16 nchan_out, nchan_in, ch, first_sf, last_sf, slot_size, slots_to_render; Word32 *tc_local_fx[MAX_OUTPUT_CHANNELS]; - float pcm_tmp[BINAURAL_CHANNELS][L_FRAME48k]; Word32 pcm_tmp_fx[BINAURAL_CHANNELS][L_FRAME48k]; - float *p_pcm_tmp[BINAURAL_CHANNELS]; Word32 *p_pcm_tmp_fx[BINAURAL_CHANNELS]; IVAS_REND_AudioConfigType inConfigType; ivas_error error; - int8_t combinedOrientationEnabled; + Word8 combinedOrientationEnabled; CREND_HANDLE hCrend; - hCrend = pCrend->hCrend; combinedOrientationEnabled = 0; - if ( hCombinedOrientationData != NULL ) + IF ( hCombinedOrientationData != NULL ) { if ( hCombinedOrientationData->enableCombinedOrientation[0] != 0 ) { @@ -3385,26 +3379,21 @@ ivas_error ivas_rend_crendProcessSubframe( push_wmops( "ivas_rend_crendProcessSubframe" ); inConfigType = getAudioConfigType( inConfig ); - if ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK ) + IF ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK ) + IF ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK ) { return error; } - for ( ch = 0; ch < nchan_in; ch++ ) + FOR ( ch = 0; ch < nchan_in; ch++ ) { - tc_local[ch] = input_f[ch]; - } - - for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) - { - p_pcm_tmp[ch] = pcm_tmp[ch]; + tc_local_fx[ch] = input_f[ch]; } - for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + FOR ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { p_pcm_tmp_fx[ch] = pcm_tmp_fx[ch]; } @@ -3420,189 +3409,85 @@ ivas_error ivas_rend_crendProcessSubframe( slots_to_render -= hTcBuffer->subframe_nbslots[last_sf]; last_sf++; } - for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - tc_local_fx[i] = tc_local_buffer_fx[i]; - } - - for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + FOR ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { subframe_len = hTcBuffer->subframe_nbslots[subframe_idx] * hTcBuffer->n_samples_granularity; - Word16 gd_bits = find_guarded_bits_fx( subframe_len ); - Word16 exp = 13; - exp -= gd_bits; /* Early Reflections */ - if ( hCrend->reflections != NULL ) + IF ( hCrend->reflections != NULL ) { - if ( hCrend->reflections->use_er == 1 && hCrend->reflections->is_ready == 1 ) + IF ( hCrend->reflections->use_er == 1 && hCrend->reflections->is_ready == 1 ) { - for ( i = 0; i < hCrend->reflections->shoebox_data.n_sources + 1; i++ ) - { - for ( j = 0; j < subframe_len; j++ ) - { - - tc_local_fx[i][j] = (Word32) float_to_fix( tc_local[i][j], 13 ); - } - } - for ( i = 0; i < 150; i++ ) - { - hCrend->reflections->shoebox_data.gains.data_fx[i] = (Word32) float_to_fix( hCrend->reflections->shoebox_data.gains.data[i], 15 ); - } - if ( ( error = ivas_er_process( hCrend->reflections, subframe_len, 0, tc_local_fx, inConfig ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_er_process( hCrend->reflections, subframe_len, 0, tc_local_fx, inConfig ) ) != IVAS_ERR_OK ) { return error; } - for ( i = 0; i < hCrend->reflections->shoebox_data.n_sources + 1; i++ ) - { - for ( j = 0; j < subframe_len; j++ ) - { - - tc_local[i][j] = fix_to_float( tc_local_fx[i][j], 13 ); - } - } + } } - if ( hDecoderConfig && combinedOrientationEnabled ) + IF ( hDecoderConfig && combinedOrientationEnabled ) { /* Rotation in SHD for: MC with elevation (5_1_2 / 5_1_4 / 7_1_4) -> BINAURAL SBA SPAR -> BINAURAL or BINAURAL_ROOM */ - if ( inConfig == IVAS_AUDIO_CONFIG_FOA || inConfig == IVAS_AUDIO_CONFIG_HOA2 || inConfig == IVAS_AUDIO_CONFIG_HOA3 ) + IF ( inConfig == IVAS_AUDIO_CONFIG_FOA || inConfig == IVAS_AUDIO_CONFIG_HOA2 || inConfig == IVAS_AUDIO_CONFIG_HOA3 ) { rotateFrame_shd( hCombinedOrientationData, tc_local_fx, subframe_len, *hIntSetup, 0 ); } /* Rotation in SD for MC -> BINAURAL_ROOM */ - else if ( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup ) + ELSE IF ( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup ) { Word16 nchan; nchan = hIntSetup->nchan_out_woLFE + hIntSetup->num_lfe; - for ( i = 0; i < nchan; i++ ) - { - for ( j = 0; j < subframe_len; j++ ) - { - - tc_local_fx[i][j] = (Word32) float_to_fix( tc_local[i][j], exp ); - } - } - for ( n = 0; n < 3; n++ ) - { - for ( i = 0; i < 3; i++ ) - { - hCombinedOrientationData->Rmat_prev_fx[n][i] = (Word32) ( hCombinedOrientationData->Rmat_prev[n][i] * ONE_IN_Q30 ); - hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][n][i] = (Word32) ( hCombinedOrientationData->Rmat[hCombinedOrientationData->subframe_idx][n][i] * ONE_IN_Q30 ); - } - } + rotateFrame_sd( hCombinedOrientationData, tc_local_fx, subframe_len, *hIntSetup, hEFAPdata, 0 ); - for ( i = 0; i < nchan; i++ ) - { - for ( j = 0; j < subframe_len; j++ ) - { - - tc_local[i][j] = (float) fix_to_float( tc_local_fx[i][j], ( exp - 3 ) ); - } - } - for ( n = 0; n < 3; n++ ) - { - for ( i = 0; i < 3; i++ ) - { - hCombinedOrientationData->Rmat_prev[n][i] = (float) ( hCombinedOrientationData->Rmat_prev_fx[n][i] ) / ONE_IN_Q30; - hCombinedOrientationData->Rmat[hCombinedOrientationData->subframe_idx][n][i] = (float) ( hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][n][i] ) / ONE_IN_Q30; - } - } + } } - if ( ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) ) + IF( ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) ) { - for ( i = 0; i < nchan_in; i++ ) - { - for ( j = 0; j < subframe_len; j++ ) - { - - tc_local_fx[i][j] = (Word32) float_to_fix( tc_local[i][j], exp ); - } - } - for ( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - for ( j = 0; j < subframe_len; j++ ) - { - - p_pcm_tmp_fx[i][j] = (Word32) float_to_fix( p_pcm_tmp[i][j], exp ); - } - } + if ( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, tc_local_fx, p_pcm_tmp_fx, output_Fs, 0 ) ) != IVAS_ERR_OK ) { return error; } - for ( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - for ( j = 0; j < subframe_len; j++ ) - { - - p_pcm_tmp[i][j] = fix_to_float( p_pcm_tmp_fx[i][j], exp ); - } - } - if ( pCrend->hCrend->hReverb != NULL ) + + IF ( pCrend->hCrend->hReverb != NULL ) { - REVERB_HANDLE hReverb = pCrend->hCrend->hReverb; - for ( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - - for ( j = 0; j < ( hReverb->full_block_size ); j++ ) - { - - p_pcm_tmp_fx[i][j] = (Word32) float_to_fix( p_pcm_tmp[i][j], ( exp ) ); - } - } - if ( ( error = ivas_reverb_process_fx( pCrend->hCrend->hReverb, inConfig, 1, tc_local_fx, p_pcm_tmp_fx, 0 ) ) != IVAS_ERR_OK ) { return error; } - for ( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - - for ( j = 0; j < ( hReverb->full_block_size ); j++ ) - { - - p_pcm_tmp[i][j] = fix_to_float( p_pcm_tmp_fx[i][j], ( exp - 2 ) ); - } - } - } - - for ( ch = 0; ch < nchan_in; ch++ ) - { - tc_local[ch] += subframe_len; - } - for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) - { - p_pcm_tmp[ch] += subframe_len; + } - for ( ch = 0; ch < nchan_in; ch++ ) + FOR ( ch = 0; ch < nchan_in; ch++ ) { tc_local_fx[ch] += subframe_len; } - for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { p_pcm_tmp_fx[ch] += subframe_len; } hTcBuffer->slots_rendered += hTcBuffer->subframe_nbslots[subframe_idx]; } - else + ELSE { return IVAS_ERR_INVALID_INPUT_FORMAT; } /* update combined orientation access index */ ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_len ); } - + IF ( pCrend->hCrend->hReverb != NULL ) + { + *pCrend->p_io_qfactor -= 2; + } /* move to output */ - for ( ch = 0; ch < nchan_out; ch++ ) + FOR ( ch = 0; ch < nchan_out; ch++ ) { - mvr2r( pcm_tmp[ch], output[ch], n_samples_to_render ); + mvr2r_Word32( pcm_tmp_fx[ch], output[ch], n_samples_to_render ); } hTcBuffer->subframes_rendered = last_sf; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 89653c36e6f525602f03530585d170cd827ee1ad..ebf5f3d4afb3964d0f8e4f4329a066359366f863 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1111,6 +1111,23 @@ ivas_error ivas_rend_crendProcess( const int16_t num_subframes /* i : number of subframes to render */ ); #endif +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_rend_crendProcessSubframe( + const CREND_WRAPPER *pCrend, /* i/o: Crend wrapper handle */ + const AUDIO_CONFIG inConfig, /* i : input audio configuration */ + const AUDIO_CONFIG outConfig, /* i : output audio configuration */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : decoder config. structure */ + const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ + const IVAS_OUTPUT_SETUP_HANDLE hIntSetup, /* i : internal setup handle */ + const EFAP_HANDLE hEFAPdata, /* i : EFAP handle */ + DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM handle */ + Word32 *input_f[], /* i : transport channels */ + Word32 *output[], /* i/o: input/output audio channels */ + const Word16 n_samples_to_render, /* i : output frame length per channel */ + const Word32 output_Fs /* i : output sampling rate */ +); + +#else ivas_error ivas_rend_crendProcessSubframe( const CREND_WRAPPER *pCrend, /* i/o: Crend wrapper handle */ const AUDIO_CONFIG inConfig, /* i : input audio configuration */ @@ -1126,6 +1143,7 @@ ivas_error ivas_rend_crendProcessSubframe( const int32_t output_Fs /* i : output sampling rate */ ); +#endif /*----------------------------------------------------------------------------------* * Reverberator @@ -1634,7 +1652,7 @@ void ivas_combined_orientation_update_index( #else void ivas_combined_orientation_update_index( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ - const int16_t samples_rendered /* i : samples rendered since the last call */ + const Word16 samples_rendered /* i : samples rendered since the last call */ ); #endif #ifdef IVAS_FLOAT_FIXED @@ -1643,6 +1661,11 @@ void ivas_combined_orientation_update_start_index( const Word16 samples_rendered /* i : samples rendered since the last call */ ); #else +void ivas_combined_orientation_update_index( + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ + const int16_t samples_rendered /* i : samples rendered since the last call */ +); + void ivas_combined_orientation_update_start_index( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ const int16_t samples_rendered /* i : samples rendered since the last call */ diff --git a/lib_rend/ivas_reflections.c b/lib_rend/ivas_reflections.c index 6e5c6781ef374a3d98f09f873ea941a2f3b472f3..7babca28ee0ebef6869432b3d2e3a2e94f2819fc 100644 --- a/lib_rend/ivas_reflections.c +++ b/lib_rend/ivas_reflections.c @@ -373,7 +373,7 @@ ivas_error ivas_er_compute_reflections( #ifdef IVAS_FLOAT_FIXED for ( i = 0; i < 150; i++ ) { - reflections->shoebox_data.gains.data_fx[i] = (Word32) float_to_fix( reflections->shoebox_data.gains.data[i], 15 ); + reflections->shoebox_data.gains.data_fx[i] = (Word32)( reflections->shoebox_data.gains.data[i]*ONE_IN_Q31); } if ( reflections->circ_buffers ) { @@ -472,7 +472,7 @@ ivas_error ivas_er_process( UWord16 ref_no, ref_delay; UWord16 n_ref_sources, n_ref; Word16 samp_idx, in_ch_idx, buf_ch_idx, ref_out_idx; - Word16 ref_gain; + Word32 ref_gain; Word32 *buffer_ch; Word32 temp; @@ -555,7 +555,7 @@ ivas_error ivas_er_process( for ( j = 0; j < n_ref; j++ ) { ref_no = j + ( i * n_ref ); - ref_gain = (Word16) reflections->shoebox_data.gains.data_fx[ref_no]; + ref_gain = (Word32) reflections->shoebox_data.gains.data_fx[ref_no]; ref_delay = (UWord16) reflections->shoebox_data.times.data[ref_no]; ref_out_idx = reflections->closest_ch_idx[ref_no]; @@ -570,7 +570,7 @@ ivas_error ivas_er_process( /* Pull reflection from circ buffer and apply gain */ for ( k = 0; k < subframe_size; k++ ) { - temp = Mpy_32_16_r( buffer_ch[samp_idx], ref_gain ); + temp = Mpy_32_32( buffer_ch[samp_idx], ref_gain ); io[ref_out_idx][k + subframe_offset] = L_add( temp, io[ref_out_idx][k + subframe_offset] ); samp_idx++; samp_idx = samp_idx % reflections->circ_len; diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 2fcc1860f263172bd80c5e59e9e56431b86cf85a..930afc334fcd12e1008d74fea833b65c9f466dc0 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -463,73 +463,53 @@ void rotateFrame_shd( const Word16 subframe_idx /* i : subframe index */ ) { - // Not yet fully converted the function to fixed, no test cases entering the function. - int16_t i, l, n, m, j; - int16_t m1, m2; - int16_t shd_rot_max_order; + // Not yet tested, no test cases entering the function. + Word16 i, l, n, m; + Word16 m1, m2; + Word16 shd_rot_max_order; - float tmp; - float tmpRot[2 * HEADROT_ORDER + 1]; - float SHrotmat_prev[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; - float SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; - float cross_fade[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; - Word16 SHrotmat_prev_fx[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; - Word16 SHrotmat_fx[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; - Word32 Rmat_prev_fx[3][3]; - Word32 Rmat_fx[3][3]; + Word32 tmp = Q31_BY_SUB_FRAME_240; + Word32 tmpRot[2 * HEADROT_ORDER + 1]; + Word16 SHrotmat_prev[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; + Word16 SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; + Word32 cross_fade[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; shd_rot_max_order = hTransSetup.ambisonics_order; - tmp = 1.0f / ( subframe_len - 1 ); - for ( i = 0; i < subframe_len; i++ ) - { - cross_fade[i] = i * tmp; - } - /* initialize rotation matrices with zeros */ - for ( i = 0; i < HEADROT_SHMAT_DIM; i++ ) + SWITCH( subframe_len ) { - set_zero( SHrotmat_prev[i], HEADROT_SHMAT_DIM ); - set_zero( SHrotmat[i], HEADROT_SHMAT_DIM ); + case L_SUBFRAME_48k: + tmp = Q31_BY_SUB_FRAME_240; + BREAK; + case L_SUBFRAME_32k: + tmp = Q31_BY_SUB_FRAME_180; + BREAK; + case L_SUBFRAME_16k: + tmp = Q31_BY_SUB_FRAME_80; + BREAK; + case L_SUBFRAME_8k: + tmp = Q31_BY_SUB_FRAME_40; + BREAK; + default: + BREAK; } - // Converting the arrays to fixed of Q14 - for ( i = 0; i < HEADROT_SHMAT_DIM; i++ ) + + FOR( i = 0; i < subframe_len; i++ ) { - for ( j = 0; j < HEADROT_SHMAT_DIM; j++ ) - { - SHrotmat_prev_fx[i][j] = (Word16) float_to_fix( SHrotmat_prev[i][j], 14 ); - SHrotmat_fx[i][j] = (Word16) float_to_fix( SHrotmat[i][j], 14 ); - } + cross_fade[i] = UL_Mpy_32_32( i, tmp ); } - for ( i = 0; i < 3; i++ ) + /* initialize rotation matrices with zeros */ + FOR ( i = 0; i < HEADROT_SHMAT_DIM; i++ ) { - for ( j = 0; j < 3; j++ ) - { - Rmat_prev_fx[i][j] = (Word32) float_to_fix( hCombinedOrientationData->Rmat_prev[i][j], 30 ); - Rmat_fx[i][j] = (Word32) float_to_fix( hCombinedOrientationData->Rmat[subframe_idx][i][j], 30 ); - } + set_val_Word16( SHrotmat_prev[i],0, HEADROT_SHMAT_DIM ); + set_val_Word16( SHrotmat[i],0, HEADROT_SHMAT_DIM ); } + /* calculate ambisonics rotation matrices for the previous and current frames */ - SHrotmatgen_fx( SHrotmat_prev_fx, Rmat_prev_fx, shd_rot_max_order ); + SHrotmatgen_fx( SHrotmat_prev, hCombinedOrientationData->Rmat_prev_fx, shd_rot_max_order ); - SHrotmatgen_fx( SHrotmat_fx, Rmat_fx, shd_rot_max_order ); + SHrotmatgen_fx( SHrotmat, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], shd_rot_max_order ); - // Converting the arrays to float again of Q14 - for ( i = 0; i < HEADROT_SHMAT_DIM; i++ ) - { - for ( j = 0; j < HEADROT_SHMAT_DIM; j++ ) - { - SHrotmat_prev[i][j] = fix_to_float( SHrotmat_prev_fx[i][j], 14 ); - SHrotmat[i][j] = fix_to_float( SHrotmat_fx[i][j], 14 ); - } - } - for ( i = 0; i < 3; i++ ) - { - for ( j = 0; j < 3; j++ ) - { - hCombinedOrientationData->Rmat_prev[i][j] = fix_to_float( Rmat_prev_fx[i][j], 30 ); - hCombinedOrientationData->Rmat[subframe_idx][i][j] = fix_to_float( Rmat_fx[i][j], 30 ); - } - } - for ( i = 0; i < subframe_len; i++ ) + FOR ( i = 0; i < subframe_len; i++ ) { /*As the rotation matrix becomes block diagonal in a SH basis, we can apply each angular-momentum block individually to save complexity. */ @@ -537,22 +517,23 @@ void rotateFrame_shd( /* loop over l blocks */ m1 = 1; m2 = 4; - for ( l = 1; l <= shd_rot_max_order; l++ ) + FOR ( l = 1; l <= shd_rot_max_order; l++ ) { /* compute mtx-vector product for this l */ - for ( n = m1; n < m2; n++ ) + FOR ( n = m1; n < m2; n++ ) { - tmpRot[n - m1] = 0.f; + tmpRot[n - m1] = 0; - for ( m = m1; m < m2; m++ ) + FOR ( m = m1; m < m2; m++ ) { /* crossfade with previous rotation gains */ - tmpRot[n - m1] += cross_fade[i] * SHrotmat[n][m] * output[m][subframe_idx * subframe_len + i] + ( 1 - cross_fade[i] ) * SHrotmat_prev[n][m] * output[m][subframe_idx * subframe_len + i]; + tmp = L_add(Mpy_32_32(Mpy_32_16_r(cross_fade[i] , SHrotmat[n][m]) , output[m][subframe_idx * subframe_len + i]) ,Mpy_32_32( Mpy_32_16_r(L_sub( ONE_IN_Q31 , cross_fade[i] ) , SHrotmat_prev[n][m] ), output[m][subframe_idx * subframe_len + i])); + tmpRot[n - m1] = L_add( L_shl( tmp, 1 ), tmpRot[n - m1] ); } } /* write back the result */ - for ( n = m1; n < m2; n++ ) + FOR ( n = m1; n < m2; n++ ) { output[n][subframe_idx * subframe_len + i] = (Word32) tmpRot[n - m1]; } @@ -578,11 +559,11 @@ void rotateFrame_shd( } /* move Rmat to Rmat_prev */ - for ( i = 0; i < 3; i++ ) + FOR ( i = 0; i < 3; i++ ) { - mvr2r( - hCombinedOrientationData->Rmat[subframe_idx][i], - hCombinedOrientationData->Rmat_prev[i], + mvr2r_Word32( + hCombinedOrientationData->Rmat_fx[subframe_idx][i], + hCombinedOrientationData->Rmat_prev_fx[i], 3 ); } @@ -756,8 +737,8 @@ void rotateFrame_sd( set_val_Word32( gains_prev_fx[ch_in], 0, nchan ); set_val_Word32( gains_fx[ch_in], 0, nchan ); /* set gains to passthrough by default */ - gains_prev_fx[ch_in][ch_in] = ONE_IN_Q28; - gains_fx[ch_in][ch_in] = ONE_IN_Q28; + gains_prev_fx[ch_in][ch_in] = ONE_IN_Q30; + gains_fx[ch_in][ch_in] = ONE_IN_Q30; /* skip LFE */ IF( ch_in == index_lfe ) @@ -788,7 +769,7 @@ void rotateFrame_sd( /* output channel index without LFE */ ch_out_woLFE = ( ch_out >= index_lfe ) ? ch_out - 1 : ch_out; - gains_prev_fx[ch_in][ch_out] = L_shr( tmp_gains_fx[ch_out_woLFE], Q2 ); // Adjusting Q30 -> Q28 + gains_prev_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Adjusting Q30 -> Q28 } } @@ -813,7 +794,7 @@ void rotateFrame_sd( /* output channel index without LFE */ ch_out_woLFE = ( ch_out >= index_lfe ) ? ch_out - 1 : ch_out; - gains_fx[ch_in][ch_out] = L_shr( tmp_gains_fx[ch_out_woLFE], Q2 ); // Adjusting Q30 -> Q28 + gains_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Adjusting Q30 -> Q28 } } } @@ -829,7 +810,7 @@ void rotateFrame_sd( out_temp = output[ch_in][i]; Word32 temp = Mpy_32_32( Mpy_32_32( ( cross_fade_fx[j] ), gains_fx[ch_in][ch_out] ), out_temp ); Word32 temp1 = Mpy_32_32( Mpy_32_32( ( ONE_IN_Q31 - cross_fade_fx[j] ), gains_prev_fx[ch_in][ch_out] ), out_temp ); - output_tmp_fx[ch_out][i] = L_add( L_add( temp, temp1 ), output_tmp_fx[ch_out][i] ); + output_tmp_fx[ch_out][i] = L_add( L_shl(L_add( temp, temp1 ),1), output_tmp_fx[ch_out][i] ); } } } @@ -2550,11 +2531,10 @@ void ivas_combined_orientation_update_index( } #endif - #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- - * ivas_combined_orientation_update_index() + * ivas_combined_orientation_set_to_start_index() * * update read index based on the number of rendered samples *------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 316dd97d997a158143d5814431738d764ddb3f70..66dfaa374c5a18705e2a6d333587845ea23ce504 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1653,7 +1653,8 @@ typedef struct ivas_binaural_crend_wrapper_struct Word32 binaural_latency_ns; CREND_HANDLE hCrend; HRTFS_HANDLE hHrtfCrend; - + Word16 *p_io_qfactor; + Word16 io_qfactor; } CREND_WRAPPER, *CREND_WRAPPER_HANDLE; #else diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index ccf6d9d4af7bd7b473217a376ed3ddefe6e07c0a..7e7972e75d2677510cc968e7c55ed96768064e66 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -5070,7 +5070,7 @@ static void renderBufferChannelLerp_fx( previousGain = gainsPrev == NULL ? 0 : gainsPrev[outChnlIdx]; /* Process current output channel only if applying non-zero gains */ - IF ( GT_32(abs( currentGain ) , EPSILON_fx) || ( gainsPrev != NULL && GT_32(abs( previousGain ) , EPSILON_fx ) )) + IF ( GT_32(abs( currentGain ) , EPSILON_FX) || ( gainsPrev != NULL && GT_32(abs( previousGain ) , EPSILON_FX ) )) { /* Reset input pointer to the beginning of input channel */ inSmpl = getSmplPtr_fx( inAudio, inChannelIdx, 0 ); @@ -5078,7 +5078,7 @@ static void renderBufferChannelLerp_fx( /* Set output pointer to first output channel sample */ outSmpl = getSmplPtr_fx( outAudio, outChnlIdx, 0 ); - IF ( gainsPrev == NULL || LE_32(abs( L_sub(previousGain , currentGain )) , EPSILON_fx )) + IF ( gainsPrev == NULL || LE_32(abs( L_sub(previousGain , currentGain )) , EPSILON_FX )) { /* If no interpolation from previous frame, apply current gain */ DO @@ -5142,6 +5142,7 @@ static void renderBufferChannel_fx( return; } #endif + /* Take one channel from input buffer and copy it to each channel in output buffer, with different gain applied per output channel */ static void renderBufferChannel( @@ -5755,7 +5756,7 @@ static ivas_error renderIsmToBinauralRoom( nchan = hCrend->reflections->shoebox_data.n_sources + 1; for ( i = 0; i < 150; i++ ) { - hCrend->reflections->shoebox_data.gains.data_fx[i] = (Word32) float_to_fix( hCrend->reflections->shoebox_data.gains.data[i], 15 ); + hCrend->reflections->shoebox_data.gains.data_fx[i] = (Word32) ( hCrend->reflections->shoebox_data.gains.data[i] * ONE_IN_Q31 ); } } } @@ -6416,7 +6417,7 @@ static ivas_error renderMcToBinaural( nchan = hCrend->reflections->shoebox_data.n_sources + 1; for ( i = 0; i < 150; i++ ) { - hCrend->reflections->shoebox_data.gains.data_fx[i] = (Word32) float_to_fix( hCrend->reflections->shoebox_data.gains.data[i], 15 ); + hCrend->reflections->shoebox_data.gains.data_fx[i] = (Word32) ( hCrend->reflections->shoebox_data.gains.data[i] * ONE_IN_Q31 ); } } } @@ -6660,7 +6661,7 @@ static ivas_error renderMcToBinauralRoom( nchan = hCrend->reflections->shoebox_data.n_sources + 1; for ( i = 0; i < 150; i++ ) { - hCrend->reflections->shoebox_data.gains.data_fx[i] = (Word32) float_to_fix( hCrend->reflections->shoebox_data.gains.data[i], 15 ); + hCrend->reflections->shoebox_data.gains.data_fx[i] = (Word32) ( hCrend->reflections->shoebox_data.gains.data[i] * ONE_IN_Q31 ); } } } @@ -6902,7 +6903,7 @@ static ivas_error renderMcCustomLsToBinauralRoom( nchan = hCrend->reflections->shoebox_data.n_sources + 1; for ( i = 0; i < 150; i++ ) { - hCrend->reflections->shoebox_data.gains.data_fx[i] = (Word32) float_to_fix( hCrend->reflections->shoebox_data.gains.data[i], 15 ); + hCrend->reflections->shoebox_data.gains.data_fx[i] = (Word32) ( hCrend->reflections->shoebox_data.gains.data[i] * ONE_IN_Q31 ); } } }