mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 08:44:04 +02:00
Minor refactor to the null backend.
This commit is contained in:
+27
-38
@@ -21180,46 +21180,39 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* For capture we need to submit silence. For playback we just read and discard. */
|
framesAvailable = ma_device_get_available_frames__null(pDevice);
|
||||||
if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) {
|
if (framesAvailable > 0) {
|
||||||
ma_device_handle_backend_data_callback(pDevice, NULL, pDeviceStateNull->pDataCapture, framesAvailable);
|
/* 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_playback || deviceType == ma_device_type_duplex) {
|
ma_device_handle_backend_data_callback(pDevice, NULL, pDeviceStateNull->pDataCapture, framesAvailable);
|
||||||
ma_device_handle_backend_data_callback(pDevice, pDeviceStateNull->pDataPlayback, NULL, framesAvailable);
|
}
|
||||||
}
|
if (deviceType == ma_device_type_playback || deviceType == ma_device_type_duplex) {
|
||||||
|
ma_device_handle_backend_data_callback(pDevice, pDeviceStateNull->pDataPlayback, NULL, framesAvailable);
|
||||||
|
}
|
||||||
|
|
||||||
/* 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user