Commit efe9d9e0 authored by David Reid's avatar David Reid

Small improvements to Core Audio.

parent 37d6bb6a
...@@ -4263,7 +4263,7 @@ static MAL_INLINE void mal_device__send_frames_to_client(mal_device* pDevice, ma ...@@ -4263,7 +4263,7 @@ static MAL_INLINE void mal_device__send_frames_to_client(mal_device* pDevice, ma
pDevice->_dspFrames = (const mal_uint8*)pSamples; pDevice->_dspFrames = (const mal_uint8*)pSamples;
mal_uint8 chunkBuffer[4096]; mal_uint8 chunkBuffer[4096];
mal_uint32 chunkFrameCount = sizeof(chunkBuffer) / mal_get_bytes_per_sample(pDevice->format) / pDevice->channels; mal_uint32 chunkFrameCount = sizeof(chunkBuffer) / mal_get_bytes_per_frame(pDevice->format, pDevice->channels);
for (;;) { for (;;) {
mal_uint32 framesJustRead = (mal_uint32)mal_dsp_read(&pDevice->dsp, chunkFrameCount, chunkBuffer, pDevice->dsp.pUserData); mal_uint32 framesJustRead = (mal_uint32)mal_dsp_read(&pDevice->dsp, chunkFrameCount, chunkBuffer, pDevice->dsp.pUserData);
...@@ -13395,14 +13395,13 @@ mal_result mal_set_AudioObject_buffer_size_in_frames(mal_context* pContext, Audi ...@@ -13395,14 +13395,13 @@ mal_result mal_set_AudioObject_buffer_size_in_frames(mal_context* pContext, Audi
propAddress.mScope = (deviceType == mal_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput; propAddress.mScope = (deviceType == mal_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput;
propAddress.mElement = kAudioObjectPropertyElementMaster; propAddress.mElement = kAudioObjectPropertyElementMaster;
OSStatus status = ((mal_AudioObjectSetPropertyData_proc)pContext->coreaudio.AudioObjectSetPropertyData)(deviceObjectID, &propAddress, 0, NULL, sizeof(chosenBufferSizeInFrames), &chosenBufferSizeInFrames); ((mal_AudioObjectSetPropertyData_proc)pContext->coreaudio.AudioObjectSetPropertyData)(deviceObjectID, &propAddress, 0, NULL, sizeof(chosenBufferSizeInFrames), &chosenBufferSizeInFrames);
// Get the actual size of the buffer.
UInt32 dataSize = sizeof(*pBufferSizeInOut);
OSStatus status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, &chosenBufferSizeInFrames);
if (status != noErr) { if (status != noErr) {
// Getting here means we were unable to set the buffer size. In this case just use whatever is currently selected. return mal_result_from_OSStatus(status);
UInt32 dataSize = sizeof(*pBufferSizeInOut);
OSStatus status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, pBufferSizeInOut);
if (status != noErr) {
return mal_result_from_OSStatus(status);
}
} }
*pBufferSizeInOut = chosenBufferSizeInFrames; *pBufferSizeInOut = chosenBufferSizeInFrames;
...@@ -13903,7 +13902,7 @@ mal_result mal_context_init__coreaudio(mal_context* pContext) ...@@ -13903,7 +13902,7 @@ mal_result mal_context_init__coreaudio(mal_context* pContext)
// It looks like Apple has moved some APIs from AudioUnit into AudioToolbox on more recent versions of macOS. They are still // It looks like Apple has moved some APIs from AudioUnit into AudioToolbox on more recent versions of macOS. They are still
// defined in AudioUnit, but just in case they decided to remove them from there entirely I'm going to do implement a fallback. // defined in AudioUnit, but just in case they decide to remove them from there entirely I'm going to implement a fallback.
// The way it'll work is that it'll first try AudioUnit, and if the required symbols are not present there we'll fall back to // The way it'll work is that it'll first try AudioUnit, and if the required symbols are not present there we'll fall back to
// AudioToolbox. // AudioToolbox.
pContext->coreaudio.hAudioUnit = mal_dlopen("AudioUnit.framework/AudioUnit"); pContext->coreaudio.hAudioUnit = mal_dlopen("AudioUnit.framework/AudioUnit");
...@@ -14213,7 +14212,6 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, mal_device_type dev ...@@ -14213,7 +14212,6 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, mal_device_type dev
} }
bestFormat.mSampleRate = origFormat.mSampleRate; bestFormat.mSampleRate = origFormat.mSampleRate;
//bestFormat = origFormat;
status = ((mal_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)((AudioUnit)pDevice->coreaudio.audioUnit, kAudioUnitProperty_StreamFormat, formatScope, formatElement, &bestFormat, sizeof(bestFormat)); status = ((mal_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)((AudioUnit)pDevice->coreaudio.audioUnit, kAudioUnitProperty_StreamFormat, formatScope, formatElement, &bestFormat, sizeof(bestFormat));
if (status != noErr) { if (status != noErr) {
...@@ -14305,7 +14303,7 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, mal_device_type dev ...@@ -14305,7 +14303,7 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, mal_device_type dev
} }
} }
actualBufferSizeInFrames = mal_next_power_of_2(actualBufferSizeInFrames / pDevice->periods); actualBufferSizeInFrames = actualBufferSizeInFrames / pDevice->periods;
result = mal_set_AudioObject_buffer_size_in_frames(pContext, deviceObjectID, deviceType, &actualBufferSizeInFrames); result = mal_set_AudioObject_buffer_size_in_frames(pContext, deviceObjectID, deviceType, &actualBufferSizeInFrames);
if (result != MAL_SUCCESS) { if (result != MAL_SUCCESS) {
return result; return result;
...@@ -23566,7 +23564,7 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount ...@@ -23566,7 +23564,7 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount
if (framesReadFromClient != 0) { if (framesReadFromClient != 0) {
pSRC->sinc.inputFrameCount += framesReadFromClient; pSRC->sinc.inputFrameCount += framesReadFromClient;
} else { } else {
// We couldn't get anything more from the client. If not more output samples can be computed from the available input samples // We couldn't get anything more from the client. If no more output samples can be computed from the available input samples
// we need to return. // we need to return.
if (((pSRC->sinc.timeIn - pSRC->sinc.inputFrameCount) * inverseFactor) < 1) { if (((pSRC->sinc.timeIn - pSRC->sinc.inputFrameCount) * inverseFactor) < 1) {
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