Commit 7a5e6ffd authored by Nishant S Kulgod's avatar Nishant S Kulgod
Browse files

commit 2

parent df121ec9
Loading
Loading
Loading
Loading
Loading
+160 −571
Original line number Diff line number Diff line
@@ -87,12 +87,6 @@ ivas_error ivas_mct_dec(
  int32_t ivas_total_brate;
  ivas_error error;

#ifdef IVAS_FLOAT_FIXED
    /* TODO: Temporary fix to avoid garbage values while calculating its q-factor
    when not initialised. */
    set_zero((float *)Aq, MCT_MAX_BLOCKS*CPE_CHANNELS*(NB_SUBFR16k + 1) * (M + 1));
#endif

  push_wmops("ivas_mct_dec");

  error = IVAS_ERR_OK;
@@ -127,32 +121,10 @@ ivas_error ivas_mct_dec(
      set_s(param_lpc[cpe_id][n], 0, NPRM_LPC_NEW);
    }

#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 );

        IF( ( error = ivas_cpe_dec_fx( st_ivas, cpe_id, &output_fx[0], output_frame, 0, &q_output ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        for ( int k = 0; k < L_FRAME48k; k++ )
        {
            output[0][k] = (float) output_fx[0][k] / ( 1 << q_output );
            output[1][k] = (float) output_fx[1][k] / ( 1 << q_output );
        }
        free( output_fx[0] );
        free( output_fx[1] );
#else
    if ((error = ivas_cpe_dec(st_ivas, cpe_id, output, output_frame, 0)) != IVAS_ERR_OK)
    {
      return error;
    }
#endif // IVAS_FLOAT_FIXED

    if (cpe_id == 0)
    {
@@ -185,217 +157,15 @@ ivas_error ivas_mct_dec(
      set_zero(x[n][1], L_FRAME48k / 2);
    }

#ifdef IVAS_FLOAT_FIXED
#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED
        hCPE = st_ivas->hCPE[cpe_id];
        sts = hCPE->hCoreCoder;

        Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )];
        Word16 ch, k, l, i, j;

        Word32 *x_fx[CPE_CHANNELS][NB_DIV];
        Word16 x_e[CPE_CHANNELS][NB_DIV];
        Word16 x_len[CPE_CHANNELS][NB_DIV] = { 0 };

        FOR( i = 0; i < CPE_CHANNELS; ++i )
        {
            x_fx[i][0] = malloc( L_FRAME48k * sizeof( Word32 ) );
            x_fx[i][1] = x_fx[i][0] + L_FRAME48k / 2;
            floatToFixed_arrL( x[i][0], x_fx[i][0], 0, L_FRAME48k / 2 );
            floatToFixed_arrL( x[i][1], x_fx[i][1], 0, L_FRAME48k / 2 );

            FOR( j = 0; j < NB_DIV; ++j )
            {
                x_e[i][j] = 31;
            }
        }

        FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
        {
            IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE )
            {
                sts[ch]->gamma = float_to_fix16( sts[ch]->gamma_float, Q15 );
                sts[ch]->preemph_fac = float_to_fix16( sts[ch]->preemph_fac_float, Q15 );
                sts[ch]->Mode2_lp_gainp = float_to_fix( sts[ch]->lp_gainp, Q16 );
                sts[ch]->hTcxLtpDec->tcxltp_gain = float_to_fix16( sts[ch]->hTcxLtpDec->tcxltp_gain_float, Q15 );
                sts[ch]->inv_gamma = float_to_fix16( 1 / sts[ch]->gamma_float, Q14 );
                f2me_16( sts[ch]->last_gain_syn_deemph_float, &sts[ch]->last_gain_syn_deemph, &sts[ch]->last_gain_syn_deemph_e );
                f2me_16( sts[ch]->last_concealed_gain_syn_deemph_float, &sts[ch]->last_concealed_gain_syn_deemph, &sts[ch]->last_concealed_gain_syn_deemph_e );
                f2me_16( sts[ch]->hTcxDec->old_gaintcx_bfi_float, &sts[ch]->hTcxDec->old_gaintcx_bfi, &sts[ch]->hTcxDec->old_gaintcx_bfi_e );
                floatToFixed_arr( Aq[cpe_id][ch], Aq_fx[cpe_id][ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) );

                sts[ch]->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( sts[ch]->hTcxDec->tcxltp_last_gain_unmodified_float, Q15 );
                sts[ch]->old_fpitch = float_to_fix( sts[ch]->old_fpitch_float, Q16 );
                //sts[ch]->hTonalMDCTConc->lastPitchLag = float_to_fix( sts[ch]->hTonalMDCTConc->lastPitchLag_float, Q16 );
                // u8bit to 16bit
                FOR( l = 0; l < IGF_START_MX; l++ )
                {
                    sts[ch]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[ch]->hIGFDec->infoTCXNoise[l];
                }
                FOR( l = 0; l < N_LTP_GAIN_MEMS; l++ )
                {
                    sts[ch]->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( sts[ch]->hTcxDec->ltpGainMemory[l], Q15 );
                }
                sts[ch]->hTcxDec->cummulative_damping_tcx = float_to_fix16( sts[ch]->hTcxDec->cummulative_damping_tcx_float, Q15 );
            }
        }
        FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
        {
            IF( sts[ch]->rate_switching_reset )
            {
                floatToFixed_arr( sts[ch]->lsp_old, sts[ch]->lsp_old_fx, Q15, M );
            }
        }
#endif
        ivas_mdct_core_invQ_fx( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id],
                                fUseTns[cpe_id], tnsData[cpe_id], x_fx, x_e, x_fx, x_e, x_len, Aq_fx[cpe_id], NULL, 1 );
#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED
        FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
        {
            IF( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE )
            {
                me2f_buf( x_fx[ch][0], x_e[ch][0], x[ch][0], sts[ch]->hTcxCfg->tcx_coded_lines );
                sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 );
                sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e );
                sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e );
            }
            IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE )
            {
                sts[ch]->lp_gainp = fix_to_float( sts[ch]->Mode2_lp_gainp, Q16 );
                //sts[ch]->hTonalMDCTConc->lastPitchLag_float = fix_to_float( sts[ch]->hTonalMDCTConc->lastPitchLag, Q16 );
                sts[ch]->hTonalMDCTConc->nFramesLost_float = fix16_to_float( sts[ch]->hTonalMDCTConc->nFramesLost, Q1 );
                sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 );
                sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e );
                sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e );
                sts[ch]->last_concealed_gain_syn_deemph_float = me2f_16( sts[ch]->last_concealed_gain_syn_deemph, sts[ch]->last_concealed_gain_syn_deemph_e );
                sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e );
                sts[ch]->hTcxDec->old_gaintcx_bfi_float = me2f_16( sts[ch]->hTcxDec->old_gaintcx_bfi, sts[ch]->hTcxDec->old_gaintcx_bfi_e );
                fixedToFloat_arr( Aq_fx[cpe_id][ch], Aq[cpe_id][ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) );
                // 16bit to u8bit
                FOR( Word16 l = 0; l < IGF_START_MX; l++ )
                {
                    sts[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) sts[ch]->hIGFDec->infoTCXNoise_evs[l];
                }
                FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ )
                {
                    sts[ch]->hTcxDec->ltpGainMemory[l] = fix16_to_float( sts[ch]->hTcxDec->ltpGainMemory_fx[l], Q15 );
                }

                Word16 subFrames = ( sts[ch]->core == TCX_10_CORE ) ? NB_DIV : 1;
                FOR( k = 0; k < subFrames; ++k )
                {
                    me2f_buf( x_fx[ch][k], x_e[ch][k], x[ch][k], x_len[ch][k] );
                    // To be made into Q11
                    // me2f_buf(x_fx[ch][k], x_e[ch][k], x[ch][k], L_FRAME48k / 2);
                }
                IF( !sts[0]->bfi || ( sts[0]->bfi && sts[ch]->core != ACELP_CORE ) )
                {
                    me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) );
                }
                sts[ch]->hTcxDec->cummulative_damping_tcx_float = fix16_to_float( sts[ch]->hTcxDec->cummulative_damping_tcx, Q15 );
            }
        }
        FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
        {
            IF( sts[ch]->rate_switching_reset )
            {
                Word16 old_Aq_12_8_e = norm_s( sts[ch]->old_Aq_12_8_fx[0] );
                fixedToFloat_arr( sts[ch]->old_Aq_12_8_fx, sts[ch]->old_Aq_12_8, ( 15 - old_Aq_12_8_e ), M + 1 );
            }
        }

        FOR( i = 0; i < CPE_CHANNELS; ++i )
        {
            free( x_fx[i][0] );
        }

