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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_audio/include/audio_util.h
diff --git a/webrtc/common_audio/include/audio_util.h b/webrtc/common_audio/include/audio_util.h
index 8262649145546180f23b6e82094d324b7f604e7f..f1c2490544cf2c3c8661bd636ad5e26bd166d1bf 100644
--- a/webrtc/common_audio/include/audio_util.h
+++ b/webrtc/common_audio/include/audio_util.h
@@ -12,6 +12,7 @@
#define WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
#include <limits>
+#include <cstring>
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/typedefs.h"
@@ -97,6 +98,68 @@ void Interleave(const T* const* deinterleaved, int samples_per_channel,
}
}
+template <typename T, typename Intermediate>
+void DownmixToMono(const T* const* input_channels,
+ int num_frames,
+ int num_channels,
+ T* out) {
+ for (int i = 0; i < num_frames; ++i) {
+ Intermediate value = input_channels[0][i];
+ for (int j = 1; j < num_channels; ++j) {
+ value += input_channels[j][i];
+ }
+ out[i] = value / num_channels;
+ }
+}
+
+// Downmixes an interleaved multichannel signal to a single channel by averaging
+// all channels.
+template <typename T, typename Intermediate>
+void DownmixInterleavedToMonoImpl(const T* interleaved,
+ int num_multichannel_frames,
+ int num_channels,
+ T* deinterleaved) {
+ assert(num_channels > 0);
+ assert(num_multichannel_frames > 0);
+
+ const T* const end = interleaved + num_multichannel_frames * num_channels;
+
+ if (num_channels == 1) {
+ std::memmove(deinterleaved, interleaved,
+ num_multichannel_frames * sizeof(*deinterleaved));
+ } else if (num_channels == 2) {
+ // Explicitly unroll for the common stereo case.
+ while (interleaved < end) {
+ *deinterleaved++ =
+ (static_cast<Intermediate>(*interleaved) + *(interleaved + 1)) / 2;
+ interleaved += 2;
+ }
+ } else {
+ while (interleaved < end) {
+ const T* const frame_end = interleaved + num_channels;
+
+ Intermediate value = *interleaved++;
+ while (interleaved < frame_end) {
+ value += *interleaved++;
+ }
+
+ *deinterleaved++ = value / num_channels;
+ }
+ }
+}
+
+template <typename T>
+void DownmixInterleavedToMono(const T* interleaved,
+ int num_multichannel_frames,
+ int num_channels,
+ 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!
+
+template <>
+void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved,
+ int num_multichannel_frames,
+ int num_channels,
+ int16_t* deinterleaved);
+
} // namespace webrtc
#endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
« 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