Per Åhgren | 398689f | 2018-08-23 11:38:27 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 14 | namespace webrtc { |
| 15 | |
| 16 | BlockDelayBuffer::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 | |
| 23 | BlockDelayBuffer::~BlockDelayBuffer() = default; |
| 24 | |
| 25 | void 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]; |
Per Åhgren | d47941e | 2019-08-22 11:51:13 +0200 | [diff] [blame^] | 38 | buf_[j][i] = frame->split_bands(0)[j][k]; |
| 39 | frame->split_bands(0)[j][k] = tmp; |
Per Åhgren | 398689f | 2018-08-23 11:38:27 +0200 | [diff] [blame] | 40 | i = i < buf_[0].size() - 1 ? i + 1 : 0; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | last_insert_ = i; |
| 45 | } |
| 46 | |
| 47 | } // namespace webrtc |