tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

main_FLP.h (19524B)


      1 /***********************************************************************
      2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
      3 Redistribution and use in source and binary forms, with or without
      4 modification, are permitted provided that the following conditions
      5 are met:
      6 - Redistributions of source code must retain the above copyright notice,
      7 this list of conditions and the following disclaimer.
      8 - Redistributions in binary form must reproduce the above copyright
      9 notice, this list of conditions and the following disclaimer in the
     10 documentation and/or other materials provided with the distribution.
     11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
     12 names of specific contributors, may be used to endorse or promote
     13 products derived from this software without specific prior written
     14 permission.
     15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25 POSSIBILITY OF SUCH DAMAGE.
     26 ***********************************************************************/
     27 
     28 #ifndef SILK_MAIN_FLP_H
     29 #define SILK_MAIN_FLP_H
     30 
     31 #include "SigProc_FLP.h"
     32 #include "SigProc_FIX.h"
     33 #include "structs_FLP.h"
     34 #include "main.h"
     35 #include "define.h"
     36 #include "debug.h"
     37 #include "entenc.h"
     38 
     39 #ifdef __cplusplus
     40 extern "C"
     41 {
     42 #endif
     43 
     44 #define silk_encoder_state_Fxx      silk_encoder_state_FLP
     45 #define silk_encode_do_VAD_Fxx      silk_encode_do_VAD_FLP
     46 #define silk_encode_frame_Fxx       silk_encode_frame_FLP
     47 
     48 /*********************/
     49 /* Encoder Functions */
     50 /*********************/
     51 
     52 /* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */
     53 void silk_HP_variable_cutoff(
     54    silk_encoder_state_Fxx          state_Fxx[]                         /* I/O  Encoder states                              */
     55 );
     56 
     57 /* Encoder main function */
     58 void silk_encode_do_VAD_FLP(
     59    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
     60    opus_int                        activity                            /* I    Decision of Opus voice activity detector    */
     61 );
     62 
     63 /* Encoder main function */
     64 opus_int silk_encode_frame_FLP(
     65    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
     66    opus_int32                      *pnBytesOut,                        /* O    Number of payload bytes;                    */
     67    ec_enc                          *psRangeEnc,                        /* I/O  compressor data structure                   */
     68    opus_int                        condCoding,                         /* I    The type of conditional coding to use       */
     69    opus_int                        maxBits,                            /* I    If > 0: maximum number of output bits       */
     70    opus_int                        useCBR                              /* I    Flag to force constant-bitrate operation    */
     71 );
     72 
     73 /* Initializes the Silk encoder state */
     74 opus_int silk_init_encoder(
     75    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
     76    int                              arch                               /* I    Run-tim architecture                        */
     77 );
     78 
     79 /* Control the Silk encoder */
     80 opus_int silk_control_encoder(
     81    silk_encoder_state_FLP          *psEnc,                             /* I/O  Pointer to Silk encoder state FLP           */
     82    silk_EncControlStruct           *encControl,                        /* I    Control structure                           */
     83    const opus_int                  allow_bw_switch,                    /* I    Flag to allow switching audio bandwidth     */
     84    const opus_int                  channelNb,                          /* I    Channel number                              */
     85    const opus_int                  force_fs_kHz
     86 );
     87 
     88 /**************************/
     89 /* Noise shaping analysis */
     90 /**************************/
     91 /* Compute noise shaping coefficients and initial gain values */
     92 void silk_noise_shape_analysis_FLP(
     93    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
     94    silk_encoder_control_FLP        *psEncCtrl,                         /* I/O  Encoder control FLP                         */
     95    const silk_float                *pitch_res,                         /* I    LPC residual from pitch analysis            */
     96    const silk_float                *x                                  /* I    Input signal [frame_length + la_shape]      */
     97 );
     98 
     99 /* Autocorrelations for a warped frequency axis */
    100 void silk_warped_autocorrelation_FLP(
    101    silk_float                      *corr,                              /* O    Result [order + 1]                          */
    102    const silk_float                *input,                             /* I    Input data to correlate                     */
    103    const silk_float                warping,                            /* I    Warping coefficient                         */
    104    const opus_int                  length,                             /* I    Length of input                             */
    105    const opus_int                  order                               /* I    Correlation order (even)                    */
    106 );
    107 
    108 /* Calculation of LTP state scaling */
    109 void silk_LTP_scale_ctrl_FLP(
    110    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
    111    silk_encoder_control_FLP        *psEncCtrl,                         /* I/O  Encoder control FLP                         */
    112    opus_int                        condCoding                          /* I    The type of conditional coding to use       */
    113 );
    114 
    115 /**********************************************/
    116 /* Prediction Analysis                        */
    117 /**********************************************/
    118 /* Find pitch lags */
    119 void silk_find_pitch_lags_FLP(
    120    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
    121    silk_encoder_control_FLP        *psEncCtrl,                         /* I/O  Encoder control FLP                         */
    122    silk_float                      res[],                              /* O    Residual                                    */
    123    const silk_float                x[],                                /* I    Speech signal                               */
    124    int                             arch                                /* I    Run-time architecture                       */
    125 );
    126 
    127 /* Find LPC and LTP coefficients */
    128 void silk_find_pred_coefs_FLP(
    129    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
    130    silk_encoder_control_FLP        *psEncCtrl,                         /* I/O  Encoder control FLP                         */
    131    const silk_float                res_pitch[],                        /* I    Residual from pitch analysis                */
    132    const silk_float                x[],                                /* I    Speech signal                               */
    133    opus_int                        condCoding                          /* I    The type of conditional coding to use       */
    134 );
    135 
    136 /* LPC analysis */
    137 void silk_find_LPC_FLP(
    138    silk_encoder_state              *psEncC,                            /* I/O  Encoder state                               */
    139    opus_int16                      NLSF_Q15[],                         /* O    NLSFs                                       */
    140    const silk_float                x[],                                /* I    Input signal                                */
    141    const silk_float                minInvGain,                         /* I    Prediction gain from LTP (dB)               */
    142    int                             arch
    143 );
    144 
    145 /* LTP analysis */
    146 void silk_find_LTP_FLP(
    147    silk_float                      XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O    Weight for LTP quantization         */
    148    silk_float                      xX[ MAX_NB_SUBFR * LTP_ORDER ],     /* O    Weight for LTP quantization                 */
    149    const silk_float                r_ptr[],                            /* I    LPC residual                                */
    150    const opus_int                  lag[  MAX_NB_SUBFR ],               /* I    LTP lags                                    */
    151    const opus_int                  subfr_length,                       /* I    Subframe length                             */
    152    const opus_int                  nb_subfr,                           /* I    number of subframes                         */
    153    int                             arch
    154 );
    155 
    156 void silk_LTP_analysis_filter_FLP(
    157    silk_float                      *LTP_res,                           /* O    LTP res MAX_NB_SUBFR*(pre_lgth+subfr_lngth) */
    158    const silk_float                *x,                                 /* I    Input signal, with preceding samples        */
    159    const silk_float                B[ LTP_ORDER * MAX_NB_SUBFR ],      /* I    LTP coefficients for each subframe          */
    160    const opus_int                  pitchL[   MAX_NB_SUBFR ],           /* I    Pitch lags                                  */
    161    const silk_float                invGains[ MAX_NB_SUBFR ],           /* I    Inverse quantization gains                  */
    162    const opus_int                  subfr_length,                       /* I    Length of each subframe                     */
    163    const opus_int                  nb_subfr,                           /* I    number of subframes                         */
    164    const opus_int                  pre_length                          /* I    Preceding samples for each subframe         */
    165 );
    166 
    167 /* Calculates residual energies of input subframes where all subframes have LPC_order   */
    168 /* of preceding samples                                                                 */
    169 void silk_residual_energy_FLP(
    170    silk_float                      nrgs[ MAX_NB_SUBFR ],               /* O    Residual energy per subframe                */
    171    const silk_float                x[],                                /* I    Input signal                                */
    172    silk_float                      a[ 2 ][ MAX_LPC_ORDER ],            /* I    AR coefs for each frame half                */
    173    const silk_float                gains[],                            /* I    Quantization gains                          */
    174    const opus_int                  subfr_length,                       /* I    Subframe length                             */
    175    const opus_int                  nb_subfr,                           /* I    number of subframes                         */
    176    const opus_int                  LPC_order                           /* I    LPC order                                   */
    177 );
    178 
    179 /* 16th order LPC analysis filter */
    180 void silk_LPC_analysis_filter_FLP(
    181    silk_float                      r_LPC[],                            /* O    LPC residual signal                         */
    182    const silk_float                PredCoef[],                         /* I    LPC coefficients                            */
    183    const silk_float                s[],                                /* I    Input signal                                */
    184    const opus_int                  length,                             /* I    Length of input signal                      */
    185    const opus_int                  Order                               /* I    LPC order                                   */
    186 );
    187 
    188 /* LTP tap quantizer */
    189 void silk_quant_LTP_gains_FLP(
    190    silk_float                      B[ MAX_NB_SUBFR * LTP_ORDER ],      /* O    Quantized LTP gains                         */
    191    opus_int8                       cbk_index[ MAX_NB_SUBFR ],          /* O    Codebook index                              */
    192    opus_int8                       *periodicity_index,                 /* O    Periodicity index                           */
    193    opus_int32                      *sum_log_gain_Q7,                   /* I/O  Cumulative max prediction gain  */
    194    silk_float                      *pred_gain_dB,                      /* O    LTP prediction gain                         */
    195    const silk_float                XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I    Correlation matrix                  */
    196    const silk_float                xX[ MAX_NB_SUBFR * LTP_ORDER ],     /* I    Correlation vector                          */
    197    const opus_int                  subfr_len,                          /* I    Number of samples per subframe              */
    198    const opus_int                  nb_subfr,                           /* I    Number of subframes                         */
    199    int                             arch                                /* I    Run-time architecture                       */
    200 );
    201 
    202 /* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
    203 silk_float silk_residual_energy_covar_FLP(                              /* O    Weighted residual energy                    */
    204    const silk_float                *c,                                 /* I    Filter coefficients                         */
    205    silk_float                      *wXX,                               /* I/O  Weighted correlation matrix, reg. out       */
    206    const silk_float                *wXx,                               /* I    Weighted correlation vector                 */
    207    const silk_float                wxx,                                /* I    Weighted correlation value                  */
    208    const opus_int                  D                                   /* I    Dimension                                   */
    209 );
    210 
    211 /* Processing of gains */
    212 void silk_process_gains_FLP(
    213    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
    214    silk_encoder_control_FLP        *psEncCtrl,                         /* I/O  Encoder control FLP                         */
    215    opus_int                        condCoding                          /* I    The type of conditional coding to use       */
    216 );
    217 
    218 /******************/
    219 /* Linear Algebra */
    220 /******************/
    221 /* Calculates correlation matrix X'*X */
    222 void silk_corrMatrix_FLP(
    223    const silk_float                *x,                                 /* I    x vector [ L+order-1 ] used to create X     */
    224    const opus_int                  L,                                  /* I    Length of vectors                           */
    225    const opus_int                  Order,                              /* I    Max lag for correlation                     */
    226    silk_float                      *XX,                                /* O    X'*X correlation matrix [order x order]     */
    227    int                             arch
    228 );
    229 
    230 /* Calculates correlation vector X'*t */
    231 void silk_corrVector_FLP(
    232    const silk_float                *x,                                 /* I    x vector [L+order-1] used to create X       */
    233    const silk_float                *t,                                 /* I    Target vector [L]                           */
    234    const opus_int                  L,                                  /* I    Length of vecors                            */
    235    const opus_int                  Order,                              /* I    Max lag for correlation                     */
    236    silk_float                      *Xt,                                /* O    X'*t correlation vector [order]             */
    237    int                             arch
    238 );
    239 
    240 /* Apply sine window to signal vector.  */
    241 /* Window types:                        */
    242 /*  1 -> sine window from 0 to pi/2     */
    243 /*  2 -> sine window from pi/2 to pi    */
    244 void silk_apply_sine_window_FLP(
    245    silk_float                      px_win[],                           /* O    Pointer to windowed signal                  */
    246    const silk_float                px[],                               /* I    Pointer to input signal                     */
    247    const opus_int                  win_type,                           /* I    Selects a window type                       */
    248    const opus_int                  length                              /* I    Window length, multiple of 4                */
    249 );
    250 
    251 /* Wrapper functions. Call flp / fix code */
    252 
    253 /* Convert AR filter coefficients to NLSF parameters */
    254 void silk_A2NLSF_FLP(
    255    opus_int16                      *NLSF_Q15,                          /* O    NLSF vector      [ LPC_order ]              */
    256    const silk_float                *pAR,                               /* I    LPC coefficients [ LPC_order ]              */
    257    const opus_int                  LPC_order                           /* I    LPC order                                   */
    258 );
    259 
    260 /* Convert NLSF parameters to AR prediction filter coefficients */
    261 void silk_NLSF2A_FLP(
    262    silk_float                      *pAR,                               /* O    LPC coefficients [ LPC_order ]              */
    263    const opus_int16                *NLSF_Q15,                          /* I    NLSF vector      [ LPC_order ]              */
    264    const opus_int                  LPC_order,                          /* I    LPC order                                   */
    265    int                             arch                                /* I    Run-time architecture                       */
    266 );
    267 
    268 /* Limit, stabilize, and quantize NLSFs */
    269 void silk_process_NLSFs_FLP(
    270    silk_encoder_state              *psEncC,                            /* I/O  Encoder state                               */
    271    silk_float                      PredCoef[ 2 ][ MAX_LPC_ORDER ],     /* O    Prediction coefficients                     */
    272    opus_int16                      NLSF_Q15[      MAX_LPC_ORDER ],     /* I/O  Normalized LSFs (quant out) (0 - (2^15-1))  */
    273    const opus_int16                prev_NLSF_Q15[ MAX_LPC_ORDER ]      /* I    Previous Normalized LSFs (0 - (2^15-1))     */
    274 );
    275 
    276 /* Floating-point Silk NSQ wrapper      */
    277 void silk_NSQ_wrapper_FLP(
    278    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
    279    silk_encoder_control_FLP        *psEncCtrl,                         /* I/O  Encoder control FLP                         */
    280    SideInfoIndices                 *psIndices,                         /* I/O  Quantization indices                        */
    281    silk_nsq_state                  *psNSQ,                             /* I/O  Noise Shaping Quantzation state             */
    282    opus_int8                       pulses[],                           /* O    Quantized pulse signal                      */
    283    const silk_float                x[]                                 /* I    Prefiltered input signal                    */
    284 );
    285 
    286 #ifdef __cplusplus
    287 }
    288 #endif
    289 
    290 #endif