Skip to content

Commit 6afe94e

Browse files
committed
Update aec.cpp
1 parent ab89297 commit 6afe94e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

webrtc-sys/src/aec.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace livekit {
66

7+
bool SampleRateSupportsMultiBand(int sample_rate_hz) {
8+
return sample_rate_hz == 32000 || sample_rate_hz == 48000;
9+
}
10+
711
Aec::Aec(const AecOptions& options) : options_(options) {
812
aec3_ = std::make_unique<webrtc::EchoCanceller3>(
913
webrtc::EchoCanceller3Config(), absl::nullopt, options.sample_rate,
@@ -32,7 +36,7 @@ void Aec::cancel_echo(int16_t* cap,
3236
cap_buf_->CopyFrom(cap, stream_cfg);
3337
rend_buf_->CopyFrom(rend, stream_cfg);
3438

35-
if (options_.sample_rate > 16000) {
39+
if (SampleRateSupportsMultiBand(options_.sample_rate)) {
3640
cap_buf_->SplitIntoFrequencyBands();
3741
rend_buf_->SplitIntoFrequencyBands();
3842
}
@@ -41,15 +45,19 @@ void Aec::cancel_echo(int16_t* cap,
4145
aec3_->AnalyzeRender(rend_buf_.get());
4246
aec3_->ProcessCapture(cap_buf_.get(), false);
4347

44-
if (options_.sample_rate > 16000) {
48+
if (SampleRateSupportsMultiBand(options_.sample_rate)) {
4549
cap_buf_->MergeFrequencyBands();
50+
rend_buf_->SplitIntoFrequencyBands();
4651
}
4752

4853
cap_buf_->CopyTo(stream_cfg, cap);
4954
}
5055

5156
std::unique_ptr<Aec> create_aec(int sample_rate, int num_channels) {
57+
if (sample_rate != 16000 && sample_rate != 32000 && sample_rate != 48000)
58+
return nullptr;
59+
5260
return std::make_unique<Aec>(AecOptions{sample_rate, num_channels});
5361
}
5462

55-
} // namespace livekit
63+
} // namespace livekit

0 commit comments

Comments
 (0)