Commit 985bcdc8 authored by xians@chromium.org's avatar xians@chromium.org

Use the absolute magnitude instead of the bar level as the level of the input signal.


NOTRY=true
BUG=357566

Review URL: https://codereview.chromium.org/216773003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260212 0039d316-1c4b-4281-b951-d872f2087c98
parent 102a446f
......@@ -42,12 +42,6 @@ int MediaStreamAudioLevelCalculator::Calculate(const int16* audio_data,
int number_of_channels,
int number_of_frames) {
DCHECK(thread_checker_.CalledOnValidThread());
// Permutation of bars that reprents the amplitude level of the audio signal.
// The number of elements is 33 because we are indexing them in the range of
// [0, 32].
static const int kPermutation[33] =
{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};
// |level_| is updated every 10 callbacks. For the case where callback comes
// every 10ms, |level_| will be updated approximately every 100ms.
static const int kUpdateFrequency = 10;
......@@ -56,18 +50,7 @@ int MediaStreamAudioLevelCalculator::Calculate(const int16* audio_data,
max_amplitude_ = std::max(max_amplitude_, max);
if (counter_++ == kUpdateFrequency) {
// Divide the max amplitude (32768) by 1000 to get in the range of [0,32]
// which is the range of the permutation array.
int index = static_cast<int>(max_amplitude_ / 1000);
// Make it less likely that the bar stays at position 0. I.e. only if
// its in the range 0-250 (instead of 0-1000)
if (index == 0 && max_amplitude_ > 250)
index = 1;
// |level_| will be the value in the permutation array that the |index| is
// pointing to.
level_ = kPermutation[index];
level_ = max_amplitude_;
// Decay the absolute maximum amplitude by 1/4.
max_amplitude_ >>= 2;
......
......@@ -20,8 +20,7 @@ class MediaStreamAudioLevelCalculator {
~MediaStreamAudioLevelCalculator();
// Calculates the signal level of the audio data.
// Returns the level of bars that the volume animation UI uses for
// presenting the energy level of the audio data.
// Returns the absolute value of the amplitude of the signal.
int Calculate(const int16* audio_data, int number_of_channels,
int number_of_frames);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment