Minor refactor to the null backend.

This commit is contained in:
David Reid
2025-12-22 11:50:44 +10:00
parent 9364a36f04
commit e598eb7fe6
+17 -28
View File
@@ -21180,36 +21180,20 @@ static ma_uint32 ma_device_get_available_frames__null(ma_device* pDevice)
} }
} }
static ma_result ma_device_wait__null(ma_device* pDevice)
{
while (ma_device_is_started(pDevice)) {
/* Check the frames available based on the timer. We want to wait until we have at least a whole period available. */
if (ma_device_get_available_frames__null(pDevice) > 0) {
break;
}
ma_sleep(1); static ma_result ma_device_step__null(ma_device* pDevice, ma_blocking_mode blockingMode)
}
return MA_SUCCESS;
}
static ma_result ma_device_step__null(ma_device* pDevice)
{ {
ma_device_state_null* pDeviceStateNull = ma_device_get_backend_state__null(pDevice); ma_device_state_null* pDeviceStateNull = ma_device_get_backend_state__null(pDevice);
ma_uint32 framesAvailable; ma_uint32 framesAvailable;
ma_device_type deviceType = ma_device_get_type(pDevice); ma_device_type deviceType = ma_device_get_type(pDevice);
/* for (;;) {
The capture and playback sides both run on the same timer, so we need only check the timer once if (!ma_device_is_started(pDevice)) {
and then just process both at the same time. return MA_DEVICE_NOT_STARTED;
*/
framesAvailable = ma_device_get_available_frames__null(pDevice);
if (framesAvailable == 0) {
/* Not enough frames available for processing. Do nothing. */
return MA_SUCCESS;
} }
framesAvailable = ma_device_get_available_frames__null(pDevice);
if (framesAvailable > 0) {
/* For capture we need to submit silence. For playback we just read and discard. */ /* For capture we need to submit silence. For playback we just read and discard. */
if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) { if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) {
ma_device_handle_backend_data_callback(pDevice, NULL, pDeviceStateNull->pDataCapture, framesAvailable); ma_device_handle_backend_data_callback(pDevice, NULL, pDeviceStateNull->pDataCapture, framesAvailable);
@@ -21220,6 +21204,15 @@ static ma_result ma_device_step__null(ma_device* pDevice)
/* The cursor needs to be advanced by the number of frames we just processed. */ /* The cursor needs to be advanced by the number of frames we just processed. */
pDeviceStateNull->cursor += framesAvailable; pDeviceStateNull->cursor += framesAvailable;
}
if (blockingMode == MA_BLOCKING_MODE_NON_BLOCKING) {
break;
}
/* Getting here means we're in blocking mode. Relax the CPU a bit and keep waiting for data. */
ma_sleep(1);
}
return MA_SUCCESS; return MA_SUCCESS;
} }
@@ -21227,14 +21220,10 @@ static ma_result ma_device_step__null(ma_device* pDevice)
static void ma_device_loop__null(ma_device* pDevice) static void ma_device_loop__null(ma_device* pDevice)
{ {
for (;;) { for (;;) {
ma_device_wait__null(pDevice); ma_result result = ma_device_step__null(pDevice, MA_BLOCKING_MODE_BLOCKING);
if (result != MA_SUCCESS) {
/* If the wait terminated due to the device being stopped, abort now. */
if (!ma_device_is_started(pDevice)) {
break; break;
} }
ma_device_step__null(pDevice);
} }
} }