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

Side by Side Diff: content/renderer/media/media_stream_audio_level_calculator.cc

Issue 1703473002: Make AudioOutputDevice restartable and reinitializable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new_mixing
Patch Set: Created 4 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/media/media_stream_audio_level_calculator.h" 5 #include "content/renderer/media/media_stream_audio_level_calculator.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 21 matching lines...) Expand all
32 : counter_(0), 32 : counter_(0),
33 max_amplitude_(0.0f), 33 max_amplitude_(0.0f),
34 level_(0.0f) { 34 level_(0.0f) {
35 } 35 }
36 36
37 MediaStreamAudioLevelCalculator::~MediaStreamAudioLevelCalculator() { 37 MediaStreamAudioLevelCalculator::~MediaStreamAudioLevelCalculator() {
38 } 38 }
39 39
40 float MediaStreamAudioLevelCalculator::Calculate( 40 float MediaStreamAudioLevelCalculator::Calculate(
41 const media::AudioBus& audio_bus) { 41 const media::AudioBus& audio_bus) {
42 DCHECK(thread_checker_.CalledOnValidThread()); 42 // DCHECK(thread_checker_.CalledOnValidThread());
43 // |level_| is updated every 10 callbacks. For the case where callback comes 43 // |level_| is updated every 10 callbacks. For the case where callback comes
44 // every 10ms, |level_| will be updated approximately every 100ms. 44 // every 10ms, |level_| will be updated approximately every 100ms.
45 static const int kUpdateFrequency = 10; 45 static const int kUpdateFrequency = 10;
46 46
47 float max = 0.0f; 47 float max = 0.0f;
48 for (int i = 0; i < audio_bus.channels(); ++i) { 48 for (int i = 0; i < audio_bus.channels(); ++i) {
49 const float max_this_channel = 49 const float max_this_channel =
50 MaxAmplitude(audio_bus.channel(i), audio_bus.frames()); 50 MaxAmplitude(audio_bus.channel(i), audio_bus.frames());
51 if (max_this_channel > max) 51 if (max_this_channel > max)
52 max = max_this_channel; 52 max = max_this_channel;
53 } 53 }
54 max_amplitude_ = std::max(max_amplitude_, max); 54 max_amplitude_ = std::max(max_amplitude_, max);
55 55
56 if (counter_++ == kUpdateFrequency) { 56 if (counter_++ == kUpdateFrequency) {
57 level_ = max_amplitude_; 57 level_ = max_amplitude_;
58 58
59 // Decay the absolute maximum amplitude by 1/4. 59 // Decay the absolute maximum amplitude by 1/4.
60 max_amplitude_ /= 4.0f; 60 max_amplitude_ /= 4.0f;
61 61
62 // Reset the counter. 62 // Reset the counter.
63 counter_ = 0; 63 counter_ = 0;
64 } 64 }
65 65
66 return level_; 66 return level_;
67 } 67 }
68 68
69 } // namespace content 69 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698