1 #ifndef PA_WIN_WASAPI_H
2 #define PA_WIN_WASAPI_H
5 * PortAudio Portable Real-Time Audio Library
6 * DirectSound specific extensions
8 * Copyright (c) 1999-2007 Ross Bencina and Phil Burk
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files
12 * (the "Software"), to deal in the Software without restriction,
13 * including without limitation the rights to use, copy, modify, merge,
14 * publish, distribute, sublicense, and/or sell copies of the Software,
15 * and to permit persons to whom the Software is furnished to do so,
16 * subject to the following conditions:
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
25 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 * The text above constitutes the entire PortAudio license; however,
32 * the PortAudio community also makes the following non-binding requests:
34 * Any person wishing to distribute modifications to the Software is
35 * requested to send the modifications to the original developer so that
36 * they can be incorporated into the canonical version. It is also
37 * requested that these non-binding requests be included along with the
42 @ingroup public_header
43 @brief WASAPI-specific PortAudio API extension header file.
46 #include "portaudio.h"
47 #include "pa_win_waveformat.h"
52 #endif /* __cplusplus */
56 typedef enum PaWasapiFlags
58 /* puts WASAPI into exclusive mode */
59 paWinWasapiExclusive = (1 << 0),
61 /* allows to skip internal PA processing completely */
62 paWinWasapiRedirectHostProcessor = (1 << 1),
64 /* assigns custom channel mask */
65 paWinWasapiUseChannelMask = (1 << 2),
67 /* selects non-Event driven method of data read/write
68 Note: WASAPI Event driven core is capable of 2ms latency!!!, but Polling
69 method can only provide 15-20ms latency. */
70 paWinWasapiPolling = (1 << 3),
72 /* forces custom thread priority setting. must be used if PaWasapiStreamInfo::threadPriority
73 is set to custom value. */
74 paWinWasapiThreadPriority = (1 << 4)
77 #define paWinWasapiExclusive (paWinWasapiExclusive)
78 #define paWinWasapiRedirectHostProcessor (paWinWasapiRedirectHostProcessor)
79 #define paWinWasapiUseChannelMask (paWinWasapiUseChannelMask)
80 #define paWinWasapiPolling (paWinWasapiPolling)
81 #define paWinWasapiThreadPriority (paWinWasapiThreadPriority)
84 /* Host processor. Allows to skip internal PA processing completely.
85 You must set paWinWasapiRedirectHostProcessor flag to PaWasapiStreamInfo::flags member
86 in order to have host processor redirected to your callback.
87 Use with caution! inputFrames and outputFrames depend solely on final device setup.
88 To query maximal values of inputFrames/outputFrames use PaWasapi_GetFramesPerHostBuffer.
90 typedef void (*PaWasapiHostProcessorCallback) (void *inputBuffer, long inputFrames,
91 void *outputBuffer, long outputFrames,
95 typedef enum PaWasapiDeviceRole
97 eRoleRemoteNetworkDevice = 0,
104 eRoleUnknownDigitalPassthrough,
107 eRoleUnknownFormFactor
112 /* Jack connection type */
113 typedef enum PaWasapiJackConnectionType
115 eJackConnTypeUnknown,
116 eJackConnType3Point5mm,
117 eJackConnTypeQuarter,
118 eJackConnTypeAtapiInternal,
120 eJackConnTypeOptical,
121 eJackConnTypeOtherDigital,
122 eJackConnTypeOtherAnalog,
123 eJackConnTypeMultichannelAnalogDIN,
124 eJackConnTypeXlrProfessional,
125 eJackConnTypeRJ11Modem,
126 eJackConnTypeCombination
128 PaWasapiJackConnectionType;
131 /* Jack geometric location */
132 typedef enum PaWasapiJackGeoLocation
135 eJackGeoLocRear = 0x1, /* matches EPcxGeoLocation::eGeoLocRear */
141 eJackGeoLocRearPanel,
143 eJackGeoLocInsideMobileLid,
146 eJackGeoLocOutsideMobileLid,
148 eJackGeoLocReserved5,
149 eJackGeoLocReserved6,
151 PaWasapiJackGeoLocation;
154 /* Jack general location */
155 typedef enum PaWasapiJackGenLocation
157 eJackGenLocPrimaryBox = 0,
162 PaWasapiJackGenLocation;
165 /* Jack's type of port */
166 typedef enum PaWasapiJackPortConnection
168 eJackPortConnJack = 0,
169 eJackPortConnIntegratedDevice,
170 eJackPortConnBothIntegratedAndJack,
173 PaWasapiJackPortConnection;
176 /* Thread priority */
177 typedef enum PaWasapiThreadPriority
179 eThreadPriorityNone = 0,
180 eThreadPriorityAudio, //!< Default for Shared mode.
181 eThreadPriorityCapture,
182 eThreadPriorityDistribution,
183 eThreadPriorityGames,
184 eThreadPriorityPlayback,
185 eThreadPriorityProAudio, //!< Default for Exclusive mode.
186 eThreadPriorityWindowManager
188 PaWasapiThreadPriority;
191 /* Stream descriptor. */
192 typedef struct PaWasapiJackDescription
194 unsigned long channelMapping;
195 unsigned long color; /* derived from macro: #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) */
196 PaWasapiJackConnectionType connectionType;
197 PaWasapiJackGeoLocation geoLocation;
198 PaWasapiJackGenLocation genLocation;
199 PaWasapiJackPortConnection portConnection;
200 unsigned int isConnected;
202 PaWasapiJackDescription;
205 /* Stream descriptor. */
206 typedef struct PaWasapiStreamInfo
208 unsigned long size; /**< sizeof(PaWasapiStreamInfo) */
209 PaHostApiTypeId hostApiType; /**< paWASAPI */
210 unsigned long version; /**< 1 */
212 unsigned long flags; /**< collection of PaWasapiFlags */
214 /* Support for WAVEFORMATEXTENSIBLE channel masks. If flags contains
215 paWinWasapiUseChannelMask this allows you to specify which speakers
216 to address in a multichannel stream. Constants for channelMask
217 are specified in pa_win_waveformat.h. Will be used only if
218 paWinWasapiUseChannelMask flag is specified.
220 PaWinWaveFormatChannelMask channelMask;
222 /* Delivers raw data to callback obtained from GetBuffer() methods skipping
223 internal PortAudio processing inventory completely. userData parameter will
224 be the same that was passed to Pa_OpenStream method. Will be used only if
225 paWinWasapiRedirectHostProcessor flag is specified.
227 PaWasapiHostProcessorCallback hostProcessorOutput;
228 PaWasapiHostProcessorCallback hostProcessorInput;
230 /* Specifies thread priority explicitly. Will be used only if paWinWasapiThreadPriority flag
233 Please note, if Input/Output streams are opened simultaniously (Full-Duplex mode)
234 you shall specify same value for threadPriority or othervise one of the values will be used
235 to setup thread priority.
237 PaWasapiThreadPriority threadPriority;
242 /** Returns default sound format for device. Format is represented by PaWinWaveFormat or
243 WAVEFORMATEXTENSIBLE structure.
245 @param pFormat Pointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure.
246 @param nFormatSize Size of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes.
247 @param nDevice Device index.
249 @return Non-negative value indicating the number of bytes copied into format decriptor
250 or, a PaErrorCode (which are always negative) if PortAudio is not initialized
251 or an error is encountered.
253 int PaWasapi_GetDeviceDefaultFormat( void *pFormat, unsigned int nFormatSize, PaDeviceIndex nDevice );
256 /** Returns device role (PaWasapiDeviceRole enum).
258 @param nDevice device index.
260 @return Non-negative value indicating device role or, a PaErrorCode (which are always negative)
261 if PortAudio is not initialized or an error is encountered.
263 int/*PaWasapiDeviceRole*/ PaWasapi_GetDeviceRole( PaDeviceIndex nDevice );
266 /** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread
267 which makes calls to Pa_WriteStream/Pa_ReadStream.
269 @param hTask Handle to pointer to priority task. Must be used with PaWasapi_RevertThreadPriority
270 method to revert thread priority to initial state.
272 @param nPriorityClass Id of thread priority of PaWasapiThreadPriority type. Specifying
273 eThreadPriorityNone does nothing.
275 @return Error code indicating success or failure.
276 @see PaWasapi_RevertThreadPriority
278 PaError PaWasapi_ThreadPriorityBoost( void **hTask, PaWasapiThreadPriority nPriorityClass );
281 /** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread
282 which makes calls to Pa_WriteStream/Pa_ReadStream.
284 @param hTask Task handle obtained by PaWasapi_BoostThreadPriority method.
285 @return Error code indicating success or failure.
286 @see PaWasapi_BoostThreadPriority
288 PaError PaWasapi_ThreadPriorityRevert( void *hTask );
291 /** Get number of frames per host buffer. This is maximal value of frames of WASAPI buffer which
292 can be locked for operations. Use this method as helper to findout maximal values of
293 inputFrames/outputFrames of PaWasapiHostProcessorCallback.
295 @param pStream Pointer to PaStream to query.
296 @param nInput Pointer to variable to receive number of input frames. Can be NULL.
297 @param nOutput Pointer to variable to receive number of output frames. Can be NULL.
298 @return Error code indicating success or failure.
299 @see PaWasapiHostProcessorCallback
301 PaError PaWasapi_GetFramesPerHostBuffer( PaStream *pStream, unsigned int *nInput, unsigned int *nOutput );
304 /** Get number of jacks associated with a WASAPI device. Use this method to determine if
305 there are any jacks associated with the provided WASAPI device. Not all audio devices
306 will support this capability. This is valid for both input and output devices.
307 @param nDevice device index.
308 @param jcount Number of jacks is returned in this variable
309 @return Error code indicating success or failure
310 @see PaWasapi_GetJackDescription
312 PaError PaWasapi_GetJackCount(PaDeviceIndex nDevice, int *jcount);
315 /** Get the jack description associated with a WASAPI device and jack number
316 Before this function is called, use PaWasapi_GetJackCount to determine the
317 number of jacks associated with device. If jcount is greater than zero, then
318 each jack from 0 to jcount can be queried with this function to get the jack
320 @param nDevice device index.
321 @param jindex Which jack to return information
322 @param KSJACK_DESCRIPTION This structure filled in on success.
323 @return Error code indicating success or failure
324 @see PaWasapi_GetJackCount
326 PaError PaWasapi_GetJackDescription(PaDeviceIndex nDevice, int jindex, PaWasapiJackDescription *pJackDescription);
332 WASAPI is implemented for Callback and Blocking interfaces. It supports Shared and Exclusive
337 Exclusive mode allows to deliver audio data directly to hardware bypassing
339 Exclusive mode is specified by 'paWinWasapiExclusive' flag.
343 Provides best audio quality with low latency. Callback interface is implemented in
347 This is the most powerful WASAPI implementation which provides glitch-free
348 audio at around 3ms latency in Exclusive mode. Lowest possible latency for this mode is
349 3 ms for HD Audio class audio chips. For the Shared mode latency can not be
353 Polling is another 2-nd method to operate with WASAPI. It is less efficient than Event-Driven
354 and provides latency at around 10-13ms. Polling must be used to overcome a system bug
355 under Windows Vista x64 when application is WOW64(32-bit) and Event-Driven method simply
356 times out (event handle is never signalled on buffer completion). Please note, such WOW64 bug
357 does not exist in Vista x86 or Windows 7.
358 Polling can be setup by speciying 'paWinWasapiPolling' flag. Our WASAPI implementation detects
359 WOW64 bug and sets 'paWinWasapiPolling' automatically.
363 Normally thread priority is set automatically and does not require modification. Although
364 if user wants some tweaking thread priority can be modified by setting 'paWinWasapiThreadPriority'
365 flag and specifying 'PaWasapiStreamInfo::threadPriority' with value from PaWasapiThreadPriority
370 Blocking interface is implemented but due to above described Poll-Driven method can not
371 deliver lowest possible latency. Specifying too low latency in Shared mode will result in
372 distorted audio although Exclusive mode adds stability.
374 Pa_IsFormatSupported:
376 To check format with correct Share Mode (Exclusive/Shared) you must supply
377 PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of
378 PaStreamParameters::hostApiSpecificStreamInfo structure.
382 To set desired Share Mode (Exclusive/Shared) you must supply
383 PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of
384 PaStreamParameters::hostApiSpecificStreamInfo structure.
389 #endif /* __cplusplus */
391 #endif /* PA_WIN_WASAPI_H */