| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/basictypes.h" | |
| 6 #include "media/audio/audio_util.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 // Number of samples in each audio array. | |
| 10 static const size_t kNumberOfSamples = 4; | |
| 11 | |
| 12 namespace media { | |
| 13 | |
| 14 TEST(AudioUtilTest, AdjustVolume_u8) { | |
| 15 // Test AdjustVolume() on 8 bit samples. | |
| 16 uint8 samples_u8[kNumberOfSamples] = { 4, 0x40, 0x80, 0xff }; | |
| 17 uint8 expected_u8[kNumberOfSamples] = { (4 - 128) / 2 + 128, | |
| 18 (0x40 - 128) / 2 + 128, | |
| 19 (0x80 - 128) / 2 + 128, | |
| 20 (0xff - 128) / 2 + 128 }; | |
| 21 bool result_u8 = media::AdjustVolume(samples_u8, sizeof(samples_u8), | |
| 22 1, // channels. | |
| 23 sizeof(samples_u8[0]), | |
| 24 0.5f); | |
| 25 EXPECT_TRUE(result_u8); | |
| 26 int expected_test = memcmp(samples_u8, expected_u8, sizeof(expected_u8)); | |
| 27 EXPECT_EQ(0, expected_test); | |
| 28 } | |
| 29 | |
| 30 TEST(AudioUtilTest, AdjustVolume_s16) { | |
| 31 // Test AdjustVolume() on 16 bit samples. | |
| 32 int16 samples_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; | |
| 33 int16 expected_s16[kNumberOfSamples] = { -1, 0x10, -8192, 30 }; | |
| 34 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16), | |
| 35 2, // channels. | |
| 36 sizeof(samples_s16[0]), | |
| 37 0.25f); | |
| 38 EXPECT_TRUE(result_s16); | |
| 39 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16)); | |
| 40 EXPECT_EQ(0, expected_test); | |
| 41 } | |
| 42 | |
| 43 TEST(AudioUtilTest, AdjustVolume_s16_zero) { | |
| 44 // Test AdjustVolume() on 16 bit samples. | |
| 45 int16 samples_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; | |
| 46 int16 expected_s16[kNumberOfSamples] = { 0, 0, 0, 0 }; | |
| 47 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16), | |
| 48 2, // channels. | |
| 49 sizeof(samples_s16[0]), | |
| 50 0.0f); | |
| 51 EXPECT_TRUE(result_s16); | |
| 52 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16)); | |
| 53 EXPECT_EQ(0, expected_test); | |
| 54 } | |
| 55 | |
| 56 TEST(AudioUtilTest, AdjustVolume_s16_one) { | |
| 57 // Test AdjustVolume() on 16 bit samples. | |
| 58 int16 samples_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; | |
| 59 int16 expected_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; | |
| 60 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16), | |
| 61 2, // channels. | |
| 62 sizeof(samples_s16[0]), | |
| 63 1.0f); | |
| 64 EXPECT_TRUE(result_s16); | |
| 65 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16)); | |
| 66 EXPECT_EQ(0, expected_test); | |
| 67 } | |
| 68 | |
| 69 TEST(AudioUtilTest, AdjustVolume_s32) { | |
| 70 // Test AdjustVolume() on 32 bit samples. | |
| 71 int32 samples_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; | |
| 72 int32 expected_s32[kNumberOfSamples] = { -1, 0x10, -8192, 30 }; | |
| 73 bool result_s32 = media::AdjustVolume(samples_s32, sizeof(samples_s32), | |
| 74 4, // channels. | |
| 75 sizeof(samples_s32[0]), | |
| 76 0.25f); | |
| 77 EXPECT_TRUE(result_s32); | |
| 78 int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32)); | |
| 79 EXPECT_EQ(0, expected_test); | |
| 80 } | |
| 81 | |
| 82 } // namespace media | |
| OLD | NEW |