annotate win64-msvc/include/pa_win_wasapi.h @ 145:13a516fa8999

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