annotate src/portaudio_20161030/include/pa_win_wasapi.h @ 151:fe80428a60a5

Add AppImage files
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 26 Jun 2018 18:00:44 +0100
parents 59a8758c56b1
children
rev   line source
cannam@140 1 #ifndef PA_WIN_WASAPI_H
cannam@140 2 #define PA_WIN_WASAPI_H
cannam@140 3 /*
cannam@140 4 * $Id: $
cannam@140 5 * PortAudio Portable Real-Time Audio Library
cannam@140 6 * DirectSound specific extensions
cannam@140 7 *
cannam@140 8 * Copyright (c) 1999-2007 Ross Bencina and Phil Burk
cannam@140 9 *
cannam@140 10 * Permission is hereby granted, free of charge, to any person obtaining
cannam@140 11 * a copy of this software and associated documentation files
cannam@140 12 * (the "Software"), to deal in the Software without restriction,
cannam@140 13 * including without limitation the rights to use, copy, modify, merge,
cannam@140 14 * publish, distribute, sublicense, and/or sell copies of the Software,
cannam@140 15 * and to permit persons to whom the Software is furnished to do so,
cannam@140 16 * subject to the following conditions:
cannam@140 17 *
cannam@140 18 * The above copyright notice and this permission notice shall be
cannam@140 19 * included in all copies or substantial portions of the Software.
cannam@140 20 *
cannam@140 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@140 22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@140 23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
cannam@140 24 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
cannam@140 25 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@140 26 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@140 27 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@140 28 */
cannam@140 29
cannam@140 30 /*
cannam@140 31 * The text above constitutes the entire PortAudio license; however,
cannam@140 32 * the PortAudio community also makes the following non-binding requests:
cannam@140 33 *
cannam@140 34 * Any person wishing to distribute modifications to the Software is
cannam@140 35 * requested to send the modifications to the original developer so that
cannam@140 36 * they can be incorporated into the canonical version. It is also
cannam@140 37 * requested that these non-binding requests be included along with the
cannam@140 38 * license above.
cannam@140 39 */
cannam@140 40
cannam@140 41 /** @file
cannam@140 42 @ingroup public_header
cannam@140 43 @brief WASAPI-specific PortAudio API extension header file.
cannam@140 44 */
cannam@140 45
cannam@140 46 #include "portaudio.h"
cannam@140 47 #include "pa_win_waveformat.h"
cannam@140 48
cannam@140 49 #ifdef __cplusplus
cannam@140 50 extern "C"
cannam@140 51 {
cannam@140 52 #endif /* __cplusplus */
cannam@140 53
cannam@140 54
cannam@140 55 /* Setup flags */
cannam@140 56 typedef enum PaWasapiFlags
cannam@140 57 {
cannam@140 58 /* puts WASAPI into exclusive mode */
cannam@140 59 paWinWasapiExclusive = (1 << 0),
cannam@140 60
cannam@140 61 /* allows to skip internal PA processing completely */
cannam@140 62 paWinWasapiRedirectHostProcessor = (1 << 1),
cannam@140 63
cannam@140 64 /* assigns custom channel mask */
cannam@140 65 paWinWasapiUseChannelMask = (1 << 2),
cannam@140 66
cannam@140 67 /* selects non-Event driven method of data read/write
cannam@140 68 Note: WASAPI Event driven core is capable of 2ms latency!!!, but Polling
cannam@140 69 method can only provide 15-20ms latency. */
cannam@140 70 paWinWasapiPolling = (1 << 3),
cannam@140 71
cannam@140 72 /* forces custom thread priority setting, must be used if PaWasapiStreamInfo::threadPriority
cannam@140 73 is set to a custom value */
cannam@140 74 paWinWasapiThreadPriority = (1 << 4)
cannam@140 75 }
cannam@140 76 PaWasapiFlags;
cannam@140 77 #define paWinWasapiExclusive (paWinWasapiExclusive)
cannam@140 78 #define paWinWasapiRedirectHostProcessor (paWinWasapiRedirectHostProcessor)
cannam@140 79 #define paWinWasapiUseChannelMask (paWinWasapiUseChannelMask)
cannam@140 80 #define paWinWasapiPolling (paWinWasapiPolling)
cannam@140 81 #define paWinWasapiThreadPriority (paWinWasapiThreadPriority)
cannam@140 82
cannam@140 83
cannam@140 84 /* Host processor. Allows to skip internal PA processing completely.
cannam@140 85 You must set paWinWasapiRedirectHostProcessor flag to PaWasapiStreamInfo::flags member
cannam@140 86 in order to have host processor redirected to your callback.
cannam@140 87 Use with caution! inputFrames and outputFrames depend solely on final device setup.
cannam@140 88 To query maximal values of inputFrames/outputFrames use PaWasapi_GetFramesPerHostBuffer.
cannam@140 89 */
cannam@140 90 typedef void (*PaWasapiHostProcessorCallback) (void *inputBuffer, long inputFrames,
cannam@140 91 void *outputBuffer, long outputFrames,
cannam@140 92 void *userData);
cannam@140 93
cannam@140 94 /* Device role. */
cannam@140 95 typedef enum PaWasapiDeviceRole
cannam@140 96 {
cannam@140 97 eRoleRemoteNetworkDevice = 0,
cannam@140 98 eRoleSpeakers,
cannam@140 99 eRoleLineLevel,
cannam@140 100 eRoleHeadphones,
cannam@140 101 eRoleMicrophone,
cannam@140 102 eRoleHeadset,
cannam@140 103 eRoleHandset,
cannam@140 104 eRoleUnknownDigitalPassthrough,
cannam@140 105 eRoleSPDIF,
cannam@140 106 eRoleHDMI,
cannam@140 107 eRoleUnknownFormFactor
cannam@140 108 }
cannam@140 109 PaWasapiDeviceRole;
cannam@140 110
cannam@140 111
cannam@140 112 /* Jack connection type. */
cannam@140 113 typedef enum PaWasapiJackConnectionType
cannam@140 114 {
cannam@140 115 eJackConnTypeUnknown,
cannam@140 116 eJackConnType3Point5mm,
cannam@140 117 eJackConnTypeQuarter,
cannam@140 118 eJackConnTypeAtapiInternal,
cannam@140 119 eJackConnTypeRCA,
cannam@140 120 eJackConnTypeOptical,
cannam@140 121 eJackConnTypeOtherDigital,
cannam@140 122 eJackConnTypeOtherAnalog,
cannam@140 123 eJackConnTypeMultichannelAnalogDIN,
cannam@140 124 eJackConnTypeXlrProfessional,
cannam@140 125 eJackConnTypeRJ11Modem,
cannam@140 126 eJackConnTypeCombination
cannam@140 127 }
cannam@140 128 PaWasapiJackConnectionType;
cannam@140 129
cannam@140 130
cannam@140 131 /* Jack geometric location. */
cannam@140 132 typedef enum PaWasapiJackGeoLocation
cannam@140 133 {
cannam@140 134 eJackGeoLocUnk = 0,
cannam@140 135 eJackGeoLocRear = 0x1, /* matches EPcxGeoLocation::eGeoLocRear */
cannam@140 136 eJackGeoLocFront,
cannam@140 137 eJackGeoLocLeft,
cannam@140 138 eJackGeoLocRight,
cannam@140 139 eJackGeoLocTop,
cannam@140 140 eJackGeoLocBottom,
cannam@140 141 eJackGeoLocRearPanel,
cannam@140 142 eJackGeoLocRiser,
cannam@140 143 eJackGeoLocInsideMobileLid,
cannam@140 144 eJackGeoLocDrivebay,
cannam@140 145 eJackGeoLocHDMI,
cannam@140 146 eJackGeoLocOutsideMobileLid,
cannam@140 147 eJackGeoLocATAPI,
cannam@140 148 eJackGeoLocReserved5,
cannam@140 149 eJackGeoLocReserved6,
cannam@140 150 }
cannam@140 151 PaWasapiJackGeoLocation;
cannam@140 152
cannam@140 153
cannam@140 154 /* Jack general location. */
cannam@140 155 typedef enum PaWasapiJackGenLocation
cannam@140 156 {
cannam@140 157 eJackGenLocPrimaryBox = 0,
cannam@140 158 eJackGenLocInternal,
cannam@140 159 eJackGenLocSeparate,
cannam@140 160 eJackGenLocOther
cannam@140 161 }
cannam@140 162 PaWasapiJackGenLocation;
cannam@140 163
cannam@140 164
cannam@140 165 /* Jack's type of port. */
cannam@140 166 typedef enum PaWasapiJackPortConnection
cannam@140 167 {
cannam@140 168 eJackPortConnJack = 0,
cannam@140 169 eJackPortConnIntegratedDevice,
cannam@140 170 eJackPortConnBothIntegratedAndJack,
cannam@140 171 eJackPortConnUnknown
cannam@140 172 }
cannam@140 173 PaWasapiJackPortConnection;
cannam@140 174
cannam@140 175
cannam@140 176 /* Thread priority. */
cannam@140 177 typedef enum PaWasapiThreadPriority
cannam@140 178 {
cannam@140 179 eThreadPriorityNone = 0,
cannam@140 180 eThreadPriorityAudio, //!< Default for Shared mode.
cannam@140 181 eThreadPriorityCapture,
cannam@140 182 eThreadPriorityDistribution,
cannam@140 183 eThreadPriorityGames,
cannam@140 184 eThreadPriorityPlayback,
cannam@140 185 eThreadPriorityProAudio, //!< Default for Exclusive mode.
cannam@140 186 eThreadPriorityWindowManager
cannam@140 187 }
cannam@140 188 PaWasapiThreadPriority;
cannam@140 189
cannam@140 190
cannam@140 191 /* Stream descriptor. */
cannam@140 192 typedef struct PaWasapiJackDescription
cannam@140 193 {
cannam@140 194 unsigned long channelMapping;
cannam@140 195 unsigned long color; /* derived from macro: #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) */
cannam@140 196 PaWasapiJackConnectionType connectionType;
cannam@140 197 PaWasapiJackGeoLocation geoLocation;
cannam@140 198 PaWasapiJackGenLocation genLocation;
cannam@140 199 PaWasapiJackPortConnection portConnection;
cannam@140 200 unsigned int isConnected;
cannam@140 201 }
cannam@140 202 PaWasapiJackDescription;
cannam@140 203
cannam@140 204
cannam@140 205 /** Stream category.
cannam@140 206 Note:
cannam@140 207 - values are equal to WASAPI AUDIO_STREAM_CATEGORY enum
cannam@140 208 - supported since Windows 8.0, noop on earler versions
cannam@140 209 - values 1,2 are deprecated on Windows 10 and not included into enumeration
cannam@140 210
cannam@140 211 @version Available as of 19.6.0
cannam@140 212 */
cannam@140 213 typedef enum PaWasapiStreamCategory
cannam@140 214 {
cannam@140 215 eAudioCategoryOther = 0,
cannam@140 216 eAudioCategoryCommunications = 3,
cannam@140 217 eAudioCategoryAlerts = 4,
cannam@140 218 eAudioCategorySoundEffects = 5,
cannam@140 219 eAudioCategoryGameEffects = 6,
cannam@140 220 eAudioCategoryGameMedia = 7,
cannam@140 221 eAudioCategoryGameChat = 8,
cannam@140 222 eAudioCategorySpeech = 9,
cannam@140 223 eAudioCategoryMovie = 10,
cannam@140 224 eAudioCategoryMedia = 11
cannam@140 225 }
cannam@140 226 PaWasapiStreamCategory;
cannam@140 227
cannam@140 228
cannam@140 229 /** Stream option.
cannam@140 230 Note:
cannam@140 231 - values are equal to WASAPI AUDCLNT_STREAMOPTIONS enum
cannam@140 232 - supported since Windows 8.1, noop on earler versions
cannam@140 233
cannam@140 234 @version Available as of 19.6.0
cannam@140 235 */
cannam@140 236 typedef enum PaWasapiStreamOption
cannam@140 237 {
cannam@140 238 eStreamOptionNone = 0, //!< default
cannam@140 239 eStreamOptionRaw = 1, //!< bypass WASAPI Audio Engine DSP effects, supported since Windows 8.1
cannam@140 240 eStreamOptionMatchFormat = 2 //!< force WASAPI Audio Engine into a stream format, supported since Windows 10
cannam@140 241 }
cannam@140 242 PaWasapiStreamOption;
cannam@140 243
cannam@140 244
cannam@140 245 /* Stream descriptor. */
cannam@140 246 typedef struct PaWasapiStreamInfo
cannam@140 247 {
cannam@140 248 unsigned long size; /**< sizeof(PaWasapiStreamInfo) */
cannam@140 249 PaHostApiTypeId hostApiType; /**< paWASAPI */
cannam@140 250 unsigned long version; /**< 1 */
cannam@140 251
cannam@140 252 unsigned long flags; /**< collection of PaWasapiFlags */
cannam@140 253
cannam@140 254 /** Support for WAVEFORMATEXTENSIBLE channel masks. If flags contains
cannam@140 255 paWinWasapiUseChannelMask this allows you to specify which speakers
cannam@140 256 to address in a multichannel stream. Constants for channelMask
cannam@140 257 are specified in pa_win_waveformat.h. Will be used only if
cannam@140 258 paWinWasapiUseChannelMask flag is specified.
cannam@140 259 */
cannam@140 260 PaWinWaveFormatChannelMask channelMask;
cannam@140 261
cannam@140 262 /** Delivers raw data to callback obtained from GetBuffer() methods skipping
cannam@140 263 internal PortAudio processing inventory completely. userData parameter will
cannam@140 264 be the same that was passed to Pa_OpenStream method. Will be used only if
cannam@140 265 paWinWasapiRedirectHostProcessor flag is specified.
cannam@140 266 */
cannam@140 267 PaWasapiHostProcessorCallback hostProcessorOutput;
cannam@140 268 PaWasapiHostProcessorCallback hostProcessorInput;
cannam@140 269
cannam@140 270 /** Specifies thread priority explicitly. Will be used only if paWinWasapiThreadPriority flag
cannam@140 271 is specified.
cannam@140 272
cannam@140 273 Please note, if Input/Output streams are opened simultaniously (Full-Duplex mode)
cannam@140 274 you shall specify same value for threadPriority or othervise one of the values will be used
cannam@140 275 to setup thread priority.
cannam@140 276 */
cannam@140 277 PaWasapiThreadPriority threadPriority;
cannam@140 278
cannam@140 279 /** Stream category.
cannam@140 280 @see PaWasapiStreamCategory
cannam@140 281 @version Available as of 19.6.0
cannam@140 282 */
cannam@140 283 PaWasapiStreamCategory streamCategory;
cannam@140 284
cannam@140 285 /** Stream option.
cannam@140 286 @see PaWasapiStreamOption
cannam@140 287 @version Available as of 19.6.0
cannam@140 288 */
cannam@140 289 PaWasapiStreamOption streamOption;
cannam@140 290 }
cannam@140 291 PaWasapiStreamInfo;
cannam@140 292
cannam@140 293
cannam@140 294 /** Returns default sound format for device. Format is represented by PaWinWaveFormat or
cannam@140 295 WAVEFORMATEXTENSIBLE structure.
cannam@140 296
cannam@140 297 @param pFormat Pointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure.
cannam@140 298 @param nFormatSize Size of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes.
cannam@140 299 @param nDevice Device index.
cannam@140 300
cannam@140 301 @return Non-negative value indicating the number of bytes copied into format decriptor
cannam@140 302 or, a PaErrorCode (which are always negative) if PortAudio is not initialized
cannam@140 303 or an error is encountered.
cannam@140 304 */
cannam@140 305 int PaWasapi_GetDeviceDefaultFormat( void *pFormat, unsigned int nFormatSize, PaDeviceIndex nDevice );
cannam@140 306
cannam@140 307
cannam@140 308 /** Returns device role (PaWasapiDeviceRole enum).
cannam@140 309
cannam@140 310 @param nDevice device index.
cannam@140 311
cannam@140 312 @return Non-negative value indicating device role or, a PaErrorCode (which are always negative)
cannam@140 313 if PortAudio is not initialized or an error is encountered.
cannam@140 314 */
cannam@140 315 int/*PaWasapiDeviceRole*/ PaWasapi_GetDeviceRole( PaDeviceIndex nDevice );
cannam@140 316
cannam@140 317
cannam@140 318 /** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread
cannam@140 319 which makes calls to Pa_WriteStream/Pa_ReadStream.
cannam@140 320
cannam@140 321 @param hTask Handle to pointer to priority task. Must be used with PaWasapi_RevertThreadPriority
cannam@140 322 method to revert thread priority to initial state.
cannam@140 323
cannam@140 324 @param nPriorityClass Id of thread priority of PaWasapiThreadPriority type. Specifying
cannam@140 325 eThreadPriorityNone does nothing.
cannam@140 326
cannam@140 327 @return Error code indicating success or failure.
cannam@140 328 @see PaWasapi_RevertThreadPriority
cannam@140 329 */
cannam@140 330 PaError PaWasapi_ThreadPriorityBoost( void **hTask, PaWasapiThreadPriority nPriorityClass );
cannam@140 331
cannam@140 332
cannam@140 333 /** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread
cannam@140 334 which makes calls to Pa_WriteStream/Pa_ReadStream.
cannam@140 335
cannam@140 336 @param hTask Task handle obtained by PaWasapi_BoostThreadPriority method.
cannam@140 337 @return Error code indicating success or failure.
cannam@140 338 @see PaWasapi_BoostThreadPriority
cannam@140 339 */
cannam@140 340 PaError PaWasapi_ThreadPriorityRevert( void *hTask );
cannam@140 341
cannam@140 342
cannam@140 343 /** Get number of frames per host buffer. This is maximal value of frames of WASAPI buffer which
cannam@140 344 can be locked for operations. Use this method as helper to findout maximal values of
cannam@140 345 inputFrames/outputFrames of PaWasapiHostProcessorCallback.
cannam@140 346
cannam@140 347 @param pStream Pointer to PaStream to query.
cannam@140 348 @param nInput Pointer to variable to receive number of input frames. Can be NULL.
cannam@140 349 @param nOutput Pointer to variable to receive number of output frames. Can be NULL.
cannam@140 350 @return Error code indicating success or failure.
cannam@140 351 @see PaWasapiHostProcessorCallback
cannam@140 352 */
cannam@140 353 PaError PaWasapi_GetFramesPerHostBuffer( PaStream *pStream, unsigned int *nInput, unsigned int *nOutput );
cannam@140 354
cannam@140 355
cannam@140 356 /** Get number of jacks associated with a WASAPI device. Use this method to determine if
cannam@140 357 there are any jacks associated with the provided WASAPI device. Not all audio devices
cannam@140 358 will support this capability. This is valid for both input and output devices.
cannam@140 359 @param nDevice device index.
cannam@140 360 @param jcount Number of jacks is returned in this variable
cannam@140 361 @return Error code indicating success or failure
cannam@140 362 @see PaWasapi_GetJackDescription
cannam@140 363 */
cannam@140 364 PaError PaWasapi_GetJackCount(PaDeviceIndex nDevice, int *jcount);
cannam@140 365
cannam@140 366
cannam@140 367 /** Get the jack description associated with a WASAPI device and jack number
cannam@140 368 Before this function is called, use PaWasapi_GetJackCount to determine the
cannam@140 369 number of jacks associated with device. If jcount is greater than zero, then
cannam@140 370 each jack from 0 to jcount can be queried with this function to get the jack
cannam@140 371 description.
cannam@140 372 @param nDevice device index.
cannam@140 373 @param jindex Which jack to return information
cannam@140 374 @param KSJACK_DESCRIPTION This structure filled in on success.
cannam@140 375 @return Error code indicating success or failure
cannam@140 376 @see PaWasapi_GetJackCount
cannam@140 377 */
cannam@140 378 PaError PaWasapi_GetJackDescription(PaDeviceIndex nDevice, int jindex, PaWasapiJackDescription *pJackDescription);
cannam@140 379
cannam@140 380
cannam@140 381 /*
cannam@140 382 IMPORTANT:
cannam@140 383
cannam@140 384 WASAPI is implemented for Callback and Blocking interfaces. It supports Shared and Exclusive
cannam@140 385 share modes.
cannam@140 386
cannam@140 387 Exclusive Mode:
cannam@140 388
cannam@140 389 Exclusive mode allows to deliver audio data directly to hardware bypassing
cannam@140 390 software mixing.
cannam@140 391 Exclusive mode is specified by 'paWinWasapiExclusive' flag.
cannam@140 392
cannam@140 393 Callback Interface:
cannam@140 394
cannam@140 395 Provides best audio quality with low latency. Callback interface is implemented in
cannam@140 396 two versions:
cannam@140 397
cannam@140 398 1) Event-Driven:
cannam@140 399 This is the most powerful WASAPI implementation which provides glitch-free
cannam@140 400 audio at around 3ms latency in Exclusive mode. Lowest possible latency for this mode is
cannam@140 401 3 ms for HD Audio class audio chips. For the Shared mode latency can not be
cannam@140 402 lower than 20 ms.
cannam@140 403
cannam@140 404 2) Poll-Driven:
cannam@140 405 Polling is another 2-nd method to operate with WASAPI. It is less efficient than Event-Driven
cannam@140 406 and provides latency at around 10-13ms. Polling must be used to overcome a system bug
cannam@140 407 under Windows Vista x64 when application is WOW64(32-bit) and Event-Driven method simply
cannam@140 408 times out (event handle is never signalled on buffer completion). Please note, such WOW64 bug
cannam@140 409 does not exist in Vista x86 or Windows 7.
cannam@140 410 Polling can be setup by speciying 'paWinWasapiPolling' flag. Our WASAPI implementation detects
cannam@140 411 WOW64 bug and sets 'paWinWasapiPolling' automatically.
cannam@140 412
cannam@140 413 Thread priority:
cannam@140 414
cannam@140 415 Normally thread priority is set automatically and does not require modification. Although
cannam@140 416 if user wants some tweaking thread priority can be modified by setting 'paWinWasapiThreadPriority'
cannam@140 417 flag and specifying 'PaWasapiStreamInfo::threadPriority' with value from PaWasapiThreadPriority
cannam@140 418 enum.
cannam@140 419
cannam@140 420 Blocking Interface:
cannam@140 421
cannam@140 422 Blocking interface is implemented but due to above described Poll-Driven method can not
cannam@140 423 deliver lowest possible latency. Specifying too low latency in Shared mode will result in
cannam@140 424 distorted audio although Exclusive mode adds stability.
cannam@140 425
cannam@140 426 Pa_IsFormatSupported:
cannam@140 427
cannam@140 428 To check format with correct Share Mode (Exclusive/Shared) you must supply
cannam@140 429 PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of
cannam@140 430 PaStreamParameters::hostApiSpecificStreamInfo structure.
cannam@140 431
cannam@140 432 Pa_OpenStream:
cannam@140 433
cannam@140 434 To set desired Share Mode (Exclusive/Shared) you must supply
cannam@140 435 PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of
cannam@140 436 PaStreamParameters::hostApiSpecificStreamInfo structure.
cannam@140 437 */
cannam@140 438
cannam@140 439 #ifdef __cplusplus
cannam@140 440 }
cannam@140 441 #endif /* __cplusplus */
cannam@140 442
cannam@140 443 #endif /* PA_WIN_WASAPI_H */