mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 08:44:04 +02:00
Reduce some stack usage.
This commit is contained in:
+13
-17
@@ -17184,6 +17184,10 @@ static ma_result ma_device_main_loop__winmm(ma_device* pDevice)
|
|||||||
{
|
{
|
||||||
ma_result result = MA_SUCCESS;
|
ma_result result = MA_SUCCESS;
|
||||||
ma_bool32 exitLoop = MA_FALSE;
|
ma_bool32 exitLoop = MA_FALSE;
|
||||||
|
ma_uint8 capturedDeviceData[MA_DATA_CONVERTER_STACK_BUFFER_SIZE];
|
||||||
|
ma_uint8 playbackDeviceData[MA_DATA_CONVERTER_STACK_BUFFER_SIZE];
|
||||||
|
ma_uint32 capturedDeviceDataCapInFrames = sizeof(capturedDeviceData) / ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels);
|
||||||
|
ma_uint32 playbackDeviceDataCapInFrames = sizeof(playbackDeviceData) / ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels);
|
||||||
|
|
||||||
MA_ASSERT(pDevice != NULL);
|
MA_ASSERT(pDevice != NULL);
|
||||||
|
|
||||||
@@ -17227,10 +17231,6 @@ static ma_result ma_device_main_loop__winmm(ma_device* pDevice)
|
|||||||
ma_uint32 capturedDevicePeriodSizeInFrames = ma_min(pDevice->capture.internalPeriodSizeInFrames, pDevice->playback.internalPeriodSizeInFrames);
|
ma_uint32 capturedDevicePeriodSizeInFrames = ma_min(pDevice->capture.internalPeriodSizeInFrames, pDevice->playback.internalPeriodSizeInFrames);
|
||||||
|
|
||||||
while (totalCapturedDeviceFramesProcessed < capturedDevicePeriodSizeInFrames) {
|
while (totalCapturedDeviceFramesProcessed < capturedDevicePeriodSizeInFrames) {
|
||||||
ma_uint8 capturedDeviceData[MA_DATA_CONVERTER_STACK_BUFFER_SIZE];
|
|
||||||
ma_uint8 playbackDeviceData[MA_DATA_CONVERTER_STACK_BUFFER_SIZE];
|
|
||||||
ma_uint32 capturedDeviceDataCapInFrames = sizeof(capturedDeviceData) / ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels);
|
|
||||||
ma_uint32 playbackDeviceDataCapInFrames = sizeof(playbackDeviceData) / ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels);
|
|
||||||
ma_uint32 capturedDeviceFramesRemaining;
|
ma_uint32 capturedDeviceFramesRemaining;
|
||||||
ma_uint32 capturedDeviceFramesProcessed;
|
ma_uint32 capturedDeviceFramesProcessed;
|
||||||
ma_uint32 capturedDeviceFramesToProcess;
|
ma_uint32 capturedDeviceFramesToProcess;
|
||||||
@@ -17311,25 +17311,23 @@ static ma_result ma_device_main_loop__winmm(ma_device* pDevice)
|
|||||||
case ma_device_type_capture:
|
case ma_device_type_capture:
|
||||||
{
|
{
|
||||||
/* We read in chunks of the period size, but use a stack allocated buffer for the intermediary. */
|
/* We read in chunks of the period size, but use a stack allocated buffer for the intermediary. */
|
||||||
ma_uint8 intermediaryBuffer[MA_DATA_CONVERTER_STACK_BUFFER_SIZE];
|
|
||||||
ma_uint32 intermediaryBufferSizeInFrames = sizeof(intermediaryBuffer) / ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels);
|
|
||||||
ma_uint32 periodSizeInFrames = pDevice->capture.internalPeriodSizeInFrames;
|
ma_uint32 periodSizeInFrames = pDevice->capture.internalPeriodSizeInFrames;
|
||||||
ma_uint32 framesReadThisPeriod = 0;
|
ma_uint32 framesReadThisPeriod = 0;
|
||||||
while (framesReadThisPeriod < periodSizeInFrames) {
|
while (framesReadThisPeriod < periodSizeInFrames) {
|
||||||
ma_uint32 framesRemainingInPeriod = periodSizeInFrames - framesReadThisPeriod;
|
ma_uint32 framesRemainingInPeriod = periodSizeInFrames - framesReadThisPeriod;
|
||||||
ma_uint32 framesProcessed;
|
ma_uint32 framesProcessed;
|
||||||
ma_uint32 framesToReadThisIteration = framesRemainingInPeriod;
|
ma_uint32 framesToReadThisIteration = framesRemainingInPeriod;
|
||||||
if (framesToReadThisIteration > intermediaryBufferSizeInFrames) {
|
if (framesToReadThisIteration > capturedDeviceDataCapInFrames) {
|
||||||
framesToReadThisIteration = intermediaryBufferSizeInFrames;
|
framesToReadThisIteration = capturedDeviceDataCapInFrames;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = ma_device_read__winmm(pDevice, intermediaryBuffer, framesToReadThisIteration, &framesProcessed);
|
result = ma_device_read__winmm(pDevice, capturedDeviceData, framesToReadThisIteration, &framesProcessed);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
exitLoop = MA_TRUE;
|
exitLoop = MA_TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ma_device__send_frames_to_client(pDevice, framesProcessed, intermediaryBuffer);
|
ma_device__send_frames_to_client(pDevice, framesProcessed, capturedDeviceData);
|
||||||
|
|
||||||
framesReadThisPeriod += framesProcessed;
|
framesReadThisPeriod += framesProcessed;
|
||||||
}
|
}
|
||||||
@@ -17338,21 +17336,19 @@ static ma_result ma_device_main_loop__winmm(ma_device* pDevice)
|
|||||||
case ma_device_type_playback:
|
case ma_device_type_playback:
|
||||||
{
|
{
|
||||||
/* We write in chunks of the period size, but use a stack allocated buffer for the intermediary. */
|
/* We write in chunks of the period size, but use a stack allocated buffer for the intermediary. */
|
||||||
ma_uint8 intermediaryBuffer[MA_DATA_CONVERTER_STACK_BUFFER_SIZE];
|
|
||||||
ma_uint32 intermediaryBufferSizeInFrames = sizeof(intermediaryBuffer) / ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels);
|
|
||||||
ma_uint32 periodSizeInFrames = pDevice->playback.internalPeriodSizeInFrames;
|
ma_uint32 periodSizeInFrames = pDevice->playback.internalPeriodSizeInFrames;
|
||||||
ma_uint32 framesWrittenThisPeriod = 0;
|
ma_uint32 framesWrittenThisPeriod = 0;
|
||||||
while (framesWrittenThisPeriod < periodSizeInFrames) {
|
while (framesWrittenThisPeriod < periodSizeInFrames) {
|
||||||
ma_uint32 framesRemainingInPeriod = periodSizeInFrames - framesWrittenThisPeriod;
|
ma_uint32 framesRemainingInPeriod = periodSizeInFrames - framesWrittenThisPeriod;
|
||||||
ma_uint32 framesProcessed;
|
ma_uint32 framesProcessed;
|
||||||
ma_uint32 framesToWriteThisIteration = framesRemainingInPeriod;
|
ma_uint32 framesToWriteThisIteration = framesRemainingInPeriod;
|
||||||
if (framesToWriteThisIteration > intermediaryBufferSizeInFrames) {
|
if (framesToWriteThisIteration > playbackDeviceDataCapInFrames) {
|
||||||
framesToWriteThisIteration = intermediaryBufferSizeInFrames;
|
framesToWriteThisIteration = playbackDeviceDataCapInFrames;
|
||||||
}
|
}
|
||||||
|
|
||||||
ma_device__read_frames_from_client(pDevice, framesToWriteThisIteration, intermediaryBuffer);
|
ma_device__read_frames_from_client(pDevice, framesToWriteThisIteration, playbackDeviceData);
|
||||||
|
|
||||||
result = ma_device_write__winmm(pDevice, intermediaryBuffer, framesToWriteThisIteration, &framesProcessed);
|
result = ma_device_write__winmm(pDevice, playbackDeviceData, framesToWriteThisIteration, &framesProcessed);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
exitLoop = MA_TRUE;
|
exitLoop = MA_TRUE;
|
||||||
break;
|
break;
|
||||||
@@ -37773,7 +37769,7 @@ static ma_result ma_resampler_process_pcm_frames__seek__linear(ma_resampler* pRe
|
|||||||
static ma_result ma_resampler_process_pcm_frames__seek__speex(ma_resampler* pResampler, const void* pFramesIn, ma_uint64* pFrameCountIn, ma_uint64* pFrameCountOut)
|
static ma_result ma_resampler_process_pcm_frames__seek__speex(ma_resampler* pResampler, const void* pFramesIn, ma_uint64* pFrameCountIn, ma_uint64* pFrameCountOut)
|
||||||
{
|
{
|
||||||
/* The generic seek method is implemented in on top of ma_resampler_process_pcm_frames__read() by just processing into a dummy buffer. */
|
/* The generic seek method is implemented in on top of ma_resampler_process_pcm_frames__read() by just processing into a dummy buffer. */
|
||||||
float devnull[8192];
|
float devnull[4096];
|
||||||
ma_uint64 totalOutputFramesToProcess;
|
ma_uint64 totalOutputFramesToProcess;
|
||||||
ma_uint64 totalOutputFramesProcessed;
|
ma_uint64 totalOutputFramesProcessed;
|
||||||
ma_uint64 totalInputFramesProcessed;
|
ma_uint64 totalInputFramesProcessed;
|
||||||
|
|||||||
Reference in New Issue
Block a user