| 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 aecpc->delayCtr = 0; | 228 aecpc->delayCtr = 0; |
| 229 aecpc->sampFactor = (aecpc->scSampFreq * 1.0f) / aecpc->splitSampFreq; | 229 aecpc->sampFactor = (aecpc->scSampFreq * 1.0f) / aecpc->splitSampFreq; |
| 230 // Sampling frequency multiplier (SWB is processed as 160 frame size). | 230 // Sampling frequency multiplier (SWB is processed as 160 frame size). |
| 231 aecpc->rate_factor = aecpc->splitSampFreq / 8000; | 231 aecpc->rate_factor = aecpc->splitSampFreq / 8000; |
| 232 | 232 |
| 233 aecpc->sum = 0; | 233 aecpc->sum = 0; |
| 234 aecpc->counter = 0; | 234 aecpc->counter = 0; |
| 235 aecpc->checkBuffSize = 1; | 235 aecpc->checkBuffSize = 1; |
| 236 aecpc->firstVal = 0; | 236 aecpc->firstVal = 0; |
| 237 | 237 |
| 238 aecpc->startup_phase = WebRtcAec_reported_delay_enabled(aecpc->aec); | 238 // We skip the startup_phase completely (setting to 0) if DA-AEC is enabled, |
| 239 // but not extended_filter mode. |
| 240 aecpc->startup_phase = WebRtcAec_extended_filter_enabled(aecpc->aec) || |
| 241 WebRtcAec_reported_delay_enabled(aecpc->aec); |
| 239 aecpc->bufSizeStart = 0; | 242 aecpc->bufSizeStart = 0; |
| 240 aecpc->checkBufSizeCtr = 0; | 243 aecpc->checkBufSizeCtr = 0; |
| 241 aecpc->msInSndCardBuf = 0; | 244 aecpc->msInSndCardBuf = 0; |
| 242 aecpc->filtDelay = -1; // -1 indicates an initialized state. | 245 aecpc->filtDelay = -1; // -1 indicates an initialized state. |
| 243 aecpc->timeForDelayChange = 0; | 246 aecpc->timeForDelayChange = 0; |
| 244 aecpc->knownDelay = 0; | 247 aecpc->knownDelay = 0; |
| 245 aecpc->lastDelayDiff = 0; | 248 aecpc->lastDelayDiff = 0; |
| 246 | 249 |
| 247 aecpc->skewFrCtr = 0; | 250 aecpc->skewFrCtr = 0; |
| 248 aecpc->resample = kAecFalse; | 251 aecpc->resample = kAecFalse; |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 // to the buffer and no delay compensation nor AEC processing | 714 // to the buffer and no delay compensation nor AEC processing |
| 712 // has been done. | 715 // has been done. |
| 713 WebRtcAec_MoveFarReadPtr(aecpc->aec, overhead_elements); | 716 WebRtcAec_MoveFarReadPtr(aecpc->aec, overhead_elements); |
| 714 | 717 |
| 715 // Enable the AEC | 718 // Enable the AEC |
| 716 aecpc->startup_phase = 0; | 719 aecpc->startup_phase = 0; |
| 717 } | 720 } |
| 718 } | 721 } |
| 719 } else { | 722 } else { |
| 720 // AEC is enabled. | 723 // AEC is enabled. |
| 721 if (WebRtcAec_reported_delay_enabled(aecpc->aec)) { | 724 EstBufDelayNormal(aecpc); |
| 722 EstBufDelayNormal(aecpc); | |
| 723 } | |
| 724 | 725 |
| 725 // Call the AEC. | 726 // Call the AEC. |
| 726 // TODO(bjornv): Re-structure such that we don't have to pass | 727 // TODO(bjornv): Re-structure such that we don't have to pass |
| 727 // |aecpc->knownDelay| as input. Change name to something like | 728 // |aecpc->knownDelay| as input. Change name to something like |
| 728 // |system_buffer_diff|. | 729 // |system_buffer_diff|. |
| 729 WebRtcAec_ProcessFrames(aecpc->aec, | 730 WebRtcAec_ProcessFrames(aecpc->aec, |
| 730 nearend, | 731 nearend, |
| 731 num_bands, | 732 num_bands, |
| 732 nrOfSamples, | 733 nrOfSamples, |
| 733 aecpc->knownDelay, | 734 aecpc->knownDelay, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 } | 776 } |
| 776 return; | 777 return; |
| 777 } | 778 } |
| 778 if (self->startup_phase) { | 779 if (self->startup_phase) { |
| 779 // In the extended mode, there isn't a startup "phase", just a special | 780 // In the extended mode, there isn't a startup "phase", just a special |
| 780 // action on the first frame. In the trusted delay case, we'll take the | 781 // action on the first frame. In the trusted delay case, we'll take the |
| 781 // current reported delay, unless it's less then our conservative | 782 // current reported delay, unless it's less then our conservative |
| 782 // measurement. | 783 // measurement. |
| 783 int startup_size_ms = | 784 int startup_size_ms = |
| 784 reported_delay_ms < kFixedDelayMs ? kFixedDelayMs : reported_delay_ms; | 785 reported_delay_ms < kFixedDelayMs ? kFixedDelayMs : reported_delay_ms; |
| 786 #if defined(WEBRTC_ANDROID) |
| 785 int target_delay = startup_size_ms * self->rate_factor * 8; | 787 int target_delay = startup_size_ms * self->rate_factor * 8; |
| 786 #if !defined(WEBRTC_ANDROID) | 788 #else |
| 787 // To avoid putting the AEC in a non-causal state we're being slightly | 789 // To avoid putting the AEC in a non-causal state we're being slightly |
| 788 // conservative and scale by 2. On Android we use a fixed delay and | 790 // conservative and scale by 2. On Android we use a fixed delay and |
| 789 // therefore there is no need to scale the target_delay. | 791 // therefore there is no need to scale the target_delay. |
| 790 target_delay /= 2; | 792 int target_delay = startup_size_ms * self->rate_factor * 8 / 2; |
| 791 #endif | 793 #endif |
| 792 int overhead_elements = | 794 int overhead_elements = |
| 793 (WebRtcAec_system_delay(self->aec) - target_delay) / PART_LEN; | 795 (WebRtcAec_system_delay(self->aec) - target_delay) / PART_LEN; |
| 794 WebRtcAec_MoveFarReadPtr(self->aec, overhead_elements); | 796 WebRtcAec_MoveFarReadPtr(self->aec, overhead_elements); |
| 795 self->startup_phase = 0; | 797 self->startup_phase = 0; |
| 796 } | 798 } |
| 797 | 799 |
| 798 if (WebRtcAec_reported_delay_enabled(self->aec)) { | 800 EstBufDelayExtended(self); |
| 799 EstBufDelayExtended(self); | |
| 800 } | |
| 801 | 801 |
| 802 { | 802 { |
| 803 // |delay_diff_offset| gives us the option to manually rewind the delay on | 803 // |delay_diff_offset| gives us the option to manually rewind the delay on |
| 804 // very low delay platforms which can't be expressed purely through | 804 // very low delay platforms which can't be expressed purely through |
| 805 // |reported_delay_ms|. | 805 // |reported_delay_ms|. |
| 806 const int adjusted_known_delay = | 806 const int adjusted_known_delay = |
| 807 WEBRTC_SPL_MAX(0, self->knownDelay + delay_diff_offset); | 807 WEBRTC_SPL_MAX(0, self->knownDelay + delay_diff_offset); |
| 808 | 808 |
| 809 WebRtcAec_ProcessFrames(self->aec, | 809 WebRtcAec_ProcessFrames(self->aec, |
| 810 near, | 810 near, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 } | 914 } |
| 915 } else { | 915 } else { |
| 916 self->timeForDelayChange = 0; | 916 self->timeForDelayChange = 0; |
| 917 } | 917 } |
| 918 self->lastDelayDiff = delay_difference; | 918 self->lastDelayDiff = delay_difference; |
| 919 | 919 |
| 920 if (self->timeForDelayChange > 25) { | 920 if (self->timeForDelayChange > 25) { |
| 921 self->knownDelay = WEBRTC_SPL_MAX((int)self->filtDelay - 256, 0); | 921 self->knownDelay = WEBRTC_SPL_MAX((int)self->filtDelay - 256, 0); |
| 922 } | 922 } |
| 923 } | 923 } |
| OLD | NEW |