OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 |
11 /* | 11 /* |
12 * entropy_coding.c | 12 * entropy_coding.c |
13 * | 13 * |
14 * This file contains all functions used to arithmetically | 14 * This file contains all functions used to arithmetically |
15 * encode the iSAC bistream. | 15 * encode the iSAC bistream. |
16 * | 16 * |
17 */ | 17 */ |
18 | 18 |
19 #include <stddef.h> | 19 #include <stddef.h> |
20 | 20 |
21 #include "arith_routins.h" | 21 #include "arith_routins.h" |
22 #include "spectrum_ar_model_tables.h" | 22 #include "spectrum_ar_model_tables.h" |
23 #include "pitch_gain_tables.h" | 23 #include "pitch_gain_tables.h" |
24 #include "pitch_lag_tables.h" | 24 #include "pitch_lag_tables.h" |
25 #include "entropy_coding.h" | 25 #include "entropy_coding.h" |
26 #include "lpc_tables.h" | 26 #include "lpc_tables.h" |
27 #include "settings.h" | 27 #include "settings.h" |
28 #include "signal_processing_library.h" | 28 #include "signal_processing_library.h" |
29 #include "webrtc/base/checks.h" | |
30 | 29 |
31 /* | 30 /* |
32 * Eenumerations for arguments to functions WebRtcIsacfix_MatrixProduct1() | 31 * Eenumerations for arguments to functions WebRtcIsacfix_MatrixProduct1() |
33 * and WebRtcIsacfix_MatrixProduct2(). | 32 * and WebRtcIsacfix_MatrixProduct2(). |
34 */ | 33 */ |
35 | 34 |
36 enum matrix_index_factor { | 35 enum matrix_index_factor { |
37 kTIndexFactor1 = 1, | 36 kTIndexFactor1 = 1, |
38 kTIndexFactor2 = 2, | 37 kTIndexFactor2 = 2, |
39 kTIndexFactor3 = SUBFRAMES, | 38 kTIndexFactor3 = SUBFRAMES, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 for (n = k; n < AR_ORDER+1; n++) | 223 for (n = k; n < AR_ORDER+1; n++) |
225 sum += WEBRTC_SPL_MUL(ARCoefQ12[n-k], ARCoefQ12[n]); /* Q24 */ | 224 sum += WEBRTC_SPL_MUL(ARCoefQ12[n-k], ARCoefQ12[n]); /* Q24 */ |
226 sum >>= 15; | 225 sum >>= 15; |
227 CorrQ11[k] = (sum * tmpGain + round) >> shftVal; | 226 CorrQ11[k] = (sum * tmpGain + round) >> shftVal; |
228 } | 227 } |
229 sum = CorrQ11[0] << 7; | 228 sum = CorrQ11[0] << 7; |
230 for (n = 0; n < FRAMESAMPLES/8; n++) | 229 for (n = 0; n < FRAMESAMPLES/8; n++) |
231 CurveQ16[n] = sum; | 230 CurveQ16[n] = sum; |
232 | 231 |
233 for (k = 1; k < AR_ORDER; k += 2) { | 232 for (k = 1; k < AR_ORDER; k += 2) { |
234 for (n = 0; n < FRAMESAMPLES/8; n++) { | 233 for (n = 0; n < FRAMESAMPLES/8; n++) |
235 const int64_t p = | 234 CurveQ16[n] += (WebRtcIsacfix_kCos[k][n] * CorrQ11[k + 1] + 2) >> 2; |
236 (WebRtcIsacfix_kCos[k][n] * (int64_t)CorrQ11[k + 1] + 2) >> 2; | |
237 RTC_DCHECK_EQ(p, (int32_t)p); // p fits in 32 bits | |
238 CurveQ16[n] += (int32_t)p; | |
239 } | |
240 } | 235 } |
241 | 236 |
242 CS_ptrQ9 = WebRtcIsacfix_kCos[0]; | 237 CS_ptrQ9 = WebRtcIsacfix_kCos[0]; |
243 | 238 |
244 /* If CorrQ11[1] too large we avoid getting overflow in the calculation by shi
fting */ | 239 /* If CorrQ11[1] too large we avoid getting overflow in the calculation by shi
fting */ |
245 sh=WebRtcSpl_NormW32(CorrQ11[1]); | 240 sh=WebRtcSpl_NormW32(CorrQ11[1]); |
246 if (CorrQ11[1]==0) /* Use next correlation */ | 241 if (CorrQ11[1]==0) /* Use next correlation */ |
247 sh=WebRtcSpl_NormW32(CorrQ11[2]); | 242 sh=WebRtcSpl_NormW32(CorrQ11[2]); |
248 | 243 |
249 if (sh<9) | 244 if (sh<9) |
250 shftVal = 9 - sh; | 245 shftVal = 9 - sh; |
251 else | 246 else |
252 shftVal = 0; | 247 shftVal = 0; |
253 | 248 |
254 for (n = 0; n < FRAMESAMPLES/8; n++) | 249 for (n = 0; n < FRAMESAMPLES/8; n++) |
255 diffQ16[n] = (CS_ptrQ9[n] * (CorrQ11[1] >> shftVal) + 2) >> 2; | 250 diffQ16[n] = (CS_ptrQ9[n] * (CorrQ11[1] >> shftVal) + 2) >> 2; |
256 for (k = 2; k < AR_ORDER; k += 2) { | 251 for (k = 2; k < AR_ORDER; k += 2) { |
257 CS_ptrQ9 = WebRtcIsacfix_kCos[k]; | 252 CS_ptrQ9 = WebRtcIsacfix_kCos[k]; |
258 for (n = 0; n < FRAMESAMPLES/8; n++) | 253 for (n = 0; n < FRAMESAMPLES/8; n++) |
259 diffQ16[n] += (CS_ptrQ9[n] * (CorrQ11[k + 1] >> shftVal) + 2) >> 2; | 254 diffQ16[n] += (CS_ptrQ9[n] * (CorrQ11[k + 1] >> shftVal) + 2) >> 2; |
260 } | 255 } |
261 | 256 |
262 for (k=0; k<FRAMESAMPLES/8; k++) { | 257 for (k=0; k<FRAMESAMPLES/8; k++) { |
263 int32_t diff_q16 = diffQ16[k] * (1 << shftVal); | 258 int32_t diff_q16 = diffQ16[k] * (1 << shftVal); |
264 CurveQ16[FRAMESAMPLES / 4 - 1 - k] = | 259 CurveQ16[FRAMESAMPLES / 4 - 1 - k] = CurveQ16[k] - diff_q16; |
265 WebRtcSpl_SubSatW32(CurveQ16[k], diff_q16); | 260 CurveQ16[k] += diff_q16; |
266 CurveQ16[k] = WebRtcSpl_AddSatW32(CurveQ16[k], diff_q16); | |
267 } | 261 } |
268 } | 262 } |
269 | 263 |
270 static void CalcRootInvArSpec(const int16_t *ARCoefQ12, | 264 static void CalcRootInvArSpec(const int16_t *ARCoefQ12, |
271 const int32_t gainQ10, | 265 const int32_t gainQ10, |
272 uint16_t *CurveQ8) | 266 uint16_t *CurveQ8) |
273 { | 267 { |
274 int32_t CorrQ11[AR_ORDER+1]; | 268 int32_t CorrQ11[AR_ORDER+1]; |
275 int32_t sum, tmpGain; | 269 int32_t sum, tmpGain; |
276 int32_t summQ16[FRAMESAMPLES/8]; | 270 int32_t summQ16[FRAMESAMPLES/8]; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 len = WebRtcIsacfix_DecLogisticMulti2(data, streamdata, invARSpec2_Q16, (int16
_t)FRAMESAMPLES); | 485 len = WebRtcIsacfix_DecLogisticMulti2(data, streamdata, invARSpec2_Q16, (int16
_t)FRAMESAMPLES); |
492 | 486 |
493 if (len<1) | 487 if (len<1) |
494 return -ISAC_RANGE_ERROR_DECODE_SPECTRUM; | 488 return -ISAC_RANGE_ERROR_DECODE_SPECTRUM; |
495 | 489 |
496 /* subtract dither and scale down spectral samples with low SNR */ | 490 /* subtract dither and scale down spectral samples with low SNR */ |
497 if (AvgPitchGain_Q12 <= 614) | 491 if (AvgPitchGain_Q12 <= 614) |
498 { | 492 { |
499 for (k = 0; k < FRAMESAMPLES; k += 4) | 493 for (k = 0; k < FRAMESAMPLES; k += 4) |
500 { | 494 { |
501 gainQ10 = WebRtcSpl_DivW32W16ResW16( | 495 gainQ10 = WebRtcSpl_DivW32W16ResW16(30 << 10, |
502 30 << 10, (int16_t)((uint32_t)(WebRtcSpl_AddSatW32( | 496 (int16_t)((uint32_t)(invARSpec2_Q16[k >> 2] + 2195456) >> 16)); |
503 invARSpec2_Q16[k >> 2], 2195456)) >> | |
504 16)); | |
505 *frQ7++ = (int16_t)((data[k] * gainQ10 + 512) >> 10); | 497 *frQ7++ = (int16_t)((data[k] * gainQ10 + 512) >> 10); |
506 *fiQ7++ = (int16_t)((data[k + 1] * gainQ10 + 512) >> 10); | 498 *fiQ7++ = (int16_t)((data[k + 1] * gainQ10 + 512) >> 10); |
507 *frQ7++ = (int16_t)((data[k + 2] * gainQ10 + 512) >> 10); | 499 *frQ7++ = (int16_t)((data[k + 2] * gainQ10 + 512) >> 10); |
508 *fiQ7++ = (int16_t)((data[k + 3] * gainQ10 + 512) >> 10); | 500 *fiQ7++ = (int16_t)((data[k + 3] * gainQ10 + 512) >> 10); |
509 } | 501 } |
510 } | 502 } |
511 else | 503 else |
512 { | 504 { |
513 for (k = 0; k < FRAMESAMPLES; k += 4) | 505 for (k = 0; k < FRAMESAMPLES; k += 4) |
514 { | 506 { |
515 gainQ10 = WebRtcSpl_DivW32W16ResW16( | 507 gainQ10 = WebRtcSpl_DivW32W16ResW16(36 << 10, |
516 36 << 10, (int16_t)((uint32_t)(WebRtcSpl_AddSatW32( | 508 (int16_t)((uint32_t)(invARSpec2_Q16[k >> 2] + 2654208) >> 16)); |
517 invARSpec2_Q16[k >> 2], 2654208)) >> | |
518 16)); | |
519 *frQ7++ = (int16_t)((data[k] * gainQ10 + 512) >> 10); | 509 *frQ7++ = (int16_t)((data[k] * gainQ10 + 512) >> 10); |
520 *fiQ7++ = (int16_t)((data[k + 1] * gainQ10 + 512) >> 10); | 510 *fiQ7++ = (int16_t)((data[k + 1] * gainQ10 + 512) >> 10); |
521 *frQ7++ = (int16_t)((data[k + 2] * gainQ10 + 512) >> 10); | 511 *frQ7++ = (int16_t)((data[k + 2] * gainQ10 + 512) >> 10); |
522 *fiQ7++ = (int16_t)((data[k + 3] * gainQ10 + 512) >> 10); | 512 *fiQ7++ = (int16_t)((data[k + 3] * gainQ10 + 512) >> 10); |
523 } | 513 } |
524 } | 514 } |
525 | 515 |
526 return len; | 516 return len; |
527 } | 517 } |
528 | 518 |
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2036 | 2026 |
2037 index_gQQ[k] = pos2QQ + WebRtcIsacfix_kQuantMinGain[k]; //ATTN: ok? | 2027 index_gQQ[k] = pos2QQ + WebRtcIsacfix_kQuantMinGain[k]; //ATTN: ok? |
2038 if (index_gQQ[k] < 0) { | 2028 if (index_gQQ[k] < 0) { |
2039 index_gQQ[k] = 0; | 2029 index_gQQ[k] = 0; |
2040 } | 2030 } |
2041 else if (index_gQQ[k] > WebRtcIsacfix_kMaxIndGain[k]) { | 2031 else if (index_gQQ[k] > WebRtcIsacfix_kMaxIndGain[k]) { |
2042 index_gQQ[k] = WebRtcIsacfix_kMaxIndGain[k]; | 2032 index_gQQ[k] = WebRtcIsacfix_kMaxIndGain[k]; |
2043 } | 2033 } |
2044 } | 2034 } |
2045 } | 2035 } |
OLD | NEW |