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

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

Issue 669393002: Merge 661693003 to M39: Avoid reporting 0 as input level when AudioProcessing zero out the audio da… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2171
Patch Set: Created 6 years, 2 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 9
10 namespace content { 10 namespace content {
(...skipping 20 matching lines...) Expand all
31 31
32 MediaStreamAudioLevelCalculator::MediaStreamAudioLevelCalculator() 32 MediaStreamAudioLevelCalculator::MediaStreamAudioLevelCalculator()
33 : counter_(0), 33 : counter_(0),
34 max_amplitude_(0), 34 max_amplitude_(0),
35 level_(0) { 35 level_(0) {
36 } 36 }
37 37
38 MediaStreamAudioLevelCalculator::~MediaStreamAudioLevelCalculator() { 38 MediaStreamAudioLevelCalculator::~MediaStreamAudioLevelCalculator() {
39 } 39 }
40 40
41 int MediaStreamAudioLevelCalculator::Calculate(const int16* audio_data, 41 int MediaStreamAudioLevelCalculator::Calculate(
42 int number_of_channels, 42 const int16* audio_data,
43 int number_of_frames) { 43 int number_of_channels,
44 int number_of_frames,
45 bool force_report_nonzero_energy) {
44 DCHECK(thread_checker_.CalledOnValidThread()); 46 DCHECK(thread_checker_.CalledOnValidThread());
45 // |level_| is updated every 10 callbacks. For the case where callback comes 47 // |level_| is updated every 10 callbacks. For the case where callback comes
46 // every 10ms, |level_| will be updated approximately every 100ms. 48 // every 10ms, |level_| will be updated approximately every 100ms.
47 static const int kUpdateFrequency = 10; 49 static const int kUpdateFrequency = 10;
48 50
49 int max = MaxAmplitude(audio_data, number_of_channels * number_of_frames); 51 int max = MaxAmplitude(audio_data, number_of_channels * number_of_frames);
50 max_amplitude_ = std::max(max_amplitude_, max); 52 max_amplitude_ = std::max(max_amplitude_, max);
51 53
52 if (counter_++ == kUpdateFrequency) { 54 if (counter_++ == kUpdateFrequency) {
53 level_ = max_amplitude_; 55 level_ = (max_amplitude_ == 0 ?
56 force_report_nonzero_energy : max_amplitude_);
54 57
55 // Decay the absolute maximum amplitude by 1/4. 58 // Decay the absolute maximum amplitude by 1/4.
56 max_amplitude_ >>= 2; 59 max_amplitude_ >>= 2;
57 60
58 // Reset the counter. 61 // Reset the counter.
59 counter_ = 0; 62 counter_ = 0;
60 } 63 }
61 64
62 return level_; 65 return level_;
63 } 66 }
64 67
65 } // namespace content 68 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_audio_level_calculator.h ('k') | content/renderer/media/webaudio_capturer_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698