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

Side by Side Diff: media/base/channel_mixer_unittest.cc

Issue 672793002: Expose the internal MatrixBuilder class as ChannelMixingMatrix. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test output_layout up to MAX. Use EXPECT_FLOAT_EQ. Created 6 years, 1 month 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
« no previous file with comments | « media/base/channel_mixer.cc ('k') | media/base/channel_mixing_matrix.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) 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 // MSVC++ requires this to be set before any other includes to get M_SQRT1_2. 5 // MSVC++ requires this to be set before any other includes to get M_SQRT1_2.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "media/audio/audio_parameters.h" 11 #include "media/audio/audio_parameters.h"
12 #include "media/base/audio_bus.h" 12 #include "media/base/audio_bus.h"
13 #include "media/base/channel_mixer.h" 13 #include "media/base/channel_mixer.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace media { 16 namespace media {
17 17
18 // Number of frames to test with. 18 // Number of frames to test with.
19 enum { kFrames = 16 }; 19 enum { kFrames = 16 };
20 20
21 // Test all possible layout conversions can be constructed and mixed. 21 // Test all possible layout conversions can be constructed and mixed.
22 TEST(ChannelMixerTest, ConstructAllPossibleLayouts) { 22 TEST(ChannelMixerTest, ConstructAllPossibleLayouts) {
23 for (ChannelLayout input_layout = CHANNEL_LAYOUT_MONO; 23 for (ChannelLayout input_layout = CHANNEL_LAYOUT_MONO;
24 input_layout <= CHANNEL_LAYOUT_MAX; 24 input_layout <= CHANNEL_LAYOUT_MAX;
25 input_layout = static_cast<ChannelLayout>(input_layout + 1)) { 25 input_layout = static_cast<ChannelLayout>(input_layout + 1)) {
26 for (ChannelLayout output_layout = CHANNEL_LAYOUT_MONO; 26 for (ChannelLayout output_layout = CHANNEL_LAYOUT_MONO;
27 output_layout < CHANNEL_LAYOUT_STEREO_DOWNMIX; 27 output_layout <= CHANNEL_LAYOUT_MAX;
28 output_layout = static_cast<ChannelLayout>(output_layout + 1)) { 28 output_layout = static_cast<ChannelLayout>(output_layout + 1)) {
29 // DISCRETE can't be tested here based on the current approach. 29 // DISCRETE can't be tested here based on the current approach.
30 // CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC is not mixable. 30 // CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC is not mixable.
31 // Stereo down mix should never be the output layout.
31 if (input_layout == CHANNEL_LAYOUT_DISCRETE || 32 if (input_layout == CHANNEL_LAYOUT_DISCRETE ||
32 input_layout == CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC || 33 input_layout == CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC ||
33 output_layout == CHANNEL_LAYOUT_DISCRETE || 34 output_layout == CHANNEL_LAYOUT_DISCRETE ||
34 output_layout == CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC) { 35 output_layout == CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC ||
36 output_layout == CHANNEL_LAYOUT_STEREO_DOWNMIX) {
35 continue; 37 continue;
36 } 38 }
37 39
38 SCOPED_TRACE(base::StringPrintf( 40 SCOPED_TRACE(base::StringPrintf(
39 "Input Layout: %d, Output Layout: %d", input_layout, output_layout)); 41 "Input Layout: %d, Output Layout: %d", input_layout, output_layout));
40 ChannelMixer mixer(input_layout, output_layout); 42 ChannelMixer mixer(input_layout, output_layout);
41 scoped_ptr<AudioBus> input_bus = AudioBus::Create( 43 scoped_ptr<AudioBus> input_bus = AudioBus::Create(
42 ChannelLayoutToChannelCount(input_layout), kFrames); 44 ChannelLayoutToChannelCount(input_layout), kFrames);
43 scoped_ptr<AudioBus> output_bus = AudioBus::Create( 45 scoped_ptr<AudioBus> output_bus = AudioBus::Create(
44 ChannelLayoutToChannelCount(output_layout), kFrames); 46 ChannelLayoutToChannelCount(output_layout), kFrames);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 for (int frame = 0; frame < output_bus->frames(); ++frame) { 155 for (int frame = 0; frame < output_bus->frames(); ++frame) {
154 ASSERT_FLOAT_EQ(output_bus->channel(ch)[frame], expected_value); 156 ASSERT_FLOAT_EQ(output_bus->channel(ch)[frame], expected_value);
155 } 157 }
156 } 158 }
157 } 159 }
158 } 160 }
159 161
160 static float kStereoToMonoValues[] = { 0.5f, 0.75f }; 162 static float kStereoToMonoValues[] = { 0.5f, 0.75f };
161 static float kMonoToStereoValues[] = { 0.5f }; 163 static float kMonoToStereoValues[] = { 0.5f };
162 // Zero the center channel since it will be mixed at scale 1 vs M_SQRT1_2. 164 // Zero the center channel since it will be mixed at scale 1 vs M_SQRT1_2.
163 static float kFiveOneToMonoValues[] = { 0.1f, 0.2f, 0.0f, 0.4f, 0.5f, 0.6f }; 165 static float kFiveOneToMonoValues[] = { 0.1f, 0.2f, 0.0f, 0.4f, 0.5f, 0.6f };
wtc 2014/10/23 19:24:00 Nit: when these inputs are mixed and scaled by 1/s
DaleCurtis 2014/10/23 19:27:55 Clipping avoidance would be nice, but I wouldn't w
164 static float kFiveDiscreteValues[] = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f }; 166 static float kFiveDiscreteValues[] = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f };
165 167
166 // Run through basic sanity tests for some common conversions. 168 // Run through basic sanity tests for some common conversions.
167 INSTANTIATE_TEST_CASE_P(ChannelMixerTest, ChannelMixerTest, testing::Values( 169 INSTANTIATE_TEST_CASE_P(ChannelMixerTest, ChannelMixerTest, testing::Values(
168 ChannelMixerTestData(CHANNEL_LAYOUT_STEREO, CHANNEL_LAYOUT_MONO, 170 ChannelMixerTestData(CHANNEL_LAYOUT_STEREO, CHANNEL_LAYOUT_MONO,
169 kStereoToMonoValues, arraysize(kStereoToMonoValues), 171 kStereoToMonoValues, arraysize(kStereoToMonoValues),
170 0.5f), 172 0.5f),
171 ChannelMixerTestData(CHANNEL_LAYOUT_MONO, CHANNEL_LAYOUT_STEREO, 173 ChannelMixerTestData(CHANNEL_LAYOUT_MONO, CHANNEL_LAYOUT_STEREO,
172 kMonoToStereoValues, arraysize(kMonoToStereoValues), 174 kMonoToStereoValues, arraysize(kMonoToStereoValues),
173 1.0f), 175 1.0f),
174 ChannelMixerTestData(CHANNEL_LAYOUT_5_1, CHANNEL_LAYOUT_MONO, 176 ChannelMixerTestData(CHANNEL_LAYOUT_5_1, CHANNEL_LAYOUT_MONO,
175 kFiveOneToMonoValues, arraysize(kFiveOneToMonoValues), 177 kFiveOneToMonoValues, arraysize(kFiveOneToMonoValues),
176 static_cast<float>(M_SQRT1_2)), 178 static_cast<float>(M_SQRT1_2)),
177 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 2, 179 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 2,
178 CHANNEL_LAYOUT_DISCRETE, 2, 180 CHANNEL_LAYOUT_DISCRETE, 2,
179 kStereoToMonoValues, arraysize(kStereoToMonoValues)), 181 kStereoToMonoValues, arraysize(kStereoToMonoValues)),
180 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 2, 182 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 2,
181 CHANNEL_LAYOUT_DISCRETE, 5, 183 CHANNEL_LAYOUT_DISCRETE, 5,
182 kStereoToMonoValues, arraysize(kStereoToMonoValues)), 184 kStereoToMonoValues, arraysize(kStereoToMonoValues)),
183 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 5, 185 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 5,
184 CHANNEL_LAYOUT_DISCRETE, 2, 186 CHANNEL_LAYOUT_DISCRETE, 2,
185 kFiveDiscreteValues, arraysize(kFiveDiscreteValues)) 187 kFiveDiscreteValues, arraysize(kFiveDiscreteValues))
186 )); 188 ));
187 189
188 } // namespace media 190 } // namespace media
OLDNEW
« no previous file with comments | « media/base/channel_mixer.cc ('k') | media/base/channel_mixing_matrix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698