Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.c

Issue 1734883003: iSAC entropy coder: Avoid signed integer overflow (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 int16_t dither1_Q7, dither2_Q7, dither_gain_Q14; 175 int16_t dither1_Q7, dither2_Q7, dither_gain_Q14;
176 176
177 /* This threshold should be equal to that in decode_spec(). */ 177 /* This threshold should be equal to that in decode_spec(). */
178 if (AvgPitchGain_Q12 < 614) { 178 if (AvgPitchGain_Q12 < 614) {
179 for (k = 0; k < length - 2; k += 3) { 179 for (k = 0; k < length - 2; k += 3) {
180 /* New random unsigned int. */ 180 /* New random unsigned int. */
181 seed = (seed * 196314165) + 907633515; 181 seed = (seed * 196314165) + 907633515;
182 182
183 /* Fixed-point dither sample between -64 and 64 (Q7). */ 183 /* Fixed-point dither sample between -64 and 64 (Q7). */
184 /* dither = seed * 128 / 4294967295 */ 184 /* dither = seed * 128 / 4294967295 */
185 dither1_Q7 = (int16_t)(((int)seed + 16777216) >> 25); 185 dither1_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25);
186 186
187 /* New random unsigned int. */ 187 /* New random unsigned int. */
188 seed = (seed * 196314165) + 907633515; 188 seed = (seed * 196314165) + 907633515;
189 189
190 /* Fixed-point dither sample between -64 and 64. */ 190 /* Fixed-point dither sample between -64 and 64. */
191 dither2_Q7 = (int16_t)(((int)seed + 16777216) >> 25); 191 dither2_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25);
192 192
193 shft = (seed >> 25) & 15; 193 shft = (seed >> 25) & 15;
194 if (shft < 5) { 194 if (shft < 5) {
195 bufQ7[k] = dither1_Q7; 195 bufQ7[k] = dither1_Q7;
196 bufQ7[k + 1] = dither2_Q7; 196 bufQ7[k + 1] = dither2_Q7;
197 bufQ7[k + 2] = 0; 197 bufQ7[k + 2] = 0;
198 } else if (shft < 10) { 198 } else if (shft < 10) {
199 bufQ7[k] = dither1_Q7; 199 bufQ7[k] = dither1_Q7;
200 bufQ7[k + 1] = 0; 200 bufQ7[k + 1] = 0;
201 bufQ7[k + 2] = dither2_Q7; 201 bufQ7[k + 2] = dither2_Q7;
202 } else { 202 } else {
203 bufQ7[k] = 0; 203 bufQ7[k] = 0;
204 bufQ7[k + 1] = dither1_Q7; 204 bufQ7[k + 1] = dither1_Q7;
205 bufQ7[k + 2] = dither2_Q7; 205 bufQ7[k + 2] = dither2_Q7;
206 } 206 }
207 } 207 }
208 } else { 208 } else {
209 dither_gain_Q14 = (int16_t)(22528 - 10 * AvgPitchGain_Q12); 209 dither_gain_Q14 = (int16_t)(22528 - 10 * AvgPitchGain_Q12);
210 210
211 /* Dither on half of the coefficients. */ 211 /* Dither on half of the coefficients. */
212 for (k = 0; k < length - 1; k += 2) { 212 for (k = 0; k < length - 1; k += 2) {
213 /* New random unsigned int */ 213 /* New random unsigned int */
214 seed = (seed * 196314165) + 907633515; 214 seed = (seed * 196314165) + 907633515;
215 215
216 /* Fixed-point dither sample between -64 and 64. */ 216 /* Fixed-point dither sample between -64 and 64. */
217 dither1_Q7 = (int16_t)(((int)seed + 16777216) >> 25); 217 dither1_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25);
218 218
219 /* Dither sample is placed in either even or odd index. */ 219 /* Dither sample is placed in either even or odd index. */
220 shft = (seed >> 25) & 1; /* Either 0 or 1 */ 220 shft = (seed >> 25) & 1; /* Either 0 or 1 */
221 221
222 bufQ7[k + shft] = (((dither_gain_Q14 * dither1_Q7) + 8192) >> 14); 222 bufQ7[k + shft] = (((dither_gain_Q14 * dither1_Q7) + 8192) >> 14);
223 bufQ7[k + 1 - shft] = 0; 223 bufQ7[k + 1 - shft] = 0;
224 } 224 }
225 } 225 }
226 } 226 }
227 227
(...skipping 19 matching lines...) Expand all
247 int16_t* bufQ7, 247 int16_t* bufQ7,
248 uint32_t seed, 248 uint32_t seed,
249 int length) { 249 int length) {
250 int k; 250 int k;
251 for (k = 0; k < length; k++) { 251 for (k = 0; k < length; k++) {
252 /* new random unsigned int */ 252 /* new random unsigned int */
253 seed = (seed * 196314165) + 907633515; 253 seed = (seed * 196314165) + 907633515;
254 254
255 /* Fixed-point dither sample between -64 and 64 (Q7). */ 255 /* Fixed-point dither sample between -64 and 64 (Q7). */
256 /* bufQ7 = seed * 128 / 4294967295 */ 256 /* bufQ7 = seed * 128 / 4294967295 */
257 bufQ7[k] = (int16_t)(((int)seed + 16777216) >> 25); 257 bufQ7[k] = (int16_t)(((int32_t)(seed + 16777216)) >> 25);
258 258
259 /* Scale by 0.35. */ 259 /* Scale by 0.35. */
260 bufQ7[k] = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(bufQ7[k], 2048, 13); 260 bufQ7[k] = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(bufQ7[k], 2048, 13);
261 } 261 }
262 } 262 }
263 263
264 /* 264 /*
265 * Function to decode the complex spectrum from the bit stream 265 * Function to decode the complex spectrum from the bit stream
266 * returns the total number of bytes in the stream. 266 * returns the total number of bytes in the stream.
267 */ 267 */
(...skipping 1789 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 /* Use the same CDF table as for bandwidth 2057 /* Use the same CDF table as for bandwidth
2058 * both take two values with equal probability. */ 2058 * both take two values with equal probability. */
2059 if (WebRtcIsac_DecHistOneStepMulti(&intVar, streamData, 2059 if (WebRtcIsac_DecHistOneStepMulti(&intVar, streamData,
2060 kOneBitEqualProbCdf_ptr, 2060 kOneBitEqualProbCdf_ptr,
2061 kOneBitEqualProbInitIndex, 1) < 0) { 2061 kOneBitEqualProbInitIndex, 1) < 0) {
2062 return -ISAC_RANGE_ERROR_DECODE_BANDWITH; 2062 return -ISAC_RANGE_ERROR_DECODE_BANDWITH;
2063 } 2063 }
2064 *jitterInfo = (int16_t)(intVar); 2064 *jitterInfo = (int16_t)(intVar);
2065 return 0; 2065 return 0;
2066 } 2066 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698