| 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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 static float CalculatePower(const float* in, size_t num_samples) { | 561 static float CalculatePower(const float* in, size_t num_samples) { |
| 562 size_t k; | 562 size_t k; |
| 563 float energy = 0.0f; | 563 float energy = 0.0f; |
| 564 | 564 |
| 565 for (k = 0; k < num_samples; ++k) { | 565 for (k = 0; k < num_samples; ++k) { |
| 566 energy += in[k] * in[k]; | 566 energy += in[k] * in[k]; |
| 567 } | 567 } |
| 568 return energy / num_samples; | 568 return energy / num_samples; |
| 569 } | 569 } |
| 570 | 570 |
| 571 static void UpdateLevel(PowerLevel* level, float energy) { | 571 static void UpdateLevel(PowerLevel* level, float power) { |
| 572 level->sfrsum += energy; | 572 level->sfrsum += power; |
| 573 level->sfrcounter++; | 573 level->sfrcounter++; |
| 574 | 574 |
| 575 if (level->sfrcounter > subCountLen) { | 575 if (level->sfrcounter > subCountLen) { |
| 576 level->framelevel = level->sfrsum / (subCountLen * PART_LEN); | 576 level->framelevel = level->sfrsum / subCountLen; |
| 577 level->sfrsum = 0; | 577 level->sfrsum = 0; |
| 578 level->sfrcounter = 0; | 578 level->sfrcounter = 0; |
| 579 if (level->framelevel > 0) { | 579 if (level->framelevel > 0) { |
| 580 if (level->framelevel < level->minlevel) { | 580 if (level->framelevel < level->minlevel) { |
| 581 level->minlevel = level->framelevel; // New minimum. | 581 level->minlevel = level->framelevel; // New minimum. |
| 582 } else { | 582 } else { |
| 583 level->minlevel *= (1 + 0.001f); // Small increase. | 583 level->minlevel *= (1 + 0.001f); // Small increase. |
| 584 } | 584 } |
| 585 } | 585 } |
| 586 level->frcounter++; | 586 level->frcounter++; |
| 587 level->frsum += level->framelevel; | 587 level->frsum += level->framelevel; |
| 588 if (level->frcounter > countLen) { | 588 if (level->frcounter > countLen) { |
| 589 level->averagelevel = level->frsum / countLen; | 589 level->averagelevel = level->frsum / countLen; |
| 590 level->frsum = 0; | 590 level->frsum = 0; |
| 591 level->frcounter = 0; | 591 level->frcounter = 0; |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 } | 594 } |
| 595 | 595 |
| 596 static void UpdateMetrics(AecCore* aec) { | 596 static void UpdateMetrics(AecCore* aec) { |
| 597 float dtmp, dtmp2; | 597 float dtmp, dtmp2; |
| 598 | 598 |
| 599 const float actThresholdNoisy = 8.0f; | 599 const float actThresholdNoisy = 8.0f; |
| 600 const float actThresholdClean = 40.0f; | 600 const float actThresholdClean = 40.0f; |
| 601 const float safety = 0.99995f; | 601 const float safety = 0.99995f; |
| 602 | 602 |
| 603 // To make noisePower consistent with the legacy code, a factor of | 603 const float noisyPower = 300000.0f; |
| 604 // 2.0f / PART_LEN2 is applied to noisyPower, since the legacy code uses | |
| 605 // the energy of a frame as the audio levels, while the new code uses a | |
| 606 // a per-sample energy (i.e., power). | |
| 607 const float noisyPower = 300000.0f * 2.0f / PART_LEN2; | |
| 608 | 604 |
| 609 float actThreshold; | 605 float actThreshold; |
| 610 float echo, suppressedEcho; | 606 float echo, suppressedEcho; |
| 611 | 607 |
| 612 if (aec->echoState) { // Check if echo is likely present | 608 if (aec->echoState) { // Check if echo is likely present |
| 613 aec->stateCounter++; | 609 aec->stateCounter++; |
| 614 } | 610 } |
| 615 | 611 |
| 616 if (aec->farlevel.frcounter == 0) { | 612 if (aec->farlevel.frcounter == 0) { |
| 617 if (aec->farlevel.minlevel < noisyPower) { | 613 if (aec->farlevel.minlevel < noisyPower) { |
| (...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1896 | 1892 |
| 1897 int WebRtcAec_system_delay(AecCore* self) { | 1893 int WebRtcAec_system_delay(AecCore* self) { |
| 1898 return self->system_delay; | 1894 return self->system_delay; |
| 1899 } | 1895 } |
| 1900 | 1896 |
| 1901 void WebRtcAec_SetSystemDelay(AecCore* self, int delay) { | 1897 void WebRtcAec_SetSystemDelay(AecCore* self, int delay) { |
| 1902 assert(delay >= 0); | 1898 assert(delay >= 0); |
| 1903 self->system_delay = delay; | 1899 self->system_delay = delay; |
| 1904 } | 1900 } |
| 1905 } // namespace webrtc | 1901 } // namespace webrtc |
| OLD | NEW |