Commit 6c7b1e3a authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

SBA, MCMASA and OMASA float code cleanup, Q-info updates for lib_com and lib_rend

parent 10b97f38
Loading
Loading
Loading
Loading
Loading
+293 −509
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include "options.h"
#include "cnst.h"
#include "prot.h"
#include "prot_fx.h"
#include "stat_enc.h"
#include "stat_dec.h"
#include "rom_com.h"
@@ -49,6 +50,7 @@
#include "wmc_auto.h"
#ifdef IVAS_FLOAT_FIXED
#include "ivas_prot_fx.h"
#include "prot_fx_enc.h"
#endif


@@ -422,277 +424,6 @@ ivas_error ind_list_realloc(
 *-----------------------------------------------------------------------*/

/*! r: maximum number of indices */
int16_t get_ivas_max_num_indices(
    const IVAS_FORMAT ivas_format, /* i  : IVAS format               */
    const int32_t ivas_total_brate /* i  : IVAS total bitrate        */
)
{
    if ( ivas_format == STEREO_FORMAT )
    {
        if ( ivas_total_brate <= IVAS_16k4 )
        {
            return 300;
        }
        else if ( ivas_total_brate <= IVAS_24k4 )
        {
            return 400;
        }
        else if ( ivas_total_brate <= IVAS_32k )
        {
            return 450;
        }
        else if ( ivas_total_brate <= IVAS_48k )
        {
            return 650;
        }
        else if ( ivas_total_brate <= IVAS_80k )
        {
            return 750;
        }
        else if ( ivas_total_brate <= IVAS_128k )
        {
            return 850;
        }
        else if ( ivas_total_brate <= IVAS_192k )
        {
            return 950;
        }
        else if ( ivas_total_brate <= IVAS_256k )
        {
            return 1350;
        }
        else
        {
            return 1650;
        }
    }
    else if ( ivas_format == ISM_FORMAT || ivas_format == MONO_FORMAT )
    {
        if ( ivas_total_brate <= IVAS_16k4 )
        {
            return 250;
        }
        else if ( ivas_total_brate <= IVAS_24k4 )
        {
            return 350;
        }
        else if ( ivas_total_brate <= IVAS_32k )
        {
            return 450;
        }
        else if ( ivas_total_brate <= IVAS_48k )
        {
            return 550;
        }
        else if ( ivas_total_brate <= IVAS_64k )
        {
            return 620;
        }
        else if ( ivas_total_brate <= IVAS_80k )
        {
            return 670;
        }
        else if ( ivas_total_brate <= IVAS_96k )
        {
            return 780;
        }
        else if ( ivas_total_brate <= IVAS_128k )
        {
            return 880;
        }
        else if ( ivas_total_brate <= IVAS_192k )
        {
            return 950;
        }
        else if ( ivas_total_brate <= IVAS_256k )
        {
            return 1100;
        }
        else if ( ivas_total_brate <= IVAS_384k )
        {
            return 1300;
        }
        else
        {
            return 1650;
        }
    }
    else if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT )
    {
        if ( ivas_total_brate <= IVAS_16k4 )
        {
            return 250;
        }
        else if ( ivas_total_brate <= IVAS_24k4 )
        {
            return 350;
        }
        else if ( ivas_total_brate <= IVAS_32k )
        {
            return 400;
        }
        else if ( ivas_total_brate <= IVAS_48k )
        {
            return 650;
        }
        else if ( ivas_total_brate <= IVAS_80k )
        {
            return 750;
        }
        else if ( ivas_total_brate <= IVAS_128k )
        {
            return 1020;
        }
        else if ( ivas_total_brate <= IVAS_160k )
        {
            return 1160;
        }
        else if ( ivas_total_brate <= IVAS_192k )
        {
            return 1220;
        }
        else if ( ivas_total_brate <= IVAS_256k )
        {
            return 1300;
        }
        else if ( ivas_total_brate <= IVAS_384k )
        {
            return 1720;
        }
        else
        {
            return 2000;
        }
    }
    else if ( ivas_format == MASA_FORMAT )
    {
        if ( ivas_total_brate <= IVAS_16k4 )
        {
            return 300;
        }
        else if ( ivas_total_brate <= IVAS_32k )
        {
            return 400;
        }
        else if ( ivas_total_brate <= IVAS_48k )
        {
            return 650;
        }
        else if ( ivas_total_brate <= IVAS_80k )
        {
            return 750;
        }
        else if ( ivas_total_brate <= IVAS_160k )
        {
            return 850;
        }
        else if ( ivas_total_brate <= IVAS_192k )
        {
            return 950;
        }
        else if ( ivas_total_brate <= IVAS_256k )
        {
            return 1150;
        }
        else if ( ivas_total_brate <= IVAS_384k )
        {
            return 1450;
        }
        else
        {
            return 1650;
        }
    }
    else if ( ivas_format == MASA_ISM_FORMAT )
    {
        if ( ivas_total_brate <= IVAS_16k4 )
        {
            return 300;
        }
        else if ( ivas_total_brate <= IVAS_32k )
        {
            return 400;
        }
        else if ( ivas_total_brate <= IVAS_48k )
        {
            return 650;
        }
        else if ( ivas_total_brate <= IVAS_80k )
        {
            return 750;
        }
        else if ( ivas_total_brate <= IVAS_160k )
        {
            return 1150;
        }
        else if ( ivas_total_brate <= IVAS_192k )
        {
            return 1250;
        }
        else if ( ivas_total_brate <= IVAS_256k )
        {
            return 1400;
        }
        else if ( ivas_total_brate <= IVAS_384k )
        {
            return 1650;
        }
        else
        {
            return 1850;
        }
    }
    else if ( ivas_format == MC_FORMAT )
    {
        if ( ivas_total_brate <= IVAS_16k4 )
        {
            return 250;
        }
        else if ( ivas_total_brate <= IVAS_24k4 )
        {
            return 350;
        }
        else if ( ivas_total_brate <= IVAS_32k )
        {
            return 400;
        }
        else if ( ivas_total_brate <= IVAS_48k )
        {
            return 650;
        }
        else if ( ivas_total_brate <= IVAS_64k )
        {
            return 750;
        }
        else if ( ivas_total_brate <= IVAS_80k )
        {
            return 850;
        }
        else if ( ivas_total_brate <= IVAS_128k )
        {
            return 1150;
        }
        else if ( ivas_total_brate <= IVAS_160k )
        {
            return 1420;
        }
        else if ( ivas_total_brate <= IVAS_256k )
        {
            return 2120;
        }
        else if ( ivas_total_brate <= IVAS_384k )
        {
            return 2250;
        }
        else
        {
            return 2450;
        }
    }

    return 2450;
}

