annotate src/opus-1.3/silk/encode_indices.c @ 79:91c729825bca pa_catalina

Update build for AUDIO_COMPONENT_FIX
author Chris Cannam
date Wed, 30 Oct 2019 12:40:34 +0000
parents 7aeed7906520
children
rev   line source
Chris@69 1 /***********************************************************************
Chris@69 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
Chris@69 3 Redistribution and use in source and binary forms, with or without
Chris@69 4 modification, are permitted provided that the following conditions
Chris@69 5 are met:
Chris@69 6 - Redistributions of source code must retain the above copyright notice,
Chris@69 7 this list of conditions and the following disclaimer.
Chris@69 8 - Redistributions in binary form must reproduce the above copyright
Chris@69 9 notice, this list of conditions and the following disclaimer in the
Chris@69 10 documentation and/or other materials provided with the distribution.
Chris@69 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
Chris@69 12 names of specific contributors, may be used to endorse or promote
Chris@69 13 products derived from this software without specific prior written
Chris@69 14 permission.
Chris@69 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Chris@69 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Chris@69 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Chris@69 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Chris@69 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Chris@69 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Chris@69 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Chris@69 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Chris@69 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Chris@69 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Chris@69 25 POSSIBILITY OF SUCH DAMAGE.
Chris@69 26 ***********************************************************************/
Chris@69 27
Chris@69 28 #ifdef HAVE_CONFIG_H
Chris@69 29 #include "config.h"
Chris@69 30 #endif
Chris@69 31
Chris@69 32 #include "main.h"
Chris@69 33
Chris@69 34 /* Encode side-information parameters to payload */
Chris@69 35 void silk_encode_indices(
Chris@69 36 silk_encoder_state *psEncC, /* I/O Encoder state */
Chris@69 37 ec_enc *psRangeEnc, /* I/O Compressor data structure */
Chris@69 38 opus_int FrameIndex, /* I Frame number */
Chris@69 39 opus_int encode_LBRR, /* I Flag indicating LBRR data is being encoded */
Chris@69 40 opus_int condCoding /* I The type of conditional coding to use */
Chris@69 41 )
Chris@69 42 {
Chris@69 43 opus_int i, k, typeOffset;
Chris@69 44 opus_int encode_absolute_lagIndex, delta_lagIndex;
Chris@69 45 opus_int16 ec_ix[ MAX_LPC_ORDER ];
Chris@69 46 opus_uint8 pred_Q8[ MAX_LPC_ORDER ];
Chris@69 47 const SideInfoIndices *psIndices;
Chris@69 48
Chris@69 49 if( encode_LBRR ) {
Chris@69 50 psIndices = &psEncC->indices_LBRR[ FrameIndex ];
Chris@69 51 } else {
Chris@69 52 psIndices = &psEncC->indices;
Chris@69 53 }
Chris@69 54
Chris@69 55 /*******************************************/
Chris@69 56 /* Encode signal type and quantizer offset */
Chris@69 57 /*******************************************/
Chris@69 58 typeOffset = 2 * psIndices->signalType + psIndices->quantOffsetType;
Chris@69 59 celt_assert( typeOffset >= 0 && typeOffset < 6 );
Chris@69 60 celt_assert( encode_LBRR == 0 || typeOffset >= 2 );
Chris@69 61 if( encode_LBRR || typeOffset >= 2 ) {
Chris@69 62 ec_enc_icdf( psRangeEnc, typeOffset - 2, silk_type_offset_VAD_iCDF, 8 );
Chris@69 63 } else {
Chris@69 64 ec_enc_icdf( psRangeEnc, typeOffset, silk_type_offset_no_VAD_iCDF, 8 );
Chris@69 65 }
Chris@69 66
Chris@69 67 /****************/
Chris@69 68 /* Encode gains */
Chris@69 69 /****************/
Chris@69 70 /* first subframe */
Chris@69 71 if( condCoding == CODE_CONDITIONALLY ) {
Chris@69 72 /* conditional coding */
Chris@69 73 silk_assert( psIndices->GainsIndices[ 0 ] >= 0 && psIndices->GainsIndices[ 0 ] < MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1 );
Chris@69 74 ec_enc_icdf( psRangeEnc, psIndices->GainsIndices[ 0 ], silk_delta_gain_iCDF, 8 );
Chris@69 75 } else {
Chris@69 76 /* independent coding, in two stages: MSB bits followed by 3 LSBs */
Chris@69 77 silk_assert( psIndices->GainsIndices[ 0 ] >= 0 && psIndices->GainsIndices[ 0 ] < N_LEVELS_QGAIN );
Chris@69 78 ec_enc_icdf( psRangeEnc, silk_RSHIFT( psIndices->GainsIndices[ 0 ], 3 ), silk_gain_iCDF[ psIndices->signalType ], 8 );
Chris@69 79 ec_enc_icdf( psRangeEnc, psIndices->GainsIndices[ 0 ] & 7, silk_uniform8_iCDF, 8 );
Chris@69 80 }
Chris@69 81
Chris@69 82 /* remaining subframes */
Chris@69 83 for( i = 1; i < psEncC->nb_subfr; i++ ) {
Chris@69 84 silk_assert( psIndices->GainsIndices[ i ] >= 0 && psIndices->GainsIndices[ i ] < MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1 );
Chris@69 85 ec_enc_icdf( psRangeEnc, psIndices->GainsIndices[ i ], silk_delta_gain_iCDF, 8 );
Chris@69 86 }
Chris@69 87
Chris@69 88 /****************/
Chris@69 89 /* Encode NLSFs */
Chris@69 90 /****************/
Chris@69 91 ec_enc_icdf( psRangeEnc, psIndices->NLSFIndices[ 0 ], &psEncC->psNLSF_CB->CB1_iCDF[ ( psIndices->signalType >> 1 ) * psEncC->psNLSF_CB->nVectors ], 8 );
Chris@69 92 silk_NLSF_unpack( ec_ix, pred_Q8, psEncC->psNLSF_CB, psIndices->NLSFIndices[ 0 ] );
Chris@69 93 celt_assert( psEncC->psNLSF_CB->order == psEncC->predictLPCOrder );
Chris@69 94 for( i = 0; i < psEncC->psNLSF_CB->order; i++ ) {
Chris@69 95 if( psIndices->NLSFIndices[ i+1 ] >= NLSF_QUANT_MAX_AMPLITUDE ) {
Chris@69 96 ec_enc_icdf( psRangeEnc, 2 * NLSF_QUANT_MAX_AMPLITUDE, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 );
Chris@69 97 ec_enc_icdf( psRangeEnc, psIndices->NLSFIndices[ i+1 ] - NLSF_QUANT_MAX_AMPLITUDE, silk_NLSF_EXT_iCDF, 8 );
Chris@69 98 } else if( psIndices->NLSFIndices[ i+1 ] <= -NLSF_QUANT_MAX_AMPLITUDE ) {
Chris@69 99 ec_enc_icdf( psRangeEnc, 0, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 );
Chris@69 100 ec_enc_icdf( psRangeEnc, -psIndices->NLSFIndices[ i+1 ] - NLSF_QUANT_MAX_AMPLITUDE, silk_NLSF_EXT_iCDF, 8 );
Chris@69 101 } else {
Chris@69 102 ec_enc_icdf( psRangeEnc, psIndices->NLSFIndices[ i+1 ] + NLSF_QUANT_MAX_AMPLITUDE, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 );
Chris@69 103 }
Chris@69 104 }
Chris@69 105
Chris@69 106 /* Encode NLSF interpolation factor */
Chris@69 107 if( psEncC->nb_subfr == MAX_NB_SUBFR ) {
Chris@69 108 silk_assert( psIndices->NLSFInterpCoef_Q2 >= 0 && psIndices->NLSFInterpCoef_Q2 < 5 );
Chris@69 109 ec_enc_icdf( psRangeEnc, psIndices->NLSFInterpCoef_Q2, silk_NLSF_interpolation_factor_iCDF, 8 );
Chris@69 110 }
Chris@69 111
Chris@69 112 if( psIndices->signalType == TYPE_VOICED )
Chris@69 113 {
Chris@69 114 /*********************/
Chris@69 115 /* Encode pitch lags */
Chris@69 116 /*********************/
Chris@69 117 /* lag index */
Chris@69 118 encode_absolute_lagIndex = 1;
Chris@69 119 if( condCoding == CODE_CONDITIONALLY && psEncC->ec_prevSignalType == TYPE_VOICED ) {
Chris@69 120 /* Delta Encoding */
Chris@69 121 delta_lagIndex = psIndices->lagIndex - psEncC->ec_prevLagIndex;
Chris@69 122 if( delta_lagIndex < -8 || delta_lagIndex > 11 ) {
Chris@69 123 delta_lagIndex = 0;
Chris@69 124 } else {
Chris@69 125 delta_lagIndex = delta_lagIndex + 9;
Chris@69 126 encode_absolute_lagIndex = 0; /* Only use delta */
Chris@69 127 }
Chris@69 128 silk_assert( delta_lagIndex >= 0 && delta_lagIndex < 21 );
Chris@69 129 ec_enc_icdf( psRangeEnc, delta_lagIndex, silk_pitch_delta_iCDF, 8 );
Chris@69 130 }
Chris@69 131 if( encode_absolute_lagIndex ) {
Chris@69 132 /* Absolute encoding */
Chris@69 133 opus_int32 pitch_high_bits, pitch_low_bits;
Chris@69 134 pitch_high_bits = silk_DIV32_16( psIndices->lagIndex, silk_RSHIFT( psEncC->fs_kHz, 1 ) );
Chris@69 135 pitch_low_bits = psIndices->lagIndex - silk_SMULBB( pitch_high_bits, silk_RSHIFT( psEncC->fs_kHz, 1 ) );
Chris@69 136 silk_assert( pitch_low_bits < psEncC->fs_kHz / 2 );
Chris@69 137 silk_assert( pitch_high_bits < 32 );
Chris@69 138 ec_enc_icdf( psRangeEnc, pitch_high_bits, silk_pitch_lag_iCDF, 8 );
Chris@69 139 ec_enc_icdf( psRangeEnc, pitch_low_bits, psEncC->pitch_lag_low_bits_iCDF, 8 );
Chris@69 140 }
Chris@69 141 psEncC->ec_prevLagIndex = psIndices->lagIndex;
Chris@69 142
Chris@69 143 /* Countour index */
Chris@69 144 silk_assert( psIndices->contourIndex >= 0 );
Chris@69 145 silk_assert( ( psIndices->contourIndex < 34 && psEncC->fs_kHz > 8 && psEncC->nb_subfr == 4 ) ||
Chris@69 146 ( psIndices->contourIndex < 11 && psEncC->fs_kHz == 8 && psEncC->nb_subfr == 4 ) ||
Chris@69 147 ( psIndices->contourIndex < 12 && psEncC->fs_kHz > 8 && psEncC->nb_subfr == 2 ) ||
Chris@69 148 ( psIndices->contourIndex < 3 && psEncC->fs_kHz == 8 && psEncC->nb_subfr == 2 ) );
Chris@69 149 ec_enc_icdf( psRangeEnc, psIndices->contourIndex, psEncC->pitch_contour_iCDF, 8 );
Chris@69 150
Chris@69 151 /********************/
Chris@69 152 /* Encode LTP gains */
Chris@69 153 /********************/
Chris@69 154 /* PERIndex value */
Chris@69 155 silk_assert( psIndices->PERIndex >= 0 && psIndices->PERIndex < 3 );
Chris@69 156 ec_enc_icdf( psRangeEnc, psIndices->PERIndex, silk_LTP_per_index_iCDF, 8 );
Chris@69 157
Chris@69 158 /* Codebook Indices */
Chris@69 159 for( k = 0; k < psEncC->nb_subfr; k++ ) {
Chris@69 160 silk_assert( psIndices->LTPIndex[ k ] >= 0 && psIndices->LTPIndex[ k ] < ( 8 << psIndices->PERIndex ) );
Chris@69 161 ec_enc_icdf( psRangeEnc, psIndices->LTPIndex[ k ], silk_LTP_gain_iCDF_ptrs[ psIndices->PERIndex ], 8 );
Chris@69 162 }
Chris@69 163
Chris@69 164 /**********************/
Chris@69 165 /* Encode LTP scaling */
Chris@69 166 /**********************/
Chris@69 167 if( condCoding == CODE_INDEPENDENTLY ) {
Chris@69 168 silk_assert( psIndices->LTP_scaleIndex >= 0 && psIndices->LTP_scaleIndex < 3 );
Chris@69 169 ec_enc_icdf( psRangeEnc, psIndices->LTP_scaleIndex, silk_LTPscale_iCDF, 8 );
Chris@69 170 }
Chris@69 171 silk_assert( !condCoding || psIndices->LTP_scaleIndex == 0 );
Chris@69 172 }
Chris@69 173
Chris@69 174 psEncC->ec_prevSignalType = psIndices->signalType;
Chris@69 175
Chris@69 176 /***************/
Chris@69 177 /* Encode seed */
Chris@69 178 /***************/
Chris@69 179 silk_assert( psIndices->Seed >= 0 && psIndices->Seed < 4 );
Chris@69 180 ec_enc_icdf( psRangeEnc, psIndices->Seed, silk_uniform4_iCDF, 8 );
Chris@69 181 }