pa_win_wasapi.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. #ifndef PA_WIN_WASAPI_H
  2. #define PA_WIN_WASAPI_H
  3. /*
  4. * $Id: $
  5. * PortAudio Portable Real-Time Audio Library
  6. * WASAPI specific extensions
  7. *
  8. * Copyright (c) 1999-2018 Ross Bencina and Phil Burk
  9. * Copyright (c) 2006-2010 David Viens
  10. * Copyright (c) 2010-2022 Dmitry Kostjuchenko
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining
  13. * a copy of this software and associated documentation files
  14. * (the "Software"), to deal in the Software without restriction,
  15. * including without limitation the rights to use, copy, modify, merge,
  16. * publish, distribute, sublicense, and/or sell copies of the Software,
  17. * and to permit persons to whom the Software is furnished to do so,
  18. * subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be
  21. * included in all copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  26. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  27. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  28. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. */
  31. /*
  32. * The text above constitutes the entire PortAudio license; however,
  33. * the PortAudio community also makes the following non-binding requests:
  34. *
  35. * Any person wishing to distribute modifications to the Software is
  36. * requested to send the modifications to the original developer so that
  37. * they can be incorporated into the canonical version. It is also
  38. * requested that these non-binding requests be included along with the
  39. * license above.
  40. */
  41. /** @file
  42. @ingroup public_header
  43. @brief WASAPI-specific PortAudio API extension header file.
  44. */
  45. #include "portaudio.h"
  46. #include "pa_win_waveformat.h"
  47. #ifdef __cplusplus
  48. extern "C"
  49. {
  50. #endif /* __cplusplus */
  51. /* Stream setup flags. */
  52. typedef enum PaWasapiFlags
  53. {
  54. /* put WASAPI into exclusive mode */
  55. paWinWasapiExclusive = (1 << 0),
  56. /* allow to skip internal PA processing completely */
  57. paWinWasapiRedirectHostProcessor = (1 << 1),
  58. /* assign custom channel mask */
  59. paWinWasapiUseChannelMask = (1 << 2),
  60. /* use Polling method (Event method is the default, see details in the IMPORTANT notes) */
  61. paWinWasapiPolling = (1 << 3),
  62. /* force custom thread priority setting, must be used if PaWasapiStreamInfo::threadPriority
  63. is set to a custom value */
  64. paWinWasapiThreadPriority = (1 << 4),
  65. /* force explicit sample format and do not allow PA to select suitable working format, API will
  66. fail if provided sample format is not supported by audio hardware in Exclusive mode
  67. or system mixer in Shared mode */
  68. paWinWasapiExplicitSampleFormat = (1 << 5),
  69. /* allow API to insert system-level channel matrix mixer and sample rate converter to allow
  70. playback formats that do not match the current configured system settings.
  71. this is in particular required for streams not matching the system mixer sample rate.
  72. only applies in Shared mode. */
  73. paWinWasapiAutoConvert = (1 << 6)
  74. }
  75. PaWasapiFlags;
  76. #define paWinWasapiExclusive (paWinWasapiExclusive)
  77. #define paWinWasapiRedirectHostProcessor (paWinWasapiRedirectHostProcessor)
  78. #define paWinWasapiUseChannelMask (paWinWasapiUseChannelMask)
  79. #define paWinWasapiPolling (paWinWasapiPolling)
  80. #define paWinWasapiThreadPriority (paWinWasapiThreadPriority)
  81. #define paWinWasapiExplicitSampleFormat (paWinWasapiExplicitSampleFormat)
  82. #define paWinWasapiAutoConvert (paWinWasapiAutoConvert)
  83. /* Stream state.
  84. @note Multiple states can be united into a bitmask.
  85. @see PaWasapiStreamStateCallback, PaWasapi_SetStreamStateHandler
  86. */
  87. typedef enum PaWasapiStreamState
  88. {
  89. /* state change was caused by the error:
  90. Example:
  91. 1) If thread execution stopped due to AUDCLNT_E_RESOURCES_INVALIDATED then state
  92. value will contain paWasapiStreamStateError|paWasapiStreamStateThreadStop.
  93. */
  94. paWasapiStreamStateError = (1 << 0),
  95. /* processing thread is preparing to start execution */
  96. paWasapiStreamStateThreadPrepare = (1 << 1),
  97. /* processing thread started execution (enters its loop) */
  98. paWasapiStreamStateThreadStart = (1 << 2),
  99. /* processing thread stopped execution */
  100. paWasapiStreamStateThreadStop = (1 << 3)
  101. }
  102. PaWasapiStreamState;
  103. #define paWasapiStreamStateError (paWasapiStreamStateError)
  104. #define paWasapiStreamStateThreadPrepare (paWasapiStreamStateThreadPrepare)
  105. #define paWasapiStreamStateThreadStart (paWasapiStreamStateThreadStart)
  106. #define paWasapiStreamStateThreadStop (paWasapiStreamStateThreadStop)
  107. /* Host processor.
  108. Allows to skip internal PA processing completely. paWinWasapiRedirectHostProcessor flag
  109. must be set to the PaWasapiStreamInfo::flags member in order to have host processor
  110. redirected to this callback.
  111. Use with caution! inputFrames and outputFrames depend solely on final device setup.
  112. To query max values of inputFrames/outputFrames use PaWasapi_GetFramesPerHostBuffer.
  113. */
  114. typedef void (*PaWasapiHostProcessorCallback) (void *inputBuffer, long inputFrames,
  115. void *outputBuffer, long outputFrames, void *userData);
  116. /* Stream state handler.
  117. @param pStream Pointer to PaStream object.
  118. @param stateFlags State flags, a collection of values from PaWasapiStreamState enum.
  119. @param errorId Error id provided by system API (HRESULT).
  120. @param userData Pointer to user data.
  121. @see PaWasapiStreamState
  122. */
  123. typedef void (*PaWasapiStreamStateCallback) (PaStream *pStream, unsigned int stateFlags,
  124. unsigned int errorId, void *pUserData);
  125. /* Device role. */
  126. typedef enum PaWasapiDeviceRole
  127. {
  128. eRoleRemoteNetworkDevice = 0,
  129. eRoleSpeakers,
  130. eRoleLineLevel,
  131. eRoleHeadphones,
  132. eRoleMicrophone,
  133. eRoleHeadset,
  134. eRoleHandset,
  135. eRoleUnknownDigitalPassthrough,
  136. eRoleSPDIF,
  137. eRoleHDMI,
  138. eRoleUnknownFormFactor
  139. }
  140. PaWasapiDeviceRole;
  141. /* Jack connection type. */
  142. typedef enum PaWasapiJackConnectionType
  143. {
  144. eJackConnTypeUnknown,
  145. eJackConnType3Point5mm,
  146. eJackConnTypeQuarter,
  147. eJackConnTypeAtapiInternal,
  148. eJackConnTypeRCA,
  149. eJackConnTypeOptical,
  150. eJackConnTypeOtherDigital,
  151. eJackConnTypeOtherAnalog,
  152. eJackConnTypeMultichannelAnalogDIN,
  153. eJackConnTypeXlrProfessional,
  154. eJackConnTypeRJ11Modem,
  155. eJackConnTypeCombination
  156. }
  157. PaWasapiJackConnectionType;
  158. /* Jack geometric location. */
  159. typedef enum PaWasapiJackGeoLocation
  160. {
  161. eJackGeoLocUnk = 0,
  162. eJackGeoLocRear = 0x1, /* matches EPcxGeoLocation::eGeoLocRear */
  163. eJackGeoLocFront,
  164. eJackGeoLocLeft,
  165. eJackGeoLocRight,
  166. eJackGeoLocTop,
  167. eJackGeoLocBottom,
  168. eJackGeoLocRearPanel,
  169. eJackGeoLocRiser,
  170. eJackGeoLocInsideMobileLid,
  171. eJackGeoLocDrivebay,
  172. eJackGeoLocHDMI,
  173. eJackGeoLocOutsideMobileLid,
  174. eJackGeoLocATAPI,
  175. eJackGeoLocReserved5,
  176. eJackGeoLocReserved6,
  177. }
  178. PaWasapiJackGeoLocation;
  179. /* Jack general location. */
  180. typedef enum PaWasapiJackGenLocation
  181. {
  182. eJackGenLocPrimaryBox = 0,
  183. eJackGenLocInternal,
  184. eJackGenLocSeparate,
  185. eJackGenLocOther
  186. }
  187. PaWasapiJackGenLocation;
  188. /* Jack's type of port. */
  189. typedef enum PaWasapiJackPortConnection
  190. {
  191. eJackPortConnJack = 0,
  192. eJackPortConnIntegratedDevice,
  193. eJackPortConnBothIntegratedAndJack,
  194. eJackPortConnUnknown
  195. }
  196. PaWasapiJackPortConnection;
  197. /* Thread priority. */
  198. typedef enum PaWasapiThreadPriority
  199. {
  200. eThreadPriorityNone = 0,
  201. eThreadPriorityAudio, //!< Default for Shared mode.
  202. eThreadPriorityCapture,
  203. eThreadPriorityDistribution,
  204. eThreadPriorityGames,
  205. eThreadPriorityPlayback,
  206. eThreadPriorityProAudio, //!< Default for Exclusive mode.
  207. eThreadPriorityWindowManager
  208. }
  209. PaWasapiThreadPriority;
  210. /* Stream descriptor. */
  211. typedef struct PaWasapiJackDescription
  212. {
  213. unsigned long channelMapping;
  214. unsigned long color; /* derived from macro: #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) */
  215. PaWasapiJackConnectionType connectionType;
  216. PaWasapiJackGeoLocation geoLocation;
  217. PaWasapiJackGenLocation genLocation;
  218. PaWasapiJackPortConnection portConnection;
  219. unsigned int isConnected;
  220. }
  221. PaWasapiJackDescription;
  222. /** Stream category.
  223. Note:
  224. - values are equal to WASAPI AUDIO_STREAM_CATEGORY enum
  225. - supported since Windows 8.0, noop on earlier versions
  226. - values 1,2 are deprecated on Windows 10 and not included into enumeration
  227. @version Available as of 19.6.0
  228. */
  229. typedef enum PaWasapiStreamCategory
  230. {
  231. eAudioCategoryOther = 0,
  232. eAudioCategoryCommunications = 3,
  233. eAudioCategoryAlerts = 4,
  234. eAudioCategorySoundEffects = 5,
  235. eAudioCategoryGameEffects = 6,
  236. eAudioCategoryGameMedia = 7,
  237. eAudioCategoryGameChat = 8,
  238. eAudioCategorySpeech = 9,
  239. eAudioCategoryMovie = 10,
  240. eAudioCategoryMedia = 11
  241. }
  242. PaWasapiStreamCategory;
  243. /** Stream option.
  244. Note:
  245. - values are equal to WASAPI AUDCLNT_STREAMOPTIONS enum
  246. - supported since Windows 8.1, noop on earlier versions
  247. @version Available as of 19.6.0
  248. */
  249. typedef enum PaWasapiStreamOption
  250. {
  251. eStreamOptionNone = 0, //!< default
  252. eStreamOptionRaw = 1, //!< bypass WASAPI Audio Engine DSP effects, supported since Windows 8.1
  253. eStreamOptionMatchFormat = 2 //!< force WASAPI Audio Engine into a stream format, supported since Windows 10
  254. }
  255. PaWasapiStreamOption;
  256. /* Stream descriptor. */
  257. typedef struct PaWasapiStreamInfo
  258. {
  259. unsigned long size; /**< sizeof(PaWasapiStreamInfo) */
  260. PaHostApiTypeId hostApiType; /**< paWASAPI */
  261. unsigned long version; /**< 1 */
  262. unsigned long flags; /**< collection of PaWasapiFlags */
  263. /** Support for WAVEFORMATEXTENSIBLE channel masks. If flags contains
  264. paWinWasapiUseChannelMask this allows you to specify which speakers
  265. to address in a multichannel stream. Constants for channelMask
  266. are specified in pa_win_waveformat.h. Will be used only if
  267. paWinWasapiUseChannelMask flag is specified.
  268. */
  269. PaWinWaveFormatChannelMask channelMask;
  270. /** Delivers raw data to callback obtained from GetBuffer() methods skipping
  271. internal PortAudio processing inventory completely. userData parameter will
  272. be the same that was passed to Pa_OpenStream method. Will be used only if
  273. paWinWasapiRedirectHostProcessor flag is specified.
  274. */
  275. PaWasapiHostProcessorCallback hostProcessorOutput;
  276. PaWasapiHostProcessorCallback hostProcessorInput;
  277. /** Specifies thread priority explicitly. Will be used only if paWinWasapiThreadPriority flag
  278. is specified.
  279. Please note, if Input/Output streams are opened simultaneously (Full-Duplex mode)
  280. you shall specify same value for threadPriority or othervise one of the values will be used
  281. to setup thread priority.
  282. */
  283. PaWasapiThreadPriority threadPriority;
  284. /** Stream category.
  285. @see PaWasapiStreamCategory
  286. @version Available as of 19.6.0
  287. */
  288. PaWasapiStreamCategory streamCategory;
  289. /** Stream option.
  290. @see PaWasapiStreamOption
  291. @version Available as of 19.6.0
  292. */
  293. PaWasapiStreamOption streamOption;
  294. }
  295. PaWasapiStreamInfo;
  296. /** Returns pointer to WASAPI's IAudioClient object of the stream.
  297. @param pStream Pointer to PaStream object.
  298. @param pAudioClient Pointer to pointer of IAudioClient.
  299. @param bOutput TRUE (1) for output stream, FALSE (0) for input stream.
  300. @return Error code indicating success or failure.
  301. */
  302. PaError PaWasapi_GetAudioClient( PaStream *pStream, void **pAudioClient, int bOutput );
  303. /** Update device list.
  304. This function is available if PA_WASAPI_MAX_CONST_DEVICE_COUNT is defined during compile time
  305. with maximum constant WASAPI device count (recommended value - 32).
  306. If PA_WASAPI_MAX_CONST_DEVICE_COUNT is set to 0 (or not defined) during compile time the implementation
  307. will not define PaWasapi_UpdateDeviceList() and thus updating device list can only be possible by calling
  308. Pa_Terminate() and then Pa_Initialize().
  309. @return Error code indicating success or failure.
  310. */
  311. PaError PaWasapi_UpdateDeviceList();
  312. /** Get current audio format of the device assigned to the opened stream.
  313. Format is represented by PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure.
  314. Use this function to reconfirm format if PA's processor is overridden and
  315. paWinWasapiRedirectHostProcessor flag is specified.
  316. @param pStream Pointer to PaStream object.
  317. @param pFormat Pointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure.
  318. @param formatSize Size of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes.
  319. @param bOutput TRUE (1) for output stream, FALSE (0) for input stream.
  320. @return Non-negative value indicating the number of bytes copied into format descriptor
  321. or, a PaErrorCode (which is always negative) if PortAudio is not initialized
  322. or an error is encountered.
  323. */
  324. int PaWasapi_GetDeviceCurrentFormat( PaStream *pStream, void *pFormat, unsigned int formatSize, int bOutput );
  325. /** Get default audio format for the device in Shared Mode.
  326. Format is represented by PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure and obtained
  327. by getting the device property with a PKEY_AudioEngine_DeviceFormat key.
  328. @param pFormat Pointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure.
  329. @param formatSize Size of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes.
  330. @param device Device index.
  331. @return Non-negative value indicating the number of bytes copied into format descriptor
  332. or, a PaErrorCode (which is always negative) if PortAudio is not initialized
  333. or an error is encountered.
  334. */
  335. int PaWasapi_GetDeviceDefaultFormat( void *pFormat, unsigned int formatSize, PaDeviceIndex device );
  336. /** Get mix audio format for the device in Shared Mode.
  337. Format is represented by PaWinWaveFormat or WAVEFORMATEXTENSIBLE structureand obtained by
  338. IAudioClient::GetMixFormat.
  339. @param pFormat Pointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure.
  340. @param formatSize Size of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes.
  341. @param device Device index.
  342. @return Non-negative value indicating the number of bytes copied into format descriptor
  343. or, a PaErrorCode (which is always negative) if PortAudio is not initialized
  344. or an error is encountered.
  345. */
  346. int PaWasapi_GetDeviceMixFormat( void *pFormat, unsigned int formatSize, PaDeviceIndex device );
  347. /** Get device role (PaWasapiDeviceRole enum).
  348. @param device Device index.
  349. @return Non-negative value indicating device role or, a PaErrorCode (which is always negative)
  350. if PortAudio is not initialized or an error is encountered.
  351. */
  352. int/*PaWasapiDeviceRole*/ PaWasapi_GetDeviceRole( PaDeviceIndex device );
  353. /** Get device IMMDevice pointer.
  354. @param device Device index.
  355. @param pAudioClient Pointer to pointer of IMMDevice.
  356. @return Error code indicating success or failure.
  357. */
  358. PaError PaWasapi_GetIMMDevice( PaDeviceIndex device, void **pIMMDevice );
  359. /** Get device loopback state:
  360. 0 - Not loopback,
  361. 1 - Loopback,
  362. negative - PaErrorCode.
  363. @param device Device index.
  364. @return Non-negative value indicating loopback state or, a PaErrorCode (which is always negative)
  365. if PortAudio is not initialized or an error is encountered.
  366. */
  367. int PaWasapi_IsLoopback( PaDeviceIndex device );
  368. /** Boost thread priority of calling thread (MMCSS).
  369. Use it for Blocking Interface only inside the thread which makes calls to Pa_WriteStream/Pa_ReadStream.
  370. @param pTask Handle to pointer to priority task. Must be used with PaWasapi_RevertThreadPriority
  371. method to revert thread priority to initial state.
  372. @param priorityClass Id of thread priority of PaWasapiThreadPriority type. Specifying
  373. eThreadPriorityNone does nothing.
  374. @return Error code indicating success or failure.
  375. @see PaWasapi_RevertThreadPriority
  376. */
  377. PaError PaWasapi_ThreadPriorityBoost( void **pTask, PaWasapiThreadPriority priorityClass );
  378. /** Boost thread priority of calling thread (MMCSS).
  379. Use it for Blocking Interface only inside the thread which makes calls to Pa_WriteStream/Pa_ReadStream.
  380. @param pTask Task handle obtained by PaWasapi_BoostThreadPriority method.
  381. @return Error code indicating success or failure.
  382. @see PaWasapi_BoostThreadPriority
  383. */
  384. PaError PaWasapi_ThreadPriorityRevert( void *pTask );
  385. /** Get number of frames per host buffer.
  386. It is max value of frames of WASAPI buffer which can be locked for operations.
  387. Use this method as helper to find out max values of inputFrames/outputFrames
  388. of PaWasapiHostProcessorCallback.
  389. @param pStream Pointer to PaStream object.
  390. @param pInput Pointer to variable to receive number of input frames. Can be NULL.
  391. @param pOutput Pointer to variable to receive number of output frames. Can be NULL.
  392. @return Error code indicating success or failure.
  393. @see PaWasapiHostProcessorCallback
  394. */
  395. PaError PaWasapi_GetFramesPerHostBuffer( PaStream *pStream, unsigned int *pInput, unsigned int *pOutput );
  396. /** Get number of jacks associated with a WASAPI device.
  397. Use this method to determine if there are any jacks associated with the provided WASAPI device.
  398. Not all audio devices will support this capability. This is valid for both input and output devices.
  399. @note Not available on UWP platform.
  400. @param device Device index.
  401. @param pJackCount Pointer to variable to receive number of jacks.
  402. @return Error code indicating success or failure.
  403. @see PaWasapi_GetJackDescription
  404. */
  405. PaError PaWasapi_GetJackCount( PaDeviceIndex device, int *pJackCount );
  406. /** Get the jack description associated with a WASAPI device and jack number.
  407. Before this function is called, use PaWasapi_GetJackCount to determine the
  408. number of jacks associated with device. If jcount is greater than zero, then
  409. each jack from 0 to jcount can be queried with this function to get the jack
  410. description.
  411. @note Not available on UWP platform.
  412. @param device Device index.
  413. @param jackIndex Jack index.
  414. @param pJackDescription Pointer to PaWasapiJackDescription.
  415. @return Error code indicating success or failure.
  416. @see PaWasapi_GetJackCount
  417. */
  418. PaError PaWasapi_GetJackDescription( PaDeviceIndex device, int jackIndex, PaWasapiJackDescription *pJackDescription );
  419. /** Set stream state handler.
  420. @param pStream Pointer to PaStream object.
  421. @param fnStateHandler Pointer to state handling function.
  422. @param pUserData Pointer to user data.
  423. @return Error code indicating success or failure.
  424. */
  425. PaError PaWasapi_SetStreamStateHandler( PaStream *pStream, PaWasapiStreamStateCallback fnStateHandler, void *pUserData );
  426. /** Set default device Id.
  427. By default implementation will use the DEVINTERFACE_AUDIO_RENDER and
  428. DEVINTERFACE_AUDIO_CAPTURE Ids if device Id is not provided explicitly. These default Ids
  429. will not allow to use Exclusive mode on UWP/WinRT platform and thus you must provide
  430. device Id explicitly via this API before calling the Pa_OpenStream().
  431. Device Ids on UWP platform are obtainable via:
  432. Windows::Media::Devices::MediaDevice::GetDefaultAudioRenderId() or
  433. Windows::Media::Devices::MediaDevice::GetDefaultAudioCaptureId() API.
  434. After the call completes, memory referenced by pointers can be freed, as implementation keeps its own copy.
  435. Call this function before calling Pa_IsFormatSupported() when Exclusive mode is requested.
  436. See an example in the IMPORTANT notes.
  437. @note UWP/WinRT platform only.
  438. @param pId Device Id, pointer to the 16-bit Unicode string (WCHAR). If NULL then device Id
  439. will be reset to the default, e.g. DEVINTERFACE_AUDIO_RENDER or DEVINTERFACE_AUDIO_CAPTURE.
  440. @param bOutput TRUE (1) for output (render), FALSE (0) for input (capture).
  441. @return Error code indicating success or failure. Will return paIncompatibleStreamHostApi if library is not compiled
  442. for UWP/WinRT platform. If Id is longer than PA_WASAPI_DEVICE_ID_LEN characters paBufferTooBig will
  443. be returned.
  444. */
  445. PaError PaWasapiWinrt_SetDefaultDeviceId( const unsigned short *pId, int bOutput );
  446. /** Populate the device list.
  447. By default the implementation will rely on DEVINTERFACE_AUDIO_RENDER and DEVINTERFACE_AUDIO_CAPTURE as
  448. default devices. If device Id is provided by PaWasapiWinrt_SetDefaultDeviceId() then those
  449. device Ids will be used as default and only devices for the device list.
  450. By populating the device list you can provide an additional available audio devices of the system to PA
  451. which are obtainable by:
  452. Windows::Devices::Enumeration::DeviceInformation::FindAllAsync(selector) where selector is obtainable by
  453. Windows::Media::Devices::MediaDevice::GetAudioRenderSelector() or
  454. Windows::Media::Devices::MediaDevice::GetAudioCaptureSelector() API.
  455. After the call completes, memory referenced by pointers can be freed, as implementation keeps its own copy.
  456. You must call PaWasapi_UpdateDeviceList() to update the internal device list of the implementation after
  457. calling this function.
  458. See an example in the IMPORTANT notes.
  459. @note UWP/WinRT platform only.
  460. @param pId Array of device Ids, pointer to the array of pointers of 16-bit Unicode string (WCHAR). If NULL
  461. and count is also 0 then device Ids will be reset to the default. Required.
  462. @param pName Array of device Names, pointer to the array of pointers of 16-bit Unicode string (WCHAR). Optional.
  463. @param pRole Array of device Roles, see PaWasapiDeviceRole and PaWasapi_GetDeviceRole() for more details. Optional.
  464. @param count Number of devices, the number of array elements (pId, pName, pRole). Maximum count of devices
  465. is limited by PA_WASAPI_DEVICE_MAX_COUNT.
  466. @param bOutput TRUE (1) for output (render), FALSE (0) for input (capture).
  467. @return Error code indicating success or failure. Will return paIncompatibleStreamHostApi if library is not compiled
  468. for UWP/WinRT platform. If Id is longer than PA_WASAPI_DEVICE_ID_LEN characters paBufferTooBig will
  469. be returned. If Name is longer than PA_WASAPI_DEVICE_NAME_LEN characters paBufferTooBig will
  470. be returned.
  471. */
  472. PaError PaWasapiWinrt_PopulateDeviceList( const unsigned short **pId, const unsigned short **pName,
  473. const PaWasapiDeviceRole *pRole, unsigned int count, int bOutput );
  474. /*
  475. IMPORTANT:
  476. WASAPI is implemented for Callback and Blocking interfaces. It supports Shared and Exclusive
  477. share modes.
  478. Exclusive Mode:
  479. Exclusive mode allows to deliver audio data directly to hardware bypassing
  480. software mixing.
  481. Exclusive mode is specified by 'paWinWasapiExclusive' flag.
  482. Callback Interface:
  483. Provides best audio quality with low latency. Callback interface is implemented in
  484. two versions:
  485. 1) Event-driven:
  486. It is the most powerful data processing method which provides glitch-free audio with
  487. around 3 ms latency in Exclusive mode. Lowest possible latency for this mode is
  488. 3 ms for HD Audio class audio chips. For the Shared mode latency can not be
  489. lower than 20 ms. This method consumes slightly less CPU in comparison to Polling.
  490. It is the default processing method unless 'paWinWasapiPolling' is specified.
  491. 2) Poll-driven:
  492. Polling is an alternative to Event-driven processing. Due to its nature Polling consumes
  493. slightly more CPU. This method is less efficient than Event-driven and its lowest possible
  494. latency is around 10-13 ms.
  495. Note: Newer Windows versions (for example 11) allow to achieve similar to Event-driven
  496. low latency.
  497. Note: Polling must be used to overcome system bug of Windows Vista (x64) when application
  498. is WOW64 (32-bit process running on 64-bit OS) that results in WASAPI callback timeout if
  499. Event-driven method is selected (event handle is never signalled on buffer completion).
  500. This WOW64 bug does not exist in Windows Vista (x86) or Windows 7 or newer Windows versions.
  501. Polling can be activated by specifying 'paWinWasapiPolling' flag. Our implementation
  502. detects WOW64 bug and sets 'paWinWasapiPolling' automatically.
  503. Thread priority:
  504. Normally thread priority is set automatically and does not require modification. Although
  505. if user wants some tweaking thread priority can be modified by setting 'paWinWasapiThreadPriority'
  506. flag and specifying 'PaWasapiStreamInfo::threadPriority' with value from PaWasapiThreadPriority
  507. enum.
  508. Blocking Interface:
  509. Blocking interface is implemented but due to above described Poll-Driven method can not
  510. deliver lowest possible latency. Specifying too low latency in Shared mode will result in
  511. distorted audio although Exclusive mode adds stability.
  512. 8.24 format:
  513. If paCustomFormat is specified as sample format then the implementation will understand it
  514. as valid 24-bits inside 32-bit container (e.g. wBitsPerSample = 32, Samples.wValidBitsPerSample = 24).
  515. By using paCustomFormat there will be small optimization when samples are be copied
  516. with Copy_24_To_24 by PA processor instead of conversion from packed 3-byte (24-bit) data
  517. with Int24_To_Int32.
  518. Pa_IsFormatSupported:
  519. To check format with correct Share Mode (Exclusive/Shared) you must supply PaWasapiStreamInfo
  520. with flags paWinWasapiExclusive set through member of PaStreamParameters::hostApiSpecificStreamInfo
  521. structure.
  522. If paWinWasapiExplicitSampleFormat flag is provided then implementation will not try to select
  523. suitable close format and will return an error instead of paFormatIsSupported. By specifying
  524. paWinWasapiExplicitSampleFormat flag it is possible to find out what sample formats are
  525. supported by Exclusive or Shared modes.
  526. Pa_OpenStream:
  527. To set desired Share Mode (Exclusive/Shared) you must supply
  528. PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of
  529. PaStreamParameters::hostApiSpecificStreamInfo structure.
  530. Coding style for parameters and structure members of the public API:
  531. 1) bXXX - boolean, [1 (TRUE), 0 (FALSE)]
  532. 2) pXXX - pointer
  533. 3) fnXXX - pointer to function
  534. 4) structure members are never prefixed with a type distinguisher
  535. UWP/WinRT:
  536. This platform has number of limitations which do not allow to enumerate audio devices without
  537. an additional external help. Enumeration is possible though from C++/CX, check the related API
  538. Windows::Devices::Enumeration::DeviceInformation::FindAllAsync().
  539. The main limitation is an absence of the device enumeration from inside the PA's implementation.
  540. This problem can be solved by using the following functions:
  541. PaWasapiWinrt_SetDefaultDeviceId() - to set default input/output device,
  542. PaWasapiWinrt_PopulateDeviceList() - to populate device list with devices.
  543. Here is an example of populating the device list which can also be updated dynamically depending on
  544. whether device was removed from or added to the system:
  545. ----------------
  546. std::vector<const UINT16 *> ids, names;
  547. std::vector<PaWasapiDeviceRole> role;
  548. ids.resize(count);
  549. names.resize(count);
  550. role.resize(count);
  551. for (UINT32 i = 0; i < count; ++i)
  552. {
  553. ids[i] = (const UINT16 *)device_ids[i].c_str();
  554. names[i] = (const UINT16 *)device_names[i].c_str();
  555. role[i] = eRoleUnknownFormFactor;
  556. }
  557. PaWasapiWinrt_SetDefaultDeviceId((const UINT16 *)default_device_id.c_str(), !capture);
  558. PaWasapiWinrt_PopulateDeviceList(ids.data(), names.data(), role.data(), count, !capture);
  559. PaWasapi_UpdateDeviceList();
  560. ----------------
  561. */
  562. #ifdef __cplusplus
  563. }
  564. #endif /* __cplusplus */
  565. #endif /* PA_WIN_WASAPI_H */