From 019ebcaf1578bd86bcf87130a354b24c06618111 Mon Sep 17 00:00:00 2001 From: Joebayld Date: Sun, 11 Dec 2016 20:36:34 -0500 Subject: [PATCH] Fixed for more than 1 stream On interfaces that contain more then 1 stream, this method would fail. Reason being because you needed to get the size of the buffer, but originally it was defaulted to 0 and thus failed. --- EZAudio/EZAudioDevice.m | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/EZAudio/EZAudioDevice.m b/EZAudio/EZAudioDevice.m index 6eacc2f6..e91f8be9 100644 --- a/EZAudio/EZAudioDevice.m +++ b/EZAudio/EZAudioDevice.m @@ -396,22 +396,34 @@ + (NSInteger)channelCountForScope:(AudioObjectPropertyScope)scope address.mElement = kAudioObjectPropertyElementMaster; address.mSelector = kAudioDevicePropertyStreamConfiguration; - AudioBufferList streamConfiguration; - UInt32 propSize = sizeof(streamConfiguration); + UInt32 dataSize = 0; + [EZAudioUtilities checkResult:AudioObjectGetPropertyDataSize(deviceID, + &address, + 0, + NULL, + &dataSize) + operation:"Failed to get buffer size"]; + + AudioBufferList *bufferList = (AudioBufferList *)(malloc(dataSize)); + [EZAudioUtilities checkResult:AudioObjectGetPropertyData(deviceID, &address, 0, NULL, - &propSize, - &streamConfiguration) - operation:"Failed to get frame size"]; + &dataSize, + bufferList) + operation:"Failed to get buffer list"]; + + UInt32 numBuffers = bufferList->mNumberBuffers; NSInteger channelCount = 0; - for (NSInteger i = 0; i < streamConfiguration.mNumberBuffers; i++) + for (NSInteger i = 0; i < numBuffers; i++) { - channelCount += streamConfiguration.mBuffers[i].mNumberChannels; + channelCount += bufferList->mBuffers[i].mNumberChannels; } + free(bufferList), bufferList = NULL; + return channelCount; }