summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoen Vos <koenvos@users.noreply.github.com>2016-02-21 13:16:46 +0800
committerJean-Marc Valin <jmvalin@jmvalin.ca>2016-06-02 15:13:35 -0400
commit383fe7c93e77207b9d8df20b53b2b003c6d44558 (patch)
tree6fdd4f403502c3f72c357536a364edb27ed20aec
parent6332665c9a683797310c19502bb6c8fedf404aec (diff)
downloadopus-383fe7c93e77207b9d8df20b53b2b003c6d44558.tar.gz
NLSF decoding now uses tables for NLSF weights
-rw-r--r--silk/A2NLSF.c2
-rw-r--r--silk/NLSF_decode.c46
-rw-r--r--silk/NLSF_encode.c2
-rw-r--r--silk/decode_parameters.c2
-rw-r--r--silk/main.h5
-rw-r--r--silk/structs.h1
-rw-r--r--silk/tables_NLSF_CB_NB_MB.c36
-rw-r--r--silk/tables_NLSF_CB_WB.c36
8 files changed, 109 insertions, 21 deletions
diff --git a/silk/A2NLSF.c b/silk/A2NLSF.c
index b6e9e5ff..a1edde1e 100644
--- a/silk/A2NLSF.c
+++ b/silk/A2NLSF.c
@@ -130,7 +130,7 @@ void silk_A2NLSF(
const opus_int d /* I Filter order (must be even) */
)
{
- opus_int i, k, m, dd, root_ix, ffrac;
+ opus_int i, k, m, dd, root_ix, ffrac;
opus_int32 xlo, xhi, xmid;
opus_int32 ylo, yhi, ymid, thr;
opus_int32 nom, den;
diff --git a/silk/NLSF_decode.c b/silk/NLSF_decode.c
index 9f715060..93c86539 100644
--- a/silk/NLSF_decode.c
+++ b/silk/NLSF_decode.c
@@ -60,25 +60,20 @@ static OPUS_INLINE void silk_NLSF_residual_dequant( /* O Return
/***********************/
/* NLSF vector decoder */
/***********************/
-void silk_NLSF_decode(
+opus_int silk_NLSF_decode( /* O Number of bits (Q5), if signalType >= 0 */
opus_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */
opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
- const silk_NLSF_CB_struct *psNLSF_CB /* I Codebook object */
+ const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */
+ const opus_int signalType /* I SignalType, to determine number of bits */
)
{
opus_int i;
opus_uint8 pred_Q8[ MAX_LPC_ORDER ];
opus_int16 ec_ix[ MAX_LPC_ORDER ];
opus_int16 res_Q10[ MAX_LPC_ORDER ];
- opus_int16 W_tmp_QW[ MAX_LPC_ORDER ];
- opus_int32 W_tmp_Q9, NLSF_Q15_tmp;
+ opus_int32 NLSF_Q15_tmp;
const opus_uint8 *pCB_element;
-
- /* Decode first stage */
- pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ NLSFIndices[ 0 ] * psNLSF_CB->order ];
- for( i = 0; i < psNLSF_CB->order; i++ ) {
- pNLSF_Q15[ i ] = silk_LSHIFT( (opus_int16)pCB_element[ i ], 7 );
- }
+ const opus_int16 *pCB_Wght_Q9;
/* Unpack entropy table indices and predictor for current CB1 index */
silk_NLSF_unpack( ec_ix, pred_Q8, psNLSF_CB, NLSFIndices[ 0 ] );
@@ -86,16 +81,35 @@ void silk_NLSF_decode(
/* Predictive residual dequantizer */
silk_NLSF_residual_dequant( res_Q10, &NLSFIndices[ 1 ], pred_Q8, psNLSF_CB->quantStepSize_Q16, psNLSF_CB->order );
- /* Weights from codebook vector */
- silk_NLSF_VQ_weights_laroia( W_tmp_QW, pNLSF_Q15, psNLSF_CB->order );
-
- /* Apply inverse square-rooted weights and add to output */
+ /* Apply inverse square-rooted weights to first stage and add to output */
+ pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ NLSFIndices[ 0 ] * psNLSF_CB->order ];
+ pCB_Wght_Q9 = &psNLSF_CB->CB1_Wght_Q9[ NLSFIndices[ 0 ] * psNLSF_CB->order ];
for( i = 0; i < psNLSF_CB->order; i++ ) {
- W_tmp_Q9 = silk_SQRT_APPROX( silk_LSHIFT( (opus_int32)W_tmp_QW[ i ], 18 - NLSF_W_Q ) );
- NLSF_Q15_tmp = silk_ADD32( pNLSF_Q15[ i ], silk_DIV32_16( silk_LSHIFT( (opus_int32)res_Q10[ i ], 14 ), W_tmp_Q9 ) );
+ NLSF_Q15_tmp = silk_ADD_LSHIFT32( silk_DIV32_16( silk_LSHIFT( (opus_int32)res_Q10[ i ], 14 ), pCB_Wght_Q9[ i ] ), (opus_int16)pCB_element[ i ], 7 );
pNLSF_Q15[ i ] = (opus_int16)silk_LIMIT( NLSF_Q15_tmp, 0, 32767 );
}
/* NLSF stabilization */
silk_NLSF_stabilize( pNLSF_Q15, psNLSF_CB->deltaMin_Q15, psNLSF_CB->order );
+
+ if( signalType >= 0 ) {
+ opus_int prob_Q8, bits_Q5;
+ const opus_uint8 *iCDF_ptr;
+ bits_Q5 = 0;
+ iCDF_ptr = &psNLSF_CB->CB1_iCDF[ ( signalType >> 1 ) * psNLSF_CB->nVectors ];
+ if( NLSFIndices[ 0 ] == 0 ) {
+ prob_Q8 = 256 - iCDF_ptr[ NLSFIndices[ 0 ] ];
+ } else {
+ prob_Q8 = iCDF_ptr[ NLSFIndices[ 0 ] - 1 ] - iCDF_ptr[ NLSFIndices[ 0 ] ];
+ }
+ bits_Q5 = ( 8 << 5 ) - ( silk_lin2log( prob_Q8 ) >> 2 );
+ for( i = 0; i < psNLSF_CB->order; i++ ) {
+ const opus_uint8 *rates_Q5;
+ rates_Q5 = &psNLSF_CB->ec_Rates_Q5[ ec_ix[ i ] ];
+ bits_Q5 += rates_Q5[ NLSFIndices[ i + 1 ] + NLSF_QUANT_MAX_AMPLITUDE ];
+ }
+ return bits_Q5;
+ }
+
+ return 0;
}
diff --git a/silk/NLSF_encode.c b/silk/NLSF_encode.c
index f03c3f1c..9bd48cbe 100644
--- a/silk/NLSF_encode.c
+++ b/silk/NLSF_encode.c
@@ -129,7 +129,7 @@ opus_int32 silk_NLSF_encode( /* O Returns
silk_memcpy( &NLSFIndices[ 1 ], &tempIndices2[ bestIndex * MAX_LPC_ORDER ], psNLSF_CB->order * sizeof( opus_int8 ) );
/* Decode */
- silk_NLSF_decode( pNLSF_Q15, NLSFIndices, psNLSF_CB );
+ silk_NLSF_decode( pNLSF_Q15, NLSFIndices, psNLSF_CB, -1 );
ret = RD_Q25[ 0 ];
RESTORE_STACK;
diff --git a/silk/decode_parameters.c b/silk/decode_parameters.c
index e345b1dc..07d6d6f4 100644
--- a/silk/decode_parameters.c
+++ b/silk/decode_parameters.c
@@ -49,7 +49,7 @@ void silk_decode_parameters(
/****************/
/* Decode NLSFs */
/****************/
- silk_NLSF_decode( pNLSF_Q15, psDec->indices.NLSFIndices, psDec->psNLSF_CB );
+ silk_NLSF_decode( pNLSF_Q15, psDec->indices.NLSFIndices, psDec->psNLSF_CB, -1 );
/* Convert NLSF parameters to AR prediction filter coefficients */
silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order );
diff --git a/silk/main.h b/silk/main.h
index 2f90d68f..60153359 100644
--- a/silk/main.h
+++ b/silk/main.h
@@ -375,10 +375,11 @@ void silk_NLSF_unpack(
/***********************/
/* NLSF vector decoder */
/***********************/
-void silk_NLSF_decode(
+opus_int silk_NLSF_decode( /* O Number of bits (Q5), if signalType >= 0 */
opus_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */
opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
- const silk_NLSF_CB_struct *psNLSF_CB /* I Codebook object */
+ const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */
+ const opus_int signalType /* I SignalType, to determine number of bits */
);
/****************************************************/
diff --git a/silk/structs.h b/silk/structs.h
index 827829dc..1a410d0d 100644
--- a/silk/structs.h
+++ b/silk/structs.h
@@ -86,6 +86,7 @@ typedef struct {
const opus_int16 quantStepSize_Q16;
const opus_int16 invQuantStepSize_Q6;
const opus_uint8 *CB1_NLSF_Q8;
+ const opus_int16 *CB1_Wght_Q9;
const opus_uint8 *CB1_iCDF;
const opus_uint8 *pred_Q8;
const opus_uint8 *ec_sel;
diff --git a/silk/tables_NLSF_CB_NB_MB.c b/silk/tables_NLSF_CB_NB_MB.c
index 8c59d207..195d5b95 100644
--- a/silk/tables_NLSF_CB_NB_MB.c
+++ b/silk/tables_NLSF_CB_NB_MB.c
@@ -74,6 +74,41 @@ static const opus_uint8 silk_NLSF_CB1_NB_MB_Q8[ 320 ] = {
64, 84, 104, 118, 156, 177, 201, 230
};
+static const opus_int16 silk_NLSF_CB1_Wght_Q9[ 320 ] = {
+ 2897, 2314, 2314, 2314, 2287, 2287, 2314, 2300, 2327, 2287,
+ 2888, 2580, 2394, 2367, 2314, 2274, 2274, 2274, 2274, 2194,
+ 2487, 2340, 2340, 2314, 2314, 2314, 2340, 2340, 2367, 2354,
+ 3216, 2766, 2340, 2340, 2314, 2274, 2221, 2207, 2261, 2194,
+ 2460, 2474, 2367, 2394, 2394, 2394, 2394, 2367, 2407, 2314,
+ 3479, 3056, 2127, 2207, 2274, 2274, 2274, 2287, 2314, 2261,
+ 3282, 3141, 2580, 2394, 2247, 2221, 2207, 2194, 2194, 2114,
+ 4096, 3845, 2221, 2620, 2620, 2407, 2314, 2394, 2367, 2074,
+ 3178, 3244, 2367, 2221, 2553, 2434, 2340, 2314, 2167, 2221,
+ 3338, 3488, 2726, 2194, 2261, 2460, 2354, 2367, 2207, 2101,
+ 2354, 2420, 2327, 2367, 2394, 2420, 2420, 2420, 2460, 2367,
+ 3779, 3629, 2434, 2527, 2367, 2274, 2274, 2300, 2207, 2048,
+ 3254, 3225, 2713, 2846, 2447, 2327, 2300, 2300, 2274, 2127,
+ 3263, 3300, 2753, 2806, 2447, 2261, 2261, 2247, 2127, 2101,
+ 2873, 2981, 2633, 2367, 2407, 2354, 2194, 2247, 2247, 2114,
+ 3225, 3197, 2633, 2580, 2274, 2181, 2247, 2221, 2221, 2141,
+ 3178, 3310, 2740, 2407, 2274, 2274, 2274, 2287, 2194, 2114,
+ 3141, 3272, 2460, 2061, 2287, 2500, 2367, 2487, 2434, 2181,
+ 3507, 3282, 2314, 2700, 2647, 2474, 2367, 2394, 2340, 2127,
+ 3423, 3535, 3038, 3056, 2300, 1950, 2221, 2274, 2274, 2274,
+ 3404, 3366, 2087, 2687, 2873, 2354, 2420, 2274, 2474, 2540,
+ 3760, 3488, 1950, 2660, 2897, 2527, 2394, 2367, 2460, 2261,
+ 3028, 3272, 2740, 2888, 2740, 2154, 2127, 2287, 2234, 2247,
+ 3695, 3657, 2025, 1969, 2660, 2700, 2580, 2500, 2327, 2367,
+ 3207, 3413, 2354, 2074, 2888, 2888, 2340, 2487, 2247, 2167,
+ 3338, 3366, 2846, 2780, 2327, 2154, 2274, 2287, 2114, 2061,
+ 2327, 2300, 2181, 2167, 2181, 2367, 2633, 2700, 2700, 2553,
+ 2407, 2434, 2221, 2261, 2221, 2221, 2340, 2420, 2607, 2700,
+ 3038, 3244, 2806, 2888, 2474, 2074, 2300, 2314, 2354, 2380,
+ 2221, 2154, 2127, 2287, 2500, 2793, 2793, 2620, 2580, 2367,
+ 3676, 3713, 2234, 1838, 2181, 2753, 2726, 2673, 2513, 2207,
+ 2793, 3160, 2726, 2553, 2846, 2513, 2181, 2394, 2221, 2181
+};
+
static const opus_uint8 silk_NLSF_CB1_iCDF_NB_MB[ 64 ] = {
212, 178, 148, 129, 108, 96, 85, 82,
79, 77, 61, 59, 57, 56, 51, 49,
@@ -150,6 +185,7 @@ const silk_NLSF_CB_struct silk_NLSF_CB_NB_MB =
SILK_FIX_CONST( 0.18, 16 ),
SILK_FIX_CONST( 1.0 / 0.18, 6 ),
silk_NLSF_CB1_NB_MB_Q8,
+ silk_NLSF_CB1_Wght_Q9,
silk_NLSF_CB1_iCDF_NB_MB,
silk_NLSF_PRED_NB_MB_Q8,
silk_NLSF_CB2_SELECT_NB_MB,
diff --git a/silk/tables_NLSF_CB_WB.c b/silk/tables_NLSF_CB_WB.c
index 50af87eb..a15f7eb4 100644
--- a/silk/tables_NLSF_CB_WB.c
+++ b/silk/tables_NLSF_CB_WB.c
@@ -98,6 +98,41 @@ static const opus_uint8 silk_NLSF_CB1_WB_Q8[ 512 ] = {
110, 119, 129, 141, 175, 198, 218, 237
};
+static const opus_int16 silk_NLSF_CB1_Wght_Q9[ 512 ] = {
+ 3657, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2963, 2963, 2925, 2846,
+ 3216, 3085, 2972, 3056, 3056, 3010, 3010, 3010, 2963, 2963, 3010, 2972, 2888, 2846, 2846, 2726,
+ 3920, 4014, 2981, 3207, 3207, 2934, 3056, 2846, 3122, 3244, 2925, 2846, 2620, 2553, 2780, 2925,
+ 3516, 3197, 3010, 3103, 3019, 2888, 2925, 2925, 2925, 2925, 2888, 2888, 2888, 2888, 2888, 2753,
+ 5054, 5054, 2934, 3573, 3385, 3056, 3085, 2793, 3160, 3160, 2972, 2846, 2513, 2540, 2753, 2888,
+ 4428, 4149, 2700, 2753, 2972, 3010, 2925, 2846, 2981, 3019, 2925, 2925, 2925, 2925, 2888, 2726,
+ 3620, 3019, 2972, 3056, 3056, 2873, 2806, 3056, 3216, 3047, 2981, 3291, 3291, 2981, 3310, 2991,
+ 5227, 5014, 2540, 3338, 3526, 3385, 3197, 3094, 3376, 2981, 2700, 2647, 2687, 2793, 2846, 2673,
+ 5081, 5174, 4615, 4428, 2460, 2897, 3047, 3207, 3169, 2687, 2740, 2888, 2846, 2793, 2846, 2700,
+ 3122, 2888, 2963, 2925, 2925, 2925, 2925, 2963, 2963, 2963, 2963, 2925, 2925, 2963, 2963, 2963,
+ 4202, 3207, 2981, 3103, 3010, 2888, 2888, 2925, 2972, 2873, 2916, 3019, 2972, 3010, 3197, 2873,
+ 3760, 3760, 3244, 3103, 2981, 2888, 2925, 2888, 2972, 2934, 2793, 2793, 2846, 2888, 2888, 2660,
+ 3854, 4014, 3207, 3122, 3244, 2934, 3047, 2963, 2963, 3085, 2846, 2793, 2793, 2793, 2793, 2580,
+ 3845, 4080, 3357, 3516, 3094, 2740, 3010, 2934, 3122, 3085, 2846, 2846, 2647, 2647, 2846, 2806,
+ 5147, 4894, 3225, 3845, 3441, 3169, 2897, 3413, 3451, 2700, 2580, 2673, 2740, 2846, 2806, 2753,
+ 4109, 3789, 3291, 3160, 2925, 2888, 2888, 2925, 2793, 2740, 2793, 2740, 2793, 2846, 2888, 2806,
+ 5081, 5054, 3047, 3545, 3244, 3056, 3085, 2944, 3103, 2897, 2740, 2740, 2740, 2846, 2793, 2620,
+ 4309, 4309, 2860, 2527, 3207, 3376, 3376, 3075, 3075, 3376, 3056, 2846, 2647, 2580, 2726, 2753,
+ 3056, 2916, 2806, 2888, 2740, 2687, 2897, 3103, 3150, 3150, 3216, 3169, 3056, 3010, 2963, 2846,
+ 4375, 3882, 2925, 2888, 2846, 2888, 2846, 2846, 2888, 2888, 2888, 2846, 2888, 2925, 2888, 2846,
+ 2981, 2916, 2916, 2981, 2981, 3056, 3122, 3216, 3150, 3056, 3010, 2972, 2972, 2972, 2925, 2740,
+ 4229, 4149, 3310, 3347, 2925, 2963, 2888, 2981, 2981, 2846, 2793, 2740, 2846, 2846, 2846, 2793,
+ 4080, 4014, 3103, 3010, 2925, 2925, 2925, 2888, 2925, 2925, 2846, 2846, 2846, 2793, 2888, 2780,
+ 4615, 4575, 3169, 3441, 3207, 2981, 2897, 3038, 3122, 2740, 2687, 2687, 2687, 2740, 2793, 2700,
+ 4149, 4269, 3789, 3657, 2726, 2780, 2888, 2888, 3010, 2972, 2925, 2846, 2687, 2687, 2793, 2888,
+ 4215, 3554, 2753, 2846, 2846, 2888, 2888, 2888, 2925, 2925, 2888, 2925, 2925, 2925, 2963, 2888,
+ 5174, 4921, 2261, 3432, 3789, 3479, 3347, 2846, 3310, 3479, 3150, 2897, 2460, 2487, 2753, 2925,
+ 3451, 3685, 3122, 3197, 3357, 3047, 3207, 3207, 2981, 3216, 3085, 2925, 2925, 2687, 2540, 2434,
+ 2981, 3010, 2793, 2793, 2740, 2793, 2846, 2972, 3056, 3103, 3150, 3150, 3150, 3103, 3010, 3010,
+ 2944, 2873, 2687, 2726, 2780, 3010, 3432, 3545, 3357, 3244, 3056, 3010, 2963, 2925, 2888, 2846,
+ 3019, 2944, 2897, 3010, 3010, 2972, 3019, 3103, 3056, 3056, 3010, 2888, 2846, 2925, 2925, 2888,
+ 3920, 3967, 3010, 3197, 3357, 3216, 3291, 3291, 3479, 3704, 3441, 2726, 2181, 2460, 2580, 2607
+};
+
static const opus_uint8 silk_NLSF_CB1_iCDF_WB[ 64 ] = {
225, 204, 201, 184, 183, 175, 158, 154,
153, 135, 119, 115, 113, 110, 109, 99,
@@ -188,6 +223,7 @@ const silk_NLSF_CB_struct silk_NLSF_CB_WB =
SILK_FIX_CONST( 0.15, 16 ),
SILK_FIX_CONST( 1.0 / 0.15, 6 ),
silk_NLSF_CB1_WB_Q8,
+ silk_NLSF_CB1_Wght_Q9,
silk_NLSF_CB1_iCDF_WB,
silk_NLSF_PRED_WB_Q8,
silk_NLSF_CB2_SELECT_WB,