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

Side by Side Diff: webrtc/modules/audio_processing/utility/blocker.cc

Issue 1846903004: Moved ring-buffer related files from common_audio to audio_processing (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Corrected order of includes Created 4 years, 8 months 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
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/common_audio/blocker.h" 11 #include "webrtc/modules/audio_processing/utility/blocker.h"
12 12
13 #include <string.h> 13 #include <string.h>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 16
17 namespace { 17 namespace {
18 18
19 // Adds |a| and |b| frame by frame into |result| (basically matrix addition). 19 // Adds |a| and |b| frame by frame into |result| (basically matrix addition).
20 void AddFrames(const float* const* a, 20 void AddFrames(const float* const* a,
21 size_t a_start_index, 21 size_t a_start_index,
(...skipping 12 matching lines...) Expand all
34 } 34 }
35 35
36 // Copies |src| into |dst| channel by channel. 36 // Copies |src| into |dst| channel by channel.
37 void CopyFrames(const float* const* src, 37 void CopyFrames(const float* const* src,
38 size_t src_start_index, 38 size_t src_start_index,
39 size_t num_frames, 39 size_t num_frames,
40 size_t num_channels, 40 size_t num_channels,
41 float* const* dst, 41 float* const* dst,
42 size_t dst_start_index) { 42 size_t dst_start_index) {
43 for (size_t i = 0; i < num_channels; ++i) { 43 for (size_t i = 0; i < num_channels; ++i) {
44 memcpy(&dst[i][dst_start_index], 44 memcpy(&dst[i][dst_start_index], &src[i][src_start_index],
45 &src[i][src_start_index],
46 num_frames * sizeof(dst[i][dst_start_index])); 45 num_frames * sizeof(dst[i][dst_start_index]));
47 } 46 }
48 } 47 }
49 48
50 // Moves |src| into |dst| channel by channel. 49 // Moves |src| into |dst| channel by channel.
51 void MoveFrames(const float* const* src, 50 void MoveFrames(const float* const* src,
52 size_t src_start_index, 51 size_t src_start_index,
53 size_t num_frames, 52 size_t num_frames,
54 size_t num_channels, 53 size_t num_channels,
55 float* const* dst, 54 float* const* dst,
56 size_t dst_start_index) { 55 size_t dst_start_index) {
57 for (size_t i = 0; i < num_channels; ++i) { 56 for (size_t i = 0; i < num_channels; ++i) {
58 memmove(&dst[i][dst_start_index], 57 memmove(&dst[i][dst_start_index], &src[i][src_start_index],
59 &src[i][src_start_index],
60 num_frames * sizeof(dst[i][dst_start_index])); 58 num_frames * sizeof(dst[i][dst_start_index]));
61 } 59 }
62 } 60 }
63 61
64 void ZeroOut(float* const* buffer, 62 void ZeroOut(float* const* buffer,
65 size_t starting_idx, 63 size_t starting_idx,
66 size_t num_frames, 64 size_t num_frames,
67 size_t num_channels) { 65 size_t num_channels) {
68 for (size_t i = 0; i < num_channels; ++i) { 66 for (size_t i = 0; i < num_channels; ++i) {
69 memset(&buffer[i][starting_idx], 0, 67 memset(&buffer[i][starting_idx], 0,
(...skipping 10 matching lines...) Expand all
80 for (size_t i = 0; i < num_channels; ++i) { 78 for (size_t i = 0; i < num_channels; ++i) {
81 for (size_t j = 0; j < num_frames; ++j) { 79 for (size_t j = 0; j < num_frames; ++j) {
82 frames[i][j] = frames[i][j] * window[j]; 80 frames[i][j] = frames[i][j] * window[j];
83 } 81 }
84 } 82 }
85 } 83 }
86 84
87 size_t gcd(size_t a, size_t b) { 85 size_t gcd(size_t a, size_t b) {
88 size_t tmp; 86 size_t tmp;
89 while (b) { 87 while (b) {
90 tmp = a; 88 tmp = a;
91 a = b; 89 a = b;
92 b = tmp % b; 90 b = tmp % b;
93 } 91 }
94 return a; 92 return a;
95 } 93 }
96 94
97 } // namespace 95 } // namespace
98 96
99 namespace webrtc { 97 namespace webrtc {
100 98
101 Blocker::Blocker(size_t chunk_size, 99 Blocker::Blocker(size_t chunk_size,
102 size_t block_size, 100 size_t block_size,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 173
176 input_buffer_.Write(input, num_input_channels, chunk_size_); 174 input_buffer_.Write(input, num_input_channels, chunk_size_);
177 size_t first_frame_in_block = frame_offset_; 175 size_t first_frame_in_block = frame_offset_;
178 176
179 // Loop through blocks. 177 // Loop through blocks.
180 while (first_frame_in_block < chunk_size_) { 178 while (first_frame_in_block < chunk_size_) {
181 input_buffer_.Read(input_block_.channels(), num_input_channels, 179 input_buffer_.Read(input_block_.channels(), num_input_channels,
182 block_size_); 180 block_size_);
183 input_buffer_.MoveReadPositionBackward(block_size_ - shift_amount_); 181 input_buffer_.MoveReadPositionBackward(block_size_ - shift_amount_);
184 182
185 ApplyWindow(window_.get(), 183 ApplyWindow(window_.get(), block_size_, num_input_channels_,
186 block_size_,
187 num_input_channels_,
188 input_block_.channels()); 184 input_block_.channels());
189 callback_->ProcessBlock(input_block_.channels(), 185 callback_->ProcessBlock(input_block_.channels(), block_size_,
190 block_size_, 186 num_input_channels_, num_output_channels_,
191 num_input_channels_,
192 num_output_channels_,
193 output_block_.channels()); 187 output_block_.channels());
194 ApplyWindow(window_.get(), 188 ApplyWindow(window_.get(), block_size_, num_output_channels_,
195 block_size_,
196 num_output_channels_,
197 output_block_.channels()); 189 output_block_.channels());
198 190
199 AddFrames(output_buffer_.channels(), 191 AddFrames(output_buffer_.channels(), first_frame_in_block,
200 first_frame_in_block, 192 output_block_.channels(), 0, block_size_, num_output_channels_,
201 output_block_.channels(), 193 output_buffer_.channels(), first_frame_in_block);
202 0,
203 block_size_,
204 num_output_channels_,
205 output_buffer_.channels(),
206 first_frame_in_block);
207 194
208 first_frame_in_block += shift_amount_; 195 first_frame_in_block += shift_amount_;
209 } 196 }
210 197
211 // Copy output buffer to output 198 // Copy output buffer to output
212 CopyFrames(output_buffer_.channels(), 199 CopyFrames(output_buffer_.channels(), 0, chunk_size_, num_output_channels_,
213 0, 200 output, 0);
214 chunk_size_,
215 num_output_channels_,
216 output,
217 0);
218 201
219 // Copy output buffer [chunk_size_, chunk_size_ + initial_delay] 202 // Copy output buffer [chunk_size_, chunk_size_ + initial_delay]
220 // to output buffer [0, initial_delay], zero the rest. 203 // to output buffer [0, initial_delay], zero the rest.
221 MoveFrames(output_buffer_.channels(), 204 MoveFrames(output_buffer_.channels(), chunk_size, initial_delay_,
222 chunk_size, 205 num_output_channels_, output_buffer_.channels(), 0);
223 initial_delay_, 206 ZeroOut(output_buffer_.channels(), initial_delay_, chunk_size_,
224 num_output_channels_,
225 output_buffer_.channels(),
226 0);
227 ZeroOut(output_buffer_.channels(),
228 initial_delay_,
229 chunk_size_,
230 num_output_channels_); 207 num_output_channels_);
231 208
232 // Calculate new starting frames. 209 // Calculate new starting frames.
233 frame_offset_ = first_frame_in_block - chunk_size_; 210 frame_offset_ = first_frame_in_block - chunk_size_;
234 } 211 }
235 212
236 } // namespace webrtc 213 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698