blob: 14aaa7af095bec6ded038ad430aa94c8aac1dd91 [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
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +000015IFChannelBuffer::IFChannelBuffer(int num_frames,
16 int num_channels,
17 int num_bands)
aluebs@webrtc.org79b9eba2014-11-26 20:21:38 +000018 : ivalid_(true),
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +000019 ibuf_(num_frames, num_channels, num_bands),
aluebs@webrtc.org79b9eba2014-11-26 20:21:38 +000020 fvalid_(true),
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +000021 fbuf_(num_frames, num_channels, num_bands) {}
aluebs@webrtc.org79b9eba2014-11-26 20:21:38 +000022
23ChannelBuffer<int16_t>* IFChannelBuffer::ibuf() {
24 RefreshI();
25 fvalid_ = false;
26 return &ibuf_;
27}
28
29ChannelBuffer<float>* IFChannelBuffer::fbuf() {
30 RefreshF();
31 ivalid_ = false;
32 return &fbuf_;
33}
34
35const ChannelBuffer<int16_t>* IFChannelBuffer::ibuf_const() const {
36 RefreshI();
37 return &ibuf_;
38}
39
40const ChannelBuffer<float>* IFChannelBuffer::fbuf_const() const {
41 RefreshF();
42 return &fbuf_;
43}
44
45void IFChannelBuffer::RefreshF() const {
46 if (!fvalid_) {
47 assert(ivalid_);
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +000048 const int16_t* const* int_channels = ibuf_.channels();
49 float* const* float_channels = fbuf_.channels();
50 for (int i = 0; i < ibuf_.num_channels(); ++i) {
51 for (int j = 0; j < ibuf_.num_frames(); ++j) {
52 float_channels[i][j] = int_channels[i][j];
53 }
54 }
aluebs@webrtc.org79b9eba2014-11-26 20:21:38 +000055 fvalid_ = true;
56 }
57}
58
59void IFChannelBuffer::RefreshI() const {
60 if (!ivalid_) {
61 assert(fvalid_);
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +000062 int16_t* const* int_channels = ibuf_.channels();
63 const float* const* float_channels = fbuf_.channels();
64 for (int i = 0; i < ibuf_.num_channels(); ++i) {
65 FloatS16ToS16(float_channels[i],
66 ibuf_.num_frames(),
67 int_channels[i]);
68 }
aluebs@webrtc.org79b9eba2014-11-26 20:21:38 +000069 ivalid_ = true;
70 }
71}
72
73} // namespace webrtc