OSStatus setSpeakerLayout(ASDeviceType typeRequested) {
AudioDeviceID currentDeviceID = kAudioDeviceUnknown;
char currentDeviceName[256];
UInt32 propertySize;
currentDeviceID = getCurrentlySelectedDeviceID(typeRequested);
getDeviceName(currentDeviceID, currentDeviceName);
AudioObjectPropertyAddress propertyAddress = {
.mSelector = kAudioDevicePropertyPreferredChannelLayout,
.mScope = kAudioDevicePropertyScopeOutput,
.mElement = kAudioObjectPropertyElementMaster,
};
if (AudioObjectHasProperty(currentDeviceID, &propertyAddress)) {
propertySize = 0;
AudioObjectGetPropertyDataSize(currentDeviceID, &propertyAddress, 0, NULL, &propertySize);
AudioChannelLayout* layout = (AudioChannelLayout*)malloc(propertySize);
// 5.1.4 Atmos L R C LFE Ls Rs Vhl Vhr Ltr Rtr
//layout->mChannelLayoutTag = kAudioChannelLayoutTag_Atmos_5_1_4;
layout->mNumberChannelDescriptions = 10;
layout->mChannelDescriptions[0].mChannelLabel = kAudioChannelLabel_Left;
layout->mChannelDescriptions[1].mChannelLabel = kAudioChannelLabel_Right;
layout->mChannelDescriptions[5].mChannelLabel = kAudioChannelLabel_Center;
layout->mChannelDescriptions[4].mChannelLabel = kAudioChannelLabel_LFEScreen;
layout->mChannelDescriptions[2].mChannelLabel = kAudioChannelLabel_LeftSurround;
layout->mChannelDescriptions[3].mChannelLabel = kAudioChannelLabel_RightSurround;
layout->mChannelDescriptions[6].mChannelLabel = kAudioChannelLabel_VerticalHeightLeft;
layout->mChannelDescriptions[7].mChannelLabel = kAudioChannelLabel_VerticalHeightRight;
layout->mChannelDescriptions[8].mChannelLabel = kAudioChannelLabel_LeftTopRear;
layout->mChannelDescriptions[9].mChannelLabel = kAudioChannelLabel_RightTopRear;
for (UInt32 i = 0; i < layout->mNumberChannelDescriptions; i++) {
layout->mChannelDescriptions[i].mChannelFlags = kAudioChannelFlags_AllOff;
}
return AudioObjectSetPropertyData(currentDeviceID, &propertyAddress, 0, NULL, propertySize, layout);
}
return 0;
}