Commit 321539c2 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'param_mc_dec_ren_fxd' into 'main'

ivas_param_mc_dec_render fixed conversion

See merge request !287
parents 47b1902a 87d67fd3
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -4985,6 +4985,24 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot(
    PARAM_MC_DEC_HANDLE hParamMC                                    /* i  : handle to the Parametric MC decoder state                        */
);

#ifdef IVAS_FLOAT_FIXED
void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx(
    Word32 *Cldfb_RealBuffer_in_fx,
    Word32 *Cldfb_ImagBuffer_in_fx,
    Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : output channel filter bank samples (real part)                   */
    Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : output channel filter bank samples (imaginary part)              */
    Word32 *mixing_matrix_fx[],                                         /* i  : parameter band wise mixing matrices (direct part)                */
    Word16 *mixing_matrix_e,                                         /* i  : parameter band wise mixing matrices (direct part)                */
    Word32 *mixing_matrix_res_fx[],                                     /* i  : parameter band wise mixing matrices (residual part)              */
    Word16 *mixing_matrix_res_e,                                     /* i  : parameter band wise mixing matrices (residual part)              */
    const UWord16 slot_idx_sfr,                                    /* i  : time slot index for the current slot within the current subframe */
    const UWord16 slot_idx_tot,                                    /* i  : time slot index for the current slot within the frame            */
    const Word16 nX,                                               /* i  : number of input channels                                         */
    const Word16 nY,                                               /* i  : number of output channels                                        */
    PARAM_MC_DEC_HANDLE hParamMC                                    /* i  : handle to the Parametric MC decoder state                        */
);
#endif

