annotate src/opus-1.3/silk/float/wrappers_FLP.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +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_FLP.h"
Chris@69 33
Chris@69 34 /* Wrappers. Calls flp / fix code */
Chris@69 35
Chris@69 36 /* Convert AR filter coefficients to NLSF parameters */
Chris@69 37 void silk_A2NLSF_FLP(
Chris@69 38 opus_int16 *NLSF_Q15, /* O NLSF vector [ LPC_order ] */
Chris@69 39 const silk_float *pAR, /* I LPC coefficients [ LPC_order ] */
Chris@69 40 const opus_int LPC_order /* I LPC order */
Chris@69 41 )
Chris@69 42 {
Chris@69 43 opus_int i;
Chris@69 44 opus_int32 a_fix_Q16[ MAX_LPC_ORDER ];
Chris@69 45
Chris@69 46 for( i = 0; i < LPC_order; i++ ) {
Chris@69 47 a_fix_Q16[ i ] = silk_float2int( pAR[ i ] * 65536.0f );
Chris@69 48 }
Chris@69 49
Chris@69 50 silk_A2NLSF( NLSF_Q15, a_fix_Q16, LPC_order );
Chris@69 51 }
Chris@69 52
Chris@69 53 /* Convert LSF parameters to AR prediction filter coefficients */
Chris@69 54 void silk_NLSF2A_FLP(
Chris@69 55 silk_float *pAR, /* O LPC coefficients [ LPC_order ] */
Chris@69 56 const opus_int16 *NLSF_Q15, /* I NLSF vector [ LPC_order ] */
Chris@69 57 const opus_int LPC_order, /* I LPC order */
Chris@69 58 int arch /* I Run-time architecture */
Chris@69 59 )
Chris@69 60 {
Chris@69 61 opus_int i;
Chris@69 62 opus_int16 a_fix_Q12[ MAX_LPC_ORDER ];
Chris@69 63
Chris@69 64 silk_NLSF2A( a_fix_Q12, NLSF_Q15, LPC_order, arch );
Chris@69 65
Chris@69 66 for( i = 0; i < LPC_order; i++ ) {
Chris@69 67 pAR[ i ] = ( silk_float )a_fix_Q12[ i ] * ( 1.0f / 4096.0f );
Chris@69 68 }
Chris@69 69 }
Chris@69 70
Chris@69 71 /******************************************/
Chris@69 72 /* Floating-point NLSF processing wrapper */
Chris@69 73 /******************************************/
Chris@69 74 void silk_process_NLSFs_FLP(
Chris@69 75 silk_encoder_state *psEncC, /* I/O Encoder state */
Chris@69 76 silk_float PredCoef[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */
Chris@69 77 opus_int16 NLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
Chris@69 78 const opus_int16 prev_NLSF_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
Chris@69 79 )
Chris@69 80 {
Chris@69 81 opus_int i, j;
Chris@69 82 opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
Chris@69 83
Chris@69 84 silk_process_NLSFs( psEncC, PredCoef_Q12, NLSF_Q15, prev_NLSF_Q15);
Chris@69 85
Chris@69 86 for( j = 0; j < 2; j++ ) {
Chris@69 87 for( i = 0; i < psEncC->predictLPCOrder; i++ ) {
Chris@69 88 PredCoef[ j ][ i ] = ( silk_float )PredCoef_Q12[ j ][ i ] * ( 1.0f / 4096.0f );
Chris@69 89 }
Chris@69 90 }
Chris@69 91 }
Chris@69 92
Chris@69 93 /****************************************/
Chris@69 94 /* Floating-point Silk NSQ wrapper */
Chris@69 95 /****************************************/
Chris@69 96 void silk_NSQ_wrapper_FLP(
Chris@69 97 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
Chris@69 98 silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */
Chris@69 99 SideInfoIndices *psIndices, /* I/O Quantization indices */
Chris@69 100 silk_nsq_state *psNSQ, /* I/O Noise Shaping Quantzation state */
Chris@69 101 opus_int8 pulses[], /* O Quantized pulse signal */
Chris@69 102 const silk_float x[] /* I Prefiltered input signal */
Chris@69 103 )
Chris@69 104 {
Chris@69 105 opus_int i, j;
Chris@69 106 opus_int16 x16[ MAX_FRAME_LENGTH ];
Chris@69 107 opus_int32 Gains_Q16[ MAX_NB_SUBFR ];
Chris@69 108 silk_DWORD_ALIGN opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
Chris@69 109 opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ];
Chris@69 110 opus_int LTP_scale_Q14;
Chris@69 111
Chris@69 112 /* Noise shaping parameters */
Chris@69 113 opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ];
Chris@69 114 opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ]; /* Packs two int16 coefficients per int32 value */
Chris@69 115 opus_int Lambda_Q10;
Chris@69 116 opus_int Tilt_Q14[ MAX_NB_SUBFR ];
Chris@69 117 opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ];
Chris@69 118
Chris@69 119 /* Convert control struct to fix control struct */
Chris@69 120 /* Noise shape parameters */
Chris@69 121 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
Chris@69 122 for( j = 0; j < psEnc->sCmn.shapingLPCOrder; j++ ) {
Chris@69 123 AR_Q13[ i * MAX_SHAPE_LPC_ORDER + j ] = silk_float2int( psEncCtrl->AR[ i * MAX_SHAPE_LPC_ORDER + j ] * 8192.0f );
Chris@69 124 }
Chris@69 125 }
Chris@69 126
Chris@69 127 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
Chris@69 128 LF_shp_Q14[ i ] = silk_LSHIFT32( silk_float2int( psEncCtrl->LF_AR_shp[ i ] * 16384.0f ), 16 ) |
Chris@69 129 (opus_uint16)silk_float2int( psEncCtrl->LF_MA_shp[ i ] * 16384.0f );
Chris@69 130 Tilt_Q14[ i ] = (opus_int)silk_float2int( psEncCtrl->Tilt[ i ] * 16384.0f );
Chris@69 131 HarmShapeGain_Q14[ i ] = (opus_int)silk_float2int( psEncCtrl->HarmShapeGain[ i ] * 16384.0f );
Chris@69 132 }
Chris@69 133 Lambda_Q10 = ( opus_int )silk_float2int( psEncCtrl->Lambda * 1024.0f );
Chris@69 134
Chris@69 135 /* prediction and coding parameters */
Chris@69 136 for( i = 0; i < psEnc->sCmn.nb_subfr * LTP_ORDER; i++ ) {
Chris@69 137 LTPCoef_Q14[ i ] = (opus_int16)silk_float2int( psEncCtrl->LTPCoef[ i ] * 16384.0f );
Chris@69 138 }
Chris@69 139
Chris@69 140 for( j = 0; j < 2; j++ ) {
Chris@69 141 for( i = 0; i < psEnc->sCmn.predictLPCOrder; i++ ) {
Chris@69 142 PredCoef_Q12[ j ][ i ] = (opus_int16)silk_float2int( psEncCtrl->PredCoef[ j ][ i ] * 4096.0f );
Chris@69 143 }
Chris@69 144 }
Chris@69 145
Chris@69 146 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
Chris@69 147 Gains_Q16[ i ] = silk_float2int( psEncCtrl->Gains[ i ] * 65536.0f );
Chris@69 148 silk_assert( Gains_Q16[ i ] > 0 );
Chris@69 149 }
Chris@69 150
Chris@69 151 if( psIndices->signalType == TYPE_VOICED ) {
Chris@69 152 LTP_scale_Q14 = silk_LTPScales_table_Q14[ psIndices->LTP_scaleIndex ];
Chris@69 153 } else {
Chris@69 154 LTP_scale_Q14 = 0;
Chris@69 155 }
Chris@69 156
Chris@69 157 /* Convert input to fix */
Chris@69 158 for( i = 0; i < psEnc->sCmn.frame_length; i++ ) {
Chris@69 159 x16[ i ] = silk_float2int( x[ i ] );
Chris@69 160 }
Chris@69 161
Chris@69 162 /* Call NSQ */
Chris@69 163 if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {
Chris@69 164 silk_NSQ_del_dec( &psEnc->sCmn, psNSQ, psIndices, x16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14,
Chris@69 165 AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch );
Chris@69 166 } else {
Chris@69 167 silk_NSQ( &psEnc->sCmn, psNSQ, psIndices, x16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14,
Chris@69 168 AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch );
Chris@69 169 }
Chris@69 170 }
Chris@69 171
Chris@69 172 /***********************************************/
Chris@69 173 /* Floating-point Silk LTP quantiation wrapper */
Chris@69 174 /***********************************************/
Chris@69 175 void silk_quant_LTP_gains_FLP(
Chris@69 176 silk_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* O Quantized LTP gains */
Chris@69 177 opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */
Chris@69 178 opus_int8 *periodicity_index, /* O Periodicity index */
Chris@69 179 opus_int32 *sum_log_gain_Q7, /* I/O Cumulative max prediction gain */
Chris@69 180 silk_float *pred_gain_dB, /* O LTP prediction gain */
Chris@69 181 const silk_float XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Correlation matrix */
Chris@69 182 const silk_float xX[ MAX_NB_SUBFR * LTP_ORDER ], /* I Correlation vector */
Chris@69 183 const opus_int subfr_len, /* I Number of samples per subframe */
Chris@69 184 const opus_int nb_subfr, /* I Number of subframes */
Chris@69 185 int arch /* I Run-time architecture */
Chris@69 186 )
Chris@69 187 {
Chris@69 188 opus_int i, pred_gain_dB_Q7;
Chris@69 189 opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ];
Chris@69 190 opus_int32 XX_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ];
Chris@69 191 opus_int32 xX_Q17[ MAX_NB_SUBFR * LTP_ORDER ];
Chris@69 192
Chris@69 193 for( i = 0; i < nb_subfr * LTP_ORDER * LTP_ORDER; i++ ) {
Chris@69 194 XX_Q17[ i ] = (opus_int32)silk_float2int( XX[ i ] * 131072.0f );
Chris@69 195 }
Chris@69 196 for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) {
Chris@69 197 xX_Q17[ i ] = (opus_int32)silk_float2int( xX[ i ] * 131072.0f );
Chris@69 198 }
Chris@69 199
Chris@69 200 silk_quant_LTP_gains( B_Q14, cbk_index, periodicity_index, sum_log_gain_Q7, &pred_gain_dB_Q7, XX_Q17, xX_Q17, subfr_len, nb_subfr, arch );
Chris@69 201
Chris@69 202 for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) {
Chris@69 203 B[ i ] = (silk_float)B_Q14[ i ] * ( 1.0f / 16384.0f );
Chris@69 204 }
Chris@69 205
Chris@69 206 *pred_gain_dB = (silk_float)pred_gain_dB_Q7 * ( 1.0f / 128.0f );
Chris@69 207 }