Chromium Code Reviews| Index: webrtc/modules/audio_processing/aec3/block_framer.cc |
| diff --git a/webrtc/modules/audio_processing/aec3/block_framer.cc b/webrtc/modules/audio_processing/aec3/block_framer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..717493b2a527b72b2cdac773ba5a01edb8ada24c |
| --- /dev/null |
| +++ b/webrtc/modules/audio_processing/aec3/block_framer.cc |
| @@ -0,0 +1,55 @@ |
| +/* |
| + * 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 "webrtc/modules/audio_processing/aec3/block_framer.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "webrtc/base/checks.h" |
| + |
| +namespace webrtc { |
| + |
| +BlockFramer::BlockFramer(size_t num_bands) |
| + : num_bands_(num_bands), |
| + buffer_(num_bands_, std::vector<float>(kBlockSize, 0.f)) {} |
| + |
| +BlockFramer::~BlockFramer() = default; |
| + |
| +void BlockFramer::InsertBlock(const std::vector<std::vector<float>>& block) { |
| + RTC_DCHECK_EQ(num_bands_, block.size()); |
| + for (size_t i = 0; i < num_bands_; ++i) { |
| + RTC_DCHECK_EQ(kBlockSize, block[i].size()); |
| + RTC_DCHECK_EQ(0, buffer_[i].size()); |
|
aleloi
2016/12/20 15:55:35
It seems that the BlockFramer methods can only be
ivoc
2016/12/21 13:04:05
I don't really understand why the buffer size shou
peah-webrtc
2016/12/21 23:13:49
It needs to be zero because of the cooperation bet
peah-webrtc
2016/12/21 23:13:50
That is fully correct! Great analysis!
Added the c
|
| + buffer_[i].resize(block[i].size()); |
|
hlundin-webrtc
2016/12/20 15:10:34
I think you can simplify these two lines to a sing
peah-webrtc
2016/12/21 23:13:50
Great suggestion! I did not know that!
Done.
|
| + std::copy(block[i].begin(), block[i].end(), buffer_[i].begin()); |
| + } |
| +} |
| + |
| +void BlockFramer::InsertBlockAndExtractSubFrame( |
| + const std::vector<std::vector<float>>& block, |
| + rtc::ArrayView<rtc::ArrayView<float>> sub_frame) { |
| + RTC_DCHECK_EQ(num_bands_, block.size()); |
| + RTC_DCHECK_EQ(num_bands_, sub_frame.size()); |
| + for (size_t i = 0; i < num_bands_; ++i) { |
| + RTC_DCHECK_LE(kSubFrameLength, buffer_[i].size() + kBlockSize); |
| + RTC_DCHECK_EQ(kBlockSize, block[i].size()); |
| + RTC_DCHECK_GE(kBlockSize, buffer_[i].size()); |
| + RTC_DCHECK_EQ(kSubFrameLength, sub_frame[i].size()); |
| + const int samples_to_frame = kSubFrameLength - buffer_[i].size(); |
| + std::copy(buffer_[i].begin(), buffer_[i].end(), sub_frame[i].begin()); |
|
hlundin-webrtc
2016/12/20 15:10:35
You can do sub_frame[i].insert(...) here, and skip
aleloi
2016/12/21 10:07:45
sub_frame is ArrayView, not vector. It can only be
hlundin-webrtc
2016/12/21 10:14:19
Acknowledged. My bad. Ignore those comments when I
peah-webrtc
2016/12/21 23:13:49
Acknowledged.
peah-webrtc
2016/12/21 23:13:50
Acknowledged.
peah-webrtc
2016/12/21 23:13:50
It seems like arrayview does not allow that.
Ackn
|
| + std::copy(block[i].begin(), block[i].begin() + samples_to_frame, |
|
hlundin-webrtc
2016/12/20 15:10:34
Same here; again, optional.
peah-webrtc
2016/12/21 23:13:49
Not allowed by arrayview.
|
| + sub_frame[i].begin() + buffer_[i].size()); |
| + buffer_[i].resize(kBlockSize - samples_to_frame); |
|
hlundin-webrtc
2016/12/20 15:10:35
I don't think you have to resize; simply insert().
peah-webrtc
2016/12/21 23:13:50
A resize to 0 was needed before the insert. But I
|
| + std::copy(block[i].begin() + samples_to_frame, block[i].end(), |
| + buffer_[i].begin()); |
| + } |
| +} |
| + |
| +} // namespace webrtc |