Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "media/audio/audio_power_monitor.h" | 5 #include "media/audio/audio_power_monitor.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 for (int frames = 0; frames < kFramesPerBuffer; frames += num_frames) { | 69 for (int frames = 0; frames < kFramesPerBuffer; frames += num_frames) { |
| 70 const int num_to_copy = std::min(num_frames, kFramesPerBuffer - frames); | 70 const int num_to_copy = std::min(num_frames, kFramesPerBuffer - frames); |
| 71 memcpy(bus_->channel(ch) + frames, data + num_frames * ch, | 71 memcpy(bus_->channel(ch) + frames, data + num_frames * ch, |
| 72 sizeof(float) * num_to_copy); | 72 sizeof(float) * num_to_copy); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 float expected_power_; | 77 float expected_power_; |
| 78 bool expected_clipped_; | 78 bool expected_clipped_; |
| 79 scoped_ptr<AudioBus> bus_; | 79 std::unique_ptr<AudioBus> bus_; |
|
danakj
2016/04/22 22:47:36
include memory
dcheng
2016/04/22 23:13:20
Done.
| |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 // Value printer for TestScenario. Required to prevent Valgrind "access to | 82 // Value printer for TestScenario. Required to prevent Valgrind "access to |
| 83 // uninitialized memory" errors (http://crbug.com/263315). | 83 // uninitialized memory" errors (http://crbug.com/263315). |
| 84 ::std::ostream& operator<<(::std::ostream& os, const TestScenario& ts) { | 84 ::std::ostream& operator<<(::std::ostream& os, const TestScenario& ts) { |
| 85 return os << "{" << ts.data().channels() << "-channel signal} --> {" | 85 return os << "{" << ts.data().channels() << "-channel signal} --> {" |
| 86 << ts.expected_power() << " dBFS, " | 86 << ts.expected_power() << " dBFS, " |
| 87 << (ts.expected_clipped() ? "clipped" : "not clipped") | 87 << (ts.expected_clipped() ? "clipped" : "not clipped") |
| 88 << "}"; | 88 << "}"; |
| 89 } | 89 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 | 180 |
| 181 private: | 181 private: |
| 182 AudioPowerMonitor power_monitor_; | 182 AudioPowerMonitor power_monitor_; |
| 183 | 183 |
| 184 DISALLOW_COPY_AND_ASSIGN(AudioPowerMonitorTest); | 184 DISALLOW_COPY_AND_ASSIGN(AudioPowerMonitorTest); |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 TEST_P(AudioPowerMonitorTest, MeasuresPowerOfSignal) { | 187 TEST_P(AudioPowerMonitorTest, MeasuresPowerOfSignal) { |
| 188 const TestScenario& scenario = GetParam(); | 188 const TestScenario& scenario = GetParam(); |
| 189 | 189 |
| 190 scoped_ptr<AudioBus> zeroed_bus = | 190 std::unique_ptr<AudioBus> zeroed_bus = |
| 191 AudioBus::Create(scenario.data().channels(), scenario.data().frames()); | 191 AudioBus::Create(scenario.data().channels(), scenario.data().frames()); |
| 192 zeroed_bus->Zero(); | 192 zeroed_bus->Zero(); |
| 193 | 193 |
| 194 // Send a "zero power" audio signal, then this scenario's audio signal, then | 194 // Send a "zero power" audio signal, then this scenario's audio signal, then |
| 195 // the "zero power" audio signal again; testing that the power monitor | 195 // the "zero power" audio signal again; testing that the power monitor |
| 196 // measurements match expected values. | 196 // measurements match expected values. |
| 197 FeedAndCheckExpectedPowerIsMeasured( | 197 FeedAndCheckExpectedPowerIsMeasured( |
| 198 *zeroed_bus, AudioPowerMonitor::zero_power(), false); | 198 *zeroed_bus, AudioPowerMonitor::zero_power(), false); |
| 199 FeedAndCheckExpectedPowerIsMeasured( | 199 FeedAndCheckExpectedPowerIsMeasured( |
| 200 scenario.data(), scenario.expected_power(), scenario.expected_clipped()); | 200 scenario.data(), scenario.expected_power(), scenario.expected_clipped()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 WithABadSample(std::numeric_limits<float>::quiet_NaN()), | 295 WithABadSample(std::numeric_limits<float>::quiet_NaN()), |
| 296 TestScenario(kStereoSilentNoise, 2, 2, -46, false), | 296 TestScenario(kStereoSilentNoise, 2, 2, -46, false), |
| 297 TestScenario(kStereoMaxAmplitude, 2, 2, | 297 TestScenario(kStereoMaxAmplitude, 2, 2, |
| 298 AudioPowerMonitor::max_power(), false), | 298 AudioPowerMonitor::max_power(), false), |
| 299 TestScenario(kRightChannelMaxAmplitude, 2, 4, -3, false), | 299 TestScenario(kRightChannelMaxAmplitude, 2, 4, -3, false), |
| 300 TestScenario(kLeftChannelHalfMaxAmplitude, 2, 4, -9, false), | 300 TestScenario(kLeftChannelHalfMaxAmplitude, 2, 4, -9, false), |
| 301 TestScenario(kStereoMixed, 2, 4, -2, false), | 301 TestScenario(kStereoMixed, 2, 4, -2, false), |
| 302 TestScenario(kStereoMixed2, 2, 8, -3, false))); | 302 TestScenario(kStereoMixed2, 2, 8, -3, false))); |
| 303 | 303 |
| 304 } // namespace media | 304 } // namespace media |
| OLD | NEW |