Commit b6ef6a13 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Added BASOPs changes in ivas_stereo_adapt_GR_dec

parent ef6d8916
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1605,6 +1605,7 @@ int16_t write_bitstream_GR(
    const int16_t GR_ord                                        /* i  : GR order to be used                 */
);

#ifndef IVAS_FLOAT_FIXED
/*! r: number of bits read */
int16_t read_flag_EC_DFT(
    const uint16_t *bit_stream,                                 /* i  : bitstream                           */
@@ -1651,6 +1652,7 @@ int16_t read_BS_adapt_GR_sg(
    int16_t *GR_ord,                                            /* o  : GR order to be used                 */
    const int16_t *map0                                         /* i  : mapping array for side gains        */
);
#endif

void stereo_dft_hybrid_ITD_flag(
    STEREO_DFT_CONFIG_DATA_HANDLE hConfig,                      /* o  : DFT stereo configuration                */
@@ -3016,12 +3018,14 @@ int16_t write_GR0(
    const int16_t len                                           /* i  : input data length                       */
);

#ifndef IVAS_FLOAT_FIXED
/*! r: number of bits read */
int16_t read_GR0(
    const uint16_t *bit_stream,                                 /* i  : bitstream to be read                    */
    int16_t *ind,                                               /* o  : parameters read                         */
    const int16_t len                                           /* i  : number of params to be read             */
);
#endif


/*----------------------------------------------------------------------------------*
+70 −18
Original line number Diff line number Diff line
@@ -54,14 +54,12 @@ void ivas_dct_windowing_fx(
    const Word16 frame_len,
    Word32 *pOut_buf,
    Word32 *pBuffer_prev,
    Word32 *pTemp_lfe
);
    Word32 *pTemp_lfe );

void ivas_get_twid_factors_fx1(
    const Word16 length,
    const Word16 **pTwid_re,
    const Word16 **pTwid_im
);
    const Word16 **pTwid_im );

Word32 ivas_get_mdct_scaling_gain_fx(
    const Word16 dct_len_by_2 );
@@ -70,15 +68,13 @@ void ivas_imdct_fx(
    const Word32 *pIn,
    Word32 *pOut,
    const Word16 length,
    Word16 *q_out
);
    Word16 *q_out );

void ivas_mdct_fx(
    const Word32 *pIn,
    Word32 *pOut,
    const Word16 length,
    Word16 *q_out
);
    Word16 *q_out );

void ivas_itda_fx(
    const Word32 *re,   /* i  : time alised signal after IDCT       */
@@ -246,8 +242,7 @@ void stereo_dft_dec_analyze_fx(
    const Word16 k_offset,                               /* i  : offset of DFT                       */
    const Word16 delay,                                  /* i  : delay in samples for input signal   */
    Word16 *q,
    Word16 *q_out_DFT 
);
    Word16 *q_out_DFT );

void filter_with_allpass_fx(
    const Word32 *sig,  /* i  : allpass input signal                */
@@ -315,4 +310,61 @@ void ivas_jbm_dec_get_adapted_subframes_fx(
    Word16 *subframe_nbslots,                                  /* i/o: subframe grid                                               */
    Word16 *nb_subframes                                       /* i/o: number of subframes in the frame                            */
);

#ifdef IVAS_FLOAT_FIXED
/*! r: number of bits read */
Word16 read_GR0(
    const UWord16 *bit_stream, /* i  : bitstream to be read        */
    Word16 *ind,               /* o  : parameters read             */
    const Word16 len           /* i  : number of params to be read */
);

/*! r: read value */
Word16 get_value(
    const UWord16 *bit_stream, /* i  : bitstream                 */
    const Word16 nbits         /* i  : number of bits to be read */
);

/*! r: number of bits read */
Word16 read_BS_GR(
    const UWord16 *bit_stream, /* i  : bitstream to be read         */
    const Word16 nb,           /* i  : starting point in bitstream  */
    Word16 *ind1,              /* o  : data array read              */
    const Word16 len,          /* i  : number of params to be read  */
    Word16 *GR_ord             /* o  : GR order to be used          */
);

/*! r: number of bits read */
Word16 read_BS_adapt_GR_sg(
    const UWord16 *bit_stream, /* i  : bitstream to be read               */
    const Word16 nb,           /* i  : starting position in bitstream     */
    Word16 *ind1,              /* o  : decoded side gain values           */
    const Word16 len,          /* i  : number of params to be read        */
    Word16 *GR_ord,            /* o  : GR order used (read from bitstream)*/
    const Word16 *map0         /* i  : initial map                        */
);

/*! r: number of bits read */
Word16 read_itd(
    Decoder_State *st, /* i  : Decoder state         */
    Word16 *pI         /* o  : ITD value             */
);

/*! r: number of bits read */
Word16 read_BS_adapt_GR_rpg(
    const UWord16 *bit_stream, /* i  : bitstream to be read         */
    const Word16 nb,           /* i  : starting point in bitstream  */
    Word16 *ind1_pred,         /* o  : decoded res pred gains       */
    const Word16 start,        /* i  : starting subband             */
    const Word16 total_no,     /* i  : number of params to be read  */
    Word16 *GR_ord             /* o  : GR order - read              */
);

/*! r: number of bits read */
Word16 read_flag_EC_DFT(
    const UWord16 *bit_stream, /* i  : bitstream            */
    Word16 *flag               /* o  : flag value           */
);
#endif

#endif
 No newline at end of file
+463 −0
Original line number Diff line number Diff line
@@ -37,8 +37,469 @@
#include "ivas_prot.h"
#include "ivas_rom_com.h"
#include "rom_dec.h"
#ifdef IVAS_FLOAT_FIXED
#include "ivas_prot_fx.h"
#endif

#ifdef IVAS_FLOAT_FIXED
/*---------------------------------------------------------------------*
 * read_GR2()
 *
 * reading a bitstream of data encoded with GR of order 2
 *---------------------------------------------------------------------*/

/*! r: number of bits read */
static Word16 read_GR2(
    const UWord16 *bit_stream, /* i  : bitstream to be read        */
    Word16 *ind,               /* o  : parameters read             */
    const Word16 len           /* i  : number of params to be read */
)
{
    Word16 i;
    UWord16 nb, ready, temp, b;
    const UWord16 *p;

    p = bit_stream;
    nb = 0;

    FOR( i = 0; i < len; i++ )
    {
        ready = 0;
        temp = 0;
        DO
        {
            b = *p++;
            IF( EQ_16( (Word16) b, 0 ) )
            {
                ready = 1;
            }
            ELSE
            {
                temp = add( (Word16) temp, 1 );
            }
        }
        WHILE( EQ_16( (Word16) ready, 0 ) );
        b = *p++;
        b = (UWord16) add( shl( (Word16) b, 1 ), (Word16) *p++ );
        ind[i] = add( shl( (Word16) temp, 2 ), (Word16) b );
        nb = (UWord16) add( (Word16) nb, add( (Word16) temp, 3 ) );
    }

    return nb;
}


/*---------------------------------------------------------------------*
 * read_GR1()
 *
 * reading a bitstream of data encoded with GR of order 1
 *---------------------------------------------------------------------*/

/*! r: number of bits read */
static Word16 read_GR1(
    const UWord16 *bit_stream, /* i  : bitstream to be read        */
    Word16 *ind,               /* o  : parameters read             */
    const Word16 len           /* i  : number of params to be read */
)
{
    Word16 i;
    UWord16 nb, ready, temp, b;
    const UWord16 *p;

    p = bit_stream;
    nb = 0;

    FOR( i = 0; i < len; i++ )
    {
        ready = 0;
        temp = 0;
        DO
        {
            b = *p++;
            IF( EQ_16( (Word16) b, 0 ) )
            {
                ready = 1;
            }
            ELSE
            {
                temp = add( (Word16) temp, 1 );
            }
        }
        WHILE( EQ_16( (Word16) ready, 0 ) );

        b = *p++;
        ind[i] = add( shl( (Word16) temp, 1 ), (Word16) b );
        nb = (UWord16) add( (Word16) nb, add( (Word16) temp, 2 ) );
    }

    return nb;
}


/*---------------------------------------------------------------------*
 * read_GR0()
 *
 *  reading a bitstream of data encoded with GR of order 0
 *---------------------------------------------------------------------*/

/*! r: number of bits read */
Word16 read_GR0(
    const UWord16 *bit_stream, /* i  : bitstream to be read        */
    Word16 *ind,               /* o  : parameters read             */
    const Word16 len           /* i  : number of params to be read */
)
{
    Word16 i;
    UWord16 nb, ready, b, temp;
    const UWord16 *p;

    p = bit_stream;
    nb = 0;

    FOR( i = 0; i < len; i++ )
    {
        ready = 0;
        temp = 0;
        DO
        {
            b = *p++;
            IF( EQ_16( (Word16) b, 0 ) )
            {
                ready = 1;
            }
            ELSE
            {
                temp = add( (Word16) temp, 1 );
            }
        }
        WHILE( EQ_16( (Word16) ready, 0 ) );
        ind[i] = temp;
        nb = (UWord16) add( (Word16) nb, add( (Word16) temp, 1 ) );
    }

    return nb;
}


/*---------------------------------------------------------------------*
 * find_map()
 *
 * find the position of the value 'val' in the array 'map'
 *---------------------------------------------------------------------*/

/*! r: index in array */
static ivas_error find_map(
    Word16 *map_idx,
    const Word16 *map, /* i  : array to look into             */
    const Word16 val,  /* i  : value to look for              */
    const Word16 len   /* i  : length of array                */
)
{
    *map_idx = 0;

    WHILE( ( NE_16( map[*map_idx], val ) ) && ( NE_16( *map_idx, len ) ) )
    {
        ( *map_idx )++;
    }


    return IVAS_ERR_OK;
}


/*---------------------------------------------------------------------*
 * decode_adapt_GR_indices1()
 *
 * decodes input array using the adaptive GR procedure
 *---------------------------------------------------------------------*/

static void decode_adapt_GR_indices1(
    const Word16 *ind,    /* i  : array of input encoded symbols            */
    const Word16 len,     /* i  : number of parameters to decode            */
    const Word16 no_symb, /* i  : number of possible symbols in GR coding   */
    Word16 *out,          /* o  : array of decoded parameters               */
    const Word16 *map0    /* i  : initial mapping array for the adaptive GR */
)
{
    const Word16 *map;
    Word16 map_symb, i;

    IF( EQ_16( no_symb, NO_SYMB_GR_SIDE_G ) )
    {
        map = &map0[15 * no_symb];
    }
    ELSE
    {
        map = &( map0[8 * no_symb] );
    }

    FOR( i = 0; i < len; i++ )
    {
        map_symb = ind[i];
        find_map( out + i, map, map_symb, no_symb );
        map = &( map0[out[i] * no_symb] );
    }

    return;
}


/*---------------------------------------------------------------------*
 * get_value()
 *
 * reads a value on 'nbits' from a bitstream
 *---------------------------------------------------------------------*/

/*! r: read value */
Word16 get_value(
    const UWord16 *bit_stream, /* i  : bitstream                 */
    const Word16 nbits         /* i  : number of bits to be read */
)
{
    Word16 i;
    UWord16 mask = 0, val = 0;

    FOR( i = nbits - 1; i >= 0; i-- )
    {
        val = (UWord16) add( (Word16) val, shl( bit_stream[i], mask ) );
        mask = add( mask, 1 );
    }

    return val;
}


/*---------------------------------------------------------------------*
 * read_BS_GR()
 *
 * decode simple GR code from a bitstream
 *---------------------------------------------------------------------*/

/*! r: number of bits read */
Word16 read_BS_GR(
    const UWord16 *bit_stream, /* i  : bitstream to be read         */
    const Word16 nb,           /* i  : starting point in bitstream  */
    Word16 *ind1,              /* o  : data array read              */
    const Word16 len,          /* i  : number of params to be read  */
    Word16 *GR_ord             /* o  : GR order to be used          */
)
{
    Word16 b, ind1_tmp[STEREO_DFT_BAND_MAX], tmp, i;

    *GR_ord = bit_stream[nb];
    b = 1;

    IF( EQ_16( *GR_ord, 0 ) )
    {
        b = add( b, read_GR0( &bit_stream[nb + b], ind1_tmp, len ) );
    }
    ELSE
    {
        b = add( b, read_GR1( &bit_stream[nb + b], ind1_tmp, len ) );
    }

    FOR( i = 0; i < len; i++ )
    {
        tmp = add( ind1_tmp[i], 1 );
        IF( tmp & 1 ) /* if odd number */
        {
            ind1[i] = negate( shr( ind1_tmp[i], 1 ) );
        }
        ELSE
        {
            ind1[i] = shr( tmp, 1 );
        }
    }

    return b;
}


/*---------------------------------------------------------------------*
 * read_BS_adapt_GR_sg()
 *
 * read and decode with adaptive GR the bitstream containing side gains values
 *---------------------------------------------------------------------*/

/*! r: number of bits read */
Word16 read_BS_adapt_GR_sg(
    const UWord16 *bit_stream, /* i  : bitstream to be read               */
    const Word16 nb,           /* i  : starting position in bitstream     */
    Word16 *ind1,              /* o  : decoded side gain values           */
    const Word16 len,          /* i  : number of params to be read        */
    Word16 *GR_ord,            /* o  : GR order used (read from bitstream)*/
    const Word16 *map0         /* i  : initial map                        */
)
{
    Word16 b, ind1_tmp[STEREO_DFT_BAND_MAX], ord;

    /* read first component */
    b = 0;
    b = add( b, read_GR1( &bit_stream[nb], ind1_tmp, 1 ) );
    /* read GR ord */
    ord = bit_stream[nb + b];
    b = add( b, 1 );

    IF( EQ_16( ord, 0 ) )
    {
        *GR_ord = 1;
        b = add( b, read_GR1( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) );
    }
    ELSE
    {
        ord = bit_stream[nb + b];
        b = add( b, 1 );
        IF( EQ_16( ord, 0 ) )
        {
            *GR_ord = 0;

            b = add( b, read_GR0( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) );
        }
        ELSE
        {
            *GR_ord = 2;
            b = add( b, read_GR2( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) );
        }
    }

    decode_adapt_GR_indices1( ind1_tmp, len, NO_SYMB_GR_SIDE_G, ind1, map0 );

    return b;
}


/*---------------------------------------------------------------------*
 * read_itd()
 *
 * read and decode ITD in DFT mode
 *---------------------------------------------------------------------*/

/*! r: number of bits read */
Word16 read_itd(
    Decoder_State *st, /* i  : Decoder state         */
    Word16 *pI         /* o  : ITD value             */
)
{
    Word16 huff_flag, sign_flag, I, i, nb = 0, ready;

    huff_flag = (Word16) get_next_indice( st, 1 );
    sign_flag = (Word16) get_next_indice( st, 1 );
    nb = add( nb, 2 );

    IF( EQ_16( huff_flag, 1 ) )
    {
        ready = 0;
        I = 0;

        WHILE( ( EQ_16( ready, 0 ) ) && ( LT_16( nb, 10 ) ) )
        {
            I = add( shl( I, 1 ), (Word16) get_next_indice( st, 1 ) );
            nb = add( nb, 1 );

            FOR( i = 0; i < 20; i++ )
            {
                IF( ( EQ_16( I, dft_code_itd[i] ) ) && ( EQ_16( dft_len_itd[i], ( sub( nb, 2 ) ) ) ) )
                {
                    I = i;
                    ready = 1;
                    BREAK;
                }
            }
        }
        IF( EQ_16( ready, 0 ) )
        {
            printf( "Error reading Huffman code for ITD: \n" );
        }
    }
    ELSE
    {
        I = (Word16) get_next_indice( st, STEREO_DFT_ITD_NBITS - 1 );
        nb = add( nb, STEREO_DFT_ITD_NBITS - 1 );
    }

    I = add( I, shl( sign_flag, 8 ) );
    *pI = I;

    return nb;
}


/*---------------------------------------------------------------------*
 * read_BS_adapt_GR_rpg()
 *
 * read and decode residual prediction gain values using adaptive GR
 *---------------------------------------------------------------------*/

/*! r: number of bits read */
Word16 read_BS_adapt_GR_rpg(
    const UWord16 *bit_stream, /* i  : bitstream to be read         */
    const Word16 nb,           /* i  : starting point in bitstream  */
    Word16 *ind1_pred,         /* o  : decoded res pred gains       */
    const Word16 start,        /* i  : starting subband             */
    const Word16 total_no,     /* i  : number of params to be read  */
    Word16 *GR_ord             /* o  : GR order - read              */
)
{
    Word16 b, ind1_tmp[STEREO_DFT_BAND_MAX], i, len;
    len = sub( total_no, start );

    /* read first band */
    b = read_GR1( &bit_stream[nb], ind1_tmp, 1 );

    IF( EQ_16( ind1_tmp[0], dft_maps_rpg[8 * NO_SYMB_GR_PRED_G] ) )
    {
        FOR( i = start; i < total_no; i++ )
        {
            ind1_pred[i] = 0;
        }
    }
    ELSE
    {
        *GR_ord = bit_stream[nb + b]; /* GR order */
        b = add( b, 1 );
        IF( EQ_16( *GR_ord, 0 ) )
        {
            b = add( b, read_GR0( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) );
        }
        ELSE
        {
            /* GR ord 1 */
            b = add( b, read_GR1( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) );
        }
        decode_adapt_GR_indices1( ind1_tmp, total_no - start, NO_SYMB_GR_PRED_G, &ind1_pred[start], dft_maps_rpg );
    }

    return b;
}


/*---------------------------------------------------------------------*
 * read_flag_EC_DFT()
 *
 * read flag differentiating between: CBR/EC with adaptive GR/GR for differential coding
 *---------------------------------------------------------------------*/

/*! r: number of bits read */
Word16 read_flag_EC_DFT(
    const UWord16 *bit_stream, /* i  : bitstream            */
    Word16 *flag               /* o  : flag value           */
)
{
    Word16 flg;

    flg = bit_stream[0];
    IF( EQ_16( flg, 0 ) )
    {
        *flag = flg;
        return 1;
    }
    ELSE
    {
        *flag = add( 2, bit_stream[1] );
        return 2;
    }
}
#else
/*---------------------------------------------------------------------*
 * read_GR2()
 *
@@ -494,3 +955,5 @@ int16_t read_flag_EC_DFT(
        return 2;
    }
}

#endif
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@
#include "ivas_cnst.h"
#include "ivas_rom_com.h"
#include "wmc_auto.h"
#ifdef IVAS_FLOAT_FIXED
#include "ivas_prot_fx.h"
#endif // IVAS_FLOAT_FIXED

/*-------------------------------------------------------------------
 * Local constants
+3 −0
Original line number Diff line number Diff line
@@ -38,6 +38,9 @@
#include "ivas_prot.h"
#include "prot.h"
#include "wmc_auto.h"
#ifdef IVAS_FLOAT_FIXED
#include "ivas_prot_fx.h"
#endif // IVAS_FLOAT_FIXED


/*-------------------------------------------------------------------*