Commit 25af05fb authored by vaclav's avatar vaclav
Browse files

fix MSAN error in MASA

parent 28e36268
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -5053,6 +5053,12 @@ ivas_error ivas_masa_enc_config(
    Encoder_Struct* st_ivas                                     /* i/o: IVAS encoder structure                          */
);

#ifdef MEM_ALLOC_APP
void ivas_masa_enc_init(
    Encoder_Struct* st_ivas                                     /* i/o: IVAS encoder structure                          */
);
#endif

void ivas_masa_set_elements(
    const int32_t ivas_total_brate,                             /* i  : codec total bitrate                             */
    const int16_t mc_mode,                                      /* i  : MC format mode                                  */
+3 −1
Original line number Diff line number Diff line
@@ -253,7 +253,9 @@ ivas_error ivas_enc(
        {
            ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */

#ifndef MEM_ALLOC_APP
#ifdef MEM_ALLOC_APP
            ivas_masa_enc_init( st_ivas );
#else
            if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK )
            {
                return error;
+137 −2
Original line number Diff line number Diff line
@@ -677,14 +677,17 @@ ivas_error ivas_masa_enc_config(
    uint8_t coherencePresent;
    uint8_t isActualTwoDir; /* Flag to tell that when there are two directions present in metadata, they both contain meaningful information. */
    int32_t ivas_total_brate;
#ifndef MEM_ALLOC_APP
    uint8_t maxBand;
    int16_t maxBin, sf;
#endif
    ivas_error error;
    int32_t ism_total_brate;
#ifndef MEM_ALLOC_APP
    int32_t masa_total_brate;
#endif

    error = IVAS_ERR_OK;

    hMasa = st_ivas->hMasa;
    hQMetaData = st_ivas->hQMetaData;
    ivas_format = st_ivas->hEncoderConfig->ivas_format;
@@ -791,6 +794,7 @@ ivas_error ivas_masa_enc_config(
        return error;
    }

#ifndef MEM_ALLOC_APP
    for ( i = 0; i < hQMetaData->no_directions; i++ )
    {
        hQMetaData->q_direction[i].cfg.nbands = hMasa->config.numCodingBands;
@@ -881,10 +885,141 @@ ivas_error ivas_masa_enc_config(
            st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS;
        }
    }

#endif
    return error;
}

#ifdef MEM_ALLOC_APP

/*-----------------------------------------------------------------------*
 * ivas_masa_enc_init()
 *
 * Frame-by-frame configuration of MASA encoder
 *-----------------------------------------------------------------------*/

void ivas_masa_enc_init(
    Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
)
{
    int16_t i;
    MASA_ENCODER_HANDLE hMasa;
    IVAS_QMETADATA_HANDLE hQMetaData;
    IVAS_FORMAT ivas_format;
    int32_t ivas_total_brate;
    uint8_t maxBand;
    int16_t maxBin, sf;
    int32_t ism_total_brate;
    int32_t masa_total_brate;

    hMasa = st_ivas->hMasa;
    hQMetaData = st_ivas->hQMetaData;
    ivas_format = st_ivas->hEncoderConfig->ivas_format;
    ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate;

    ism_total_brate = 0;
    if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) )
    {
        for ( i = 0; i < st_ivas->nSCE; i++ )
        {
            ism_total_brate += st_ivas->hSCE[i]->element_brate;
        }
    }

    for ( i = 0; i < hQMetaData->no_directions; i++ )
    {
        hQMetaData->q_direction[i].cfg.nbands = hMasa->config.numCodingBands;
        hQMetaData->q_direction[i].cfg.nblocks = hMasa->config.joinedSubframes == TRUE ? 1 : 4;

        if ( ivas_format == MC_FORMAT )
        {
            hQMetaData->q_direction[i].cfg.mc_ls_setup = st_ivas->hEncoderConfig->mc_input_setup;
        }
        else
        {
            /* Just to be sure that this default value is maintained */
            hQMetaData->q_direction[i].cfg.mc_ls_setup = MC_LS_SETUP_INVALID;
        }
    }

    hQMetaData->all_coherence_zero = !hMasa->config.coherencePresent;

    ivas_set_qmetadata_maxbit_req( hQMetaData, ivas_format );

    /* Find maximum band usable */
    maxBin = (int16_t) ( st_ivas->hEncoderConfig->input_Fs * INV_CLDFB_BANDWIDTH );
    maxBand = 0;
    while ( maxBand <= MASA_FREQUENCY_BANDS && MASA_band_grouping_24[maxBand] <= maxBin )
    {
        maxBand++;
    }
    maxBand--;

    st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0;
    masa_total_brate = ivas_total_brate;
    if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC )
    {
        masa_total_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism );
    }
    if ( masa_total_brate >= IVAS_384k && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) )
    {
        int16_t continueLoop;
        continueLoop = 1;
        while ( maxBand > 5 && continueLoop )
        {
            for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
            {
                if ( hMasa->data.energy[sf][maxBand - 1] > 100000 )
                {
                    continueLoop = 0;
                    break;
                }
            }
            if ( continueLoop )
            {
                maxBand--;
            }
        }

        if ( maxBand < MASA_MAXIMUM_CODING_SUBBANDS )
        {
            st_ivas->hQMetaData->q_direction->cfg.inactiveBands = MASA_MAXIMUM_CODING_SUBBANDS - maxBand;
        }
        else
        {
            st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0;
        }
    }

    masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL );

    if ( hMasa->config.numTwoDirBands >= hMasa->config.numCodingBands )
    {
        hMasa->config.numTwoDirBands = hMasa->config.numCodingBands;
        set_c( (int8_t *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands );
    }

    /* Transmit stereo signals using a mono downmix at lowest bitrates */
    if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && st_ivas->nCPE == 1 && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL )
    {
        st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ( ivas_total_brate - ism_total_brate < MASA_STEREO_MIN_BITRATE ) ? 1 : 0;
    }

    if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) )
    {
        if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX )
        {
            st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise;
        }
        else
        {
            st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS;
        }
    }

    return;
}

#endif

/*-----------------------------------------------------------------------*
 * ivas_masa_surrcoh_signicant()
+3 −0
Original line number Diff line number Diff line
@@ -133,6 +133,9 @@ ivas_error ivas_mcmasa_enc_open(
        return error;
    }

#ifdef MEM_ALLOC_APP
    ivas_masa_enc_init( st_ivas );
#endif

    /* Determine the number of bands */
    hMcMasa->nbands = st_ivas->hMasa->config.numCodingBands;
+4 −0
Original line number Diff line number Diff line
@@ -301,6 +301,10 @@ ivas_error ivas_omasa_enc_config(
        return error;
    }

#ifdef MEM_ALLOC_APP
    ivas_masa_enc_init( st_ivas );
#endif

    if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC )
    {
        /* Configure oMASA analysis based on MASA config */