Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /*********************************************************************** |
michael@0 | 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
michael@0 | 3 | Redistribution and use in source and binary forms, with or without |
michael@0 | 4 | modification, are permitted provided that the following conditions |
michael@0 | 5 | are met: |
michael@0 | 6 | - Redistributions of source code must retain the above copyright notice, |
michael@0 | 7 | this list of conditions and the following disclaimer. |
michael@0 | 8 | - Redistributions in binary form must reproduce the above copyright |
michael@0 | 9 | notice, this list of conditions and the following disclaimer in the |
michael@0 | 10 | documentation and/or other materials provided with the distribution. |
michael@0 | 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the |
michael@0 | 12 | names of specific contributors, may be used to endorse or promote |
michael@0 | 13 | products derived from this software without specific prior written |
michael@0 | 14 | permission. |
michael@0 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
michael@0 | 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
michael@0 | 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
michael@0 | 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
michael@0 | 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
michael@0 | 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
michael@0 | 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
michael@0 | 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
michael@0 | 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
michael@0 | 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
michael@0 | 25 | POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 26 | ***********************************************************************/ |
michael@0 | 27 | |
michael@0 | 28 | #ifdef HAVE_CONFIG_H |
michael@0 | 29 | #include "config.h" |
michael@0 | 30 | #endif |
michael@0 | 31 | |
michael@0 | 32 | #include "main.h" |
michael@0 | 33 | |
michael@0 | 34 | /* Decode side-information parameters from payload */ |
michael@0 | 35 | void silk_decode_indices( |
michael@0 | 36 | silk_decoder_state *psDec, /* I/O State */ |
michael@0 | 37 | ec_dec *psRangeDec, /* I/O Compressor data structure */ |
michael@0 | 38 | opus_int FrameIndex, /* I Frame number */ |
michael@0 | 39 | opus_int decode_LBRR, /* I Flag indicating LBRR data is being decoded */ |
michael@0 | 40 | opus_int condCoding /* I The type of conditional coding to use */ |
michael@0 | 41 | ) |
michael@0 | 42 | { |
michael@0 | 43 | opus_int i, k, Ix; |
michael@0 | 44 | opus_int decode_absolute_lagIndex, delta_lagIndex; |
michael@0 | 45 | opus_int16 ec_ix[ MAX_LPC_ORDER ]; |
michael@0 | 46 | opus_uint8 pred_Q8[ MAX_LPC_ORDER ]; |
michael@0 | 47 | |
michael@0 | 48 | /*******************************************/ |
michael@0 | 49 | /* Decode signal type and quantizer offset */ |
michael@0 | 50 | /*******************************************/ |
michael@0 | 51 | if( decode_LBRR || psDec->VAD_flags[ FrameIndex ] ) { |
michael@0 | 52 | Ix = ec_dec_icdf( psRangeDec, silk_type_offset_VAD_iCDF, 8 ) + 2; |
michael@0 | 53 | } else { |
michael@0 | 54 | Ix = ec_dec_icdf( psRangeDec, silk_type_offset_no_VAD_iCDF, 8 ); |
michael@0 | 55 | } |
michael@0 | 56 | psDec->indices.signalType = (opus_int8)silk_RSHIFT( Ix, 1 ); |
michael@0 | 57 | psDec->indices.quantOffsetType = (opus_int8)( Ix & 1 ); |
michael@0 | 58 | |
michael@0 | 59 | /****************/ |
michael@0 | 60 | /* Decode gains */ |
michael@0 | 61 | /****************/ |
michael@0 | 62 | /* First subframe */ |
michael@0 | 63 | if( condCoding == CODE_CONDITIONALLY ) { |
michael@0 | 64 | /* Conditional coding */ |
michael@0 | 65 | psDec->indices.GainsIndices[ 0 ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_delta_gain_iCDF, 8 ); |
michael@0 | 66 | } else { |
michael@0 | 67 | /* Independent coding, in two stages: MSB bits followed by 3 LSBs */ |
michael@0 | 68 | psDec->indices.GainsIndices[ 0 ] = (opus_int8)silk_LSHIFT( ec_dec_icdf( psRangeDec, silk_gain_iCDF[ psDec->indices.signalType ], 8 ), 3 ); |
michael@0 | 69 | psDec->indices.GainsIndices[ 0 ] += (opus_int8)ec_dec_icdf( psRangeDec, silk_uniform8_iCDF, 8 ); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | /* Remaining subframes */ |
michael@0 | 73 | for( i = 1; i < psDec->nb_subfr; i++ ) { |
michael@0 | 74 | psDec->indices.GainsIndices[ i ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_delta_gain_iCDF, 8 ); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | /**********************/ |
michael@0 | 78 | /* Decode LSF Indices */ |
michael@0 | 79 | /**********************/ |
michael@0 | 80 | psDec->indices.NLSFIndices[ 0 ] = (opus_int8)ec_dec_icdf( psRangeDec, &psDec->psNLSF_CB->CB1_iCDF[ ( psDec->indices.signalType >> 1 ) * psDec->psNLSF_CB->nVectors ], 8 ); |
michael@0 | 81 | silk_NLSF_unpack( ec_ix, pred_Q8, psDec->psNLSF_CB, psDec->indices.NLSFIndices[ 0 ] ); |
michael@0 | 82 | silk_assert( psDec->psNLSF_CB->order == psDec->LPC_order ); |
michael@0 | 83 | for( i = 0; i < psDec->psNLSF_CB->order; i++ ) { |
michael@0 | 84 | Ix = ec_dec_icdf( psRangeDec, &psDec->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 ); |
michael@0 | 85 | if( Ix == 0 ) { |
michael@0 | 86 | Ix -= ec_dec_icdf( psRangeDec, silk_NLSF_EXT_iCDF, 8 ); |
michael@0 | 87 | } else if( Ix == 2 * NLSF_QUANT_MAX_AMPLITUDE ) { |
michael@0 | 88 | Ix += ec_dec_icdf( psRangeDec, silk_NLSF_EXT_iCDF, 8 ); |
michael@0 | 89 | } |
michael@0 | 90 | psDec->indices.NLSFIndices[ i+1 ] = (opus_int8)( Ix - NLSF_QUANT_MAX_AMPLITUDE ); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | /* Decode LSF interpolation factor */ |
michael@0 | 94 | if( psDec->nb_subfr == MAX_NB_SUBFR ) { |
michael@0 | 95 | psDec->indices.NLSFInterpCoef_Q2 = (opus_int8)ec_dec_icdf( psRangeDec, silk_NLSF_interpolation_factor_iCDF, 8 ); |
michael@0 | 96 | } else { |
michael@0 | 97 | psDec->indices.NLSFInterpCoef_Q2 = 4; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | if( psDec->indices.signalType == TYPE_VOICED ) |
michael@0 | 101 | { |
michael@0 | 102 | /*********************/ |
michael@0 | 103 | /* Decode pitch lags */ |
michael@0 | 104 | /*********************/ |
michael@0 | 105 | /* Get lag index */ |
michael@0 | 106 | decode_absolute_lagIndex = 1; |
michael@0 | 107 | if( condCoding == CODE_CONDITIONALLY && psDec->ec_prevSignalType == TYPE_VOICED ) { |
michael@0 | 108 | /* Decode Delta index */ |
michael@0 | 109 | delta_lagIndex = (opus_int16)ec_dec_icdf( psRangeDec, silk_pitch_delta_iCDF, 8 ); |
michael@0 | 110 | if( delta_lagIndex > 0 ) { |
michael@0 | 111 | delta_lagIndex = delta_lagIndex - 9; |
michael@0 | 112 | psDec->indices.lagIndex = (opus_int16)( psDec->ec_prevLagIndex + delta_lagIndex ); |
michael@0 | 113 | decode_absolute_lagIndex = 0; |
michael@0 | 114 | } |
michael@0 | 115 | } |
michael@0 | 116 | if( decode_absolute_lagIndex ) { |
michael@0 | 117 | /* Absolute decoding */ |
michael@0 | 118 | psDec->indices.lagIndex = (opus_int16)ec_dec_icdf( psRangeDec, silk_pitch_lag_iCDF, 8 ) * silk_RSHIFT( psDec->fs_kHz, 1 ); |
michael@0 | 119 | psDec->indices.lagIndex += (opus_int16)ec_dec_icdf( psRangeDec, psDec->pitch_lag_low_bits_iCDF, 8 ); |
michael@0 | 120 | } |
michael@0 | 121 | psDec->ec_prevLagIndex = psDec->indices.lagIndex; |
michael@0 | 122 | |
michael@0 | 123 | /* Get countour index */ |
michael@0 | 124 | psDec->indices.contourIndex = (opus_int8)ec_dec_icdf( psRangeDec, psDec->pitch_contour_iCDF, 8 ); |
michael@0 | 125 | |
michael@0 | 126 | /********************/ |
michael@0 | 127 | /* Decode LTP gains */ |
michael@0 | 128 | /********************/ |
michael@0 | 129 | /* Decode PERIndex value */ |
michael@0 | 130 | psDec->indices.PERIndex = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTP_per_index_iCDF, 8 ); |
michael@0 | 131 | |
michael@0 | 132 | for( k = 0; k < psDec->nb_subfr; k++ ) { |
michael@0 | 133 | psDec->indices.LTPIndex[ k ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTP_gain_iCDF_ptrs[ psDec->indices.PERIndex ], 8 ); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | /**********************/ |
michael@0 | 137 | /* Decode LTP scaling */ |
michael@0 | 138 | /**********************/ |
michael@0 | 139 | if( condCoding == CODE_INDEPENDENTLY ) { |
michael@0 | 140 | psDec->indices.LTP_scaleIndex = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTPscale_iCDF, 8 ); |
michael@0 | 141 | } else { |
michael@0 | 142 | psDec->indices.LTP_scaleIndex = 0; |
michael@0 | 143 | } |
michael@0 | 144 | } |
michael@0 | 145 | psDec->ec_prevSignalType = psDec->indices.signalType; |
michael@0 | 146 | |
michael@0 | 147 | /***************/ |
michael@0 | 148 | /* Decode seed */ |
michael@0 | 149 | /***************/ |
michael@0 | 150 | psDec->indices.Seed = (opus_int8)ec_dec_icdf( psRangeDec, silk_uniform4_iCDF, 8 ); |
michael@0 | 151 | } |