Reformatting changes with an update to the MSVC project files
[opus.git] / silk / fixed / main_FIX.h
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, (subject to the limitations in the disclaimer below)
5 are permitted provided that the following conditions 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 Skype Limited, nor the names of specific
12 contributors, may be used to endorse or promote products derived from
13 this software without specific prior written permission.
14 NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
15 BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
16 CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE 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 #ifndef FORCE_CPP_BUILD
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif
44 #endif
45
46 #define silk_encoder_state_Fxx      silk_encoder_state_FIX
47 #define silk_encode_do_VAD_Fxx      silk_encode_do_VAD_FIX
48 #define silk_encode_frame_Fxx       silk_encode_frame_FIX
49
50 /*********************/
51 /* Encoder Functions */
52 /*********************/
53
54 /* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */
55 void silk_HP_variable_cutoff(
56     silk_encoder_state_Fxx          state_Fxx[]                             /* I/O  Encoder states                                                              */
57 );
58
59 /* Encoder main function */
60 void silk_encode_do_VAD_FIX(
61     silk_encoder_state_FIX          *psEnc                                  /* I/O  Pointer to Silk FIX encoder state                                           */
62 );
63
64 /* Encoder main function */
65 opus_int silk_encode_frame_FIX(
66     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Pointer to Silk FIX encoder state                                           */
67     opus_int32                      *pnBytesOut,                            /* O    Pointer to number of payload bytes;                                         */
68     ec_enc                          *psRangeEnc,                            /* I/O  compressor data structure                                                   */
69     opus_int                        condCoding,                             /* I    The type of conditional coding to use                                       */
70     opus_int                        maxBits,                                /* I    If > 0: maximum number of output bits                                       */
71     opus_int                        useCBR                                  /* I    Flag to force constant-bitrate operation                                    */
72 );
73
74 /* Initializes the Silk encoder state */
75 opus_int silk_init_encoder(
76     silk_encoder_state_Fxx          *psEnc                                  /* I/O  Pointer to Silk FIX encoder state                                           */
77 );
78
79 /* Control the Silk encoder */
80 opus_int silk_control_encoder(
81     silk_encoder_state_Fxx          *psEnc,                                 /* I/O  Pointer to Silk encoder state                                               */
82     silk_EncControlStruct           *encControl,                            /* I    Control structure                                                           */
83     const opus_int32                TargetRate_bps,                         /* I    Target max bitrate (bps)                                                    */
84     const opus_int                  allow_bw_switch,                        /* I    Flag to allow switching audio bandwidth                                     */
85     const opus_int                  channelNb,                              /* I    Channel number                                                              */
86     const opus_int                  force_fs_kHz
87 );
88
89 /****************/
90 /* Prefiltering */
91 /****************/
92 void silk_prefilter_FIX(
93     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Encoder state                                                               */
94     const silk_encoder_control_FIX  *psEncCtrl,                             /* I    Encoder control                                                             */
95     opus_int16                      xw[],                                   /* O    Weighted signal                                                             */
96     const opus_int16                x[]                                     /* I    Speech signal                                                               */
97 );
98
99 /**************************/
100 /* Noise shaping analysis */
101 /**************************/
102 /* Compute noise shaping coefficients and initial gain values */
103 void silk_noise_shape_analysis_FIX(
104     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Encoder state FIX                                                           */
105     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  Encoder control FIX                                                         */
106     const opus_int16                *pitch_res,                             /* I    LPC residual from pitch analysis                                            */
107     const opus_int16                *x                                      /* I    Input signal [ frame_length + la_shape ]                                    */
108 );
109
110 /* Autocorrelations for a warped frequency axis */
111 void silk_warped_autocorrelation_FIX(
112           opus_int32                *corr,                                  /* O    Result [order + 1]                                                          */
113           opus_int                  *scale,                                 /* O    Scaling of the correlation vector                                           */
114     const opus_int16                *input,                                 /* I    Input data to correlate                                                     */
115     const opus_int                  warping_Q16,                            /* I    Warping coefficient                                                         */
116     const opus_int                  length,                                 /* I    Length of input                                                             */
117     const opus_int                  order                                   /* I    Correlation order (even)                                                    */
118 );
119
120 /* Calculation of LTP state scaling */
121 void silk_LTP_scale_ctrl_FIX(
122     silk_encoder_state_FIX          *psEnc,                                 /* I/O  encoder state                                                               */
123     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  encoder control                                                             */
124     opus_int                        condCoding                              /* I    The type of conditional coding to use                                       */
125 );
126
127 /**********************************************/
128 /* Prediction Analysis                        */
129 /**********************************************/
130 /* Find pitch lags */
131 void silk_find_pitch_lags_FIX(
132     silk_encoder_state_FIX          *psEnc,                                 /* I/O  encoder state                                                               */
133     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  encoder control                                                             */
134     opus_int16                      res[],                                  /* O    residual                                                                    */
135     const opus_int16                x[]                                     /* I    Speech signal                                                               */
136 );
137
138 /* Find LPC and LTP coefficients */
139 void silk_find_pred_coefs_FIX(
140     silk_encoder_state_FIX          *psEnc,                                 /* I/O  encoder state                                                               */
141     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  encoder control                                                             */
142     const opus_int16                res_pitch[],                            /* I    Residual from pitch analysis                                                */
143     const opus_int16                x[],                                    /* I    Speech signal                                                               */
144     opus_int                        condCoding                              /* I    The type of conditional coding to use                                       */
145 );
146
147 /* LPC analysis */
148 void silk_find_LPC_FIX(
149     opus_int16                      NLSF_Q15[],                             /* O    NLSFs                                                                       */
150     opus_int8                       *interpIndex,                           /* O    NLSF interpolation index, only used for NLSF interpolation                  */
151     const opus_int16                prev_NLSFq_Q15[],                       /* I    previous NLSFs, only used for NLSF interpolation                            */
152     const opus_int                  useInterpNLSFs,                         /* I    Flag                                                                        */
153     const opus_int                  firstFrameAfterReset,                   /* I    Flag                                                                        */
154     const opus_int                  LPC_order,                              /* I    LPC order                                                                   */
155     const opus_int16                x[],                                    /* I    Input signal                                                                */
156     const opus_int                  subfr_length,                           /* I    Input signal subframe length including preceeding samples                   */
157     const opus_int                  nb_subfr                                /* I    Number of subframes                                                         */
158 );
159
160 /* LTP analysis */
161 void silk_find_LTP_FIX(
162     opus_int16                      b_Q14[ MAX_NB_SUBFR * LTP_ORDER ],      /* O    LTP coefs                                                                   */
163     opus_int32                      WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O    Weight for LTP quantization                                           */
164     opus_int                        *LTPredCodGain_Q7,                      /* O    LTP coding gain                                                             */
165     const opus_int16                r_lpc[],                                /* I    residual signal after LPC signal + state for first 10 ms                    */
166     const opus_int                  lag[ MAX_NB_SUBFR ],                    /* I    LTP lags                                                                    */
167     const opus_int32                Wght_Q15[ MAX_NB_SUBFR ],               /* I    weights                                                                     */
168     const opus_int                  subfr_length,                           /* I    subframe length                                                             */
169     const opus_int                  nb_subfr,                               /* I    number of subframes                                                         */
170     const opus_int                  mem_offset,                             /* I    number of samples in LTP memory                                             */
171     opus_int                        corr_rshifts[ MAX_NB_SUBFR ]            /* O    right shifts applied to correlations                                        */
172 );
173
174 void silk_LTP_analysis_filter_FIX(
175     opus_int16                      *LTP_res,                               /* O    LTP residual signal of length MAX_NB_SUBFR * ( pre_length + subfr_length )  */
176     const opus_int16                *x,                                     /* I    Pointer to input signal with at least max( pitchL ) preceeding samples      */
177     const opus_int16                LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],/* I    LTP_ORDER LTP coefficients for each MAX_NB_SUBFR subframe                   */
178     const opus_int                  pitchL[ MAX_NB_SUBFR ],                 /* I    Pitch lag, one for each subframe                                            */
179     const opus_int32                invGains_Q16[ MAX_NB_SUBFR ],           /* I    Inverse quantization gains, one for each subframe                           */
180     const opus_int                  subfr_length,                           /* I    Length of each subframe                                                     */
181     const opus_int                  nb_subfr,                               /* I    Number of subframes                                                         */
182     const opus_int                  pre_length                              /* I    Length of the preceeding samples starting at &x[0] for each subframe        */
183 );
184
185 /* Calculates residual energies of input subframes where all subframes have LPC_order   */
186 /* of preceeding samples                                                                */
187 void silk_residual_energy_FIX(
188           opus_int32                nrgs[ MAX_NB_SUBFR ],                   /* O    Residual energy per subframe                                                */
189           opus_int                  nrgsQ[ MAX_NB_SUBFR ],                  /* O    Q value per subframe                                                        */
190     const opus_int16                x[],                                    /* I    Input signal                                                                */
191           opus_int16                a_Q12[ 2 ][ MAX_LPC_ORDER ],            /* I    AR coefs for each frame half                                                */
192     const opus_int32                gains[ MAX_NB_SUBFR ],                  /* I    Quantization gains                                                          */
193     const opus_int                  subfr_length,                           /* I    Subframe length                                                             */
194     const opus_int                  nb_subfr,                               /* I    Number of subframes                                                         */
195     const opus_int                  LPC_order                               /* I    LPC order                                                                   */
196 );
197
198 /* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
199 opus_int32 silk_residual_energy16_covar_FIX(
200     const opus_int16                *c,                                     /* I    Prediction vector                                                           */
201     const opus_int32                *wXX,                                   /* I    Correlation matrix                                                          */
202     const opus_int32                *wXx,                                   /* I    Correlation vector                                                          */
203     opus_int32                      wxx,                                    /* I    Signal energy                                                               */
204     opus_int                        D,                                      /* I    Dimension                                                                   */
205     opus_int                        cQ                                      /* I    Q value for c vector 0 - 15                                                 */
206 );
207
208 /* Processing of gains */
209 void silk_process_gains_FIX(
210     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Encoder state                                                               */
211     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  Encoder control                                                             */
212     opus_int                        condCoding                              /* I    The type of conditional coding to use                                       */
213 );
214
215 /******************/
216 /* Linear Algebra */
217 /******************/
218 /* Calculates correlation matrix X'*X */
219 void silk_corrMatrix_FIX(
220     const opus_int16                *x,                                     /* I    x vector [L + order - 1] used to form data matrix X                         */
221     const opus_int                  L,                                      /* I    Length of vectors                                                           */
222     const opus_int                  order,                                  /* I    Max lag for correlation                                                     */
223     const opus_int                  head_room,                              /* I    Desired headroom                                                            */
224     opus_int32                      *XX,                                    /* O    Pointer to X'*X correlation matrix [ order x order ]                        */
225     opus_int                        *rshifts                                /* I/O  Right shifts of correlations                                                */
226 );
227
228 /* Calculates correlation vector X'*t */
229 void silk_corrVector_FIX(
230     const opus_int16                *x,                                     /* I    x vector [L + order - 1] used to form data matrix X                         */
231     const opus_int16                *t,                                     /* I    Target vector [L]                                                           */
232     const opus_int                  L,                                      /* I    Length of vectors                                                           */
233     const opus_int                  order,                                  /* I    Max lag for correlation                                                     */
234     opus_int32                      *Xt,                                    /* O    Pointer to X'*t correlation vector [order]                                  */
235     const opus_int                  rshifts                                 /* I    Right shifts of correlations                                                */
236 );
237
238 /* Add noise to matrix diagonal */
239 void silk_regularize_correlations_FIX(
240     opus_int32                      *XX,                                    /* I/O  Correlation matrices                                                        */
241     opus_int32                      *xx,                                    /* I/O  Correlation values                                                          */
242     opus_int32                      noise,                                  /* I    Noise to add                                                                */
243     opus_int                        D                                       /* I    Dimension of XX                                                             */
244 );
245
246 /* Solves Ax = b, assuming A is symmetric */
247 void silk_solve_LDL_FIX(
248     opus_int32                      *A,                                     /* I    Pointer to symetric square matrix A                                         */
249     opus_int                        M,                                      /* I    Size of matrix                                                              */
250     const opus_int32                *b,                                     /* I    Pointer to b vector                                                         */
251     opus_int32                      *x_Q16                                  /* O    Pointer to x solution vector                                                */
252 );
253
254 #ifndef FORCE_CPP_BUILD
255 #ifdef __cplusplus
256 }
257 #endif /* __cplusplus */
258 #endif /* FORCE_CPP_BUILD */
259 #endif /* SILK_MAIN_FIX_H */