#endif
#else
    ivas_mdct_core_invQ(st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id],
      fUseTns[cpe_id], tnsData[cpe_id], x, x, Aq[cpe_id], NULL, 1);
#endif

    st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect;
    st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect;
  }

  /* MCT core decoder */
#ifdef IVAS_FLOAT_FIXED
#if 1
    Word32 *signal_out_fx[MAX_TRANSPORT_CHANNELS];
    Decoder_State *st, *sts_tmp[MAX_TRANSPORT_CHANNELS];
    int i = 0;
    for (cpe_id = 0; cpe_id < nCPE; cpe_id++)
    {
        for (int ch = 0; ch < CPE_CHANNELS; ch++)
        {
            sts_tmp[i] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch];
            i++;
        }
    }

    i = 0;
    for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++)
    {
        if (sts_tmp[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE)
        {
            continue;
        }
        i++;
    }

    for (int i = 0; i < hMCT->nchan_out_woLFE; ++i)
    {
        signal_out_fx[i] = malloc(L_FRAME48k * sizeof(Word32));
        floatToFixed_arrL(output[i], signal_out_fx[i], Q12, L_FRAME48k);
    }
    Word16 q_x[MAX_TRANSPORT_CHANNELS];
    set16_fx(q_x, Q12, MAX_TRANSPORT_CHANNELS);
#endif

    ivas_mct_core_dec(hMCT, st_ivas->hCPE, nCPE, signal_out_fx, q_x);
     
    for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++)
    {
        fixedToFloat_arrL(signal_out_fx[ch], output[ch], q_x[ch], L_FRAME48k);
        free(signal_out_fx[ch]);
    }
    /*for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++)
    {
        dbgwrite_txt(output[ch] , L_FRAME48k, "Fixed_code_mct_core.txt", NULL);
        for (int k = 0; k < L_FRAME48k; k++)
        {
            k = k;
        }
    }*/
