cannam@130: #ifndef PA_WIN_WASAPI_H cannam@130: #define PA_WIN_WASAPI_H cannam@130: /* cannam@130: * $Id: $ cannam@130: * PortAudio Portable Real-Time Audio Library cannam@130: * DirectSound specific extensions cannam@130: * cannam@130: * Copyright (c) 1999-2007 Ross Bencina and Phil Burk cannam@130: * cannam@130: * Permission is hereby granted, free of charge, to any person obtaining cannam@130: * a copy of this software and associated documentation files cannam@130: * (the "Software"), to deal in the Software without restriction, cannam@130: * including without limitation the rights to use, copy, modify, merge, cannam@130: * publish, distribute, sublicense, and/or sell copies of the Software, cannam@130: * and to permit persons to whom the Software is furnished to do so, cannam@130: * subject to the following conditions: cannam@130: * cannam@130: * The above copyright notice and this permission notice shall be cannam@130: * included in all copies or substantial portions of the Software. cannam@130: * cannam@130: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, cannam@130: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF cannam@130: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. cannam@130: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR cannam@130: * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF cannam@130: * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION cannam@130: * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cannam@130: */ cannam@130: cannam@130: /* cannam@130: * The text above constitutes the entire PortAudio license; however, cannam@130: * the PortAudio community also makes the following non-binding requests: cannam@130: * cannam@130: * Any person wishing to distribute modifications to the Software is cannam@130: * requested to send the modifications to the original developer so that cannam@130: * they can be incorporated into the canonical version. It is also cannam@130: * requested that these non-binding requests be included along with the cannam@130: * license above. cannam@130: */ cannam@130: cannam@130: /** @file cannam@130: @ingroup public_header cannam@130: @brief WASAPI-specific PortAudio API extension header file. cannam@130: */ cannam@130: cannam@130: #include "portaudio.h" cannam@130: #include "pa_win_waveformat.h" cannam@130: cannam@130: #ifdef __cplusplus cannam@130: extern "C" cannam@130: { cannam@130: #endif /* __cplusplus */ cannam@130: cannam@130: cannam@130: /* Setup flags */ cannam@130: typedef enum PaWasapiFlags cannam@130: { cannam@130: /* puts WASAPI into exclusive mode */ cannam@130: paWinWasapiExclusive = (1 << 0), cannam@130: cannam@130: /* allows to skip internal PA processing completely */ cannam@130: paWinWasapiRedirectHostProcessor = (1 << 1), cannam@130: cannam@130: /* assigns custom channel mask */ cannam@130: paWinWasapiUseChannelMask = (1 << 2), cannam@130: cannam@130: /* selects non-Event driven method of data read/write cannam@130: Note: WASAPI Event driven core is capable of 2ms latency!!!, but Polling cannam@130: method can only provide 15-20ms latency. */ cannam@130: paWinWasapiPolling = (1 << 3), cannam@130: cannam@130: /* forces custom thread priority setting. must be used if PaWasapiStreamInfo::threadPriority cannam@130: is set to custom value. */ cannam@130: paWinWasapiThreadPriority = (1 << 4) cannam@130: } cannam@130: PaWasapiFlags; cannam@130: #define paWinWasapiExclusive (paWinWasapiExclusive) cannam@130: #define paWinWasapiRedirectHostProcessor (paWinWasapiRedirectHostProcessor) cannam@130: #define paWinWasapiUseChannelMask (paWinWasapiUseChannelMask) cannam@130: #define paWinWasapiPolling (paWinWasapiPolling) cannam@130: #define paWinWasapiThreadPriority (paWinWasapiThreadPriority) cannam@130: cannam@130: cannam@130: /* Host processor. Allows to skip internal PA processing completely. cannam@130: You must set paWinWasapiRedirectHostProcessor flag to PaWasapiStreamInfo::flags member cannam@130: in order to have host processor redirected to your callback. cannam@130: Use with caution! inputFrames and outputFrames depend solely on final device setup. cannam@130: To query maximal values of inputFrames/outputFrames use PaWasapi_GetFramesPerHostBuffer. cannam@130: */ cannam@130: typedef void (*PaWasapiHostProcessorCallback) (void *inputBuffer, long inputFrames, cannam@130: void *outputBuffer, long outputFrames, cannam@130: void *userData); cannam@130: cannam@130: /* Device role */ cannam@130: typedef enum PaWasapiDeviceRole cannam@130: { cannam@130: eRoleRemoteNetworkDevice = 0, cannam@130: eRoleSpeakers, cannam@130: eRoleLineLevel, cannam@130: eRoleHeadphones, cannam@130: eRoleMicrophone, cannam@130: eRoleHeadset, cannam@130: eRoleHandset, cannam@130: eRoleUnknownDigitalPassthrough, cannam@130: eRoleSPDIF, cannam@130: eRoleHDMI, cannam@130: eRoleUnknownFormFactor cannam@130: } cannam@130: PaWasapiDeviceRole; cannam@130: cannam@130: cannam@130: /* Jack connection type */ cannam@130: typedef enum PaWasapiJackConnectionType cannam@130: { cannam@130: eJackConnTypeUnknown, cannam@130: eJackConnType3Point5mm, cannam@130: eJackConnTypeQuarter, cannam@130: eJackConnTypeAtapiInternal, cannam@130: eJackConnTypeRCA, cannam@130: eJackConnTypeOptical, cannam@130: eJackConnTypeOtherDigital, cannam@130: eJackConnTypeOtherAnalog, cannam@130: eJackConnTypeMultichannelAnalogDIN, cannam@130: eJackConnTypeXlrProfessional, cannam@130: eJackConnTypeRJ11Modem, cannam@130: eJackConnTypeCombination cannam@130: } cannam@130: PaWasapiJackConnectionType; cannam@130: cannam@130: cannam@130: /* Jack geometric location */ cannam@130: typedef enum PaWasapiJackGeoLocation cannam@130: { cannam@130: eJackGeoLocUnk = 0, cannam@130: eJackGeoLocRear = 0x1, /* matches EPcxGeoLocation::eGeoLocRear */ cannam@130: eJackGeoLocFront, cannam@130: eJackGeoLocLeft, cannam@130: eJackGeoLocRight, cannam@130: eJackGeoLocTop, cannam@130: eJackGeoLocBottom, cannam@130: eJackGeoLocRearPanel, cannam@130: eJackGeoLocRiser, cannam@130: eJackGeoLocInsideMobileLid, cannam@130: eJackGeoLocDrivebay, cannam@130: eJackGeoLocHDMI, cannam@130: eJackGeoLocOutsideMobileLid, cannam@130: eJackGeoLocATAPI, cannam@130: eJackGeoLocReserved5, cannam@130: eJackGeoLocReserved6, cannam@130: } cannam@130: PaWasapiJackGeoLocation; cannam@130: cannam@130: cannam@130: /* Jack general location */ cannam@130: typedef enum PaWasapiJackGenLocation cannam@130: { cannam@130: eJackGenLocPrimaryBox = 0, cannam@130: eJackGenLocInternal, cannam@130: eJackGenLocSeparate, cannam@130: eJackGenLocOther cannam@130: } cannam@130: PaWasapiJackGenLocation; cannam@130: cannam@130: cannam@130: /* Jack's type of port */ cannam@130: typedef enum PaWasapiJackPortConnection cannam@130: { cannam@130: eJackPortConnJack = 0, cannam@130: eJackPortConnIntegratedDevice, cannam@130: eJackPortConnBothIntegratedAndJack, cannam@130: eJackPortConnUnknown cannam@130: } cannam@130: PaWasapiJackPortConnection; cannam@130: cannam@130: cannam@130: /* Thread priority */ cannam@130: typedef enum PaWasapiThreadPriority cannam@130: { cannam@130: eThreadPriorityNone = 0, cannam@130: eThreadPriorityAudio, //!< Default for Shared mode. cannam@130: eThreadPriorityCapture, cannam@130: eThreadPriorityDistribution, cannam@130: eThreadPriorityGames, cannam@130: eThreadPriorityPlayback, cannam@130: eThreadPriorityProAudio, //!< Default for Exclusive mode. cannam@130: eThreadPriorityWindowManager cannam@130: } cannam@130: PaWasapiThreadPriority; cannam@130: cannam@130: cannam@130: /* Stream descriptor. */ cannam@130: typedef struct PaWasapiJackDescription cannam@130: { cannam@130: unsigned long channelMapping; cannam@130: unsigned long color; /* derived from macro: #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) */ cannam@130: PaWasapiJackConnectionType connectionType; cannam@130: PaWasapiJackGeoLocation geoLocation; cannam@130: PaWasapiJackGenLocation genLocation; cannam@130: PaWasapiJackPortConnection portConnection; cannam@130: unsigned int isConnected; cannam@130: } cannam@130: PaWasapiJackDescription; cannam@130: cannam@130: cannam@130: /* Stream descriptor. */ cannam@130: typedef struct PaWasapiStreamInfo cannam@130: { cannam@130: unsigned long size; /**< sizeof(PaWasapiStreamInfo) */ cannam@130: PaHostApiTypeId hostApiType; /**< paWASAPI */ cannam@130: unsigned long version; /**< 1 */ cannam@130: cannam@130: unsigned long flags; /**< collection of PaWasapiFlags */ cannam@130: cannam@130: /* Support for WAVEFORMATEXTENSIBLE channel masks. If flags contains cannam@130: paWinWasapiUseChannelMask this allows you to specify which speakers cannam@130: to address in a multichannel stream. Constants for channelMask cannam@130: are specified in pa_win_waveformat.h. Will be used only if cannam@130: paWinWasapiUseChannelMask flag is specified. cannam@130: */ cannam@130: PaWinWaveFormatChannelMask channelMask; cannam@130: cannam@130: /* Delivers raw data to callback obtained from GetBuffer() methods skipping cannam@130: internal PortAudio processing inventory completely. userData parameter will cannam@130: be the same that was passed to Pa_OpenStream method. Will be used only if cannam@130: paWinWasapiRedirectHostProcessor flag is specified. cannam@130: */ cannam@130: PaWasapiHostProcessorCallback hostProcessorOutput; cannam@130: PaWasapiHostProcessorCallback hostProcessorInput; cannam@130: cannam@130: /* Specifies thread priority explicitly. Will be used only if paWinWasapiThreadPriority flag cannam@130: is specified. cannam@130: cannam@130: Please note, if Input/Output streams are opened simultaniously (Full-Duplex mode) cannam@130: you shall specify same value for threadPriority or othervise one of the values will be used cannam@130: to setup thread priority. cannam@130: */ cannam@130: PaWasapiThreadPriority threadPriority; cannam@130: } cannam@130: PaWasapiStreamInfo; cannam@130: cannam@130: cannam@130: /** Returns default sound format for device. Format is represented by PaWinWaveFormat or cannam@130: WAVEFORMATEXTENSIBLE structure. cannam@130: cannam@130: @param pFormat Pointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure. cannam@130: @param nFormatSize Size of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes. cannam@130: @param nDevice Device index. cannam@130: cannam@130: @return Non-negative value indicating the number of bytes copied into format decriptor cannam@130: or, a PaErrorCode (which are always negative) if PortAudio is not initialized cannam@130: or an error is encountered. cannam@130: */ cannam@130: int PaWasapi_GetDeviceDefaultFormat( void *pFormat, unsigned int nFormatSize, PaDeviceIndex nDevice ); cannam@130: cannam@130: cannam@130: /** Returns device role (PaWasapiDeviceRole enum). cannam@130: cannam@130: @param nDevice device index. cannam@130: cannam@130: @return Non-negative value indicating device role or, a PaErrorCode (which are always negative) cannam@130: if PortAudio is not initialized or an error is encountered. cannam@130: */ cannam@130: int/*PaWasapiDeviceRole*/ PaWasapi_GetDeviceRole( PaDeviceIndex nDevice ); cannam@130: cannam@130: cannam@130: /** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread cannam@130: which makes calls to Pa_WriteStream/Pa_ReadStream. cannam@130: cannam@130: @param hTask Handle to pointer to priority task. Must be used with PaWasapi_RevertThreadPriority cannam@130: method to revert thread priority to initial state. cannam@130: cannam@130: @param nPriorityClass Id of thread priority of PaWasapiThreadPriority type. Specifying cannam@130: eThreadPriorityNone does nothing. cannam@130: cannam@130: @return Error code indicating success or failure. cannam@130: @see PaWasapi_RevertThreadPriority cannam@130: */ cannam@130: PaError PaWasapi_ThreadPriorityBoost( void **hTask, PaWasapiThreadPriority nPriorityClass ); cannam@130: cannam@130: cannam@130: /** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread cannam@130: which makes calls to Pa_WriteStream/Pa_ReadStream. cannam@130: cannam@130: @param hTask Task handle obtained by PaWasapi_BoostThreadPriority method. cannam@130: @return Error code indicating success or failure. cannam@130: @see PaWasapi_BoostThreadPriority cannam@130: */ cannam@130: PaError PaWasapi_ThreadPriorityRevert( void *hTask ); cannam@130: cannam@130: cannam@130: /** Get number of frames per host buffer. This is maximal value of frames of WASAPI buffer which cannam@130: can be locked for operations. Use this method as helper to findout maximal values of cannam@130: inputFrames/outputFrames of PaWasapiHostProcessorCallback. cannam@130: cannam@130: @param pStream Pointer to PaStream to query. cannam@130: @param nInput Pointer to variable to receive number of input frames. Can be NULL. cannam@130: @param nOutput Pointer to variable to receive number of output frames. Can be NULL. cannam@130: @return Error code indicating success or failure. cannam@130: @see PaWasapiHostProcessorCallback cannam@130: */ cannam@130: PaError PaWasapi_GetFramesPerHostBuffer( PaStream *pStream, unsigned int *nInput, unsigned int *nOutput ); cannam@130: cannam@130: cannam@130: /** Get number of jacks associated with a WASAPI device. Use this method to determine if cannam@130: there are any jacks associated with the provided WASAPI device. Not all audio devices cannam@130: will support this capability. This is valid for both input and output devices. cannam@130: @param nDevice device index. cannam@130: @param jcount Number of jacks is returned in this variable cannam@130: @return Error code indicating success or failure cannam@130: @see PaWasapi_GetJackDescription cannam@130: */ cannam@130: PaError PaWasapi_GetJackCount(PaDeviceIndex nDevice, int *jcount); cannam@130: cannam@130: cannam@130: /** Get the jack description associated with a WASAPI device and jack number cannam@130: Before this function is called, use PaWasapi_GetJackCount to determine the cannam@130: number of jacks associated with device. If jcount is greater than zero, then cannam@130: each jack from 0 to jcount can be queried with this function to get the jack cannam@130: description. cannam@130: @param nDevice device index. cannam@130: @param jindex Which jack to return information cannam@130: @param KSJACK_DESCRIPTION This structure filled in on success. cannam@130: @return Error code indicating success or failure cannam@130: @see PaWasapi_GetJackCount cannam@130: */ cannam@130: PaError PaWasapi_GetJackDescription(PaDeviceIndex nDevice, int jindex, PaWasapiJackDescription *pJackDescription); cannam@130: cannam@130: cannam@130: /* cannam@130: IMPORTANT: cannam@130: cannam@130: WASAPI is implemented for Callback and Blocking interfaces. It supports Shared and Exclusive cannam@130: share modes. cannam@130: cannam@130: Exclusive Mode: cannam@130: cannam@130: Exclusive mode allows to deliver audio data directly to hardware bypassing cannam@130: software mixing. cannam@130: Exclusive mode is specified by 'paWinWasapiExclusive' flag. cannam@130: cannam@130: Callback Interface: cannam@130: cannam@130: Provides best audio quality with low latency. Callback interface is implemented in cannam@130: two versions: cannam@130: cannam@130: 1) Event-Driven: cannam@130: This is the most powerful WASAPI implementation which provides glitch-free cannam@130: audio at around 3ms latency in Exclusive mode. Lowest possible latency for this mode is cannam@130: 3 ms for HD Audio class audio chips. For the Shared mode latency can not be cannam@130: lower than 20 ms. cannam@130: cannam@130: 2) Poll-Driven: cannam@130: Polling is another 2-nd method to operate with WASAPI. It is less efficient than Event-Driven cannam@130: and provides latency at around 10-13ms. Polling must be used to overcome a system bug cannam@130: under Windows Vista x64 when application is WOW64(32-bit) and Event-Driven method simply cannam@130: times out (event handle is never signalled on buffer completion). Please note, such WOW64 bug cannam@130: does not exist in Vista x86 or Windows 7. cannam@130: Polling can be setup by speciying 'paWinWasapiPolling' flag. Our WASAPI implementation detects cannam@130: WOW64 bug and sets 'paWinWasapiPolling' automatically. cannam@130: cannam@130: Thread priority: cannam@130: cannam@130: Normally thread priority is set automatically and does not require modification. Although cannam@130: if user wants some tweaking thread priority can be modified by setting 'paWinWasapiThreadPriority' cannam@130: flag and specifying 'PaWasapiStreamInfo::threadPriority' with value from PaWasapiThreadPriority cannam@130: enum. cannam@130: cannam@130: Blocking Interface: cannam@130: cannam@130: Blocking interface is implemented but due to above described Poll-Driven method can not cannam@130: deliver lowest possible latency. Specifying too low latency in Shared mode will result in cannam@130: distorted audio although Exclusive mode adds stability. cannam@130: cannam@130: Pa_IsFormatSupported: cannam@130: cannam@130: To check format with correct Share Mode (Exclusive/Shared) you must supply cannam@130: PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of cannam@130: PaStreamParameters::hostApiSpecificStreamInfo structure. cannam@130: cannam@130: Pa_OpenStream: cannam@130: cannam@130: To set desired Share Mode (Exclusive/Shared) you must supply cannam@130: PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of cannam@130: PaStreamParameters::hostApiSpecificStreamInfo structure. cannam@130: */ cannam@130: cannam@130: #ifdef __cplusplus cannam@130: } cannam@130: #endif /* __cplusplus */ cannam@130: cannam@130: #endif /* PA_WIN_WASAPI_H */