Index: media/base/audio_hardware_config.cc |
diff --git a/media/base/audio_hardware_config.cc b/media/base/audio_hardware_config.cc |
index 65506ca8f05e144ddd4ca4eb2bdd0cce56eac103..d00e03f6b089334b19be067c96d6445ace1585d6 100644 |
--- a/media/base/audio_hardware_config.cc |
+++ b/media/base/audio_hardware_config.cc |
@@ -5,6 +5,7 @@ |
#include "media/base/audio_hardware_config.h" |
#include <algorithm> |
+#include <cmath> |
#include "base/logging.h" |
#include "build/build_config.h" |
@@ -14,11 +15,7 @@ using media::AudioParameters; |
namespace media { |
-#if defined(OS_LINUX) || defined(OS_MACOSX) |
-#define HIGH_LATENCY_AUDIO_SUPPORT 1 |
-#endif |
- |
-#if defined(HIGH_LATENCY_AUDIO_SUPPORT) |
+#if !defined(OS_WIN) |
// Taken from "Bit Twiddling Hacks" |
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 |
static uint32_t RoundUpToPowerOfTwo(uint32_t v) { |
@@ -102,9 +99,19 @@ void AudioHardwareConfig::UpdateOutputConfig( |
int AudioHardwareConfig::GetHighLatencyBufferSize() const { |
AutoLock auto_lock(config_lock_); |
-#if defined(HIGH_LATENCY_AUDIO_SUPPORT) |
- // Empirically, use the nearest higher power of two buffer size corresponding |
- // to 20 ms worth of samples. For a given sample rate, this works out to: |
+ |
+ // Empirically, we consider 20ms of samples to be high latency. |
+ const double twenty_ms_size = 2.0 * output_params_.sample_rate() / 100; |
+ |
+#if defined(OS_WIN) |
+ // Windows doesn't use power of two buffer sizes, so we should always round up |
+ // to the nearest multiple of the output buffer size. |
+ const int high_latency_buffer_size = |
+ std::ceil(twenty_ms_size / output_params_.frames_per_buffer()) * |
+ output_params_.frames_per_buffer(); |
+#else |
+ // On other platforms use the nearest higher power of two buffer size. For a |
+ // given sample rate, this works out to: |
// |
// <= 3200 : 64 |
// <= 6400 : 128 |
@@ -115,14 +122,11 @@ int AudioHardwareConfig::GetHighLatencyBufferSize() const { |
// <= 204800 : 4096 |
// |
// On Linux, the minimum hardware buffer size is 512, so the lower calculated |
- // values are unused. OSX may have a value as low as 128. Windows is device |
- // dependent but will generally be sample_rate() / 100. |
- const int high_latency_buffer_size = |
- RoundUpToPowerOfTwo(2 * output_params_.sample_rate() / 100); |
+ // values are unused. OSX may have a value as low as 128. |
+ const int high_latency_buffer_size = RoundUpToPowerOfTwo(twenty_ms_size); |
+#endif // defined(OS_WIN) |
+ |
return std::max(output_params_.frames_per_buffer(), high_latency_buffer_size); |
-#else |
- return output_params_.frames_per_buffer(); |
-#endif |
} |
} // namespace media |