Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: media/audio/audio_power_monitor.h

Issue 14600025: Replace AudioSilenceDetector with an AudioPowerMonitor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_AUDIO_AUDIO_POWER_MONITOR_H_
6 #define MEDIA_AUDIO_AUDIO_POWER_MONITOR_H_
7
8 #include "base/callback.h"
9 #include "media/base/media_export.h"
10
11 // An audio signal power monitor. It is periodically provided an AudioBus by
12 // the native audio thread, and the audio samples in each channel are analyzed
13 // to determine the average power of the signal over a time period. Here
14 // "average power" is defined as the RMS of the amplitudes, converted to dBFS
15 // (decibels relative to full-scale) units.
16 //
17 // Note that extreme care has been taken to make the AudioPowerMonitor::Scan()
18 // method safe to be called on the native audio thread. The code acquires no
19 // locks, nor engages in any operation that could result in an
20 // undetermined/unbounded amount of run-time.
21
22 namespace base {
23 class MessageLoop;
24 class TimeDelta;
25 }
26
27 namespace media {
28
29 class AudioBus;
30
31 class MEDIA_EXPORT AudioPowerMonitor {
32 public:
33 // Reports power level in terms of dBFS. This means negative infinity
34 // represents zero power, and 0.0f represents maximum power.
35 typedef base::Callback<void(float)> PowerMeasurementCallback;
36
37 // |sample_rate| is the audio signal sample rate (Hz). |measurement_period|
38 // represents the time length of audio signal to analyze before invoking the
39 // callback to report the current power level.
40 AudioPowerMonitor(int sample_rate,
41 const base::TimeDelta& measurement_period,
42 base::MessageLoop* message_loop,
43 const PowerMeasurementCallback& notify_power_level);
44
45 ~AudioPowerMonitor();
46
47 // Scan more |frames| of audio data from |buffer|. It is safe to call this
48 // from a real-time priority thread.
49 void Scan(const AudioBus* buffer, int frames);
50
51 // dBFS value corresponding to zero power in the audio signal.
52 static const float kZeroPowerDBFS;
53 // dBFS value corresponding to maximum power in the audio signal.
54 static const float kMaxPowerDBFS;
55
56 private:
57 void ResetScanAccumulations();
58
59 // Number of audio frames to be scanned before reporting a power level
60 // measurement via callback.
61 const int num_frames_per_callback_;
62
63 // MessageLoop and callback used to notify of the current power level.
64 base::MessageLoop* const message_loop_;
65 const PowerMeasurementCallback notify_power_level_;
66
67 // Accumulations over one or more scans. Reset after each successful callback
68 // is made.
69 float sum_of_squares_so_far_;
70 int frames_so_far_;
71
72 DISALLOW_COPY_AND_ASSIGN(AudioPowerMonitor);
73 };
74
75 } // namespace media
76
77 #endif // MEDIA_AUDIO_AUDIO_POWER_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698