cannam@154
|
1 /***********************************************************************
|
cannam@154
|
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
|
cannam@154
|
3 Redistribution and use in source and binary forms, with or without
|
cannam@154
|
4 modification, are permitted provided that the following conditions
|
cannam@154
|
5 are met:
|
cannam@154
|
6 - Redistributions of source code must retain the above copyright notice,
|
cannam@154
|
7 this list of conditions and the following disclaimer.
|
cannam@154
|
8 - Redistributions in binary form must reproduce the above copyright
|
cannam@154
|
9 notice, this list of conditions and the following disclaimer in the
|
cannam@154
|
10 documentation and/or other materials provided with the distribution.
|
cannam@154
|
11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
|
cannam@154
|
12 names of specific contributors, may be used to endorse or promote
|
cannam@154
|
13 products derived from this software without specific prior written
|
cannam@154
|
14 permission.
|
cannam@154
|
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
cannam@154
|
16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
cannam@154
|
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
cannam@154
|
18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
cannam@154
|
19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
cannam@154
|
20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
cannam@154
|
21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
cannam@154
|
22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
cannam@154
|
23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
cannam@154
|
24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
cannam@154
|
25 POSSIBILITY OF SUCH DAMAGE.
|
cannam@154
|
26 ***********************************************************************/
|
cannam@154
|
27
|
cannam@154
|
28 #ifdef HAVE_CONFIG_H
|
cannam@154
|
29 #include "config.h"
|
cannam@154
|
30 #endif
|
cannam@154
|
31
|
cannam@154
|
32 #include "main.h"
|
cannam@154
|
33
|
cannam@154
|
34 /* Decode parameters from payload */
|
cannam@154
|
35 void silk_decode_parameters(
|
cannam@154
|
36 silk_decoder_state *psDec, /* I/O State */
|
cannam@154
|
37 silk_decoder_control *psDecCtrl, /* I/O Decoder control */
|
cannam@154
|
38 opus_int condCoding /* I The type of conditional coding to use */
|
cannam@154
|
39 )
|
cannam@154
|
40 {
|
cannam@154
|
41 opus_int i, k, Ix;
|
cannam@154
|
42 opus_int16 pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ];
|
cannam@154
|
43 const opus_int8 *cbk_ptr_Q7;
|
cannam@154
|
44
|
cannam@154
|
45 /* Dequant Gains */
|
cannam@154
|
46 silk_gains_dequant( psDecCtrl->Gains_Q16, psDec->indices.GainsIndices,
|
cannam@154
|
47 &psDec->LastGainIndex, condCoding == CODE_CONDITIONALLY, psDec->nb_subfr );
|
cannam@154
|
48
|
cannam@154
|
49 /****************/
|
cannam@154
|
50 /* Decode NLSFs */
|
cannam@154
|
51 /****************/
|
cannam@154
|
52 silk_NLSF_decode( pNLSF_Q15, psDec->indices.NLSFIndices, psDec->psNLSF_CB );
|
cannam@154
|
53
|
cannam@154
|
54 /* Convert NLSF parameters to AR prediction filter coefficients */
|
cannam@154
|
55 silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order, psDec->arch );
|
cannam@154
|
56
|
cannam@154
|
57 /* If just reset, e.g., because internal Fs changed, do not allow interpolation */
|
cannam@154
|
58 /* improves the case of packet loss in the first frame after a switch */
|
cannam@154
|
59 if( psDec->first_frame_after_reset == 1 ) {
|
cannam@154
|
60 psDec->indices.NLSFInterpCoef_Q2 = 4;
|
cannam@154
|
61 }
|
cannam@154
|
62
|
cannam@154
|
63 if( psDec->indices.NLSFInterpCoef_Q2 < 4 ) {
|
cannam@154
|
64 /* Calculation of the interpolated NLSF0 vector from the interpolation factor, */
|
cannam@154
|
65 /* the previous NLSF1, and the current NLSF1 */
|
cannam@154
|
66 for( i = 0; i < psDec->LPC_order; i++ ) {
|
cannam@154
|
67 pNLSF0_Q15[ i ] = psDec->prevNLSF_Q15[ i ] + silk_RSHIFT( silk_MUL( psDec->indices.NLSFInterpCoef_Q2,
|
cannam@154
|
68 pNLSF_Q15[ i ] - psDec->prevNLSF_Q15[ i ] ), 2 );
|
cannam@154
|
69 }
|
cannam@154
|
70
|
cannam@154
|
71 /* Convert NLSF parameters to AR prediction filter coefficients */
|
cannam@154
|
72 silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 0 ], pNLSF0_Q15, psDec->LPC_order, psDec->arch );
|
cannam@154
|
73 } else {
|
cannam@154
|
74 /* Copy LPC coefficients for first half from second half */
|
cannam@154
|
75 silk_memcpy( psDecCtrl->PredCoef_Q12[ 0 ], psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof( opus_int16 ) );
|
cannam@154
|
76 }
|
cannam@154
|
77
|
cannam@154
|
78 silk_memcpy( psDec->prevNLSF_Q15, pNLSF_Q15, psDec->LPC_order * sizeof( opus_int16 ) );
|
cannam@154
|
79
|
cannam@154
|
80 /* After a packet loss do BWE of LPC coefs */
|
cannam@154
|
81 if( psDec->lossCnt ) {
|
cannam@154
|
82 silk_bwexpander( psDecCtrl->PredCoef_Q12[ 0 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 );
|
cannam@154
|
83 silk_bwexpander( psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 );
|
cannam@154
|
84 }
|
cannam@154
|
85
|
cannam@154
|
86 if( psDec->indices.signalType == TYPE_VOICED ) {
|
cannam@154
|
87 /*********************/
|
cannam@154
|
88 /* Decode pitch lags */
|
cannam@154
|
89 /*********************/
|
cannam@154
|
90
|
cannam@154
|
91 /* Decode pitch values */
|
cannam@154
|
92 silk_decode_pitch( psDec->indices.lagIndex, psDec->indices.contourIndex, psDecCtrl->pitchL, psDec->fs_kHz, psDec->nb_subfr );
|
cannam@154
|
93
|
cannam@154
|
94 /* Decode Codebook Index */
|
cannam@154
|
95 cbk_ptr_Q7 = silk_LTP_vq_ptrs_Q7[ psDec->indices.PERIndex ]; /* set pointer to start of codebook */
|
cannam@154
|
96
|
cannam@154
|
97 for( k = 0; k < psDec->nb_subfr; k++ ) {
|
cannam@154
|
98 Ix = psDec->indices.LTPIndex[ k ];
|
cannam@154
|
99 for( i = 0; i < LTP_ORDER; i++ ) {
|
cannam@154
|
100 psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER + i ] = silk_LSHIFT( cbk_ptr_Q7[ Ix * LTP_ORDER + i ], 7 );
|
cannam@154
|
101 }
|
cannam@154
|
102 }
|
cannam@154
|
103
|
cannam@154
|
104 /**********************/
|
cannam@154
|
105 /* Decode LTP scaling */
|
cannam@154
|
106 /**********************/
|
cannam@154
|
107 Ix = psDec->indices.LTP_scaleIndex;
|
cannam@154
|
108 psDecCtrl->LTP_scale_Q14 = silk_LTPScales_table_Q14[ Ix ];
|
cannam@154
|
109 } else {
|
cannam@154
|
110 silk_memset( psDecCtrl->pitchL, 0, psDec->nb_subfr * sizeof( opus_int ) );
|
cannam@154
|
111 silk_memset( psDecCtrl->LTPCoef_Q14, 0, LTP_ORDER * psDec->nb_subfr * sizeof( opus_int16 ) );
|
cannam@154
|
112 psDec->indices.PERIndex = 0;
|
cannam@154
|
113 psDecCtrl->LTP_scale_Q14 = 0;
|
cannam@154
|
114 }
|
cannam@154
|
115 }
|