From 88f85741978fd44e28eb5f166601b1f1c6337c14 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 21 Jul 2021 20:37:42 +1000 Subject: [PATCH 1/4] Fix a bug when converting from stereo to mono. Public issue https://github.com/mackron/miniaudio/issues/347 --- miniaudio.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 97d8d650..8311736e 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -1,6 +1,6 @@ /* Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file. -miniaudio - v0.10.39 - 2021-07-20 +miniaudio - v0.10.40 - TBD David Reid - mackron@gmail.com @@ -1498,7 +1498,7 @@ extern "C" { #define MA_VERSION_MAJOR 0 #define MA_VERSION_MINOR 10 -#define MA_VERSION_REVISION 39 +#define MA_VERSION_REVISION 40 #define MA_VERSION_STRING MA_XSTRINGIFY(MA_VERSION_MAJOR) "." MA_XSTRINGIFY(MA_VERSION_MINOR) "." MA_XSTRINGIFY(MA_VERSION_REVISION) #if defined(_MSC_VER) && !defined(__clang__) @@ -40881,7 +40881,7 @@ static ma_result ma_channel_converter_process_pcm_frames__stereo_to_mono(ma_chan const float* pFramesInF32 = (const float*)pFramesIn; for (iFrame = 0; iFrame < frameCount; ++iFrame) { - pFramesOutF32[iFrame] = (pFramesInF32[iFrame*2+0] + pFramesInF32[iFrame*2+0]) * 0.5f; + pFramesOutF32[iFrame] = (pFramesInF32[iFrame*2+0] + pFramesInF32[iFrame*2+1]) * 0.5f; } } break; @@ -69396,6 +69396,9 @@ The following miscellaneous changes have also been made. /* REVISION HISTORY ================ +v0.10.40 - TBD + - Fix a bug when converting from stereo to mono. + v0.10.39 - 2021-07-20 - Core Audio: Fix a deadlock when the default device is changed. - Core Audio: Fix compilation errors on macOS and iOS. From 05e99c880b4975e8348c093c2d59b4467d093fe9 Mon Sep 17 00:00:00 2001 From: David Reid Date: Thu, 22 Jul 2021 19:28:38 +1000 Subject: [PATCH 2/4] PulseAudio: Fix a glitch when pausing and resuming a device. Public issue https://github.com/mackron/miniaudio/issues/348 --- miniaudio.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 8311736e..a926f359 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -23075,10 +23075,11 @@ static ma_result ma_device_write_to_stream__pulse(ma_device* pDevice, ma_pa_stre framesMapped = bytesMapped / bpf; - if (deviceState == MA_STATE_STARTED) { + if (deviceState == MA_STATE_STARTED || deviceState == MA_STATE_STARTING) { /* Check for starting state just in case this is being used to do the initial fill. */ ma_device_handle_backend_data_callback(pDevice, pMappedPCMFrames, NULL, framesMapped); } else { - /* Device is not started. Don't write anything to it. */ + /* Device is not started. Write silence. */ + ma_silence_pcm_frames(pMappedPCMFrames, framesMapped, pDevice->playback.format, pDevice->playback.channels); } pulseResult = ((ma_pa_stream_write_proc)pDevice->pContext->pulse.pa_stream_write)(pStream, pMappedPCMFrames, bytesMapped, NULL, 0, MA_PA_SEEK_RELATIVE); @@ -23286,6 +23287,9 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi /* The callback needs to be set before connecting the stream. */ ((ma_pa_stream_set_read_callback_proc)pDevice->pContext->pulse.pa_stream_set_read_callback)((ma_pa_stream*)pDevice->pulse.pStreamCapture, ma_device_on_read__pulse, pDevice); + /* State callback for checking when the device has been corked. */ + ((ma_pa_stream_set_suspended_callback_proc)pDevice->pContext->pulse.pa_stream_set_suspended_callback)((ma_pa_stream*)pDevice->pulse.pStreamCapture, ma_device_on_suspended__pulse, pDevice); + /* Connect after we've got all of our internal state set up. */ streamFlags = MA_PA_STREAM_START_CORKED | MA_PA_STREAM_ADJUST_LATENCY | MA_PA_STREAM_FIX_FORMAT | MA_PA_STREAM_FIX_RATE | MA_PA_STREAM_FIX_CHANNELS; @@ -23377,7 +23381,6 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi attr = ma_device__pa_buffer_attr_new(pDescriptorPlayback->periodSizeInFrames, pDescriptorPlayback->periodCount, &ss); - ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[PulseAudio] Playback attr: maxlength=%d, tlength=%d, prebuf=%d, minreq=%d, fragsize=%d; periodSizeInFrames=%d\n", attr.maxlength, attr.tlength, attr.prebuf, attr.minreq, attr.fragsize, pDescriptorPlayback->periodSizeInFrames); ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[PulseAudio] Playback attr: maxlength=%d, tlength=%d, prebuf=%d, minreq=%d, fragsize=%d; periodSizeInFrames=%d\n", attr.maxlength, attr.tlength, attr.prebuf, attr.minreq, attr.fragsize, pDescriptorPlayback->periodSizeInFrames); pDevice->pulse.pStreamPlayback = ma_context__pa_stream_new__pulse(pDevice->pContext, pConfig->pulse.pStreamNamePlayback, &ss, &cmap); From 3622dbea39e4e7bcf93525fa15c064897b62b31d Mon Sep 17 00:00:00 2001 From: David Reid Date: Fri, 23 Jul 2021 18:36:27 +1000 Subject: [PATCH 3/4] Update revision history. --- miniaudio.h | 1 + 1 file changed, 1 insertion(+) diff --git a/miniaudio.h b/miniaudio.h index a926f359..dcee545f 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -69401,6 +69401,7 @@ REVISION HISTORY ================ v0.10.40 - TBD - Fix a bug when converting from stereo to mono. + - PulseAudio: Fix a glitch when pausing and resuming a device. v0.10.39 - 2021-07-20 - Core Audio: Fix a deadlock when the default device is changed. From 37fe1343f04f6fd9bd82229ca50a48b77ecce564 Mon Sep 17 00:00:00 2001 From: David Reid Date: Fri, 23 Jul 2021 19:33:39 +1000 Subject: [PATCH 4/4] Version 0.10.40 --- extras/miniaudio_split/miniaudio.c | 13 ++++++++----- extras/miniaudio_split/miniaudio.h | 4 ++-- miniaudio.h | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/extras/miniaudio_split/miniaudio.c b/extras/miniaudio_split/miniaudio.c index 082bf38b..e4e13b39 100644 --- a/extras/miniaudio_split/miniaudio.c +++ b/extras/miniaudio_split/miniaudio.c @@ -1,6 +1,6 @@ /* Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file. -miniaudio - v0.10.39 - 2021-07-20 +miniaudio - v0.10.40 - 2021-07-23 David Reid - mackron@gmail.com @@ -16546,10 +16546,11 @@ static ma_result ma_device_write_to_stream__pulse(ma_device* pDevice, ma_pa_stre framesMapped = bytesMapped / bpf; - if (deviceState == MA_STATE_STARTED) { + if (deviceState == MA_STATE_STARTED || deviceState == MA_STATE_STARTING) { /* Check for starting state just in case this is being used to do the initial fill. */ ma_device_handle_backend_data_callback(pDevice, pMappedPCMFrames, NULL, framesMapped); } else { - /* Device is not started. Don't write anything to it. */ + /* Device is not started. Write silence. */ + ma_silence_pcm_frames(pMappedPCMFrames, framesMapped, pDevice->playback.format, pDevice->playback.channels); } pulseResult = ((ma_pa_stream_write_proc)pDevice->pContext->pulse.pa_stream_write)(pStream, pMappedPCMFrames, bytesMapped, NULL, 0, MA_PA_SEEK_RELATIVE); @@ -16757,6 +16758,9 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi /* The callback needs to be set before connecting the stream. */ ((ma_pa_stream_set_read_callback_proc)pDevice->pContext->pulse.pa_stream_set_read_callback)((ma_pa_stream*)pDevice->pulse.pStreamCapture, ma_device_on_read__pulse, pDevice); + /* State callback for checking when the device has been corked. */ + ((ma_pa_stream_set_suspended_callback_proc)pDevice->pContext->pulse.pa_stream_set_suspended_callback)((ma_pa_stream*)pDevice->pulse.pStreamCapture, ma_device_on_suspended__pulse, pDevice); + /* Connect after we've got all of our internal state set up. */ streamFlags = MA_PA_STREAM_START_CORKED | MA_PA_STREAM_ADJUST_LATENCY | MA_PA_STREAM_FIX_FORMAT | MA_PA_STREAM_FIX_RATE | MA_PA_STREAM_FIX_CHANNELS; @@ -16848,7 +16852,6 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi attr = ma_device__pa_buffer_attr_new(pDescriptorPlayback->periodSizeInFrames, pDescriptorPlayback->periodCount, &ss); - ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[PulseAudio] Playback attr: maxlength=%d, tlength=%d, prebuf=%d, minreq=%d, fragsize=%d; periodSizeInFrames=%d\n", attr.maxlength, attr.tlength, attr.prebuf, attr.minreq, attr.fragsize, pDescriptorPlayback->periodSizeInFrames); ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[PulseAudio] Playback attr: maxlength=%d, tlength=%d, prebuf=%d, minreq=%d, fragsize=%d; periodSizeInFrames=%d\n", attr.maxlength, attr.tlength, attr.prebuf, attr.minreq, attr.fragsize, pDescriptorPlayback->periodSizeInFrames); pDevice->pulse.pStreamPlayback = ma_context__pa_stream_new__pulse(pDevice->pContext, pConfig->pulse.pStreamNamePlayback, &ss, &cmap); @@ -34352,7 +34355,7 @@ static ma_result ma_channel_converter_process_pcm_frames__stereo_to_mono(ma_chan const float* pFramesInF32 = (const float*)pFramesIn; for (iFrame = 0; iFrame < frameCount; ++iFrame) { - pFramesOutF32[iFrame] = (pFramesInF32[iFrame*2+0] + pFramesInF32[iFrame*2+0]) * 0.5f; + pFramesOutF32[iFrame] = (pFramesInF32[iFrame*2+0] + pFramesInF32[iFrame*2+1]) * 0.5f; } } break; diff --git a/extras/miniaudio_split/miniaudio.h b/extras/miniaudio_split/miniaudio.h index e8edfa53..4ffa0091 100644 --- a/extras/miniaudio_split/miniaudio.h +++ b/extras/miniaudio_split/miniaudio.h @@ -1,6 +1,6 @@ /* Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file. -miniaudio - v0.10.39 - 2021-07-20 +miniaudio - v0.10.40 - 2021-07-23 David Reid - mackron@gmail.com @@ -20,7 +20,7 @@ extern "C" { #define MA_VERSION_MAJOR 0 #define MA_VERSION_MINOR 10 -#define MA_VERSION_REVISION 39 +#define MA_VERSION_REVISION 40 #define MA_VERSION_STRING MA_XSTRINGIFY(MA_VERSION_MAJOR) "." MA_XSTRINGIFY(MA_VERSION_MINOR) "." MA_XSTRINGIFY(MA_VERSION_REVISION) #if defined(_MSC_VER) && !defined(__clang__) diff --git a/miniaudio.h b/miniaudio.h index dcee545f..27425c72 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -1,6 +1,6 @@ /* Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file. -miniaudio - v0.10.40 - TBD +miniaudio - v0.10.40 - 2021-07-23 David Reid - mackron@gmail.com @@ -69399,7 +69399,7 @@ The following miscellaneous changes have also been made. /* REVISION HISTORY ================ -v0.10.40 - TBD +v0.10.40 - 2021-07-23 - Fix a bug when converting from stereo to mono. - PulseAudio: Fix a glitch when pausing and resuming a device.