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?

enter image description here

ok, after playing around core audio apis, done.

  1. get audiodeviceid:

    audiodeviceid audiodevice = getmyawesomedeviceid(); 
  2. create audioobjectpropertyaddress:

    audioobjectpropertyaddress propertyaddress; propertyaddress.mselector = kaudiodevicepropertypreferredchannellayout; propertyaddress.mscope = kaudiodevicepropertyscopeoutput; propertyaddress.melement = kaudioobjectpropertyelementmaster; 
  3. query if audio object has property:

    audioobjecthasproperty(audiodevice, &propertyaddress) 
  4. get data size of property , create audiochannellayout:

    uint32 propsize(0); audioobjectgetpropertydatasize(audiodevice, &propertyaddress, 0, null, &propsize); audiochannellayout* layout = (audiochannellayout*)malloc(propsize); 
  5. 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; } 
  6. set audioobject property data:

    audioobjectsetpropertydata(audiodevice, &propertyaddress, 0, null, propsize, layout); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -