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 #include <memory> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
13 #include "media/base/audio_parameters.h" | 14 #include "media/base/audio_parameters.h" |
14 #include "media/base/channel_mixer.h" | 15 #include "media/base/channel_mixer.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace media { | 18 namespace media { |
18 | 19 |
(...skipping 15 matching lines...) Expand all Loading... |
34 input_layout == CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC || | 35 input_layout == CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC || |
35 output_layout == CHANNEL_LAYOUT_DISCRETE || | 36 output_layout == CHANNEL_LAYOUT_DISCRETE || |
36 output_layout == CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC || | 37 output_layout == CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC || |
37 output_layout == CHANNEL_LAYOUT_STEREO_DOWNMIX) { | 38 output_layout == CHANNEL_LAYOUT_STEREO_DOWNMIX) { |
38 continue; | 39 continue; |
39 } | 40 } |
40 | 41 |
41 SCOPED_TRACE(base::StringPrintf( | 42 SCOPED_TRACE(base::StringPrintf( |
42 "Input Layout: %d, Output Layout: %d", input_layout, output_layout)); | 43 "Input Layout: %d, Output Layout: %d", input_layout, output_layout)); |
43 ChannelMixer mixer(input_layout, output_layout); | 44 ChannelMixer mixer(input_layout, output_layout); |
44 scoped_ptr<AudioBus> input_bus = AudioBus::Create( | 45 std::unique_ptr<AudioBus> input_bus = |
45 ChannelLayoutToChannelCount(input_layout), kFrames); | 46 AudioBus::Create(ChannelLayoutToChannelCount(input_layout), kFrames); |
46 scoped_ptr<AudioBus> output_bus = AudioBus::Create( | 47 std::unique_ptr<AudioBus> output_bus = |
47 ChannelLayoutToChannelCount(output_layout), kFrames); | 48 AudioBus::Create(ChannelLayoutToChannelCount(output_layout), kFrames); |
48 for (int ch = 0; ch < input_bus->channels(); ++ch) | 49 for (int ch = 0; ch < input_bus->channels(); ++ch) |
49 std::fill(input_bus->channel(ch), input_bus->channel(ch) + kFrames, 1); | 50 std::fill(input_bus->channel(ch), input_bus->channel(ch) + kFrames, 1); |
50 | 51 |
51 mixer.Transform(input_bus.get(), output_bus.get()); | 52 mixer.Transform(input_bus.get(), output_bus.get()); |
52 } | 53 } |
53 } | 54 } |
54 } | 55 } |
55 | 56 |
56 struct ChannelMixerTestData { | 57 struct ChannelMixerTestData { |
57 ChannelMixerTestData(ChannelLayout input_layout, ChannelLayout output_layout, | 58 ChannelMixerTestData(ChannelLayout input_layout, ChannelLayout output_layout, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return os << data.DebugString(); | 98 return os << data.DebugString(); |
98 } | 99 } |
99 | 100 |
100 class ChannelMixerTest : public testing::TestWithParam<ChannelMixerTestData> {}; | 101 class ChannelMixerTest : public testing::TestWithParam<ChannelMixerTestData> {}; |
101 | 102 |
102 // Verify channels are mixed and scaled correctly. The test only works if all | 103 // Verify channels are mixed and scaled correctly. The test only works if all |
103 // output channels have the same value. | 104 // output channels have the same value. |
104 TEST_P(ChannelMixerTest, Mixing) { | 105 TEST_P(ChannelMixerTest, Mixing) { |
105 ChannelLayout input_layout = GetParam().input_layout; | 106 ChannelLayout input_layout = GetParam().input_layout; |
106 int input_channels = GetParam().input_channels; | 107 int input_channels = GetParam().input_channels; |
107 scoped_ptr<AudioBus> input_bus = AudioBus::Create(input_channels, kFrames); | 108 std::unique_ptr<AudioBus> input_bus = |
| 109 AudioBus::Create(input_channels, kFrames); |
108 AudioParameters input_audio(AudioParameters::AUDIO_PCM_LINEAR, input_layout, | 110 AudioParameters input_audio(AudioParameters::AUDIO_PCM_LINEAR, input_layout, |
109 AudioParameters::kAudioCDSampleRate, 16, kFrames); | 111 AudioParameters::kAudioCDSampleRate, 16, kFrames); |
110 if (input_layout == CHANNEL_LAYOUT_DISCRETE) | 112 if (input_layout == CHANNEL_LAYOUT_DISCRETE) |
111 input_audio.set_channels_for_discrete(input_channels); | 113 input_audio.set_channels_for_discrete(input_channels); |
112 | 114 |
113 ChannelLayout output_layout = GetParam().output_layout; | 115 ChannelLayout output_layout = GetParam().output_layout; |
114 int output_channels = GetParam().output_channels; | 116 int output_channels = GetParam().output_channels; |
115 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_channels, kFrames); | 117 std::unique_ptr<AudioBus> output_bus = |
| 118 AudioBus::Create(output_channels, kFrames); |
116 AudioParameters output_audio(AudioParameters::AUDIO_PCM_LINEAR, output_layout, | 119 AudioParameters output_audio(AudioParameters::AUDIO_PCM_LINEAR, output_layout, |
117 AudioParameters::kAudioCDSampleRate, 16, | 120 AudioParameters::kAudioCDSampleRate, 16, |
118 kFrames); | 121 kFrames); |
119 if (output_layout == CHANNEL_LAYOUT_DISCRETE) | 122 if (output_layout == CHANNEL_LAYOUT_DISCRETE) |
120 output_audio.set_channels_for_discrete(output_channels); | 123 output_audio.set_channels_for_discrete(output_channels); |
121 | 124 |
122 const float* channel_values = GetParam().channel_values; | 125 const float* channel_values = GetParam().channel_values; |
123 ASSERT_EQ(input_bus->channels(), GetParam().num_channel_values); | 126 ASSERT_EQ(input_bus->channels(), GetParam().num_channel_values); |
124 | 127 |
125 float expected_value = 0; | 128 float expected_value = 0; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 kStereoToMonoValues, arraysize(kStereoToMonoValues)), | 178 kStereoToMonoValues, arraysize(kStereoToMonoValues)), |
176 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 2, | 179 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 2, |
177 CHANNEL_LAYOUT_DISCRETE, 5, | 180 CHANNEL_LAYOUT_DISCRETE, 5, |
178 kStereoToMonoValues, arraysize(kStereoToMonoValues)), | 181 kStereoToMonoValues, arraysize(kStereoToMonoValues)), |
179 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 5, | 182 ChannelMixerTestData(CHANNEL_LAYOUT_DISCRETE, 5, |
180 CHANNEL_LAYOUT_DISCRETE, 2, | 183 CHANNEL_LAYOUT_DISCRETE, 2, |
181 kFiveDiscreteValues, arraysize(kFiveDiscreteValues)) | 184 kFiveDiscreteValues, arraysize(kFiveDiscreteValues)) |
182 )); | 185 )); |
183 | 186 |
184 } // namespace media | 187 } // namespace media |
OLD | NEW |