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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 farend_ptr = new_farend; | 289 farend_ptr = new_farend; |
290 } | 290 } |
291 | 291 |
292 aecpc->farend_started = 1; | 292 aecpc->farend_started = 1; |
293 WebRtcAec_SetSystemDelay(aecpc->aec, WebRtcAec_system_delay(aecpc->aec) + | 293 WebRtcAec_SetSystemDelay(aecpc->aec, WebRtcAec_system_delay(aecpc->aec) + |
294 static_cast<int>(newNrOfSamples)); | 294 static_cast<int>(newNrOfSamples)); |
295 | 295 |
296 // Write the time-domain data to |far_pre_buf|. | 296 // Write the time-domain data to |far_pre_buf|. |
297 WebRtc_WriteBuffer(aecpc->far_pre_buf, farend_ptr, newNrOfSamples); | 297 WebRtc_WriteBuffer(aecpc->far_pre_buf, farend_ptr, newNrOfSamples); |
298 | 298 |
299 // TODO(minyue): reduce to |PART_LEN| samples for each buffering, when | 299 // TODO(minyue): reduce to |PART_LEN| samples for each buffering. |
300 // WebRtcAec_BufferFarendPartition() is changed to take |PART_LEN| samples. | |
301 while (WebRtc_available_read(aecpc->far_pre_buf) >= PART_LEN2) { | 300 while (WebRtc_available_read(aecpc->far_pre_buf) >= PART_LEN2) { |
302 // We have enough data to pass to the FFT, hence read PART_LEN2 samples. | 301 // We have enough data to pass to the FFT, hence read PART_LEN2 samples. |
303 { | 302 { |
304 float* ptmp = NULL; | 303 float* ptmp = NULL; |
305 float tmp[PART_LEN2]; | 304 float tmp[PART_LEN2]; |
306 WebRtc_ReadBuffer(aecpc->far_pre_buf, | 305 WebRtc_ReadBuffer(aecpc->far_pre_buf, |
307 reinterpret_cast<void**>(&ptmp), tmp, PART_LEN2); | 306 reinterpret_cast<void**>(&ptmp), tmp, PART_LEN2); |
308 WebRtcAec_BufferFarendPartition(aecpc->aec, ptmp); | 307 WebRtcAec_BufferFarendBlock(aecpc->aec, &ptmp[PART_LEN]); |
309 } | 308 } |
310 | 309 |
311 // Rewind |far_pre_buf| PART_LEN samples for overlap before continuing. | 310 // Rewind |far_pre_buf| PART_LEN samples for overlap before continuing. |
312 WebRtc_MoveReadPtr(aecpc->far_pre_buf, -PART_LEN); | 311 WebRtc_MoveReadPtr(aecpc->far_pre_buf, -PART_LEN); |
313 } | 312 } |
314 | 313 |
315 return 0; | 314 return 0; |
316 } | 315 } |
317 | 316 |
318 int32_t WebRtcAec_Process(void* aecInst, | 317 int32_t WebRtcAec_Process(void* aecInst, |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 WebRtcAec_system_delay(aecpc->aec) / PART_LEN - aecpc->bufSizeStart; | 645 WebRtcAec_system_delay(aecpc->aec) / PART_LEN - aecpc->bufSizeStart; |
647 if (overhead_elements == 0) { | 646 if (overhead_elements == 0) { |
648 // Enable the AEC | 647 // Enable the AEC |
649 aecpc->startup_phase = 0; | 648 aecpc->startup_phase = 0; |
650 } else if (overhead_elements > 0) { | 649 } else if (overhead_elements > 0) { |
651 // TODO(bjornv): Do we need a check on how much we actually | 650 // TODO(bjornv): Do we need a check on how much we actually |
652 // moved the read pointer? It should always be possible to move | 651 // moved the read pointer? It should always be possible to move |
653 // the pointer |overhead_elements| since we have only added data | 652 // the pointer |overhead_elements| since we have only added data |
654 // to the buffer and no delay compensation nor AEC processing | 653 // to the buffer and no delay compensation nor AEC processing |
655 // has been done. | 654 // has been done. |
656 WebRtcAec_MoveFarReadPtr(aecpc->aec, overhead_elements); | 655 WebRtcAec_AdjustFarendBufferSizeAndSystemDelay(aecpc->aec, |
| 656 overhead_elements); |
657 | 657 |
658 // Enable the AEC | 658 // Enable the AEC |
659 aecpc->startup_phase = 0; | 659 aecpc->startup_phase = 0; |
660 } | 660 } |
661 } | 661 } |
662 } else { | 662 } else { |
663 // AEC is enabled. | 663 // AEC is enabled. |
664 EstBufDelayNormal(aecpc); | 664 EstBufDelayNormal(aecpc); |
665 | 665 |
666 // Call the AEC. | 666 // Call the AEC. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 #if defined(WEBRTC_ANDROID) | 723 #if defined(WEBRTC_ANDROID) |
724 int target_delay = startup_size_ms * self->rate_factor * 8; | 724 int target_delay = startup_size_ms * self->rate_factor * 8; |
725 #else | 725 #else |
726 // To avoid putting the AEC in a non-causal state we're being slightly | 726 // To avoid putting the AEC in a non-causal state we're being slightly |
727 // conservative and scale by 2. On Android we use a fixed delay and | 727 // conservative and scale by 2. On Android we use a fixed delay and |
728 // therefore there is no need to scale the target_delay. | 728 // therefore there is no need to scale the target_delay. |
729 int target_delay = startup_size_ms * self->rate_factor * 8 / 2; | 729 int target_delay = startup_size_ms * self->rate_factor * 8 / 2; |
730 #endif | 730 #endif |
731 int overhead_elements = | 731 int overhead_elements = |
732 (WebRtcAec_system_delay(self->aec) - target_delay) / PART_LEN; | 732 (WebRtcAec_system_delay(self->aec) - target_delay) / PART_LEN; |
733 WebRtcAec_MoveFarReadPtr(self->aec, overhead_elements); | 733 WebRtcAec_AdjustFarendBufferSizeAndSystemDelay(self->aec, |
| 734 overhead_elements); |
734 self->startup_phase = 0; | 735 self->startup_phase = 0; |
735 } | 736 } |
736 | 737 |
737 EstBufDelayExtended(self); | 738 EstBufDelayExtended(self); |
738 | 739 |
739 { | 740 { |
740 // |delay_diff_offset| gives us the option to manually rewind the delay on | 741 // |delay_diff_offset| gives us the option to manually rewind the delay on |
741 // very low delay platforms which can't be expressed purely through | 742 // very low delay platforms which can't be expressed purely through |
742 // |reported_delay_ms|. | 743 // |reported_delay_ms|. |
743 const int adjusted_known_delay = | 744 const int adjusted_known_delay = |
(...skipping 18 matching lines...) Expand all Loading... |
762 // 1) Compensating for the frame(s) that will be read/processed. | 763 // 1) Compensating for the frame(s) that will be read/processed. |
763 current_delay += FRAME_LEN * aecpc->rate_factor; | 764 current_delay += FRAME_LEN * aecpc->rate_factor; |
764 | 765 |
765 // 2) Account for resampling frame delay. | 766 // 2) Account for resampling frame delay. |
766 if (aecpc->skewMode == kAecTrue && aecpc->resample == kAecTrue) { | 767 if (aecpc->skewMode == kAecTrue && aecpc->resample == kAecTrue) { |
767 current_delay -= kResamplingDelay; | 768 current_delay -= kResamplingDelay; |
768 } | 769 } |
769 | 770 |
770 // 3) Compensate for non-causality, if needed, by flushing one block. | 771 // 3) Compensate for non-causality, if needed, by flushing one block. |
771 if (current_delay < PART_LEN) { | 772 if (current_delay < PART_LEN) { |
772 current_delay += WebRtcAec_MoveFarReadPtr(aecpc->aec, 1) * PART_LEN; | 773 current_delay += |
| 774 WebRtcAec_AdjustFarendBufferSizeAndSystemDelay(aecpc->aec, 1) * |
| 775 PART_LEN; |
773 } | 776 } |
774 | 777 |
775 // We use -1 to signal an initialized state in the "extended" implementation; | 778 // We use -1 to signal an initialized state in the "extended" implementation; |
776 // compensate for that. | 779 // compensate for that. |
777 aecpc->filtDelay = aecpc->filtDelay < 0 ? 0 : aecpc->filtDelay; | 780 aecpc->filtDelay = aecpc->filtDelay < 0 ? 0 : aecpc->filtDelay; |
778 aecpc->filtDelay = | 781 aecpc->filtDelay = |
779 WEBRTC_SPL_MAX(0, static_cast<int16_t>(0.8 * | 782 WEBRTC_SPL_MAX(0, static_cast<int16_t>(0.8 * |
780 aecpc->filtDelay + | 783 aecpc->filtDelay + |
781 0.2 * current_delay)); | 784 0.2 * current_delay)); |
782 | 785 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 // 1) Compensating for the frame(s) that will be read/processed. | 820 // 1) Compensating for the frame(s) that will be read/processed. |
818 current_delay += FRAME_LEN * self->rate_factor; | 821 current_delay += FRAME_LEN * self->rate_factor; |
819 | 822 |
820 // 2) Account for resampling frame delay. | 823 // 2) Account for resampling frame delay. |
821 if (self->skewMode == kAecTrue && self->resample == kAecTrue) { | 824 if (self->skewMode == kAecTrue && self->resample == kAecTrue) { |
822 current_delay -= kResamplingDelay; | 825 current_delay -= kResamplingDelay; |
823 } | 826 } |
824 | 827 |
825 // 3) Compensate for non-causality, if needed, by flushing two blocks. | 828 // 3) Compensate for non-causality, if needed, by flushing two blocks. |
826 if (current_delay < PART_LEN) { | 829 if (current_delay < PART_LEN) { |
827 current_delay += WebRtcAec_MoveFarReadPtr(self->aec, 2) * PART_LEN; | 830 current_delay += |
| 831 WebRtcAec_AdjustFarendBufferSizeAndSystemDelay(self->aec, 2) * PART_LEN; |
828 } | 832 } |
829 | 833 |
830 if (self->filtDelay == -1) { | 834 if (self->filtDelay == -1) { |
831 self->filtDelay = WEBRTC_SPL_MAX(0, 0.5 * current_delay); | 835 self->filtDelay = WEBRTC_SPL_MAX(0, 0.5 * current_delay); |
832 } else { | 836 } else { |
833 self->filtDelay = WEBRTC_SPL_MAX( | 837 self->filtDelay = WEBRTC_SPL_MAX( |
834 0, static_cast<int16_t>(0.95 * self->filtDelay + 0.05 * current_delay)); | 838 0, static_cast<int16_t>(0.95 * self->filtDelay + 0.05 * current_delay)); |
835 } | 839 } |
836 | 840 |
837 delay_difference = self->filtDelay - self->knownDelay; | 841 delay_difference = self->filtDelay - self->knownDelay; |
(...skipping 12 matching lines...) Expand all Loading... |
850 } else { | 854 } else { |
851 self->timeForDelayChange = 0; | 855 self->timeForDelayChange = 0; |
852 } | 856 } |
853 self->lastDelayDiff = delay_difference; | 857 self->lastDelayDiff = delay_difference; |
854 | 858 |
855 if (self->timeForDelayChange > 25) { | 859 if (self->timeForDelayChange > 25) { |
856 self->knownDelay = WEBRTC_SPL_MAX((int)self->filtDelay - 256, 0); | 860 self->knownDelay = WEBRTC_SPL_MAX((int)self->filtDelay - 256, 0); |
857 } | 861 } |
858 } | 862 } |
859 } // namespace webrtc | 863 } // namespace webrtc |
OLD | NEW |