OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_QuarterVolume) { | |
83 // Test MixStreams() on 8 bit samples. | |
84 uint8 dst_u8[kNumberOfSamples] = { 14, 0x44, 0x80, 0xff }; | |
85 uint8 src_u8[kNumberOfSamples] = { 4, 0x40, 0x80, 0xff }; | |
86 uint8 expected_u8[kNumberOfSamples] = { 0, /* saturation */ | |
87 (0x44 - 128) + (0x40 - 128) / 4 + 128, | |
88 (0x80 - 128) + (0x80 - 128) / 4 + 128, | |
89 0xff /* saturation */ }; | |
90 media::MixStreams(dst_u8, src_u8, sizeof(dst_u8), sizeof(src_u8[0]), 0.25f); | |
91 int expected_test = memcmp(dst_u8, expected_u8, sizeof(expected_u8)); | |
92 EXPECT_EQ(0, expected_test); | |
93 } | |
94 | |
95 TEST(AudioUtilTest, MixStreams_u8_FullVolume) { | |
96 // Test MixStreams() on 8 bit samples. | |
97 uint8 dst_u8[kNumberOfSamples] = { 44, 0x44, 0x80, 0xff }; | |
98 uint8 src_u8[kNumberOfSamples] = { 4, 0x40, 0x80, 0xff }; | |
99 uint8 expected_u8[kNumberOfSamples] = { 0, /* saturation */ | |
100 (0x44 - 128) + (0x40 - 128) + 128, | |
101 (0x80 - 128) + (0x80 - 128) + 128, | |
102 0xff /* saturation */ }; | |
103 media::MixStreams(dst_u8, src_u8, sizeof(dst_u8), sizeof(src_u8[0]), 1.0f); | |
104 int expected_test = memcmp(dst_u8, expected_u8, sizeof(expected_u8)); | |
105 EXPECT_EQ(0, expected_test); | |
106 } | |
107 | |
108 TEST(AudioUtilTest, MixStreams_s16_QuarterVolume) { | |
109 // Test MixStreams() on 16 bit samples. | |
110 int16 dst_s16[kNumberOfSamples] = { -4, 0x40, -32760, 32760 }; | |
111 int16 src_s16[kNumberOfSamples] = { -4, 0x40, -123, 123 }; | |
112 int16 expected_s16[kNumberOfSamples] = { -5, 0x50, -32768, 32767 }; | |
113 media::MixStreams(dst_s16, | |
114 src_s16, | |
115 sizeof(dst_s16), | |
116 sizeof(src_s16[0]), | |
117 0.25f); | |
118 int expected_test = memcmp(dst_s16, expected_s16, sizeof(expected_s16)); | |
119 EXPECT_EQ(0, expected_test); | |
120 } | |
121 | |
122 TEST(AudioUtilTest, MixStreams_s16_FullVolume) { | |
123 // Test MixStreams() on 16 bit samples. | |
124 int16 dst_s16[kNumberOfSamples] = { -4, 0x40, -32760, 32760 }; | |
125 int16 src_s16[kNumberOfSamples] = { -4, 0x40, -123, 123 }; | |
126 int16 expected_s16[kNumberOfSamples] = { -8, 0x80, -32768, 32767 }; | |
127 media::MixStreams(dst_s16, | |
128 src_s16, | |
129 sizeof(dst_s16), | |
130 sizeof(src_s16[0]), | |
131 1.0f); | |
132 int expected_test = memcmp(dst_s16, expected_s16, sizeof(expected_s16)); | |
133 EXPECT_EQ(0, expected_test); | |
134 } | |
135 | |
136 TEST(AudioUtilTest, MixStreams_s32_QuarterVolume) { | |
137 // Test MixStreams() on 32 bit samples. | |
138 int32 dst_s32[kNumberOfSamples] = { -4, 0x40, -32768, 2147483640 }; | |
139 int32 src_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; | |
140 int32 expected_s32[kNumberOfSamples] = { -5, 0x50, -40960, 2147483647 }; | |
141 media::MixStreams(dst_s32, | |
142 src_s32, | |
143 sizeof(dst_s32), | |
144 sizeof(src_s32[0]), | |
145 0.25f); | |
146 int expected_test = memcmp(dst_s32, expected_s32, sizeof(expected_s32)); | |
147 EXPECT_EQ(0, expected_test); | |
148 } | |
149 | |
150 TEST(AudioUtilTest, MixStreams_s32_FullVolume) { | |
151 // Test MixStreams() on 32 bit samples. | |
152 int32 dst_s32[kNumberOfSamples] = { -4, 0x40, -32768, 2147483640 }; | |
153 int32 src_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; | |
154 int32 expected_s32[kNumberOfSamples] = { -8, 0x80, -65536, 2147483647 }; | |
155 media::MixStreams(dst_s32, | |
156 src_s32, | |
157 sizeof(dst_s32), | |
158 sizeof(src_s32[0]), | |
159 1.0); | |
160 int expected_test = memcmp(dst_s32, expected_s32, sizeof(expected_s32)); | |
161 EXPECT_EQ(0, expected_test); | |
162 } | |
163 | |
164 } // namespace media | 82 } // namespace media |
OLD | NEW |