#if 1
    if (sts_tmp[0]->igf)
    {
        if (!hMCT->currBlockDataCnt)
        {
            for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++)
            {
                st = sts_tmp[ch];

                IF(st->igf)
                {
                    me2f_buf(st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, (N_MAX_TCX - IGF_START_MN));
                    FOR(Word16 l = 0; l < IGF_START_MX; l++)
                    {
                        st->hIGFDec->infoTCXNoise[l] = (uint8_t)st->hIGFDec->infoTCXNoise_evs[l];
                    }
                }
            }
        }
    }
#endif
#else
  ivas_mct_core_dec(hMCT, st_ivas->hCPE, nCPE, output);
    /*for (int ch = 0; ch < hMCT->nchan_out_woLFE; ch++)
    {
        dbgwrite_txt(output[ch], L_FRAME48k, "Float_code_mct_core.txt", NULL);
    }*/
#endif

  /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/
  if (st_ivas->sba_dirac_stereo_flag && st_ivas->ivas_format != SBA_ISM_FORMAT)
@@ -426,22 +196,7 @@ ivas_error ivas_mct_dec(
  if (st_ivas->renderer_type == RENDERER_MC)
  {
    /* Equalization in MDCT Domain */
#ifdef IVAS_FLOAT_FIXED
        Word32 *output_fx[MAX_TRANSPORT_CHANNELS];
        for ( int i = 0; i < st_ivas->nchan_transport; ++i )
        {
            output_fx[i] = malloc( L_FRAME48k * sizeof( Word32 ) );
            floatToFixed_arrL( output[i], output_fx[i], Q11, L_FRAME48k );
        }
        ivas_ls_setup_conversion_process_mdct_fx( st_ivas, output_fx);
        for ( int i = 0; i < st_ivas->nchan_transport; ++i )
        {
            fixedToFloat_arrL( output_fx[i], output[i], Q11, L_FRAME48k );
            free(output_fx[i]);
        }
#else
    ivas_ls_setup_conversion_process_mdct(st_ivas, output);
#endif
  }

  else if (st_ivas->renderer_type == RENDERER_MC_PARAMMC && (st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO))
@@ -457,65 +212,7 @@ ivas_error ivas_mct_dec(
      }
    }

