blob: 9160f694a278014d19c509a700cfa68ce2500287 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.org63a50982012-05-02 23:56:37 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000011#include "webrtc/modules/audio_processing/audio_buffer.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
andrew@webrtc.org17e40642014-03-04 20:58:13 +000013#include "webrtc/common_audio/include/audio_util.h"
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000014#include "webrtc/common_audio/resampler/push_sinc_resampler.h"
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000015#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000016
niklase@google.com470e71d2011-07-07 08:21:25 +000017namespace webrtc {
18namespace {
19
20enum {
21 kSamplesPer8kHzChannel = 80,
22 kSamplesPer16kHzChannel = 160,
23 kSamplesPer32kHzChannel = 320
24};
25
andrew@webrtc.org103657b2014-04-24 18:28:56 +000026bool HasKeyboardChannel(AudioProcessing::ChannelLayout layout) {
27 switch (layout) {
28 case AudioProcessing::kMono:
29 case AudioProcessing::kStereo:
30 return false;
31 case AudioProcessing::kMonoAndKeyboard:
32 case AudioProcessing::kStereoAndKeyboard:
33 return true;
34 }
35 assert(false);
36 return false;
37}
38
39int KeyboardChannelIndex(AudioProcessing::ChannelLayout layout) {
40 switch (layout) {
41 case AudioProcessing::kMono:
42 case AudioProcessing::kStereo:
43 assert(false);
44 return -1;
45 case AudioProcessing::kMonoAndKeyboard:
46 return 1;
47 case AudioProcessing::kStereoAndKeyboard:
48 return 2;
49 }
50 assert(false);
51 return -1;
52}
53
54
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000055void StereoToMono(const float* left, const float* right, float* out,
56 int samples_per_channel) {
57 for (int i = 0; i < samples_per_channel; ++i) {
58 out[i] = (left[i] + right[i]) / 2;
59 }
niklase@google.com470e71d2011-07-07 08:21:25 +000060}
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000061
62void StereoToMono(const int16_t* left, const int16_t* right, int16_t* out,
63 int samples_per_channel) {
andrew@webrtc.org103657b2014-04-24 18:28:56 +000064 for (int i = 0; i < samples_per_channel; ++i) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000065 out[i] = (left[i] + right[i]) >> 1;
andrew@webrtc.org103657b2014-04-24 18:28:56 +000066 }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000067}
68
niklase@google.com470e71d2011-07-07 08:21:25 +000069} // namespace
70
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000071class SplitChannelBuffer {
72 public:
73 SplitChannelBuffer(int samples_per_split_channel, int num_channels)
74 : low_(samples_per_split_channel, num_channels),
75 high_(samples_per_split_channel, num_channels) {
niklase@google.com470e71d2011-07-07 08:21:25 +000076 }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000077 ~SplitChannelBuffer() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000078
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000079 int16_t* low_channel(int i) { return low_.channel(i); }
80 int16_t* high_channel(int i) { return high_.channel(i); }
81
82 private:
83 ChannelBuffer<int16_t> low_;
84 ChannelBuffer<int16_t> high_;
niklase@google.com470e71d2011-07-07 08:21:25 +000085};
86
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000087AudioBuffer::AudioBuffer(int input_samples_per_channel,
88 int num_input_channels,
89 int process_samples_per_channel,
90 int num_process_channels,
91 int output_samples_per_channel)
92 : input_samples_per_channel_(input_samples_per_channel),
93 num_input_channels_(num_input_channels),
94 proc_samples_per_channel_(process_samples_per_channel),
95 num_proc_channels_(num_process_channels),
96 output_samples_per_channel_(output_samples_per_channel),
97 samples_per_split_channel_(proc_samples_per_channel_),
andrew@webrtc.orged083d42011-09-19 15:28:51 +000098 num_mixed_channels_(0),
99 num_mixed_low_pass_channels_(0),
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000100 data_was_mixed_(false),
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000101 reference_copied_(false),
102 activity_(AudioFrame::kVadUnknown),
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000103 is_muted_(false),
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000104 data_(NULL),
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000105 keyboard_data_(NULL),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000106 channels_(new ChannelBuffer<int16_t>(proc_samples_per_channel_,
107 num_proc_channels_)) {
108 assert(input_samples_per_channel_ > 0);
109 assert(proc_samples_per_channel_ > 0);
110 assert(output_samples_per_channel_ > 0);
111 assert(num_input_channels_ > 0 && num_input_channels_ <= 2);
112 assert(num_proc_channels_ <= num_input_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000114 if (num_input_channels_ == 2 && num_proc_channels_ == 1) {
115 input_buffer_.reset(new ChannelBuffer<float>(input_samples_per_channel_,
116 num_proc_channels_));
117 }
118
119 if (input_samples_per_channel_ != proc_samples_per_channel_ ||
120 output_samples_per_channel_ != proc_samples_per_channel_) {
121 // Create an intermediate buffer for resampling.
122 process_buffer_.reset(new ChannelBuffer<float>(proc_samples_per_channel_,
123 num_proc_channels_));
124 }
125
126 if (input_samples_per_channel_ != proc_samples_per_channel_) {
127 input_resamplers_.reserve(num_proc_channels_);
128 for (int i = 0; i < num_proc_channels_; ++i) {
129 input_resamplers_.push_back(
130 new PushSincResampler(input_samples_per_channel_,
131 proc_samples_per_channel_));
132 }
133 }
134
135 if (output_samples_per_channel_ != proc_samples_per_channel_) {
136 output_resamplers_.reserve(num_proc_channels_);
137 for (int i = 0; i < num_proc_channels_; ++i) {
138 output_resamplers_.push_back(
139 new PushSincResampler(proc_samples_per_channel_,
140 output_samples_per_channel_));
141 }
142 }
143
144 if (proc_samples_per_channel_ == kSamplesPer32kHzChannel) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000145 samples_per_split_channel_ = kSamplesPer16kHzChannel;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000146 split_channels_.reset(new SplitChannelBuffer(samples_per_split_channel_,
147 num_proc_channels_));
148 filter_states_.reset(new SplitFilterStates[num_proc_channels_]);
149 }
150}
151
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000152AudioBuffer::~AudioBuffer() {}
153
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000154void AudioBuffer::CopyFrom(const float* const* data,
155 int samples_per_channel,
156 AudioProcessing::ChannelLayout layout) {
157 assert(samples_per_channel == input_samples_per_channel_);
158 assert(ChannelsFromLayout(layout) == num_input_channels_);
159 InitForNewData();
160
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000161 if (HasKeyboardChannel(layout)) {
162 keyboard_data_ = data[KeyboardChannelIndex(layout)];
163 }
164
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000165 // Downmix.
166 const float* const* data_ptr = data;
167 if (num_input_channels_ == 2 && num_proc_channels_ == 1) {
168 StereoToMono(data[0],
169 data[1],
170 input_buffer_->channel(0),
171 input_samples_per_channel_);
172 data_ptr = input_buffer_->channels();
173 }
174
175 // Resample.
176 if (input_samples_per_channel_ != proc_samples_per_channel_) {
177 for (int i = 0; i < num_proc_channels_; ++i) {
178 input_resamplers_[i]->Resample(data_ptr[i],
179 input_samples_per_channel_,
180 process_buffer_->channel(i),
181 proc_samples_per_channel_);
182 }
183 data_ptr = process_buffer_->channels();
184 }
185
186 // Convert to int16.
187 for (int i = 0; i < num_proc_channels_; ++i) {
188 ScaleAndRoundToInt16(data_ptr[i], proc_samples_per_channel_,
189 channels_->channel(i));
190 }
191}
192
193void AudioBuffer::CopyTo(int samples_per_channel,
194 AudioProcessing::ChannelLayout layout,
195 float* const* data) {
196 assert(samples_per_channel == output_samples_per_channel_);
197 assert(ChannelsFromLayout(layout) == num_proc_channels_);
198
199 // Convert to float.
200 float* const* data_ptr = data;
201 if (output_samples_per_channel_ != proc_samples_per_channel_) {
202 // Convert to an intermediate buffer for subsequent resampling.
203 data_ptr = process_buffer_->channels();
204 }
205 for (int i = 0; i < num_proc_channels_; ++i) {
206 ScaleToFloat(channels_->channel(i), proc_samples_per_channel_, data_ptr[i]);
207 }
208
209 // Resample.
210 if (output_samples_per_channel_ != proc_samples_per_channel_) {
211 for (int i = 0; i < num_proc_channels_; ++i) {
212 output_resamplers_[i]->Resample(data_ptr[i],
213 proc_samples_per_channel_,
214 data[i],
215 output_samples_per_channel_);
216 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000217 }
218}
219
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000220void AudioBuffer::InitForNewData() {
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000221 data_ = NULL;
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000222 keyboard_data_ = NULL;
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000223 data_was_mixed_ = false;
224 num_mixed_channels_ = 0;
225 num_mixed_low_pass_channels_ = 0;
226 reference_copied_ = false;
227 activity_ = AudioFrame::kVadUnknown;
228 is_muted_ = false;
229}
230
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000231const int16_t* AudioBuffer::data(int channel) const {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000232 assert(channel >= 0 && channel < num_proc_channels_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000233 if (data_ != NULL) {
234 return data_;
235 }
236
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000237 return channels_->channel(channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000238}
239
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000240int16_t* AudioBuffer::data(int channel) {
241 const AudioBuffer* t = this;
242 return const_cast<int16_t*>(t->data(channel));
243}
244
245const int16_t* AudioBuffer::low_pass_split_data(int channel) const {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000246 assert(channel >= 0 && channel < num_proc_channels_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000247 if (split_channels_.get() == NULL) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000248 return data(channel);
249 }
250
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000251 return split_channels_->low_channel(channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000252}
253
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000254int16_t* AudioBuffer::low_pass_split_data(int channel) {
255 const AudioBuffer* t = this;
256 return const_cast<int16_t*>(t->low_pass_split_data(channel));
257}
258
259const int16_t* AudioBuffer::high_pass_split_data(int channel) const {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000260 assert(channel >= 0 && channel < num_proc_channels_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000261 if (split_channels_.get() == NULL) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000262 return NULL;
263 }
264
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000265 return split_channels_->high_channel(channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000266}
267
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000268int16_t* AudioBuffer::high_pass_split_data(int channel) {
269 const AudioBuffer* t = this;
270 return const_cast<int16_t*>(t->high_pass_split_data(channel));
271}
272
273const int16_t* AudioBuffer::mixed_data(int channel) const {
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000274 assert(channel >= 0 && channel < num_mixed_channels_);
275
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000276 return mixed_channels_->channel(channel);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000277}
278
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000279const int16_t* AudioBuffer::mixed_low_pass_data(int channel) const {
niklase@google.com470e71d2011-07-07 08:21:25 +0000280 assert(channel >= 0 && channel < num_mixed_low_pass_channels_);
281
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000282 return mixed_low_pass_channels_->channel(channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000283}
284
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000285const int16_t* AudioBuffer::low_pass_reference(int channel) const {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000286 assert(channel >= 0 && channel < num_proc_channels_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000287 if (!reference_copied_) {
288 return NULL;
289 }
290
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000291 return low_pass_reference_channels_->channel(channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000292}
293
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000294const float* AudioBuffer::keyboard_data() const {
295 return keyboard_data_;
296}
297
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000298SplitFilterStates* AudioBuffer::filter_states(int channel) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000299 assert(channel >= 0 && channel < num_proc_channels_);
300 return &filter_states_[channel];
niklase@google.com470e71d2011-07-07 08:21:25 +0000301}
302
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000303void AudioBuffer::set_activity(AudioFrame::VADActivity activity) {
304 activity_ = activity;
305}
306
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000307AudioFrame::VADActivity AudioBuffer::activity() const {
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000308 return activity_;
309}
310
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000311bool AudioBuffer::is_muted() const {
312 return is_muted_;
313}
314
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000315int AudioBuffer::num_channels() const {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000316 return num_proc_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000317}
318
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000319int AudioBuffer::samples_per_channel() const {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000320 return proc_samples_per_channel_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000321}
322
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000323int AudioBuffer::samples_per_split_channel() const {
niklase@google.com470e71d2011-07-07 08:21:25 +0000324 return samples_per_split_channel_;
325}
326
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000327int AudioBuffer::samples_per_keyboard_channel() const {
328 // We don't resample the keyboard channel.
329 return input_samples_per_channel_;
330}
331
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000332// TODO(andrew): Do deinterleaving and mixing in one step?
333void AudioBuffer::DeinterleaveFrom(AudioFrame* frame) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000334 assert(proc_samples_per_channel_ == input_samples_per_channel_);
335 assert(num_proc_channels_ == num_input_channels_);
336 assert(frame->num_channels_ == num_proc_channels_);
337 assert(frame->samples_per_channel_ == proc_samples_per_channel_);
338 InitForNewData();
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000339 activity_ = frame->vad_activity_;
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000340 if (frame->energy_ == 0) {
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000341 is_muted_ = true;
342 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000343
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000344 if (num_proc_channels_ == 1) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000345 // We can get away with a pointer assignment in this case.
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000346 data_ = frame->data_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000347 return;
348 }
349
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000350 int16_t* interleaved = frame->data_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000351 for (int i = 0; i < num_proc_channels_; i++) {
352 int16_t* deinterleaved = channels_->channel(i);
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000353 int interleaved_idx = i;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000354 for (int j = 0; j < proc_samples_per_channel_; j++) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000355 deinterleaved[j] = interleaved[interleaved_idx];
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000356 interleaved_idx += num_proc_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000357 }
358 }
359}
360
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000361void AudioBuffer::InterleaveTo(AudioFrame* frame, bool data_changed) const {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000362 assert(proc_samples_per_channel_ == output_samples_per_channel_);
363 assert(num_proc_channels_ == num_input_channels_);
364 assert(frame->num_channels_ == num_proc_channels_);
365 assert(frame->samples_per_channel_ == proc_samples_per_channel_);
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000366 frame->vad_activity_ = activity_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000367
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000368 if (!data_changed) {
369 return;
370 }
371
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000372 if (num_proc_channels_ == 1) {
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000373 if (data_was_mixed_) {
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000374 memcpy(frame->data_,
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000375 channels_->channel(0),
376 sizeof(int16_t) * proc_samples_per_channel_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000377 } else {
378 // These should point to the same buffer in this case.
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000379 assert(data_ == frame->data_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000380 }
381
382 return;
383 }
384
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000385 int16_t* interleaved = frame->data_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000386 for (int i = 0; i < num_proc_channels_; i++) {
387 int16_t* deinterleaved = channels_->channel(i);
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000388 int interleaved_idx = i;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000389 for (int j = 0; j < proc_samples_per_channel_; j++) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000390 interleaved[interleaved_idx] = deinterleaved[j];
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000391 interleaved_idx += num_proc_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000392 }
393 }
394}
395
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000396void AudioBuffer::CopyAndMix(int num_mixed_channels) {
397 // We currently only support the stereo to mono case.
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000398 assert(num_proc_channels_ == 2);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000399 assert(num_mixed_channels == 1);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000400 if (!mixed_channels_.get()) {
401 mixed_channels_.reset(
402 new ChannelBuffer<int16_t>(proc_samples_per_channel_,
403 num_mixed_channels));
404 }
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000405
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000406 StereoToMono(channels_->channel(0),
407 channels_->channel(1),
408 mixed_channels_->channel(0),
409 proc_samples_per_channel_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000410
niklase@google.com470e71d2011-07-07 08:21:25 +0000411 num_mixed_channels_ = num_mixed_channels;
412}
413
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000414void AudioBuffer::CopyAndMixLowPass(int num_mixed_channels) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000415 // We currently only support the stereo to mono case.
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000416 assert(num_proc_channels_ == 2);
niklase@google.com470e71d2011-07-07 08:21:25 +0000417 assert(num_mixed_channels == 1);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000418 if (!mixed_low_pass_channels_.get()) {
419 mixed_low_pass_channels_.reset(
420 new ChannelBuffer<int16_t>(samples_per_split_channel_,
421 num_mixed_channels));
422 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000423
424 StereoToMono(low_pass_split_data(0),
425 low_pass_split_data(1),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000426 mixed_low_pass_channels_->channel(0),
niklase@google.com470e71d2011-07-07 08:21:25 +0000427 samples_per_split_channel_);
428
429 num_mixed_low_pass_channels_ = num_mixed_channels;
430}
431
432void AudioBuffer::CopyLowPassToReference() {
433 reference_copied_ = true;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000434 if (!low_pass_reference_channels_.get()) {
435 low_pass_reference_channels_.reset(
436 new ChannelBuffer<int16_t>(samples_per_split_channel_,
437 num_proc_channels_));
438 }
439 for (int i = 0; i < num_proc_channels_; i++) {
440 low_pass_reference_channels_->CopyFrom(low_pass_split_data(i), i);
niklase@google.com470e71d2011-07-07 08:21:25 +0000441 }
442}
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000443
niklase@google.com470e71d2011-07-07 08:21:25 +0000444} // namespace webrtc