1 /*
2  *  Copyright (c) 2011 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_FIX_SOURCE_SETTINGS_H_
19 #define MODULES_AUDIO_CODING_CODECS_ISAC_FIX_SOURCE_SETTINGS_H_
20 
21 /* sampling frequency (Hz) */
22 #define FS 16000
23 /* 1.5 times Sampling frequency */
24 #define FS_1_HALF (uint32_t)24000
25 /* Three times Sampling frequency */
26 #define FS3 (uint32_t)48000
27 /* Eight times Sampling frequency */
28 #define FS8 (uint32_t)128000
29 
30 /* number of samples per frame (either 480 (30ms) or 960 (60ms)) */
31 #define INITIAL_FRAMESAMPLES 960
32 
33 /* miliseconds */
34 #define FRAMESIZE 30
35 /* number of samples per frame processed in the encoder (30ms) */
36 #define FRAMESAMPLES 480 /* ((FRAMESIZE*FS)/1000) */
37 #define FRAMESAMPLES_HALF 240
38 /* max number of samples per frame (= 60 ms frame) */
39 #define MAX_FRAMESAMPLES 960
40 /* number of samples per 10ms frame */
41 #define FRAMESAMPLES_10ms 160 /* ((10*FS)/1000) */
42 /* Number of samples per 1 ms */
43 #define SAMPLES_PER_MSEC 16
44 /* number of subframes */
45 #define SUBFRAMES 6
46 /* length of a subframe */
47 #define UPDATE 80
48 /* length of half a subframe (low/high band) */
49 #define HALF_SUBFRAMELEN 40 /* (UPDATE/2) */
50 /* samples of look ahead (in a half-band, so actually half the samples of look
51  * ahead @ FS) */
52 #define QLOOKAHEAD 24 /* 3 ms */
53 
54 /* order of AR model in spectral entropy coder */
55 #define AR_ORDER 6
56 #define MAX_ORDER 13
57 #define LEVINSON_MAX_ORDER 12
58 
59 /* window length (masking analysis) */
60 #define WINLEN 256
61 /* order of low-band pole filter used to approximate masking curve */
62 #define ORDERLO 12
63 /* order of hi-band pole filter used to approximate masking curve */
64 #define ORDERHI 6
65 
66 #define KLT_NUM_AVG_GAIN 0
67 #define KLT_NUM_AVG_SHAPE 0
68 #define KLT_NUM_MODELS 3
69 #define LPC_SHAPE_ORDER 18 /* (ORDERLO + ORDERHI) */
70 
71 #define KLT_ORDER_GAIN 12   /* (2 * SUBFRAMES) */
72 #define KLT_ORDER_SHAPE 108 /*  (LPC_SHAPE_ORDER * SUBFRAMES) */
73 
74 /* order for post_filter_bank */
75 #define POSTQORDER 3
76 /* order for pre-filterbank */
77 #define QORDER 3
78 /* for decimator */
79 #define ALLPASSSECTIONS 2
80 /* The number of composite all-pass filter factors */
81 #define NUMBEROFCOMPOSITEAPSECTIONS 4
82 
83 /* The number of all-pass filter factors in an upper or lower channel*/
84 #define NUMBEROFCHANNELAPSECTIONS 2
85 
86 #define DPMIN_Q10 -10240  /* -10.00 in Q10 */
87 #define DPMAX_Q10 10240   /* 10.00 in Q10 */
88 #define MINBITS_Q10 10240 /* 10.0 in Q10 */
89 
90 /* array size for byte stream in number of Word16. */
91 #define STREAM_MAXW16 \
92   300 /* The old maximum size still needed for the decoding */
93 #define STREAM_MAXW16_30MS \
94   100 /* 100 Word16 = 200 bytes = 53.4 kbit/s @ 30 ms.framelength */
95 #define STREAM_MAXW16_60MS \
96   200 /* 200 Word16 = 400 bytes = 53.4 kbit/s @ 60 ms.framelength */
97 /* This is used only at the decoder bit-stream struct.
98  * - The encoder and decoder bitstream containers are of different size because
99  *   old iSAC limited the encoded bitstream to 600 bytes. But newer versions
100  *   restrict to shorter bitstream.
101  * - We add 10 bytes of guards to the internal bitstream container. The reason
102  *   is that entropy decoder might read few bytes (3 according to our
103  *   observations) more than the actual size of the bitstream. To avoid reading
104  *   outside memory, in rare occasion of full-size bitstream we add 10 bytes
105  *   of guard. */
106 #define INTERNAL_STREAM_SIZE_W16 (STREAM_MAXW16 + 5)
107 
108 /* storage size for bit counts */
109 //#define BIT_COUNTER_SIZE                        30
110 /* maximum order of any AR model or filter */
111 #define MAX_AR_MODEL_ORDER 12
112 
113 /* Maximum number of iterations allowed to limit payload size */
114 #define MAX_PAYLOAD_LIMIT_ITERATION 1
115 
116 /* Bandwidth estimator */
117 
118 #define MIN_ISAC_BW 10000 /* Minimum bandwidth in bits per sec */
119 #define MAX_ISAC_BW 32000 /* Maxmum bandwidth in bits per sec */
120 #define MIN_ISAC_MD 5     /* Minimum Max Delay in ?? */
121 #define MAX_ISAC_MD 25    /* Maxmum Max Delay in ?? */
122 #define DELAY_CORRECTION_MAX 717
123 #define DELAY_CORRECTION_MED 819
124 #define Thld_30_60 18000
125 #define Thld_60_30 27000
126 
127 /* assumed header size; we don't know the exact number (header compression may
128  * be used) */
129 #define HEADER_SIZE 35 /* bytes */
130 #define INIT_FRAME_LEN 60
131 #define INIT_BN_EST 20000
132 #define INIT_BN_EST_Q7 2560000    /* 20 kbps in Q7 */
133 #define INIT_REC_BN_EST_Q5 789312 /* INIT_BN_EST + INIT_HDR_RATE in Q5 */
134 
135 /* 8738 in Q18 is ~ 1/30 */
136 /* #define INIT_HDR_RATE (((HEADER_SIZE * 8 * 1000) * 8738) >> NUM_BITS_TO_SHIFT
137  * (INIT_FRAME_LEN)) */
138 #define INIT_HDR_RATE 4666
139 /* number of packets in a row for a high rate burst */
140 #define BURST_LEN 3
141 /* ms, max time between two full bursts */
142 #define BURST_INTERVAL 800
143 /* number of packets in a row for initial high rate burst */
144 #define INIT_BURST_LEN 5
145 /* bits/s, rate for the first BURST_LEN packets */
146 #define INIT_RATE 10240000 /* INIT_BN_EST in Q9 */
147 
148 /* For pitch analysis */
149 #define PITCH_FRAME_LEN 240   /* (FRAMESAMPLES/2) 30 ms  */
150 #define PITCH_MAX_LAG 140     /* 57 Hz  */
151 #define PITCH_MIN_LAG 20      /* 400 Hz */
152 #define PITCH_MIN_LAG_Q8 5120 /* 256 * PITCH_MIN_LAG */
153 #define OFFSET_Q8 768         /* 256 * 3 */
154 
155 #define PITCH_MAX_GAIN_Q12 1843 /* 0.45 */
156 #define PITCH_LAG_SPAN2 65      /* (PITCH_MAX_LAG/2-PITCH_MIN_LAG/2+5) */
157 #define PITCH_CORR_LEN2 60      /* 15 ms  */
158 #define PITCH_CORR_STEP2 60     /* (PITCH_FRAME_LEN/4) */
159 #define PITCH_SUBFRAMES 4
160 #define PITCH_SUBFRAME_LEN 60 /* (PITCH_FRAME_LEN/PITCH_SUBFRAMES) */
161 
162 /* For pitch filter */
163 #define PITCH_BUFFSIZE \
164   190 /* (PITCH_MAX_LAG + 50) Extra 50 for fraction and LP filters */
165 #define PITCH_INTBUFFSIZE 430 /* (PITCH_FRAME_LEN+PITCH_BUFFSIZE) */
166 #define PITCH_FRACS 8
167 #define PITCH_FRACORDER 9
168 #define PITCH_DAMPORDER 5
169 
170 /* Order of high pass filter */
171 #define HPORDER 2
172 
173 /* PLC */
174 #define DECAY_RATE \
175   10 /* Q15, 20% of decay every lost frame apllied linearly sample by sample*/
176 #define PLC_WAS_USED 1
177 #define PLC_NOT_USED 3
178 #define RECOVERY_OVERLAP 80
179 #define RESAMP_RES 256
180 #define RESAMP_RES_BIT 8
181 
182 /* Define Error codes */
183 /* 6000 General */
184 #define ISAC_MEMORY_ALLOCATION_FAILED 6010
185 #define ISAC_MODE_MISMATCH 6020
186 #define ISAC_DISALLOWED_BOTTLENECK 6030
187 #define ISAC_DISALLOWED_FRAME_LENGTH 6040
188 /* 6200 Bandwidth estimator */
189 #define ISAC_RANGE_ERROR_BW_ESTIMATOR 6240
190 /* 6400 Encoder */
191 #define ISAC_ENCODER_NOT_INITIATED 6410
192 #define ISAC_DISALLOWED_CODING_MODE 6420
193 #define ISAC_DISALLOWED_FRAME_MODE_ENCODER 6430
194 #define ISAC_DISALLOWED_BITSTREAM_LENGTH 6440
195 #define ISAC_PAYLOAD_LARGER_THAN_LIMIT 6450
196 /* 6600 Decoder */
197 #define ISAC_DECODER_NOT_INITIATED 6610
198 #define ISAC_EMPTY_PACKET 6620
199 #define ISAC_PACKET_TOO_SHORT 6625
200 #define ISAC_DISALLOWED_FRAME_MODE_DECODER 6630
201 #define ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH 6640
202 #define ISAC_RANGE_ERROR_DECODE_BANDWIDTH 6650
203 #define ISAC_RANGE_ERROR_DECODE_PITCH_GAIN 6660
204 #define ISAC_RANGE_ERROR_DECODE_PITCH_LAG 6670
205 #define ISAC_RANGE_ERROR_DECODE_LPC 6680
206 #define ISAC_RANGE_ERROR_DECODE_SPECTRUM 6690
207 #define ISAC_LENGTH_MISMATCH 6730
208 /* 6800 Call setup formats */
209 #define ISAC_INCOMPATIBLE_FORMATS 6810
210 
211 #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_FIX_SOURCE_SETTINGS_H_ */
212