niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 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_MAIN_SOURCE_AUDIO_BUFFER_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_BUFFER_H_ |
| 13 | |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/interface/module_common_types.h" |
| 15 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 16 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | namespace webrtc { |
| 19 | |
| 20 | struct AudioChannel; |
| 21 | struct SplitAudioChannel; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
| 23 | class AudioBuffer { |
| 24 | public: |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 25 | AudioBuffer(int max_num_channels, int samples_per_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | virtual ~AudioBuffer(); |
| 27 | |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 28 | int num_channels() const; |
| 29 | int samples_per_channel() const; |
| 30 | int samples_per_split_channel() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 32 | int16_t* data(int channel) const; |
| 33 | int16_t* low_pass_split_data(int channel) const; |
| 34 | int16_t* high_pass_split_data(int channel) const; |
| 35 | int16_t* mixed_data(int channel) const; |
| 36 | int16_t* mixed_low_pass_data(int channel) const; |
| 37 | int16_t* low_pass_reference(int channel) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 39 | int32_t* analysis_filter_state1(int channel) const; |
| 40 | int32_t* analysis_filter_state2(int channel) const; |
| 41 | int32_t* synthesis_filter_state1(int channel) const; |
| 42 | int32_t* synthesis_filter_state2(int channel) const; |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 43 | |
| 44 | void set_activity(AudioFrame::VADActivity activity); |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 45 | AudioFrame::VADActivity activity() const; |
| 46 | |
| 47 | bool is_muted() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 49 | // Use for int16 interleaved data. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | void DeinterleaveFrom(AudioFrame* audioFrame); |
| 51 | void InterleaveTo(AudioFrame* audioFrame) const; |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 52 | // If |data_changed| is false, only the non-audio data members will be copied |
| 53 | // to |frame|. |
| 54 | void InterleaveTo(AudioFrame* frame, bool data_changed) const; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 55 | |
| 56 | // Use for float deinterleaved data. |
| 57 | void CopyFrom(const float* const* data, int samples_per_channel, |
| 58 | int num_channels); |
| 59 | void CopyTo(int samples_per_channel, int num_channels, |
| 60 | float* const* data) const; |
| 61 | |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 62 | void Mix(int num_mixed_channels); |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 63 | void CopyAndMix(int num_mixed_channels); |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 64 | void CopyAndMixLowPass(int num_mixed_channels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | void CopyLowPassToReference(); |
| 66 | |
| 67 | private: |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 68 | // Called from DeinterleaveFrom() and CopyFrom(). |
| 69 | void InitForNewData(int num_channels); |
| 70 | |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 71 | const int max_num_channels_; |
| 72 | int num_channels_; |
| 73 | int num_mixed_channels_; |
| 74 | int num_mixed_low_pass_channels_; |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 75 | // Whether the original data was replaced with mixed data. |
| 76 | bool data_was_mixed_; |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 77 | const int samples_per_channel_; |
| 78 | int samples_per_split_channel_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | bool reference_copied_; |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 80 | AudioFrame::VADActivity activity_; |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 81 | bool is_muted_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 83 | int16_t* data_; |
| 84 | scoped_array<AudioChannel> channels_; |
| 85 | scoped_array<SplitAudioChannel> split_channels_; |
| 86 | scoped_array<AudioChannel> mixed_channels_; |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 87 | // TODO(andrew): improve this, we don't need the full 32 kHz space here. |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 88 | scoped_array<AudioChannel> mixed_low_pass_channels_; |
| 89 | scoped_array<AudioChannel> low_pass_reference_channels_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | }; |
| 91 | } // namespace webrtc |
| 92 | |
| 93 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_BUFFER_H_ |