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 | |
| 11 | #include "webrtc/modules/audio_processing/channel_buffer.h" |
| 12 | |
| 13 | namespace webrtc { |
| 14 | |
| 15 | IFChannelBuffer::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 | |
| 21 | ChannelBuffer<int16_t>* IFChannelBuffer::ibuf() { |
| 22 | RefreshI(); |
| 23 | fvalid_ = false; |
| 24 | return &ibuf_; |
| 25 | } |
| 26 | |
| 27 | ChannelBuffer<float>* IFChannelBuffer::fbuf() { |
| 28 | RefreshF(); |
| 29 | ivalid_ = false; |
| 30 | return &fbuf_; |
| 31 | } |
| 32 | |
| 33 | const ChannelBuffer<int16_t>* IFChannelBuffer::ibuf_const() const { |
| 34 | RefreshI(); |
| 35 | return &ibuf_; |
| 36 | } |
| 37 | |
| 38 | const ChannelBuffer<float>* IFChannelBuffer::fbuf_const() const { |
| 39 | RefreshF(); |
| 40 | return &fbuf_; |
| 41 | } |
| 42 | |
| 43 | void 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 | |
| 55 | void 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 |