iOS: Add support for configuring the size of the IO buffer.

This commit is contained in:
David Reid
2021-12-28 08:13:30 +10:00
parent fdf2a28338
commit 3f044fc658
+9 -9
View File
@@ -31272,7 +31272,6 @@ static ma_result ma_device__untrack__coreaudio(ma_device* pDevice)
-(void)dealloc -(void)dealloc
{ {
[self remove_handler]; [self remove_handler];
[super dealloc];
} }
-(void)remove_handler -(void)remove_handler
@@ -31428,8 +31427,6 @@ static ma_result ma_device_init_internal__coreaudio(ma_context* pContext, ma_dev
AURenderCallbackStruct callbackInfo; AURenderCallbackStruct callbackInfo;
#if defined(MA_APPLE_DESKTOP) #if defined(MA_APPLE_DESKTOP)
AudioObjectID deviceObjectID; AudioObjectID deviceObjectID;
#else
UInt32 actualPeriodSizeInFramesSize = sizeof(actualPeriodSizeInFrames);
#endif #endif
/* This API should only be used for a single device type: playback or capture. No full-duplex mode. */ /* This API should only be used for a single device type: playback or capture. No full-duplex mode. */
@@ -31714,13 +31711,16 @@ static ma_result ma_device_init_internal__coreaudio(ma_context* pContext, ma_dev
} }
#else #else
/* /*
I don't know how to configure buffer sizes on iOS so for now we're not allowing it to be configured. Instead we're On iOS, the size of the IO buffer needs to be specified in seconds and is a floating point
just going to set it to the value of kAudioUnitProperty_MaximumFramesPerSlice. number. I don't trust any potential truncation errors due to converting from float to integer
so I'm going to explicitly set the actual period size to the next power of 2.
*/ */
status = ((ma_AudioUnitGetProperty_proc)pContext->coreaudio.AudioUnitGetProperty)(pData->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, &actualPeriodSizeInFrames, &actualPeriodSizeInFramesSize); @autoreleasepool {
if (status != noErr) { AVAudioSession* pAudioSession = [AVAudioSession sharedInstance];
((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); MA_ASSERT(pAudioSession != NULL);
return ma_result_from_OSStatus(status);
[pAudioSession setPreferredIOBufferDuration:((float)actualPeriodSizeInFrames / pAudioSession.sampleRate) error:nil];
actualPeriodSizeInFrames = ma_next_power_of_2((ma_uint32)(pAudioSession.IOBufferDuration * pAudioSession.sampleRate));
} }
#endif #endif