c++ - WASAPI: Choosing a wave format for exclusive output -
i'm trying open exclusive stream output device using wasapi. i'm having trouble choosing acceptable format, since there appear no hints formats accepted given device.
in case, iaudioclient::getmixformat()
, otherwise return sort of default format device, returns format can't used in exclusive mode (iaudioclient::isformatsupported()
returns audclnt_e_unsupported_format
). don't know go there. there's ridiculous number of combinations of wave format parameters - literally have iterate through every 1 of them until works?
well, asked msdn forums , came answer.
you need check device's default device format via immdevice::openpropertystore()
, , subsequently ipropertystore::getvalue()
, not iaudioclient::getmixformat()
. here code retrieved acceptable waveformatex structure:
//coinitialize/enumerate devices ipropertystore* store = nullptr; hr = device->openpropertystore(stgm_read, &store); if (failed(hr)) { exitprocess(1); } propvariant prop; hr = store->getvalue(pkey_audioengine_deviceformat, &prop); if (failed(hr)) { exitprocess(2); } hr = device->activate ( __uuidof(iaudioclient), clsctx_all, null, (void**)&audioclient ); device->release(); device = nullptr; if (failed(hr)) { exitprocess(3); } hr = audioclient->isformatsupported ( audclnt_sharemode_exclusive, (pwaveformatex)prop.blob.pblobdata, null ); if (failed(hr)) { exitprocess(4); }
the final value of hr s_ok.
Comments
Post a Comment