int16_t computeMixingMatricesISM(
    const int16_t num_inputs,
    const int16_t num_responses,
+172 −3
Original line number Diff line number Diff line
@@ -1136,7 +1136,176 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot(
    return;
}

#ifdef IVAS_FLOAT_FIXED
void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx(
    Word32 *Cldfb_RealBuffer_in_fx,
    Word32 *Cldfb_ImagBuffer_in_fx,
    Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : output channel filter bank samples (real part)                   */
    Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : output channel filter bank samples (imaginary part)              */
    Word32 *mixing_matrix_fx[],                                         /* i  : parameter band wise mixing matrices (direct part)                */
    Word16 *mixing_matrix_e,                                         /* i  : parameter band wise mixing matrices (direct part)                */
    Word32 *mixing_matrix_res_fx[],                                     /* i  : parameter band wise mixing matrices (residual part)              */
    Word16 *mixing_matrix_res_e,                                     /* i  : parameter band wise mixing matrices (residual part)              */
    const UWord16 slot_idx_sfr,                                    /* i  : time slot index for the current slot within the current subframe */
    const UWord16 slot_idx_tot,                                    /* i  : time slot index for the current slot within the frame            */
    const Word16 nX,                                               /* i  : number of input channels                                         */
    const Word16 nY,                                               /* i  : number of output channels                                        */
    PARAM_MC_DEC_HANDLE hParamMC                                    /* i  : handle to the Parametric MC decoder state                        */
)
{
    Word16 param_band_idx, band, ch_idx;
    Word16 have_residual;
    Word16 brange[2];
    DIRAC_OUTPUT_SYNTHESIS_COV_STATE h_synthesis_state = hParamMC->h_output_synthesis_cov_state;

    Word32 mixing_matrix_smooth_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
    Word16 mixing_matrix_smooth_e;
    Word32 mixing_matrix_res_smooth_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
    Word16 mixing_matrix_res_smooth_e;
    Word32 mixing_matrix_buffer_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
    Word16 mixing_matrix_buffer_e;
    Word32 input_f_real_fx[PARAM_MC_MAX_TRANSPORT_CHANS];
    Word32 input_f_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS];
    Word32 output_f_real_fx[MAX_CICP_CHANNELS];
    Word32 output_f_imag_fx[MAX_CICP_CHANNELS];
    Word16 output_f_real_e;
    Word16 output_f_imag_e;
    Word32 diff_f_real_fx[MAX_CICP_CHANNELS];
    Word32 diff_f_imag_fx[MAX_CICP_CHANNELS];
    Word16 diff_f_real_e;
    Word16 diff_f_imag_e;

    set_zero_fx( input_f_real_fx, PARAM_MC_MAX_TRANSPORT_CHANS );
    set_zero_fx( input_f_imag_fx, PARAM_MC_MAX_TRANSPORT_CHANS );
    set_zero_fx( output_f_real_fx, MAX_CICP_CHANNELS );
    set_zero_fx( output_f_imag_fx, MAX_CICP_CHANNELS );
    set_zero_fx( diff_f_real_fx, MAX_CICP_CHANNELS );
    set_zero_fx( diff_f_imag_fx, MAX_CICP_CHANNELS );

    FOR ( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ )
    {
        /* final mixing */
        have_residual = 0;
        move16();
        brange[0] = hParamMC->band_grouping[param_band_idx];
        move16();
        brange[1] = hParamMC->band_grouping[param_band_idx + 1];
        move16();

        IF ( brange[0] < hParamMC->h_output_synthesis_params.max_band_decorr )
        {
            have_residual = 1;
            move16();
        }

        v_multc_fixed(mixing_matrix_fx[param_band_idx], L_deposit_h(hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot]), mixing_matrix_smooth_fx, nY * nX);
        mixing_matrix_smooth_e = mixing_matrix_e[param_band_idx]; // interpolator is W16
        move16();

        v_multc_fixed(h_synthesis_state.mixing_matrix_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h(hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, nY * nX);
        mixing_matrix_buffer_e = h_synthesis_state.mixing_matrix_old_exp[param_band_idx]; // interpolator is W16

        v_add_fixed_me(mixing_matrix_smooth_fx, mixing_matrix_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_smooth_fx, &mixing_matrix_smooth_e, nY * nX, 0);

        IF ( have_residual )
        {
            /* residual mixing matrix interpolation*/

            v_multc_fixed(mixing_matrix_res_fx[param_band_idx], L_deposit_h(hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot]), mixing_matrix_res_smooth_fx, nY * nY );
            mixing_matrix_res_smooth_e = mixing_matrix_res_e[param_band_idx] ; // interpolator is W16

            set_zero_fx(mixing_matrix_buffer_fx, nY * nY);
            v_multc_fixed(h_synthesis_state.mixing_matrix_res_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot]) ), mixing_matrix_buffer_fx, nY * nY);
            mixing_matrix_buffer_e = h_synthesis_state.mixing_matrix_res_old_exp[param_band_idx]; // interpolator is W16


            v_add_fixed_me(mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_res_smooth_fx, &mixing_matrix_res_smooth_e, nY * nY, 0);
        }



        FOR ( band = brange[0]; band < brange[1]; band++ )
        {
            assert( band >= 0 );

            IF ( have_residual )
            {
                /* collect diffuse prototypes */
                assert( band < hParamMC->h_output_synthesis_params.max_band_decorr );
                FOR ( ch_idx = 0; ch_idx < nY; ch_idx++ )
                {
                    diff_f_real_fx[ch_idx] = Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band]; // Q6
                    move32();
                    diff_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band];
                    move32();
                }

                /* apply residual mixing */

                matrix_product_fx( mixing_matrix_res_smooth_fx, nY, nY, 0, diff_f_real_fx, nY, 1, 0, output_f_real_fx );
                output_f_real_e = add( mixing_matrix_res_smooth_e, 25 );
                scale_sig32(output_f_real_fx, nY, 6 - (31 - output_f_real_e) );


                matrix_product_fx(mixing_matrix_res_smooth_fx, nY, nY, 0, diff_f_imag_fx, nY, 1, 0, output_f_imag_fx);
                output_f_imag_e = mixing_matrix_res_smooth_e + 25;
                scale_sig32(output_f_imag_fx, nY,  6 - (31 - output_f_imag_e) );

                FOR ( ch_idx = 0; ch_idx < nY; ch_idx++ )
                {
                    Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band] = output_f_real_fx[ch_idx]; // Q6
                    move32();
                    Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = output_f_imag_fx[ch_idx];
                    move32();
                }
            }
            ELSE
            {
                FOR ( ch_idx = 0; ch_idx < nY; ch_idx++ )
                {
                    Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band] = 0;
                    move32();
                    Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = 0;
                    move32();
                }
            }

            /* collect input signals, still in cldfb buffers */
            FOR ( ch_idx = 0; ch_idx < nX; ch_idx++ )
            {

                input_f_real_fx[ch_idx] = Cldfb_RealBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; // Q6
                move32();
                input_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band];
                move32();

            }

            /* apply mixing matrix */

            matrix_product_fx(mixing_matrix_smooth_fx, nY, nX, 0, input_f_real_fx, nX, 1, 0, output_f_real_fx);
            output_f_real_e = add( mixing_matrix_smooth_e, 25 );
            scale_sig32(output_f_real_fx, MAX_CICP_CHANNELS, sub( 6, sub(31, output_f_real_e) ) );


            matrix_product_fx(mixing_matrix_smooth_fx, nY, nX, 0, input_f_imag_fx, nX, 1, 0, output_f_imag_fx);
            output_f_imag_e = add( mixing_matrix_smooth_e, 25 );
            scale_sig32(output_f_imag_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_imag_e ) ) );

            /* collect output */
            FOR ( ch_idx = 0; ch_idx < nY; ch_idx++ )
            {
                Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band] = L_add(Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band], output_f_real_fx[ch_idx] );
                Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = L_add(Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band], output_f_imag_fx[ch_idx] );
                
            }
        }
    }

    return;
}

