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