Home | History | Annotate | Download | only in fixed
      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_FIX_H
     29 #define SILK_MAIN_FIX_H
     30 
     31 #include "SigProc_FIX.h"
     32 #include "structs_FIX.h"
     33 #include "control.h"
     34 #include "main.h"
     35 #include "PLC.h"
     36 #include "debug.h"
     37 #include "entenc.h"
     38 
     39 #if ((defined(OPUS_ARM_ASM) && defined(FIXED_POINT)) \
     40    || defined(OPUS_ARM_MAY_HAVE_NEON_INTR))
     41 #include "fixed/arm/warped_autocorrelation_FIX_arm.h"
     42 #endif
     43 
     44 #ifndef FORCE_CPP_BUILD
     45 #ifdef __cplusplus
     46 extern "C"
     47 {
     48 #endif
     49 #endif
     50 
     51 #define silk_encoder_state_Fxx      silk_encoder_state_FIX
     52 #define silk_encode_do_VAD_Fxx      silk_encode_do_VAD_FIX
     53 #define silk_encode_frame_Fxx       silk_encode_frame_FIX
     54 
     55 #define QC  10
     56 #define QS  13
     57 
     58 /*********************/
     59 /* Encoder Functions */
     60 /*********************/
     61 
     62 /* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */
     63 void silk_HP_variable_cutoff(
     64     silk_encoder_state_Fxx          state_Fxx[]                             /* I/O  Encoder states                                                              */
     65 );
     66 
     67 /* Encoder main function */
     68 void silk_encode_do_VAD_FIX(
     69     silk_encoder_state_FIX          *psEnc                                  /* I/O  Pointer to Silk FIX encoder state                                           */
     70 );
     71 
     72 /* Encoder main function */
     73 opus_int silk_encode_frame_FIX(
     74     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Pointer to Silk FIX encoder state                                           */
     75     opus_int32                      *pnBytesOut,                            /* O    Pointer to number of payload bytes;                                         */
     76     ec_enc                          *psRangeEnc,                            /* I/O  compressor data structure                                                   */
     77     opus_int                        condCoding,                             /* I    The type of conditional coding to use                                       */
     78     opus_int                        maxBits,                                /* I    If > 0: maximum number of output bits                                       */
     79     opus_int                        useCBR                                  /* I    Flag to force constant-bitrate operation                                    */
     80 );
     81 
     82 /* Initializes the Silk encoder state */
     83 opus_int silk_init_encoder(
     84     silk_encoder_state_Fxx          *psEnc,                                 /* I/O  Pointer to Silk FIX encoder state                                           */
     85     int                              arch                                   /* I    Run-time architecture                                                       */
     86 );
     87 
     88 /* Control the Silk encoder */
     89 opus_int silk_control_encoder(
     90     silk_encoder_state_Fxx          *psEnc,                                 /* I/O  Pointer to Silk encoder state                                               */
     91     silk_EncControlStruct           *encControl,                            /* I    Control structure                                                           */
     92     const opus_int                  allow_bw_switch,                        /* I    Flag to allow switching audio bandwidth                                     */
     93     const opus_int                  channelNb,                              /* I    Channel number                                                              */
     94     const opus_int                  force_fs_kHz
     95 );
     96 
     97 /**************************/
     98 /* Noise shaping analysis */
     99 /**************************/
    100 /* Compute noise shaping coefficients and initial gain values */
    101 void silk_noise_shape_analysis_FIX(
    102     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Encoder state FIX                                                           */
    103     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  Encoder control FIX                                                         */
    104     const opus_int16                *pitch_res,                             /* I    LPC residual from pitch analysis                                            */
    105     const opus_int16                *x,                                     /* I    Input signal [ frame_length + la_shape ]                                    */
    106     int                              arch                                   /* I    Run-time architecture                                                       */
    107 );
    108 
    109 /* Autocorrelations for a warped frequency axis */
    110 void silk_warped_autocorrelation_FIX_c(
    111           opus_int32                *corr,                                  /* O    Result [order + 1]                                                          */
    112           opus_int                  *scale,                                 /* O    Scaling of the correlation vector                                           */
    113     const opus_int16                *input,                                 /* I    Input data to correlate                                                     */
    114     const opus_int                  warping_Q16,                            /* I    Warping coefficient                                                         */
    115     const opus_int                  length,                                 /* I    Length of input                                                             */
    116     const opus_int                  order                                   /* I    Correlation order (even)                                                    */
    117 );
    118 
    119 #if !defined(OVERRIDE_silk_warped_autocorrelation_FIX)
    120 #define silk_warped_autocorrelation_FIX(corr, scale, input, warping_Q16, length, order, arch) \
    121         ((void)(arch), silk_warped_autocorrelation_FIX_c(corr, scale, input, warping_Q16, length, order))
    122 #endif
    123 
    124 /* Calculation of LTP state scaling */
    125 void silk_LTP_scale_ctrl_FIX(
    126     silk_encoder_state_FIX          *psEnc,                                 /* I/O  encoder state                                                               */
    127     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  encoder control                                                             */
    128     opus_int                        condCoding                              /* I    The type of conditional coding to use                                       */
    129 );
    130 
    131 /**********************************************/
    132 /* Prediction Analysis                        */
    133 /**********************************************/
    134 /* Find pitch lags */
    135 void silk_find_pitch_lags_FIX(
    136     silk_encoder_state_FIX          *psEnc,                                 /* I/O  encoder state                                                               */
    137     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  encoder control                                                             */
    138     opus_int16                      res[],                                  /* O    residual                                                                    */
    139     const opus_int16                x[],                                    /* I    Speech signal                                                               */
    140     int                             arch                                    /* I    Run-time architecture                                                       */
    141 );
    142 
    143 /* Find LPC and LTP coefficients */
    144 void silk_find_pred_coefs_FIX(
    145     silk_encoder_state_FIX          *psEnc,                                 /* I/O  encoder state                                                               */
    146     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  encoder control                                                             */
    147     const opus_int16                res_pitch[],                            /* I    Residual from pitch analysis                                                */
    148     const opus_int16                x[],                                    /* I    Speech signal                                                               */
    149     opus_int                        condCoding                              /* I    The type of conditional coding to use                                       */
    150 );
    151 
    152 /* LPC analysis */
    153 void silk_find_LPC_FIX(
    154     silk_encoder_state              *psEncC,                                /* I/O  Encoder state                                                               */
    155     opus_int16                      NLSF_Q15[],                             /* O    NLSFs                                                                       */
    156     const opus_int16                x[],                                    /* I    Input signal                                                                */
    157     const opus_int32                minInvGain_Q30                          /* I    Inverse of max prediction gain                                              */
    158 );
    159 
    160 /* LTP analysis */
    161 void silk_find_LTP_FIX(
    162     opus_int32                      XXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O    Correlation matrix                                               */
    163     opus_int32                      xXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER ],  /* O    Correlation vector                                                          */
    164     const opus_int16                r_lpc[],                                /* I    Residual signal after LPC                                                   */
    165     const opus_int                  lag[ MAX_NB_SUBFR ],                    /* I    LTP lags                                                                    */
    166     const opus_int                  subfr_length,                           /* I    Subframe length                                                             */
    167     const opus_int                  nb_subfr,                               /* I    Number of subframes                                                         */
    168     int                             arch                                    /* I    Run-time architecture                                                       */
    169 );
    170 
    171 void silk_LTP_analysis_filter_FIX(
    172     opus_int16                      *LTP_res,                               /* O    LTP residual signal of length MAX_NB_SUBFR * ( pre_length + subfr_length )  */
    173     const opus_int16                *x,                                     /* I    Pointer to input signal with at least max( pitchL ) preceding samples       */
    174     const opus_int16                LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],/* I    LTP_ORDER LTP coefficients for each MAX_NB_SUBFR subframe                   */
    175     const opus_int                  pitchL[ MAX_NB_SUBFR ],                 /* I    Pitch lag, one for each subframe                                            */
    176     const opus_int32                invGains_Q16[ MAX_NB_SUBFR ],           /* I    Inverse quantization gains, one for each subframe                           */
    177     const opus_int                  subfr_length,                           /* I    Length of each subframe                                                     */
    178     const opus_int                  nb_subfr,                               /* I    Number of subframes                                                         */
    179     const opus_int                  pre_length                              /* I    Length of the preceding samples starting at &x[0] for each subframe         */
    180 );
    181 
    182 /* Calculates residual energies of input subframes where all subframes have LPC_order   */
    183 /* of preceding samples                                                                 */
    184 void silk_residual_energy_FIX(
    185           opus_int32                nrgs[ MAX_NB_SUBFR ],                   /* O    Residual energy per subframe                                                */
    186           opus_int                  nrgsQ[ MAX_NB_SUBFR ],                  /* O    Q value per subframe                                                        */
    187     const opus_int16                x[],                                    /* I    Input signal                                                                */
    188           opus_int16                a_Q12[ 2 ][ MAX_LPC_ORDER ],            /* I    AR coefs for each frame half                                                */
    189     const opus_int32                gains[ MAX_NB_SUBFR ],                  /* I    Quantization gains                                                          */
    190     const opus_int                  subfr_length,                           /* I    Subframe length                                                             */
    191     const opus_int                  nb_subfr,                               /* I    Number of subframes                                                         */
    192     const opus_int                  LPC_order,                              /* I    LPC order                                                                   */
    193     int                             arch                                    /* I    Run-time architecture                                                       */
    194 );
    195 
    196 /* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
    197 opus_int32 silk_residual_energy16_covar_FIX(
    198     const opus_int16                *c,                                     /* I    Prediction vector                                                           */
    199     const opus_int32                *wXX,                                   /* I    Correlation matrix                                                          */
    200     const opus_int32                *wXx,                                   /* I    Correlation vector                                                          */
    201     opus_int32                      wxx,                                    /* I    Signal energy                                                               */
    202     opus_int                        D,                                      /* I    Dimension                                                                   */
    203     opus_int                        cQ                                      /* I    Q value for c vector 0 - 15                                                 */
    204 );
    205 
    206 /* Processing of gains */
    207 void silk_process_gains_FIX(
    208     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Encoder state                                                               */
    209     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  Encoder control                                                             */
    210     opus_int                        condCoding                              /* I    The type of conditional coding to use                                       */
    211 );
    212 
    213 /******************/
    214 /* Linear Algebra */
    215 /******************/
    216 /* Calculates correlation matrix X'*X */
    217 void silk_corrMatrix_FIX(
    218     const opus_int16                *x,                                     /* I    x vector [L + order - 1] used to form data matrix X                         */
    219     const opus_int                  L,                                      /* I    Length of vectors                                                           */
    220     const opus_int                  order,                                  /* I    Max lag for correlation                                                     */
    221     opus_int32                      *XX,                                    /* O    Pointer to X'*X correlation matrix [ order x order ]                        */
    222     opus_int32                      *nrg,                                   /* O    Energy of x vector                                                          */
    223     opus_int                        *rshifts,                               /* O    Right shifts of correlations                                                */
    224     int                              arch                                   /* I    Run-time architecture                                                       */
    225 );
    226 
    227 /* Calculates correlation vector X'*t */
    228 void silk_corrVector_FIX(
    229     const opus_int16                *x,                                     /* I    x vector [L + order - 1] used to form data matrix X                         */
    230     const opus_int16                *t,                                     /* I    Target vector [L]                                                           */
    231     const opus_int                  L,                                      /* I    Length of vectors                                                           */
    232     const opus_int                  order,                                  /* I    Max lag for correlation                                                     */
    233     opus_int32                      *Xt,                                    /* O    Pointer to X'*t correlation vector [order]                                  */
    234     const opus_int                  rshifts,                                /* I    Right shifts of correlations                                                */
    235     int                             arch                                    /* I    Run-time architecture                                                       */
    236 );
    237 
    238 #ifndef FORCE_CPP_BUILD
    239 #ifdef __cplusplus
    240 }
    241 #endif /* __cplusplus */
    242 #endif /* FORCE_CPP_BUILD */
    243 #endif /* SILK_MAIN_FIX_H */
    244