annotate win64-msvc/include/pa_win_wasapi.h @ 130:1c067f014d80

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