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

Side by Side Diff: media/audio/audio_util_unittest.cc

Issue 155894: Surround Sound handling by folding 5 channels down to stereo. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_util.cc ('k') | media/audio/win/waveout_output_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 int16 expected_s16[kNumberOfSamples] = { 0, 0, 0, 0 }; 43 int16 expected_s16[kNumberOfSamples] = { 0, 0, 0, 0 };
44 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16), 44 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16),
45 2, // channels. 45 2, // channels.
46 sizeof(samples_s16[0]), 46 sizeof(samples_s16[0]),
47 0.0f); 47 0.0f);
48 EXPECT_EQ(true, result_s16); 48 EXPECT_EQ(true, result_s16);
49 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16)); 49 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16));
50 EXPECT_EQ(0, expected_test); 50 EXPECT_EQ(0, expected_test);
51 } 51 }
52 52
53 TEST(AudioUtilTest, AdjustVolume_s16_one) {
54 // Test AdjustVolume() on 16 bit samples.
55 int16 samples_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
56 int16 expected_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
57 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16),
58 2, // channels.
59 sizeof(samples_s16[0]),
60 1.0f);
61 EXPECT_EQ(true, result_s16);
62 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16));
63 EXPECT_EQ(0, expected_test);
64 }
65
53 TEST(AudioUtilTest, AdjustVolume_s32) { 66 TEST(AudioUtilTest, AdjustVolume_s32) {
54 // Test AdjustVolume() on 32 bit samples. 67 // Test AdjustVolume() on 32 bit samples.
55 int32 samples_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; 68 int32 samples_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
56 int32 expected_s32[kNumberOfSamples] = { -1, 0x10, -8192, 30 }; 69 int32 expected_s32[kNumberOfSamples] = { -1, 0x10, -8192, 30 };
57 bool result_s32 = media::AdjustVolume(samples_s32, sizeof(samples_s32), 70 bool result_s32 = media::AdjustVolume(samples_s32, sizeof(samples_s32),
58 4, // channels. 71 4, // channels.
59 sizeof(samples_s32[0]), 72 sizeof(samples_s32[0]),
60 0.25f); 73 0.25f);
61 EXPECT_EQ(true, result_s32); 74 EXPECT_EQ(true, result_s32);
62 int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32)); 75 int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32));
63 EXPECT_EQ(0, expected_test); 76 EXPECT_EQ(0, expected_test);
64 } 77 }
65 78
79 TEST(AudioUtilTest, FoldChannels_u8) {
80 // Test AdjustVolume() on 16 bit samples.
81 uint8 samples_u8[6] = { 130, 100, 150, 70, 130, 170 };
82 uint8 expected_u8[2] = { 43, 153 };
83 bool result_u8 = media::FoldChannels(samples_u8, sizeof(samples_u8),
84 6, // channels.
85 sizeof(samples_u8[0]),
86 1.0f);
87 EXPECT_EQ(true, result_u8);
88 int expected_test = memcmp(samples_u8, expected_u8, sizeof(expected_u8));
89 EXPECT_EQ(0, expected_test);
90 }
91
92 TEST(AudioUtilTest, FoldChannels_s16) {
93 // Test AdjustVolume() on 16 bit samples.
94 int16 samples_s16[6] = { 12, 1, 3, 7, 13, 17 };
95 int16 expected_s16[2] = { static_cast<int16>(12 * .707 + 1 + 7),
96 static_cast<int16>(12 * .707 + 3 + 13) };
97 bool result_s16 = media::FoldChannels(samples_s16, sizeof(samples_s16),
98 6, // channels.
99 sizeof(samples_s16[0]),
100 1.00f);
101 EXPECT_EQ(true, result_s16);
102 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16));
103 EXPECT_EQ(0, expected_test);
104 }
105
106 TEST(AudioUtilTest, FoldChannels_s32) {
107 // Test AdjustVolume() on 16 bit samples.
108 int32 samples_s32[6] = { 12, 1, 3, 7, 13, 17 };
109 int32 expected_s32[2] = { static_cast<int16>(12 * .707 + 1 + 7),
110 static_cast<int16>(12 * .707 + 3 + 13) };
111 bool result_s32 = media::FoldChannels(samples_s32, sizeof(samples_s32),
112 6, // channels.
113 sizeof(samples_s32[0]),
114 1.00f);
115 EXPECT_EQ(true, result_s32);
116 int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32));
117 EXPECT_EQ(0, expected_test);
118 }
119
120 // This mimics 1 second of audio at 48000 samples per second.
121 // Running the unittest will produce timing.
122 TEST(AudioUtilTest, FoldChannels_s16_benchmark) {
123 const int kBufferSize = 1024 * 6;
124 // Test AdjustVolume() on 16 bit samples.
125 for (int i = 0; i < 48000; ++i) {
126 int16 samples_s16[kBufferSize];
127 for (int j = 0; j < kBufferSize; ++j)
128 samples_s16[j] = j;
129
130 bool result_s16 = media::FoldChannels(samples_s16, sizeof(samples_s16),
131 6, // channels.
132 sizeof(samples_s16[0]),
133 0.5f);
134 EXPECT_EQ(true, result_s16);
135 }
136 }
66 } // namespace media 137 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_util.cc ('k') | media/audio/win/waveout_output_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698