aluebs@webrtc.org | 79b9eba | 2014-11-26 20:21:38 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 035e912 | 2015-01-28 19:57:00 +0000 | [diff] [blame] | 11 | #include "webrtc/common_audio/channel_buffer.h" |
aluebs@webrtc.org | 79b9eba | 2014-11-26 20:21:38 +0000 | [diff] [blame] | 12 | |
| 13 | namespace webrtc { |
| 14 | |
aluebs@webrtc.org | d35a5c3 | 2015-02-10 22:52:15 +0000 | [diff] [blame] | 15 | IFChannelBuffer::IFChannelBuffer(int num_frames, |
| 16 | int num_channels, |
| 17 | int num_bands) |
aluebs@webrtc.org | 79b9eba | 2014-11-26 20:21:38 +0000 | [diff] [blame] | 18 | : ivalid_(true), |
aluebs@webrtc.org | d35a5c3 | 2015-02-10 22:52:15 +0000 | [diff] [blame] | 19 | ibuf_(num_frames, num_channels, num_bands), |
aluebs@webrtc.org | 79b9eba | 2014-11-26 20:21:38 +0000 | [diff] [blame] | 20 | fvalid_(true), |
aluebs@webrtc.org | d35a5c3 | 2015-02-10 22:52:15 +0000 | [diff] [blame] | 21 | fbuf_(num_frames, num_channels, num_bands) {} |
aluebs@webrtc.org | 79b9eba | 2014-11-26 20:21:38 +0000 | [diff] [blame] | 22 | |
| 23 | ChannelBuffer<int16_t>* IFChannelBuffer::ibuf() { |
| 24 | RefreshI(); |
| 25 | fvalid_ = false; |
| 26 | return &ibuf_; |
| 27 | } |
| 28 | |
| 29 | ChannelBuffer<float>* IFChannelBuffer::fbuf() { |
| 30 | RefreshF(); |
| 31 | ivalid_ = false; |
| 32 | return &fbuf_; |
| 33 | } |
| 34 | |
| 35 | const ChannelBuffer<int16_t>* IFChannelBuffer::ibuf_const() const { |
| 36 | RefreshI(); |
| 37 | return &ibuf_; |
| 38 | } |
| 39 | |
| 40 | const ChannelBuffer<float>* IFChannelBuffer::fbuf_const() const { |
| 41 | RefreshF(); |
| 42 | return &fbuf_; |
| 43 | } |
| 44 | |
| 45 | void IFChannelBuffer::RefreshF() const { |
| 46 | if (!fvalid_) { |
| 47 | assert(ivalid_); |
aluebs@webrtc.org | d35a5c3 | 2015-02-10 22:52:15 +0000 | [diff] [blame] | 48 | 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.org | 79b9eba | 2014-11-26 20:21:38 +0000 | [diff] [blame] | 55 | fvalid_ = true; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void IFChannelBuffer::RefreshI() const { |
| 60 | if (!ivalid_) { |
| 61 | assert(fvalid_); |
aluebs@webrtc.org | d35a5c3 | 2015-02-10 22:52:15 +0000 | [diff] [blame] | 62 | 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.org | 79b9eba | 2014-11-26 20:21:38 +0000 | [diff] [blame] | 69 | ivalid_ = true; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | } // namespace webrtc |