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

Side by Side Diff: webrtc/common_audio/blocker.cc

Issue 1316523002: Convert channel counts to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Fix compile Created 4 years, 11 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
« no previous file with comments | « webrtc/common_audio/blocker.h ('k') | webrtc/common_audio/blocker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common_audio/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,
22 const float* const* b, 22 const float* const* b,
23 int b_start_index, 23 int b_start_index,
24 size_t num_frames, 24 size_t num_frames,
25 int num_channels, 25 size_t num_channels,
26 float* const* result, 26 float* const* result,
27 size_t result_start_index) { 27 size_t result_start_index) {
28 for (int i = 0; i < num_channels; ++i) { 28 for (size_t i = 0; i < num_channels; ++i) {
29 for (size_t j = 0; j < num_frames; ++j) { 29 for (size_t j = 0; j < num_frames; ++j) {
30 result[i][j + result_start_index] = 30 result[i][j + result_start_index] =
31 a[i][j + a_start_index] + b[i][j + b_start_index]; 31 a[i][j + a_start_index] + b[i][j + b_start_index];
32 } 32 }
33 } 33 }
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 int 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 (int 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],
45 &src[i][src_start_index], 45 &src[i][src_start_index],
46 num_frames * sizeof(dst[i][dst_start_index])); 46 num_frames * sizeof(dst[i][dst_start_index]));
47 } 47 }
48 } 48 }
49 49
50 // Moves |src| into |dst| channel by channel. 50 // Moves |src| into |dst| channel by channel.
51 void MoveFrames(const float* const* src, 51 void MoveFrames(const float* const* src,
52 size_t src_start_index, 52 size_t src_start_index,
53 size_t num_frames, 53 size_t num_frames,
54 int num_channels, 54 size_t num_channels,
55 float* const* dst, 55 float* const* dst,
56 size_t dst_start_index) { 56 size_t dst_start_index) {
57 for (int i = 0; i < num_channels; ++i) { 57 for (size_t i = 0; i < num_channels; ++i) {
58 memmove(&dst[i][dst_start_index], 58 memmove(&dst[i][dst_start_index],
59 &src[i][src_start_index], 59 &src[i][src_start_index],
60 num_frames * sizeof(dst[i][dst_start_index])); 60 num_frames * sizeof(dst[i][dst_start_index]));
61 } 61 }
62 } 62 }
63 63
64 void ZeroOut(float* const* buffer, 64 void ZeroOut(float* const* buffer,
65 size_t starting_idx, 65 size_t starting_idx,
66 size_t num_frames, 66 size_t num_frames,
67 int num_channels) { 67 size_t num_channels) {
68 for (int i = 0; i < num_channels; ++i) { 68 for (size_t i = 0; i < num_channels; ++i) {
69 memset(&buffer[i][starting_idx], 0, 69 memset(&buffer[i][starting_idx], 0,
70 num_frames * sizeof(buffer[i][starting_idx])); 70 num_frames * sizeof(buffer[i][starting_idx]));
71 } 71 }
72 } 72 }
73 73
74 // Pointwise multiplies each channel of |frames| with |window|. Results are 74 // Pointwise multiplies each channel of |frames| with |window|. Results are
75 // stored in |frames|. 75 // stored in |frames|.
76 void ApplyWindow(const float* window, 76 void ApplyWindow(const float* window,
77 size_t num_frames, 77 size_t num_frames,
78 int num_channels, 78 size_t num_channels,
79 float* const* frames) { 79 float* const* frames) {
80 for (int i = 0; i < num_channels; ++i) { 80 for (size_t i = 0; i < num_channels; ++i) {
81 for (size_t j = 0; j < num_frames; ++j) { 81 for (size_t j = 0; j < num_frames; ++j) {
82 frames[i][j] = frames[i][j] * window[j]; 82 frames[i][j] = frames[i][j] * window[j];
83 } 83 }
84 } 84 }
85 } 85 }
86 86
87 size_t gcd(size_t a, size_t b) { 87 size_t gcd(size_t a, size_t b) {
88 size_t tmp; 88 size_t tmp;
89 while (b) { 89 while (b) {
90 tmp = a; 90 tmp = a;
91 a = b; 91 a = b;
92 b = tmp % b; 92 b = tmp % b;
93 } 93 }
94 return a; 94 return a;
95 } 95 }
96 96
97 } // namespace 97 } // namespace
98 98
99 namespace webrtc { 99 namespace webrtc {
100 100
101 Blocker::Blocker(size_t chunk_size, 101 Blocker::Blocker(size_t chunk_size,
102 size_t block_size, 102 size_t block_size,
103 int num_input_channels, 103 size_t num_input_channels,
104 int num_output_channels, 104 size_t num_output_channels,
105 const float* window, 105 const float* window,
106 size_t shift_amount, 106 size_t shift_amount,
107 BlockerCallback* callback) 107 BlockerCallback* callback)
108 : chunk_size_(chunk_size), 108 : chunk_size_(chunk_size),
109 block_size_(block_size), 109 block_size_(block_size),
110 num_input_channels_(num_input_channels), 110 num_input_channels_(num_input_channels),
111 num_output_channels_(num_output_channels), 111 num_output_channels_(num_output_channels),
112 initial_delay_(block_size_ - gcd(chunk_size, shift_amount)), 112 initial_delay_(block_size_ - gcd(chunk_size, shift_amount)),
113 frame_offset_(0), 113 frame_offset_(0),
114 input_buffer_(num_input_channels_, chunk_size_ + initial_delay_), 114 input_buffer_(num_input_channels_, chunk_size_ + initial_delay_),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // 6. For both the input and the output buffers, we copy sections _b_ and _c_ 159 // 6. For both the input and the output buffers, we copy sections _b_ and _c_
160 // into section _a_ and _b_. 160 // into section _a_ and _b_.
161 // 7. We set the new frame_offset to be the difference between the first frame 161 // 7. We set the new frame_offset to be the difference between the first frame
162 // of |bl| and the border between sections _a_ and _b_. 162 // of |bl| and the border between sections _a_ and _b_.
163 // 163 //
164 // * delay here refers to inintial_delay_ 164 // * delay here refers to inintial_delay_
165 // 165 //
166 // TODO(claguna): Look at using ring buffers to eliminate some copies. 166 // TODO(claguna): Look at using ring buffers to eliminate some copies.
167 void Blocker::ProcessChunk(const float* const* input, 167 void Blocker::ProcessChunk(const float* const* input,
168 size_t chunk_size, 168 size_t chunk_size,
169 int num_input_channels, 169 size_t num_input_channels,
170 int num_output_channels, 170 size_t num_output_channels,
171 float* const* output) { 171 float* const* output) {
172 RTC_CHECK_EQ(chunk_size, chunk_size_); 172 RTC_CHECK_EQ(chunk_size, chunk_size_);
173 RTC_CHECK_EQ(num_input_channels, num_input_channels_); 173 RTC_CHECK_EQ(num_input_channels, num_input_channels_);
174 RTC_CHECK_EQ(num_output_channels, num_output_channels_); 174 RTC_CHECK_EQ(num_output_channels, num_output_channels_);
175 175
176 input_buffer_.Write(input, num_input_channels, chunk_size_); 176 input_buffer_.Write(input, num_input_channels, chunk_size_);
177 size_t first_frame_in_block = frame_offset_; 177 size_t first_frame_in_block = frame_offset_;
178 178
179 // Loop through blocks. 179 // Loop through blocks.
180 while (first_frame_in_block < chunk_size_) { 180 while (first_frame_in_block < chunk_size_) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 ZeroOut(output_buffer_.channels(), 227 ZeroOut(output_buffer_.channels(),
228 initial_delay_, 228 initial_delay_,
229 chunk_size_, 229 chunk_size_,
230 num_output_channels_); 230 num_output_channels_);
231 231
232 // Calculate new starting frames. 232 // Calculate new starting frames.
233 frame_offset_ = first_frame_in_block - chunk_size_; 233 frame_offset_ = first_frame_in_block - chunk_size_;
234 } 234 }
235 235
236 } // namespace webrtc 236 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_audio/blocker.h ('k') | webrtc/common_audio/blocker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698