From 31c7eb5c552482cc782b1599c94532cecf09851a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 23 Nov 2020 10:40:20 -0800 Subject: Fix capture buffer size scaling in CoreAudio --- alc/backends/coreaudio.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'alc/backends') diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 60103f51..6ec0f3ab 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -550,13 +550,13 @@ void CoreAudioCapture::open(const ALCchar *name) throw al::backend_exception{ALC_INVALID_VALUE, "Could not set input format: %u", err}; /* Calculate the minimum AudioUnit output format frame count for the pre- - * conversion ring buffer. + * conversion ring buffer. Ensure at least 100ms for the total buffer. */ - uint64_t FrameCount64{mDevice->UpdateSize}; - FrameCount64 = FrameCount64*static_cast(outputFormat.mSampleRate) + (mDevice->Frequency-1) / - mDevice->Frequency; + double srateScale{double{outputFormat.mSampleRate} / mDevice->Frequency}; + auto FrameCount64 = maxu64(static_cast(mDevice->BufferSize*srateScale + 0.5), + static_cast(outputFormat.mSampleRate)/10); FrameCount64 += MAX_RESAMPLER_PADDING; - if(FrameCount64 > std::numeric_limits::max()/2) + if(FrameCount64 > std::numeric_limits::max()) throw al::backend_exception{ALC_INVALID_VALUE, "Calculated frame count is too large: %" PRIu64, FrameCount64}; -- cgit v1.2.3