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" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 class ChannelMixerTest : public testing::TestWithParam<ChannelMixerTestData> {}; | 93 class ChannelMixerTest : public testing::TestWithParam<ChannelMixerTestData> {}; |
94 | 94 |
95 // Verify channels are mixed and scaled correctly. The test only works if all | 95 // Verify channels are mixed and scaled correctly. The test only works if all |
96 // output channels have the same value. | 96 // output channels have the same value. |
97 TEST_P(ChannelMixerTest, Mixing) { | 97 TEST_P(ChannelMixerTest, Mixing) { |
98 ChannelLayout input_layout = GetParam().input_layout; | 98 ChannelLayout input_layout = GetParam().input_layout; |
99 int input_channels = GetParam().input_channels; | 99 int input_channels = GetParam().input_channels; |
100 scoped_ptr<AudioBus> input_bus = AudioBus::Create(input_channels, kFrames); | 100 scoped_ptr<AudioBus> input_bus = AudioBus::Create(input_channels, kFrames); |
101 AudioParameters input_audio(AudioParameters::AUDIO_PCM_LINEAR, | 101 AudioParameters input_audio(AudioParameters::AUDIO_PCM_LINEAR, |
102 input_layout, | 102 input_layout, |
| 103 input_layout == CHANNEL_LAYOUT_DISCRETE ? |
| 104 input_channels : |
| 105 ChannelLayoutToChannelCount(input_layout), |
| 106 0, |
103 AudioParameters::kAudioCDSampleRate, 16, | 107 AudioParameters::kAudioCDSampleRate, 16, |
104 kFrames); | 108 kFrames, |
105 if (input_layout == CHANNEL_LAYOUT_DISCRETE) | 109 AudioParameters::NO_EFFECTS); |
106 input_audio.SetDiscreteChannels(input_channels); | |
107 | 110 |
108 ChannelLayout output_layout = GetParam().output_layout; | 111 ChannelLayout output_layout = GetParam().output_layout; |
109 int output_channels = GetParam().output_channels; | 112 int output_channels = GetParam().output_channels; |
110 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_channels, kFrames); | 113 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_channels, kFrames); |
111 AudioParameters output_audio(AudioParameters::AUDIO_PCM_LINEAR, | 114 AudioParameters output_audio(AudioParameters::AUDIO_PCM_LINEAR, |
112 output_layout, | 115 output_layout, |
| 116 output_layout == CHANNEL_LAYOUT_DISCRETE ? |
| 117 output_channels : |
| 118 ChannelLayoutToChannelCount(output_layout), |
| 119 0, |
113 AudioParameters::kAudioCDSampleRate, 16, | 120 AudioParameters::kAudioCDSampleRate, 16, |
114 kFrames); | 121 kFrames, |
115 if (output_layout == CHANNEL_LAYOUT_DISCRETE) | 122 AudioParameters::NO_EFFECTS); |
116 output_audio.SetDiscreteChannels(output_channels); | |
117 | 123 |
118 const float* channel_values = GetParam().channel_values; | 124 const float* channel_values = GetParam().channel_values; |
119 ASSERT_EQ(input_bus->channels(), GetParam().num_channel_values); | 125 ASSERT_EQ(input_bus->channels(), GetParam().num_channel_values); |
120 | 126 |
121 float expected_value = 0; | 127 float expected_value = 0; |
122 float scale = GetParam().scale; | 128 float scale = GetParam().scale; |
123 for (int ch = 0; ch < input_bus->channels(); ++ch) { | 129 for (int ch = 0; ch < input_bus->channels(); ++ch) { |
124 std::fill(input_bus->channel(ch), input_bus->channel(ch) + kFrames, | 130 std::fill(input_bus->channel(ch), input_bus->channel(ch) + kFrames, |
125 channel_values[ch]); | 131 channel_values[ch]); |
126 expected_value += channel_values[ch] * scale; | 132 expected_value += channel_values[ch] * scale; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 kStereoToMonoValues, arraysize(kStereoToMonoValues)), | 177 kStereoToMonoValues, arraysize(kStereoToMonoValues)), |
172 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 2, | 178 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 2, |
173 CHANNEL_LAYOUT_DISCRETE, 5, | 179 CHANNEL_LAYOUT_DISCRETE, 5, |
174 kStereoToMonoValues, arraysize(kStereoToMonoValues)), | 180 kStereoToMonoValues, arraysize(kStereoToMonoValues)), |
175 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 5, | 181 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 5, |
176 CHANNEL_LAYOUT_DISCRETE, 2, | 182 CHANNEL_LAYOUT_DISCRETE, 2, |
177 kFiveDiscreteValues, arraysize(kFiveDiscreteValues)) | 183 kFiveDiscreteValues, arraysize(kFiveDiscreteValues)) |
178 )); | 184 )); |
179 | 185 |
180 } // namespace media | 186 } // namespace media |
OLD | NEW |