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

Unified Diff: media/filters/audio_renderer_algorithm_ola.cc

Issue 164031: Mute audio under OLA when given rate would cause poor quality. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/audio_renderer_algorithm_ola.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/audio_renderer_algorithm_ola.cc
===================================================================
--- media/filters/audio_renderer_algorithm_ola.cc (revision 22918)
+++ media/filters/audio_renderer_algorithm_ola.cc (working copy)
@@ -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 @@
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 @@
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_)
« no previous file with comments | « media/filters/audio_renderer_algorithm_ola.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698