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