mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
PulseAudio: Use a bigger default buffer size.
Public issue https://github.com/mackron/miniaudio/issues/427
This commit is contained in:
+28
-2
@@ -28777,6 +28777,32 @@ static void ma_device_on_rerouted__pulse(ma_pa_stream* pStream, void* pUserData)
|
||||
ma_device__on_notification_rerouted(pDevice);
|
||||
}
|
||||
|
||||
static ma_uint32 ma_calculate_period_size_in_frames_from_descriptor__pulse(const ma_device_descriptor* pDescriptor, ma_uint32 nativeSampleRate, ma_performance_profile performanceProfile)
|
||||
{
|
||||
/*
|
||||
There have been reports from users where buffers of < ~20ms result glitches when running through
|
||||
PipeWire. To work around this we're going to have to use a different default buffer size.
|
||||
*/
|
||||
const ma_uint32 defaultPeriodSizeInMilliseconds_LowLatency = 25;
|
||||
const ma_uint32 defaultPeriodSizeInMilliseconds_Conservative = MA_DEFAULT_PERIOD_SIZE_IN_MILLISECONDS_CONSERVATIVE;
|
||||
|
||||
MA_ASSERT(nativeSampleRate != 0);
|
||||
|
||||
if (pDescriptor->periodSizeInFrames == 0) {
|
||||
if (pDescriptor->periodSizeInMilliseconds == 0) {
|
||||
if (performanceProfile == ma_performance_profile_low_latency) {
|
||||
return ma_calculate_buffer_size_in_frames_from_milliseconds(defaultPeriodSizeInMilliseconds_LowLatency, nativeSampleRate);
|
||||
} else {
|
||||
return ma_calculate_buffer_size_in_frames_from_milliseconds(defaultPeriodSizeInMilliseconds_Conservative, nativeSampleRate);
|
||||
}
|
||||
} else {
|
||||
return ma_calculate_buffer_size_in_frames_from_milliseconds(pDescriptor->periodSizeInMilliseconds, nativeSampleRate);
|
||||
}
|
||||
} else {
|
||||
return pDescriptor->periodSizeInFrames;
|
||||
}
|
||||
}
|
||||
|
||||
static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_config* pConfig, ma_device_descriptor* pDescriptorPlayback, ma_device_descriptor* pDescriptorCapture)
|
||||
{
|
||||
/*
|
||||
@@ -28882,7 +28908,7 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
|
||||
}
|
||||
|
||||
/* We now have enough information to calculate our actual period size in frames. */
|
||||
pDescriptorCapture->periodSizeInFrames = ma_calculate_buffer_size_in_frames_from_descriptor(pDescriptorCapture, ss.rate, pConfig->performanceProfile);
|
||||
pDescriptorCapture->periodSizeInFrames = ma_calculate_period_size_in_frames_from_descriptor__pulse(pDescriptorCapture, ss.rate, pConfig->performanceProfile);
|
||||
|
||||
attr = ma_device__pa_buffer_attr_new(pDescriptorCapture->periodSizeInFrames, pDescriptorCapture->periodCount, &ss);
|
||||
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[PulseAudio] Capture attr: maxlength=%d, tlength=%d, prebuf=%d, minreq=%d, fragsize=%d; periodSizeInFrames=%d\n", attr.maxlength, attr.tlength, attr.prebuf, attr.minreq, attr.fragsize, pDescriptorCapture->periodSizeInFrames);
|
||||
@@ -29018,7 +29044,7 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
|
||||
}
|
||||
|
||||
/* We now have enough information to calculate the actual buffer size in frames. */
|
||||
pDescriptorPlayback->periodSizeInFrames = ma_calculate_buffer_size_in_frames_from_descriptor(pDescriptorPlayback, ss.rate, pConfig->performanceProfile);
|
||||
pDescriptorPlayback->periodSizeInFrames = ma_calculate_period_size_in_frames_from_descriptor__pulse(pDescriptorPlayback, ss.rate, pConfig->performanceProfile);
|
||||
|
||||
attr = ma_device__pa_buffer_attr_new(pDescriptorPlayback->periodSizeInFrames, pDescriptorPlayback->periodCount, &ss);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user