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

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: Change ProcessStream interface 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
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,
Andrew MacDonald 2015/07/22 22:47:21 Why "multichannel"? To differentiate from the "fra
mgraczyk 2015/07/23 00:16:54 Done.
120 int num_channels,
121 T* deinterleaved) {
122 assert(num_channels > 0);
Andrew MacDonald 2015/07/22 22:47:21 For new code we should use DCHECK.
mgraczyk 2015/07/23 00:16:54 Done.
123 assert(num_multichannel_frames > 0);
124
125 const T* const end = interleaved + num_multichannel_frames * num_channels;
126
127 while (interleaved < end) {
128 const T* const frame_end = interleaved + num_channels;
129
130 Intermediate value = *interleaved++;
131 while (interleaved < frame_end) {
132 value += *interleaved++;
133 }
134
135 *deinterleaved++ = value / num_channels;
136 }
137 }
138
139 template <typename T>
140 void DownmixInterleavedToMono(const T* interleaved,
141 int num_multichannel_frames,
142 int num_channels,
143 T* deinterleaved);
144
145 template <>
146 void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved,
147 int num_multichannel_frames,
148 int num_channels,
149 int16_t* deinterleaved);
150
100 } // namespace webrtc 151 } // namespace webrtc
101 152
102 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ 153 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698