From 781ce447fd4203e7515a1d4b317e5e71ae919d6d Mon Sep 17 00:00:00 2001 From: David Reid Date: Tue, 2 Feb 2021 18:12:52 +1000 Subject: [PATCH] iOS: Experimental fixes to automatic stream routing. Public issue https://github.com/mackron/miniaudio/issues/101 --- miniaudio.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index e17aa8b1..c99c37a1 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -25714,16 +25714,26 @@ static ma_result ma_device__untrack__coreaudio(ma_device* pDevice) printf("[Core Audio] Changing Route. inputNumberChannels=%d; outputNumberOfChannels=%d\n", (int)pSession.inputNumberOfChannels, (int)pSession.outputNumberOfChannels); #endif - m_pDevice->sampleRate = (ma_uint32)pSession.sampleRate; + ma_uint32 previousState = ma_device_get_state(m_pDevice); + + if (previousState == MA_DEVICE_STARTED) { + ma_device_stop(m_pDevice); + } if (m_pDevice->type == ma_device_type_capture || m_pDevice->type == ma_device_type_duplex) { - m_pDevice->capture.internalChannels = (ma_uint32)pSession.inputNumberOfChannels; + m_pDevice->capture.internalChannels = (ma_uint32)pSession.inputNumberOfChannels; + m_pDevice->capture.internalSampleRate = (ma_uint32)pSession.sampleRate; ma_device__post_init_setup(m_pDevice, ma_device_type_capture); } if (m_pDevice->type == ma_device_type_playback || m_pDevice->type == ma_device_type_duplex) { - m_pDevice->playback.internalChannels = (ma_uint32)pSession.outputNumberOfChannels; + m_pDevice->playback.internalChannels = (ma_uint32)pSession.outputNumberOfChannels; + m_pDevice->playback.internalSampleRate = (ma_uint32)pSession.sampleRate; ma_device__post_init_setup(m_pDevice, ma_device_type_playback); } + + if (previousState == MA_DEVICE_STARTED) { + ma_device_start(m_pDevice); + } } @end #endif