#ifdef IVAS_FLOAT_FIXED
        Word32 **output_fx;
        Word16 x_all_e[MAX_CICP_CHANNELS][NB_DIV] = { 0 };
        Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV];
        IF( ( output_fx = (Word32 **) malloc( MAX_CICP_CHANNELS * sizeof( Word32 * ) ) ) == NULL )
        {
            return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
        }
        FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
        {
            FOR( n = 0; n < CPE_CHANNELS; n++ )
            {
                IF( ( output_fx[n + cpe_id * CPE_CHANNELS] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL )
                {
                    return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) );
                }
                f2me_buf( output[n + cpe_id * CPE_CHANNELS], output_fx[n + cpe_id * CPE_CHANNELS], &x_all_e[n + cpe_id * CPE_CHANNELS][0], 960 );
                Scale_sig32( output_fx[n + cpe_id * CPE_CHANNELS], L_FRAME48k, -1 ); /*Scaling the signal down by 1 because of overflow*/
                x_all_e[n + cpe_id * CPE_CHANNELS][0]++;
                x_all_fx[n + cpe_id * CPE_CHANNELS][0] = output_fx[n + cpe_id * CPE_CHANNELS];
                x_all_fx[n + cpe_id * CPE_CHANNELS][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 );
                x_all_e[n + cpe_id * CPE_CHANNELS][1] = x_all_e[n + cpe_id * CPE_CHANNELS][0];
            }
        }
        f2me_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt );
        f2me_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt );
        PARAM_MC_DEC_HANDLE hParamMC;
        hParamMC = st_ivas->hParamMC;
        floatToFixed_arr16( hParamMC->icld_q, hParamMC->icld_q_fx, 8, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe );
        floatToFixed_arr32( hParamMC->ls_conv_dmx_matrix, hParamMC->ls_conv_dmx_matrix_fx, 15, st_ivas->hDecoderConfig->nchan_out * ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) );
		FOR(Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++)
		{
			FOR(Word16 chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++)
			{
				st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix(st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30); /*Q30*/
			}
		}
        ivas_ls_setup_conversion_process_mdct_param_mc_fx( st_ivas, x_all_fx, x_all_e );
        FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
        {
            FOR( n = 0; n < CPE_CHANNELS; n++ )
            {
                me2f_buf( &x_all_fx[n + cpe_id * CPE_CHANNELS][0][0], x_all_e[n + cpe_id * CPE_CHANNELS][0], &x_all[n + cpe_id * CPE_CHANNELS][0][0], L_FRAME48k / 2 );
                me2f_buf( &x_all_fx[n + cpe_id * CPE_CHANNELS][1][0], x_all_e[n + cpe_id * CPE_CHANNELS][1], &x_all[n + cpe_id * CPE_CHANNELS][1][0], L_FRAME48k / 2 );
            }
        }
        me2f_buf( st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt );
        me2f_buf( st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt );

        FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
        {
            FOR( n = 0; n < CPE_CHANNELS; n++ )
            {
                free( output_fx[n + cpe_id * CPE_CHANNELS] );
            }
        }
#else
    ivas_ls_setup_conversion_process_mdct_param_mc(st_ivas, x_all);
#endif //
  }

  for (cpe_id = 0; cpe_id < nCPE; cpe_id++)