#endif
/*-------------------------------------------------------------------*
 * computeMixingMatrices()
 *
+50 −7
Original line number Diff line number Diff line
@@ -4442,21 +4442,16 @@ ivas_error ivas_jbm_dec_render(
                {
                    /* Convert CICP19 -> Ambisonics */
#if 1
                    Word16 Q_in_buffer_td = 31;
                    FOR( i = 0; i < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ )
                    {
                        Q_in_buffer_td = s_min( Q_in_buffer_td, Q_factor_arrL( p_output[i], *nSamplesRendered ) );
                    }
                    FOR( i = 0; i < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ )
                    {
                        floatToFixed_arrL( p_output[i], p_output_fx[i], Q_in_buffer_td, *nSamplesRendered );
                        floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, *nSamplesRendered );
                    }
#endif
                    ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
#if 1
                    FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ )
                    {
                        fixedToFloat_arrL( p_output_fx[i], p_output[i], Q_in_buffer_td - 3, *nSamplesRendered );
                        fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered );
                    }
#endif
                }
@@ -5263,7 +5258,17 @@ ivas_error ivas_jbm_dec_render(
                if ( ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ) )
                {
                    crendInPlaceRotation = TRUE;
#ifdef IVAS_FLOAT_FIXED
                    ivas_mc2sba_fx( st_ivas->hTransSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX );
#if 1
                    FOR( i = 0; i < ( st_ivas->hIntSetup.ambisonics_order + 1 ) * ( st_ivas->hIntSetup.ambisonics_order + 1 ); i++ )
                    {
                        fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered );
                    }
#endif
#else
                    ivas_mc2sba( st_ivas->hTransSetup, p_tc, p_output, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE );
#endif // IVAS_FLOAT_FIXED
                }
            }

@@ -5334,7 +5339,17 @@ ivas_error ivas_jbm_dec_render(
            }
            else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
            {
#ifdef IVAS_FLOAT_FIXED
                ivas_mc2sba_fx( st_ivas->hIntSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
#if 1
                FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ )
                {
                    fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered );
                }
#endif
#else
                ivas_mc2sba( st_ivas->hIntSetup, p_tc, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f );
#endif
            }
            else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD )
            {
@@ -5465,7 +5480,21 @@ ivas_error ivas_jbm_dec_render(
            }
            else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
            {
#ifdef IVAS_FLOAT_FIXED
                    FOR( i = 0; i < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ )
                    {
                        floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, *nSamplesRendered );
                    }
                ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
#if 1
                FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ )
                {
                    fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered );
                }
#endif
#else
                ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f );
#endif
            }
            else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD )
            {
@@ -5514,7 +5543,21 @@ ivas_error ivas_jbm_dec_render(
                        mvr2r( st_ivas->hTcBuffer->tc[LFE_CHANNEL - 1] + offset, p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
                    }

#ifdef IVAS_FLOAT_FIXED
                    FOR( i = 0; i < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ )
                    {
                        floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, *nSamplesRendered );
                    }
                    ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
#if 1
                    FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ )
                    {
                        fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered );
                    }
#endif
#else
                    ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f );
#endif
                }
                else if ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_5_1 && ( output_config == IVAS_AUDIO_CONFIG_5_1_2 || output_config == IVAS_AUDIO_CONFIG_5_1_4 || output_config == IVAS_AUDIO_CONFIG_7_1 ) )
                {
+259 −12

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ void ivas_mc2sba_fx(
                /* Add LFE to omni W with gain*/
                FOR( k = 0; k < output_frame; k++ )
                {
                    buffer_tmp_fx[0][k] = L_add( buffer_tmp_fx[0][k], L_shr( Mult_32_16( in_buffer_td_fx[i][k], gain_lfe_fx ), 2 ) ); /*Q+14-15-2==Q-3*/
                    buffer_tmp_fx[0][k] = L_add( buffer_tmp_fx[0][k], L_shl( Mult_32_16( in_buffer_td_fx[i][k], gain_lfe_fx ), 1 ) ); /*Q+14-15+1==Q*/
                }
            }

@@ -259,7 +259,7 @@ void ivas_mc2sba_fx(
            {
                FOR( k = 0; k < output_frame; k++ )
                {
                    buffer_tmp_fx[j][k] = L_add( buffer_tmp_fx[j][k], L_shr( Mult_32_32( in_buffer_td_fx[i][k], gains_fx[j] ), 1 ) ); /*Q+29-31-1==Q-3*/
                    buffer_tmp_fx[j][k] = L_add( buffer_tmp_fx[j][k], L_shl( Mult_32_32( in_buffer_td_fx[i][k], gains_fx[j] ), 2 ) ); /*Q+29-31+2==Q*/
                }
            }
        }
Loading