summaryrefslogtreecommitdiffstats
path: root/media/audio/audio_util_unittest.cc
diff options
context:
space:
mode:
authorfbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-25 03:16:21 +0000
committerfbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-25 03:16:21 +0000
commit9787fec1d6a14f3ca72288d277d3049c2c65b85e (patch)
tree07c5beebcd00439d414831d179cec77d7dfe0c38 /media/audio/audio_util_unittest.cc
parente435d6b7103f0d0c57133121454458bda6ccb69f (diff)
downloadchromium_src-9787fec1d6a14f3ca72288d277d3049c2c65b85e.zip
chromium_src-9787fec1d6a14f3ca72288d277d3049c2c65b85e.tar.gz
chromium_src-9787fec1d6a14f3ca72288d277d3049c2c65b85e.tar.bz2
Surround Sound handling by folding 5 channels down to stereo.
BUG=16026 TEST=play a movie trailer with 5.1 audio. It should sound roughly the same as quicktime. Review URL: http://codereview.chromium.org/155894 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21613 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_util_unittest.cc')
-rw-r--r--media/audio/audio_util_unittest.cc71
1 files changed, 71 insertions, 0 deletions
diff --git a/media/audio/audio_util_unittest.cc b/media/audio/audio_util_unittest.cc
index 415a108..aa5df4c 100644
--- a/media/audio/audio_util_unittest.cc
+++ b/media/audio/audio_util_unittest.cc
@@ -50,6 +50,19 @@ TEST(AudioUtilTest, AdjustVolume_s16_zero) {
EXPECT_EQ(0, expected_test);
}
+TEST(AudioUtilTest, AdjustVolume_s16_one) {
+ // Test AdjustVolume() on 16 bit samples.
+ int16 samples_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
+ int16 expected_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
+ bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16),
+ 2, // channels.
+ sizeof(samples_s16[0]),
+ 1.0f);
+ EXPECT_EQ(true, result_s16);
+ int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16));
+ EXPECT_EQ(0, expected_test);
+}
+
TEST(AudioUtilTest, AdjustVolume_s32) {
// Test AdjustVolume() on 32 bit samples.
int32 samples_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
@@ -63,4 +76,62 @@ TEST(AudioUtilTest, AdjustVolume_s32) {
EXPECT_EQ(0, expected_test);
}
+TEST(AudioUtilTest, FoldChannels_u8) {
+ // Test AdjustVolume() on 16 bit samples.
+ uint8 samples_u8[6] = { 130, 100, 150, 70, 130, 170 };
+ uint8 expected_u8[2] = { 43, 153 };
+ bool result_u8 = media::FoldChannels(samples_u8, sizeof(samples_u8),
+ 6, // channels.
+ sizeof(samples_u8[0]),
+ 1.0f);
+ EXPECT_EQ(true, result_u8);
+ int expected_test = memcmp(samples_u8, expected_u8, sizeof(expected_u8));
+ EXPECT_EQ(0, expected_test);
+}
+
+TEST(AudioUtilTest, FoldChannels_s16) {
+ // Test AdjustVolume() on 16 bit samples.
+ int16 samples_s16[6] = { 12, 1, 3, 7, 13, 17 };
+ int16 expected_s16[2] = { static_cast<int16>(12 * .707 + 1 + 7),
+ static_cast<int16>(12 * .707 + 3 + 13) };
+ bool result_s16 = media::FoldChannels(samples_s16, sizeof(samples_s16),
+ 6, // channels.
+ sizeof(samples_s16[0]),
+ 1.00f);
+ EXPECT_EQ(true, result_s16);
+ int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16));
+ EXPECT_EQ(0, expected_test);
+}
+
+TEST(AudioUtilTest, FoldChannels_s32) {
+ // Test AdjustVolume() on 16 bit samples.
+ int32 samples_s32[6] = { 12, 1, 3, 7, 13, 17 };
+ int32 expected_s32[2] = { static_cast<int16>(12 * .707 + 1 + 7),
+ static_cast<int16>(12 * .707 + 3 + 13) };
+ bool result_s32 = media::FoldChannels(samples_s32, sizeof(samples_s32),
+ 6, // channels.
+ sizeof(samples_s32[0]),
+ 1.00f);
+ EXPECT_EQ(true, result_s32);
+ int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32));
+ EXPECT_EQ(0, expected_test);
+}
+
+// This mimics 1 second of audio at 48000 samples per second.
+// Running the unittest will produce timing.
+TEST(AudioUtilTest, FoldChannels_s16_benchmark) {
+ const int kBufferSize = 1024 * 6;
+ // Test AdjustVolume() on 16 bit samples.
+ for (int i = 0; i < 48000; ++i) {
+ int16 samples_s16[kBufferSize];
+ for (int j = 0; j < kBufferSize; ++j)
+ samples_s16[j] = j;
+
+ bool result_s16 = media::FoldChannels(samples_s16, sizeof(samples_s16),
+ 6, // channels.
+ sizeof(samples_s16[0]),
+ 0.5f);
+ EXPECT_EQ(true, result_s16);
+ }
+}
} // namespace media