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

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

Issue 216773003: Use the absolute magnitude instead of the bar level as the level of the input signal (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 8 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
« no previous file with comments | « content/renderer/media/media_stream_audio_level_calculator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 24 matching lines...) Expand all
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(const int16* audio_data,
42 int number_of_channels, 42 int number_of_channels,
43 int number_of_frames) { 43 int number_of_frames) {
44 DCHECK(thread_checker_.CalledOnValidThread()); 44 DCHECK(thread_checker_.CalledOnValidThread());
45 // Permutation of bars that reprents the amplitude level of the audio signal.
46 // The number of elements is 33 because we are indexing them in the range of
47 // [0, 32].
48 static const int kPermutation[33] =
no longer working on chromium 2014/03/28 10:30:34 Tommi, it turns out that libjingle uses _currentLe
tommi (sloooow) - chröme 2014/03/28 11:57:02 great :)
49 {0,1,2,3,4,4,5,5,5,5,6,6,6,6,6,7,7,7,7,8,8,8,9,9,9,9,9,9,9,9,9,9,9};
50
51 // |level_| is updated every 10 callbacks. For the case where callback comes 45 // |level_| is updated every 10 callbacks. For the case where callback comes
52 // every 10ms, |level_| will be updated approximately every 100ms. 46 // every 10ms, |level_| will be updated approximately every 100ms.
53 static const int kUpdateFrequency = 10; 47 static const int kUpdateFrequency = 10;
54 48
55 int max = MaxAmplitude(audio_data, number_of_channels * number_of_frames); 49 int max = MaxAmplitude(audio_data, number_of_channels * number_of_frames);
56 max_amplitude_ = std::max(max_amplitude_, max); 50 max_amplitude_ = std::max(max_amplitude_, max);
57 51
58 if (counter_++ == kUpdateFrequency) { 52 if (counter_++ == kUpdateFrequency) {
59 // Divide the max amplitude (32768) by 1000 to get in the range of [0,32] 53 level_ = max_amplitude_;
60 // which is the range of the permutation array.
61 int index = static_cast<int>(max_amplitude_ / 1000);
62
63 // Make it less likely that the bar stays at position 0. I.e. only if
64 // its in the range 0-250 (instead of 0-1000)
65 if (index == 0 && max_amplitude_ > 250)
66 index = 1;
67
68 // |level_| will be the value in the permutation array that the |index| is
69 // pointing to.
70 level_ = kPermutation[index];
71 54
72 // Decay the absolute maximum amplitude by 1/4. 55 // Decay the absolute maximum amplitude by 1/4.
73 max_amplitude_ >>= 2; 56 max_amplitude_ >>= 2;
74 57
75 // Reset the counter. 58 // Reset the counter.
76 counter_ = 0; 59 counter_ = 0;
77 } 60 }
78 61
79 return level_; 62 return level_;
80 } 63 }
81 64
82 } // namespace content 65 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_audio_level_calculator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698