1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/silk/decode_indices.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,151 @@ 1.4 +/*********************************************************************** 1.5 +Copyright (c) 2006-2011, Skype Limited. All rights reserved. 1.6 +Redistribution and use in source and binary forms, with or without 1.7 +modification, are permitted provided that the following conditions 1.8 +are met: 1.9 +- Redistributions of source code must retain the above copyright notice, 1.10 +this list of conditions and the following disclaimer. 1.11 +- Redistributions in binary form must reproduce the above copyright 1.12 +notice, this list of conditions and the following disclaimer in the 1.13 +documentation and/or other materials provided with the distribution. 1.14 +- Neither the name of Internet Society, IETF or IETF Trust, nor the 1.15 +names of specific contributors, may be used to endorse or promote 1.16 +products derived from this software without specific prior written 1.17 +permission. 1.18 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1.19 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.20 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.21 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 1.22 +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.23 +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.24 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.25 +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.26 +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.27 +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.28 +POSSIBILITY OF SUCH DAMAGE. 1.29 +***********************************************************************/ 1.30 + 1.31 +#ifdef HAVE_CONFIG_H 1.32 +#include "config.h" 1.33 +#endif 1.34 + 1.35 +#include "main.h" 1.36 + 1.37 +/* Decode side-information parameters from payload */ 1.38 +void silk_decode_indices( 1.39 + silk_decoder_state *psDec, /* I/O State */ 1.40 + ec_dec *psRangeDec, /* I/O Compressor data structure */ 1.41 + opus_int FrameIndex, /* I Frame number */ 1.42 + opus_int decode_LBRR, /* I Flag indicating LBRR data is being decoded */ 1.43 + opus_int condCoding /* I The type of conditional coding to use */ 1.44 +) 1.45 +{ 1.46 + opus_int i, k, Ix; 1.47 + opus_int decode_absolute_lagIndex, delta_lagIndex; 1.48 + opus_int16 ec_ix[ MAX_LPC_ORDER ]; 1.49 + opus_uint8 pred_Q8[ MAX_LPC_ORDER ]; 1.50 + 1.51 + /*******************************************/ 1.52 + /* Decode signal type and quantizer offset */ 1.53 + /*******************************************/ 1.54 + if( decode_LBRR || psDec->VAD_flags[ FrameIndex ] ) { 1.55 + Ix = ec_dec_icdf( psRangeDec, silk_type_offset_VAD_iCDF, 8 ) + 2; 1.56 + } else { 1.57 + Ix = ec_dec_icdf( psRangeDec, silk_type_offset_no_VAD_iCDF, 8 ); 1.58 + } 1.59 + psDec->indices.signalType = (opus_int8)silk_RSHIFT( Ix, 1 ); 1.60 + psDec->indices.quantOffsetType = (opus_int8)( Ix & 1 ); 1.61 + 1.62 + /****************/ 1.63 + /* Decode gains */ 1.64 + /****************/ 1.65 + /* First subframe */ 1.66 + if( condCoding == CODE_CONDITIONALLY ) { 1.67 + /* Conditional coding */ 1.68 + psDec->indices.GainsIndices[ 0 ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_delta_gain_iCDF, 8 ); 1.69 + } else { 1.70 + /* Independent coding, in two stages: MSB bits followed by 3 LSBs */ 1.71 + psDec->indices.GainsIndices[ 0 ] = (opus_int8)silk_LSHIFT( ec_dec_icdf( psRangeDec, silk_gain_iCDF[ psDec->indices.signalType ], 8 ), 3 ); 1.72 + psDec->indices.GainsIndices[ 0 ] += (opus_int8)ec_dec_icdf( psRangeDec, silk_uniform8_iCDF, 8 ); 1.73 + } 1.74 + 1.75 + /* Remaining subframes */ 1.76 + for( i = 1; i < psDec->nb_subfr; i++ ) { 1.77 + psDec->indices.GainsIndices[ i ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_delta_gain_iCDF, 8 ); 1.78 + } 1.79 + 1.80 + /**********************/ 1.81 + /* Decode LSF Indices */ 1.82 + /**********************/ 1.83 + psDec->indices.NLSFIndices[ 0 ] = (opus_int8)ec_dec_icdf( psRangeDec, &psDec->psNLSF_CB->CB1_iCDF[ ( psDec->indices.signalType >> 1 ) * psDec->psNLSF_CB->nVectors ], 8 ); 1.84 + silk_NLSF_unpack( ec_ix, pred_Q8, psDec->psNLSF_CB, psDec->indices.NLSFIndices[ 0 ] ); 1.85 + silk_assert( psDec->psNLSF_CB->order == psDec->LPC_order ); 1.86 + for( i = 0; i < psDec->psNLSF_CB->order; i++ ) { 1.87 + Ix = ec_dec_icdf( psRangeDec, &psDec->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 ); 1.88 + if( Ix == 0 ) { 1.89 + Ix -= ec_dec_icdf( psRangeDec, silk_NLSF_EXT_iCDF, 8 ); 1.90 + } else if( Ix == 2 * NLSF_QUANT_MAX_AMPLITUDE ) { 1.91 + Ix += ec_dec_icdf( psRangeDec, silk_NLSF_EXT_iCDF, 8 ); 1.92 + } 1.93 + psDec->indices.NLSFIndices[ i+1 ] = (opus_int8)( Ix - NLSF_QUANT_MAX_AMPLITUDE ); 1.94 + } 1.95 + 1.96 + /* Decode LSF interpolation factor */ 1.97 + if( psDec->nb_subfr == MAX_NB_SUBFR ) { 1.98 + psDec->indices.NLSFInterpCoef_Q2 = (opus_int8)ec_dec_icdf( psRangeDec, silk_NLSF_interpolation_factor_iCDF, 8 ); 1.99 + } else { 1.100 + psDec->indices.NLSFInterpCoef_Q2 = 4; 1.101 + } 1.102 + 1.103 + if( psDec->indices.signalType == TYPE_VOICED ) 1.104 + { 1.105 + /*********************/ 1.106 + /* Decode pitch lags */ 1.107 + /*********************/ 1.108 + /* Get lag index */ 1.109 + decode_absolute_lagIndex = 1; 1.110 + if( condCoding == CODE_CONDITIONALLY && psDec->ec_prevSignalType == TYPE_VOICED ) { 1.111 + /* Decode Delta index */ 1.112 + delta_lagIndex = (opus_int16)ec_dec_icdf( psRangeDec, silk_pitch_delta_iCDF, 8 ); 1.113 + if( delta_lagIndex > 0 ) { 1.114 + delta_lagIndex = delta_lagIndex - 9; 1.115 + psDec->indices.lagIndex = (opus_int16)( psDec->ec_prevLagIndex + delta_lagIndex ); 1.116 + decode_absolute_lagIndex = 0; 1.117 + } 1.118 + } 1.119 + if( decode_absolute_lagIndex ) { 1.120 + /* Absolute decoding */ 1.121 + psDec->indices.lagIndex = (opus_int16)ec_dec_icdf( psRangeDec, silk_pitch_lag_iCDF, 8 ) * silk_RSHIFT( psDec->fs_kHz, 1 ); 1.122 + psDec->indices.lagIndex += (opus_int16)ec_dec_icdf( psRangeDec, psDec->pitch_lag_low_bits_iCDF, 8 ); 1.123 + } 1.124 + psDec->ec_prevLagIndex = psDec->indices.lagIndex; 1.125 + 1.126 + /* Get countour index */ 1.127 + psDec->indices.contourIndex = (opus_int8)ec_dec_icdf( psRangeDec, psDec->pitch_contour_iCDF, 8 ); 1.128 + 1.129 + /********************/ 1.130 + /* Decode LTP gains */ 1.131 + /********************/ 1.132 + /* Decode PERIndex value */ 1.133 + psDec->indices.PERIndex = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTP_per_index_iCDF, 8 ); 1.134 + 1.135 + for( k = 0; k < psDec->nb_subfr; k++ ) { 1.136 + psDec->indices.LTPIndex[ k ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTP_gain_iCDF_ptrs[ psDec->indices.PERIndex ], 8 ); 1.137 + } 1.138 + 1.139 + /**********************/ 1.140 + /* Decode LTP scaling */ 1.141 + /**********************/ 1.142 + if( condCoding == CODE_INDEPENDENTLY ) { 1.143 + psDec->indices.LTP_scaleIndex = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTPscale_iCDF, 8 ); 1.144 + } else { 1.145 + psDec->indices.LTP_scaleIndex = 0; 1.146 + } 1.147 + } 1.148 + psDec->ec_prevSignalType = psDec->indices.signalType; 1.149 + 1.150 + /***************/ 1.151 + /* Decode seed */ 1.152 + /***************/ 1.153 + psDec->indices.Seed = (opus_int8)ec_dec_icdf( psRangeDec, silk_uniform4_iCDF, 8 ); 1.154 +}