blob: 45e62a450d70186692a6e301ebf194641a30cec6 [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;
26class SplitChannelBuffer;
27
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;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000057 int16_t* data(int channel) const;
58 int16_t* low_pass_split_data(int channel) const;
59 int16_t* high_pass_split_data(int channel) const;
60 int16_t* mixed_data(int channel) const;
61 int16_t* mixed_low_pass_data(int channel) const;
62 int16_t* low_pass_reference(int channel) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000063
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000064 SplitFilterStates* filter_states(int channel) const;
andrew@webrtc.orged083d42011-09-19 15:28:51 +000065
66 void set_activity(AudioFrame::VADActivity activity);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000067 AudioFrame::VADActivity activity() const;
68
69 bool is_muted() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000070
andrew@webrtc.org17e40642014-03-04 20:58:13 +000071 // Use for int16 interleaved data.
niklase@google.com470e71d2011-07-07 08:21:25 +000072 void DeinterleaveFrom(AudioFrame* audioFrame);
73 void InterleaveTo(AudioFrame* audioFrame) const;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000074 // If |data_changed| is false, only the non-audio data members will be copied
75 // to |frame|.
76 void InterleaveTo(AudioFrame* frame, bool data_changed) const;
andrew@webrtc.org17e40642014-03-04 20:58:13 +000077
78 // Use for float deinterleaved data.
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000079 void CopyFrom(const float* const* data,
80 int samples_per_channel,
81 AudioProcessing::ChannelLayout layout);
82 void CopyTo(int samples_per_channel,
83 AudioProcessing::ChannelLayout layout,
84 float* const* data);
andrew@webrtc.org17e40642014-03-04 20:58:13 +000085
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000086 void CopyAndMix(int num_mixed_channels);
andrew@webrtc.orged083d42011-09-19 15:28:51 +000087 void CopyAndMixLowPass(int num_mixed_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +000088 void CopyLowPassToReference();
89
90 private:
andrew@webrtc.org17e40642014-03-04 20:58:13 +000091 // Called from DeinterleaveFrom() and CopyFrom().
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000092 void InitForNewData();
andrew@webrtc.org17e40642014-03-04 20:58:13 +000093
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000094 const int input_samples_per_channel_;
95 const int num_input_channels_;
96 const int proc_samples_per_channel_;
97 const int num_proc_channels_;
98 const int output_samples_per_channel_;
99 int samples_per_split_channel_;
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000100 int num_mixed_channels_;
101 int num_mixed_low_pass_channels_;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000102 // Whether the original data was replaced with mixed data.
103 bool data_was_mixed_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000104 bool reference_copied_;
andrew@webrtc.orged083d42011-09-19 15:28:51 +0000105 AudioFrame::VADActivity activity_;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000106 bool is_muted_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000108 int16_t* data_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000109 scoped_ptr<ChannelBuffer<int16_t> > channels_;
110 scoped_ptr<SplitChannelBuffer> split_channels_;
111 scoped_ptr<SplitFilterStates[]> filter_states_;
112 scoped_ptr<ChannelBuffer<int16_t> > mixed_channels_;
113 scoped_ptr<ChannelBuffer<int16_t> > mixed_low_pass_channels_;
114 scoped_ptr<ChannelBuffer<int16_t> > low_pass_reference_channels_;
115 scoped_ptr<ChannelBuffer<float> > input_buffer_;
116 scoped_ptr<ChannelBuffer<float> > process_buffer_;
117 ScopedVector<PushSincResampler> input_resamplers_;
118 ScopedVector<PushSincResampler> output_resamplers_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000119};
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000120
niklase@google.com470e71d2011-07-07 08:21:25 +0000121} // namespace webrtc
122
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000123#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_