@@ -552,108 +249,7 @@ ivas_error ivas_mct_dec(
      mvr2r(synth[n], output[cpe_id * CPE_CHANNELS + n], output_frame);

      /* Save synthesis for HQ FEC */
#ifdef IVAS_FLOAT_FIXED
            Word32 exp_max = 0, i;
            Word32 output_fx[L_FRAME48k];
            if ( ( sts[n]->codec_mode == MODE1 && sts[n]->hTcxDec != NULL ) && ( ( sts[n]->core == ACELP_CORE && !( sts[n]->bfi == 1 && sts[n]->con_tcx == 1 ) ) || sts[n]->core == HQ_CORE ) )
            {
                double max_prev_synth_buffer = 0.0f, max_old_out = 0.0f, max_delay_buf_out = 0.0f, max_ouput = 0.0f, max_synth_history = 0.0f;
                Word32 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0;

                /*Find maximum values for all the buffers*/
                for ( i = 0; i < NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); i++ )
                {
                    max_prev_synth_buffer = max( max_prev_synth_buffer, fabs( sts[n]->prev_synth_buffer[i] ) );
                }
                if ( (Word16) max_prev_synth_buffer != 0 )
                {
                    frexp( max_prev_synth_buffer, &exp_prev_synth_buffer );
                }

                for ( i = NS2SA( sts[n]->output_Fs, N_ZERO_MDCT_NS ); i < NS2SA( sts[n]->output_Fs, N_ZERO_MDCT_NS ) + NS2SA( sts[n]->output_Fs, PH_ECU_LOOKAHEAD_NS ); i++ )
                {
                    max_old_out = max( max_old_out, fabs( sts[n]->hHQ_core->old_out[i] ) );
                }
                if ( (Word16) max_old_out != 0 )
                {
                    frexp( max_old_out, &exp_old_out );
                }

                for ( i = 0; i < NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ); i++ )
                {
                    max_delay_buf_out = max( max_delay_buf_out, fabs( sts[n]->delay_buf_out[i] ) );
                }
                if ( (Word16) max_delay_buf_out != 0 )
                {
                    frexp( max_delay_buf_out, &exp_delay_buf_out );
                }

                for ( i = 0; i < output_frame; i++ )
                {
                    max_ouput = max( max_ouput, fabs( output[cpe_id * CPE_CHANNELS + n][i] ) );
                }
                if ( (Word16) max_ouput != 0 )
                {
                    frexp( max_ouput, &exp_ouput );
                }

                for ( i = output_frame; i < 2 * output_frame - NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ) + NS2SA( sts[n]->output_Fs, PH_ECU_MEM_NS ); i++ )
                {
                    max_synth_history = max( max_synth_history, fabs( sts[n]->hTcxDec->synth_history[i] ) );
                }

                if ( (Word16) max_synth_history != 0 )
                {
                    frexp( max_synth_history, &exp_synth_history );
                }

                /*Find a commen maximum exp*/
                exp_max = max( exp_synth_history, exp_ouput );
                exp_max = max( exp_max, exp_prev_synth_buffer );
                exp_max = max( exp_max, exp_old_out );
                exp_max = max( exp_max, exp_delay_buf_out );

                for ( i = 0; i < NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ); i++ )
                {
                    f2fix_16( &sts[n]->delay_buf_out[i], &sts[n]->delay_buf_out_fx[i], exp_max );
                }
                for ( i = NS2SA( sts[n]->output_Fs, N_ZERO_MDCT_NS ); i < NS2SA( sts[n]->output_Fs, PH_ECU_LOOKAHEAD_NS ); i++ )
                {
                    f2fix_16( &sts[n]->hHQ_core->old_out[i], &sts[n]->hHQ_core->old_out_fx[i], exp_max );
                }
                for ( i = 0; i < NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); i++ )
                {
                    f2fix_16( &sts[n]->prev_synth_buffer[i], &sts[n]->prev_synth_buffer_fx[i], exp_max );
                }
                for ( i = output_frame; i < 2 * output_frame - NS2SA( sts[n]->output_Fs, DELAY_CLDFB_NS ) + NS2SA( sts[n]->output_Fs, PH_ECU_MEM_NS ); i++ )
                {
                    f2fix_16( &sts[n]->hTcxDec->synth_history[i], &sts[n]->hTcxDec->synth_history_fx[i], exp_max );
                }
                for ( i = 0; i < output_frame; i++ )
                {
                    f2fix( &output[cpe_id * CPE_CHANNELS + n][i], &output_fx[i], exp_max );
                }
            }

            save_synthesis_hq_fec_fx( sts[n], output_fx, output_frame, hCPE );
      save_synthesis_hq_fec(sts[n], output[cpe_id * CPE_CHANNELS + n], output_frame, hCPE);
            if ( ( sts[n]->codec_mode == MODE1 && sts[n]->hTcxDec != NULL ) && ( ( sts[n]->core == ACELP_CORE && !( sts[n]->bfi == 1 && sts[n]->con_tcx == 1 ) ) || sts[n]->core == HQ_CORE ) )
            {
                /*dumps*/
                float track = 0;
                for ( i = 0; i < 2 * output_frame; i++ )
                {
                    fix2f_16( &sts[n]->hTcxDec->synth_history_fx[i], &track, exp_max );
                    fix2f_16( &sts[n]->hTcxDec->synth_history_fx[i], &sts[n]->hTcxDec->synth_history[i], exp_max );
#ifdef DUMPS_ENABLED
                    dbgwrite_txt( &track, 1, "Fixed_code_synth_history_fx.txt", NULL );
                    dbgwrite_txt( &sts[n]->hTcxDec->synth_history[i], 1, "Float_code_synth_history_fx.txt", NULL );
#endif
                }
            }
