| Index: media/audio/audio_power_monitor.h
|
| diff --git a/media/audio/audio_power_monitor.h b/media/audio/audio_power_monitor.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..355f32b60d4779d1e86cb3dbe96f9e5578b43d40
|
| --- /dev/null
|
| +++ b/media/audio/audio_power_monitor.h
|
| @@ -0,0 +1,77 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef MEDIA_AUDIO_AUDIO_POWER_MONITOR_H_
|
| +#define MEDIA_AUDIO_AUDIO_POWER_MONITOR_H_
|
| +
|
| +#include "base/callback.h"
|
| +#include "media/base/media_export.h"
|
| +
|
| +// An audio signal power monitor. It is periodically provided an AudioBus by
|
| +// the native audio thread, and the audio samples in each channel are analyzed
|
| +// to determine the average power of the signal over a time period. Here
|
| +// "average power" is defined as the RMS of the amplitudes, converted to dBFS
|
| +// (decibels relative to full-scale) units.
|
| +//
|
| +// Note that extreme care has been taken to make the AudioPowerMonitor::Scan()
|
| +// method safe to be called on the native audio thread. The code acquires no
|
| +// locks, nor engages in any operation that could result in an
|
| +// undetermined/unbounded amount of run-time.
|
| +
|
| +namespace base {
|
| +class MessageLoop;
|
| +class TimeDelta;
|
| +}
|
| +
|
| +namespace media {
|
| +
|
| +class AudioBus;
|
| +
|
| +class MEDIA_EXPORT AudioPowerMonitor {
|
| + public:
|
| + // Reports power level in terms of dBFS. This means negative infinity
|
| + // represents zero power, and 0.0f represents maximum power.
|
| + typedef base::Callback<void(float)> PowerMeasurementCallback;
|
| +
|
| + // |sample_rate| is the audio signal sample rate (Hz). |measurement_period|
|
| + // represents the time length of audio signal to analyze before invoking the
|
| + // callback to report the current power level.
|
| + AudioPowerMonitor(int sample_rate,
|
| + const base::TimeDelta& measurement_period,
|
| + base::MessageLoop* message_loop,
|
| + const PowerMeasurementCallback& notify_power_level);
|
| +
|
| + ~AudioPowerMonitor();
|
| +
|
| + // Scan more |frames| of audio data from |buffer|. It is safe to call this
|
| + // from a real-time priority thread.
|
| + void Scan(const AudioBus* buffer, int frames);
|
| +
|
| + // dBFS value corresponding to zero power in the audio signal.
|
| + static const float kZeroPowerDBFS;
|
| + // dBFS value corresponding to maximum power in the audio signal.
|
| + static const float kMaxPowerDBFS;
|
| +
|
| + private:
|
| + void ResetScanAccumulations();
|
| +
|
| + // Number of audio frames to be scanned before reporting a power level
|
| + // measurement via callback.
|
| + const int num_frames_per_callback_;
|
| +
|
| + // MessageLoop and callback used to notify of the current power level.
|
| + base::MessageLoop* const message_loop_;
|
| + const PowerMeasurementCallback notify_power_level_;
|
| +
|
| + // Accumulations over one or more scans. Reset after each successful callback
|
| + // is made.
|
| + float sum_of_squares_so_far_;
|
| + int frames_so_far_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(AudioPowerMonitor);
|
| +};
|
| +
|
| +} // namespace media
|
| +
|
| +#endif // MEDIA_AUDIO_AUDIO_POWER_MONITOR_H_
|
|
|