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