summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authordalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-23 01:03:37 +0000
committerdalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-23 01:03:37 +0000
commit771980b7451d31243892928be881796e13cefb7b (patch)
tree6e547e1f112f80c08fb4b626e30c25861b70aa34 /media
parent55c9f7c311c4103356f43a36656cf1e0e42f1f1f (diff)
downloadchromium_src-771980b7451d31243892928be881796e13cefb7b.zip
chromium_src-771980b7451d31243892928be881796e13cefb7b.tar.gz
chromium_src-771980b7451d31243892928be881796e13cefb7b.tar.bz2
Select OSX buffer size based on sample rate.
Similar to what we do on Windows. The default buffer size is too small for higher sample rates. BUG=179058 TEST=audio playback sounds correct. Review URL: https://codereview.chromium.org/12662043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189965 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/audio/mac/audio_low_latency_input_mac.cc6
-rw-r--r--media/audio/mac/audio_manager_mac.cc33
2 files changed, 28 insertions, 11 deletions
diff --git a/media/audio/mac/audio_low_latency_input_mac.cc b/media/audio/mac/audio_low_latency_input_mac.cc
index 972ae39..c1d9866 100644
--- a/media/audio/mac/audio_low_latency_input_mac.cc
+++ b/media/audio/mac/audio_low_latency_input_mac.cc
@@ -497,17 +497,13 @@ OSStatus AUAudioInputStream::Provide(UInt32 number_of_frames,
if (!audio_data)
return kAudioUnitErr_InvalidElement;
- // See http://crbug.com/154352 for details.
- CHECK_EQ(number_of_frames, static_cast<UInt32>(number_of_frames_));
-
// Accumulate captured audio in FIFO until we can match the output size
// requested by the client.
- DCHECK_LE(fifo_->forward_bytes(), requested_size_bytes_);
fifo_->Append(audio_data, buffer.mDataByteSize);
// Deliver recorded data to the client as soon as the FIFO contains a
// sufficient amount.
- if (fifo_->forward_bytes() >= requested_size_bytes_) {
+ while (fifo_->forward_bytes() >= requested_size_bytes_) {
// Read from FIFO into temporary data buffer.
fifo_->Read(data_->GetWritableData(), requested_size_bytes_);
diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc
index 1520be5..93dbcc9 100644
--- a/media/audio/mac/audio_manager_mac.cc
+++ b/media/audio/mac/audio_manager_mac.cc
@@ -32,6 +32,23 @@ static const int kMaxOutputStreams = 50;
// Default buffer size in samples for low-latency input and output streams.
static const int kDefaultLowLatencyBufferSize = 128;
+static int ChooseBufferSize(int output_sample_rate) {
+ int buffer_size = kDefaultLowLatencyBufferSize;
+ const int user_buffer_size = GetUserBufferSize();
+ if (user_buffer_size) {
+ buffer_size = user_buffer_size;
+ } else if (output_sample_rate > 48000) {
+ // The default buffer size is too small for higher sample rates and may lead
+ // to glitching. Adjust upwards by multiples of the default size.
+ if (output_sample_rate <= 96000)
+ buffer_size = 2 * kDefaultLowLatencyBufferSize;
+ else if (output_sample_rate <= 192000)
+ buffer_size = 4 * kDefaultLowLatencyBufferSize;
+ }
+
+ return buffer_size;
+}
+
static bool HasAudioHardware(AudioObjectPropertySelector selector) {
AudioDeviceID output_device_id = kAudioObjectUnknown;
const AudioObjectPropertyAddress property_address = {
@@ -370,11 +387,17 @@ void AudioManagerMac::GetAudioInputDeviceNames(
AudioParameters AudioManagerMac::GetInputStreamParameters(
const std::string& device_id) {
+ // Due to the sharing of the input and output buffer sizes, we need to choose
+ // the input buffer size based on the output sample rate. See
+ // http://crbug.com/154352.
+ const int buffer_size = ChooseBufferSize(
+ AUAudioOutputStream::HardwareSampleRate());
+
// TODO(xians): query the native channel layout for the specific device.
return AudioParameters(
AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
AUAudioInputStream::HardwareSampleRate(), 16,
- kDefaultLowLatencyBufferSize);
+ buffer_size);
}
AudioOutputStream* AudioManagerMac::MakeLinearOutputStream(
@@ -430,10 +453,8 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
ChannelLayout channel_layout = GuessChannelLayout(hardware_channels);
- int buffer_size = kDefaultLowLatencyBufferSize;
- int user_buffer_size = GetUserBufferSize();
- if (user_buffer_size)
- buffer_size = user_buffer_size;
+ const int hardware_sample_rate = AUAudioOutputStream::HardwareSampleRate();
+ const int buffer_size = ChooseBufferSize(hardware_sample_rate);
int input_channels = 0;
if (input_params.IsValid()) {
@@ -452,7 +473,7 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
AudioParameters::AUDIO_PCM_LOW_LATENCY,
channel_layout,
input_channels,
- AUAudioOutputStream::HardwareSampleRate(),
+ hardware_sample_rate,
16,
buffer_size);