mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00

This is a reland of 87a7b82520
Original change's description:
> Refactoring of the noise suppressor and adding true multichannel support
>
> This CL adds proper multichannel support to the noise suppressor.
> To accomplish that in a safe way, a full refactoring of the noise
> suppressor code has been done.
>
> Due to floating point precision, the changes made are not entirely
> bitexact. They are, however, very close to being bitexact.
>
> As a safety measure, the former noise suppressor code is preserved
> and a kill-switch is added to allow revering to the legacy noise
> suppressor in case issues arise.
>
> Bug: webrtc:10895, b/143344262
> Change-Id: I0b071011b23265ac12e6d4b3956499d122286657
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/158407
> Commit-Queue: Per Åhgren <peah@webrtc.org>
> Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#29646}
Bug: webrtc:10895, b/143344262
Change-Id: I236f1e67bb0baa4e30908a4cf7a8a7bb55fbced3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/158747
Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org>
Commit-Queue: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29663}
102 lines
3.4 KiB
C++
102 lines
3.4 KiB
C++
/*
|
|
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "modules/audio_processing/ns/noise_suppressor.h"
|
|
|
|
#include <deque>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "rtc_base/strings/string_builder.h"
|
|
#include "test/gmock.h"
|
|
#include "test/gtest.h"
|
|
|
|
namespace webrtc {
|
|
namespace {
|
|
|
|
std::string ProduceDebugText(int sample_rate_hz,
|
|
size_t num_channels,
|
|
NsConfig::SuppressionLevel level) {
|
|
rtc::StringBuilder ss;
|
|
ss << "Sample rate: " << sample_rate_hz << ", num_channels: " << num_channels
|
|
<< ", level: " << static_cast<int>(level);
|
|
return ss.Release();
|
|
}
|
|
|
|
void PopulateInputFrameWithIdenticalChannels(size_t num_channels,
|
|
size_t num_bands,
|
|
size_t frame_index,
|
|
AudioBuffer* audio) {
|
|
for (size_t ch = 0; ch < num_channels; ++ch) {
|
|
for (size_t b = 0; b < num_bands; ++b) {
|
|
for (size_t i = 0; i < 160; ++i) {
|
|
float value = static_cast<int>(frame_index * 160 + i);
|
|
audio->split_bands(ch)[b][i] = (value > 0 ? 5000 * b + value : 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void VerifyIdenticalChannels(size_t num_channels,
|
|
size_t num_bands,
|
|
size_t frame_index,
|
|
const AudioBuffer& audio) {
|
|
EXPECT_GT(num_channels, 1u);
|
|
for (size_t ch = 1; ch < num_channels; ++ch) {
|
|
for (size_t b = 0; b < num_bands; ++b) {
|
|
for (size_t i = 0; i < 160; ++i) {
|
|
EXPECT_EQ(audio.split_bands_const(ch)[b][i],
|
|
audio.split_bands_const(0)[b][i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// Verifies that the same noise reduction effect is applied to all channels.
|
|
TEST(NoiseSuppressor, IdenticalChannelEffects) {
|
|
for (auto rate : {16000, 32000, 48000}) {
|
|
for (auto num_channels : {1, 4, 8}) {
|
|
for (auto level :
|
|
{NsConfig::SuppressionLevel::k6dB, NsConfig::SuppressionLevel::k12dB,
|
|
NsConfig::SuppressionLevel::k18dB,
|
|
NsConfig::SuppressionLevel::k21dB}) {
|
|
SCOPED_TRACE(ProduceDebugText(rate, num_channels, level));
|
|
|
|
const size_t num_bands = rate / 16000;
|
|
// const int frame_length = rtc::CheckedDivExact(rate, 100);
|
|
AudioBuffer audio(rate, num_channels, rate, num_channels, rate,
|
|
num_channels);
|
|
NsConfig cfg;
|
|
NoiseSuppressor ns(cfg, rate, num_channels);
|
|
for (size_t frame_index = 0; frame_index < 1000; ++frame_index) {
|
|
if (rate > 16000) {
|
|
audio.SplitIntoFrequencyBands();
|
|
}
|
|
|
|
PopulateInputFrameWithIdenticalChannels(num_channels, num_bands,
|
|
frame_index, &audio);
|
|
|
|
ns.Analyze(audio);
|
|
ns.Process(&audio);
|
|
if (num_channels > 1) {
|
|
VerifyIdenticalChannels(num_channels, num_bands, frame_index,
|
|
audio);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace webrtc
|