blob: 9c07550170d7080f0de89e991ce1565e26130f43 [file] [log] [blame]
aluebs@webrtc.org79b9eba2014-11-26 20:21:38 +00001/*
2 * Copyright (c) 2014 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
kjellander@webrtc.org035e9122015-01-28 19:57:00 +000011#include "webrtc/common_audio/channel_buffer.h"
aluebs@webrtc.org79b9eba2014-11-26 20:21:38 +000012
13namespace webrtc {
14
15IFChannelBuffer::IFChannelBuffer(int samples_per_channel, int num_channels)
16 : ivalid_(true),
17 ibuf_(samples_per_channel, num_channels),
18 fvalid_(true),
19 fbuf_(samples_per_channel, num_channels) {}
20
21ChannelBuffer<int16_t>* IFChannelBuffer::ibuf() {
22 RefreshI();
23 fvalid_ = false;
24 return &ibuf_;
25}
26
27ChannelBuffer<float>* IFChannelBuffer::fbuf() {
28 RefreshF();
29 ivalid_ = false;
30 return &fbuf_;
31}
32
33const ChannelBuffer<int16_t>* IFChannelBuffer::ibuf_const() const {
34 RefreshI();
35 return &ibuf_;
36}
37
38const ChannelBuffer<float>* IFChannelBuffer::fbuf_const() const {
39 RefreshF();
40 return &fbuf_;
41}
42
43void IFChannelBuffer::RefreshF() const {
44 if (!fvalid_) {
45 assert(ivalid_);
46 const int16_t* const int_data = ibuf_.data();
47 float* const float_data = fbuf_.data();
48 const int length = fbuf_.length();
49 for (int i = 0; i < length; ++i)
50 float_data[i] = int_data[i];
51 fvalid_ = true;
52 }
53}
54
55void IFChannelBuffer::RefreshI() const {
56 if (!ivalid_) {
57 assert(fvalid_);
58 FloatS16ToS16(fbuf_.data(), ibuf_.length(), ibuf_.data());
59 ivalid_ = true;
60 }
61}
62
63} // namespace webrtc