annotate src/opus-1.3/silk/float/wrappers_FLP.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 4664ac0c1032
children
rev   line source
cannam@154 1 /***********************************************************************
cannam@154 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
cannam@154 3 Redistribution and use in source and binary forms, with or without
cannam@154 4 modification, are permitted provided that the following conditions
cannam@154 5 are met:
cannam@154 6 - Redistributions of source code must retain the above copyright notice,
cannam@154 7 this list of conditions and the following disclaimer.
cannam@154 8 - Redistributions in binary form must reproduce the above copyright
cannam@154 9 notice, this list of conditions and the following disclaimer in the
cannam@154 10 documentation and/or other materials provided with the distribution.
cannam@154 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
cannam@154 12 names of specific contributors, may be used to endorse or promote
cannam@154 13 products derived from this software without specific prior written
cannam@154 14 permission.
cannam@154 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cannam@154 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cannam@154 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
cannam@154 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
cannam@154 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
cannam@154 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
cannam@154 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
cannam@154 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
cannam@154 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
cannam@154 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
cannam@154 25 POSSIBILITY OF SUCH DAMAGE.
cannam@154 26 ***********************************************************************/
cannam@154 27
cannam@154 28 #ifdef HAVE_CONFIG_H
cannam@154 29 #include "config.h"
cannam@154 30 #endif
cannam@154 31
cannam@154 32 #include "main_FLP.h"
cannam@154 33
cannam@154 34 /* Wrappers. Calls flp / fix code */
cannam@154 35
cannam@154 36 /* Convert AR filter coefficients to NLSF parameters */
cannam@154 37 void silk_A2NLSF_FLP(
cannam@154 38 opus_int16 *NLSF_Q15, /* O NLSF vector [ LPC_order ] */
cannam@154 39 const silk_float *pAR, /* I LPC coefficients [ LPC_order ] */
cannam@154 40 const opus_int LPC_order /* I LPC order */
cannam@154 41 )
cannam@154 42 {
cannam@154 43 opus_int i;
cannam@154 44 opus_int32 a_fix_Q16[ MAX_LPC_ORDER ];
cannam@154 45
cannam@154 46 for( i = 0; i < LPC_order; i++ ) {
cannam@154 47 a_fix_Q16[ i ] = silk_float2int( pAR[ i ] * 65536.0f );
cannam@154 48 }
cannam@154 49
cannam@154 50 silk_A2NLSF( NLSF_Q15, a_fix_Q16, LPC_order );
cannam@154 51 }
cannam@154 52
cannam@154 53 /* Convert LSF parameters to AR prediction filter coefficients */
cannam@154 54 void silk_NLSF2A_FLP(
cannam@154 55 silk_float *pAR, /* O LPC coefficients [ LPC_order ] */
cannam@154 56 const opus_int16 *NLSF_Q15, /* I NLSF vector [ LPC_order ] */
cannam@154 57 const opus_int LPC_order, /* I LPC order */
cannam@154 58 int arch /* I Run-time architecture */
cannam@154 59 )
cannam@154 60 {
cannam@154 61 opus_int i;
cannam@154 62 opus_int16 a_fix_Q12[ MAX_LPC_ORDER ];
cannam@154 63
cannam@154 64 silk_NLSF2A( a_fix_Q12, NLSF_Q15, LPC_order, arch );
cannam@154 65
cannam@154 66 for( i = 0; i < LPC_order; i++ ) {
cannam@154 67 pAR[ i ] = ( silk_float )a_fix_Q12[ i ] * ( 1.0f / 4096.0f );
cannam@154 68 }
cannam@154 69 }
cannam@154 70
cannam@154 71 /******************************************/
cannam@154 72 /* Floating-point NLSF processing wrapper */
cannam@154 73 /******************************************/
cannam@154 74 void silk_process_NLSFs_FLP(
cannam@154 75 silk_encoder_state *psEncC, /* I/O Encoder state */
cannam@154 76 silk_float PredCoef[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */
cannam@154 77 opus_int16 NLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
cannam@154 78 const opus_int16 prev_NLSF_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
cannam@154 79 )
cannam@154 80 {
cannam@154 81 opus_int i, j;
cannam@154 82 opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
cannam@154 83
cannam@154 84 silk_process_NLSFs( psEncC, PredCoef_Q12, NLSF_Q15, prev_NLSF_Q15);
cannam@154 85
cannam@154 86 for( j = 0; j < 2; j++ ) {
cannam@154 87 for( i = 0; i < psEncC->predictLPCOrder; i++ ) {
cannam@154 88 PredCoef[ j ][ i ] = ( silk_float )PredCoef_Q12[ j ][ i ] * ( 1.0f / 4096.0f );
cannam@154 89 }
cannam@154 90 }
cannam@154 91 }
cannam@154 92
cannam@154 93 /****************************************/
cannam@154 94 /* Floating-point Silk NSQ wrapper */
cannam@154 95 /****************************************/
cannam@154 96 void silk_NSQ_wrapper_FLP(
cannam@154 97 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
cannam@154 98 silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */
cannam@154 99 SideInfoIndices *psIndices, /* I/O Quantization indices */
cannam@154 100 silk_nsq_state *psNSQ, /* I/O Noise Shaping Quantzation state */
cannam@154 101 opus_int8 pulses[], /* O Quantized pulse signal */
cannam@154 102 const silk_float x[] /* I Prefiltered input signal */
cannam@154 103 )
cannam@154 104 {
cannam@154 105 opus_int i, j;
cannam@154 106 opus_int16 x16[ MAX_FRAME_LENGTH ];
cannam@154 107 opus_int32 Gains_Q16[ MAX_NB_SUBFR ];
cannam@154 108 silk_DWORD_ALIGN opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
cannam@154 109 opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ];
cannam@154 110 opus_int LTP_scale_Q14;
cannam@154 111
cannam@154 112 /* Noise shaping parameters */
cannam@154 113 opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ];
cannam@154 114 opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ]; /* Packs two int16 coefficients per int32 value */
cannam@154 115 opus_int Lambda_Q10;
cannam@154 116 opus_int Tilt_Q14[ MAX_NB_SUBFR ];
cannam@154 117 opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ];
cannam@154 118
cannam@154 119 /* Convert control struct to fix control struct */
cannam@154 120 /* Noise shape parameters */
cannam@154 121 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
cannam@154 122 for( j = 0; j < psEnc->sCmn.shapingLPCOrder; j++ ) {
cannam@154 123 AR_Q13[ i * MAX_SHAPE_LPC_ORDER + j ] = silk_float2int( psEncCtrl->AR[ i * MAX_SHAPE_LPC_ORDER + j ] * 8192.0f );
cannam@154 124 }
cannam@154 125 }
cannam@154 126
cannam@154 127 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
cannam@154 128 LF_shp_Q14[ i ] = silk_LSHIFT32( silk_float2int( psEncCtrl->LF_AR_shp[ i ] * 16384.0f ), 16 ) |
cannam@154 129 (opus_uint16)silk_float2int( psEncCtrl->LF_MA_shp[ i ] * 16384.0f );
cannam@154 130 Tilt_Q14[ i ] = (opus_int)silk_float2int( psEncCtrl->Tilt[ i ] * 16384.0f );
cannam@154 131 HarmShapeGain_Q14[ i ] = (opus_int)silk_float2int( psEncCtrl->HarmShapeGain[ i ] * 16384.0f );
cannam@154 132 }
cannam@154 133 Lambda_Q10 = ( opus_int )silk_float2int( psEncCtrl->Lambda * 1024.0f );
cannam@154 134
cannam@154 135 /* prediction and coding parameters */
cannam@154 136 for( i = 0; i < psEnc->sCmn.nb_subfr * LTP_ORDER; i++ ) {
cannam@154 137 LTPCoef_Q14[ i ] = (opus_int16)silk_float2int( psEncCtrl->LTPCoef[ i ] * 16384.0f );
cannam@154 138 }
cannam@154 139
cannam@154 140 for( j = 0; j < 2; j++ ) {
cannam@154 141 for( i = 0; i < psEnc->sCmn.predictLPCOrder; i++ ) {
cannam@154 142 PredCoef_Q12[ j ][ i ] = (opus_int16)silk_float2int( psEncCtrl->PredCoef[ j ][ i ] * 4096.0f );
cannam@154 143 }
cannam@154 144 }
cannam@154 145
cannam@154 146 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
cannam@154 147 Gains_Q16[ i ] = silk_float2int( psEncCtrl->Gains[ i ] * 65536.0f );
cannam@154 148 silk_assert( Gains_Q16[ i ] > 0 );
cannam@154 149 }
cannam@154 150
cannam@154 151 if( psIndices->signalType == TYPE_VOICED ) {
cannam@154 152 LTP_scale_Q14 = silk_LTPScales_table_Q14[ psIndices->LTP_scaleIndex ];
cannam@154 153 } else {
cannam@154 154 LTP_scale_Q14 = 0;
cannam@154 155 }
cannam@154 156
cannam@154 157 /* Convert input to fix */
cannam@154 158 for( i = 0; i < psEnc->sCmn.frame_length; i++ ) {
cannam@154 159 x16[ i ] = silk_float2int( x[ i ] );
cannam@154 160 }
cannam@154 161
cannam@154 162 /* Call NSQ */
cannam@154 163 if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {
cannam@154 164 silk_NSQ_del_dec( &psEnc->sCmn, psNSQ, psIndices, x16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14,
cannam@154 165 AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch );
cannam@154 166 } else {
cannam@154 167 silk_NSQ( &psEnc->sCmn, psNSQ, psIndices, x16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14,
cannam@154 168 AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch );
cannam@154 169 }
cannam@154 170 }
cannam@154 171
cannam@154 172 /***********************************************/
cannam@154 173 /* Floating-point Silk LTP quantiation wrapper */
cannam@154 174 /***********************************************/
cannam@154 175 void silk_quant_LTP_gains_FLP(
cannam@154 176 silk_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* O Quantized LTP gains */
cannam@154 177 opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */
cannam@154 178 opus_int8 *periodicity_index, /* O Periodicity index */
cannam@154 179 opus_int32 *sum_log_gain_Q7, /* I/O Cumulative max prediction gain */
cannam@154 180 silk_float *pred_gain_dB, /* O LTP prediction gain */
cannam@154 181 const silk_float XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Correlation matrix */
cannam@154 182 const silk_float xX[ MAX_NB_SUBFR * LTP_ORDER ], /* I Correlation vector */
cannam@154 183 const opus_int subfr_len, /* I Number of samples per subframe */
cannam@154 184 const opus_int nb_subfr, /* I Number of subframes */
cannam@154 185 int arch /* I Run-time architecture */
cannam@154 186 )
cannam@154 187 {
cannam@154 188 opus_int i, pred_gain_dB_Q7;
cannam@154 189 opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ];
cannam@154 190 opus_int32 XX_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ];
cannam@154 191 opus_int32 xX_Q17[ MAX_NB_SUBFR * LTP_ORDER ];
cannam@154 192
cannam@154 193 for( i = 0; i < nb_subfr * LTP_ORDER * LTP_ORDER; i++ ) {
cannam@154 194 XX_Q17[ i ] = (opus_int32)silk_float2int( XX[ i ] * 131072.0f );
cannam@154 195 }
cannam@154 196 for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) {
cannam@154 197 xX_Q17[ i ] = (opus_int32)silk_float2int( xX[ i ] * 131072.0f );
cannam@154 198 }
cannam@154 199
cannam@154 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 );
cannam@154 201
cannam@154 202 for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) {
cannam@154 203 B[ i ] = (silk_float)B_Q14[ i ] * ( 1.0f / 16384.0f );
cannam@154 204 }
cannam@154 205
cannam@154 206 *pred_gain_dB = (silk_float)pred_gain_dB_Q7 * ( 1.0f / 128.0f );
cannam@154 207 }