osx - How to set speaker configuration programatically using Core Audio API on Mac OS X? -
i have 7.1 channel audio output device , custom kext drive that. custom application needs send 7.1 rear channel audio data device device receives 2 channel audio data. checked "configure speaker" option in "audio midi setup" application , it's set stereo. when set "7.1 rear surround" works fine. in final product, don't want user have of manually. so, question - there core audio api or other means of doing programatically?
ok, after playing around core audio apis, done.
get audiodeviceid:
audiodeviceid audiodevice = getmyawesomedeviceid();
create audioobjectpropertyaddress:
audioobjectpropertyaddress propertyaddress; propertyaddress.mselector = kaudiodevicepropertypreferredchannellayout; propertyaddress.mscope = kaudiodevicepropertyscopeoutput; propertyaddress.melement = kaudioobjectpropertyelementmaster;
query if audio object has property:
audioobjecthasproperty(audiodevice, &propertyaddress)
get data size of property , create audiochannellayout:
uint32 propsize(0); audioobjectgetpropertydatasize(audiodevice, &propertyaddress, 0, null, &propsize); audiochannellayout* layout = (audiochannellayout*)malloc(propsize);
configure audiochannellayout structure (eg: stereo layout):
audiochannellabel labels[2] = {kaudiochannellabel_right, kaudiochannellabel_left}; layout->mnumberchanneldescriptions = 2; (uint32 = 2; < layout->mnumberchanneldescriptions; i++) { layout->mchanneldescriptions[i].mchannellabel = labels[i]; layout->mchanneldescriptions[i].mchannelflags = kaudiochannelflags_alloff; }
set audioobject property data:
audioobjectsetpropertydata(audiodevice, &propertyaddress, 0, null, propsize, layout);
Comments
Post a Comment