summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorkylep@chromium.org <kylep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-10 23:58:28 +0000
committerkylep@chromium.org <kylep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-10 23:58:28 +0000
commitc1641569cbca3b06fa39abbaf16b2fb879514794 (patch)
treea37a84736adb0ee7593c988ac0b23e7229d760a0 /media
parent73f5b3628564ad8162a3901cb672264eb71ef970 (diff)
downloadchromium_src-c1641569cbca3b06fa39abbaf16b2fb879514794.zip
chromium_src-c1641569cbca3b06fa39abbaf16b2fb879514794.tar.gz
chromium_src-c1641569cbca3b06fa39abbaf16b2fb879514794.tar.bz2
Mute audio under OLA when given rate would cause poor quality.
BUG=18362 TEST=none Review URL: http://codereview.chromium.org/164031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22974 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/filters/audio_renderer_algorithm_ola.cc20
-rw-r--r--media/filters/audio_renderer_algorithm_ola.h4
2 files changed, 21 insertions, 3 deletions
diff --git a/media/filters/audio_renderer_algorithm_ola.cc b/media/filters/audio_renderer_algorithm_ola.cc
index 7d959a1..1d22d11 100644
--- a/media/filters/audio_renderer_algorithm_ola.cc
+++ b/media/filters/audio_renderer_algorithm_ola.cc
@@ -4,6 +4,7 @@
#include "media/filters/audio_renderer_algorithm_ola.h"
+#include <algorithm>
#include <cmath>
#include "media/base/buffers.h"
@@ -14,6 +15,11 @@ namespace media {
const double kDefaultWindowLength = 0.08;
const double kDefaultCrossfadeLength = 0.008;
+// Default mute ranges for fast/slow audio. These rates would sound better
+// under a frequency domain algorithm.
+const float kMinRate = 0.75f;
+const float kMaxRate = 4.0f;
+
AudioRendererAlgorithmOLA::AudioRendererAlgorithmOLA()
: input_step_(0),
output_step_(0),
@@ -41,9 +47,19 @@ size_t AudioRendererAlgorithmOLA::FillBuffer(uint8* dest, size_t length) {
return dest_written;
}
+ // Mute when out of acceptable quality range. Note: This may not play at the
+ // speed requested as we can only consume as much data as we have, and audio
+ // timestamps drive the pipeline clock.
+ if (playback_rate() < kMinRate || playback_rate() > kMaxRate) {
+ size_t consume = static_cast<size_t>(length * playback_rate());
+ size_t safe_to_consume = std::min(QueueSize(), consume);
+ memset(dest, 0, length);
+ AlignToSampleBoundary(&safe_to_consume);
+ AdvanceInputPosition(safe_to_consume);
+ return length;
+ }
+
// For other playback rates, OLA with crossfade!
- // TODO(kylep): Limit the rates to reasonable values. We may want to do this
- // on the UI side or in set_playback_rate().
while (length >= output_step_ + crossfade_size_) {
// If we don't have enough data to completely finish this loop, quit.
if (QueueSize() < window_size_)
diff --git a/media/filters/audio_renderer_algorithm_ola.h b/media/filters/audio_renderer_algorithm_ola.h
index c38374bf..eb23a9a 100644
--- a/media/filters/audio_renderer_algorithm_ola.h
+++ b/media/filters/audio_renderer_algorithm_ola.h
@@ -7,7 +7,9 @@
// consumes more input data than output data requested and crossfades samples
// to fill |buffer_out|. For speeds less than 1.0f, FillBuffer() consumers less
// input data than output data requested and draws overlapping samples from the
-// input data to fill |buffer_out|. As ARAB is thread-unsafe, so is ARAO.
+// input data to fill |buffer_out|. ARAO will mute the audio for very high or
+// very low playback rates to preserve quality. As ARAB is thread-unsafe, so is
+// ARAO.
#ifndef MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_OLA_H_
#define MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_OLA_H_