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 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 15 | IFChannelBuffer::IFChannelBuffer(size_t num_frames, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 16 | size_t num_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 17 | size_t 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_) { |
kjellander | e80f9d0 | 2016-02-23 13:33:32 -0800 | [diff] [blame] | 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(); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 50 | for (size_t i = 0; i < ibuf_.num_channels(); ++i) { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 51 | for (size_t j = 0; j < ibuf_.num_frames(); ++j) { |
aluebs@webrtc.org | d35a5c3 | 2015-02-10 22:52:15 +0000 | [diff] [blame] | 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_) { |
kjellander | e80f9d0 | 2016-02-23 13:33:32 -0800 | [diff] [blame] | 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(); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 64 | for (size_t i = 0; i < ibuf_.num_channels(); ++i) { |
aluebs@webrtc.org | d35a5c3 | 2015-02-10 22:52:15 +0000 | [diff] [blame] | 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 |