OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... | |
23 | 23 |
24 class PushSincResampler; | 24 class PushSincResampler; |
25 class IFChannelBuffer; | 25 class IFChannelBuffer; |
26 | 26 |
27 enum Band { | 27 enum Band { |
28 kBand0To8kHz = 0, | 28 kBand0To8kHz = 0, |
29 kBand8To16kHz = 1, | 29 kBand8To16kHz = 1, |
30 kBand16To24kHz = 2 | 30 kBand16To24kHz = 2 |
31 }; | 31 }; |
32 | 32 |
33 template <typename T, typename Intermediate> | |
aluebs-webrtc
2015/07/14 23:12:43
What do you think about adding these to audio_util
mgraczyk
2015/07/15 01:12:46
Done.
| |
34 void DownmixStereoToMono(int num_frames, | |
aluebs-webrtc
2015/07/14 23:12:42
Is it worth it to specialize for the stereo case?
mgraczyk
2015/07/15 01:12:46
Probably, although I didn't benchmark it. I figure
aluebs-webrtc
2015/07/15 18:04:05
Yes, common, but do you gain anything? It definiti
mgraczyk
2015/07/15 20:03:19
The if statement is basically free because it's at
| |
35 T* out, | |
36 const T* left, | |
37 const T* right) { | |
aluebs-webrtc
2015/07/14 23:12:42
Inputs before outputs?
mgraczyk
2015/07/15 01:12:46
Done.
| |
38 for (int i = 0; i < num_frames; ++i) { | |
39 out[i] = (static_cast<Intermediate>(left[i]) + right[i]) / 2; | |
40 } | |
41 } | |
42 | |
43 template <typename T, typename Intermediate> | |
44 void DownmixToMono(int num_frames, | |
45 T* out, | |
46 const T* const* input_channels, | |
47 int num_channels) { | |
aluebs-webrtc
2015/07/14 23:12:42
Inputs before outputs?
mgraczyk
2015/07/15 01:12:46
Done.
| |
48 if (num_channels == 2) { | |
49 DownmixStereoToMono<T, Intermediate>(num_frames, out, input_channels[0], | |
50 input_channels[1]); | |
51 } else { | |
52 for (int i = 0; i < num_frames; ++i) { | |
53 Intermediate value = input_channels[0][i]; | |
54 for (int j = 1; j < num_channels; ++j) { | |
55 value += input_channels[j][i]; | |
56 } | |
57 out[i] = value / num_channels; | |
58 } | |
59 } | |
60 } | |
61 | |
62 // Downmixes an interleaved multichannel signal to a single channel by averaging | |
63 // all channels. | |
64 template <typename T, typename Intermediate> | |
65 void DownmixInterleavedToMonoImpl(const T* interleaved, | |
66 T* deinterleaved, | |
67 int num_multichannel_frames, | |
68 int num_channels) { | |
aluebs-webrtc
2015/07/14 23:12:43
Inputs before outputs?
mgraczyk
2015/07/15 01:12:46
Done.
| |
69 assert(num_channels > 0); | |
70 assert(num_multichannel_frames > 0); | |
71 | |
72 const T* const end = interleaved + num_multichannel_frames * num_channels; | |
73 | |
74 if (num_channels == 1) { | |
75 std::memmove( | |
76 deinterleaved, interleaved, | |
77 num_channels * num_multichannel_frames * sizeof(*deinterleaved)); | |
aluebs-webrtc
2015/07/14 23:12:42
You don't need to multiply by num_channels since y
mgraczyk
2015/07/15 01:12:46
Done.
| |
78 } else if (num_channels == 2) { | |
aluebs-webrtc
2015/07/14 23:12:42
Is it worth it to specialize for the stereo case?
mgraczyk
2015/07/15 01:12:46
Same answer, although here the savings is not goin
aluebs-webrtc
2015/07/15 21:29:16
So, should this be removed as well following the s
mgraczyk
2015/07/15 21:53:55
Done.
| |
79 // Explicitly unroll for the common stereo case. | |
80 while (interleaved < end) { | |
81 *deinterleaved++ = | |
82 (static_cast<Intermediate>(*interleaved) + *(interleaved + 1)) / 2; | |
83 interleaved += 2; | |
84 } | |
85 } else { | |
86 while (interleaved < end) { | |
aluebs-webrtc
2015/07/14 23:12:43
I find for with indexes easier to follow, but I le
mgraczyk
2015/07/15 01:12:46
Acknowledged.
| |
87 const T* const frame_end = interleaved + num_channels; | |
88 | |
89 Intermediate value = *interleaved++; | |
90 while (interleaved < frame_end) { | |
91 value += *interleaved++; | |
92 } | |
93 | |
94 *deinterleaved++ = value / num_channels; | |
95 } | |
96 } | |
97 } | |
98 | |
33 class AudioBuffer { | 99 class AudioBuffer { |
34 public: | 100 public: |
35 // TODO(ajm): Switch to take ChannelLayouts. | 101 // TODO(ajm): Switch to take ChannelLayouts. |
36 AudioBuffer(int input_num_frames, | 102 AudioBuffer(int input_num_frames, |
37 int num_input_channels, | 103 int num_input_channels, |
38 int process_num_frames, | 104 int process_num_frames, |
39 int num_process_channels, | 105 int num_process_channels, |
40 int output_num_frames); | 106 int output_num_frames); |
41 virtual ~AudioBuffer(); | 107 virtual ~AudioBuffer(); |
42 | 108 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 void set_activity(AudioFrame::VADActivity activity); | 171 void set_activity(AudioFrame::VADActivity activity); |
106 AudioFrame::VADActivity activity() const; | 172 AudioFrame::VADActivity activity() const; |
107 | 173 |
108 // Use for int16 interleaved data. | 174 // Use for int16 interleaved data. |
109 void DeinterleaveFrom(AudioFrame* audioFrame); | 175 void DeinterleaveFrom(AudioFrame* audioFrame); |
110 // If |data_changed| is false, only the non-audio data members will be copied | 176 // If |data_changed| is false, only the non-audio data members will be copied |
111 // to |frame|. | 177 // to |frame|. |
112 void InterleaveTo(AudioFrame* frame, bool data_changed) const; | 178 void InterleaveTo(AudioFrame* frame, bool data_changed) const; |
113 | 179 |
114 // Use for float deinterleaved data. | 180 // Use for float deinterleaved data. |
115 void CopyFrom(const float* const* data, | 181 void CopyFrom(const float* const* data, const StreamConfig& stream_config); |
116 int num_frames, | 182 void CopyTo(const StreamConfig& stream_config, float* const* data); |
117 AudioProcessing::ChannelLayout layout); | |
118 void CopyTo(int num_frames, | |
119 AudioProcessing::ChannelLayout layout, | |
120 float* const* data); | |
121 void CopyLowPassToReference(); | 183 void CopyLowPassToReference(); |
122 | 184 |
123 // Splits the signal into different bands. | 185 // Splits the signal into different bands. |
124 void SplitIntoFrequencyBands(); | 186 void SplitIntoFrequencyBands(); |
125 // Recombine the different bands into one signal. | 187 // Recombine the different bands into one signal. |
126 void MergeFrequencyBands(); | 188 void MergeFrequencyBands(); |
127 | 189 |
128 private: | 190 private: |
129 // Called from DeinterleaveFrom() and CopyFrom(). | 191 // Called from DeinterleaveFrom() and CopyFrom(). |
130 void InitForNewData(); | 192 void InitForNewData(); |
(...skipping 26 matching lines...) Expand all Loading... | |
157 rtc::scoped_ptr<ChannelBuffer<int16_t> > low_pass_reference_channels_; | 219 rtc::scoped_ptr<ChannelBuffer<int16_t> > low_pass_reference_channels_; |
158 rtc::scoped_ptr<IFChannelBuffer> input_buffer_; | 220 rtc::scoped_ptr<IFChannelBuffer> input_buffer_; |
159 rtc::scoped_ptr<ChannelBuffer<float> > process_buffer_; | 221 rtc::scoped_ptr<ChannelBuffer<float> > process_buffer_; |
160 ScopedVector<PushSincResampler> input_resamplers_; | 222 ScopedVector<PushSincResampler> input_resamplers_; |
161 ScopedVector<PushSincResampler> output_resamplers_; | 223 ScopedVector<PushSincResampler> output_resamplers_; |
162 }; | 224 }; |
163 | 225 |
164 } // namespace webrtc | 226 } // namespace webrtc |
165 | 227 |
166 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_ | 228 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_ |
OLD | NEW |