Commit 40c0ac86 authored by Jonas Svedberg's avatar Jonas Svedberg
Browse files

added all SNS-VQ stage1 DCT16 encoder side code, decoder and tables still to be added

parent a3c74343
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1403,6 +1403,10 @@ typedef enum _DCTTYPE
    IDCT_T2_XX_24 = 1,
    DCT_T2_21_XX = 2, /* truncated DCT_T2_21 */
    IDCT_T2_XX_21 = 3
 #ifdef ERI_SNSVQ_ROMOPT
  , DCT_T2_16_XX = 4, /* truncated DCT_T2_16 */
    IDCT_T2_XX_16 = 5
 #endif 
} DCTTYPE;


+69 −1
Original line number Diff line number Diff line
@@ -5597,6 +5597,8 @@ const int16_t ivas_sns_cdbks_tcx20_levels[SNS_MSVQ_NSTAGES_TCX20] = { 128, 64, 3
const int16_t ivas_sns_cdbks_tcx20_bits[SNS_MSVQ_NSTAGES_TCX20] = { 7, 6, 5, 5 };
/* codebooks trained for no adaptive tilt */
#ifndef ERI_SNSVQ_ROMOPT
const float ivas_sns_cdbk_tcx20_stage1[ 128 * 16 ] = {
  -3.24881770f, -1.99497051f, -0.04725080f, 1.02318508f, 1.51589220f, 1.44649178f, 1.27858728f, 1.15137095f, 0.98029724f, 0.69167126f, 0.33414576f, 0.11759238f, -0.27510520f, -0.63610342f, -1.05394049f, -1.28304590f,
  -3.24340413f, -4.15075396f, -2.86242117f, -1.11561919f, 1.12899983f, 1.98341478f, 0.56638511f, -0.05841474f, -0.14875192f, 0.31098029f, 1.87121037f, 0.91347082f, 1.02548459f, 1.98227488f, 1.30278860f, 0.49435585f,
@@ -5727,6 +5729,8 @@ const float ivas_sns_cdbk_tcx20_stage1[ 128 * 16 ] = {
  2.58466208f, 2.01534437f, 1.28252767f, 0.44865967f, -0.33100837f, -0.81011259f, -1.06701187f, -1.12743988f, -1.21505758f, -0.99337144f, -0.66853937f, -0.46093443f, -0.22132067f, 0.00996599f, 0.24481197f, 0.30882455f,
  -0.62864502f, 1.04984327f, 1.56877053f, 0.77975000f, 0.01037804f, 0.92352492f, 1.12297462f, 0.76284403f, -0.16106015f, -0.21398417f, -0.62673537f, -1.68917053f, -1.60748063f, -0.79116243f, -0.06290217f, -0.43694470f
};
#endif
const float ivas_sns_cdbk_tcx20_stage2[ 64 * 16 ] = {
  -0.14487037f, 0.32346300f, 0.29798679f, -0.52393127f, -0.25671033f, 0.85717754f, -0.09030235f, -0.41110330f, -0.32938564f, -0.36580017f, -0.13142117f, -0.06404494f, 0.10671000f, 0.18731030f, 0.26606878f, 0.27885301f,
  0.52707061f, 0.35016312f, 0.54090507f, 0.82023896f, 0.46675870f, -0.60012182f, -0.76783382f, -0.39198749f, -0.17916696f, -0.17307722f, -0.10507731f, -0.09327542f, -0.12176361f, -0.12715624f, -0.11980175f, -0.02587481f,
@@ -5862,8 +5866,11 @@ const float ivas_sns_cdbk_tcx20_stage4[ 32 * 16 ] = {
  0.44241891f, -0.06885632f, -0.14130761f, -0.04771012f, -0.00863562f, 0.00586591f, 0.12381405f, 0.08059256f, -0.06764947f, -0.22513354f, -0.10536820f, 0.02669478f, 0.01147300f, -0.01584685f, -0.02845628f, 0.01810479f
};
#ifdef ERI_SNSVQ_ROMOPT
 const float *const ivas_sns_cdbks_tcx20[SNS_MSVQ_NSTAGES_TCX20] = { NULL, ivas_sns_cdbk_tcx20_stage2, ivas_sns_cdbk_tcx20_stage3, ivas_sns_cdbk_tcx20_stage4 };
#else 
const float *const ivas_sns_cdbks_tcx20[SNS_MSVQ_NSTAGES_TCX20] = { ivas_sns_cdbk_tcx20_stage1, ivas_sns_cdbk_tcx20_stage2, ivas_sns_cdbk_tcx20_stage3, ivas_sns_cdbk_tcx20_stage4 };
#endif 
const float ivas_sns_means_tcx20[M] = {
    0.9155f , 1.2408f , 1.0050f , 0.5846f,
    0.2472f , 0.1902f , 0.0984f , 0.1039f,
@@ -5874,6 +5881,7 @@ const float ivas_sns_means_tcx20[M] = {
const int16_t ivas_sns_cdbks_tcx10_levels[SNS_MSVQ_NSTAGES_TCX10] = { 128, 32, 8 };
const int16_t ivas_sns_cdbks_tcx10_bits[SNS_MSVQ_NSTAGES_TCX10] = { 7, 5, 3 };
#ifndef ERI_SNSVQ_ROMOPT
const float ivas_sns_cdbk_tcx10_stage1[ 128 * 16 ] = {
  0.06343891f, -0.00651786f, -0.56994713f, -0.98772396f, -1.35099293f, -1.24848646f, -1.20301995f, -0.81089507f, -0.06563095f, 1.11147581f, 1.73933309f, 1.65859611f, 1.26237806f, 0.68028141f, 0.12449909f, -0.39678907f,
  -1.34007175f, -1.50272189f, -2.07958791f, -2.38322761f, -2.22156614f, -1.96435669f, -1.68760863f, -1.23664935f, -0.28772180f, 0.87765579f, 1.83822720f, 1.95281398f, 2.33671266f, 2.76119687f, 2.75790597f, 2.17899850f,
@@ -6004,6 +6012,8 @@ const float ivas_sns_cdbk_tcx10_stage1[ 128 * 16 ] = {
  2.30575156f, 2.37005513f, 1.37776397f, 0.78509487f, 0.18022242f, -0.13093354f, 0.22126477f, -0.11444642f, -0.35716968f, -0.59492665f, -0.35765935f, -0.44655201f, -1.03213345f, -1.27074059f, -1.44000075f, -1.49558947f,
  -1.00874079f, -1.64011865f, -1.86084729f, -1.06805908f, 0.07222945f, 1.36179475f, 1.87160360f, 1.76248472f, 1.52374330f, 1.04119855f, 0.73448166f, 0.13768018f, -0.49711929f, -0.73696841f, -0.89885406f, -0.79450886f
};
#endif
const float ivas_sns_cdbk_tcx10_stage2[ 32 * 16 ] = {
  0.30627323f, 0.48836579f, -0.02716944f, -0.47680077f, -0.52992614f, -0.25467720f, -0.13298242f, -0.14929291f, -0.14808149f, 0.08665801f, 0.28830653f, 0.27526330f, 0.09942358f, -0.01755061f, 0.03315580f, 0.15903469f,
  0.40931263f, -0.04412117f, -0.08826419f, 0.38716891f, 0.51515595f, 0.42227845f, 0.34963425f, 0.26800736f, 0.03770000f, -0.19967080f, -0.31044249f, -0.32623294f, -0.38445978f, -0.38085950f, -0.38590829f, -0.26929836f,
@@ -6049,7 +6059,11 @@ const float ivas_sns_cdbk_tcx10_stage3[ 8 * 16 ] = {
  -0.18216919f, 0.06012195f, 0.24774113f, 0.41673922f, 0.28902704f, -0.14711768f, -0.20580810f, -0.08400793f, -0.06024452f, -0.19915854f, -0.17662518f, -0.08993148f, 0.01116638f, 0.13122555f, 0.08011919f, -0.09107791f
};
#ifdef ERI_SNSVQ_ROMOPT
const float *const ivas_sns_cdbks_tcx10[SNS_MSVQ_NSTAGES_TCX10] = { NULL, ivas_sns_cdbk_tcx10_stage2, ivas_sns_cdbk_tcx10_stage3};
#else
const float *const ivas_sns_cdbks_tcx10[SNS_MSVQ_NSTAGES_TCX10] = { ivas_sns_cdbk_tcx10_stage1, ivas_sns_cdbk_tcx10_stage2, ivas_sns_cdbk_tcx10_stage3};
#endif 
const float ivas_sns_means_tcx10[M] = {
    0.9510f , 1.1892f , 0.8969f , 0.3467f,
@@ -6058,6 +6072,60 @@ const float ivas_sns_means_tcx10[M] = {
    -0.4801f , -0.4108f , -0.4564f , -0.6112f
};
#ifdef ERI_SNSVQ_ROMOPT
 /*  DCT16 domain segmentwise structured SNS-VQ stage1  tables indexed as  tcx20 "0"  and tcx10 as "1" */
const float snsSt1_tr_midQ_truncQ_tcx20[M] = { 0 };
const float  snsSt1_tr_midQ_truncQ_tcx10[M]={ 0 };
const float *const snsSt1_tr_midQ_truncQ[2]= {snsSt1_tr_midQ_truncQ_tcx20, snsSt1_tr_midQ_truncQ_tcx10};
const float  snsSt1_dct_invScaleF_tcx20[3] = {0 };
const float  snsSt1_dct_invScaleF_tcx10[3] = {0 };
const float *const snsSt1_dct_invScaleF[2]= { snsSt1_dct_invScaleF_tcx20, snsSt1_dct_invScaleF_tcx10};
const float  snsSt1_dct_scaleF_tcx20[3] = {0 };
const float  snsSt1_dct_scaleF_tcx10[3] = {0 };
const float *const snsSt1_dct_scaleF[2] = { snsSt1_dct_scaleF_tcx20, snsSt1_dct_scaleF_tcx10};
const int16_t snsSt1_dct_n_segm[2] = { 4, 4 };
const int16_t  snsSt1_dct_cols_per_segment_tcx20[4]= { 0 };
const int16_t  snsSt1_dct_cols_per_segment_tcx10[4]= { 0 };
const int16_t *const snsSt1_dct_cols_per_segment[2]= { snsSt1_dct_cols_per_segment_tcx20, snsSt1_dct_cols_per_segment_tcx10};
const int16_t  snsSt1_trunc_dct_cols_per_segment_tcx20[4]= { 0 };
const int16_t  snsSt1_trunc_dct_cols_per_segment_tcx10[4]= { 0 };
const int16_t *const snsSt1_trunc_dct_cols_per_segment[2]= { snsSt1_trunc_dct_cols_per_segment_tcx20, snsSt1_trunc_dct_cols_per_segment_tcx10};
const int16_t  snsSt1_cum_entries_per_segment_tcx20[5]={0};
const int16_t  snsSt1_cum_entries_per_segment_tcx10[5]={0};
const int16_t *const  snsSt1_cum_entries_per_segment[2]={ snsSt1_cum_entries_per_segment_tcx20 ,snsSt1_cum_entries_per_segment_tcx10};
const int16_t  snsSt1_entries_per_segment_tcx20[4]={0};
const int16_t  snsSt1_entries_per_segment_tcx10[4]={0};
const int16_t *const  snsSt1_entries_per_segment[2]={ snsSt1_entries_per_segment_tcx20 ,snsSt1_entries_per_segment_tcx10};
const Word8 *const snsSt1_stage1_W8Qx_dct_sections_tcx20[4]={0};  
const Word8 *const snsSt1_stage1_W8Qx_dct_sections_tcx10[4]={0};  
const Word8 *const* snsSt1_stage1_W8Qx_dct_sections[2]={snsSt1_stage1_W8Qx_dct_sections_tcx20, snsSt1_stage1_W8Qx_dct_sections_tcx10 };  
const Word16 *const snsSt1_dct_col_syn_shift_tcx20[4]={0}; 
const Word16 *const snsSt1_dct_col_syn_shift_tcx10[4]={0};
const Word16 *const* snsSt1_dct_col_syn_shift[2]={snsSt1_dct_col_syn_shift_tcx20, snsSt1_dct_col_syn_shift_tcx10 };
const Word8 snsSt1_segm_neighbour_fwd_tcx20[128]={0};
const Word8 snsSt1_segm_neighbour_fwd_tcx10[128]={0};
const Word8 *const snsSt1_segm_neighbour_fwd[2]={snsSt1_segm_neighbour_fwd_tcx20  , snsSt1_segm_neighbour_fwd_tcx10};
const Word8 snsSt1_segm_neighbour_rev_tcx20[128]={0};
const Word8 snsSt1_segm_neighbour_rev_tcx10[128]={0};
const Word8 *const snsSt1_segm_neighbour_rev[2]={snsSt1_segm_neighbour_rev_tcx20  , snsSt1_segm_neighbour_rev_tcx10};
const int16_t snsSt1_npost[2]={8, 4}; /*number of circ. neigbours to postcheck  */
#endif  /*   ERI_SNSVQ_ROMOPT */
const int16_t ivas_sns_cdbks_side_tcx20_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 32 };
const int16_t ivas_sns_cdbks_side_tcx20_bits[SNS_MSVQ_NSTAGES_SIDE] = { 5, 5 };
const int16_t ivas_sns_cdbks_side_tcx10_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 8 };
+16 −0
Original line number Diff line number Diff line
@@ -420,6 +420,22 @@ extern const float *const ivas_sns_cdbks_tcx10[];
extern const float ivas_sns_means_tcx20[];
extern const float ivas_sns_means_tcx10[];

#ifdef ERI_SNSVQ_ROMOPT
extern const float *const snsSt1_tr_midQ_truncQ[];
extern const float *const snsSt1_dct_invScaleF[];
extern const float *const snsSt1_dct_scaleF[];
extern const int16_t snsSt1_dct_n_segm[];
extern const int16_t *const snsSt1_dct_cols_per_segment[] ;
extern const int16_t *const snsSt1_trunc_dct_cols_per_segment[];
extern const int16_t *const snsSt1_cum_entries_per_segment[];
extern const int16_t *const snsSt1_entries_per_segment[];
extern const Word8 *const *snsSt1_stage1_W8Qx_dct_sections[];
extern const Word16 *const *snsSt1_dct_col_syn_shift[];
extern const Word8 *const snsSt1_segm_neighbour_fwd[];
extern const Word8 *const snsSt1_segm_neighbour_rev[];
extern const int16_t snsSt1_npost[]; 
#endif /*   ERI_SNSVQ_ROMOPT */

extern const int16_t ivas_sns_cdbks_side_tcx20_levels[];
extern const int16_t ivas_sns_cdbks_side_tcx20_bits[];
extern const int16_t ivas_sns_cdbks_side_tcx10_levels[];
+127 −11
Original line number Diff line number Diff line
@@ -2027,6 +2027,74 @@ int16_t tcxlpc_get_cdk(
    return cdk;
}


#ifdef ERI_SNSVQ_ROMOPT
void dec_SNS_FDCNG_MSVQ_DCT_stage1(
    const int16_t n_segm,                         /* i:  */
    const int16_t *cum_entries_per_segment,       /*i:  */
    const Word8 *const *stage1_W8Qx_dct_sections, /* i:  */
    const int16_t *cols_per_segment,              /* i:  */
    const int16_t *const *dct_col_syn_shift,      /* i:   */

    const int16_t max_trunc,  /* i:   */
    const float *dct_scaleF,  /* i:   */
    const float *midQ_truncQ, /* i:   */

    int16_t j_full,            /* i:   index full range           */
    int16_t n,                 /* i:   dimension to generate      */
    const float *invTrfMatrix, /* i:   IDCT matrix for synthesis */
    const DCTTYPE idcttype,    /* i:   specify which IDCT */
    float *uq,                 /* o:   synthesized stage1 vector  */
    Word16 *uq_ind             /* o:   synthesized stage1 vector in BASOP */
)
{
    int16_t col, segm_ind, j;
    float dct_vec[NPART];
    float idct_vec[NPART];
    const Word8 *cbpW8;
    const Word16 *dct_col_shift_tab;

    assert( n ==M || n == NPART );

    segm_ind = 0;
    for ( col = 1; col <= n_segm; col++ )
    {
        if ( j_full >= cum_entries_per_segment[col] )
        {
            segm_ind++;
        }
    }

    j = j_full - cum_entries_per_segment[segm_ind]; /* j  is the local segment index */

    // assert( j < entries_per_segment[segm_ind] );

    /* Word8 column variable Qx storage*/
    cbpW8 = stage1_W8Qx_dct_sections[segm_ind]; /*   Word8 storage fixed  ptr_init */
    cbpW8 += j * cols_per_segment[segm_ind];    /*    adaptive ptr init */
    dct_col_shift_tab = dct_col_syn_shift[segm_ind];

    for ( col = 0; col < cols_per_segment[segm_ind]; col++ )
    {
        dct_vec[col] = (float) ( ( (Word16) cbpW8[col] ) << dct_col_shift_tab[col] );
        /* LOGIC( 1 ); SHIFT( 1 );  ADD( 1 );
           in BASOP:   s_and(for W8->W16), shl(), sub()
         */
    }
    dctT2_N_apply_matrix( (const float *) dct_vec, idct_vec, cols_per_segment[segm_ind], n, invTrfMatrix, max_trunc, idcttype );

    /*scale down to original   domain and move to Q0  */
    v_multc( idct_vec, dct_scaleF[1], idct_vec, n );
    /*   dct_scaleF[1] --> 0.0625-->scale down from  search Q4 domain  to Q0 ,
       not really  relevant for  BASOP loop */

    /*add common  mid  vector,  in  input bands domain */
    v_add( idct_vec, midQ_truncQ, uq, n );
    assert( uq_ind == NULL );
}
#endif


void dec_FDCNG_MSVQ_stage1(
    int16_t j_full,            /* i:   index full range           */
    int16_t n,                 /* i:   dimension to generate      */
@@ -2139,6 +2207,7 @@ void msvq_dec(

        if ( i == 0 && applyIDCT_flag != 0 )
        {  
            assert( 0 && "IDCT16 code here" );
            assert( start == 0 );
            dec_FDCNG_MSVQ_stage1( Idx[0], N, invTrfMatrix, IDCT_T2_XX_24, uq, uq_ind ); /* IDCT_T2 N=24 used for all synthesis  */
        }
@@ -2460,7 +2529,11 @@ void dctT2_N_apply_matrix(
        mat_step_col = matrix_row_dim; /* matrix maximum storage size dependent,  width of first row in matrix  */
        mat_step_row = 0;
        mat_step_col_flag = 1;
#ifdef ERI_SNSVQ_ROMOPT
        assert( dcttype == DCT_T2_16_XX ||  dcttype == DCT_T2_21_XX || dcttype == DCT_T2_24_XX );
#else 
        assert( dcttype == DCT_T2_21_XX || dcttype == DCT_T2_24_XX );
 #endif 
    }
    else
    {
@@ -2470,7 +2543,11 @@ void dctT2_N_apply_matrix(
        mat_step_col = 1;
        mat_step_row = matrix_row_dim;
        mat_step_col_flag = 0;
#ifdef ERI_SNSVQ_ROMOPT
        assert( dcttype == IDCT_T2_XX_16 ||  dcttype == IDCT_T2_XX_24 );
#else 
        assert( dcttype == IDCT_T2_XX_24 );
#endif 
    }

    pt_y = tmp_y;
@@ -2547,8 +2624,11 @@ void extend_dctN_input(
    }
}


#ifdef ERI_SNSVQ_ROMOPT
/* inititate idctN   DCT_MAXTRUNC x N matrix in  RAM  from a quantized compressed ROM format */
#else
/* inititate idct24 FDCNG_VQ_DCT_MAXTRUNCx N matrix in  RAM  from a  quantized compressed ROM format */
#endif
void create_IDCT_N_Matrix( float *inv_matrixFloatQ, const int16_t N, const int16_t n_cols, const int16_t alloc_size )
{
    int16_t c, c1, r, r_flip, W16_val;
@@ -2558,6 +2638,9 @@ void create_IDCT_N_Matrix( float *inv_matrixFloatQ, const int16_t N, const int16
    const Word8 *idx_ptr;
    Word16 idx;
    float( *ptr )[FDCNG_VQ_DCT_MAXTRUNC] = (void *) inv_matrixFloatQ; /*  fixed number of columns pointers, to   simplifies adressing in ANSIC   */
#ifdef ERI_SNSVQ_ROMOPT
    float( *ptrM )[M] = (void *) inv_matrixFloatQ; /*  fixed number of columns pointers, to   simplifies adressing in ANSIC   */
#endif

    absval_ptr = unique_idctT2_24coeffsQ16;
    idx_ptr = idctT2_24_compressed_idx;
@@ -2569,6 +2652,14 @@ void create_IDCT_N_Matrix( float *inv_matrixFloatQ, const int16_t N, const int16
        idx_ptr = idctT2_21_compressed_idx;
        len = N;
    }
#ifdef ERI_SNSVQ_ROMOPT
    if ( N == M )
    {
        absval_ptr = unique_idctT2_16coeffsQ16;
        idx_ptr = idctT2_16_compressed_idx;
        len = N;
    }
#endif

    assert( alloc_size >= ( n_cols * len ) ); /* enough space for the full expanded IDCT matrix  */
    assert( N <= len );
@@ -2596,13 +2687,35 @@ void create_IDCT_N_Matrix( float *inv_matrixFloatQ, const int16_t N, const int16
       flip symmetry for odd, even is used to save 50%   IDCT Table ROM */
    /* for an odd DCT  center  is not flipped  e.g  for DCT21  */

#ifdef ERI_SNSVQ_ROMOPT
    assert( n_cols == FDCNG_VQ_DCT_MAXTRUNC || n_cols == M );
#else
    assert( n_cols == FDCNG_VQ_DCT_MAXTRUNC );
#endif
    assert( ( n_cols & 1 ) == 0 );


    for ( c = 0; c < ( n_cols ); c += 2 )
    {
        c1 = c + 1;
        r_flip = len - 1;
#ifdef ERI_SNSVQ_ROMOPT
        if ( n_cols == M )
        {
            for ( r = 0; r < ( len / 2 ); r++, r_flip-- )
            {
#define WMC_TOOL_SKIP
                ptrM[r_flip][c] = ptrM[r][c];        /* flipped */
                ptrM[r_flip][c1] = -( ptrM[r][c1] ); /* flipped and sign swapped */
                MOVE( 2 );
                MULT( 1 ); /* for negate */
#undef WMC_TOOL_SKIP
            }

        }
        else
        {
#endif
            for ( r = 0; r < ( len / 2 ); r++, r_flip-- )
            {
#define WMC_TOOL_SKIP
@@ -2612,5 +2725,8 @@ void create_IDCT_N_Matrix( float *inv_matrixFloatQ, const int16_t N, const int16
                MULT( 1 ); /* for negate */
#undef WMC_TOOL_SKIP
            }
#ifdef ERI_SNSVQ_ROMOPT
        }
#endif
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -172,6 +172,10 @@

#define EUALER2QUAT_FIX                                 /*Dlb :fix for issue 430 issue in euler2quat, sign of quat y is inverted*/
#define HR_METADATA                                     /* Nok: encode directional MASA metadata with more bits at 384k and 512k */


#define ERI_SNSVQ_ROMOPT                               /* BASOP ROM OPT store added SNS VQ stage 1 tables  in DCT16 domain,  as for FDCNGVQ stage 1  */

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
#endif
Loading