Index: webrtc/audio/utility/audio_frame_operations_unittest.cc |
diff --git a/webrtc/audio/utility/audio_frame_operations_unittest.cc b/webrtc/audio/utility/audio_frame_operations_unittest.cc |
index 36377bd02d8e0db830e7a8353521703908cfc5d1..1babc1ab4a16315e651ea041510f061e5c9f0d1d 100644 |
--- a/webrtc/audio/utility/audio_frame_operations_unittest.cc |
+++ b/webrtc/audio/utility/audio_frame_operations_unittest.cc |
@@ -27,6 +27,16 @@ class AudioFrameOperationsTest : public ::testing::Test { |
AudioFrame frame_; |
}; |
+void SetFrameData(AudioFrame* frame, int16_t ch1, int16_t ch2, |
hlundin-webrtc
2017/02/24 09:46:36
Please, run "git cl format" on your patch.
jens.nielsen
2017/02/24 14:55:49
Done.
|
+ int16_t ch3, int16_t ch4) { |
aleloi
2017/02/24 10:39:32
Please change parameter ordering: input params fir
jens.nielsen
2017/02/24 14:55:49
Done.
|
+ for (size_t i = 0; i < frame->samples_per_channel_ * 4; i += 4) { |
+ frame->data_[i] = ch1; |
+ frame->data_[i + 1] = ch2; |
+ frame->data_[i + 2] = ch3; |
+ frame->data_[i + 3] = ch4; |
+ } |
+} |
+ |
void SetFrameData(AudioFrame* frame, int16_t left, int16_t right) { |
for (size_t i = 0; i < frame->samples_per_channel_ * 2; i += 2) { |
frame->data_[i] = left; |
@@ -145,6 +155,86 @@ TEST_F(AudioFrameOperationsTest, StereoToMonoDoesNotWrapAround) { |
VerifyFramesAreEqual(mono_frame, frame_); |
} |
+TEST_F(AudioFrameOperationsTest, QuadToMonoFailsWithBadParameters) { |
+ frame_.num_channels_ = 1; |
+ EXPECT_EQ(-1, AudioFrameOperations::QuadToMono(&frame_)); |
+ frame_.num_channels_ = 2; |
+ EXPECT_EQ(-1, AudioFrameOperations::QuadToMono(&frame_)); |
+} |
+ |
+TEST_F(AudioFrameOperationsTest, QuadToMonoSucceeds) { |
+ frame_.num_channels_ = 4; |
+ SetFrameData(&frame_, 4, 2, 6, 8); |
+ AudioFrame temp_frame; |
+ temp_frame.CopyFrom(frame_); |
+ EXPECT_EQ(0, AudioFrameOperations::QuadToMono(&frame_)); |
+ |
+ AudioFrame mono_frame; |
+ mono_frame.samples_per_channel_ = 320; |
+ mono_frame.num_channels_ = 1; |
+ SetFrameData(&mono_frame, 5); |
+ VerifyFramesAreEqual(mono_frame, frame_); |
+ |
+ SetFrameData(&frame_, 0); |
hlundin-webrtc
2017/02/24 09:46:36
Let this be a separate TEST_F. This will also avoi
jens.nielsen
2017/02/24 11:11:19
Will do. Should I also change the StereoToMono and
jens.nielsen
2017/02/24 14:55:49
Done.
hlundin-webrtc
2017/02/27 07:52:02
That is up to you. I think you are living by the B
jens.nielsen
2017/02/27 13:28:15
Alright I was reluctant to change too much in one
|
+ AudioFrameOperations::QuadToMono(temp_frame.data_, |
+ frame_.samples_per_channel_, |
+ frame_.data_); |
+ frame_.num_channels_ = 1; // Need to set manually. |
+ VerifyFramesAreEqual(mono_frame, frame_); |
+} |
+ |
+TEST_F(AudioFrameOperationsTest, QuadToMonoDoesNotWrapAround) { |
+ frame_.num_channels_ = 4; |
+ SetFrameData(&frame_, -32768, -32768, -32768, -32768); |
+ EXPECT_EQ(0, AudioFrameOperations::QuadToMono(&frame_)); |
+ |
+ AudioFrame mono_frame; |
+ mono_frame.samples_per_channel_ = 320; |
+ mono_frame.num_channels_ = 1; |
+ SetFrameData(&mono_frame, -32768); |
+ VerifyFramesAreEqual(mono_frame, frame_); |
+} |
+ |
+TEST_F(AudioFrameOperationsTest, QuadToStereoFailsWithBadParameters) { |
+ frame_.num_channels_ = 1; |
+ EXPECT_EQ(-1, AudioFrameOperations::QuadToStereo(&frame_)); |
+ frame_.num_channels_ = 2; |
+ EXPECT_EQ(-1, AudioFrameOperations::QuadToStereo(&frame_)); |
+} |
+ |
+TEST_F(AudioFrameOperationsTest, QuadToStereoSucceeds) { |
+ frame_.num_channels_ = 4; |
+ SetFrameData(&frame_, 4, 2, 6, 8); |
+ AudioFrame temp_frame; |
+ temp_frame.CopyFrom(frame_); |
+ EXPECT_EQ(0, AudioFrameOperations::QuadToStereo(&frame_)); |
+ |
+ AudioFrame stereo_frame; |
+ stereo_frame.samples_per_channel_ = 320; |
+ stereo_frame.num_channels_ = 2; |
+ SetFrameData(&stereo_frame, 3, 7); |
+ VerifyFramesAreEqual(stereo_frame, frame_); |
+ |
+ SetFrameData(&frame_, 0); |
+ AudioFrameOperations::QuadToStereo(temp_frame.data_, |
hlundin-webrtc
2017/02/24 09:46:36
Let this be a separate TEST_F.
jens.nielsen
2017/02/24 14:55:49
Done.
|
+ frame_.samples_per_channel_, |
+ frame_.data_); |
+ frame_.num_channels_ = 2; // Need to set manually. |
+ VerifyFramesAreEqual(stereo_frame, frame_); |
+} |
+ |
+TEST_F(AudioFrameOperationsTest, QuadToStereoDoesNotWrapAround) { |
+ frame_.num_channels_ = 4; |
+ SetFrameData(&frame_, -32768, -32768, -32768, -32768); |
+ EXPECT_EQ(0, AudioFrameOperations::QuadToStereo(&frame_)); |
+ |
+ AudioFrame stereo_frame; |
+ stereo_frame.samples_per_channel_ = 320; |
+ stereo_frame.num_channels_ = 2; |
+ SetFrameData(&stereo_frame, -32768, -32768); |
+ VerifyFramesAreEqual(stereo_frame, frame_); |
+} |
+ |
TEST_F(AudioFrameOperationsTest, SwapStereoChannelsSucceedsOnStereo) { |
SetFrameData(&frame_, 0, 1); |