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 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
| 16 | #include "webrtc/modules/audio_processing/common.h" |
| 17 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
aluebs@webrtc.org | be05c74 | 2014-11-14 22:18:10 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/audio_processing/splitting_filter.h" |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 19 | #include "webrtc/modules/interface/module_common_types.h" |
| 20 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 21 | #include "webrtc/system_wrappers/interface/scoped_vector.h" |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 22 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | namespace webrtc { |
| 25 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 26 | class PushSincResampler; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 27 | class IFChannelBuffer; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 28 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | class AudioBuffer { |
| 30 | public: |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 31 | // TODO(ajm): Switch to take ChannelLayouts. |
| 32 | AudioBuffer(int input_samples_per_channel, |
| 33 | int num_input_channels, |
| 34 | int process_samples_per_channel, |
| 35 | int num_process_channels, |
| 36 | int output_samples_per_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | virtual ~AudioBuffer(); |
| 38 | |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 39 | int num_channels() const; |
| 40 | int samples_per_channel() const; |
| 41 | int samples_per_split_channel() const; |
andrew@webrtc.org | 103657b | 2014-04-24 18:28:56 +0000 | [diff] [blame] | 42 | int samples_per_keyboard_channel() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
kwiberg@webrtc.org | e364ac9 | 2014-07-18 07:50:29 +0000 | [diff] [blame] | 44 | // Sample array accessors. Channels are guaranteed to be stored contiguously |
| 45 | // in memory. Prefer to use the const variants of each accessor when |
| 46 | // possible, since they incur less float<->int16 conversion overhead. |
andrew@webrtc.org | 65f9338 | 2014-04-30 16:44:13 +0000 | [diff] [blame] | 47 | int16_t* data(int channel); |
| 48 | const int16_t* data(int channel) const; |
aluebs@webrtc.org | be05c74 | 2014-11-14 22:18:10 +0000 | [diff] [blame] | 49 | int16_t* const* channels(); |
| 50 | const int16_t* const* channels() const; |
andrew@webrtc.org | 65f9338 | 2014-04-30 16:44:13 +0000 | [diff] [blame] | 51 | int16_t* low_pass_split_data(int channel); |
| 52 | const int16_t* low_pass_split_data(int channel) const; |
| 53 | int16_t* high_pass_split_data(int channel); |
aluebs@webrtc.org | be05c74 | 2014-11-14 22:18:10 +0000 | [diff] [blame] | 54 | const int16_t* high_pass_split_data(int channel) const; |
| 55 | int16_t* const* low_pass_split_channels(); |
| 56 | const int16_t* const* low_pass_split_channels() const; |
| 57 | int16_t* const* high_pass_split_channels(); |
| 58 | const int16_t* const* high_pass_split_channels() const; |
aluebs@webrtc.org | 2561d52 | 2014-07-17 08:27:39 +0000 | [diff] [blame] | 59 | // Returns a pointer to the low-pass data downmixed to mono. If this data |
| 60 | // isn't already available it re-calculates it. |
| 61 | const int16_t* mixed_low_pass_data(); |
andrew@webrtc.org | 65f9338 | 2014-04-30 16:44:13 +0000 | [diff] [blame] | 62 | const int16_t* low_pass_reference(int channel) const; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 63 | |
| 64 | // Float versions of the accessors, with automatic conversion back and forth |
| 65 | // as necessary. The range of the numbers are the same as for int16_t. |
| 66 | float* data_f(int channel); |
kwiberg@webrtc.org | 38214d5 | 2014-07-03 09:47:33 +0000 | [diff] [blame] | 67 | const float* data_f(int channel) const; |
claguna@google.com | bfacaab | 2014-09-25 20:52:08 +0000 | [diff] [blame] | 68 | |
| 69 | float* const* channels_f(); |
| 70 | const float* const* channels_f() const; |
| 71 | |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 72 | float* low_pass_split_data_f(int channel); |
kwiberg@webrtc.org | 38214d5 | 2014-07-03 09:47:33 +0000 | [diff] [blame] | 73 | const float* low_pass_split_data_f(int channel) const; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 74 | float* high_pass_split_data_f(int channel); |
kwiberg@webrtc.org | 38214d5 | 2014-07-03 09:47:33 +0000 | [diff] [blame] | 75 | const float* high_pass_split_data_f(int channel) const; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 76 | |
claguna@google.com | bfacaab | 2014-09-25 20:52:08 +0000 | [diff] [blame] | 77 | float* const* low_pass_split_channels_f(); |
| 78 | const float* const* low_pass_split_channels_f() const; |
| 79 | float* const* high_pass_split_channels_f(); |
| 80 | const float* const* high_pass_split_channels_f() const; |
aluebs@webrtc.org | 087da13 | 2014-11-17 23:01:23 +0000 | [diff] [blame^] | 81 | float* const* super_high_pass_split_channels_f(); |
| 82 | const float* const* super_high_pass_split_channels_f() const; |
claguna@google.com | bfacaab | 2014-09-25 20:52:08 +0000 | [diff] [blame] | 83 | |
andrew@webrtc.org | 103657b | 2014-04-24 18:28:56 +0000 | [diff] [blame] | 84 | const float* keyboard_data() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 86 | void set_activity(AudioFrame::VADActivity activity); |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 87 | AudioFrame::VADActivity activity() const; |
| 88 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 89 | // Use for int16 interleaved data. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | void DeinterleaveFrom(AudioFrame* audioFrame); |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 91 | // If |data_changed| is false, only the non-audio data members will be copied |
| 92 | // to |frame|. |
| 93 | void InterleaveTo(AudioFrame* frame, bool data_changed) const; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 94 | |
| 95 | // Use for float deinterleaved data. |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 96 | void CopyFrom(const float* const* data, |
| 97 | int samples_per_channel, |
| 98 | AudioProcessing::ChannelLayout layout); |
| 99 | void CopyTo(int samples_per_channel, |
| 100 | AudioProcessing::ChannelLayout layout, |
| 101 | float* const* data); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | void CopyLowPassToReference(); |
| 103 | |
aluebs@webrtc.org | be05c74 | 2014-11-14 22:18:10 +0000 | [diff] [blame] | 104 | // Splits the signal into different bands. |
| 105 | void SplitIntoFrequencyBands(); |
| 106 | // Recombine the different bands into one signal. |
| 107 | void MergeFrequencyBands(); |
| 108 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | private: |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 110 | // Called from DeinterleaveFrom() and CopyFrom(). |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 111 | void InitForNewData(); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 112 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 113 | const int input_samples_per_channel_; |
| 114 | const int num_input_channels_; |
| 115 | const int proc_samples_per_channel_; |
| 116 | const int num_proc_channels_; |
| 117 | const int output_samples_per_channel_; |
| 118 | int samples_per_split_channel_; |
aluebs@webrtc.org | 2561d52 | 2014-07-17 08:27:39 +0000 | [diff] [blame] | 119 | bool mixed_low_pass_valid_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | bool reference_copied_; |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 121 | AudioFrame::VADActivity activity_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
andrew@webrtc.org | 103657b | 2014-04-24 18:28:56 +0000 | [diff] [blame] | 123 | const float* keyboard_data_; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 124 | scoped_ptr<IFChannelBuffer> channels_; |
kwiberg@webrtc.org | 2b6bc8d | 2014-07-17 09:46:37 +0000 | [diff] [blame] | 125 | scoped_ptr<IFChannelBuffer> split_channels_low_; |
| 126 | scoped_ptr<IFChannelBuffer> split_channels_high_; |
aluebs@webrtc.org | 087da13 | 2014-11-17 23:01:23 +0000 | [diff] [blame^] | 127 | scoped_ptr<IFChannelBuffer> split_channels_super_high_; |
aluebs@webrtc.org | be05c74 | 2014-11-14 22:18:10 +0000 | [diff] [blame] | 128 | scoped_ptr<SplittingFilter> splitting_filter_; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 129 | scoped_ptr<ChannelBuffer<int16_t> > mixed_low_pass_channels_; |
| 130 | scoped_ptr<ChannelBuffer<int16_t> > low_pass_reference_channels_; |
| 131 | scoped_ptr<ChannelBuffer<float> > input_buffer_; |
| 132 | scoped_ptr<ChannelBuffer<float> > process_buffer_; |
| 133 | ScopedVector<PushSincResampler> input_resamplers_; |
| 134 | ScopedVector<PushSincResampler> output_resamplers_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 135 | }; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 136 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | } // namespace webrtc |
| 138 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 139 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_ |