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" |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/interface/module_common_types.h" |
| 19 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 20 | #include "webrtc/system_wrappers/interface/scoped_vector.h" |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 21 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | namespace webrtc { |
| 24 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 25 | class PushSincResampler; |
| 26 | class SplitChannelBuffer; |
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 | |
| 29 | struct SplitFilterStates { |
| 30 | SplitFilterStates() { |
| 31 | memset(analysis_filter_state1, 0, sizeof(analysis_filter_state1)); |
| 32 | memset(analysis_filter_state2, 0, sizeof(analysis_filter_state2)); |
| 33 | memset(synthesis_filter_state1, 0, sizeof(synthesis_filter_state1)); |
| 34 | memset(synthesis_filter_state2, 0, sizeof(synthesis_filter_state2)); |
| 35 | } |
| 36 | |
| 37 | static const int kStateSize = 6; |
| 38 | int analysis_filter_state1[kStateSize]; |
| 39 | int analysis_filter_state2[kStateSize]; |
| 40 | int synthesis_filter_state1[kStateSize]; |
| 41 | int synthesis_filter_state2[kStateSize]; |
| 42 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
| 44 | class AudioBuffer { |
| 45 | public: |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 46 | // TODO(ajm): Switch to take ChannelLayouts. |
| 47 | AudioBuffer(int input_samples_per_channel, |
| 48 | int num_input_channels, |
| 49 | int process_samples_per_channel, |
| 50 | int num_process_channels, |
| 51 | int output_samples_per_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | virtual ~AudioBuffer(); |
| 53 | |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 54 | int num_channels() const; |
| 55 | int samples_per_channel() const; |
| 56 | int samples_per_split_channel() const; |
andrew@webrtc.org | 103657b | 2014-04-24 18:28:56 +0000 | [diff] [blame] | 57 | int samples_per_keyboard_channel() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
aluebs@webrtc.org | fb2e7c2 | 2014-07-11 11:40:48 +0000 | [diff] [blame] | 59 | // It can be assumed that channels are stored contiguously. |
andrew@webrtc.org | 65f9338 | 2014-04-30 16:44:13 +0000 | [diff] [blame] | 60 | int16_t* data(int channel); |
| 61 | const int16_t* data(int channel) const; |
| 62 | int16_t* low_pass_split_data(int channel); |
| 63 | const int16_t* low_pass_split_data(int channel) const; |
| 64 | int16_t* high_pass_split_data(int channel); |
| 65 | const int16_t* high_pass_split_data(int channel) const; |
aluebs@webrtc.org | 2561d52 | 2014-07-17 08:27:39 +0000 | [diff] [blame^] | 66 | // Returns a pointer to the low-pass data downmixed to mono. If this data |
| 67 | // isn't already available it re-calculates it. |
| 68 | const int16_t* mixed_low_pass_data(); |
andrew@webrtc.org | 65f9338 | 2014-04-30 16:44:13 +0000 | [diff] [blame] | 69 | const int16_t* low_pass_reference(int channel) const; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 70 | |
| 71 | // Float versions of the accessors, with automatic conversion back and forth |
| 72 | // as necessary. The range of the numbers are the same as for int16_t. |
| 73 | float* data_f(int channel); |
kwiberg@webrtc.org | 38214d5 | 2014-07-03 09:47:33 +0000 | [diff] [blame] | 74 | const float* data_f(int channel) const; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 75 | float* low_pass_split_data_f(int channel); |
kwiberg@webrtc.org | 38214d5 | 2014-07-03 09:47:33 +0000 | [diff] [blame] | 76 | const float* low_pass_split_data_f(int channel) const; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 77 | float* high_pass_split_data_f(int channel); |
kwiberg@webrtc.org | 38214d5 | 2014-07-03 09:47:33 +0000 | [diff] [blame] | 78 | const float* high_pass_split_data_f(int channel) const; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 79 | |
andrew@webrtc.org | 103657b | 2014-04-24 18:28:56 +0000 | [diff] [blame] | 80 | const float* keyboard_data() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
andrew@webrtc.org | 65f9338 | 2014-04-30 16:44:13 +0000 | [diff] [blame] | 82 | SplitFilterStates* filter_states(int channel); |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 83 | |
| 84 | void set_activity(AudioFrame::VADActivity activity); |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 85 | AudioFrame::VADActivity activity() const; |
| 86 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 87 | // Use for int16 interleaved data. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 88 | void DeinterleaveFrom(AudioFrame* audioFrame); |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 89 | // If |data_changed| is false, only the non-audio data members will be copied |
| 90 | // to |frame|. |
| 91 | void InterleaveTo(AudioFrame* frame, bool data_changed) const; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 92 | |
| 93 | // Use for float deinterleaved data. |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 94 | void CopyFrom(const float* const* data, |
| 95 | int samples_per_channel, |
| 96 | AudioProcessing::ChannelLayout layout); |
| 97 | void CopyTo(int samples_per_channel, |
| 98 | AudioProcessing::ChannelLayout layout, |
| 99 | float* const* data); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | void CopyLowPassToReference(); |
| 101 | |
| 102 | private: |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 103 | // Called from DeinterleaveFrom() and CopyFrom(). |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 104 | void InitForNewData(); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 105 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 106 | const int input_samples_per_channel_; |
| 107 | const int num_input_channels_; |
| 108 | const int proc_samples_per_channel_; |
| 109 | const int num_proc_channels_; |
| 110 | const int output_samples_per_channel_; |
| 111 | int samples_per_split_channel_; |
aluebs@webrtc.org | 2561d52 | 2014-07-17 08:27:39 +0000 | [diff] [blame^] | 112 | bool mixed_low_pass_valid_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | bool reference_copied_; |
andrew@webrtc.org | ed083d4 | 2011-09-19 15:28:51 +0000 | [diff] [blame] | 114 | AudioFrame::VADActivity activity_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
andrew@webrtc.org | 103657b | 2014-04-24 18:28:56 +0000 | [diff] [blame] | 116 | const float* keyboard_data_; |
mflodman@webrtc.org | d5da250 | 2014-05-15 11:17:21 +0000 | [diff] [blame] | 117 | scoped_ptr<IFChannelBuffer> channels_; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 118 | scoped_ptr<SplitChannelBuffer> split_channels_; |
| 119 | scoped_ptr<SplitFilterStates[]> filter_states_; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 120 | scoped_ptr<ChannelBuffer<int16_t> > mixed_low_pass_channels_; |
| 121 | scoped_ptr<ChannelBuffer<int16_t> > low_pass_reference_channels_; |
| 122 | scoped_ptr<ChannelBuffer<float> > input_buffer_; |
| 123 | scoped_ptr<ChannelBuffer<float> > process_buffer_; |
| 124 | ScopedVector<PushSincResampler> input_resamplers_; |
| 125 | ScopedVector<PushSincResampler> output_resamplers_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 126 | }; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 127 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | } // namespace webrtc |
| 129 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 130 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_ |