OLD | NEW |
---|---|
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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 &(audio_history[signal_length - kUnvoicedLpcOrder]), | 668 &(audio_history[signal_length - kUnvoicedLpcOrder]), |
669 sizeof(int16_t) * kUnvoicedLpcOrder); | 669 sizeof(int16_t) * kUnvoicedLpcOrder); |
670 memcpy(unvoiced_vector - kUnvoicedLpcOrder, | 670 memcpy(unvoiced_vector - kUnvoicedLpcOrder, |
671 &(audio_history[signal_length - 128 - kUnvoicedLpcOrder]), | 671 &(audio_history[signal_length - 128 - kUnvoicedLpcOrder]), |
672 sizeof(int16_t) * kUnvoicedLpcOrder); | 672 sizeof(int16_t) * kUnvoicedLpcOrder); |
673 WebRtcSpl_FilterMAFastQ12(&audio_history[signal_length - 128], | 673 WebRtcSpl_FilterMAFastQ12(&audio_history[signal_length - 128], |
674 unvoiced_vector, | 674 unvoiced_vector, |
675 parameters.ar_filter, | 675 parameters.ar_filter, |
676 kUnvoicedLpcOrder + 1, | 676 kUnvoicedLpcOrder + 1, |
677 128); | 677 128); |
678 int16_t unvoiced_prescale; | 678 const int16_t unvoiced_max_abs = |
679 if (WebRtcSpl_MaxAbsValueW16(unvoiced_vector, 128) > 4000) { | 679 WebRtcSpl_MaxAbsValueW16(unvoiced_vector, 128); |
680 unvoiced_prescale = 4; | 680 // Pick the smallest n such that 2^n > unvoiced_max_abs; then the maximum |
681 } else { | 681 // value of the dot product is less than 2^7 * 2^(2*n) = 2^(2*n + 7), so to |
682 unvoiced_prescale = 0; | 682 // prevent overflows we want 2n + 7 <= 31, which means we should shift by |
683 // 2n + 7 - 31 bits, if this value is greater than zero. | |
684 int unvoiced_prescale = | |
685 std::max(0, 2 * WebRtcSpl_GetSizeInBits(unvoiced_max_abs) - 24); | |
686 // Since WebRtcSpl_MaxAbsValueW16 returns 2^15 - 1 when the input contains | |
687 // -2^15, we have to increase the prescale in that case to avoid the | |
688 // possibility of overflow. | |
689 if (unvoiced_max_abs == WEBRTC_SPL_WORD16_MAX) { | |
690 unvoiced_prescale++; | |
kwiberg-webrtc
2016/12/16 10:23:32
Wouldn't you need to add 2, not just 1? And it's p
ivoc
2016/12/16 11:45:01
The worst case is if the whole array is filled wit
| |
683 } | 691 } |
692 | |
684 int32_t unvoiced_energy = WebRtcSpl_DotProductWithScale(unvoiced_vector, | 693 int32_t unvoiced_energy = WebRtcSpl_DotProductWithScale(unvoiced_vector, |
685 unvoiced_vector, | 694 unvoiced_vector, |
686 128, | 695 128, |
687 unvoiced_prescale); | 696 unvoiced_prescale); |
688 | 697 |
689 // Normalize |unvoiced_energy| to 28 or 29 bits to preserve sqrt() accuracy. | 698 // Normalize |unvoiced_energy| to 28 or 29 bits to preserve sqrt() accuracy. |
690 int16_t unvoiced_scale = WebRtcSpl_NormW32(unvoiced_energy) - 3; | 699 int16_t unvoiced_scale = WebRtcSpl_NormW32(unvoiced_energy) - 3; |
691 // Make sure we do an odd number of shifts since we already have 7 shifts | 700 // Make sure we do an odd number of shifts since we already have 7 shifts |
692 // from dividing with 128 earlier. This will make the total scale factor | 701 // from dividing with 128 earlier. This will make the total scale factor |
693 // even, which is suitable for the sqrt. | 702 // even, which is suitable for the sqrt. |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; | 970 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; |
962 while (samples_generated < length) { | 971 while (samples_generated < length) { |
963 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); | 972 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); |
964 random_vector_->IncreaseSeedIncrement(seed_increment); | 973 random_vector_->IncreaseSeedIncrement(seed_increment); |
965 random_vector_->Generate(rand_length, &random_vector[samples_generated]); | 974 random_vector_->Generate(rand_length, &random_vector[samples_generated]); |
966 samples_generated += rand_length; | 975 samples_generated += rand_length; |
967 } | 976 } |
968 } | 977 } |
969 | 978 |
970 } // namespace webrtc | 979 } // namespace webrtc |
OLD | NEW |