diff options
author | vrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-23 19:16:35 +0000 |
---|---|---|
committer | vrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-23 19:16:35 +0000 |
commit | 0d9e8ca63187c8167076f6e70b2c1b8c5dd3b96e (patch) | |
tree | 1afb78f2e330cef022dd8f02cdcb5fc7cf4f6f99 /media/audio/audio_util.cc | |
parent | 8f6304e029f9c57ebfc2dbce56ee66104cfc1070 (diff) | |
download | chromium_src-0d9e8ca63187c8167076f6e70b2c1b8c5dd3b96e.zip chromium_src-0d9e8ca63187c8167076f6e70b2c1b8c5dd3b96e.tar.gz chromium_src-0d9e8ca63187c8167076f6e70b2c1b8c5dd3b96e.tar.bz2 |
Increase the buffer size in AudioRendererImpl to fix muted playback rate
This CL temporarily removes GetBufferSizeForSampleRate() and uses
SelectSamplesPerPacket() to determine the size of samples_per_packet in
AudioDevice. This restores the buffer size that AudioRendererImpl
used prior to r113821. SelectSamplesPerPacket() calculates a much larger
samples_per_packet value than GetBufferSizeForSampleRate(), so it fixes
the issue described in 108239.
This CL also does some mild refactoring to move audio_common.cc into
audio_util.cc.
BUG=108239
TEST=media_unittests,content_unittests, manual testing of different playback rates
Review URL: https://chromiumcodereview.appspot.com/9416085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123292 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_util.cc')
-rw-r--r-- | media/audio/audio_util.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc index b4b87518..8caced5 100644 --- a/media/audio/audio_util.cc +++ b/media/audio/audio_util.cc @@ -14,9 +14,11 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/shared_memory.h" +#include "base/time.h" #if defined(OS_WIN) #include "base/win/windows_version.h" #endif +#include "media/audio/audio_parameters.h" #include "media/audio/audio_util.h" #if defined(OS_MACOSX) #include "media/audio/mac/audio_low_latency_input_mac.h" @@ -436,4 +438,29 @@ void Crossfade(int bytes_to_crossfade, int number_of_channels, } } +// The minimum number of samples in a hardware packet. +// This value is selected so that we can handle down to 5khz sample rate. +static const int kMinSamplesPerHardwarePacket = 1024; + +// The maximum number of samples in a hardware packet. +// This value is selected so that we can handle up to 192khz sample rate. +static const int kMaxSamplesPerHardwarePacket = 64 * 1024; + +// This constant governs the hardware audio buffer size, this value should be +// chosen carefully. +// This value is selected so that we have 8192 samples for 48khz streams. +static const int kMillisecondsPerHardwarePacket = 170; + +uint32 SelectSamplesPerPacket(int sample_rate) { + // Select the number of samples that can provide at least + // |kMillisecondsPerHardwarePacket| worth of audio data. + int samples = kMinSamplesPerHardwarePacket; + while (samples <= kMaxSamplesPerHardwarePacket && + samples * base::Time::kMillisecondsPerSecond < + sample_rate * kMillisecondsPerHardwarePacket) { + samples *= 2; + } + return samples; +} + } // namespace media |