Initial Skype commit taken from FreeSwitch, which got it from the IETF draft.
[opus.git] / src / SKP_Silk_structs_FIX.h
1 /***********************************************************************\r
2 Copyright (c) 2006-2010, 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 SKP_SILK_STRUCTS_FIX_H\r
29 #define SKP_SILK_STRUCTS_FIX_H\r
30 \r
31 #include "SKP_Silk_typedef.h"\r
32 #include "SKP_Silk_define_FIX.h"\r
33 #include "SKP_Silk_main.h"\r
34 #include "SKP_Silk_structs.h"\r
35 \r
36 #if LOW_COMPLEXITY_ONLY\r
37 #include "SKP_Silk_resample_rom.h"\r
38 #endif\r
39 \r
40 #ifdef __cplusplus\r
41 extern "C"\r
42 {\r
43 #endif\r
44 \r
45 /********************************/\r
46 /* Noise shaping analysis state */\r
47 /********************************/\r
48 typedef struct {\r
49     SKP_int     LastGainIndex;\r
50     SKP_int32   HarmBoost_smth_Q16;\r
51     SKP_int32   HarmShapeGain_smth_Q16;\r
52     SKP_int32   Tilt_smth_Q16;\r
53 } SKP_Silk_shape_state_FIX;\r
54 \r
55 /********************************/\r
56 /* Prefilter state              */\r
57 /********************************/\r
58 typedef struct {\r
59     SKP_int16   sLTP_shp1[ LTP_BUF_LENGTH ];\r
60     SKP_int32   sAR_shp2_Q14[ SHAPE_LPC_ORDER_MAX ];\r
61     SKP_int16   sLTP_shp2_FIX[ LTP_BUF_LENGTH ];\r
62     SKP_int     sLTP_shp_buf_idx1;\r
63     SKP_int     sAR_shp_buf_idx2;\r
64     SKP_int     sLTP_shp_buf_idx2;\r
65     SKP_int32   sLF_AR_shp1_Q12;\r
66     SKP_int32   sLF_MA_shp1_Q12;\r
67     SKP_int32   sLF_AR_shp2_Q12;\r
68     SKP_int32   sLF_MA_shp2_Q12;\r
69     SKP_int     sHarmHP;\r
70     SKP_int32   rand_seed;\r
71     SKP_int     lagPrev;\r
72 } SKP_Silk_prefilter_state_FIX;\r
73 \r
74 /*****************************/\r
75 /* Prediction analysis state */\r
76 /*****************************/\r
77 typedef struct {\r
78     SKP_int   pitch_LPC_win_length;\r
79     SKP_int   min_pitch_lag;                                        /* Lowest possible pitch lag (samples)  */\r
80     SKP_int   max_pitch_lag;                                        /* Highest possible pitch lag (samples) */\r
81     SKP_int   prev_NLSFq_Q15[ MAX_LPC_ORDER ];                      /* Prev. quant. normalized LSF vector   */\r
82 } SKP_Silk_predict_state_FIX;\r
83 \r
84 #if( defined( SAVE_ALL_INTERNAL_DATA ) || defined( USE_FLT2FIX_WRAPPER ) )\r
85 /*******************************************/\r
86 /* Structure containing NLSF MSVQ codebook */\r
87 /*******************************************/\r
88 /* structure for one stage of MSVQ */\r
89 typedef struct {\r
90     const SKP_int32     nVectors;\r
91     const SKP_float     *CB;\r
92     const SKP_float     *Rates;\r
93 } SKP_Silk_NLSF_CBS_FLP_TMP;\r
94 \r
95 typedef struct {\r
96     const SKP_int32                 nStages;\r
97 \r
98     /* fields for (de)quantizing */\r
99     const SKP_Silk_NLSF_CBS_FLP_TMP *CBStages;\r
100     const SKP_float                 *NDeltaMin;\r
101 \r
102     /* fields for arithmetic (de)coding */\r
103     const SKP_uint16                *CDF;\r
104     const SKP_uint16 * const        *StartPtr;\r
105     const SKP_int                   *MiddleIx;\r
106 } SKP_Silk_NLSF_CB_struct_FLP_TMP;\r
107 #endif\r
108 \r
109 /********************************/\r
110 /* Encoder state FIX            */\r
111 /********************************/\r
112 typedef struct {\r
113     SKP_Silk_encoder_state          sCmn;                           /* Common struct, shared with floating-point code */\r
114 \r
115 #if HIGH_PASS_INPUT\r
116     SKP_int32                       variable_HP_smth1_Q15;          /* State of first smoother                                              */\r
117     SKP_int32                       variable_HP_smth2_Q15;          /* State of second smoother                                             */\r
118 #endif\r
119     SKP_Silk_shape_state_FIX        sShape;                         /* Shape state                                                          */\r
120     SKP_Silk_prefilter_state_FIX    sPrefilt;                       /* Prefilter State                                                      */\r
121     SKP_Silk_predict_state_FIX      sPred;                          /* Prediction state                                                     */\r
122     SKP_Silk_nsq_state              sNSQ;                           /* Noise Shape Quantizer State                                          */\r
123     SKP_Silk_nsq_state              sNSQ_LBRR;                      /* Noise Shape Quantizer State ( for low bitrate redundancy )           */\r
124     \r
125     /* Function pointer to noise shaping quantizer (will be set to SKP_Silk_NSQ or SKP_Silk_NSQ_del_dec) */\r
126     void    (* NoiseShapingQuantizer)( SKP_Silk_encoder_state *, SKP_Silk_encoder_control *, SKP_Silk_nsq_state *, const SKP_int16 *, \r
127                                         SKP_int *, const SKP_int, const SKP_int16 *, const SKP_int16 *, const SKP_int16 *, const SKP_int *, \r
128                                         const SKP_int *, const SKP_int32 *, const SKP_int32 *, SKP_int, const SKP_int\r
129     );\r
130 \r
131     /* Buffer for find pitch and noise shape analysis */\r
132     SKP_array_of_int16_4_byte_aligned( x_buf, 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX );    \r
133     SKP_int                         LTPCorr_Q15;                    /* Normalized correlation from pitch lag estimator                      */\r
134     SKP_int                         mu_LTP_Q8;                      /* Rate-distortion tradeoff in LTP quantization                         */\r
135     SKP_int32                       SNR_dB_Q7;                      /* Quality setting                                                      */\r
136     SKP_int32                       avgGain_Q16;                    /* average gain during active speech                                    */\r
137     SKP_int32                       avgGain_Q16_one_bit_per_sample; /* average gain during active speech                                    */\r
138     SKP_int                         BufferedInChannel_ms;           /* Simulated number of ms buffer because of exceeded TargetRate_bps     */\r
139     SKP_int                         speech_activity_Q8;             /* Speech activity in Q8                                                */\r
140     SKP_int32                       pitchEstimationThreshold_Q16;   /* Threshold for pitch estimator                                        */\r
141     \r
142     /* Parameters For LTP scaling Control */\r
143     SKP_int                         prevLTPredCodGain_Q7;\r
144     SKP_int                         HPLTPredCodGain_Q7;\r
145 \r
146     SKP_int32                       inBandFEC_SNR_comp_Q8;          /* Compensation to SNR_dB when using inband FEC Voiced      */\r
147 \r
148 #ifdef USE_FLT2FIX_WRAPPER\r
149     const SKP_Silk_NLSF_CB_struct_FLP_TMP *psNLSF_CB_FLP[ 2 ];      /* Pointers to voiced/unvoiced NLSF codebooks */    \r
150 #endif\r
151 } SKP_Silk_encoder_state_FIX;\r
152 \r
153 /************************/\r
154 /* Encoder control FIX  */\r
155 /************************/\r
156 typedef struct {\r
157     SKP_Silk_encoder_control        sCmn;                           /* Common struct, shared with floating-point code */\r
158 \r
159     /* Prediction and coding parameters */\r
160     SKP_int32                   Gains_Q16[ NB_SUBFR ];\r
161     SKP_array_of_int16_4_byte_aligned( PredCoef_Q12[ 2 ], MAX_LPC_ORDER );\r
162     SKP_int16                   LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ];\r
163     SKP_int                     LTP_scale_Q14;\r
164 \r
165     /* Noise shaping parameters */\r
166     /* Testing */\r
167     SKP_array_of_int16_4_byte_aligned( AR1_Q13, NB_SUBFR * SHAPE_LPC_ORDER_MAX );\r
168     SKP_array_of_int16_4_byte_aligned( AR2_Q13, NB_SUBFR * SHAPE_LPC_ORDER_MAX );\r
169     SKP_int32   LF_shp_Q14[        NB_SUBFR ];          /* Packs two int16 coefficients per int32 value             */\r
170     SKP_int     GainsPre_Q14[      NB_SUBFR ];\r
171     SKP_int     HarmBoost_Q14[     NB_SUBFR ];\r
172     SKP_int     Tilt_Q14[          NB_SUBFR ];\r
173     SKP_int     HarmShapeGain_Q14[ NB_SUBFR ];\r
174     SKP_int     Lambda_Q10;\r
175     SKP_int     input_quality_Q14;\r
176     SKP_int     coding_quality_Q14;\r
177     SKP_int32   pitch_freq_low_Hz;\r
178     SKP_int     current_SNR_dB_Q7;\r
179 \r
180     /* measures */\r
181     SKP_int     sparseness_Q8;\r
182     SKP_int     LTPredCodGain_Q7;\r
183     SKP_int     input_quality_bands_Q15[ VAD_N_BANDS ];\r
184     SKP_int     input_tilt_Q15;\r
185     SKP_int32   ResNrg[ NB_SUBFR ];             /* Residual energy per subframe                             */\r
186     SKP_int     ResNrgQ[ NB_SUBFR ];            /* Q domain for the residual energy > 0                     */\r
187     \r
188 } SKP_Silk_encoder_control_FIX;\r
189 \r
190 \r
191 #ifdef __cplusplus\r
192 }\r
193 #endif\r
194 \r
195 #endif\r