Chromium Code Reviews| 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 |
| 11 #include "webrtc/modules/audio_processing/utility/delay_estimator.h" | 11 #include "webrtc/modules/audio_processing/utility/delay_estimator.h" |
| 12 | 12 |
| 13 #include <algorithm> | |
|
hlundin-webrtc
2016/05/11 13:06:19
C system files go before C++ system files.
peah-webrtc
2016/05/11 13:16:08
Good catch!
Done.
| |
| 13 #include <assert.h> | 14 #include <assert.h> |
| 14 #include <stdlib.h> | 15 #include <stdlib.h> |
| 15 #include <string.h> | 16 #include <string.h> |
| 16 | 17 |
| 17 // Number of right shifts for scaling is linearly depending on number of bits in | 18 // Number of right shifts for scaling is linearly depending on number of bits in |
| 18 // the far-end binary spectrum. | 19 // the far-end binary spectrum. |
| 19 static const int kShiftsAtZero = 13; // Right shifts at zero binary spectrum. | 20 static const int kShiftsAtZero = 13; // Right shifts at zero binary spectrum. |
| 20 static const int kShiftsLinearSlope = 3; | 21 static const int kShiftsLinearSlope = 3; |
| 21 | 22 |
| 22 static const int32_t kProbabilityOffset = 1024; // 2 in Q9. | 23 static const int32_t kProbabilityOffset = 1024; // 2 in Q9. |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 // 1) The valley is distinct enough (|valley_depth| > |kProbabilityOffset|) | 612 // 1) The valley is distinct enough (|valley_depth| > |kProbabilityOffset|) |
| 612 // and | 613 // and |
| 613 // 2) The depth of the valley is deep enough | 614 // 2) The depth of the valley is deep enough |
| 614 // (|value_best_candidate| < |minimum_probability|) | 615 // (|value_best_candidate| < |minimum_probability|) |
| 615 // and deeper than the best estimate so far | 616 // and deeper than the best estimate so far |
| 616 // (|value_best_candidate| < |last_delay_probability|) | 617 // (|value_best_candidate| < |last_delay_probability|) |
| 617 valid_candidate = ((valley_depth > kProbabilityOffset) && | 618 valid_candidate = ((valley_depth > kProbabilityOffset) && |
| 618 ((value_best_candidate < self->minimum_probability) || | 619 ((value_best_candidate < self->minimum_probability) || |
| 619 (value_best_candidate < self->last_delay_probability))); | 620 (value_best_candidate < self->last_delay_probability))); |
| 620 | 621 |
| 621 UpdateRobustValidationStatistics(self, candidate_delay, valley_depth, | 622 // Check for nonstationary farend signal. |
| 622 value_best_candidate); | 623 const bool non_stationary_farend = |
| 624 std::any_of(self->farend->far_bit_counts, | |
| 625 self->farend->far_bit_counts + self->history_size, | |
| 626 [](int a) { return a > 0; }); | |
| 627 | |
| 628 if (non_stationary_farend) { | |
| 629 // Only update the validation statistics when the farend is nonstationary | |
| 630 // as the underlying estimates are otherwise frozen. | |
| 631 UpdateRobustValidationStatistics(self, candidate_delay, valley_depth, | |
| 632 value_best_candidate); | |
| 633 } | |
| 634 | |
| 623 if (self->robust_validation_enabled) { | 635 if (self->robust_validation_enabled) { |
| 624 int is_histogram_valid = HistogramBasedValidation(self, candidate_delay); | 636 int is_histogram_valid = HistogramBasedValidation(self, candidate_delay); |
| 625 valid_candidate = RobustValidation(self, candidate_delay, valid_candidate, | 637 valid_candidate = RobustValidation(self, candidate_delay, valid_candidate, |
| 626 is_histogram_valid); | 638 is_histogram_valid); |
| 627 | 639 |
| 628 } | 640 } |
| 629 if (valid_candidate) { | 641 |
| 642 // Only update the delay estimate when the farend is nonstationary and when | |
| 643 // a valid delay candidate is available. | |
| 644 if (non_stationary_farend && valid_candidate) { | |
| 630 if (candidate_delay != self->last_delay) { | 645 if (candidate_delay != self->last_delay) { |
| 631 self->last_delay_histogram = | 646 self->last_delay_histogram = |
| 632 (self->histogram[candidate_delay] > kLastHistogramMax ? | 647 (self->histogram[candidate_delay] > kLastHistogramMax ? |
| 633 kLastHistogramMax : self->histogram[candidate_delay]); | 648 kLastHistogramMax : self->histogram[candidate_delay]); |
| 634 // Adjust the histogram if we made a change to |last_delay|, though it was | 649 // Adjust the histogram if we made a change to |last_delay|, though it was |
| 635 // not the most likely one according to the histogram. | 650 // not the most likely one according to the histogram. |
| 636 if (self->histogram[candidate_delay] < | 651 if (self->histogram[candidate_delay] < |
| 637 self->histogram[self->compare_delay]) { | 652 self->histogram[self->compare_delay]) { |
| 638 self->histogram[self->compare_delay] = self->histogram[candidate_delay]; | 653 self->histogram[self->compare_delay] = self->histogram[candidate_delay]; |
| 639 } | 654 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 int32_t diff = new_value - *mean_value; | 693 int32_t diff = new_value - *mean_value; |
| 679 | 694 |
| 680 // mean_new = mean_value + ((new_value - mean_value) >> factor); | 695 // mean_new = mean_value + ((new_value - mean_value) >> factor); |
| 681 if (diff < 0) { | 696 if (diff < 0) { |
| 682 diff = -((-diff) >> factor); | 697 diff = -((-diff) >> factor); |
| 683 } else { | 698 } else { |
| 684 diff = (diff >> factor); | 699 diff = (diff >> factor); |
| 685 } | 700 } |
| 686 *mean_value += diff; | 701 *mean_value += diff; |
| 687 } | 702 } |
| OLD | NEW |