| 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, | |
| 107 AudioParameters::kAudioCDSampleRate, 16, | 103 AudioParameters::kAudioCDSampleRate, 16, |
| 108 kFrames, | 104 kFrames); |
| 109 AudioParameters::NO_EFFECTS); | 105 if (input_layout == CHANNEL_LAYOUT_DISCRETE) |
| 106 input_audio.SetDiscreteChannels(input_channels); |
| 110 | 107 |
| 111 ChannelLayout output_layout = GetParam().output_layout; | 108 ChannelLayout output_layout = GetParam().output_layout; |
| 112 int output_channels = GetParam().output_channels; | 109 int output_channels = GetParam().output_channels; |
| 113 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_channels, kFrames); | 110 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_channels, kFrames); |
| 114 AudioParameters output_audio(AudioParameters::AUDIO_PCM_LINEAR, | 111 AudioParameters output_audio(AudioParameters::AUDIO_PCM_LINEAR, |
| 115 output_layout, | 112 output_layout, |
| 116 output_layout == CHANNEL_LAYOUT_DISCRETE ? | |
| 117 output_channels : | |
| 118 ChannelLayoutToChannelCount(output_layout), | |
| 119 0, | |
| 120 AudioParameters::kAudioCDSampleRate, 16, | 113 AudioParameters::kAudioCDSampleRate, 16, |
| 121 kFrames, | 114 kFrames); |
| 122 AudioParameters::NO_EFFECTS); | 115 if (output_layout == CHANNEL_LAYOUT_DISCRETE) |
| 116 output_audio.SetDiscreteChannels(output_channels); |
| 123 | 117 |
| 124 const float* channel_values = GetParam().channel_values; | 118 const float* channel_values = GetParam().channel_values; |
| 125 ASSERT_EQ(input_bus->channels(), GetParam().num_channel_values); | 119 ASSERT_EQ(input_bus->channels(), GetParam().num_channel_values); |
| 126 | 120 |
| 127 float expected_value = 0; | 121 float expected_value = 0; |
| 128 float scale = GetParam().scale; | 122 float scale = GetParam().scale; |
| 129 for (int ch = 0; ch < input_bus->channels(); ++ch) { | 123 for (int ch = 0; ch < input_bus->channels(); ++ch) { |
| 130 std::fill(input_bus->channel(ch), input_bus->channel(ch) + kFrames, | 124 std::fill(input_bus->channel(ch), input_bus->channel(ch) + kFrames, |
| 131 channel_values[ch]); | 125 channel_values[ch]); |
| 132 expected_value += channel_values[ch] * scale; | 126 expected_value += channel_values[ch] * scale; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 kStereoToMonoValues, arraysize(kStereoToMonoValues)), | 171 kStereoToMonoValues, arraysize(kStereoToMonoValues)), |
| 178 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 2, | 172 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 2, |
| 179 CHANNEL_LAYOUT_DISCRETE, 5, | 173 CHANNEL_LAYOUT_DISCRETE, 5, |
| 180 kStereoToMonoValues, arraysize(kStereoToMonoValues)), | 174 kStereoToMonoValues, arraysize(kStereoToMonoValues)), |
| 181 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 5, | 175 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 5, |
| 182 CHANNEL_LAYOUT_DISCRETE, 2, | 176 CHANNEL_LAYOUT_DISCRETE, 2, |
| 183 kFiveDiscreteValues, arraysize(kFiveDiscreteValues)) | 177 kFiveDiscreteValues, arraysize(kFiveDiscreteValues)) |
| 184 )); | 178 )); |
| 185 | 179 |
| 186 } // namespace media | 180 } // namespace media |
| OLD | NEW |