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

Unified Diff: media/audio/audio_util_unittest.cc

Issue 9641026: Add software audio mixing to the audio utils. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 9 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
« media/audio/audio_util.cc ('K') | « media/audio/audio_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_util_unittest.cc
===================================================================
--- media/audio/audio_util_unittest.cc (revision 125439)
+++ media/audio/audio_util_unittest.cc (working copy)
@@ -79,6 +79,75 @@
EXPECT_EQ(0, expected_test);
}
+TEST(AudioUtilTest, MixStreams_u8) {
+ // Test MixStreams() on 8 bit samples.
+ uint8 dst_u8[kNumberOfSamples] = { 44, 0x44, 0x80, 0xff };
+ uint8 src_u8[kNumberOfSamples] = { 4, 0x40, 0x80, 0xff };
+ uint8 expected_u8[kNumberOfSamples] = { 0, /* saturation */
+ (0x44 - 128) + (0x40 - 128) / 2 + 128,
+ (0x80 - 128) + (0x80 - 128) / 2 + 128,
+ 0xff /* saturation */ };
+ media::MixStreams(dst_u8, src_u8, sizeof(dst_u8), sizeof(src_u8[0]), 0.5f);
vrk (LEFT CHROMIUM) 2012/03/12 18:40:24 It looks like you are adjusting the volume in most
enal1 2012/03/12 21:20:53 Added missing test and changed u8 test. Now we tes
vrk (LEFT CHROMIUM) 2012/03/20 00:27:53 Thanks enal! Can you do the name change as well? (
+ int expected_test = memcmp(dst_u8, expected_u8, sizeof(expected_u8));
+ EXPECT_EQ(0, expected_test);
+}
+
+TEST(AudioUtilTest, MixStreams_s16) {
+ // Test MixStreams() on 16 bit samples.
+ int16 dst_s16[kNumberOfSamples] = { -4, 0x40, -32760, 32760 };
+ int16 src_s16[kNumberOfSamples] = { -4, 0x40, -123, 123 };
+ int16 expected_s16[kNumberOfSamples] = { -5, 0x50, -32768, 32767 };
+ media::MixStreams(dst_s16,
+ src_s16,
+ sizeof(dst_s16),
+ sizeof(src_s16[0]),
+ 0.25f);
+ int expected_test = memcmp(dst_s16, expected_s16, sizeof(expected_s16));
+ EXPECT_EQ(0, expected_test);
+}
+
+TEST(AudioUtilTest, MixStreams_s16_one) {
+ // Test MixStreams() on 16 bit samples.
+ int16 dst_s16[kNumberOfSamples] = { -4, 0x40, -32760, 32760 };
+ int16 src_s16[kNumberOfSamples] = { -4, 0x40, -123, 123 };
+ int16 expected_s16[kNumberOfSamples] = { -8, 0x80, -32768, 32767 };
+ media::MixStreams(dst_s16,
+ src_s16,
+ sizeof(dst_s16),
+ sizeof(src_s16[0]),
+ 1.0f);
+ int expected_test = memcmp(dst_s16, expected_s16, sizeof(expected_s16));
+ EXPECT_EQ(0, expected_test);
+}
+
+TEST(AudioUtilTest, MixStreams_s32) {
+ // Test MixStreams() on 32 bit samples.
+ int32 dst_s32[kNumberOfSamples] = { -4, 0x40, -32768, 2147483640 };
+ int32 src_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
+ int32 expected_s32[kNumberOfSamples] = { -5, 0x50, -40960, 2147483647 };
+ media::MixStreams(dst_s32,
+ src_s32,
+ sizeof(dst_s32),
+ sizeof(src_s32[0]),
+ 0.25f);
+ int expected_test = memcmp(dst_s32, expected_s32, sizeof(expected_s32));
+ EXPECT_EQ(0, expected_test);
+}
+
+TEST(AudioUtilTest, MixStreams_s32_one) {
+ // Test MixStreams() on 32 bit samples.
+ int32 dst_s32[kNumberOfSamples] = { -4, 0x40, -32768, 2147483640 };
+ int32 src_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
+ int32 expected_s32[kNumberOfSamples] = { -8, 0x80, -65536, 2147483647 };
+ media::MixStreams(dst_s32,
+ src_s32,
+ sizeof(dst_s32),
+ sizeof(src_s32[0]),
+ 1.0);
+ int expected_test = memcmp(dst_s32, expected_s32, sizeof(expected_s32));
+ EXPECT_EQ(0, expected_test);
+}
+
TEST(AudioUtilTest, FoldChannels_u8) {
// Test FoldChannels() on 8 bit samples.
uint8 samples_u8[6] = { 100, 150, 130, 70, 130, 170 };
« media/audio/audio_util.cc ('K') | « media/audio/audio_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698