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