blob: 7eac7ecfe44f390905c50ac56b00fda58d7e23fe [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
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000054void StereoToMono(const float* left, const float* right, float* out,
55 int samples_per_channel) {
56 for (int i = 0; i < samples_per_channel; ++i) {
57 out[i] = (left[i] + right[i]) / 2;
58 }
niklase@google.com470e71d2011-07-07 08:21:25 +000059}
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000060
61void StereoToMono(const int16_t* left, const int16_t* right, int16_t* out,
62 int samples_per_channel) {
andrew@webrtc.org103657b2014-04-24 18:28:56 +000063 for (int i = 0; i < samples_per_channel; ++i) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000064 out[i] = (left[i] + right[i]) >> 1;
andrew@webrtc.org103657b2014-04-24 18:28:56 +000065 }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000066}
67
niklase@google.com470e71d2011-07-07 08:21:25 +000068} // namespace
69
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +000070// One int16_t and one float ChannelBuffer that are kept in sync. The sync is
71// broken when someone requests write access to either ChannelBuffer, and
72// reestablished when someone requests the outdated ChannelBuffer. It is
73// therefore safe to use the return value of ibuf() and fbuf() until the next
74// call to the other method.
75class IFChannelBuffer {
76 public:
77 IFChannelBuffer(int samples_per_channel, int num_channels)
78 : ivalid_(true),
79 ibuf_(samples_per_channel, num_channels),
80 fvalid_(true),
81 fbuf_(samples_per_channel, num_channels) {}
82
83 ChannelBuffer<int16_t>* ibuf() {
84 RefreshI();
85 fvalid_ = false;
86 return &ibuf_;
87 }
88
89 ChannelBuffer<float>* fbuf() {
90 RefreshF();
91 ivalid_ = false;
92 return &fbuf_;
93 }
94
95 private:
96 void RefreshF() {
97 if (!fvalid_) {
98 assert(ivalid_);
99 const int16_t* const int_data = ibuf_.data();
100 float* const float_data = fbuf_.data();
101 const int length = fbuf_.length();
102 for (int i = 0; i < length; ++i)
103 float_data[i] = int_data[i];
104 fvalid_ = true;
105 }
106 }
107
108 void RefreshI() {
109 if (!ivalid_) {
110 assert(fvalid_);
111 const float* const float_data = fbuf_.data();
112 int16_t* const int_data = ibuf_.data();
113 const int length = ibuf_.length();
114 for (int i = 0; i < length; ++i)
115 int_data[i] = WEBRTC_SPL_SAT(std::numeric_limits<int16_t>::max(),
116 float_data[i],
117 std::numeric_limits<int16_t>::min());
118 ivalid_ = true;
119 }
120 }
121
122 bool ivalid_;
123 ChannelBuffer<int16_t> ibuf_;
124 bool fvalid_;
125 ChannelBuffer<float> fbuf_;
126};
127
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000128class SplitChannelBuffer {
129 public:
130 SplitChannelBuffer(int samples_per_split_channel, int num_channels)
131 : low_(samples_per_split_channel, num_channels),
132 high_(samples_per_split_channel, num_channels) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000133 }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000134 ~SplitChannelBuffer() {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000136 int16_t* low_channel(int i) { return low_.ibuf()->channel(i); }
137 int16_t* high_channel(int i) { return high_.ibuf()->channel(i); }
138 float* low_channel_f(int i) { return low_.fbuf()->channel(i); }
139 float* high_channel_f(int i) { return high_.fbuf()->channel(i); }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000140
141 private:
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000142 IFChannelBuffer low_;
143 IFChannelBuffer high_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000144};
145
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000146AudioBuffer::AudioBuffer(int input_samples_per_channel,
147 int num_input_channels,
148 int process_samples_per_channel,
149 int num_process_channels,
150 int output_samples_per_channel)
151 : input_samples_per_channel_(input_samples_per_channel),
152 num_input_channels_(num_input_channels),
153 proc_samples_per_channel_(process_samples_per_channel),
154 num_proc_channels_(num_process_channels),
155 output_samples_per_channel_(output_samples_per_channel),
156 samples_per_split_channel_(proc_samples_per_channel_),
aluebs@webrtc.org2561d522014-07-17 08:27:39 +0000157 mixed_low_pass_valid_(false),
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000158 reference_copied_(false),
159 activity_(AudioFrame::kVadUnknown),
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000160 keyboard_data_(NULL),
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000161 channels_(new IFChannelBuffer(proc_samples_per_channel_,
162 num_proc_channels_)) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000163 assert(input_samples_per_channel_ > 0);
164 assert(proc_samples_per_channel_ > 0);
165 assert(output_samples_per_channel_ > 0);
166 assert(num_input_channels_ > 0 && num_input_channels_ <= 2);
167 assert(num_proc_channels_ <= num_input_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000169 if (num_input_channels_ == 2 && num_proc_channels_ == 1) {
170 input_buffer_.reset(new ChannelBuffer<float>(input_samples_per_channel_,
171 num_proc_channels_));
172 }
173
174 if (input_samples_per_channel_ != proc_samples_per_channel_ ||
175 output_samples_per_channel_ != proc_samples_per_channel_) {
176 // Create an intermediate buffer for resampling.
177 process_buffer_.reset(new ChannelBuffer<float>(proc_samples_per_channel_,
178 num_proc_channels_));
179 }
180
181 if (input_samples_per_channel_ != proc_samples_per_channel_) {
182 input_resamplers_.reserve(num_proc_channels_);
183 for (int i = 0; i < num_proc_channels_; ++i) {
184 input_resamplers_.push_back(
185 new PushSincResampler(input_samples_per_channel_,
186 proc_samples_per_channel_));
187 }
188 }
189
190 if (output_samples_per_channel_ != proc_samples_per_channel_) {
191 output_resamplers_.reserve(num_proc_channels_);
192 for (int i = 0; i < num_proc_channels_; ++i) {
193 output_resamplers_.push_back(
194 new PushSincResampler(proc_samples_per_channel_,
195 output_samples_per_channel_));
196 }
197 }
198
199 if (proc_samples_per_channel_ == kSamplesPer32kHzChannel) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000200 samples_per_split_channel_ = kSamplesPer16kHzChannel;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000201 split_channels_.reset(new SplitChannelBuffer(samples_per_split_channel_,
202 num_proc_channels_));
203 filter_states_.reset(new SplitFilterStates[num_proc_channels_]);
204 }
205}
206
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000207AudioBuffer::~AudioBuffer() {}
208
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000209void AudioBuffer::CopyFrom(const float* const* data,
210 int samples_per_channel,
211 AudioProcessing::ChannelLayout layout) {
212 assert(samples_per_channel == input_samples_per_channel_);
213 assert(ChannelsFromLayout(layout) == num_input_channels_);
214 InitForNewData();
215
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000216 if (HasKeyboardChannel(layout)) {
217 keyboard_data_ = data[KeyboardChannelIndex(layout)];
218 }
219
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000220 // Downmix.
221 const float* const* data_ptr = data;
222 if (num_input_channels_ == 2 && num_proc_channels_ == 1) {
223 StereoToMono(data[0],
224 data[1],
225 input_buffer_->channel(0),
226 input_samples_per_channel_);
227 data_ptr = input_buffer_->channels();
228 }
229
230 // Resample.
231 if (input_samples_per_channel_ != proc_samples_per_channel_) {
232 for (int i = 0; i < num_proc_channels_; ++i) {
233 input_resamplers_[i]->Resample(data_ptr[i],
234 input_samples_per_channel_,
235 process_buffer_->channel(i),
236 proc_samples_per_channel_);
237 }
238 data_ptr = process_buffer_->channels();
239 }
240
241 // Convert to int16.
242 for (int i = 0; i < num_proc_channels_; ++i) {
243 ScaleAndRoundToInt16(data_ptr[i], proc_samples_per_channel_,
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000244 channels_->ibuf()->channel(i));
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000245 }
246}
247
248void AudioBuffer::CopyTo(int samples_per_channel,
249 AudioProcessing::ChannelLayout layout,
250 float* const* data) {
251 assert(samples_per_channel == output_samples_per_channel_);
252 assert(ChannelsFromLayout(layout) == num_proc_channels_);
253
254 // Convert to float.
255 float* const* data_ptr = data;
256 if (output_samples_per_channel_ != proc_samples_per_channel_) {
257 // Convert to an intermediate buffer for subsequent resampling.
258 data_ptr = process_buffer_->channels();
259 }
260 for (int i = 0; i < num_proc_channels_; ++i) {
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000261 ScaleToFloat(channels_->ibuf()->channel(i),
262 proc_samples_per_channel_,
263 data_ptr[i]);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000264 }
265
266 // Resample.
267 if (output_samples_per_channel_ != proc_samples_per_channel_) {
268 for (int i = 0; i < num_proc_channels_; ++i) {
269 output_resamplers_[i]->Resample(data_ptr[i],
270 proc_samples_per_channel_,
271 data[i],
272 output_samples_per_channel_);
273 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000274 }
275}
276
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000277void AudioBuffer::InitForNewData() {
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000278 keyboard_data_ = NULL;
aluebs@webrtc.org2561d522014-07-17 08:27:39 +0000279 mixed_low_pass_valid_ = false;
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000280 reference_copied_ = false;
281 activity_ = AudioFrame::kVadUnknown;
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000282}
283
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000284const int16_t* AudioBuffer::data(int channel) const {
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000285 return channels_->ibuf()->channel(channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000286}
287
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000288int16_t* AudioBuffer::data(int channel) {
aluebs@webrtc.org2561d522014-07-17 08:27:39 +0000289 mixed_low_pass_valid_ = false;
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000290 const AudioBuffer* t = this;
291 return const_cast<int16_t*>(t->data(channel));
292}
293
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +0000294const float* AudioBuffer::data_f(int channel) const {
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000295 return channels_->fbuf()->channel(channel);
296}
297
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +0000298float* AudioBuffer::data_f(int channel) {
aluebs@webrtc.org2561d522014-07-17 08:27:39 +0000299 mixed_low_pass_valid_ = false;
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +0000300 const AudioBuffer* t = this;
301 return const_cast<float*>(t->data_f(channel));
302}
303
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000304const int16_t* AudioBuffer::low_pass_split_data(int channel) const {
kwiberg@webrtc.org8e4401b2014-06-03 10:04:13 +0000305 return split_channels_.get() ? split_channels_->low_channel(channel)
306 : data(channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000307}
308
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000309int16_t* AudioBuffer::low_pass_split_data(int channel) {
aluebs@webrtc.org2561d522014-07-17 08:27:39 +0000310 mixed_low_pass_valid_ = false;
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000311 const AudioBuffer* t = this;
312 return const_cast<int16_t*>(t->low_pass_split_data(channel));
313}
314
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +0000315const float* AudioBuffer::low_pass_split_data_f(int channel) const {
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000316 return split_channels_.get() ? split_channels_->low_channel_f(channel)
317 : data_f(channel);
318}
319
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +0000320float* AudioBuffer::low_pass_split_data_f(int channel) {
aluebs@webrtc.org2561d522014-07-17 08:27:39 +0000321 mixed_low_pass_valid_ = false;
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +0000322 const AudioBuffer* t = this;
323 return const_cast<float*>(t->low_pass_split_data_f(channel));
324}
325
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000326const int16_t* AudioBuffer::high_pass_split_data(int channel) const {
kwiberg@webrtc.org8e4401b2014-06-03 10:04:13 +0000327 return split_channels_.get() ? split_channels_->high_channel(channel) : NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000328}
329
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000330int16_t* AudioBuffer::high_pass_split_data(int channel) {
331 const AudioBuffer* t = this;
332 return const_cast<int16_t*>(t->high_pass_split_data(channel));
333}
334
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +0000335const float* AudioBuffer::high_pass_split_data_f(int channel) const {
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000336 return split_channels_.get() ? split_channels_->high_channel_f(channel)
337 : NULL;
338}
339
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +0000340float* AudioBuffer::high_pass_split_data_f(int channel) {
341 const AudioBuffer* t = this;
342 return const_cast<float*>(t->high_pass_split_data_f(channel));
343}
344
aluebs@webrtc.org2561d522014-07-17 08:27:39 +0000345const int16_t* AudioBuffer::mixed_low_pass_data() {
346 // Currently only mixing stereo to mono is supported.
347 assert(num_proc_channels_ == 1 || num_proc_channels_ == 2);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000348
aluebs@webrtc.org2561d522014-07-17 08:27:39 +0000349 if (num_proc_channels_ == 1) {
350 return low_pass_split_data(0);
351 }
352
353 if (!mixed_low_pass_valid_) {
354 if (!mixed_low_pass_channels_.get()) {
355 mixed_low_pass_channels_.reset(
356 new ChannelBuffer<int16_t>(samples_per_split_channel_, 1));
357 }
358 StereoToMono(low_pass_split_data(0),
359 low_pass_split_data(1),
360 mixed_low_pass_channels_->data(),
361 samples_per_split_channel_);
362 mixed_low_pass_valid_ = true;
363 }
364 return mixed_low_pass_channels_->data();
niklase@google.com470e71d2011-07-07 08:21:25 +0000365}
366
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000367const int16_t* AudioBuffer::low_pass_reference(int channel) const {
niklase@google.com470e71d2011-07-07 08:21:25 +0000368 if (!reference_copied_) {
369 return NULL;
370 }
371
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000372 return low_pass_reference_channels_->channel(channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000373}
374
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000375const float* AudioBuffer::keyboard_data() const {
376 return keyboard_data_;
377}
378
andrew@webrtc.org65f93382014-04-30 16:44:13 +0000379SplitFilterStates* AudioBuffer::filter_states(int channel) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000380 assert(channel >= 0 && channel < num_proc_channels_);
381 return &filter_states_[channel];
niklase@google.com470e71d2011-07-07 08:21:25 +0000382}
383
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000384void AudioBuffer::set_activity(AudioFrame::VADActivity activity) {
385 activity_ = activity;
386}
387
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000388AudioFrame::VADActivity AudioBuffer::activity() const {
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000389 return activity_;
390}
391
392int AudioBuffer::num_channels() const {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000393 return num_proc_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000394}
395
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000396int AudioBuffer::samples_per_channel() const {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000397 return proc_samples_per_channel_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000398}
399
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000400int AudioBuffer::samples_per_split_channel() const {
niklase@google.com470e71d2011-07-07 08:21:25 +0000401 return samples_per_split_channel_;
402}
403
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000404int AudioBuffer::samples_per_keyboard_channel() const {
405 // We don't resample the keyboard channel.
406 return input_samples_per_channel_;
407}
408
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000409// TODO(andrew): Do deinterleaving and mixing in one step?
410void AudioBuffer::DeinterleaveFrom(AudioFrame* frame) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000411 assert(proc_samples_per_channel_ == input_samples_per_channel_);
412 assert(num_proc_channels_ == num_input_channels_);
413 assert(frame->num_channels_ == num_proc_channels_);
414 assert(frame->samples_per_channel_ == proc_samples_per_channel_);
415 InitForNewData();
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000416 activity_ = frame->vad_activity_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000417
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000418 int16_t* interleaved = frame->data_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000419 for (int i = 0; i < num_proc_channels_; i++) {
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000420 int16_t* deinterleaved = channels_->ibuf()->channel(i);
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000421 int interleaved_idx = i;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000422 for (int j = 0; j < proc_samples_per_channel_; j++) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000423 deinterleaved[j] = interleaved[interleaved_idx];
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000424 interleaved_idx += num_proc_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000425 }
426 }
427}
428
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000429void AudioBuffer::InterleaveTo(AudioFrame* frame, bool data_changed) const {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000430 assert(proc_samples_per_channel_ == output_samples_per_channel_);
431 assert(num_proc_channels_ == num_input_channels_);
432 assert(frame->num_channels_ == num_proc_channels_);
433 assert(frame->samples_per_channel_ == proc_samples_per_channel_);
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000434 frame->vad_activity_ = activity_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000435
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000436 if (!data_changed) {
437 return;
438 }
439
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000440 int16_t* interleaved = frame->data_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000441 for (int i = 0; i < num_proc_channels_; i++) {
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000442 int16_t* deinterleaved = channels_->ibuf()->channel(i);
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000443 int interleaved_idx = i;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000444 for (int j = 0; j < proc_samples_per_channel_; j++) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000445 interleaved[interleaved_idx] = deinterleaved[j];
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000446 interleaved_idx += num_proc_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000447 }
448 }
449}
450
niklase@google.com470e71d2011-07-07 08:21:25 +0000451void AudioBuffer::CopyLowPassToReference() {
452 reference_copied_ = true;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000453 if (!low_pass_reference_channels_.get()) {
454 low_pass_reference_channels_.reset(
455 new ChannelBuffer<int16_t>(samples_per_split_channel_,
456 num_proc_channels_));
457 }
458 for (int i = 0; i < num_proc_channels_; i++) {
459 low_pass_reference_channels_->CopyFrom(low_pass_split_data(i), i);
niklase@google.com470e71d2011-07-07 08:21:25 +0000460 }
461}
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000462
niklase@google.com470e71d2011-07-07 08:21:25 +0000463} // namespace webrtc