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)) {} | |
aleloi
2016/12/23 14:28:38
Suggestion: initialize the buffer with 16 zeroes a
peah-webrtc
2017/01/02 08:45:10
That does not seem to work.
I think the reason is
aleloi
2017/01/09 13:49:28
Ok, I see. Sorry for the delay.
| |
22 | |
23 BlockFramer::~BlockFramer() = default; | |
24 | |
25 // All the constants are chosen so that the buffer is either empty or has enough | |
26 // samples for InsertBlockAndExtractSubFrame to produce a frame. In order to | |
27 // achieve this, the InsertBlockAndExtractSubFrame and InsertBlock methods need | |
28 // to be called in the correct order. | |
29 void BlockFramer::InsertBlock(const std::vector<std::vector<float>>& block) { | |
30 RTC_DCHECK_EQ(num_bands_, block.size()); | |
31 for (size_t i = 0; i < num_bands_; ++i) { | |
32 RTC_DCHECK_EQ(kBlockSize, block[i].size()); | |
33 RTC_DCHECK_EQ(0, buffer_[i].size()); | |
34 buffer_[i].insert(buffer_[i].begin(), block[i].begin(), block[i].end()); | |
35 } | |
36 } | |
37 | |
38 void BlockFramer::InsertBlockAndExtractSubFrame( | |
39 const std::vector<std::vector<float>>& block, | |
40 std::vector<rtc::ArrayView<float>>* sub_frame) { | |
41 RTC_DCHECK_EQ(num_bands_, block.size()); | |
42 RTC_DCHECK_EQ(num_bands_, sub_frame->size()); | |
43 for (size_t i = 0; i < num_bands_; ++i) { | |
44 RTC_DCHECK_LE(kSubFrameLength, buffer_[i].size() + kBlockSize); | |
45 RTC_DCHECK_EQ(kBlockSize, block[i].size()); | |
46 RTC_DCHECK_GE(kBlockSize, buffer_[i].size()); | |
47 RTC_DCHECK_EQ(kSubFrameLength, (*sub_frame)[i].size()); | |
48 const int samples_to_frame = kSubFrameLength - buffer_[i].size(); | |
49 std::copy(buffer_[i].begin(), buffer_[i].end(), (*sub_frame)[i].begin()); | |
50 std::copy(block[i].begin(), block[i].begin() + samples_to_frame, | |
51 (*sub_frame)[i].begin() + buffer_[i].size()); | |
52 buffer_[i].resize(0); | |
53 buffer_[i].insert(buffer_[i].begin(), block[i].begin() + samples_to_frame, | |
54 block[i].end()); | |
55 } | |
56 } | |
57 | |
58 } // namespace webrtc | |
OLD | NEW |