Fixes some compiler warnings
[opus.git] / silk / silk_structs.h
1 /***********************************************************************\r
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
3 Redistribution and use in source and binary forms, with or without \r
4 modification, (subject to the limitations in the disclaimer below) \r
5 are permitted provided that the following conditions are met:\r
6 - Redistributions of source code must retain the above copyright notice,\r
7 this list of conditions and the following disclaimer.\r
8 - Redistributions in binary form must reproduce the above copyright \r
9 notice, this list of conditions and the following disclaimer in the \r
10 documentation and/or other materials provided with the distribution.\r
11 - Neither the name of Skype Limited, nor the names of specific \r
12 contributors, may be used to endorse or promote products derived from \r
13 this software without specific prior written permission.\r
14 NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
15 BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
16 CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
17 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
18 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
19 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
22 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
23 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
26 ***********************************************************************/\r
27 \r
28 #ifndef SILK_STRUCTS_H\r
29 #define SILK_STRUCTS_H\r
30 \r
31 #ifdef HAVE_CONFIG_H\r
32 #include "config.h"\r
33 #endif\r
34 \r
35 #include "silk_typedef.h"\r
36 #include "silk_SigProc_FIX.h"\r
37 #include "silk_define.h"\r
38 #include "entenc.h"\r
39 #include "entdec.h"\r
40 \r
41 #ifdef __cplusplus\r
42 extern "C"\r
43 {\r
44 #endif\r
45 \r
46 /************************************/\r
47 /* Noise shaping quantization state */\r
48 /************************************/\r
49 typedef struct {\r
50     SKP_int16   xq[           2 * MAX_FRAME_LENGTH ]; /* Buffer for quantized output signal */\r
51     SKP_int32   sLTP_shp_Q10[ 2 * MAX_FRAME_LENGTH ];\r
52     SKP_int32   sLPC_Q14[ MAX_SUB_FRAME_LENGTH + NSQ_LPC_BUF_LENGTH ];\r
53     SKP_int32   sAR2_Q14[ MAX_SHAPE_LPC_ORDER ];\r
54     SKP_int32   sLF_AR_shp_Q12;\r
55     SKP_int     lagPrev;\r
56     SKP_int     sLTP_buf_idx;\r
57     SKP_int     sLTP_shp_buf_idx;\r
58     SKP_int32   rand_seed;\r
59     SKP_int32   prev_inv_gain_Q16;\r
60     SKP_int     rewhite_flag;\r
61 } silk_nsq_state;\r
62 \r
63 /********************************/\r
64 /* VAD state                    */\r
65 /********************************/\r
66 typedef struct {\r
67     SKP_int32   AnaState[ 2 ];                  /* Analysis filterbank state: 0-8 kHz                       */\r
68     SKP_int32   AnaState1[ 2 ];                 /* Analysis filterbank state: 0-4 kHz                       */\r
69     SKP_int32   AnaState2[ 2 ];                 /* Analysis filterbank state: 0-2 kHz                       */\r
70     SKP_int32   XnrgSubfr[ VAD_N_BANDS ];       /* Subframe energies                                        */\r
71     SKP_int32   NrgRatioSmth_Q8[ VAD_N_BANDS ]; /* Smoothed energy level in each band                       */\r
72     SKP_int16   HPstate;                        /* State of differentiator in the lowest band               */\r
73     SKP_int32   NL[ VAD_N_BANDS ];              /* Noise energy level in each band                          */\r
74     SKP_int32   inv_NL[ VAD_N_BANDS ];          /* Inverse noise energy level in each band                  */\r
75     SKP_int32   NoiseLevelBias[ VAD_N_BANDS ];  /* Noise level estimator bias/offset                        */\r
76     SKP_int32   counter;                        /* Frame counter used in the initial phase                  */\r
77 } silk_VAD_state;\r
78 \r
79 /* Variable cut-off low-pass filter state */\r
80 typedef struct {\r
81     SKP_int32                   In_LP_State[ 2 ];           /* Low pass filter state */\r
82     SKP_int32                   transition_frame_no;        /* Counter which is mapped to a cut-off frequency */\r
83     SKP_int                     mode;                       /* Operating mode, <0: switch down, >0: switch up; 0: do nothing */\r
84 } silk_LP_state;\r
85 \r
86 /* Structure containing NLSF codebook */\r
87 typedef struct {\r
88     const SKP_int16             nVectors;\r
89     const SKP_int16             order;\r
90     const SKP_int16             quantStepSize_Q16;\r
91     const SKP_int16             invQuantStepSize_Q6;\r
92     const SKP_uint8             *CB1_NLSF_Q8;\r
93     const SKP_uint8             *CB1_iCDF;\r
94     const SKP_uint8             *pred_Q8;\r
95     const SKP_uint8             *ec_sel;\r
96     const SKP_uint8             *ec_iCDF;\r
97     const SKP_uint8             *ec_Rates_Q5;\r
98     const SKP_int16             *deltaMin_Q15;\r
99 } silk_NLSF_CB_struct;\r
100 \r
101 typedef struct {\r
102     SKP_int16                   pred_prev_Q13[ 2 ];\r
103     SKP_int16                   sMid[ 2 ];\r
104     SKP_int16                   sSide[ 2 ];\r
105     SKP_int32                   mid_side_amp_Q0[ 4 ];\r
106     SKP_int16                   smth_width_Q14;\r
107     SKP_int16                   width_prev_Q14;\r
108     SKP_int8                    ix[ MAX_FRAMES_PER_PACKET ][ 2 ][ 4 ];\r
109 } stereo_enc_state;\r
110 \r
111 typedef struct {\r
112     SKP_int16                   pred_prev_Q13[ 2 ];\r
113     SKP_int16                   sMid[ 2 ];\r
114     SKP_int16                   sSide[ 2 ];\r
115 } stereo_dec_state;\r
116 \r
117 typedef struct {\r
118     SKP_int8                    GainsIndices[ MAX_NB_SUBFR ];\r
119     SKP_int8                    LTPIndex[ MAX_NB_SUBFR ];\r
120     SKP_int8                    NLSFIndices[ MAX_LPC_ORDER + 1 ];\r
121     SKP_int16                   lagIndex;\r
122     SKP_int8                    contourIndex;\r
123     SKP_int8                    signalType;\r
124     SKP_int8                    quantOffsetType;\r
125     SKP_int8                    NLSFInterpCoef_Q2;\r
126     SKP_int8                    PERIndex;\r
127     SKP_int8                    LTP_scaleIndex;\r
128     SKP_int8                    Seed;\r
129 } SideInfoIndices;\r
130 \r
131 /********************************/\r
132 /* Encoder state                */\r
133 /********************************/\r
134 typedef struct {\r
135     SKP_int32                       In_HP_State[ 2 ];               /* High pass filter state                                               */\r
136     SKP_int32                       variable_HP_smth1_Q15;          /* State of first smoother                                              */\r
137     SKP_int32                       variable_HP_smth2_Q15;          /* State of second smoother                                             */\r
138     SKP_int                         HP_cutoff_Hz;                   /* Fixed cutoff frequency (if zero: adaptive)                           */\r
139     silk_LP_state                   sLP;                            /* Low pass filter state                                                */\r
140     silk_VAD_state                  sVAD;                           /* Voice activity detector state                                        */\r
141     silk_nsq_state                  sNSQ;                           /* Noise Shape Quantizer State                                          */\r
142     SKP_int16                       prev_NLSFq_Q15[ MAX_LPC_ORDER ];/* Previously quantized NLSF vector                                     */\r
143     SKP_int                         speech_activity_Q8;             /* Speech activity                                                      */\r
144     SKP_int                         allow_bandwidth_switch;         /* Flag indicating that switching of internal bandwidth is allowed      */\r
145     SKP_int8                        LBRRprevLastGainIndex;\r
146     SKP_int8                        prevSignalType;\r
147     SKP_int                         prevLag;\r
148     SKP_int                         pitch_LPC_win_length;\r
149     SKP_int                         max_pitch_lag;                  /* Highest possible pitch lag (samples)                                 */\r
150     SKP_int32                       API_fs_Hz;                      /* API sampling frequency (Hz)                                          */\r
151     SKP_int32                       prev_API_fs_Hz;                 /* Previous API sampling frequency (Hz)                                 */\r
152     SKP_int                         maxInternal_fs_Hz;              /* Maximum internal sampling frequency (Hz)                             */\r
153     SKP_int                         minInternal_fs_Hz;              /* Minimum internal sampling frequency (Hz)                             */\r
154     SKP_int                         desiredInternal_fs_Hz;          /* Soft request for internal sampling frequency (Hz)                    */\r
155     SKP_int                         fs_kHz;                         /* Internal sampling frequency (kHz)                                    */\r
156     SKP_int                         nb_subfr;                       /* Number of 5 ms subframes in a frame                                  */\r
157     SKP_int                         frame_length;                   /* Frame length (samples)                                               */\r
158     SKP_int                         subfr_length;                   /* Subframe length (samples)                                            */\r
159     SKP_int                         ltp_mem_length;                 /* Length of LTP memory                                                 */\r
160     SKP_int                         la_pitch;                       /* Look-ahead for pitch analysis (samples)                              */\r
161     SKP_int                         la_shape;                       /* Look-ahead for noise shape analysis (samples)                        */\r
162     SKP_int                         shapeWinLength;                 /* Window length for noise shape analysis (samples)                     */\r
163     SKP_int32                       TargetRate_bps;                 /* Target bitrate (bps)                                                 */\r
164     SKP_int                         PacketSize_ms;                  /* Number of milliseconds to put in each packet                         */\r
165     SKP_int                         PacketLoss_perc;                /* Packet loss rate measured by farend                                  */\r
166     SKP_int32                       frameCounter;\r
167     SKP_int                         Complexity;                     /* Complexity setting                                                   */\r
168     SKP_int                         nStatesDelayedDecision;         /* Number of states in delayed decision quantization                    */\r
169     SKP_int                         useInterpolatedNLSFs;           /* Flag for using NLSF interpolation                                    */\r
170     SKP_int                         shapingLPCOrder;                /* Filter order for noise shaping filters                               */\r
171     SKP_int                         predictLPCOrder;                /* Filter order for prediction filters                                  */\r
172     SKP_int                         pitchEstimationComplexity;      /* Complexity level for pitch estimator                                 */\r
173     SKP_int                         pitchEstimationLPCOrder;        /* Whitening filter order for pitch estimator                           */\r
174     SKP_int32                       pitchEstimationThreshold_Q16;   /* Threshold for pitch estimator                                        */\r
175     SKP_int                         LTPQuantLowComplexity;          /* Flag for low complexity LTP quantization                             */\r
176     SKP_int                         mu_LTP_Q9;                      /* Rate-distortion tradeoff in LTP quantization                         */\r
177     SKP_int                         NLSF_MSVQ_Survivors;            /* Number of survivors in NLSF MSVQ                                     */\r
178     SKP_int                         first_frame_after_reset;        /* Flag for deactivating NLSF interp. and fluc. reduction after resets  */\r
179     SKP_int                         controlled_since_last_payload;  /* Flag for ensuring codec_control only runs once per packet            */\r
180         SKP_int                         warping_Q16;                    /* Warping parameter for warped noise shaping                           */\r
181     SKP_int                         useCBR;                         /* Flag to enable constant bitrate                                      */\r
182     SKP_int                         prefillFlag;                    /* Flag to indicate that only buffers are prefilled, no coding          */\r
183     const SKP_uint8                 *pitch_lag_low_bits_iCDF;       /* Pointer to iCDF table for low bits of pitch lag index                */\r
184     const SKP_uint8                 *pitch_contour_iCDF;            /* Pointer to iCDF table for pitch contour index                        */\r
185     const silk_NLSF_CB_struct       *psNLSF_CB;                     /* Pointer to NLSF codebook                                             */\r
186     SKP_int                         input_quality_bands_Q15[ VAD_N_BANDS ];\r
187     SKP_int                         input_tilt_Q15;\r
188     SKP_int                         SNR_dB_Q7;                      /* Quality setting                                                      */\r
189 \r
190     SKP_int8                        VAD_flags[ MAX_FRAMES_PER_PACKET ];\r
191     SKP_int8                        LBRR_flag;\r
192     SKP_int                         LBRR_flags[ MAX_FRAMES_PER_PACKET ];\r
193 \r
194     SideInfoIndices                 indices;\r
195         SKP_int8                        pulses[ MAX_FRAME_LENGTH ];\r
196 \r
197     /* Input/output buffering */\r
198     SKP_int16                       inputBuf__[ MAX_FRAME_LENGTH + 2 ]; /* Buffer containing input signal                                   */\r
199     SKP_int16                       *inputBuf;                      /* Points to second element of above buffer                             */\r
200     SKP_int                         inputBufIx;\r
201     SKP_int                         nFramesPerPacket;\r
202     SKP_int                         nFramesEncoded;                 /* Number of frames analyzed in current packet                          */\r
203 \r
204     SKP_int                         nChannelsAPI;\r
205     SKP_int                         nChannelsInternal;\r
206     SKP_int                         channelNb;\r
207 \r
208     /* Parameters For LTP scaling Control */\r
209     SKP_int                         frames_since_onset;\r
210 \r
211     /* Specifically for entropy coding */\r
212     SKP_int                         ec_prevSignalType;\r
213     SKP_int16                       ec_prevLagIndex;\r
214 \r
215     silk_resampler_state_struct resampler_state;\r
216 \r
217     /* DTX */\r
218     SKP_int                         useDTX;                         /* Flag to enable DTX                                                   */\r
219     SKP_int                         inDTX;                          /* Flag to signal DTX period                                            */\r
220     SKP_int                         noSpeechCounter;                /* Counts concecutive nonactive frames, used by DTX                     */\r
221 \r
222     /* Inband Low Bitrate Redundancy (LBRR) data */ \r
223     SKP_int                         useInBandFEC;                   /* Saves the API setting for query                                      */\r
224     SKP_int                         LBRR_enabled;                   /* Depends on useInBandFRC, bitrate and packet loss rate                */\r
225     SKP_int                         LBRR_GainIncreases;             /* Gains increment for coding LBRR frames                               */\r
226     SideInfoIndices                 indices_LBRR[ MAX_FRAMES_PER_PACKET ];\r
227         SKP_int8                        pulses_LBRR[ MAX_FRAMES_PER_PACKET ][ MAX_FRAME_LENGTH ];\r
228 } silk_encoder_state;\r
229 \r
230 \r
231 /* Struct for Packet Loss Concealment */\r
232 typedef struct {\r
233     SKP_int32   pitchL_Q8;                      /* Pitch lag to use for voiced concealment                  */\r
234     SKP_int16   LTPCoef_Q14[ LTP_ORDER ];       /* LTP coeficients to use for voiced concealment            */\r
235     SKP_int16   prevLPC_Q12[ MAX_LPC_ORDER ];\r
236     SKP_int     last_frame_lost;                /* Was previous frame lost                                  */\r
237     SKP_int32   rand_seed;                      /* Seed for unvoiced signal generation                      */\r
238     SKP_int16   randScale_Q14;                  /* Scaling of unvoiced random signal                        */\r
239     SKP_int32   conc_energy;\r
240     SKP_int     conc_energy_shift;\r
241     SKP_int16   prevLTP_scale_Q14;\r
242     SKP_int32   prevGain_Q16[ MAX_NB_SUBFR ];\r
243     SKP_int     fs_kHz;\r
244 } silk_PLC_struct;\r
245 \r
246 /* Struct for CNG */\r
247 typedef struct {\r
248     SKP_int32   CNG_exc_buf_Q10[ MAX_FRAME_LENGTH ];\r
249     SKP_int16   CNG_smth_NLSF_Q15[ MAX_LPC_ORDER ];\r
250     SKP_int32   CNG_synth_state[ MAX_LPC_ORDER ];\r
251     SKP_int32   CNG_smth_Gain_Q16;\r
252     SKP_int32   rand_seed;\r
253     SKP_int     fs_kHz;\r
254 } silk_CNG_struct;\r
255 \r
256 /********************************/\r
257 /* Decoder state                */\r
258 /********************************/\r
259 typedef struct {\r
260     SKP_int32       prev_inv_gain_Q16;\r
261     SKP_int32       sLTP_Q16[ 2 * MAX_FRAME_LENGTH ];\r
262     SKP_int32       sLPC_Q14[ MAX_SUB_FRAME_LENGTH + MAX_LPC_ORDER ];\r
263     SKP_int32       exc_Q10[ MAX_FRAME_LENGTH ];\r
264     SKP_int16       outBuf[ 2 * MAX_FRAME_LENGTH ];             /* Buffer for output signal                                             */\r
265     SKP_int         lagPrev;                                    /* Previous Lag                                                         */\r
266     SKP_int8        LastGainIndex;                              /* Previous gain index                                                  */\r
267     SKP_int         fs_kHz;                                     /* Sampling frequency in kHz                                            */\r
268     SKP_int32       prev_API_sampleRate;                        /* Previous API sample frequency (Hz)                                   */\r
269     SKP_int         nb_subfr;                                   /* Number of 5 ms subframes in a frame                                  */\r
270     SKP_int         frame_length;                               /* Frame length (samples)                                               */\r
271     SKP_int         subfr_length;                               /* Subframe length (samples)                                            */\r
272     SKP_int         ltp_mem_length;                             /* Length of LTP memory                                                 */\r
273     SKP_int         LPC_order;                                  /* LPC order                                                            */\r
274     SKP_int16       prevNLSF_Q15[ MAX_LPC_ORDER ];              /* Used to interpolate LSFs                                             */\r
275     SKP_int         first_frame_after_reset;                    /* Flag for deactivating NLSF interp. and fluc. reduction after resets  */\r
276     const SKP_uint8 *pitch_lag_low_bits_iCDF;                   /* Pointer to iCDF table for low bits of pitch lag index                */\r
277     const SKP_uint8 *pitch_contour_iCDF;                        /* Pointer to iCDF table for pitch contour index                        */\r
278 \r
279     /* For buffering payload in case of more frames per packet */\r
280     SKP_int         nFramesDecoded;\r
281     SKP_int         nFramesPerPacket;\r
282 \r
283     /* Specifically for entropy coding */\r
284     SKP_int         ec_prevSignalType;\r
285     SKP_int16       ec_prevLagIndex;\r
286 \r
287     SKP_int         VAD_flags[ MAX_FRAMES_PER_PACKET ];\r
288     SKP_int         LBRR_flag;\r
289     SKP_int         LBRR_flags[ MAX_FRAMES_PER_PACKET ];\r
290 \r
291     silk_resampler_state_struct resampler_state;\r
292 \r
293     const silk_NLSF_CB_struct   *psNLSF_CB;                 /* Pointer to NLSF codebook                                             */\r
294 \r
295     /* Quantization indices */\r
296     SideInfoIndices indices;\r
297     \r
298     /* CNG state */\r
299     silk_CNG_struct sCNG;\r
300 \r
301     /* Stuff used for PLC */\r
302     SKP_int         lossCnt;\r
303     SKP_int         prevSignalType;\r
304 \r
305     silk_PLC_struct sPLC;\r
306 \r
307 } silk_decoder_state;\r
308 \r
309 /************************/\r
310 /* Decoder control      */\r
311 /************************/\r
312 typedef struct {\r
313     /* prediction and coding parameters */\r
314     SKP_int             pitchL[ MAX_NB_SUBFR ];\r
315     SKP_int32           Gains_Q16[ MAX_NB_SUBFR ];\r
316     /* holds interpolated and final coefficients, 4-byte aligned */\r
317     SKP_DWORD_ALIGN SKP_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];\r
318     SKP_int16           LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ];\r
319     SKP_int             LTP_scale_Q14;\r
320 } silk_decoder_control;\r
321 \r
322 \r
323 #ifdef __cplusplus\r
324 }\r
325 #endif\r
326 \r
327 #endif\r