Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "media/audio/audio_util.h" | 6 #include "media/audio/audio_util.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 // Number of samples in each audio array. | 9 // Number of samples in each audio array. |
| 10 static const size_t kNumberOfSamples = 4; | 10 static const size_t kNumberOfSamples = 4; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 int32 expected_s32[kNumberOfSamples] = { -1, 0x10, -8192, 30 }; | 72 int32 expected_s32[kNumberOfSamples] = { -1, 0x10, -8192, 30 }; |
| 73 bool result_s32 = media::AdjustVolume(samples_s32, sizeof(samples_s32), | 73 bool result_s32 = media::AdjustVolume(samples_s32, sizeof(samples_s32), |
| 74 4, // channels. | 74 4, // channels. |
| 75 sizeof(samples_s32[0]), | 75 sizeof(samples_s32[0]), |
| 76 0.25f); | 76 0.25f); |
| 77 EXPECT_TRUE(result_s32); | 77 EXPECT_TRUE(result_s32); |
| 78 int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32)); | 78 int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32)); |
| 79 EXPECT_EQ(0, expected_test); | 79 EXPECT_EQ(0, expected_test); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST(AudioUtilTest, MixStreams_u8) { | |
| 83 // Test MixStreams() on 8 bit samples. | |
| 84 uint8 dst_u8[kNumberOfSamples] = { 44, 0x44, 0x80, 0xff }; | |
| 85 uint8 src_u8[kNumberOfSamples] = { 4, 0x40, 0x80, 0xff }; | |
| 86 uint8 expected_u8[kNumberOfSamples] = { 0, /* saturation */ | |
| 87 (0x44 - 128) + (0x40 - 128) / 2 + 128, | |
| 88 (0x80 - 128) + (0x80 - 128) / 2 + 128, | |
| 89 0xff /* saturation */ }; | |
| 90 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? (
| |
| 91 int expected_test = memcmp(dst_u8, expected_u8, sizeof(expected_u8)); | |
| 92 EXPECT_EQ(0, expected_test); | |
| 93 } | |
| 94 | |
| 95 TEST(AudioUtilTest, MixStreams_s16) { | |
| 96 // Test MixStreams() on 16 bit samples. | |
| 97 int16 dst_s16[kNumberOfSamples] = { -4, 0x40, -32760, 32760 }; | |
| 98 int16 src_s16[kNumberOfSamples] = { -4, 0x40, -123, 123 }; | |
| 99 int16 expected_s16[kNumberOfSamples] = { -5, 0x50, -32768, 32767 }; | |
| 100 media::MixStreams(dst_s16, | |
| 101 src_s16, | |
| 102 sizeof(dst_s16), | |
| 103 sizeof(src_s16[0]), | |
| 104 0.25f); | |
| 105 int expected_test = memcmp(dst_s16, expected_s16, sizeof(expected_s16)); | |
| 106 EXPECT_EQ(0, expected_test); | |
| 107 } | |
| 108 | |
| 109 TEST(AudioUtilTest, MixStreams_s16_one) { | |
| 110 // Test MixStreams() on 16 bit samples. | |
| 111 int16 dst_s16[kNumberOfSamples] = { -4, 0x40, -32760, 32760 }; | |
| 112 int16 src_s16[kNumberOfSamples] = { -4, 0x40, -123, 123 }; | |
| 113 int16 expected_s16[kNumberOfSamples] = { -8, 0x80, -32768, 32767 }; | |
| 114 media::MixStreams(dst_s16, | |
| 115 src_s16, | |
| 116 sizeof(dst_s16), | |
| 117 sizeof(src_s16[0]), | |
| 118 1.0f); | |
| 119 int expected_test = memcmp(dst_s16, expected_s16, sizeof(expected_s16)); | |
| 120 EXPECT_EQ(0, expected_test); | |
| 121 } | |
| 122 | |
| 123 TEST(AudioUtilTest, MixStreams_s32) { | |
| 124 // Test MixStreams() on 32 bit samples. | |
| 125 int32 dst_s32[kNumberOfSamples] = { -4, 0x40, -32768, 2147483640 }; | |
| 126 int32 src_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; | |
| 127 int32 expected_s32[kNumberOfSamples] = { -5, 0x50, -40960, 2147483647 }; | |
| 128 media::MixStreams(dst_s32, | |
| 129 src_s32, | |
| 130 sizeof(dst_s32), | |
| 131 sizeof(src_s32[0]), | |
| 132 0.25f); | |
| 133 int expected_test = memcmp(dst_s32, expected_s32, sizeof(expected_s32)); | |
| 134 EXPECT_EQ(0, expected_test); | |
| 135 } | |
| 136 | |
| 137 TEST(AudioUtilTest, MixStreams_s32_one) { | |
| 138 // Test MixStreams() on 32 bit samples. | |
| 139 int32 dst_s32[kNumberOfSamples] = { -4, 0x40, -32768, 2147483640 }; | |
| 140 int32 src_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; | |
| 141 int32 expected_s32[kNumberOfSamples] = { -8, 0x80, -65536, 2147483647 }; | |
| 142 media::MixStreams(dst_s32, | |
| 143 src_s32, | |
| 144 sizeof(dst_s32), | |
| 145 sizeof(src_s32[0]), | |
| 146 1.0); | |
| 147 int expected_test = memcmp(dst_s32, expected_s32, sizeof(expected_s32)); | |
| 148 EXPECT_EQ(0, expected_test); | |
| 149 } | |
| 150 | |
| 82 TEST(AudioUtilTest, FoldChannels_u8) { | 151 TEST(AudioUtilTest, FoldChannels_u8) { |
| 83 // Test FoldChannels() on 8 bit samples. | 152 // Test FoldChannels() on 8 bit samples. |
| 84 uint8 samples_u8[6] = { 100, 150, 130, 70, 130, 170 }; | 153 uint8 samples_u8[6] = { 100, 150, 130, 70, 130, 170 }; |
| 85 uint8 expected_u8[2] = { static_cast<uint8>((130 - 128) * 0.707 + | 154 uint8 expected_u8[2] = { static_cast<uint8>((130 - 128) * 0.707 + |
| 86 (100 - 128) + 128), | 155 (100 - 128) + 128), |
| 87 static_cast<uint8>((130 - 128) * 0.707 + | 156 static_cast<uint8>((130 - 128) * 0.707 + |
| 88 (150 - 128) + 128) }; | 157 (150 - 128) + 128) }; |
| 89 bool result_u8 = media::FoldChannels(samples_u8, sizeof(samples_u8), | 158 bool result_u8 = media::FoldChannels(samples_u8, sizeof(samples_u8), |
| 90 6, // channels. | 159 6, // channels. |
| 91 sizeof(samples_u8[0]), | 160 sizeof(samples_u8[0]), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 bool result_s16 = media::FoldChannels(samples_s16, sizeof(samples_s16), | 201 bool result_s16 = media::FoldChannels(samples_s16, sizeof(samples_s16), |
| 133 8, // channels. | 202 8, // channels. |
| 134 sizeof(samples_s16[0]), | 203 sizeof(samples_s16[0]), |
| 135 1.00f); | 204 1.00f); |
| 136 EXPECT_TRUE(result_s16); | 205 EXPECT_TRUE(result_s16); |
| 137 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16)); | 206 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16)); |
| 138 EXPECT_EQ(0, expected_test); | 207 EXPECT_EQ(0, expected_test); |
| 139 } | 208 } |
| 140 | 209 |
| 141 } // namespace media | 210 } // namespace media |
| OLD | NEW |