Commit e4eea225 authored by vaclav's avatar vaclav
Browse files

fix

parent 19bb5749
Loading
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -4948,20 +4948,10 @@ void ivas_masa_estimate_energy(
    const int16_t nchan_transport                               /* i  : number of MASA input/transport channels         */
);

#ifdef MEM_ALLOC_APP
ivas_error ivas_masa_enc_config_memory(
#else
ivas_error ivas_masa_enc_config(
#endif
    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                                  */
+0 −8
Original line number Diff line number Diff line
@@ -228,14 +228,10 @@ 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 */

#ifdef MEM_ALLOC_APP
            ivas_masa_enc_init( st_ivas );
#else
            if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK )
            {
                return error;
            }
#endif

            if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1,
                                             ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK )
@@ -297,14 +293,10 @@ ivas_error ivas_enc(
        /* Estimate TF-tile energy for the input MASA stream */
        ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport );

#ifdef MEM_ALLOC_APP
        ivas_masa_enc_init( st_ivas );
#else
        if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK )
        {
            return error;
        }
#endif

        set_s( nb_bits_metadata, 0, MAX_SCE + 1 );
        idx_separated_object = 0;
+2 −2
Original line number Diff line number Diff line
@@ -1270,8 +1270,8 @@ ivas_error ivas_reconfig_enc(
    }
    else if ( ivas_format == MASA_FORMAT )
    {
        /* reconfigure the MASA format encoder */
        error = ivas_masa_enc_config_memory( st_ivas );
        /* no reallocation is needed */
        return IVAS_ERR_OK;
    }
    else if ( ivas_format == SBA_ISM_FORMAT )
    {
+2 −206
Original line number Diff line number Diff line
@@ -702,31 +702,17 @@ void ivas_masa_estimate_energy(
}


#ifdef MEM_ALLOC_APP
/*-----------------------------------------------------------------------*
 * ivas_masa_enc_config_memory()
 *
 * Frame-by-frame configuration of MASA encoder memory
 *-----------------------------------------------------------------------*/
#else
/*-----------------------------------------------------------------------*
 * ivas_masa_enc_config()
 *
 * Frame-by-frame configuration of MASA encoder
 *-----------------------------------------------------------------------*/
#endif

#ifdef MEM_ALLOC_APP
ivas_error ivas_masa_enc_config_memory(
#else
ivas_error ivas_masa_enc_config(
#endif
    Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
)
{
#ifndef MEM_ALLOC_APP
    int16_t i;
#endif
    MASA_ENCODER_HANDLE hMasa;
    IVAS_QMETADATA_HANDLE hQMetaData;
    IVAS_FORMAT ivas_format;
@@ -734,15 +720,11 @@ 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;
#ifndef MEM_ALLOC_APP
    int32_t ism_total_brate;
    int32_t masa_total_brate;
#endif

    error = IVAS_ERR_OK;
    hMasa = st_ivas->hMasa;
@@ -750,7 +732,6 @@ ivas_error ivas_masa_enc_config(
    ivas_format = st_ivas->hEncoderConfig->ivas_format;
    ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate;

#ifndef MEM_ALLOC_APP
    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 ) )
    {
@@ -761,7 +742,7 @@ ivas_error ivas_masa_enc_config(
    }

    ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, ivas_format, st_ivas->ism_mode, ism_total_brate );
#endif

    hQMetaData->is_masa_ivas_format = 1;

    if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT )
@@ -798,7 +779,6 @@ ivas_error ivas_masa_enc_config(
        ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) );
    }

#ifndef MEM_ALLOC_APP
    /* Setup importance weights for two-direction band selection. */
    if ( hMasa->config.numberOfDirections == 2 )
    {
@@ -846,7 +826,6 @@ ivas_error ivas_masa_enc_config(
    {
        set_c( (int8_t *) hMasa->data.twoDirBands, 0, hMasa->config.numCodingBands );
    }
#endif

    /* Set qmeta to correct values */
    if ( ( error = ivas_qmetadata_allocate_memory( hQMetaData, hMasa->config.numCodingBands, hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands != 0 ? 2 : 1, hMasa->config.useCoherence ) ) != IVAS_ERR_OK )
@@ -854,7 +833,6 @@ 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;
@@ -945,192 +923,10 @@ 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;
        }
    }

    ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, ivas_format, st_ivas->ism_mode, ism_total_brate );

    /* Setup importance weights for two-direction band selection. */
    if ( hMasa->config.numberOfDirections == 2 )
    {
        set_f( hMasa->data.importanceWeight, 1.0f, hMasa->config.numCodingBands );

        if ( hMasa->config.numCodingBands == 5 )
        {
            hMasa->data.importanceWeight[4] = 0.7f;
        }
        else if ( hMasa->config.numCodingBands == 8 )
        {
            hMasa->data.importanceWeight[7] = 0.7f;
        }
        else if ( hMasa->config.numCodingBands == 10 )
        {
            hMasa->data.importanceWeight[8] = 0.7f;
            hMasa->data.importanceWeight[9] = 0.1f;
        }
        else if ( hMasa->config.numCodingBands == 12 )
        {
            hMasa->data.importanceWeight[10] = 0.7f;
            hMasa->data.importanceWeight[11] = 0.1f;
        }
        else if ( hMasa->config.numCodingBands == 18 )
        {
            hMasa->data.importanceWeight[14] = 0.8f;
            hMasa->data.importanceWeight[15] = 0.5f;
            hMasa->data.importanceWeight[16] = 0.2f;
            hMasa->data.importanceWeight[17] = 0.0f;
        }
        else if ( hMasa->config.numCodingBands == 24 )
        {
            hMasa->data.importanceWeight[20] = 0.8f;
            hMasa->data.importanceWeight[21] = 0.5f;
            hMasa->data.importanceWeight[22] = 0.2f;
            hMasa->data.importanceWeight[23] = 0.0f;
        }

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

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

    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 )
        {
            hQMetaData->q_direction->cfg.inactiveBands = MASA_MAXIMUM_CODING_SUBBANDS - maxBand;
        }
        else
        {
            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 || hMasa->data.hOmasaData->omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX )
        {
            hMasa->data.hOmasaData->lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise;
        }
        else
        {
            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;
    return error;
}

#endif

/*-----------------------------------------------------------------------*
 * ivas_masa_surrcoh_signicant()
+0 −8
Original line number Diff line number Diff line
@@ -128,19 +128,11 @@ ivas_error ivas_mcmasa_enc_open(
    }

    /* With McMASA, we config MASA encoder only in init as we know the input and there are no frame-by-frame changes currently. */
#ifdef MEM_ALLOC_APP
    if ( ( error = ivas_masa_enc_config_memory( st_ivas ) ) != IVAS_ERR_OK )
#else
    if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK )
#endif
    {
        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;
    hMcMasa->nCodingBands = st_ivas->hMasa->config.numCodingBands;
Loading