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 // 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 expected_value += channel_values[ch] * scale; | 136 expected_value += channel_values[ch] * scale; |
135 } | 137 } |
136 | 138 |
137 ChannelMixer mixer(input_audio, output_audio); | 139 ChannelMixer mixer(input_audio, output_audio); |
138 mixer.Transform(input_bus.get(), output_bus.get()); | 140 mixer.Transform(input_bus.get(), output_bus.get()); |
139 | 141 |
140 // Validate the output channel | 142 // Validate the output channel |
141 if (input_layout != CHANNEL_LAYOUT_DISCRETE) { | 143 if (input_layout != CHANNEL_LAYOUT_DISCRETE) { |
142 for (int ch = 0; ch < output_bus->channels(); ++ch) { | 144 for (int ch = 0; ch < output_bus->channels(); ++ch) { |
143 for (int frame = 0; frame < output_bus->frames(); ++frame) { | 145 for (int frame = 0; frame < output_bus->frames(); ++frame) { |
144 ASSERT_FLOAT_EQ(output_bus->channel(ch)[frame], expected_value); | 146 ASSERT_FLOAT_EQ(expected_value, output_bus->channel(ch)[frame]); |
145 } | 147 } |
146 } | 148 } |
147 } else { | 149 } else { |
148 // Processing discrete mixing. If there is a matching input channel, | 150 // Processing discrete mixing. If there is a matching input channel, |
149 // then the output channel should be set. If no input channel, | 151 // then the output channel should be set. If no input channel, |
150 // output channel should be 0 | 152 // output channel should be 0 |
151 for (int ch = 0; ch < output_bus->channels(); ++ch) { | 153 for (int ch = 0; ch < output_bus->channels(); ++ch) { |
152 expected_value = (ch < input_channels) ? channel_values[ch] : 0; | 154 expected_value = (ch < input_channels) ? channel_values[ch] : 0; |
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(expected_value, output_bus->channel(ch)[frame]); |
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 }; |
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 }; |
(...skipping 14 matching lines...) Expand all Loading... |
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 |
OLD | NEW |