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