Word16 get_ivas_max_num_indices_fx(
    const IVAS_FORMAT ivas_format, /* i  : IVAS format               */
    const Word32 ivas_total_brate  /* i  : IVAS total bitrate        */
@@ -912,269 +643,89 @@ Word16 get_ivas_max_num_indices_fx(
        }
        ELSE
        {
            return 1850;
        }
    }
    ELSE IF( EQ_16( ivas_format, MC_FORMAT ) )
    {
        IF( LE_32( ivas_total_brate, IVAS_16k4 ) )
        {
            return 250;
        }
        ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) )
        {
            return 350;
        }
        ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) )
        {
            return 400;
        }
        ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) )
        {
            return 650;
        }
        ELSE IF( LE_32( ivas_total_brate, IVAS_64k ) )
        {
            return 750;
        }
        ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) )
        {
            return 850;
        }
        ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) )
        {
            return 1150;
        }
        ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) )
        {
            return 1420;
        }
        ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) )
        {
            return 2120;
        }
        ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) )
        {
            return 2250;
        }
        ELSE
        {
            return 2450;
        }
    }

    return 2450;
}
/*-----------------------------------------------------------------------*
 * get_BWE_max_num_indices()
 *
 * Get the maximum number of indices in the BWE
 *-----------------------------------------------------------------------*/

/*! r: maximum number of indices */
int16_t get_BWE_max_num_indices(
    const int32_t extl_brate /* i  : extensiona layer bitrate  */
)
{
    /* set the maximum number of indices in the BWE */
    if ( extl_brate < SWB_BWE_16k )
    {
        return 30;
    }
    else
    {
        return 150;
    }
}


/*-----------------------------------------------------------------------*
 * get_ivas_max_num_indices_metadata()
 *
 * Set the maximum allowed number of metadata indices in the list
 *-----------------------------------------------------------------------*/

