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 enum IsacSamplingRate {kIsacWideband = 16,  kIsacSuperWideband = 32};
86 #define UB_LPC_GAIN_DIM                 SUBFRAMES
87 #define FB_STATE_SIZE_WORD32                    6
88 
89 
90 /* order for post_filter_bank */
91 #define POSTQORDER                              3
92 /* order for pre-filterbank */
93 #define QORDER                                  3
94 /* another order */
95 #define QORDER_ALL                              (POSTQORDER+QORDER-1)
96 /* for decimator */
97 #define ALLPASSSECTIONS                         2
98 
99 
100 /* array size for byte stream in number of bytes. */
101 /* The old maximum size still needed for the decoding */
102 #define STREAM_SIZE_MAX     600
103 #define STREAM_SIZE_MAX_30  200 /* 200 bytes=53.4 kbps @ 30 ms.framelength */
104 #define STREAM_SIZE_MAX_60  400 /* 400 bytes=53.4 kbps @ 60 ms.framelength */
105 
106 /* storage size for bit counts */
107 #define BIT_COUNTER_SIZE                        30
108 /* maximum order of any AR model or filter */
109 #define MAX_AR_MODEL_ORDER                      12//50
110 
111 
112 /* For pitch analysis */
113 #define PITCH_FRAME_LEN                         (FRAMESAMPLES_HALF) /* 30 ms  */
114 #define PITCH_MAX_LAG                           140     /* 57 Hz  */
115 #define PITCH_MIN_LAG                           20              /* 400 Hz */
116 #define PITCH_MAX_GAIN                          0.45
117 #define PITCH_MAX_GAIN_06                       0.27  /* PITCH_MAX_GAIN*0.6 */
118 #define PITCH_MAX_GAIN_Q12      1843
119 #define PITCH_LAG_SPAN2                     (PITCH_MAX_LAG/2-PITCH_MIN_LAG/2+5)
120 #define PITCH_CORR_LEN2                         60     /* 15 ms  */
121 #define PITCH_CORR_STEP2                        (PITCH_FRAME_LEN/4)
122 #define PITCH_BW        11     /* half the band width of correlation surface */
123 #define PITCH_SUBFRAMES                         4
124 #define PITCH_GRAN_PER_SUBFRAME                 5
125 #define PITCH_SUBFRAME_LEN        (PITCH_FRAME_LEN/PITCH_SUBFRAMES)
126 #define PITCH_UPDATE              (PITCH_SUBFRAME_LEN/PITCH_GRAN_PER_SUBFRAME)
127 /* maximum number of peaks to be examined in correlation surface */
128 #define PITCH_MAX_NUM_PEAKS                  10
129 #define PITCH_PEAK_DECAY               0.85
130 /* For weighting filter */
131 #define PITCH_WLPCORDER                   6
132 #define PITCH_WLPCWINLEN               PITCH_FRAME_LEN
133 #define PITCH_WLPCASYM                   0.3         /* asymmetry parameter */
134 #define PITCH_WLPCBUFLEN               PITCH_WLPCWINLEN
135 /* For pitch filter */
136 /* Extra 50 for fraction and LP filters */
137 #define PITCH_BUFFSIZE                   (PITCH_MAX_LAG + 50)
138 #define PITCH_INTBUFFSIZE               (PITCH_FRAME_LEN+PITCH_BUFFSIZE)
139 /* Max rel. step for interpolation */
140 #define PITCH_UPSTEP                1.5
141 /* Max rel. step for interpolation */
142 #define PITCH_DOWNSTEP                   0.67
143 #define PITCH_FRACS                             8
144 #define PITCH_FRACORDER                         9
145 #define PITCH_DAMPORDER                         5
146 #define PITCH_FILTDELAY                         1.5f
147 /* stepsize for quantization of the pitch Gain */
148 #define PITCH_GAIN_STEPSIZE                     0.125
149 
150 
151 
152 /* Order of high pass filter */
153 #define HPORDER                                 2
154 
155 /* some mathematical constants */
156 /* log2(exp) */
157 #define LOG2EXP                                 1.44269504088896
158 #define PI                                      3.14159265358979
159 
160 /* Maximum number of iterations allowed to limit payload size */
161 #define MAX_PAYLOAD_LIMIT_ITERATION             5
162 
163 /* Redundant Coding */
164 #define RCU_BOTTLENECK_BPS                      16000
165 #define RCU_TRANSCODING_SCALE                   0.40f
166 #define RCU_TRANSCODING_SCALE_INVERSE           2.5f
167 
168 #define RCU_TRANSCODING_SCALE_UB                0.50f
169 #define RCU_TRANSCODING_SCALE_UB_INVERSE        2.0f
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