Commit 915bb8a0 authored by scherkus@chromium.org's avatar scherkus@chromium.org

Revert 258215 "Remove muting for extreme playbackRates."

It exposed a bug in the WSOLA algorithm that causes it to incorrectly
trigger underflows.

> Remove muting for extreme playbackRates.
> 
> Audio was muted below 0.5x and above 4x as the quality degraded
> significantly under the crossfade algorithm. The quality is now much
> better under the WSLOA algorithm (r220343).
> 
> BUG=289354
> R=scherkus@chromium.org
> R=dalecurtis@chromium.org
> 
> Review URL: https://codereview.chromium.org/205093002

BUG=368083
TBR=sandersd@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274701 0039d316-1c4b-4281-b951-d872f2087c98
parent 8d8f030f
...@@ -46,6 +46,12 @@ namespace media { ...@@ -46,6 +46,12 @@ namespace media {
// |search_block_index_| = |search_block_center_offset_| - // |search_block_index_| = |search_block_center_offset_| -
// |search_block_center_offset_|. // |search_block_center_offset_|.
// Max/min supported playback rates for fast/slow audio. Audio outside of these
// ranges are muted.
// Audio at these speeds would sound better under a frequency domain algorithm.
static const float kMinPlaybackRate = 0.5f;
static const float kMaxPlaybackRate = 4.0f;
// Overlap-and-add window size in milliseconds. // Overlap-and-add window size in milliseconds.
static const int kOlaWindowSizeMs = 20; static const int kOlaWindowSizeMs = 20;
...@@ -70,6 +76,8 @@ AudioRendererAlgorithm::AudioRendererAlgorithm() ...@@ -70,6 +76,8 @@ AudioRendererAlgorithm::AudioRendererAlgorithm()
: channels_(0), : channels_(0),
samples_per_second_(0), samples_per_second_(0),
playback_rate_(0), playback_rate_(0),
muted_(false),
muted_partial_frame_(0),
capacity_(kStartingBufferSizeInFrames), capacity_(kStartingBufferSizeInFrames),
output_time_(0.0), output_time_(0.0),
search_block_center_offset_(0), search_block_center_offset_(0),
...@@ -143,6 +151,31 @@ int AudioRendererAlgorithm::FillBuffer(AudioBus* dest, int requested_frames) { ...@@ -143,6 +151,31 @@ int AudioRendererAlgorithm::FillBuffer(AudioBus* dest, int requested_frames) {
DCHECK_EQ(channels_, dest->channels()); DCHECK_EQ(channels_, dest->channels());
// Optimize the |muted_| case to issue a single clear instead of performing
// the full crossfade and clearing each crossfaded frame.
if (muted_) {
int frames_to_render =
std::min(static_cast<int>(audio_buffer_.frames() / playback_rate_),
requested_frames);
// Compute accurate number of frames to actually skip in the source data.
// Includes the leftover partial frame from last request. However, we can
// only skip over complete frames, so a partial frame may remain for next
// time.
muted_partial_frame_ += frames_to_render * playback_rate_;
int seek_frames = static_cast<int>(muted_partial_frame_);
dest->ZeroFrames(frames_to_render);
audio_buffer_.SeekFrames(seek_frames);
// Determine the partial frame that remains to be skipped for next call. If
// the user switches back to playing, it may be off time by this partial
// frame, which would be undetectable. If they subsequently switch to
// another playback rate that mutes, the code will attempt to line up the
// frames again.
muted_partial_frame_ -= seek_frames;
return frames_to_render;
}
int slower_step = ceil(ola_window_size_ * playback_rate_); int slower_step = ceil(ola_window_size_ * playback_rate_);
int faster_step = ceil(ola_window_size_ / playback_rate_); int faster_step = ceil(ola_window_size_ / playback_rate_);
...@@ -167,6 +200,8 @@ int AudioRendererAlgorithm::FillBuffer(AudioBus* dest, int requested_frames) { ...@@ -167,6 +200,8 @@ int AudioRendererAlgorithm::FillBuffer(AudioBus* dest, int requested_frames) {
void AudioRendererAlgorithm::SetPlaybackRate(float new_rate) { void AudioRendererAlgorithm::SetPlaybackRate(float new_rate) {
DCHECK_GE(new_rate, 0); DCHECK_GE(new_rate, 0);
playback_rate_ = new_rate; playback_rate_ = new_rate;
muted_ =
playback_rate_ < kMinPlaybackRate || playback_rate_ > kMaxPlaybackRate;
} }
void AudioRendererAlgorithm::FlushBuffers() { void AudioRendererAlgorithm::FlushBuffers() {
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
// are preserved. See audio_renderer_algorith.cc for a more elaborate // are preserved. See audio_renderer_algorith.cc for a more elaborate
// description of the algorithm. // description of the algorithm.
// //
// Audio at very low or very high playback rates are muted to preserve quality.
//
#ifndef MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ #ifndef MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_
#define MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ #define MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_
...@@ -82,6 +84,9 @@ class MEDIA_EXPORT AudioRendererAlgorithm { ...@@ -82,6 +84,9 @@ class MEDIA_EXPORT AudioRendererAlgorithm {
// Returns the samples per second for this audio stream. // Returns the samples per second for this audio stream.
int samples_per_second() { return samples_per_second_; } int samples_per_second() { return samples_per_second_; }
// Is the sound currently muted?
bool is_muted() { return muted_; }
private: private:
// Within |search_block_|, find the block of data that is most similar to // Within |search_block_|, find the block of data that is most similar to
// |target_block_|, and write it in |optimal_block_|. This method assumes that // |target_block_|, and write it in |optimal_block_|. This method assumes that
...@@ -135,6 +140,12 @@ class MEDIA_EXPORT AudioRendererAlgorithm { ...@@ -135,6 +140,12 @@ class MEDIA_EXPORT AudioRendererAlgorithm {
// Buffered audio data. // Buffered audio data.
AudioBufferQueue audio_buffer_; AudioBufferQueue audio_buffer_;
// True if the audio should be muted.
bool muted_;
// If muted, keep track of partial frames that should have been skipped over.
double muted_partial_frame_;
// How many frames to have in the queue before we report the queue is full. // How many frames to have in the queue before we report the queue is full.
int capacity_; int capacity_;
......
...@@ -151,7 +151,7 @@ class AudioRendererAlgorithmTest : public testing::Test { ...@@ -151,7 +151,7 @@ class AudioRendererAlgorithmTest : public testing::Test {
bool all_zero = true; bool all_zero = true;
for (int i = 0; i < frames_written && all_zero; ++i) for (int i = 0; i < frames_written && all_zero; ++i)
all_zero = audio_data->channel(ch)[i] == 0.0f; all_zero = audio_data->channel(ch)[i] == 0.0f;
ASSERT_FALSE(all_zero) << " for channel " << ch; ASSERT_EQ(algorithm_.is_muted(), all_zero) << " for channel " << ch;
} }
} }
......
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