blob: 5c26ae29d0b821a8d46e191da672a9091e0ee2ae [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
16#include "webrtc/modules/audio_processing/common.h"
17#include "webrtc/modules/audio_processing/include/audio_processing.h"
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000018#include "webrtc/modules/interface/module_common_types.h"
19#include "webrtc/system_wrappers/interface/scoped_ptr.h"
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000020#include "webrtc/system_wrappers/interface/scoped_vector.h"
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000021#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
niklase@google.com470e71d2011-07-07 08:21:25 +000023namespace webrtc {
24
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000025class PushSincResampler;
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +000026class IFChannelBuffer;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000027
28struct SplitFilterStates {
29 SplitFilterStates() {
30 memset(analysis_filter_state1, 0, sizeof(analysis_filter_state1));
31 memset(analysis_filter_state2, 0, sizeof(analysis_filter_state2));
32 memset(synthesis_filter_state1, 0, sizeof(synthesis_filter_state1));
33 memset(synthesis_filter_state2, 0, sizeof(synthesis_filter_state2));
34 }
35
36 static const int kStateSize = 6;
37 int analysis_filter_state1[kStateSize];
38 int analysis_filter_state2[kStateSize];
39 int synthesis_filter_state1[kStateSize];
40 int synthesis_filter_state2[kStateSize];
41};
niklase@google.com470e71d2011-07-07 08:21:25 +000042
43class AudioBuffer {
44 public:
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000045 // TODO(ajm): Switch to take ChannelLayouts.
46 AudioBuffer(int input_samples_per_channel,
47 int num_input_channels,
48 int process_samples_per_channel,
49 int num_process_channels,
50 int output_samples_per_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +000051 virtual ~AudioBuffer();
52
andrew@webrtc.orged083d42011-09-19 15:28:51 +000053 int num_channels() const;
54 int samples_per_channel() const;
55 int samples_per_split_channel() const;
andrew@webrtc.org103657b2014-04-24 18:28:56 +000056 int samples_per_keyboard_channel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000057
aluebs@webrtc.orgfb2e7c22014-07-11 11:40:48 +000058 // It can be assumed that channels are stored contiguously.
andrew@webrtc.org65f93382014-04-30 16:44:13 +000059 int16_t* data(int channel);
60 const int16_t* data(int channel) const;
61 int16_t* low_pass_split_data(int channel);
62 const int16_t* low_pass_split_data(int channel) const;
63 int16_t* high_pass_split_data(int channel);
64 const int16_t* high_pass_split_data(int channel) const;
aluebs@webrtc.org2561d522014-07-17 08:27:39 +000065 // Returns a pointer to the low-pass data downmixed to mono. If this data
66 // isn't already available it re-calculates it.
67 const int16_t* mixed_low_pass_data();
andrew@webrtc.org65f93382014-04-30 16:44:13 +000068 const int16_t* low_pass_reference(int channel) const;
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +000069
70 // Float versions of the accessors, with automatic conversion back and forth
71 // as necessary. The range of the numbers are the same as for int16_t.
72 float* data_f(int channel);
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +000073 const float* data_f(int channel) const;
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +000074 float* low_pass_split_data_f(int channel);
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +000075 const float* low_pass_split_data_f(int channel) const;
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +000076 float* high_pass_split_data_f(int channel);
kwiberg@webrtc.org38214d52014-07-03 09:47:33 +000077 const float* high_pass_split_data_f(int channel) const;
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +000078
andrew@webrtc.org103657b2014-04-24 18:28:56 +000079 const float* keyboard_data() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
andrew@webrtc.org65f93382014-04-30 16:44:13 +000081 SplitFilterStates* filter_states(int channel);
andrew@webrtc.orged083d42011-09-19 15:28:51 +000082
83 void set_activity(AudioFrame::VADActivity activity);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000084 AudioFrame::VADActivity activity() const;
85
andrew@webrtc.org17e40642014-03-04 20:58:13 +000086 // Use for int16 interleaved data.
niklase@google.com470e71d2011-07-07 08:21:25 +000087 void DeinterleaveFrom(AudioFrame* audioFrame);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000088 // If |data_changed| is false, only the non-audio data members will be copied
89 // to |frame|.
90 void InterleaveTo(AudioFrame* frame, bool data_changed) const;
andrew@webrtc.org17e40642014-03-04 20:58:13 +000091
92 // Use for float deinterleaved data.
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000093 void CopyFrom(const float* const* data,
94 int samples_per_channel,
95 AudioProcessing::ChannelLayout layout);
96 void CopyTo(int samples_per_channel,
97 AudioProcessing::ChannelLayout layout,
98 float* const* data);
niklase@google.com470e71d2011-07-07 08:21:25 +000099 void CopyLowPassToReference();
100
101 private:
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000102 // Called from DeinterleaveFrom() and CopyFrom().
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000103 void InitForNewData();
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000104
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000105 const int input_samples_per_channel_;
106 const int num_input_channels_;
107 const int proc_samples_per_channel_;
108 const int num_proc_channels_;
109 const int output_samples_per_channel_;
110 int samples_per_split_channel_;
aluebs@webrtc.org2561d522014-07-17 08:27:39 +0000111 bool mixed_low_pass_valid_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112 bool reference_copied_;
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000113 AudioFrame::VADActivity activity_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000115 const float* keyboard_data_;
mflodman@webrtc.orgd5da2502014-05-15 11:17:21 +0000116 scoped_ptr<IFChannelBuffer> channels_;
kwiberg@webrtc.org2b6bc8d2014-07-17 09:46:37 +0000117 scoped_ptr<IFChannelBuffer> split_channels_low_;
118 scoped_ptr<IFChannelBuffer> split_channels_high_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000119 scoped_ptr<SplitFilterStates[]> filter_states_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000120 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.com470e71d2011-07-07 08:21:25 +0000126};
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000127
niklase@google.com470e71d2011-07-07 08:21:25 +0000128} // namespace webrtc
129
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000130#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_