blob: c05ffc90bfbc3ffb2544270fa0db72a526d4ca8b [file] [log] [blame]
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +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.org2e244602014-04-22 21:00:04 +000011#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_
12#define WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000013
andrew@webrtc.org2e244602014-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.org382c8b32013-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.org2e244602014-04-22 21:00:04 +000020#include "webrtc/system_wrappers/interface/scoped_vector.h"
pbos@webrtc.org382c8b32013-05-28 08:11:59 +000021#include "webrtc/typedefs.h"
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000022
23namespace webrtc {
24
andrew@webrtc.org2e244602014-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};
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000042
43class AudioBuffer {
44 public:
andrew@webrtc.org2e244602014-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);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000051 virtual ~AudioBuffer();
52
53 int num_channels() const;
54 int samples_per_channel() const;
55 int samples_per_split_channel() const;
andrew@webrtc.orgfbf25682014-04-24 18:28:56 +000056 int samples_per_keyboard_channel() const;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000057
andrew@webrtc.orgc2e64382014-04-30 16:44:13 +000058 int16_t* data(int channel);
59 const int16_t* data(int channel) const;
60 int16_t* low_pass_split_data(int channel);
61 const int16_t* low_pass_split_data(int channel) const;
62 int16_t* high_pass_split_data(int channel);
63 const int16_t* high_pass_split_data(int channel) const;
64 const int16_t* mixed_data(int channel) const;
65 const int16_t* mixed_low_pass_data(int channel) const;
66 const int16_t* low_pass_reference(int channel) const;
andrew@webrtc.orgfbf25682014-04-24 18:28:56 +000067 const float* keyboard_data() const;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000068
andrew@webrtc.orgc2e64382014-04-30 16:44:13 +000069 SplitFilterStates* filter_states(int channel);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000070
71 void set_activity(AudioFrame::VADActivity activity);
72 AudioFrame::VADActivity activity() const;
73
andrew@webrtc.org3c5112c2014-03-04 20:58:13 +000074 // Use for int16 interleaved data.
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000075 void DeinterleaveFrom(AudioFrame* audioFrame);
76 void InterleaveTo(AudioFrame* audioFrame) const;
77 // If |data_changed| is false, only the non-audio data members will be copied
78 // to |frame|.
79 void InterleaveTo(AudioFrame* frame, bool data_changed) const;
andrew@webrtc.org3c5112c2014-03-04 20:58:13 +000080
81 // Use for float deinterleaved data.
andrew@webrtc.org2e244602014-04-22 21:00:04 +000082 void CopyFrom(const float* const* data,
83 int samples_per_channel,
84 AudioProcessing::ChannelLayout layout);
85 void CopyTo(int samples_per_channel,
86 AudioProcessing::ChannelLayout layout,
87 float* const* data);
andrew@webrtc.org3c5112c2014-03-04 20:58:13 +000088
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000089 void CopyAndMix(int num_mixed_channels);
90 void CopyAndMixLowPass(int num_mixed_channels);
91 void CopyLowPassToReference();
92
93 private:
andrew@webrtc.org3c5112c2014-03-04 20:58:13 +000094 // Called from DeinterleaveFrom() and CopyFrom().
andrew@webrtc.org2e244602014-04-22 21:00:04 +000095 void InitForNewData();
andrew@webrtc.org3c5112c2014-03-04 20:58:13 +000096
andrew@webrtc.org2e244602014-04-22 21:00:04 +000097 const int input_samples_per_channel_;
98 const int num_input_channels_;
99 const int proc_samples_per_channel_;
100 const int num_proc_channels_;
101 const int output_samples_per_channel_;
102 int samples_per_split_channel_;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000103 int num_mixed_channels_;
104 int num_mixed_low_pass_channels_;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000105 bool reference_copied_;
106 AudioFrame::VADActivity activity_;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000107
kwiberg@webrtc.org8b4f5392014-05-08 07:10:11 +0000108 // If non-null, use this instead of channels_->channel(0). This is an
109 // optimization for the case num_proc_channels_ == 1 that allows us to point
110 // to the data instead of copying it.
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000111 int16_t* data_;
kwiberg@webrtc.org8b4f5392014-05-08 07:10:11 +0000112
andrew@webrtc.orgfbf25682014-04-24 18:28:56 +0000113 const float* keyboard_data_;
mflodman@webrtc.org409cf2a2014-05-14 09:39:56 +0000114 scoped_ptr<ChannelBuffer<int16_t> > channels_;
andrew@webrtc.org2e244602014-04-22 21:00:04 +0000115 scoped_ptr<SplitChannelBuffer> split_channels_;
116 scoped_ptr<SplitFilterStates[]> filter_states_;
117 scoped_ptr<ChannelBuffer<int16_t> > mixed_channels_;
118 scoped_ptr<ChannelBuffer<int16_t> > mixed_low_pass_channels_;
119 scoped_ptr<ChannelBuffer<int16_t> > low_pass_reference_channels_;
120 scoped_ptr<ChannelBuffer<float> > input_buffer_;
121 scoped_ptr<ChannelBuffer<float> > process_buffer_;
122 ScopedVector<PushSincResampler> input_resamplers_;
123 ScopedVector<PushSincResampler> output_resamplers_;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000124};
andrew@webrtc.org2e244602014-04-22 21:00:04 +0000125
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000126} // namespace webrtc
127
andrew@webrtc.org2e244602014-04-22 21:00:04 +0000128#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_