media/libopus/silk/float/wrappers_FLP.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libopus/silk/float/wrappers_FLP.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,201 @@
     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_FLP.h"
    1.36 +
    1.37 +/* Wrappers. Calls flp / fix code */
    1.38 +
    1.39 +/* Convert AR filter coefficients to NLSF parameters */
    1.40 +void silk_A2NLSF_FLP(
    1.41 +    opus_int16                      *NLSF_Q15,                          /* O    NLSF vector      [ LPC_order ]              */
    1.42 +    const silk_float                *pAR,                               /* I    LPC coefficients [ LPC_order ]              */
    1.43 +    const opus_int                  LPC_order                           /* I    LPC order                                   */
    1.44 +)
    1.45 +{
    1.46 +    opus_int   i;
    1.47 +    opus_int32 a_fix_Q16[ MAX_LPC_ORDER ];
    1.48 +
    1.49 +    for( i = 0; i < LPC_order; i++ ) {
    1.50 +        a_fix_Q16[ i ] = silk_float2int( pAR[ i ] * 65536.0f );
    1.51 +    }
    1.52 +
    1.53 +    silk_A2NLSF( NLSF_Q15, a_fix_Q16, LPC_order );
    1.54 +}
    1.55 +
    1.56 +/* Convert LSF parameters to AR prediction filter coefficients */
    1.57 +void silk_NLSF2A_FLP(
    1.58 +    silk_float                      *pAR,                               /* O    LPC coefficients [ LPC_order ]              */
    1.59 +    const opus_int16                *NLSF_Q15,                          /* I    NLSF vector      [ LPC_order ]              */
    1.60 +    const opus_int                  LPC_order                           /* I    LPC order                                   */
    1.61 +)
    1.62 +{
    1.63 +    opus_int   i;
    1.64 +    opus_int16 a_fix_Q12[ MAX_LPC_ORDER ];
    1.65 +
    1.66 +    silk_NLSF2A( a_fix_Q12, NLSF_Q15, LPC_order );
    1.67 +
    1.68 +    for( i = 0; i < LPC_order; i++ ) {
    1.69 +        pAR[ i ] = ( silk_float )a_fix_Q12[ i ] * ( 1.0f / 4096.0f );
    1.70 +    }
    1.71 +}
    1.72 +
    1.73 +/******************************************/
    1.74 +/* Floating-point NLSF processing wrapper */
    1.75 +/******************************************/
    1.76 +void silk_process_NLSFs_FLP(
    1.77 +    silk_encoder_state              *psEncC,                            /* I/O  Encoder state                               */
    1.78 +    silk_float                      PredCoef[ 2 ][ MAX_LPC_ORDER ],     /* O    Prediction coefficients                     */
    1.79 +    opus_int16                      NLSF_Q15[      MAX_LPC_ORDER ],     /* I/O  Normalized LSFs (quant out) (0 - (2^15-1))  */
    1.80 +    const opus_int16                prev_NLSF_Q15[ MAX_LPC_ORDER ]      /* I    Previous Normalized LSFs (0 - (2^15-1))     */
    1.81 +)
    1.82 +{
    1.83 +    opus_int     i, j;
    1.84 +    opus_int16   PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
    1.85 +
    1.86 +    silk_process_NLSFs( psEncC, PredCoef_Q12, NLSF_Q15, prev_NLSF_Q15);
    1.87 +
    1.88 +    for( j = 0; j < 2; j++ ) {
    1.89 +        for( i = 0; i < psEncC->predictLPCOrder; i++ ) {
    1.90 +            PredCoef[ j ][ i ] = ( silk_float )PredCoef_Q12[ j ][ i ] * ( 1.0f / 4096.0f );
    1.91 +        }
    1.92 +    }
    1.93 +}
    1.94 +
    1.95 +/****************************************/
    1.96 +/* Floating-point Silk NSQ wrapper      */
    1.97 +/****************************************/
    1.98 +void silk_NSQ_wrapper_FLP(
    1.99 +    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
   1.100 +    silk_encoder_control_FLP        *psEncCtrl,                         /* I/O  Encoder control FLP                         */
   1.101 +    SideInfoIndices                 *psIndices,                         /* I/O  Quantization indices                        */
   1.102 +    silk_nsq_state                  *psNSQ,                             /* I/O  Noise Shaping Quantzation state             */
   1.103 +    opus_int8                       pulses[],                           /* O    Quantized pulse signal                      */
   1.104 +    const silk_float                x[]                                 /* I    Prefiltered input signal                    */
   1.105 +)
   1.106 +{
   1.107 +    opus_int     i, j;
   1.108 +    opus_int32   x_Q3[ MAX_FRAME_LENGTH ];
   1.109 +    opus_int32   Gains_Q16[ MAX_NB_SUBFR ];
   1.110 +    silk_DWORD_ALIGN opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
   1.111 +    opus_int16   LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ];
   1.112 +    opus_int     LTP_scale_Q14;
   1.113 +
   1.114 +    /* Noise shaping parameters */
   1.115 +    opus_int16   AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ];
   1.116 +    opus_int32   LF_shp_Q14[ MAX_NB_SUBFR ];         /* Packs two int16 coefficients per int32 value             */
   1.117 +    opus_int     Lambda_Q10;
   1.118 +    opus_int     Tilt_Q14[ MAX_NB_SUBFR ];
   1.119 +    opus_int     HarmShapeGain_Q14[ MAX_NB_SUBFR ];
   1.120 +
   1.121 +    /* Convert control struct to fix control struct */
   1.122 +    /* Noise shape parameters */
   1.123 +    for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
   1.124 +        for( j = 0; j < psEnc->sCmn.shapingLPCOrder; j++ ) {
   1.125 +            AR2_Q13[ i * MAX_SHAPE_LPC_ORDER + j ] = silk_float2int( psEncCtrl->AR2[ i * MAX_SHAPE_LPC_ORDER + j ] * 8192.0f );
   1.126 +        }
   1.127 +    }
   1.128 +
   1.129 +    for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
   1.130 +        LF_shp_Q14[ i ] =   silk_LSHIFT32( silk_float2int( psEncCtrl->LF_AR_shp[ i ]     * 16384.0f ), 16 ) |
   1.131 +                              (opus_uint16)silk_float2int( psEncCtrl->LF_MA_shp[ i ]     * 16384.0f );
   1.132 +        Tilt_Q14[ i ]   =        (opus_int)silk_float2int( psEncCtrl->Tilt[ i ]          * 16384.0f );
   1.133 +        HarmShapeGain_Q14[ i ] = (opus_int)silk_float2int( psEncCtrl->HarmShapeGain[ i ] * 16384.0f );
   1.134 +    }
   1.135 +    Lambda_Q10 = ( opus_int )silk_float2int( psEncCtrl->Lambda * 1024.0f );
   1.136 +
   1.137 +    /* prediction and coding parameters */
   1.138 +    for( i = 0; i < psEnc->sCmn.nb_subfr * LTP_ORDER; i++ ) {
   1.139 +        LTPCoef_Q14[ i ] = (opus_int16)silk_float2int( psEncCtrl->LTPCoef[ i ] * 16384.0f );
   1.140 +    }
   1.141 +
   1.142 +    for( j = 0; j < 2; j++ ) {
   1.143 +        for( i = 0; i < psEnc->sCmn.predictLPCOrder; i++ ) {
   1.144 +            PredCoef_Q12[ j ][ i ] = (opus_int16)silk_float2int( psEncCtrl->PredCoef[ j ][ i ] * 4096.0f );
   1.145 +        }
   1.146 +    }
   1.147 +
   1.148 +    for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
   1.149 +        Gains_Q16[ i ] = silk_float2int( psEncCtrl->Gains[ i ] * 65536.0f );
   1.150 +        silk_assert( Gains_Q16[ i ] > 0 );
   1.151 +    }
   1.152 +
   1.153 +    if( psIndices->signalType == TYPE_VOICED ) {
   1.154 +        LTP_scale_Q14 = silk_LTPScales_table_Q14[ psIndices->LTP_scaleIndex ];
   1.155 +    } else {
   1.156 +        LTP_scale_Q14 = 0;
   1.157 +    }
   1.158 +
   1.159 +    /* Convert input to fix */
   1.160 +    for( i = 0; i < psEnc->sCmn.frame_length; i++ ) {
   1.161 +        x_Q3[ i ] = silk_float2int( 8.0f * x[ i ] );
   1.162 +    }
   1.163 +
   1.164 +    /* Call NSQ */
   1.165 +    if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {
   1.166 +        silk_NSQ_del_dec( &psEnc->sCmn, psNSQ, psIndices, x_Q3, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14,
   1.167 +            AR2_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14 );
   1.168 +    } else {
   1.169 +        silk_NSQ( &psEnc->sCmn, psNSQ, psIndices, x_Q3, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14,
   1.170 +            AR2_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14 );
   1.171 +    }
   1.172 +}
   1.173 +
   1.174 +/***********************************************/
   1.175 +/* Floating-point Silk LTP quantiation wrapper */
   1.176 +/***********************************************/
   1.177 +void silk_quant_LTP_gains_FLP(
   1.178 +    silk_float                      B[ MAX_NB_SUBFR * LTP_ORDER ],      /* I/O  (Un-)quantized LTP gains                    */
   1.179 +    opus_int8                       cbk_index[ MAX_NB_SUBFR ],          /* O    Codebook index                              */
   1.180 +    opus_int8                       *periodicity_index,                 /* O    Periodicity index                           */
   1.181 +    opus_int32                      *sum_log_gain_Q7,                   /* I/O  Cumulative max prediction gain  */
   1.182 +    const silk_float                W[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I    Error weights                        */
   1.183 +    const opus_int                  mu_Q10,                             /* I    Mu value (R/D tradeoff)                     */
   1.184 +    const opus_int                  lowComplexity,                      /* I    Flag for low complexity                     */
   1.185 +    const opus_int                  nb_subfr                            /* I    number of subframes                         */
   1.186 +)
   1.187 +{
   1.188 +    opus_int   i;
   1.189 +    opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ];
   1.190 +    opus_int32 W_Q18[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ];
   1.191 +
   1.192 +    for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) {
   1.193 +        B_Q14[ i ] = (opus_int16)silk_float2int( B[ i ] * 16384.0f );
   1.194 +    }
   1.195 +    for( i = 0; i < nb_subfr * LTP_ORDER * LTP_ORDER; i++ ) {
   1.196 +        W_Q18[ i ] = (opus_int32)silk_float2int( W[ i ] * 262144.0f );
   1.197 +    }
   1.198 +
   1.199 +    silk_quant_LTP_gains( B_Q14, cbk_index, periodicity_index, sum_log_gain_Q7, W_Q18, mu_Q10, lowComplexity, nb_subfr );
   1.200 +
   1.201 +    for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) {
   1.202 +        B[ i ] = (silk_float)B_Q14[ i ] * ( 1.0f / 16384.0f );
   1.203 +    }
   1.204 +}

mercurial