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

Unified Diff: webrtc/voice_engine/utility_unittest.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
« webrtc/voice_engine/utility.cc ('K') | « webrtc/voice_engine/utility.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/voice_engine/utility_unittest.cc
diff --git a/webrtc/voice_engine/utility_unittest.cc b/webrtc/voice_engine/utility_unittest.cc
index ecd0baaeb30cc100a770fdc14ce65ecde4a33ca3..317a16dc0366d5d8dce189f5e43f3461536887a4 100644
--- a/webrtc/voice_engine/utility_unittest.cc
+++ b/webrtc/voice_engine/utility_unittest.cc
@@ -74,6 +74,20 @@ void SetStereoFrame(AudioFrame* frame, float left, float right,
}
}
+void SetQuadFrame(AudioFrame* frame, float ch1, float ch2,
+ float ch3, float ch4, int sample_rate_hz) {
aleloi 2017/02/24 10:39:32 Please change param order.
jens.nielsen 2017/02/24 14:55:49 Done.
+ memset(frame->data_, 0, sizeof(frame->data_));
+ frame->num_channels_ = 4;
+ frame->sample_rate_hz_ = sample_rate_hz;
+ frame->samples_per_channel_ = sample_rate_hz / 100;
aleloi 2017/02/24 10:39:32 Please use rtc::CheckedDivExact<int>(sample_rate_h
jens.nielsen 2017/02/24 14:55:49 Done.
+ for (size_t i = 0; i < frame->samples_per_channel_; i++) {
+ frame->data_[i * 4] = static_cast<int16_t>(ch1 * i);
+ frame->data_[i * 4 + 1] = static_cast<int16_t>(ch2 * i);
+ frame->data_[i * 4 + 2] = static_cast<int16_t>(ch3 * i);
+ frame->data_[i * 4 + 3] = static_cast<int16_t>(ch4 * i);
+ }
+}
+
// Keep the existing sample rate.
void SetStereoFrame(AudioFrame* frame, float left, float right) {
SetStereoFrame(frame, left, right, frame->sample_rate_hz_);
@@ -128,30 +142,45 @@ void UtilityTest::RunResampleTest(int src_channels,
int dst_channels,
int dst_sample_rate_hz) {
PushResampler<int16_t> resampler; // Create a new one with every test.
- const int16_t kSrcLeft = 30; // Shouldn't overflow for any used sample rate.
- const int16_t kSrcRight = 15;
+ const int16_t kSrcCh1 = 30; // Shouldn't overflow for any used sample rate.
+ const int16_t kSrcCh2 = 15;
+ const int16_t kSrcCh3 = 22;
+ const int16_t kSrcCh4 = 8;
const float resampling_factor = (1.0 * src_sample_rate_hz) /
dst_sample_rate_hz;
- const float dst_left = resampling_factor * kSrcLeft;
- const float dst_right = resampling_factor * kSrcRight;
- const float dst_mono = (dst_left + dst_right) / 2;
+ const float dst_ch1 = resampling_factor * kSrcCh1;
+ const float dst_ch2 = resampling_factor * kSrcCh2;
+ const float dst_ch3 = resampling_factor * kSrcCh3;
+ const float dst_ch4 = resampling_factor * kSrcCh4;
+ const float dst_stereo_to_mono = (dst_ch1 + dst_ch2) / 2;
+ const float dst_quad_to_mono = (dst_ch1 + dst_ch2 + dst_ch3 + dst_ch4) / 4;
+ const float dst_quad_to_stereo_ch1 = (dst_ch1 + dst_ch2) / 2;
+ const float dst_quad_to_stereo_ch2 = (dst_ch3 + dst_ch4) / 2;
if (src_channels == 1)
- SetMonoFrame(&src_frame_, kSrcLeft, src_sample_rate_hz);
+ SetMonoFrame(&src_frame_, kSrcCh1, src_sample_rate_hz);
+ else if (src_channels == 2)
+ SetStereoFrame(&src_frame_, kSrcCh1, kSrcCh2, src_sample_rate_hz);
else
- SetStereoFrame(&src_frame_, kSrcLeft, kSrcRight, src_sample_rate_hz);
+ SetQuadFrame(&src_frame_, kSrcCh1, kSrcCh2, kSrcCh3, kSrcCh4,
+ src_sample_rate_hz);
if (dst_channels == 1) {
SetMonoFrame(&dst_frame_, 0, dst_sample_rate_hz);
if (src_channels == 1)
- SetMonoFrame(&golden_frame_, dst_left, dst_sample_rate_hz);
+ SetMonoFrame(&golden_frame_, dst_ch1, dst_sample_rate_hz);
+ else if (src_channels == 2)
+ SetMonoFrame(&golden_frame_, dst_stereo_to_mono, dst_sample_rate_hz);
else
- SetMonoFrame(&golden_frame_, dst_mono, dst_sample_rate_hz);
+ SetMonoFrame(&golden_frame_, dst_quad_to_mono, dst_sample_rate_hz);
} else {
SetStereoFrame(&dst_frame_, 0, 0, dst_sample_rate_hz);
if (src_channels == 1)
- SetStereoFrame(&golden_frame_, dst_left, dst_left, dst_sample_rate_hz);
+ SetStereoFrame(&golden_frame_, dst_ch1, dst_ch1, dst_sample_rate_hz);
+ else if (src_channels == 2)
+ SetStereoFrame(&golden_frame_, dst_ch1, dst_ch2, dst_sample_rate_hz);
else
- SetStereoFrame(&golden_frame_, dst_left, dst_right, dst_sample_rate_hz);
+ SetStereoFrame(&golden_frame_, dst_quad_to_stereo_ch1,
+ dst_quad_to_stereo_ch2, dst_sample_rate_hz);
}
// The sinc resampler has a known delay, which we compute here. Multiplying by
@@ -207,14 +236,19 @@ TEST_F(UtilityTest, RemixAndResampleMixingOnlySucceeds) {
TEST_F(UtilityTest, RemixAndResampleSucceeds) {
const int kSampleRates[] = {8000, 16000, 32000, 44100, 48000, 96000};
const int kSampleRatesSize = sizeof(kSampleRates) / sizeof(*kSampleRates);
- const int kChannels[] = {1, 2};
- const int kChannelsSize = sizeof(kChannels) / sizeof(*kChannels);
+ const int kSrcChannels[] = {1, 2, 4};
+ const int kDstChannels[] = {1, 2};
+
for (int src_rate = 0; src_rate < kSampleRatesSize; src_rate++) {
for (int dst_rate = 0; dst_rate < kSampleRatesSize; dst_rate++) {
- for (int src_channel = 0; src_channel < kChannelsSize; src_channel++) {
- for (int dst_channel = 0; dst_channel < kChannelsSize; dst_channel++) {
- RunResampleTest(kChannels[src_channel], kSampleRates[src_rate],
- kChannels[dst_channel], kSampleRates[dst_rate]);
+ for (int src_channel = 0;
+ src_channel < sizeof(kSrcChannels) / sizeof(*kSrcChannels);
hlundin-webrtc 2017/02/24 09:46:36 Use arraysize() from webrtc/base/arraysize.h.
jens.nielsen 2017/02/24 14:55:49 Done.
+ src_channel++) {
+ for (int dst_channel = 0;
+ dst_channel < sizeof(kDstChannels) / sizeof(*kDstChannels);
+ dst_channel++) {
+ RunResampleTest(kSrcChannels[src_channel], kSampleRates[src_rate],
+ kDstChannels[dst_channel], kSampleRates[dst_rate]);
}
}
}
« webrtc/voice_engine/utility.cc ('K') | « webrtc/voice_engine/utility.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698