Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(749)

Side by Side Diff: webrtc/modules/audio_processing/aec3/frame_blocker.cc

Issue 2584493002: Added first layer of the echo canceller 3 functionality (Closed)
Patch Set: Restricted the AnalyzeRender access, added ability to add external reporting of echo failure, and o… Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
hlundin-webrtc 2016/12/16 10:04:47 Order of methods is wrong.
peah-webrtc 2016/12/20 10:10:26 Done.
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/frame_blocker.h"
12
13 #include <algorithm>
14
15 #include "webrtc/base/checks.h"
16 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h"
17
18 namespace webrtc {
19
20 FrameBlocker::FrameBlocker(size_t num_bands, size_t frame_length)
21 : num_bands_(num_bands),
22 frame_length_(frame_length),
23 buffer_(num_bands_ * kBlockSize, 0.f) {}
24
25 FrameBlocker::~FrameBlocker() = default;
26
27 void FrameBlocker::InsertFrameAndExtractBlock(size_t sub_frame_index,
28 rtc::ArrayView<const float> frame,
29 rtc::ArrayView<float> block) {
30 RTC_DCHECK_LE(sub_frame_index * kSubFrameLength, frame_length_);
aleloi 2016/12/16 15:04:31 Please DCHECK that the frame is large enough.
peah-webrtc 2016/12/20 10:10:25 I'm not sure what you mean here. The frame is the
31 rtc::ArrayView<const float> frame_view[num_bands_];
hlundin-webrtc 2016/12/16 10:04:47 Please, comment that this is an array of ArrayView
peah-webrtc 2016/12/20 10:10:25 Done.
32 for (size_t i = 0; i < num_bands_; ++i) {
33 frame_view[i] = rtc::ArrayView<const float>(
34 &frame[i * frame_length_ + kSubFrameLength * sub_frame_index],
35 kSubFrameLength);
aleloi 2016/12/16 15:04:31 I think this does the same thing: ... = frame.subv
peah-webrtc 2016/12/20 10:10:25 Great! That is definitely better. I changed to tha
36 }
37 InsertFrameAndExtractBlock(rtc::ArrayView<const rtc::ArrayView<const float>>(
hlundin-webrtc 2016/12/16 10:04:47 An ArrayView of ArrayViews... I think a vector<Arr
peah-webrtc 2016/12/20 10:10:26 What would be the benefit of that be? I changed t
hlundin-webrtc 2016/12/20 15:10:34 Acknowledged.
peah-webrtc 2016/12/21 23:13:49 Acknowledged.
38 &frame_view[0], num_bands_),
39 block);
40 }
41
42 void FrameBlocker::InsertFrameAndExtractBlock(size_t sub_frame_index,
43 const float* const* frame,
44 rtc::ArrayView<float> block) {
45 RTC_DCHECK_LE(sub_frame_index * kSubFrameLength, frame_length_);
46 rtc::ArrayView<const float> frame_view[num_bands_];
hlundin-webrtc 2016/12/16 10:04:47 Again, consider using a vector.
peah-webrtc 2016/12/20 10:10:26 Please see question above.
47 for (size_t i = 0; i < num_bands_; ++i) {
48 frame_view[i] = rtc::ArrayView<const float>(
49 &frame[i][sub_frame_index * kSubFrameLength], kSubFrameLength);
50 }
51 InsertFrameAndExtractBlock(rtc::ArrayView<const rtc::ArrayView<const float>>(
52 &frame_view[0], num_bands_),
53 block);
54 }
55
56 void FrameBlocker::InsertFrameAndExtractBlock(
hlundin-webrtc 2016/12/16 10:04:47 I need a better explanation of what is supposed to
peah-webrtc 2016/12/20 10:10:26 True. I added that into the header file. Done.
57 rtc::ArrayView<const rtc::ArrayView<const float>> frame,
hlundin-webrtc 2016/12/16 10:04:47 Aha! Here is the root of all evil. :) I would reco
peah-webrtc 2016/12/20 10:10:25 Please see question above. I don't see why we want
58 rtc::ArrayView<float> block) {
59 RTC_DCHECK_LE(buffer_size_, kBlockSize);
hlundin-webrtc 2016/12/16 10:04:47 DCHECK that block is long enough.
peah-webrtc 2016/12/20 10:10:25 Done.
60 RTC_DCHECK_GE(kBlockSize - buffer_size_, kSubFrameLength - kBlockSize);
61
aleloi 2016/12/16 15:04:31 I think this is complex enough to warrant a few un
peah-webrtc 2016/12/20 10:10:26 I fully agree. I have now changed to one band per
aleloi 2016/12/20 15:55:35 I like it now!
peah-webrtc 2016/12/21 23:13:49 Great!
62 const size_t samples_to_block = kBlockSize - buffer_size_;
63 size_t band_start_index = 0;
64 for (size_t i = 0; i < num_bands_; ++i) {
65 RTC_DCHECK_EQ(kSubFrameLength, frame[i].size());
66 std::copy(buffer_.begin() + band_start_index,
67 buffer_.begin() + band_start_index + buffer_size_,
68 block.begin() + band_start_index);
69 std::copy(frame[i].begin(), frame[i].begin() + samples_to_block,
70 block.begin() + band_start_index + buffer_size_);
71 std::copy(frame[i].begin() + samples_to_block, frame[i].end(),
72 buffer_.begin() + band_start_index);
73
74 band_start_index += kBlockSize;
75 }
76 buffer_size_ = kSubFrameLength - samples_to_block;
77 }
78
79 bool FrameBlocker::IsBlockAvailable() {
80 return kBlockSize == buffer_size_;
81 }
82
83 bool FrameBlocker::ExtractBlockIfAvailable(rtc::ArrayView<float> block) {
84 RTC_DCHECK_GE(kBlockSize, buffer_size_);
85 if (!IsBlockAvailable()) {
86 return false;
87 }
88 size_t band_start_index = 0;
89 for (size_t i = 0; i < num_bands_; ++i) {
90 std::copy(buffer_.begin() + band_start_index,
91 buffer_.begin() + band_start_index + buffer_size_,
92 block.begin() + band_start_index);
93 band_start_index += kBlockSize;
94 }
95 buffer_size_ = 0;
96 return true;
97 }
98
99 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698