/*! r: maximum number of indices */
int16_t get_ivas_max_num_indices_metadata(
    const IVAS_FORMAT ivas_format, /* i  : IVAS format              */
    const int32_t ivas_total_brate /* i  : IVAS total bitrate       */
)
{
    /* set the maximum required number of metadata indices */
    if ( ivas_format == MONO_FORMAT )
    {
        return 0;
    }
    else if ( ivas_format == STEREO_FORMAT )
    {
        if ( ivas_total_brate <= IVAS_16k4 )
        {
            return 60;
        }
        else
        {
            return 80;
        }
    }
    else if ( ivas_format == ISM_FORMAT )
    {
        if ( ivas_total_brate <= IVAS_16k4 )
        {
            return 20;
        }
        else if ( ivas_total_brate <= IVAS_32k )
        {
            return 65;
        }
        else
        {
            return 80;
        }
    }
    else if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT )
    {
        if ( ivas_total_brate <= IVAS_16k4 )
        {
            return 100;
        }
        else if ( ivas_total_brate <= IVAS_24k4 )
        {
            return 200;
        }
        else if ( ivas_total_brate <= IVAS_32k )
        {
            return 300;
        }
        else if ( ivas_total_brate <= IVAS_192k )
        {
            return 500;
        }
        else if ( ivas_total_brate <= IVAS_256k )
        {
            return 1050;
        }
        else if ( ivas_total_brate <= IVAS_384k )
        {
            return 2000;
        }
        else
        {
            return 2500;
        }
    }
    else if ( ivas_format == MASA_FORMAT )
    {
        if ( ivas_total_brate <= IVAS_16k4 )
        {
            return 80;
        }
        else if ( ivas_total_brate <= IVAS_32k )
        {
            return 125;
        }
        else if ( ivas_total_brate <= IVAS_48k )
        {
            return 205;
        }
        else if ( ivas_total_brate <= IVAS_96k )
        {
            return 240;
        }
        else if ( ivas_total_brate <= IVAS_128k )
        {
            return 305;
        }
        else if ( ivas_total_brate <= IVAS_160k )
        {
            return 425;
        }
        else if ( ivas_total_brate <= IVAS_192k )
        {
            return 630;
        }
        else if ( ivas_total_brate <= IVAS_256k )
        {
            return 850;
        }
        else if ( ivas_total_brate <= IVAS_384k )
        {
            return 1000;
        }
        else
        {
            return 1750;
            return 1850;
        }
    }
    else if ( ivas_format == MASA_ISM_FORMAT )
    ELSE IF( EQ_16( ivas_format, MC_FORMAT ) )
    {
        if ( ivas_total_brate <= IVAS_16k4 )
        IF( LE_32( ivas_total_brate, IVAS_16k4 ) )
        {
            return 80;
            return 250;
        }
        else if ( ivas_total_brate <= IVAS_32k )
        ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) )
        {
            return 125 + 100;
            return 350;
        }
        else if ( ivas_total_brate <= IVAS_48k )
        ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) )
        {
            return 205 + 100;
            return 400;
        }
        else if ( ivas_total_brate <= IVAS_96k )
        ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) )
        {
            return 240 + 150;
            return 650;
        }
        else if ( ivas_total_brate <= IVAS_128k )
        ELSE IF( LE_32( ivas_total_brate, IVAS_64k ) )
        {
            return 305 + 30;
            return 750;
        }
        else if ( ivas_total_brate <= IVAS_160k )
        ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) )
        {
            return 425 + 30;
            return 850;
        }
        else if ( ivas_total_brate <= IVAS_192k )
        ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) )
        {
            return 630 + 30;
            return 1150;
        }
        else if ( ivas_total_brate <= IVAS_256k )
        ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) )
        {
            return 850 + 30;
            return 1420;
        }
        else if ( ivas_total_brate <= IVAS_384k )
        ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) )
        {
            return 1000 + 30;
            return 2120;
        }
        else
        ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) )
        {
            return 1750 + 30;
        }
            return 2250;
        }
    else if ( ivas_format == MC_FORMAT )
    {
        if ( ivas_total_brate <= IVAS_13k2 )
        ELSE
        {
            return 80;
            return 2450;
        }
        else if ( ivas_total_brate <= IVAS_24k4 )
        {
            return 100;
    }
        else if ( ivas_total_brate <= IVAS_64k )
        {
            return 210;

    return 2450;
}
        else if ( ivas_total_brate <= IVAS_96k )
/*-----------------------------------------------------------------------*
 * get_BWE_max_num_indices()
 *
 * Get the maximum number of indices in the BWE
 *-----------------------------------------------------------------------*/

/*! r: maximum number of indices */
int16_t get_BWE_max_num_indices(
    const int32_t extl_brate /* i  : extensiona layer bitrate  */
)
{
            return 220;
    /* set the maximum number of indices in the BWE */
    if ( extl_brate < SWB_BWE_16k )
    {
        return 30;
    }
    else
    {
            return 300;
        return 150;
    }
}

    return 50;
}

/*-----------------------------------------------------------------------*
 * get_ivas_max_num_indices_metadata()
 *
 * Set the maximum allowed number of metadata indices in the list
 *-----------------------------------------------------------------------*/

