blob: fe2cf36c30bf1dcce9eecc5ae0198123a769fd52 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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.orgddbb8a22014-04-22 21:00:04 +000011#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_
12#define WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000014#include <vector>
15
aluebs@webrtc.org79b9eba2014-11-26 20:21:38 +000016#include "webrtc/common_audio/include/audio_util.h"
aluebs@webrtc.org87893762014-11-27 23:40:25 +000017#include "webrtc/modules/audio_processing/channel_buffer.h"
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000018#include "webrtc/modules/audio_processing/include/audio_processing.h"
aluebs@webrtc.orgbe05c742014-11-14 22:18:10 +000019#include "webrtc/modules/audio_processing/splitting_filter.h"
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000020#include "webrtc/modules/interface/module_common_types.h"
21#include "webrtc/system_wrappers/interface/scoped_ptr.h"
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000022#include "webrtc/system_wrappers/interface/scoped_vector.h"
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000023#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
niklase@google.com470e71d2011-07-07 08:21:25 +000025namespace webrtc {
26
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000027class PushSincResampler;
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +000028class IFChannelBuffer;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000029
niklase@google.com470e71d2011-07-07 08:21:25 +000030class AudioBuffer {
31 public:
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000032 // TODO(ajm): Switch to take ChannelLayouts.
33 AudioBuffer(int input_samples_per_channel,
34 int num_input_channels,
35 int process_samples_per_channel,
36 int num_process_channels,
37 int output_samples_per_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +000038 virtual ~AudioBuffer();
39
andrew@webrtc.orged083d42011-09-19 15:28:51 +000040 int num_channels() const;
41 int samples_per_channel() const;
42 int samples_per_split_channel() const;
andrew@webrtc.org103657b2014-04-24 18:28:56 +000043 int samples_per_keyboard_channel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000044
kwiberg@webrtc.orge364ac92014-07-18 07:50:29 +000045 // Sample array accessors. Channels are guaranteed to be stored contiguously
46 // in memory. Prefer to use the const variants of each accessor when
47 // possible, since they incur less float<->int16 conversion overhead.
andrew@webrtc.org65f93382014-04-30 16:44:13 +000048 int16_t* data(int channel);
49 const int16_t* data(int channel) const;
aluebs@webrtc.orgbe05c742014-11-14 22:18:10 +000050 int16_t* const* channels();
51 const int16_t* const* channels() const;
andrew@webrtc.org65f93382014-04-30 16:44:13 +000052 int16_t* low_pass_split_data(int channel);
53 const int16_t* low_pass_split_data(int channel) const;
54 int16_t* high_pass_split_data(int channel);
aluebs@webrtc.orgbe05c742014-11-14 22:18:10 +000055 const int16_t* high_pass_split_data(int channel) const;
56 int16_t* const* low_pass_split_channels();
57 const int16_t* const* low_pass_split_channels() const;
58 int16_t* const* high_pass_split_channels();
59 const int16_t* const* high_pass_split_channels() const;
aluebs@webrtc.org2561d522014-07-17 08:27:39 +000060 // Returns a pointer to the low-pass data downmixed to mono. If this data
61 // isn't already available it re-calculates it.
62 const int16_t* mixed_low_pass_data();
andrew@webrtc.org65f93382014-04-30 16:44:13 +000063 const int16_t* low_pass_reference(int channel) const;
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +000064
65 // Float versions of the accessors, with automatic conversion back and forth
66 // as necessary. The range of the numbers are the same as for int16_t.
67 float* data_f(int channel);
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +000068 const float* data_f(int channel) const;
claguna@google.combfacaab2014-09-25 20:52:08 +000069
70 float* const* channels_f();
71 const float* const* channels_f() const;
72
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +000073 float* low_pass_split_data_f(int channel);
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +000074 const float* low_pass_split_data_f(int channel) const;
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +000075 float* high_pass_split_data_f(int channel);
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +000076 const float* high_pass_split_data_f(int channel) const;
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +000077
claguna@google.combfacaab2014-09-25 20:52:08 +000078 float* const* low_pass_split_channels_f();
79 const float* const* low_pass_split_channels_f() const;
80 float* const* high_pass_split_channels_f();
81 const float* const* high_pass_split_channels_f() const;
aluebs@webrtc.org087da132014-11-17 23:01:23 +000082 float* const* super_high_pass_split_channels_f();
83 const float* const* super_high_pass_split_channels_f() const;
claguna@google.combfacaab2014-09-25 20:52:08 +000084
andrew@webrtc.org103657b2014-04-24 18:28:56 +000085 const float* keyboard_data() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000086
andrew@webrtc.orged083d42011-09-19 15:28:51 +000087 void set_activity(AudioFrame::VADActivity activity);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000088 AudioFrame::VADActivity activity() const;
89
andrew@webrtc.org17e40642014-03-04 20:58:13 +000090 // Use for int16 interleaved data.
niklase@google.com470e71d2011-07-07 08:21:25 +000091 void DeinterleaveFrom(AudioFrame* audioFrame);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000092 // If |data_changed| is false, only the non-audio data members will be copied
93 // to |frame|.
94 void InterleaveTo(AudioFrame* frame, bool data_changed) const;
andrew@webrtc.org17e40642014-03-04 20:58:13 +000095
96 // Use for float deinterleaved data.
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000097 void CopyFrom(const float* const* data,
98 int samples_per_channel,
99 AudioProcessing::ChannelLayout layout);
100 void CopyTo(int samples_per_channel,
101 AudioProcessing::ChannelLayout layout,
102 float* const* data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000103 void CopyLowPassToReference();
104
aluebs@webrtc.orgbe05c742014-11-14 22:18:10 +0000105 // Splits the signal into different bands.
106 void SplitIntoFrequencyBands();
107 // Recombine the different bands into one signal.
108 void MergeFrequencyBands();
109
niklase@google.com470e71d2011-07-07 08:21:25 +0000110 private:
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000111 // Called from DeinterleaveFrom() and CopyFrom().
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000112 void InitForNewData();
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000113
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000114 const int input_samples_per_channel_;
115 const int num_input_channels_;
116 const int proc_samples_per_channel_;
117 const int num_proc_channels_;
118 const int output_samples_per_channel_;
119 int samples_per_split_channel_;
aluebs@webrtc.org2561d522014-07-17 08:27:39 +0000120 bool mixed_low_pass_valid_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000121 bool reference_copied_;
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000122 AudioFrame::VADActivity activity_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000123
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000124 const float* keyboard_data_;
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000125 scoped_ptr<IFChannelBuffer> channels_;
aluebs@webrtc.org79b9eba2014-11-26 20:21:38 +0000126 ScopedVector<IFChannelBuffer> split_channels_;
aluebs@webrtc.orgbe05c742014-11-14 22:18:10 +0000127 scoped_ptr<SplittingFilter> splitting_filter_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000128 scoped_ptr<ChannelBuffer<int16_t> > mixed_low_pass_channels_;
129 scoped_ptr<ChannelBuffer<int16_t> > low_pass_reference_channels_;
130 scoped_ptr<ChannelBuffer<float> > input_buffer_;
131 scoped_ptr<ChannelBuffer<float> > process_buffer_;
132 ScopedVector<PushSincResampler> input_resamplers_;
133 ScopedVector<PushSincResampler> output_resamplers_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000134};
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000135
niklase@google.com470e71d2011-07-07 08:21:25 +0000136} // namespace webrtc
137
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000138#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_