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 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 14 | #include "webrtc/base/scoped_ptr.h" |
kjellander@webrtc.org | 035e912 | 2015-01-28 19:57:00 +0000 | [diff] [blame] | 15 | #include "webrtc/common_audio/channel_buffer.h" |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 16 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
aluebs@webrtc.org | be05c74 | 2014-11-14 22:18:10 +0000 | [diff] [blame] | 17 | #include "webrtc/modules/audio_processing/splitting_filter.h" |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/interface/module_common_types.h" |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 19 | #include "webrtc/system_wrappers/interface/scoped_vector.h" |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 20 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | namespace webrtc { |
| 23 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 24 | class PushSincResampler; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 25 | class IFChannelBuffer; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 26 | |
aluebs@webrtc.org | a7384a1 | 2014-12-03 01:06:35 +0000 | [diff] [blame] | 27 | enum Band { |
| 28 | kBand0To8kHz = 0, |
| 29 | kBand8To16kHz = 1, |
| 30 | kBand16To24kHz = 2 |
| 31 | }; |
| 32 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | class AudioBuffer { |
| 34 | public: |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 35 | // TODO(ajm): Switch to take ChannelLayouts. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame^] | 36 | AudioBuffer(size_t input_num_frames, |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 37 | int num_input_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame^] | 38 | size_t process_num_frames, |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 39 | int num_process_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame^] | 40 | size_t output_num_frames); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | virtual ~AudioBuffer(); |
| 42 | |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 43 | int num_channels() const; |
aluebs@webrtc.org | 27d106b | 2014-12-11 17:09:21 +0000 | [diff] [blame] | 44 | void set_num_channels(int num_channels); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame^] | 45 | size_t num_frames() const; |
| 46 | size_t num_frames_per_band() const; |
| 47 | size_t num_keyboard_frames() const; |
| 48 | size_t num_bands() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
aluebs@webrtc.org | 3aca0b0 | 2015-02-26 21:52:20 +0000 | [diff] [blame] | 50 | // Returns a pointer array to the full-band channels. |
| 51 | // Usage: |
| 52 | // channels()[channel][sample]. |
| 53 | // Where: |
| 54 | // 0 <= channel < |num_proc_channels_| |
| 55 | // 0 <= sample < |proc_num_frames_| |
aluebs@webrtc.org | be05c74 | 2014-11-14 22:18:10 +0000 | [diff] [blame] | 56 | int16_t* const* channels(); |
aluebs@webrtc.org | a7384a1 | 2014-12-03 01:06:35 +0000 | [diff] [blame] | 57 | const int16_t* const* channels_const() const; |
aluebs@webrtc.org | 3aca0b0 | 2015-02-26 21:52:20 +0000 | [diff] [blame] | 58 | float* const* channels_f(); |
| 59 | const float* const* channels_const_f() const; |
| 60 | |
| 61 | // Returns a pointer array to the bands for a specific channel. |
| 62 | // Usage: |
| 63 | // split_bands(channel)[band][sample]. |
| 64 | // Where: |
| 65 | // 0 <= channel < |num_proc_channels_| |
| 66 | // 0 <= band < |num_bands_| |
| 67 | // 0 <= sample < |num_split_frames_| |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 68 | int16_t* const* split_bands(int channel); |
| 69 | const int16_t* const* split_bands_const(int channel) const; |
aluebs@webrtc.org | 3aca0b0 | 2015-02-26 21:52:20 +0000 | [diff] [blame] | 70 | float* const* split_bands_f(int channel); |
| 71 | const float* const* split_bands_const_f(int channel) const; |
| 72 | |
| 73 | // Returns a pointer array to the channels for a specific band. |
| 74 | // Usage: |
| 75 | // split_channels(band)[channel][sample]. |
| 76 | // Where: |
| 77 | // 0 <= band < |num_bands_| |
| 78 | // 0 <= channel < |num_proc_channels_| |
| 79 | // 0 <= sample < |num_split_frames_| |
aluebs@webrtc.org | a7384a1 | 2014-12-03 01:06:35 +0000 | [diff] [blame] | 80 | int16_t* const* split_channels(Band band); |
| 81 | const int16_t* const* split_channels_const(Band band) const; |
aluebs@webrtc.org | 3aca0b0 | 2015-02-26 21:52:20 +0000 | [diff] [blame] | 82 | float* const* split_channels_f(Band band); |
| 83 | const float* const* split_channels_const_f(Band band) const; |
| 84 | |
| 85 | // Returns a pointer to the ChannelBuffer that encapsulates the full-band |
| 86 | // data. |
| 87 | ChannelBuffer<int16_t>* data(); |
| 88 | const ChannelBuffer<int16_t>* data() const; |
| 89 | ChannelBuffer<float>* data_f(); |
| 90 | const ChannelBuffer<float>* data_f() const; |
| 91 | |
| 92 | // Returns a pointer to the ChannelBuffer that encapsulates the split data. |
| 93 | ChannelBuffer<int16_t>* split_data(); |
| 94 | const ChannelBuffer<int16_t>* split_data() const; |
| 95 | ChannelBuffer<float>* split_data_f(); |
| 96 | const ChannelBuffer<float>* split_data_f() const; |
aluebs@webrtc.org | a7384a1 | 2014-12-03 01:06:35 +0000 | [diff] [blame] | 97 | |
aluebs@webrtc.org | 2561d52 | 2014-07-17 08:27:39 +0000 | [diff] [blame] | 98 | // Returns a pointer to the low-pass data downmixed to mono. If this data |
| 99 | // isn't already available it re-calculates it. |
| 100 | const int16_t* mixed_low_pass_data(); |
andrew@webrtc.org | 65f9338 | 2014-04-30 16:44:13 +0000 | [diff] [blame] | 101 | const int16_t* low_pass_reference(int channel) const; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 102 | |
andrew@webrtc.org | 103657b | 2014-04-24 18:28:56 +0000 | [diff] [blame] | 103 | const float* keyboard_data() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 105 | void set_activity(AudioFrame::VADActivity activity); |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 106 | AudioFrame::VADActivity activity() const; |
| 107 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 108 | // Use for int16 interleaved data. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | void DeinterleaveFrom(AudioFrame* audioFrame); |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 110 | // If |data_changed| is false, only the non-audio data members will be copied |
| 111 | // to |frame|. |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 112 | void InterleaveTo(AudioFrame* frame, bool data_changed); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 113 | |
| 114 | // Use for float deinterleaved data. |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 115 | void CopyFrom(const float* const* data, const StreamConfig& stream_config); |
| 116 | void CopyTo(const StreamConfig& stream_config, float* const* data); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | void CopyLowPassToReference(); |
| 118 | |
aluebs@webrtc.org | be05c74 | 2014-11-14 22:18:10 +0000 | [diff] [blame] | 119 | // Splits the signal into different bands. |
| 120 | void SplitIntoFrequencyBands(); |
| 121 | // Recombine the different bands into one signal. |
| 122 | void MergeFrequencyBands(); |
| 123 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 124 | private: |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 125 | // Called from DeinterleaveFrom() and CopyFrom(). |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 126 | void InitForNewData(); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 127 | |
aluebs@webrtc.org | 27d106b | 2014-12-11 17:09:21 +0000 | [diff] [blame] | 128 | // The audio is passed into DeinterleaveFrom() or CopyFrom() with input |
| 129 | // format (samples per channel and number of channels). |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame^] | 130 | const size_t input_num_frames_; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 131 | const int num_input_channels_; |
aluebs@webrtc.org | 27d106b | 2014-12-11 17:09:21 +0000 | [diff] [blame] | 132 | // The audio is stored by DeinterleaveFrom() or CopyFrom() with processing |
| 133 | // format. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame^] | 134 | const size_t proc_num_frames_; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 135 | const int num_proc_channels_; |
aluebs@webrtc.org | 27d106b | 2014-12-11 17:09:21 +0000 | [diff] [blame] | 136 | // The audio is returned by InterleaveTo() and CopyTo() with output samples |
| 137 | // per channels and the current number of channels. This last one can be |
| 138 | // changed at any time using set_num_channels(). |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame^] | 139 | const size_t output_num_frames_; |
aluebs@webrtc.org | 27d106b | 2014-12-11 17:09:21 +0000 | [diff] [blame] | 140 | int num_channels_; |
| 141 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame^] | 142 | size_t num_bands_; |
| 143 | size_t num_split_frames_; |
aluebs@webrtc.org | 2561d52 | 2014-07-17 08:27:39 +0000 | [diff] [blame] | 144 | bool mixed_low_pass_valid_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 145 | bool reference_copied_; |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 146 | AudioFrame::VADActivity activity_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 147 | |
andrew@webrtc.org | 103657b | 2014-04-24 18:28:56 +0000 | [diff] [blame] | 148 | const float* keyboard_data_; |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 149 | rtc::scoped_ptr<IFChannelBuffer> data_; |
| 150 | rtc::scoped_ptr<IFChannelBuffer> split_data_; |
| 151 | rtc::scoped_ptr<SplittingFilter> splitting_filter_; |
| 152 | rtc::scoped_ptr<ChannelBuffer<int16_t> > mixed_low_pass_channels_; |
| 153 | rtc::scoped_ptr<ChannelBuffer<int16_t> > low_pass_reference_channels_; |
Alejandro Luebs | 05c7605 | 2015-05-20 14:39:39 -0700 | [diff] [blame] | 154 | rtc::scoped_ptr<IFChannelBuffer> input_buffer_; |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 155 | rtc::scoped_ptr<IFChannelBuffer> output_buffer_; |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 156 | rtc::scoped_ptr<ChannelBuffer<float> > process_buffer_; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 157 | ScopedVector<PushSincResampler> input_resamplers_; |
| 158 | ScopedVector<PushSincResampler> output_resamplers_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | }; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 160 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 161 | } // namespace webrtc |
| 162 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 163 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_ |