1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 /*
12  * settings.h
13  *
14  * Declaration of #defines used in the iSAC codec
15  *
16  */
17 
18 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SETTINGS_H_
19 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SETTINGS_H_
20 
21 /* sampling frequency (Hz) */
22 #define FS                                      16000
23 
24 /* number of samples per frame (either 320 (20ms), 480 (30ms) or 960 (60ms)) */
25 #define INITIAL_FRAMESAMPLES     960
26 
27 
28 #define MAXFFTSIZE 2048
29 #define NFACTOR 11
30 
31 
32 
33 /* do not modify the following; this will have to be modified if we
34  * have a 20ms framesize option */
35 /**********************************************************************/
36 /* miliseconds */
37 #define FRAMESIZE                               30
38 /* number of samples per frame processed in the encoder, 480 */
39 #define FRAMESAMPLES                            480 /* ((FRAMESIZE*FS)/1000) */
40 #define FRAMESAMPLES_HALF      240
41 #define FRAMESAMPLES_QUARTER                    120
42 /**********************************************************************/
43 
44 
45 
46 /* max number of samples per frame (= 60 ms frame) */
47 #define MAX_FRAMESAMPLES      960
48 #define MAX_SWBFRAMESAMPLES                     (MAX_FRAMESAMPLES * 2)
49 /* number of samples per 10ms frame */
50 #define FRAMESAMPLES_10ms                       ((10*FS)/1000)
51 #define SWBFRAMESAMPLES_10ms                    (FRAMESAMPLES_10ms * 2)
52 /* number of samples in 30 ms frame */
53 #define FRAMESAMPLES_30ms            480
54 /* number of subframes */
55 #define SUBFRAMES                               6
56 /* length of a subframe */
57 #define UPDATE                                  80
58 /* length of half a subframe (low/high band) */
59 #define HALF_SUBFRAMELEN                        (UPDATE/2)
60 /* samples of look ahead (in a half-band, so actually
61  * half the samples of look ahead @ FS) */
62 #define QLOOKAHEAD                              24    /* 3 ms */
63 /* order of AR model in spectral entropy coder */
64 #define AR_ORDER                                6
65 /* order of LP model in spectral entropy coder */
66 #define LP_ORDER                                0
67 
68 /* window length (masking analysis) */
69 #define WINLEN                                  256
70 /* order of low-band pole filter used to approximate masking curve */
71 #define ORDERLO                                 12
72 /* order of hi-band pole filter used to approximate masking curve */
73 #define ORDERHI                                 6
74 
75 #define UB_LPC_ORDER                            4
76 #define UB_LPC_VEC_PER_FRAME                    2
77 #define UB16_LPC_VEC_PER_FRAME                  4
78 #define UB_ACTIVE_SUBFRAMES                     2
79 #define UB_MAX_LPC_ORDER                        6
80 #define UB_INTERPOL_SEGMENTS                    1
81 #define UB16_INTERPOL_SEGMENTS                  3
82 #define LB_TOTAL_DELAY_SAMPLES                 48
83 enum ISACBandwidth {isac8kHz = 8, isac12kHz = 12, isac16kHz = 16};
84 enum ISACBand {kIsacLowerBand = 0, kIsacUpperBand12 = 1, kIsacUpperBand16 = 2};
85 #define UB_LPC_GAIN_DIM                 SUBFRAMES
86 #define FB_STATE_SIZE_WORD32                    6
87 
88 
89 /* order for post_filter_bank */
90 #define POSTQORDER                              3
91 /* order for pre-filterbank */
92 #define QORDER                                  3
93 /* another order */
94 #define QORDER_ALL                              (POSTQORDER+QORDER-1)
95 /* for decimator */
96 #define ALLPASSSECTIONS                         2
97 
98 
99 /* array size for byte stream in number of bytes. */
100 /* The old maximum size still needed for the decoding */
101 #define STREAM_SIZE_MAX     600
102 #define STREAM_SIZE_MAX_30  200 /* 200 bytes=53.4 kbps @ 30 ms.framelength */
103 #define STREAM_SIZE_MAX_60  400 /* 400 bytes=53.4 kbps @ 60 ms.framelength */
104 
105 /* storage size for bit counts */
106 #define BIT_COUNTER_SIZE                        30
107 /* maximum order of any AR model or filter */
108 #define MAX_AR_MODEL_ORDER                      12//50
109 
110 
111 /* For pitch analysis */
112 #define PITCH_FRAME_LEN                         (FRAMESAMPLES_HALF) /* 30 ms  */
113 #define PITCH_MAX_LAG                           140     /* 57 Hz  */
114 #define PITCH_MIN_LAG                           20              /* 400 Hz */
115 #define PITCH_MAX_GAIN                          0.45
116 #define PITCH_MAX_GAIN_06                       0.27  /* PITCH_MAX_GAIN*0.6 */
117 #define PITCH_MAX_GAIN_Q12      1843
118 #define PITCH_LAG_SPAN2                     (PITCH_MAX_LAG/2-PITCH_MIN_LAG/2+5)
119 #define PITCH_CORR_LEN2                         60     /* 15 ms  */
120 #define PITCH_CORR_STEP2                        (PITCH_FRAME_LEN/4)
121 #define PITCH_BW        11     /* half the band width of correlation surface */
122 #define PITCH_SUBFRAMES                         4
123 #define PITCH_GRAN_PER_SUBFRAME                 5
124 #define PITCH_SUBFRAME_LEN        (PITCH_FRAME_LEN/PITCH_SUBFRAMES)
125 #define PITCH_UPDATE              (PITCH_SUBFRAME_LEN/PITCH_GRAN_PER_SUBFRAME)
126 /* maximum number of peaks to be examined in correlation surface */
127 #define PITCH_MAX_NUM_PEAKS                  10
128 #define PITCH_PEAK_DECAY               0.85
129 /* For weighting filter */
130 #define PITCH_WLPCORDER                   6
131 #define PITCH_WLPCWINLEN               PITCH_FRAME_LEN
132 #define PITCH_WLPCASYM                   0.3         /* asymmetry parameter */
133 #define PITCH_WLPCBUFLEN               PITCH_WLPCWINLEN
134 /* For pitch filter */
135 /* Extra 50 for fraction and LP filters */
136 #define PITCH_BUFFSIZE                   (PITCH_MAX_LAG + 50)
137 #define PITCH_INTBUFFSIZE               (PITCH_FRAME_LEN+PITCH_BUFFSIZE)
138 /* Max rel. step for interpolation */
139 #define PITCH_UPSTEP                1.5
140 /* Max rel. step for interpolation */
141 #define PITCH_DOWNSTEP                   0.67
142 #define PITCH_FRACS                             8
143 #define PITCH_FRACORDER                         9
144 #define PITCH_DAMPORDER                         5
145 #define PITCH_FILTDELAY                         1.5f
146 /* stepsize for quantization of the pitch Gain */
147 #define PITCH_GAIN_STEPSIZE                     0.125
148 
149 
150 
151 /* Order of high pass filter */
152 #define HPORDER                                 2
153 
154 /* some mathematical constants */
155 /* log2(exp) */
156 #define LOG2EXP                                 1.44269504088896
157 #define PI                                      3.14159265358979
158 
159 /* Maximum number of iterations allowed to limit payload size */
160 #define MAX_PAYLOAD_LIMIT_ITERATION             5
161 
162 /* Redundant Coding */
163 #define RCU_BOTTLENECK_BPS                      16000
164 #define RCU_TRANSCODING_SCALE                   0.40f
165 #define RCU_TRANSCODING_SCALE_INVERSE           2.5f
166 
167 #define RCU_TRANSCODING_SCALE_UB                0.50f
168 #define RCU_TRANSCODING_SCALE_UB_INVERSE        2.0f
169 
170 
171 /* Define Error codes */
172 /* 6000 General */
173 #define ISAC_MEMORY_ALLOCATION_FAILED    6010
174 #define ISAC_MODE_MISMATCH       6020
175 #define ISAC_DISALLOWED_BOTTLENECK     6030
176 #define ISAC_DISALLOWED_FRAME_LENGTH    6040
177 #define ISAC_UNSUPPORTED_SAMPLING_FREQUENCY         6050
178 
179 /* 6200 Bandwidth estimator */
180 #define ISAC_RANGE_ERROR_BW_ESTIMATOR    6240
181 /* 6400 Encoder */
182 #define ISAC_ENCODER_NOT_INITIATED     6410
183 #define ISAC_DISALLOWED_CODING_MODE     6420
184 #define ISAC_DISALLOWED_FRAME_MODE_ENCODER   6430
185 #define ISAC_DISALLOWED_BITSTREAM_LENGTH            6440
186 #define ISAC_PAYLOAD_LARGER_THAN_LIMIT              6450
187 #define ISAC_DISALLOWED_ENCODER_BANDWIDTH           6460
188 /* 6600 Decoder */
189 #define ISAC_DECODER_NOT_INITIATED     6610
190 #define ISAC_EMPTY_PACKET       6620
191 #define ISAC_DISALLOWED_FRAME_MODE_DECODER   6630
192 #define ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH  6640
193 #define ISAC_RANGE_ERROR_DECODE_BANDWIDTH   6650
194 #define ISAC_RANGE_ERROR_DECODE_PITCH_GAIN   6660
195 #define ISAC_RANGE_ERROR_DECODE_PITCH_LAG   6670
196 #define ISAC_RANGE_ERROR_DECODE_LPC     6680
197 #define ISAC_RANGE_ERROR_DECODE_SPECTRUM   6690
198 #define ISAC_LENGTH_MISMATCH      6730
199 #define ISAC_RANGE_ERROR_DECODE_BANDWITH            6740
200 #define ISAC_DISALLOWED_BANDWIDTH_MODE_DECODER      6750
201 #define ISAC_DISALLOWED_LPC_MODEL                   6760
202 /* 6800 Call setup formats */
203 #define ISAC_INCOMPATIBLE_FORMATS     6810
204 
205 #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SETTINGS_H_ */
206