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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_ |
| 13 | |
| 14 | #include "webrtc/common_audio/include/audio_util.h" |
| 15 | #include "webrtc/modules/audio_processing/common.h" |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | // One int16_t and one float ChannelBuffer that are kept in sync. The sync is |
| 20 | // broken when someone requests write access to either ChannelBuffer, and |
| 21 | // reestablished when someone requests the outdated ChannelBuffer. It is |
| 22 | // therefore safe to use the return value of ibuf_const() and fbuf_const() |
| 23 | // until the next call to ibuf() or fbuf(), and the return value of ibuf() and |
| 24 | // fbuf() until the next call to any of the other functions. |
| 25 | class IFChannelBuffer { |
| 26 | public: |
| 27 | IFChannelBuffer(int samples_per_channel, int num_channels); |
| 28 | |
| 29 | ChannelBuffer<int16_t>* ibuf(); |
| 30 | ChannelBuffer<float>* fbuf(); |
| 31 | const ChannelBuffer<int16_t>* ibuf_const() const; |
| 32 | const ChannelBuffer<float>* fbuf_const() const; |
| 33 | |
| 34 | int num_channels() const { return ibuf_.num_channels(); } |
| 35 | int samples_per_channel() const { return ibuf_.samples_per_channel(); } |
| 36 | |
| 37 | private: |
| 38 | void RefreshF() const; |
| 39 | void RefreshI() const; |
| 40 | |
| 41 | mutable bool ivalid_; |
| 42 | mutable ChannelBuffer<int16_t> ibuf_; |
| 43 | mutable bool fvalid_; |
| 44 | mutable ChannelBuffer<float> fbuf_; |
| 45 | }; |
| 46 | |
| 47 | } // namespace webrtc |
| 48 | |
| 49 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_ |