#else
            save_synthesis_hq_fec( sts[n], output[cpe_id * CPE_CHANNELS + n], output_frame, hCPE );
#endif

      /* CoreCoder common updates */
      updt_dec_common(sts[n], NORMAL_HQ_CORE, -1, output[cpe_id * CPE_CHANNELS + n]);
@@ -664,14 +260,7 @@ ivas_error ivas_mct_dec(
    /* synthesis synchronization between stereo modes */
    if (!st_ivas->sba_dirac_stereo_flag || (st_ivas->ivas_format == SBA_ISM_FORMAT && cpe_id < nCPE - 2))
    {
#ifdef IVAS_FLOAT_FIXED
          synchro_synthesis_fixed( ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0 );
#else
      synchro_synthesis(ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0);
#endif

          //Todo use below once input is fixed not done due to complication in pointer
          //synchro_synthesis_fixed_clean( ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0 );
    }

  }
+58 −0
Original line number Diff line number Diff line
@@ -903,6 +903,8 @@ void ivas_sba_mix_matrix_determiner_fx(
}
#endif // IVAS_FLOAT_FIXED

#ifdef IVAS_FLOAT_FIXED

void ivas_sba_mix_matrix_determiner(
    SPAR_DEC_HANDLE hSpar,          /* i/o: SPAR decoder handle                 */
    float *output[],                /* i/o: transport/output audio channels     */
@@ -1092,4 +1094,60 @@ void ivas_sba_mix_matrix_determiner(
    return;
}

#else

void ivas_sba_mix_matrix_determiner(
  SPAR_DEC_HANDLE hSpar,          /* i/o: SPAR decoder handle                 */
  float *output[],                /* i/o: transport/output audio channels     */
  const int16_t bfi,              /* i  : BFI flag                            */
  const int16_t nchan_remapped,   /* i  : num channels after remapping of TCs */
  const int16_t output_frame,     /* i  : output frame length                 */
  const int16_t num_md_sub_frames /* i  : number of subframes in mixing matrix*/
)
{
  int16_t i, ch;
  float temp;
  int16_t num_bands_out, nchan_transport, nchan_out;

  /* Convert numeric range */
  for (ch = 0; ch < nchan_remapped; ch++)
  {
    for (i = 0; i < output_frame; i++)
    {
      temp = output[ch][i];
      temp = floorf(temp + 0.5f);

      if (temp > MAX16B_FLT)
      {
        temp = MAX16B_FLT;
      }
      else if (temp < (-1.0f * PCM16_TO_FLT_FAC))
      {
        temp = (-1.0f * PCM16_TO_FLT_FAC);
      }
      temp *= (1.0f / PCM16_TO_FLT_FAC);
      output[ch][i] = temp;
    }
  }

  /* AGC */
  nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
  nchan_out = nchan_transport;
  ivas_agc_dec_process(hSpar->hAgcDec, output, output, nchan_transport, output_frame);

  /* Convert numeric range back */
  for (ch = 0; ch < nchan_out; ch++)
  {
    for (i = 0; i < output_frame; i++)
    {
      output[ch][i] = output[ch][i] * PCM16_TO_FLT_FAC;
    }
  }

  /* Mixing matrix determiner */
  num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands;
  ivas_spar_dec_gen_umx_mat(hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames);

  return;
}
#endif
+121 −1

File changed.

Preview size limit exceeded, changes collapsed.