OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 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 | |
11 #include "webrtc/modules/audio_processing/aec3/block_framer.h" | |
12 | |
13 #include <algorithm> | |
14 | |
15 #include "webrtc/base/checks.h" | |
16 | |
17 namespace webrtc { | |
18 | |
19 BlockFramer::BlockFramer(size_t num_bands) | |
20 : num_bands_(num_bands), | |
21 buffer_(num_bands_, std::vector<float>(kBlockSize, 0.f)) {} | |
22 | |
23 BlockFramer::~BlockFramer() = default; | |
24 | |
25 void BlockFramer::InsertBlock(const std::vector<std::vector<float>>& block) { | |
26 RTC_DCHECK_EQ(num_bands_, block.size()); | |
27 for (size_t i = 0; i < num_bands_; ++i) { | |
28 RTC_DCHECK_EQ(kBlockSize, block[i].size()); | |
29 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
| |
30 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.
| |
31 std::copy(block[i].begin(), block[i].end(), buffer_[i].begin()); | |
32 } | |
33 } | |
34 | |
35 void BlockFramer::InsertBlockAndExtractSubFrame( | |
36 const std::vector<std::vector<float>>& block, | |
37 rtc::ArrayView<rtc::ArrayView<float>> sub_frame) { | |
38 RTC_DCHECK_EQ(num_bands_, block.size()); | |
39 RTC_DCHECK_EQ(num_bands_, sub_frame.size()); | |
40 for (size_t i = 0; i < num_bands_; ++i) { | |
41 RTC_DCHECK_LE(kSubFrameLength, buffer_[i].size() + kBlockSize); | |
42 RTC_DCHECK_EQ(kBlockSize, block[i].size()); | |
43 RTC_DCHECK_GE(kBlockSize, buffer_[i].size()); | |
44 RTC_DCHECK_EQ(kSubFrameLength, sub_frame[i].size()); | |
45 const int samples_to_frame = kSubFrameLength - buffer_[i].size(); | |
46 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
| |
47 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.
| |
48 sub_frame[i].begin() + buffer_[i].size()); | |
49 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
| |
50 std::copy(block[i].begin() + samples_to_frame, block[i].end(), | |
51 buffer_[i].begin()); | |
52 } | |
53 } | |
54 | |
55 } // namespace webrtc | |
OLD | NEW |