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

Unified Diff: media/filters/audio_renderer_algorithm_ola.cc

Issue 157001: Modify OLA to use window size in seconds instead of bytes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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') | media/tools/wav_ola_test.cc » ('j') | 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 20385)
+++ media/filters/audio_renderer_algorithm_ola.cc (working copy)
@@ -11,13 +11,14 @@
namespace media {
-// Default window size in bytes.
-// TODO(kylep): base the window size in seconds, not bytes.
-const size_t kDefaultWindowSize = 4096;
+// Default window and crossfade lengths in seconds.
+const double kDefaultWindowLength = 0.08;
+const double kDefaultCrossfadeLength = 0.008;
AudioRendererAlgorithmOLA::AudioRendererAlgorithmOLA()
: input_step_(0),
- output_step_(0) {
+ output_step_(0),
+ window_size_(0) {
}
AudioRendererAlgorithmOLA::~AudioRendererAlgorithmOLA() {
@@ -47,7 +48,7 @@
// on the UI side or in set_playback_rate().
while (dest_remaining >= output_step_ + crossfade_size_) {
// If we don't have enough data to completely finish this loop, quit.
- if (QueueSize() < kDefaultWindowSize)
+ if (QueueSize() < window_size_)
break;
// Copy bulk of data to output (including some to crossfade to the next
@@ -89,7 +90,7 @@
// Advance pointers again.
AdvanceInputPosition(crossfade_size);
- dest += crossfade_size;
+ dest += crossfade_size_;
}
return dest_written;
}
@@ -97,21 +98,32 @@
void AudioRendererAlgorithmOLA::set_playback_rate(float new_rate) {
AudioRendererAlgorithmBase::set_playback_rate(new_rate);
+ // Calculate the window size from our default length and our audio properties.
+ // Precision is not an issue because we will round this to a sample boundary.
+ // This will not overflow because each parameter is checked in Initialize().
+ window_size_ = static_cast<size_t>(sample_rate()
+ * sample_bytes()
+ * channels()
+ * kDefaultWindowLength);
+
// Adjusting step sizes to accomodate requested playback rate.
if (playback_rate() > 1.0f) {
- input_step_ = kDefaultWindowSize;
+ input_step_ = window_size_;
output_step_ = static_cast<size_t>(ceil(
- static_cast<float>(kDefaultWindowSize / playback_rate())));
+ static_cast<float>(window_size_ / playback_rate())));
} else {
input_step_ = static_cast<size_t>(ceil(
- static_cast<float>(kDefaultWindowSize * playback_rate())));
- output_step_ = kDefaultWindowSize;
+ static_cast<float>(window_size_ * playback_rate())));
+ output_step_ = window_size_;
}
AlignToSampleBoundary(&input_step_);
AlignToSampleBoundary(&output_step_);
// Calculate length for crossfading.
- crossfade_size_ = kDefaultWindowSize / 10;
+ crossfade_size_ = static_cast<size_t>(sample_rate()
+ * sample_bytes()
+ * channels()
+ * kDefaultCrossfadeLength);
AlignToSampleBoundary(&crossfade_size_);
// To keep true to playback rate, modify the steps.
« no previous file with comments | « media/filters/audio_renderer_algorithm_ola.h ('k') | media/tools/wav_ola_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698