Commit 23c91751 authored by David Reid's avatar David Reid

Rename more variables for consistency.

parent 54e82c74
...@@ -1645,8 +1645,8 @@ struct mal_context ...@@ -1645,8 +1645,8 @@ struct mal_context
mal_result (* onDeviceReinit )(mal_device* pDevice); mal_result (* onDeviceReinit )(mal_device* pDevice);
mal_result (* onDeviceStart )(mal_device* pDevice); mal_result (* onDeviceStart )(mal_device* pDevice);
mal_result (* onDeviceStop )(mal_device* pDevice); mal_result (* onDeviceStop )(mal_device* pDevice);
mal_result (* onDeviceWrite )(mal_device* pDevice, const void* pPCMFrames, mal_uint32 pcmFrameCount); /* Data is in internal device format. */ mal_result (* onDeviceWrite )(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount); /* Data is in internal device format. */
mal_result (* onDeviceRead )(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcmFrameCount); /* Data is in internal device format. */ mal_result (* onDeviceRead )(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount); /* Data is in internal device format. */
mal_result (* onDeviceBreakMainLoop)(mal_device* pDevice); mal_result (* onDeviceBreakMainLoop)(mal_device* pDevice);
mal_result (* onDeviceMainLoop )(mal_device* pDevice); mal_result (* onDeviceMainLoop )(mal_device* pDevice);
...@@ -4956,7 +4956,7 @@ mal_result mal_device_stop__null(mal_device* pDevice) ...@@ -4956,7 +4956,7 @@ mal_result mal_device_stop__null(mal_device* pDevice)
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_result result = MAL_SUCCESS; mal_result result = MAL_SUCCESS;
mal_uint32 totalPCMFramesProcessed; mal_uint32 totalPCMFramesProcessed;
...@@ -4966,10 +4966,10 @@ mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, m ...@@ -4966,10 +4966,10 @@ mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, m
/* Keep going until everything has been read. */ /* Keep going until everything has been read. */
totalPCMFramesProcessed = 0; totalPCMFramesProcessed = 0;
while (totalPCMFramesProcessed < pcmFrameCount) { while (totalPCMFramesProcessed < frameCount) {
/* If there are any frames remaining in the current period, consume those first. */ /* If there are any frames remaining in the current period, consume those first. */
if (pDevice->null_device.currentPeriodFramesRemainingPlayback > 0) { if (pDevice->null_device.currentPeriodFramesRemainingPlayback > 0) {
mal_uint32 framesRemaining = (pcmFrameCount - totalPCMFramesProcessed); mal_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed);
mal_uint32 framesToProcess = pDevice->null_device.currentPeriodFramesRemainingPlayback; mal_uint32 framesToProcess = pDevice->null_device.currentPeriodFramesRemainingPlayback;
if (framesToProcess > framesRemaining) { if (framesToProcess > framesRemaining) {
framesToProcess = framesRemaining; framesToProcess = framesRemaining;
...@@ -4995,8 +4995,8 @@ mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, m ...@@ -4995,8 +4995,8 @@ mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, m
} }
/* If we've consumed the whole buffer we can return now. */ /* If we've consumed the whole buffer we can return now. */
mal_assert(totalPCMFramesProcessed <= pcmFrameCount); mal_assert(totalPCMFramesProcessed <= frameCount);
if (totalPCMFramesProcessed == pcmFrameCount) { if (totalPCMFramesProcessed == frameCount) {
break; break;
} }
...@@ -5024,7 +5024,7 @@ mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, m ...@@ -5024,7 +5024,7 @@ mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, m
return result; return result;
} }
mal_result mal_device_read__null(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_read__null(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_result result = MAL_SUCCESS; mal_result result = MAL_SUCCESS;
mal_uint32 totalPCMFramesProcessed; mal_uint32 totalPCMFramesProcessed;
...@@ -5039,11 +5039,11 @@ mal_result mal_device_read__null(mal_device* pDevice, void* pPCMFrames, mal_uint ...@@ -5039,11 +5039,11 @@ mal_result mal_device_read__null(mal_device* pDevice, void* pPCMFrames, mal_uint
/* Keep going until everything has been read. */ /* Keep going until everything has been read. */
totalPCMFramesProcessed = 0; totalPCMFramesProcessed = 0;
while (totalPCMFramesProcessed < pcmFrameCount) { while (totalPCMFramesProcessed < frameCount) {
/* If there are any frames remaining in the current period, consume those first. */ /* If there are any frames remaining in the current period, consume those first. */
if (pDevice->null_device.currentPeriodFramesRemainingCapture > 0) { if (pDevice->null_device.currentPeriodFramesRemainingCapture > 0) {
mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels); mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels);
mal_uint32 framesRemaining = (pcmFrameCount - totalPCMFramesProcessed); mal_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed);
mal_uint32 framesToProcess = pDevice->null_device.currentPeriodFramesRemainingCapture; mal_uint32 framesToProcess = pDevice->null_device.currentPeriodFramesRemainingCapture;
if (framesToProcess > framesRemaining) { if (framesToProcess > framesRemaining) {
framesToProcess = framesRemaining; framesToProcess = framesRemaining;
...@@ -5062,8 +5062,8 @@ mal_result mal_device_read__null(mal_device* pDevice, void* pPCMFrames, mal_uint ...@@ -5062,8 +5062,8 @@ mal_result mal_device_read__null(mal_device* pDevice, void* pPCMFrames, mal_uint
} }
/* If we've consumed the whole buffer we can return now. */ /* If we've consumed the whole buffer we can return now. */
mal_assert(totalPCMFramesProcessed <= pcmFrameCount); mal_assert(totalPCMFramesProcessed <= frameCount);
if (totalPCMFramesProcessed == pcmFrameCount) { if (totalPCMFramesProcessed == frameCount) {
break; break;
} }
...@@ -7183,19 +7183,19 @@ mal_result mal_device_reroute__wasapi(mal_device* pDevice) ...@@ -7183,19 +7183,19 @@ mal_result mal_device_reroute__wasapi(mal_device* pDevice)
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_write__wasapi(mal_device* pDevice, const void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_write__wasapi(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_result result = MAL_SUCCESS; mal_result result = MAL_SUCCESS;
mal_bool32 wasStartedOnEntry; mal_bool32 wasStartedOnEntry;
mal_uint32 totalPCMFramesWritten; mal_uint32 totalFramesWritten;
HRESULT hr; HRESULT hr;
DWORD waitResult; DWORD waitResult;
wasStartedOnEntry = pDevice->wasapi.isStarted; wasStartedOnEntry = pDevice->wasapi.isStarted;
/* Try to write every frame. */ /* Try to write every frame. */
totalPCMFramesWritten = 0; totalFramesWritten = 0;
while (totalPCMFramesWritten < pcmFrameCount) { while (totalFramesWritten < frameCount) {
/* /*
If we've already got a pointer to the device buffer we will want to fill that up first. Once it's consumed we'll want to reset If we've already got a pointer to the device buffer we will want to fill that up first. Once it's consumed we'll want to reset
the event and set the cached pointer to NULL. the event and set the cached pointer to NULL.
...@@ -7205,12 +7205,12 @@ mal_result mal_device_write__wasapi(mal_device* pDevice, const void* pPCMFrames, ...@@ -7205,12 +7205,12 @@ mal_result mal_device_write__wasapi(mal_device* pDevice, const void* pPCMFrames,
mal_uint32 deviceBufferFramesConsumed = pDevice->wasapi.deviceBufferFramesCapacityPlayback - pDevice->wasapi.deviceBufferFramesRemainingPlayback; mal_uint32 deviceBufferFramesConsumed = pDevice->wasapi.deviceBufferFramesCapacityPlayback - pDevice->wasapi.deviceBufferFramesRemainingPlayback;
void* pDst = (mal_uint8*)pDevice->wasapi.pDeviceBufferPlayback + (deviceBufferFramesConsumed * bpf); void* pDst = (mal_uint8*)pDevice->wasapi.pDeviceBufferPlayback + (deviceBufferFramesConsumed * bpf);
const void* pSrc = (const mal_uint8*)pPCMFrames + (totalPCMFramesWritten * bpf); const void* pSrc = (const mal_uint8*)pPCMFrames + (totalFramesWritten * bpf);
mal_uint32 framesToCopy = mal_min(pDevice->wasapi.deviceBufferFramesRemainingPlayback, (pcmFrameCount - totalPCMFramesWritten)); mal_uint32 framesToCopy = mal_min(pDevice->wasapi.deviceBufferFramesRemainingPlayback, (frameCount - totalFramesWritten));
mal_copy_memory(pDst, pSrc, framesToCopy * bpf); mal_copy_memory(pDst, pSrc, framesToCopy * bpf);
pDevice->wasapi.deviceBufferFramesRemainingPlayback -= framesToCopy; pDevice->wasapi.deviceBufferFramesRemainingPlayback -= framesToCopy;
totalPCMFramesWritten += framesToCopy; totalFramesWritten += framesToCopy;
} }
/* Getting here means we've consumed the device buffer and need to wait for more to become available. */ /* Getting here means we've consumed the device buffer and need to wait for more to become available. */
...@@ -7243,8 +7243,8 @@ mal_result mal_device_write__wasapi(mal_device* pDevice, const void* pPCMFrames, ...@@ -7243,8 +7243,8 @@ mal_result mal_device_write__wasapi(mal_device* pDevice, const void* pPCMFrames,
} }
} }
mal_assert(totalPCMFramesWritten <= pcmFrameCount); mal_assert(totalFramesWritten <= frameCount);
if (totalPCMFramesWritten == pcmFrameCount) { if (totalFramesWritten == frameCount) {
break; break;
} }
...@@ -7288,10 +7288,10 @@ mal_result mal_device_write__wasapi(mal_device* pDevice, const void* pPCMFrames, ...@@ -7288,10 +7288,10 @@ mal_result mal_device_write__wasapi(mal_device* pDevice, const void* pPCMFrames,
return result; return result;
} }
mal_result mal_device_read__wasapi(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_read__wasapi(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_result result = MAL_SUCCESS; mal_result result = MAL_SUCCESS;
mal_uint32 totalPCMFramesRead; mal_uint32 totalFramesRead;
HRESULT hr; HRESULT hr;
DWORD waitResult; DWORD waitResult;
DWORD flags; /* Passed to IAudioCaptureClient_GetBuffer(). */ DWORD flags; /* Passed to IAudioCaptureClient_GetBuffer(). */
...@@ -7308,20 +7308,20 @@ mal_result mal_device_read__wasapi(mal_device* pDevice, void* pPCMFrames, mal_ui ...@@ -7308,20 +7308,20 @@ mal_result mal_device_read__wasapi(mal_device* pDevice, void* pPCMFrames, mal_ui
} }
/* Try to read every frame. */ /* Try to read every frame. */
totalPCMFramesRead = 0; totalFramesRead = 0;
while (totalPCMFramesRead < pcmFrameCount) { while (totalFramesRead < frameCount) {
/* Make sure we consume any cached data before waiting for more. */ /* Make sure we consume any cached data before waiting for more. */
if (pDevice->wasapi.pDeviceBufferCapture != NULL && pDevice->wasapi.deviceBufferFramesRemainingCapture > 0) { if (pDevice->wasapi.pDeviceBufferCapture != NULL && pDevice->wasapi.deviceBufferFramesRemainingCapture > 0) {
mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels); mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels);
mal_uint32 deviceBufferFramesConsumed = pDevice->wasapi.deviceBufferFramesCapacityCapture - pDevice->wasapi.deviceBufferFramesRemainingCapture; mal_uint32 deviceBufferFramesConsumed = pDevice->wasapi.deviceBufferFramesCapacityCapture - pDevice->wasapi.deviceBufferFramesRemainingCapture;
void* pDst = (mal_uint8*)pPCMFrames + (totalPCMFramesRead * bpf); void* pDst = (mal_uint8*)pPCMFrames + (totalFramesRead * bpf);
const void* pSrc = (const mal_uint8*)pDevice->wasapi.pDeviceBufferCapture + (deviceBufferFramesConsumed * bpf); const void* pSrc = (const mal_uint8*)pDevice->wasapi.pDeviceBufferCapture + (deviceBufferFramesConsumed * bpf);
mal_uint32 framesToCopy = mal_min(pDevice->wasapi.deviceBufferFramesRemainingCapture, (pcmFrameCount - totalPCMFramesRead)); mal_uint32 framesToCopy = mal_min(pDevice->wasapi.deviceBufferFramesRemainingCapture, (frameCount - totalFramesRead));
mal_copy_memory(pDst, pSrc, framesToCopy * bpf); mal_copy_memory(pDst, pSrc, framesToCopy * bpf);
pDevice->wasapi.deviceBufferFramesRemainingCapture -= framesToCopy; pDevice->wasapi.deviceBufferFramesRemainingCapture -= framesToCopy;
totalPCMFramesRead += framesToCopy; totalFramesRead += framesToCopy;
} }
/* Getting here means we've consumed the device buffer and need to wait for more to become available. */ /* Getting here means we've consumed the device buffer and need to wait for more to become available. */
...@@ -7340,8 +7340,8 @@ mal_result mal_device_read__wasapi(mal_device* pDevice, void* pPCMFrames, mal_ui ...@@ -7340,8 +7340,8 @@ mal_result mal_device_read__wasapi(mal_device* pDevice, void* pPCMFrames, mal_ui
ResetEvent(pDevice->wasapi.hEventCapture); ResetEvent(pDevice->wasapi.hEventCapture);
} }
mal_assert(totalPCMFramesRead <= pcmFrameCount); mal_assert(totalFramesRead <= frameCount);
if (totalPCMFramesRead == pcmFrameCount) { if (totalFramesRead == frameCount) {
break; break;
} }
...@@ -8572,11 +8572,11 @@ mal_result mal_device_map_next_playback_buffer__dsound(mal_device* pDevice) ...@@ -8572,11 +8572,11 @@ mal_result mal_device_map_next_playback_buffer__dsound(mal_device* pDevice)
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_write__dsound(mal_device* pDevice, const void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_write__dsound(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_result result = MAL_SUCCESS; mal_result result = MAL_SUCCESS;
mal_bool32 wasStartedOnEntry; mal_bool32 wasStartedOnEntry;
mal_uint32 totalPCMFramesWritten; mal_uint32 totalFramesWritten;
HRESULT hr; HRESULT hr;
mal_assert(pDevice != NULL); mal_assert(pDevice != NULL);
...@@ -8592,20 +8592,20 @@ mal_result mal_device_write__dsound(mal_device* pDevice, const void* pPCMFrames, ...@@ -8592,20 +8592,20 @@ mal_result mal_device_write__dsound(mal_device* pDevice, const void* pPCMFrames,
} }
} }
totalPCMFramesWritten = 0; totalFramesWritten = 0;
while (totalPCMFramesWritten < pcmFrameCount) { while (totalFramesWritten < frameCount) {
/* If a buffer is mapped we need to write to that first. Once it's consumed we reset the event and unmap it. */ /* If a buffer is mapped we need to write to that first. Once it's consumed we reset the event and unmap it. */
if (pDevice->dsound.pMappedBufferPlayback != NULL && pDevice->dsound.mappedBufferFramesRemainingPlayback > 0) { if (pDevice->dsound.pMappedBufferPlayback != NULL && pDevice->dsound.mappedBufferFramesRemainingPlayback > 0) {
mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels); mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels);
mal_uint32 mappedBufferFramesConsumed = pDevice->dsound.mappedBufferFramesCapacityPlayback - pDevice->dsound.mappedBufferFramesRemainingPlayback; mal_uint32 mappedBufferFramesConsumed = pDevice->dsound.mappedBufferFramesCapacityPlayback - pDevice->dsound.mappedBufferFramesRemainingPlayback;
void* pDst = (mal_uint8*)pDevice->dsound.pMappedBufferPlayback + (mappedBufferFramesConsumed * bpf); void* pDst = (mal_uint8*)pDevice->dsound.pMappedBufferPlayback + (mappedBufferFramesConsumed * bpf);
const void* pSrc = (const mal_uint8*)pPCMFrames + (totalPCMFramesWritten * bpf); const void* pSrc = (const mal_uint8*)pPCMFrames + (totalFramesWritten * bpf);
mal_uint32 framesToCopy = mal_min(pDevice->dsound.mappedBufferFramesRemainingPlayback, (pcmFrameCount - totalPCMFramesWritten)); mal_uint32 framesToCopy = mal_min(pDevice->dsound.mappedBufferFramesRemainingPlayback, (frameCount - totalFramesWritten));
mal_copy_memory(pDst, pSrc, framesToCopy * bpf); mal_copy_memory(pDst, pSrc, framesToCopy * bpf);
pDevice->dsound.mappedBufferFramesRemainingPlayback -= framesToCopy; pDevice->dsound.mappedBufferFramesRemainingPlayback -= framesToCopy;
totalPCMFramesWritten += framesToCopy; totalFramesWritten += framesToCopy;
} }
/* Getting here means we've consumed the device buffer and need to wait for more to become available. */ /* Getting here means we've consumed the device buffer and need to wait for more to become available. */
...@@ -8630,8 +8630,8 @@ mal_result mal_device_write__dsound(mal_device* pDevice, const void* pPCMFrames, ...@@ -8630,8 +8630,8 @@ mal_result mal_device_write__dsound(mal_device* pDevice, const void* pPCMFrames,
} }
} }
mal_assert(totalPCMFramesWritten <= pcmFrameCount); mal_assert(totalFramesWritten <= frameCount);
if (totalPCMFramesWritten == pcmFrameCount) { if (totalFramesWritten == frameCount) {
break; break;
} }
...@@ -8710,10 +8710,10 @@ mal_result mal_device_map_next_capture_buffer__dsound(mal_device* pDevice) ...@@ -8710,10 +8710,10 @@ mal_result mal_device_map_next_capture_buffer__dsound(mal_device* pDevice)
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_read__dsound(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_read__dsound(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_result result = MAL_SUCCESS; mal_result result = MAL_SUCCESS;
mal_uint32 totalPCMFramesRead; mal_uint32 totalFramesRead;
HRESULT hr; HRESULT hr;
mal_assert(pDevice != NULL); mal_assert(pDevice != NULL);
...@@ -8727,20 +8727,20 @@ mal_result mal_device_read__dsound(mal_device* pDevice, void* pPCMFrames, mal_ui ...@@ -8727,20 +8727,20 @@ mal_result mal_device_read__dsound(mal_device* pDevice, void* pPCMFrames, mal_ui
} }
} }
totalPCMFramesRead = 0; totalFramesRead = 0;
while (totalPCMFramesRead < pcmFrameCount) { while (totalFramesRead < frameCount) {
/* If a buffer is mapped we need to write to that first. Once it's consumed we reset the event and unmap it. */ /* If a buffer is mapped we need to write to that first. Once it's consumed we reset the event and unmap it. */
if (pDevice->dsound.pMappedBufferCapture != NULL && pDevice->dsound.mappedBufferFramesRemainingCapture > 0) { if (pDevice->dsound.pMappedBufferCapture != NULL && pDevice->dsound.mappedBufferFramesRemainingCapture > 0) {
mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels); mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels);
mal_uint32 mappedBufferFramesConsumed = pDevice->dsound.mappedBufferFramesCapacityCapture - pDevice->dsound.mappedBufferFramesRemainingCapture; mal_uint32 mappedBufferFramesConsumed = pDevice->dsound.mappedBufferFramesCapacityCapture - pDevice->dsound.mappedBufferFramesRemainingCapture;
void* pDst = (mal_uint8*)pPCMFrames + (totalPCMFramesRead * bpf); void* pDst = (mal_uint8*)pPCMFrames + (totalFramesRead * bpf);
const void* pSrc = (const mal_uint8*)pDevice->dsound.pMappedBufferCapture + (mappedBufferFramesConsumed * bpf); const void* pSrc = (const mal_uint8*)pDevice->dsound.pMappedBufferCapture + (mappedBufferFramesConsumed * bpf);
mal_uint32 framesToCopy = mal_min(pDevice->dsound.mappedBufferFramesRemainingCapture, (pcmFrameCount - totalPCMFramesRead)); mal_uint32 framesToCopy = mal_min(pDevice->dsound.mappedBufferFramesRemainingCapture, (frameCount - totalFramesRead));
mal_copy_memory(pDst, pSrc, framesToCopy * bpf); mal_copy_memory(pDst, pSrc, framesToCopy * bpf);
pDevice->dsound.mappedBufferFramesRemainingCapture -= framesToCopy; pDevice->dsound.mappedBufferFramesRemainingCapture -= framesToCopy;
totalPCMFramesRead += framesToCopy; totalFramesRead += framesToCopy;
} }
/* Getting here means we've consumed the device buffer and need to wait for more to become available. */ /* Getting here means we've consumed the device buffer and need to wait for more to become available. */
...@@ -8758,8 +8758,8 @@ mal_result mal_device_read__dsound(mal_device* pDevice, void* pPCMFrames, mal_ui ...@@ -8758,8 +8758,8 @@ mal_result mal_device_read__dsound(mal_device* pDevice, void* pPCMFrames, mal_ui
} }
} }
mal_assert(totalPCMFramesRead <= pcmFrameCount); mal_assert(totalFramesRead <= frameCount);
if (totalPCMFramesRead == pcmFrameCount) { if (totalFramesRead == frameCount) {
break; break;
} }
...@@ -9516,19 +9516,19 @@ mal_result mal_device_stop__winmm(mal_device* pDevice) ...@@ -9516,19 +9516,19 @@ mal_result mal_device_stop__winmm(mal_device* pDevice)
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_result result = MAL_SUCCESS; mal_result result = MAL_SUCCESS;
MMRESULT resultMM; MMRESULT resultMM;
mal_uint32 totalPCMFramesWritten; mal_uint32 totalFramesWritten;
WAVEHDR* pWAVEHDR = (WAVEHDR*)pDevice->winmm.pWAVEHDR; WAVEHDR* pWAVEHDR = (WAVEHDR*)pDevice->winmm.pWAVEHDR;
mal_assert(pDevice != NULL); mal_assert(pDevice != NULL);
mal_assert(pPCMFrames != NULL); mal_assert(pPCMFrames != NULL);
/* Keep processing as much data as possible. */ /* Keep processing as much data as possible. */
totalPCMFramesWritten = 0; totalFramesWritten = 0;
while (totalPCMFramesWritten < pcmFrameCount) { while (totalFramesWritten < frameCount) {
/* If the current header has some space available we need to write part of it. */ /* If the current header has some space available we need to write part of it. */
if (pWAVEHDR[pDevice->winmm.iNextHeader].dwUser == 0) { /* 0 = unlocked. */ if (pWAVEHDR[pDevice->winmm.iNextHeader].dwUser == 0) { /* 0 = unlocked. */
/* /*
...@@ -9538,13 +9538,13 @@ mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames, ...@@ -9538,13 +9538,13 @@ mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames,
mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels); mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels);
mal_uint32 framesRemainingInHeader = (pWAVEHDR[pDevice->winmm.iNextHeader].dwBufferLength/bpf) - pDevice->winmm.headerFramesConsumedPlayback; mal_uint32 framesRemainingInHeader = (pWAVEHDR[pDevice->winmm.iNextHeader].dwBufferLength/bpf) - pDevice->winmm.headerFramesConsumedPlayback;
mal_uint32 framesToCopy = mal_min(framesRemainingInHeader, (pcmFrameCount - totalPCMFramesWritten)); mal_uint32 framesToCopy = mal_min(framesRemainingInHeader, (frameCount - totalFramesWritten));
const void* pSrc = mal_offset_ptr(pPCMFrames, totalPCMFramesWritten*bpf); const void* pSrc = mal_offset_ptr(pPCMFrames, totalFramesWritten*bpf);
void* pDst = mal_offset_ptr(pWAVEHDR[pDevice->winmm.iNextHeader].lpData, pDevice->winmm.headerFramesConsumedPlayback*bpf); void* pDst = mal_offset_ptr(pWAVEHDR[pDevice->winmm.iNextHeader].lpData, pDevice->winmm.headerFramesConsumedPlayback*bpf);
mal_copy_memory(pDst, pSrc, framesToCopy*bpf); mal_copy_memory(pDst, pSrc, framesToCopy*bpf);
pDevice->winmm.headerFramesConsumedPlayback += framesToCopy; pDevice->winmm.headerFramesConsumedPlayback += framesToCopy;
totalPCMFramesWritten += framesToCopy; totalFramesWritten += framesToCopy;
/* If we've consumed the buffer entirely we need to write it out to the device. */ /* If we've consumed the buffer entirely we need to write it out to the device. */
if (pDevice->winmm.headerFramesConsumedPlayback == (pWAVEHDR[pDevice->winmm.iNextHeader].dwBufferLength/bpf)) { if (pDevice->winmm.headerFramesConsumedPlayback == (pWAVEHDR[pDevice->winmm.iNextHeader].dwBufferLength/bpf)) {
...@@ -9569,8 +9569,8 @@ mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames, ...@@ -9569,8 +9569,8 @@ mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames,
} }
/* If at this point we have consumed the entire input buffer we can return. */ /* If at this point we have consumed the entire input buffer we can return. */
mal_assert(totalPCMFramesWritten <= pcmFrameCount); mal_assert(totalFramesWritten <= frameCount);
if (totalPCMFramesWritten == pcmFrameCount) { if (totalFramesWritten == frameCount) {
break; break;
} }
...@@ -9599,14 +9599,14 @@ mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames, ...@@ -9599,14 +9599,14 @@ mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames,
return result; return result;
} }
mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_assert(pDevice != NULL); mal_assert(pDevice != NULL);
mal_assert(pPCMFrames != NULL); mal_assert(pPCMFrames != NULL);
mal_result result = MAL_SUCCESS; mal_result result = MAL_SUCCESS;
MMRESULT resultMM; MMRESULT resultMM;
mal_uint32 totalPCMFramesRead; mal_uint32 totalFramesRead;
WAVEHDR* pWAVEHDR = (WAVEHDR*)pDevice->winmm.pWAVEHDR; WAVEHDR* pWAVEHDR = (WAVEHDR*)pDevice->winmm.pWAVEHDR;
/* We want to start the device immediately. */ /* We want to start the device immediately. */
...@@ -9635,21 +9635,21 @@ mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uin ...@@ -9635,21 +9635,21 @@ mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uin
} }
/* Keep processing as much data as possible. */ /* Keep processing as much data as possible. */
totalPCMFramesRead = 0; totalFramesRead = 0;
while (totalPCMFramesRead < pcmFrameCount) { while (totalFramesRead < frameCount) {
/* If the current header has some space available we need to write part of it. */ /* If the current header has some space available we need to write part of it. */
if (pWAVEHDR[pDevice->winmm.iNextHeader].dwUser == 0) { /* 0 = unlocked. */ if (pWAVEHDR[pDevice->winmm.iNextHeader].dwUser == 0) { /* 0 = unlocked. */
/* The buffer is available for reading. If we fully consume it we need to add it back to the buffer. */ /* The buffer is available for reading. If we fully consume it we need to add it back to the buffer. */
mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels); mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels);
mal_uint32 framesRemainingInHeader = (pWAVEHDR[pDevice->winmm.iNextHeader].dwBufferLength/bpf) - pDevice->winmm.headerFramesConsumedCapture; mal_uint32 framesRemainingInHeader = (pWAVEHDR[pDevice->winmm.iNextHeader].dwBufferLength/bpf) - pDevice->winmm.headerFramesConsumedCapture;
mal_uint32 framesToCopy = mal_min(framesRemainingInHeader, (pcmFrameCount - totalPCMFramesRead)); mal_uint32 framesToCopy = mal_min(framesRemainingInHeader, (frameCount - totalFramesRead));
const void* pSrc = mal_offset_ptr(pWAVEHDR[pDevice->winmm.iNextHeader].lpData, pDevice->winmm.headerFramesConsumedCapture*bpf); const void* pSrc = mal_offset_ptr(pWAVEHDR[pDevice->winmm.iNextHeader].lpData, pDevice->winmm.headerFramesConsumedCapture*bpf);
void* pDst = mal_offset_ptr(pPCMFrames, totalPCMFramesRead*bpf); void* pDst = mal_offset_ptr(pPCMFrames, totalFramesRead*bpf);
mal_copy_memory(pDst, pSrc, framesToCopy*bpf); mal_copy_memory(pDst, pSrc, framesToCopy*bpf);
pDevice->winmm.headerFramesConsumedCapture += framesToCopy; pDevice->winmm.headerFramesConsumedCapture += framesToCopy;
totalPCMFramesRead += framesToCopy; totalFramesRead += framesToCopy;
/* If we've consumed the buffer entirely we need to add it back to the device. */ /* If we've consumed the buffer entirely we need to add it back to the device. */
if (pDevice->winmm.headerFramesConsumedCapture == (pWAVEHDR[pDevice->winmm.iNextHeader].dwBufferLength/bpf)) { if (pDevice->winmm.headerFramesConsumedCapture == (pWAVEHDR[pDevice->winmm.iNextHeader].dwBufferLength/bpf)) {
...@@ -9673,8 +9673,8 @@ mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uin ...@@ -9673,8 +9673,8 @@ mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uin
} }
/* If at this point we have filled the entire input buffer we can return. */ /* If at this point we have filled the entire input buffer we can return. */
mal_assert(totalPCMFramesRead <= pcmFrameCount); mal_assert(totalFramesRead <= frameCount);
if (totalPCMFramesRead == pcmFrameCount) { if (totalFramesRead == frameCount) {
break; break;
} }
...@@ -11346,7 +11346,7 @@ mal_result mal_device_stop__alsa(mal_device* pDevice) ...@@ -11346,7 +11346,7 @@ mal_result mal_device_stop__alsa(mal_device* pDevice)
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_write__alsa(mal_device* pDevice, const void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_write__alsa(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_snd_pcm_sframes_t resultALSA; mal_snd_pcm_sframes_t resultALSA;
mal_uint32 totalPCMFramesProcessed; mal_uint32 totalPCMFramesProcessed;
...@@ -11355,9 +11355,9 @@ mal_result mal_device_write__alsa(mal_device* pDevice, const void* pPCMFrames, m ...@@ -11355,9 +11355,9 @@ mal_result mal_device_write__alsa(mal_device* pDevice, const void* pPCMFrames, m
mal_assert(pPCMFrames != NULL); mal_assert(pPCMFrames != NULL);
totalPCMFramesProcessed = 0; totalPCMFramesProcessed = 0;
while (totalPCMFramesProcessed < pcmFrameCount) { while (totalPCMFramesProcessed < frameCount) {
const void* pSrc = mal_offset_ptr(pPCMFrames, totalPCMFramesProcessed * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels)); const void* pSrc = mal_offset_ptr(pPCMFrames, totalPCMFramesProcessed * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels));
mal_uint32 framesRemaining = (pcmFrameCount - totalPCMFramesProcessed); mal_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed);
resultALSA = ((mal_snd_pcm_writei_proc)pDevice->pContext->alsa.snd_pcm_writei)((mal_snd_pcm_t*)pDevice->alsa.pPCM, pSrc, framesRemaining); resultALSA = ((mal_snd_pcm_writei_proc)pDevice->pContext->alsa.snd_pcm_writei)((mal_snd_pcm_t*)pDevice->alsa.pPCM, pSrc, framesRemaining);
if (resultALSA < 0) { if (resultALSA < 0) {
...@@ -11393,7 +11393,7 @@ mal_result mal_device_write__alsa(mal_device* pDevice, const void* pPCMFrames, m ...@@ -11393,7 +11393,7 @@ mal_result mal_device_write__alsa(mal_device* pDevice, const void* pPCMFrames, m
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_read__alsa(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_read__alsa(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_snd_pcm_sframes_t resultALSA; mal_snd_pcm_sframes_t resultALSA;
mal_uint32 totalPCMFramesProcessed; mal_uint32 totalPCMFramesProcessed;
...@@ -11409,9 +11409,9 @@ mal_result mal_device_read__alsa(mal_device* pDevice, void* pPCMFrames, mal_uint ...@@ -11409,9 +11409,9 @@ mal_result mal_device_read__alsa(mal_device* pDevice, void* pPCMFrames, mal_uint
} }
totalPCMFramesProcessed = 0; totalPCMFramesProcessed = 0;
while (totalPCMFramesProcessed < pcmFrameCount) { while (totalPCMFramesProcessed < frameCount) {
void* pDst = mal_offset_ptr(pPCMFrames, totalPCMFramesProcessed * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels)); void* pDst = mal_offset_ptr(pPCMFrames, totalPCMFramesProcessed * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels));
mal_uint32 framesRemaining = (pcmFrameCount - totalPCMFramesProcessed); mal_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed);
resultALSA = ((mal_snd_pcm_readi_proc)pDevice->pContext->alsa.snd_pcm_readi)((mal_snd_pcm_t*)pDevice->alsa.pPCM, pDst, framesRemaining); resultALSA = ((mal_snd_pcm_readi_proc)pDevice->pContext->alsa.snd_pcm_readi)((mal_snd_pcm_t*)pDevice->alsa.pPCM, pDst, framesRemaining);
if (resultALSA < 0) { if (resultALSA < 0) {
...@@ -16924,13 +16924,13 @@ mal_result mal_device_stop__sndio(mal_device* pDevice) ...@@ -16924,13 +16924,13 @@ mal_result mal_device_stop__sndio(mal_device* pDevice)
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_write__sndio(mal_device* pDevice, const void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_write__sndio(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount)
{ {
if (!pDevice->sndio.isStarted) { if (!pDevice->sndio.isStarted) {
mal_device_start__sndio(pDevice); /* <-- Doesn't actually playback until data is written. */ mal_device_start__sndio(pDevice); /* <-- Doesn't actually playback until data is written. */
} }
int result = ((mal_sio_write_proc)pDevice->pContext->sndio.sio_write)((struct mal_sio_hdl*)pDevice->sndio.handle, pPCMFrames, pcmFrameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels)); int result = ((mal_sio_write_proc)pDevice->pContext->sndio.sio_write)((struct mal_sio_hdl*)pDevice->sndio.handle, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels));
if (result == 0) { if (result == 0) {
return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[sndio] Failed to send data from the client to the device.", MAL_FAILED_TO_SEND_DATA_TO_DEVICE); return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[sndio] Failed to send data from the client to the device.", MAL_FAILED_TO_SEND_DATA_TO_DEVICE);
} }
...@@ -16938,13 +16938,13 @@ mal_result mal_device_write__sndio(mal_device* pDevice, const void* pPCMFrames, ...@@ -16938,13 +16938,13 @@ mal_result mal_device_write__sndio(mal_device* pDevice, const void* pPCMFrames,
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_read__sndio(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_read__sndio(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount)
{ {
if (!pDevice->sndio.isStarted) { if (!pDevice->sndio.isStarted) {
mal_device_start__sndio(pDevice); mal_device_start__sndio(pDevice);
} }
int result = ((mal_sio_read_proc)pDevice->pContext->sndio.sio_read)((struct mal_sio_hdl*)pDevice->sndio.handle, pPCMFrames, pcmFrameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels)); int result = ((mal_sio_read_proc)pDevice->pContext->sndio.sio_read)((struct mal_sio_hdl*)pDevice->sndio.handle, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels));
if (result == 0) { if (result == 0) {
return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[sndio] Failed to read data from the device to be sent to the device.", MAL_FAILED_TO_SEND_DATA_TO_DEVICE); return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[sndio] Failed to read data from the device to be sent to the device.", MAL_FAILED_TO_SEND_DATA_TO_DEVICE);
} }
...@@ -17562,9 +17562,9 @@ mal_result mal_device_stop__audio4(mal_device* pDevice) ...@@ -17562,9 +17562,9 @@ mal_result mal_device_stop__audio4(mal_device* pDevice)
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_write__audio4(mal_device* pDevice, const void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_write__audio4(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount)
{ {
int result = write(pDevice->audio4.fd, pPCMFrames, pcmFrameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels)); int result = write(pDevice->audio4.fd, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels));
if (result < 0) { if (result < 0) {
return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[audio4] Failed to write data to the device.", MAL_FAILED_TO_SEND_DATA_TO_DEVICE); return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[audio4] Failed to write data to the device.", MAL_FAILED_TO_SEND_DATA_TO_DEVICE);
} }
...@@ -17572,9 +17572,9 @@ mal_result mal_device_write__audio4(mal_device* pDevice, const void* pPCMFrames, ...@@ -17572,9 +17572,9 @@ mal_result mal_device_write__audio4(mal_device* pDevice, const void* pPCMFrames,
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_read__audio4(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_read__audio4(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount)
{ {
int result = read(pDevice->audio4.fd, pPCMFrames, pcmFrameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels)); int result = read(pDevice->audio4.fd, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels));
if (result < 0) { if (result < 0) {
return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[audio4] Failed to read data from the device.", MAL_FAILED_TO_READ_DATA_FROM_DEVICE); return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[audio4] Failed to read data from the device.", MAL_FAILED_TO_READ_DATA_FROM_DEVICE);
} }
...@@ -17964,9 +17964,9 @@ mal_result mal_device_stop__oss(mal_device* pDevice) ...@@ -17964,9 +17964,9 @@ mal_result mal_device_stop__oss(mal_device* pDevice)
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_write__oss(mal_device* pDevice, const void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_write__oss(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount)
{ {
int resultOSS = write(pDevice->oss.fd, pPCMFrames, pcmFrameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels)); int resultOSS = write(pDevice->oss.fd, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels));
if (resultOSS < 0) { if (resultOSS < 0) {
return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[OSS] Failed to send data from the client to the device.", MAL_FAILED_TO_SEND_DATA_TO_DEVICE); return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[OSS] Failed to send data from the client to the device.", MAL_FAILED_TO_SEND_DATA_TO_DEVICE);
} }
...@@ -17974,9 +17974,9 @@ mal_result mal_device_write__oss(mal_device* pDevice, const void* pPCMFrames, ma ...@@ -17974,9 +17974,9 @@ mal_result mal_device_write__oss(mal_device* pDevice, const void* pPCMFrames, ma
return MAL_SUCCESS; return MAL_SUCCESS;
} }
mal_result mal_device_read__oss(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_read__oss(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount)
{ {
int resultOSS = read(pDevice->oss.fd, pPCMFrames, pcmFrameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels)); int resultOSS = read(pDevice->oss.fd, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels));
if (resultOSS < 0) { if (resultOSS < 0) {
return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[OSS] Failed to read data from the device to be sent to the client.", MAL_FAILED_TO_READ_DATA_FROM_DEVICE); return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[OSS] Failed to read data from the device to be sent to the client.", MAL_FAILED_TO_READ_DATA_FROM_DEVICE);
} }
...@@ -20834,10 +20834,10 @@ void mal_device_uninit(mal_device* pDevice) ...@@ -20834,10 +20834,10 @@ void mal_device_uninit(mal_device* pDevice)
/* /*
Writes PCM frames to the device. Writes PCM frames to the device.
*/ */
mal_result mal_device_write(mal_device* pDevice, const void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_write(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_result result; mal_result result;
mal_uint32 totalPCMFramesWritten = 0; mal_uint32 totalFramesWritten = 0;
if (mal_device__is_async(pDevice)) { if (mal_device__is_async(pDevice)) {
return MAL_INVALID_ARGS; return MAL_INVALID_ARGS;
...@@ -20851,7 +20851,7 @@ mal_result mal_device_write(mal_device* pDevice, const void* pPCMFrames, mal_uin ...@@ -20851,7 +20851,7 @@ mal_result mal_device_write(mal_device* pDevice, const void* pPCMFrames, mal_uin
/* If it's a passthrough we can call the backend directly, otherwise we need a data conversion into an intermediary buffer. */ /* If it's a passthrough we can call the backend directly, otherwise we need a data conversion into an intermediary buffer. */
if (pDevice->dsp.isPassthrough) { if (pDevice->dsp.isPassthrough) {
/* Fast path. Write directly to the device. */ /* Fast path. Write directly to the device. */
result = pDevice->pContext->onDeviceWrite(pDevice, pPCMFrames, pcmFrameCount); result = pDevice->pContext->onDeviceWrite(pDevice, pPCMFrames, frameCount);
} else { } else {
/* Slow path. Perform a data conversion. */ /* Slow path. Perform a data conversion. */
...@@ -20862,17 +20862,17 @@ mal_result mal_device_write(mal_device* pDevice, const void* pPCMFrames, mal_uin ...@@ -20862,17 +20862,17 @@ mal_result mal_device_write(mal_device* pDevice, const void* pPCMFrames, mal_uin
mal_uint8 buffer[4096]; mal_uint8 buffer[4096];
mal_uint32 bufferSizeInFrames = sizeof(buffer) / mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels); mal_uint32 bufferSizeInFrames = sizeof(buffer) / mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels);
while (totalPCMFramesWritten < pcmFrameCount) { while (totalFramesWritten < frameCount) {
mal_uint32 framesRemaining = (pcmFrameCount - totalPCMFramesWritten); mal_uint32 framesRemaining = (frameCount - totalFramesWritten);
mal_uint32 framesToProcess = framesRemaining; mal_uint32 framesToProcess = framesRemaining;
if (framesToProcess > bufferSizeInFrames) { if (framesToProcess > bufferSizeInFrames) {
framesToProcess = bufferSizeInFrames; framesToProcess = bufferSizeInFrames;
} }
mal_pcm_convert(buffer, pDevice->internalFormat, mal_offset_ptr(pPCMFrames, totalPCMFramesWritten * mal_get_bytes_per_frame(pDevice->format, pDevice->channels)), pDevice->format, framesToProcess*pDevice->channels, mal_dither_mode_none); mal_pcm_convert(buffer, pDevice->internalFormat, mal_offset_ptr(pPCMFrames, totalFramesWritten * mal_get_bytes_per_frame(pDevice->format, pDevice->channels)), pDevice->format, framesToProcess*pDevice->channels, mal_dither_mode_none);
result = pDevice->pContext->onDeviceWrite(pDevice, buffer, framesToProcess); result = pDevice->pContext->onDeviceWrite(pDevice, buffer, framesToProcess);
totalPCMFramesWritten += framesToProcess; totalFramesWritten += framesToProcess;
if (result != MAL_SUCCESS) { if (result != MAL_SUCCESS) {
break; break;
...@@ -20886,10 +20886,10 @@ mal_result mal_device_write(mal_device* pDevice, const void* pPCMFrames, mal_uin ...@@ -20886,10 +20886,10 @@ mal_result mal_device_write(mal_device* pDevice, const void* pPCMFrames, mal_uin
/* /*
Reads PCM frames from the device. Reads PCM frames from the device.
*/ */
mal_result mal_device_read(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcmFrameCount) mal_result mal_device_read(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount)
{ {
mal_result result; mal_result result;
mal_uint32 totalPCMFramesRead = 0; mal_uint32 totalFramesRead = 0;
if (pDevice == NULL || pPCMFrames == NULL) { if (pDevice == NULL || pPCMFrames == NULL) {
return MAL_INVALID_ARGS; return MAL_INVALID_ARGS;
...@@ -20908,7 +20908,7 @@ mal_result mal_device_read(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcm ...@@ -20908,7 +20908,7 @@ mal_result mal_device_read(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcm
/* If it's a passthrough we can call the backend directly, otherwise we need a data conversion into an intermediary buffer. */ /* If it's a passthrough we can call the backend directly, otherwise we need a data conversion into an intermediary buffer. */
if (pDevice->dsp.isPassthrough) { if (pDevice->dsp.isPassthrough) {
/* Fast path. Write directly to the device. */ /* Fast path. Write directly to the device. */
result = pDevice->pContext->onDeviceRead(pDevice, pPCMFrames, pcmFrameCount); result = pDevice->pContext->onDeviceRead(pDevice, pPCMFrames, frameCount);
} else { } else {
/* Slow path. Perform a data conversion. */ /* Slow path. Perform a data conversion. */
...@@ -20919,8 +20919,8 @@ mal_result mal_device_read(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcm ...@@ -20919,8 +20919,8 @@ mal_result mal_device_read(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcm
mal_uint8 buffer[4096]; mal_uint8 buffer[4096];
mal_uint32 bufferSizeInFrames = sizeof(buffer) / mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels); mal_uint32 bufferSizeInFrames = sizeof(buffer) / mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels);
while (totalPCMFramesRead < pcmFrameCount) { while (totalFramesRead < frameCount) {
mal_uint32 framesRemaining = (pcmFrameCount - totalPCMFramesRead); mal_uint32 framesRemaining = (frameCount - totalFramesRead);
mal_uint32 framesToProcess = framesRemaining; mal_uint32 framesToProcess = framesRemaining;
if (framesToProcess > bufferSizeInFrames) { if (framesToProcess > bufferSizeInFrames) {
framesToProcess = bufferSizeInFrames; framesToProcess = bufferSizeInFrames;
...@@ -20928,9 +20928,9 @@ mal_result mal_device_read(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcm ...@@ -20928,9 +20928,9 @@ mal_result mal_device_read(mal_device* pDevice, void* pPCMFrames, mal_uint32 pcm
result = pDevice->pContext->onDeviceRead(pDevice, buffer, framesToProcess); result = pDevice->pContext->onDeviceRead(pDevice, buffer, framesToProcess);
mal_pcm_convert(mal_offset_ptr(pPCMFrames, totalPCMFramesRead * mal_get_bytes_per_frame(pDevice->format, pDevice->channels)), pDevice->format, buffer, pDevice->internalFormat, framesToProcess*pDevice->channels, mal_dither_mode_none); mal_pcm_convert(mal_offset_ptr(pPCMFrames, totalFramesRead * mal_get_bytes_per_frame(pDevice->format, pDevice->channels)), pDevice->format, buffer, pDevice->internalFormat, framesToProcess*pDevice->channels, mal_dither_mode_none);
totalPCMFramesRead += framesToProcess; totalFramesRead += framesToProcess;
if (result != MAL_SUCCESS) { if (result != MAL_SUCCESS) {
break; break;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment