blob: 0a242eede7f63d11fa1510be441ab6f7fbb4813b [file] [log] [blame]
Per Åhgren398689f2018-08-23 11:38:27 +02001/*
2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10#include "modules/audio_processing/aec3/block_delay_buffer.h"
11
12#include "rtc_base/checks.h"
13
14namespace webrtc {
15
16BlockDelayBuffer::BlockDelayBuffer(size_t num_bands,
17 size_t frame_length,
18 size_t delay_samples)
19 : frame_length_(frame_length),
20 delay_(delay_samples),
21 buf_(num_bands, std::vector<float>(delay_, 0.f)) {}
22
23BlockDelayBuffer::~BlockDelayBuffer() = default;
24
25void BlockDelayBuffer::DelaySignal(AudioBuffer* frame) {
26 RTC_DCHECK_EQ(1, frame->num_channels());
27 RTC_DCHECK_EQ(buf_.size(), frame->num_bands());
28 if (delay_ == 0) {
29 return;
30 }
31
32 const size_t i_start = last_insert_;
33 size_t i = 0;
34 for (size_t j = 0; j < buf_.size(); ++j) {
35 i = i_start;
36 for (size_t k = 0; k < frame_length_; ++k) {
37 const float tmp = buf_[j][i];
Steve Antonf254e9e2019-08-21 17:52:28 +000038 buf_[j][i] = frame->split_bands_f(0)[j][k];
39 frame->split_bands_f(0)[j][k] = tmp;
Per Åhgren398689f2018-08-23 11:38:27 +020040 i = i < buf_[0].size() - 1 ? i + 1 : 0;
41 }
42 }
43
44 last_insert_ = i;
45}
46
47} // namespace webrtc