Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: webrtc/common_audio/include/audio_util.h

Issue 1226093007: Allow more than 2 input channels in AudioProcessing. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Reupload Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/common_audio/audio_util_unittest.cc ('k') | webrtc/common_audio/wav_file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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
11 #ifndef WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ 11 #ifndef WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
12 #define WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ 12 #define WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
13 13
14 #include <limits> 14 #include <limits>
15 #include <cstring>
15 16
16 #include "webrtc/base/scoped_ptr.h" 17 #include "webrtc/base/scoped_ptr.h"
17 #include "webrtc/typedefs.h" 18 #include "webrtc/typedefs.h"
18 19
19 namespace webrtc { 20 namespace webrtc {
20 21
21 typedef std::numeric_limits<int16_t> limits_int16; 22 typedef std::numeric_limits<int16_t> limits_int16;
22 23
23 // The conversion functions use the following naming convention: 24 // The conversion functions use the following naming convention:
24 // S16: int16_t [-32768, 32767] 25 // S16: int16_t [-32768, 32767]
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 for (int i = 0; i < num_channels; ++i) { 91 for (int i = 0; i < num_channels; ++i) {
91 const T* channel = deinterleaved[i]; 92 const T* channel = deinterleaved[i];
92 int interleaved_idx = i; 93 int interleaved_idx = i;
93 for (int j = 0; j < samples_per_channel; ++j) { 94 for (int j = 0; j < samples_per_channel; ++j) {
94 interleaved[interleaved_idx] = channel[j]; 95 interleaved[interleaved_idx] = channel[j];
95 interleaved_idx += num_channels; 96 interleaved_idx += num_channels;
96 } 97 }
97 } 98 }
98 } 99 }
99 100
101 template <typename T, typename Intermediate>
102 void DownmixToMono(const T* const* input_channels,
103 int num_frames,
104 int num_channels,
105 T* out) {
106 for (int i = 0; i < num_frames; ++i) {
107 Intermediate value = input_channels[0][i];
108 for (int j = 1; j < num_channels; ++j) {
109 value += input_channels[j][i];
110 }
111 out[i] = value / num_channels;
112 }
113 }
114
115 // Downmixes an interleaved multichannel signal to a single channel by averaging
116 // all channels.
117 template <typename T, typename Intermediate>
118 void DownmixInterleavedToMonoImpl(const T* interleaved,
119 int num_multichannel_frames,
120 int num_channels,
121 T* deinterleaved) {
122 assert(num_channels > 0);
123 assert(num_multichannel_frames > 0);
124
125 const T* const end = interleaved + num_multichannel_frames * num_channels;
126
127 if (num_channels == 1) {
128 std::memmove(deinterleaved, interleaved,
129 num_multichannel_frames * sizeof(*deinterleaved));
130 } else if (num_channels == 2) {
131 // Explicitly unroll for the common stereo case.
132 while (interleaved < end) {
133 *deinterleaved++ =
134 (static_cast<Intermediate>(*interleaved) + *(interleaved + 1)) / 2;
135 interleaved += 2;
136 }
137 } else {
138 while (interleaved < end) {
139 const T* const frame_end = interleaved + num_channels;
140
141 Intermediate value = *interleaved++;
142 while (interleaved < frame_end) {
143 value += *interleaved++;
144 }
145
146 *deinterleaved++ = value / num_channels;
147 }
148 }
149 }
150
151 template <typename T>
152 void DownmixInterleavedToMono(const T* interleaved,
153 int num_multichannel_frames,
154 int num_channels,
155 T* deinterleaved);
aluebs-webrtc 2015/07/15 21:29:17 I don't see what this declaration (with no definit
mgraczyk 2015/07/15 21:53:56 This is the template declaration for DownmixInterl
aluebs-webrtc 2015/07/16 00:20:52 Oh, you are right. Thanks for clarifying!
156
157 template <>
158 void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved,
159 int num_multichannel_frames,
160 int num_channels,
161 int16_t* deinterleaved);
162
100 } // namespace webrtc 163 } // namespace webrtc
101 164
102 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ 165 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
OLDNEW
« no previous file with comments | « webrtc/common_audio/audio_util_unittest.cc ('k') | webrtc/common_audio/wav_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698