Silk makes use of Opus VAD
[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, 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     opus_int                        activity                                /* I    Decision of Opus voice activity detector                                    */
71 );
72
73 /* Encoder main function */
74 opus_int silk_encode_frame_FIX(
75     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Pointer to Silk FIX encoder state                                           */
76     opus_int32                      *pnBytesOut,                            /* O    Pointer to number of payload bytes;                                         */
77     ec_enc                          *psRangeEnc,                            /* I/O  compressor data structure                                                   */
78     opus_int                        condCoding,                             /* I    The type of conditional coding to use                                       */
79     opus_int                        maxBits,                                /* I    If > 0: maximum number of output bits                                       */
80     opus_int                        useCBR                                  /* I    Flag to force constant-bitrate operation                                    */
81 );
82
83 /* Initializes the Silk encoder state */
84 opus_int silk_init_encoder(
85     silk_encoder_state_Fxx          *psEnc,                                 /* I/O  Pointer to Silk FIX encoder state                                           */
86     int                              arch                                   /* I    Run-time architecture                                                       */
87 );
88
89 /* Control the Silk encoder */
90 opus_int silk_control_encoder(
91     silk_encoder_state_Fxx          *psEnc,                                 /* I/O  Pointer to Silk encoder state                                               */
92     silk_EncControlStruct           *encControl,                            /* I    Control structure                                                           */
93     const opus_int                  allow_bw_switch,                        /* I    Flag to allow switching audio bandwidth                                     */
94     const opus_int                  channelNb,                              /* I    Channel number                                                              */
95     const opus_int                  force_fs_kHz
96 );
97
98 /**************************/
99 /* Noise shaping analysis */
100 /**************************/
101 /* Compute noise shaping coefficients and initial gain values */
102 void silk_noise_shape_analysis_FIX(
103     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Encoder state FIX                                                           */
104     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  Encoder control FIX                                                         */
105     const opus_int16                *pitch_res,                             /* I    LPC residual from pitch analysis                                            */
106     const opus_int16                *x,                                     /* I    Input signal [ frame_length + la_shape ]                                    */
107     int                              arch                                   /* I    Run-time architecture                                                       */
108 );
109
110 /* Autocorrelations for a warped frequency axis */
111 void silk_warped_autocorrelation_FIX_c(
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 #if !defined(OVERRIDE_silk_warped_autocorrelation_FIX)
121 #define silk_warped_autocorrelation_FIX(corr, scale, input, warping_Q16, length, order, arch) \
122         ((void)(arch), silk_warped_autocorrelation_FIX_c(corr, scale, input, warping_Q16, length, order))
123 #endif
124
125 /* Calculation of LTP state scaling */
126 void silk_LTP_scale_ctrl_FIX(
127     silk_encoder_state_FIX          *psEnc,                                 /* I/O  encoder state                                                               */
128     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  encoder control                                                             */
129     opus_int                        condCoding                              /* I    The type of conditional coding to use                                       */
130 );
131
132 /**********************************************/
133 /* Prediction Analysis                        */
134 /**********************************************/
135 /* Find pitch lags */
136 void silk_find_pitch_lags_FIX(
137     silk_encoder_state_FIX          *psEnc,                                 /* I/O  encoder state                                                               */
138     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  encoder control                                                             */
139     opus_int16                      res[],                                  /* O    residual                                                                    */
140     const opus_int16                x[],                                    /* I    Speech signal                                                               */
141     int                             arch                                    /* I    Run-time architecture                                                       */
142 );
143
144 /* Find LPC and LTP coefficients */
145 void silk_find_pred_coefs_FIX(
146     silk_encoder_state_FIX          *psEnc,                                 /* I/O  encoder state                                                               */
147     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  encoder control                                                             */
148     const opus_int16                res_pitch[],                            /* I    Residual from pitch analysis                                                */
149     const opus_int16                x[],                                    /* I    Speech signal                                                               */
150     opus_int                        condCoding                              /* I    The type of conditional coding to use                                       */
151 );
152
153 /* LPC analysis */
154 void silk_find_LPC_FIX(
155     silk_encoder_state              *psEncC,                                /* I/O  Encoder state                                                               */
156     opus_int16                      NLSF_Q15[],                             /* O    NLSFs                                                                       */
157     const opus_int16                x[],                                    /* I    Input signal                                                                */
158     const opus_int32                minInvGain_Q30                          /* I    Inverse of max prediction gain                                              */
159 );
160
161 /* LTP analysis */
162 void silk_find_LTP_FIX(
163     opus_int32                      XXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O    Correlation matrix                                               */
164     opus_int32                      xXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER ],  /* O    Correlation vector                                                          */
165     const opus_int16                r_lpc[],                                /* I    Residual signal after LPC                                                   */
166     const opus_int                  lag[ MAX_NB_SUBFR ],                    /* I    LTP lags                                                                    */
167     const opus_int                  subfr_length,                           /* I    Subframe length                                                             */
168     const opus_int                  nb_subfr,                               /* I    Number of subframes                                                         */
169     int                             arch                                    /* I    Run-time architecture                                                       */
170 );
171
172 void silk_LTP_analysis_filter_FIX(
173     opus_int16                      *LTP_res,                               /* O    LTP residual signal of length MAX_NB_SUBFR * ( pre_length + subfr_length )  */
174     const opus_int16                *x,                                     /* I    Pointer to input signal with at least max( pitchL ) preceding samples       */
175     const opus_int16                LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],/* I    LTP_ORDER LTP coefficients for each MAX_NB_SUBFR subframe                   */
176     const opus_int                  pitchL[ MAX_NB_SUBFR ],                 /* I    Pitch lag, one for each subframe                                            */
177     const opus_int32                invGains_Q16[ MAX_NB_SUBFR ],           /* I    Inverse quantization gains, one for each subframe                           */
178     const opus_int                  subfr_length,                           /* I    Length of each subframe                                                     */
179     const opus_int                  nb_subfr,                               /* I    Number of subframes                                                         */
180     const opus_int                  pre_length                              /* I    Length of the preceding samples starting at &x[0] for each subframe         */
181 );
182
183 /* Calculates residual energies of input subframes where all subframes have LPC_order   */
184 /* of preceding samples                                                                 */
185 void silk_residual_energy_FIX(
186           opus_int32                nrgs[ MAX_NB_SUBFR ],                   /* O    Residual energy per subframe                                                */
187           opus_int                  nrgsQ[ MAX_NB_SUBFR ],                  /* O    Q value per subframe                                                        */
188     const opus_int16                x[],                                    /* I    Input signal                                                                */
189           opus_int16                a_Q12[ 2 ][ MAX_LPC_ORDER ],            /* I    AR coefs for each frame half                                                */
190     const opus_int32                gains[ MAX_NB_SUBFR ],                  /* I    Quantization gains                                                          */
191     const opus_int                  subfr_length,                           /* I    Subframe length                                                             */
192     const opus_int                  nb_subfr,                               /* I    Number of subframes                                                         */
193     const opus_int                  LPC_order,                              /* I    LPC order                                                                   */
194     int                             arch                                    /* I    Run-time architecture                                                       */
195 );
196
197 /* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
198 opus_int32 silk_residual_energy16_covar_FIX(
199     const opus_int16                *c,                                     /* I    Prediction vector                                                           */
200     const opus_int32                *wXX,                                   /* I    Correlation matrix                                                          */
201     const opus_int32                *wXx,                                   /* I    Correlation vector                                                          */
202     opus_int32                      wxx,                                    /* I    Signal energy                                                               */
203     opus_int                        D,                                      /* I    Dimension                                                                   */
204     opus_int                        cQ                                      /* I    Q value for c vector 0 - 15                                                 */
205 );
206
207 /* Processing of gains */
208 void silk_process_gains_FIX(
209     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Encoder state                                                               */
210     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  Encoder control                                                             */
211     opus_int                        condCoding                              /* I    The type of conditional coding to use                                       */
212 );
213
214 /******************/
215 /* Linear Algebra */
216 /******************/
217 /* Calculates correlation matrix X'*X */
218 void silk_corrMatrix_FIX(
219     const opus_int16                *x,                                     /* I    x vector [L + order - 1] used to form data matrix X                         */
220     const opus_int                  L,                                      /* I    Length of vectors                                                           */
221     const opus_int                  order,                                  /* I    Max lag for correlation                                                     */
222     opus_int32                      *XX,                                    /* O    Pointer to X'*X correlation matrix [ order x order ]                        */
223     opus_int32                      *nrg,                                   /* O    Energy of x vector                                                          */
224     opus_int                        *rshifts,                               /* O    Right shifts of correlations                                                */
225     int                              arch                                   /* I    Run-time architecture                                                       */
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     int                             arch                                    /* I    Run-time architecture                                                       */
237 );
238
239 #ifndef FORCE_CPP_BUILD
240 #ifdef __cplusplus
241 }
242 #endif /* __cplusplus */
243 #endif /* FORCE_CPP_BUILD */
244 #endif /* SILK_MAIN_FIX_H */