cannam@154: /*********************************************************************** cannam@154: Copyright (c) 2006-2011, Skype Limited. All rights reserved. cannam@154: Redistribution and use in source and binary forms, with or without cannam@154: modification, are permitted provided that the following conditions cannam@154: are met: cannam@154: - Redistributions of source code must retain the above copyright notice, cannam@154: this list of conditions and the following disclaimer. cannam@154: - Redistributions in binary form must reproduce the above copyright cannam@154: notice, this list of conditions and the following disclaimer in the cannam@154: documentation and/or other materials provided with the distribution. cannam@154: - Neither the name of Internet Society, IETF or IETF Trust, nor the cannam@154: names of specific contributors, may be used to endorse or promote cannam@154: products derived from this software without specific prior written cannam@154: permission. cannam@154: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" cannam@154: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE cannam@154: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE cannam@154: ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE cannam@154: LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR cannam@154: CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF cannam@154: SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS cannam@154: INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN cannam@154: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) cannam@154: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE cannam@154: POSSIBILITY OF SUCH DAMAGE. cannam@154: ***********************************************************************/ cannam@154: cannam@154: #ifdef HAVE_CONFIG_H cannam@154: #include "config.h" cannam@154: #endif cannam@154: cannam@154: #include "main.h" cannam@154: cannam@154: /* Decode parameters from payload */ cannam@154: void silk_decode_parameters( cannam@154: silk_decoder_state *psDec, /* I/O State */ cannam@154: silk_decoder_control *psDecCtrl, /* I/O Decoder control */ cannam@154: opus_int condCoding /* I The type of conditional coding to use */ cannam@154: ) cannam@154: { cannam@154: opus_int i, k, Ix; cannam@154: opus_int16 pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ]; cannam@154: const opus_int8 *cbk_ptr_Q7; cannam@154: cannam@154: /* Dequant Gains */ cannam@154: silk_gains_dequant( psDecCtrl->Gains_Q16, psDec->indices.GainsIndices, cannam@154: &psDec->LastGainIndex, condCoding == CODE_CONDITIONALLY, psDec->nb_subfr ); cannam@154: cannam@154: /****************/ cannam@154: /* Decode NLSFs */ cannam@154: /****************/ cannam@154: silk_NLSF_decode( pNLSF_Q15, psDec->indices.NLSFIndices, psDec->psNLSF_CB ); cannam@154: cannam@154: /* Convert NLSF parameters to AR prediction filter coefficients */ cannam@154: silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order, psDec->arch ); cannam@154: cannam@154: /* If just reset, e.g., because internal Fs changed, do not allow interpolation */ cannam@154: /* improves the case of packet loss in the first frame after a switch */ cannam@154: if( psDec->first_frame_after_reset == 1 ) { cannam@154: psDec->indices.NLSFInterpCoef_Q2 = 4; cannam@154: } cannam@154: cannam@154: if( psDec->indices.NLSFInterpCoef_Q2 < 4 ) { cannam@154: /* Calculation of the interpolated NLSF0 vector from the interpolation factor, */ cannam@154: /* the previous NLSF1, and the current NLSF1 */ cannam@154: for( i = 0; i < psDec->LPC_order; i++ ) { cannam@154: pNLSF0_Q15[ i ] = psDec->prevNLSF_Q15[ i ] + silk_RSHIFT( silk_MUL( psDec->indices.NLSFInterpCoef_Q2, cannam@154: pNLSF_Q15[ i ] - psDec->prevNLSF_Q15[ i ] ), 2 ); cannam@154: } cannam@154: cannam@154: /* Convert NLSF parameters to AR prediction filter coefficients */ cannam@154: silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 0 ], pNLSF0_Q15, psDec->LPC_order, psDec->arch ); cannam@154: } else { cannam@154: /* Copy LPC coefficients for first half from second half */ cannam@154: silk_memcpy( psDecCtrl->PredCoef_Q12[ 0 ], psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof( opus_int16 ) ); cannam@154: } cannam@154: cannam@154: silk_memcpy( psDec->prevNLSF_Q15, pNLSF_Q15, psDec->LPC_order * sizeof( opus_int16 ) ); cannam@154: cannam@154: /* After a packet loss do BWE of LPC coefs */ cannam@154: if( psDec->lossCnt ) { cannam@154: silk_bwexpander( psDecCtrl->PredCoef_Q12[ 0 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 ); cannam@154: silk_bwexpander( psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 ); cannam@154: } cannam@154: cannam@154: if( psDec->indices.signalType == TYPE_VOICED ) { cannam@154: /*********************/ cannam@154: /* Decode pitch lags */ cannam@154: /*********************/ cannam@154: cannam@154: /* Decode pitch values */ cannam@154: silk_decode_pitch( psDec->indices.lagIndex, psDec->indices.contourIndex, psDecCtrl->pitchL, psDec->fs_kHz, psDec->nb_subfr ); cannam@154: cannam@154: /* Decode Codebook Index */ cannam@154: cbk_ptr_Q7 = silk_LTP_vq_ptrs_Q7[ psDec->indices.PERIndex ]; /* set pointer to start of codebook */ cannam@154: cannam@154: for( k = 0; k < psDec->nb_subfr; k++ ) { cannam@154: Ix = psDec->indices.LTPIndex[ k ]; cannam@154: for( i = 0; i < LTP_ORDER; i++ ) { cannam@154: psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER + i ] = silk_LSHIFT( cbk_ptr_Q7[ Ix * LTP_ORDER + i ], 7 ); cannam@154: } cannam@154: } cannam@154: cannam@154: /**********************/ cannam@154: /* Decode LTP scaling */ cannam@154: /**********************/ cannam@154: Ix = psDec->indices.LTP_scaleIndex; cannam@154: psDecCtrl->LTP_scale_Q14 = silk_LTPScales_table_Q14[ Ix ]; cannam@154: } else { cannam@154: silk_memset( psDecCtrl->pitchL, 0, psDec->nb_subfr * sizeof( opus_int ) ); cannam@154: silk_memset( psDecCtrl->LTPCoef_Q14, 0, LTP_ORDER * psDec->nb_subfr * sizeof( opus_int16 ) ); cannam@154: psDec->indices.PERIndex = 0; cannam@154: psDecCtrl->LTP_scale_Q14 = 0; cannam@154: } cannam@154: }