/*! r: maximum number of indices */
Word16 get_ivas_max_num_indices_metadata_fx(
    const IVAS_FORMAT ivas_format, /* i  : IVAS format              */
    const Word32 ivas_total_brate  /* i  : IVAS total bitrate       */
@@ -2244,7 +1795,52 @@ void reset_indices_dec(
 *
 * writing forward or backward to a serial stream
 *-------------------------------------------------------------------*/
#ifdef IVAS_FLOAT_FIXED
static Word16 write_indices_to_stream_fx(
    Indice *ind_list,
    UWord16 **pt_stream,
    const Word16 inc,
    const Word16 num_indices )
{
    Word16 i, k;
    Word16 value, nb_bits;
    UWord16 mask;

    FOR( i = 0; i < num_indices; i++ )
    {
        value = ind_list[i].value;
        nb_bits = ind_list[i].nb_bits;
        move16();
        move16();

        IF( nb_bits > 0 )
        {
            /* mask from MSB to LSB */
            mask = (UWord16) L_shl( 1, sub( nb_bits, 1 ) );

            /* write bit by bit */
            FOR( k = 0; k < nb_bits; k++ )
            {
                IF( L_and( value, mask ) )
                {
                    **pt_stream = 1;
                    move16();
                    *pt_stream += inc;
                }
                ELSE
                {
                    **pt_stream = 0;
                    move16();
                    *pt_stream += inc;
                }

                mask = (UWord16) L_shr( mask, 1 );
            }
        }
    }
    return 0;
}
#else
static int16_t write_indices_to_stream(
    Indice *ind_list,
    uint16_t **pt_stream,
@@ -2285,13 +1881,158 @@ static int16_t write_indices_to_stream(
    }
    return 0;
}
#endif

/*-------------------------------------------------------------------*
 * write_indices_element()
 *
 * Bitstream writing function of one element (one SCE or one CPE)
 *-------------------------------------------------------------------*/
#ifdef IVAS_FLOAT_FIXED
static ivas_error write_indices_element_fx(
    Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure                                          */
    UWord16 **pt_stream,     /* i  : pointer to bitstream buffer                                     */
    const Word16 is_SCE,     /* i  : flag to distingusih SCE and CPE                                 */
    const Word16 element_id  /* i  : id of the SCE or CPE                                            */
)
{
    Word16 ch;
    Encoder_State **sts = NULL;
    UWord16 *pt_stream_loc;
    UWord16 *pt_stream_backup;
    UWord16 *pt_stream_end;
    Word16 nb_bits_tot_metadata;
    Word16 nb_ind_tot_metadata;

    Indice *ind_list_metadata;
    Word16 n, n_channels;
    ivas_error error;

    error = IVAS_ERR_OK;
    move32();

    ind_list_metadata = NULL;
    nb_ind_tot_metadata = 0;
    move16();

    IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) )
    {
        sts = st_ivas->hSCE[0]->hCoreCoder;
        nb_bits_tot_metadata = 0;
        move16();
    }
    ELSE
    {
        nb_bits_tot_metadata = 0;
        move16();
        test();
        test();
        IF( is_SCE && st_ivas->hSCE[element_id] != NULL )
        {
            sts = st_ivas->hSCE[element_id]->hCoreCoder;

            IF( st_ivas->hSCE[element_id]->hMetaData != NULL )
            {
                nb_bits_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_bits_tot;
                ind_list_metadata = st_ivas->hSCE[element_id]->hMetaData->ind_list;
                nb_ind_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot;
                move16();
                move16();
            }
        }
        ELSE IF( !is_SCE && st_ivas->hCPE[element_id] != NULL )
        {
            sts = st_ivas->hCPE[element_id]->hCoreCoder;

            IF( st_ivas->hCPE[element_id]->hMetaData != NULL )
            {
                nb_bits_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_bits_tot;
                ind_list_metadata = st_ivas->hCPE[element_id]->hMetaData->ind_list;
                nb_ind_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot;
                move16();
                move16();
            }
        }
    }

    n_channels = 1;
    move16();
    if ( GT_16( sts[0]->element_mode, IVAS_CPE_DFT ) )
    {
        n_channels = CPE_CHANNELS;
        move16();
    }

    /*----------------------------------------------------------------*
     * Bitstream packing (conversion of individual indices into a serial stream)
     *----------------------------------------------------------------*/

    pt_stream_loc = *pt_stream;
    pt_stream_end = pt_stream_loc;

    FOR( n = 0; n < n_channels; n++ )
    {
        /* write the metadata buffer */
        test();
        IF( n == 0 && nb_bits_tot_metadata != 0 )
        {
            pt_stream_backup = pt_stream_loc;

            FOR( ch = 0; ch < n_channels; ch++ )
            {
                pt_stream_loc += sts[ch]->hBstr->nb_bits_tot;
            }
            pt_stream_loc += nb_bits_tot_metadata - 1;
            pt_stream_end = pt_stream_loc + 1;

            write_indices_to_stream_fx( ind_list_metadata, &pt_stream_loc, -1,
                                        nb_ind_tot_metadata );

            /* restore previous pointer position */
            pt_stream_loc = pt_stream_backup;
        }
        write_indices_to_stream_fx( sts[n]->hBstr->ind_list, &pt_stream_loc, 1,
                                    sts[n]->hBstr->nb_ind_tot );

        if ( pt_stream_loc > pt_stream_end )
        {
            pt_stream_end = pt_stream_loc;
        }
    }

    /*----------------------------------------------------------------*
     * Clearing of indices
     * Reset index pointers
     *----------------------------------------------------------------*/

    IF( is_SCE ) /* EVS and SCE */
    {
        IF( st_ivas->hSCE[element_id]->hMetaData != NULL )
        {
            reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot );
        }

        reset_indices_enc( sts[0]->hBstr, sts[0]->hBstr->nb_ind_tot );
    }
    ELSE
    {
        IF( st_ivas->hCPE[element_id]->hMetaData != NULL )
        {
            reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot );
        }

        FOR( n = 0; n < n_channels; n++ )
        {
            reset_indices_enc( sts[n]->hBstr, sts[n]->hBstr->nb_ind_tot );
        }
    }

    /* update pointer */
    *pt_stream = pt_stream_end;

    return error;
}
#else
static ivas_error write_indices_element(
    Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure                                          */
    uint16_t **pt_stream,    /* i  : pointer to bitstream buffer                                     */
@@ -2422,6 +2163,7 @@ static ivas_error write_indices_element(

    return error;
}
#endif

/*-------------------------------------------------------------------*
 * write_indices_ivas()
@@ -2429,7 +2171,48 @@ static ivas_error write_indices_element(
 * Write the buffer of indices to a serial bitstream buffer,
 * each bit represented as a uint16_t of value 0 or 1
 *-------------------------------------------------------------------*/
#ifdef IVAS_FLOAT_FIXED
ivas_error write_indices_ivas_fx(
    Encoder_Struct *st_ivas, /* i/o: encoder state structure             */
    UWord16 *bit_stream,     /* i/o: output bitstream                    */
    UWord16 *num_bits        /* i  : number of indices written to output */
)
{
    Word16 i, n;
    UWord16 *pt_stream;
    ivas_error error;

    error = IVAS_ERR_OK;
    move32();

    pt_stream = bit_stream;
    FOR( i = 0; i < MAX_BITS_PER_FRAME; ++i )
    {
        bit_stream[i] = 0;
        move16();
    }


    /*-----------------------------------------------------------------*
     * Encode Payload
     *-----------------------------------------------------------------*/

    FOR( n = 0; n < st_ivas->nSCE; n++ )
    {
        write_indices_element_fx( st_ivas, &pt_stream, 1, n );
    }

    FOR( n = 0; n < st_ivas->nCPE; n++ )
    {
        write_indices_element_fx( st_ivas, &pt_stream, 0, n );
    }

    *num_bits = (UWord16) ( pt_stream - bit_stream );
    move16();

    return error;
}
#else
ivas_error write_indices_ivas(
    Encoder_Struct *st_ivas, /* i/o: encoder state structure             */
    uint16_t *bit_stream,    /* i/o: output bitstream                    */
@@ -2467,6 +2250,7 @@ ivas_error write_indices_ivas(

    return error;
}
#endif

#ifndef IVAS_FLOAT_FIXED
/*---------------------------------------------------------------------*
+2 −2
Original line number Diff line number Diff line
@@ -1088,7 +1088,7 @@ static void decoder_selectCodec(
}


void dec_prm_core( Decoder_State *st )
static void dec_prm_core( Decoder_State *st )
{
    Word16 n, frame_size_index, num_bits;
    UWord16 lsb;
@@ -1178,7 +1178,7 @@ void dec_prm_core( Decoder_State *st )
 * Set st->core, and st->bwidth if signalled together with the core.
 *-----------------------------------------------------------------*/

void decision_matrix_core_dec(
static void decision_matrix_core_dec(
    Decoder_State *st /* i/o: decoder state structure                   */
)
{
+22 −22

File changed.

Preview size limit exceeded, changes collapsed.

+52 −46

File changed.

Preview size limit exceeded, changes collapsed.

+79 −79

File changed.

Preview size limit exceeded, changes collapsed.

Loading