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

Unified Diff: webrtc/audio/utility/audio_frame_operations.cc

Issue 2712743004: Support 4 channel mic in Windows Core Audio (Closed)
Patch Set: Fix formatting Created 3 years, 10 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
Index: webrtc/audio/utility/audio_frame_operations.cc
diff --git a/webrtc/audio/utility/audio_frame_operations.cc b/webrtc/audio/utility/audio_frame_operations.cc
index 6fcb84e722d5a07cfcf9d04c90641e4e238464fd..b97d1d3c902d81148c74d71b6b255d769f1975b9 100644
--- a/webrtc/audio/utility/audio_frame_operations.cc
+++ b/webrtc/audio/utility/audio_frame_operations.cc
@@ -114,6 +114,79 @@ int AudioFrameOperations::StereoToMono(AudioFrame* frame) {
return 0;
}
+void AudioFrameOperations::QuadToMono(const int16_t* src_audio,
hlundin-webrtc 2017/02/24 09:46:35 The order of the methods in the .cc file and the .
jens.nielsen 2017/02/24 14:55:48 Done.
+ size_t samples_per_channel,
+ int16_t* dst_audio) {
+ for (size_t i = 0; i < samples_per_channel; i++) {
+ dst_audio[i] = (src_audio[4 * i] + src_audio[4 * i + 1] +
+ src_audio[4 * i + 2] + src_audio[4 * i + 3]) >> 2;
aleloi 2017/02/24 10:39:31 I think this can overflow. If so, can the sum be s
jens.nielsen 2017/02/24 11:11:18 I was too, and was about to fix that here as well
aleloi 2017/02/24 13:32:52 I tried to look it up: http://en.cppreference.com/
jens.nielsen 2017/02/24 14:55:48 Done.
+ }
+}
+
+int AudioFrameOperations::QuadToMono(AudioFrame* frame) {
+ if (frame->num_channels_ != 4) {
+ return -1;
+ }
+
aleloi 2017/02/24 10:39:31 I think this is a good place to RTC_DCHECK_LE that
jens.nielsen 2017/02/24 14:55:48 Done. But the damage is already done here if the b
+ QuadToMono(frame->data_, frame->samples_per_channel_, frame->data_);
+ frame->num_channels_ = 1;
+
+ return 0;
+}
+
+void AudioFrameOperations::QuadToStereo(const int16_t* src_audio,
+ size_t samples_per_channel,
+ int16_t* dst_audio) {
+ for (size_t i = 0; i < samples_per_channel; i++) {
+ dst_audio[i * 2] = (src_audio[4 * i] + src_audio[4 * i + 1]) >> 1;
+ dst_audio[i * 2 + 1] = (src_audio[4 * i + 2] + src_audio[4 * i + 3]) >> 1;
aleloi 2017/02/24 10:39:31 I have concerns for overflows here as well.
jens.nielsen 2017/02/24 14:55:48 Done.
+ }
+}
+
+int AudioFrameOperations::QuadToStereo(AudioFrame* frame) {
+ if (frame->num_channels_ != 4) {
+ return -1;
+ }
+
aleloi 2017/02/24 10:39:31 Please add RTC_DCHECK_LE(samples_per_channel_ * 4
jens.nielsen 2017/02/24 14:55:48 Done.
+ QuadToStereo(frame->data_, frame->samples_per_channel_, frame->data_);
+ frame->num_channels_ = 2;
+
+ return 0;
+}
+
+void AudioFrameOperations::DownmixChannels(const int16_t* src_audio,
+ size_t src_channels,
+ size_t samples_per_channel,
+ int16_t* dst_audio,
+ size_t dst_channels) {
+ if (src_channels == 2 && dst_channels == 1) {
+ StereoToMono(src_audio, samples_per_channel, dst_audio);
+ } else if (src_channels == 4 && dst_channels == 2) {
+ QuadToStereo(src_audio, samples_per_channel, dst_audio);
+ } else if (src_channels == 4 && dst_channels == 1) {
+ QuadToMono(src_audio, samples_per_channel, dst_audio);
+ }
hlundin-webrtc 2017/02/24 09:46:36 I'd like to see some kind of DCHECK that the numbe
jens.nielsen 2017/02/24 14:55:48 Done.
+}
+
+int AudioFrameOperations::DownmixChannels(AudioFrame* frame,
+ size_t dst_channels) {
+ if (frame->num_channels_ >= dst_channels) {
hlundin-webrtc 2017/02/24 09:46:35 This is not needed. You are explicitly testing all
jens.nielsen 2017/02/24 14:55:48 Done.
+ return -1;
+ }
+
+ if (frame->num_channels_ == 2 && dst_channels == 1) {
+ return StereoToMono(frame);
+ } else if (frame->num_channels_ == 4 && dst_channels == 2) {
+ return QuadToStereo(frame);
+ } else if (frame->num_channels_ == 4 && dst_channels == 1) {
+ return QuadToMono(frame);
+ } else {
hlundin-webrtc 2017/02/24 09:46:36 Delete the else statement and simply return -1 unc
jens.nielsen 2017/02/24 14:55:48 Done.
+ return -1;
+ }
+
+ return 0;
+}
+
void AudioFrameOperations::SwapStereoChannels(AudioFrame* frame) {
RTC_DCHECK(frame);
if (frame->num_channels_ != 2) {

Powered by Google App Engine
This is Rietveld 408576698