PortAudio  2.0
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
pa_win_wasapi.c File Reference

WASAPI implementation of support for a host API. More...

#include <windows.h>
#include <stdio.h>
#include <process.h>
#include <assert.h>
#include <mmreg.h>
#include <malloc.h>
#include <memory.h>
#include <mmsystem.h>
#include "pa_util.h"
#include "pa_allocation.h"
#include "pa_hostapi.h"
#include "pa_stream.h"
#include "pa_cpuload.h"
#include "pa_process.h"
#include "pa_win_wasapi.h"
#include "pa_debugprint.h"
#include "pa_ringbuffer.h"
#include "pa_win_coinitialize.h"
#include <basetyps.h>
#include <rpcsal.h>
#include <sal.h>
#include <sdkddkver.h>
#include <propkeydef.h>
#include <audioclient.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
#include <functiondiscoverykeys.h>
#include <devicetopology.h>

Data Structures

struct  _tagpropertykey
 
struct  _BYTE_BLOB
 
struct  PaWasapiDeviceInfo
 
struct  PaWasapiHostApiRepresentation
 
struct  PaWasapiAudioClientParams
 
struct  PaWasapiSubStream
 
struct  PaWasapiHostProcessor
 
struct  PaWasapiStream
 
struct  ThreadIdleScheduler
 
struct  _SystemTimer
 

Macros

#define PA_WASAPI_MAX_CONST_DEVICE_COUNT   0
 
#define WINVER   0x0600
 Poll mode time slots logging. More...
 
#define _WIN32_WINNT   WINVER
 
#define WINAPI   __stdcall
 
#define __unaligned
 
#define __C89_NAMELESS
 
#define __LPCGUID_DEFINED__
 
#define PROPERTYKEY_DEFINED
 
#define __MIDL_CONST   const
 
#define NONAMELESSUNION
 
#define WAVE_FORMAT_IEEE_FLOAT   0x0003
 
#define __MINGW_EXTENSION
 
#define COBJMACROS
 
#define INITGUID
 
#define GUID_SECT
 
#define __DEFINE_GUID(n, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)   static const GUID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
 
#define __DEFINE_IID(n, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)   static const IID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
 
#define __DEFINE_CLSID(n, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)   static const CLSID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
 
#define PA_DEFINE_CLSID(className, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)   __DEFINE_CLSID(pa_CLSID_##className, 0x##l, 0x##w1, 0x##w2, 0x##b1, 0x##b2, 0x##b3, 0x##b4, 0x##b5, 0x##b6, 0x##b7, 0x##b8)
 
#define PA_DEFINE_IID(interfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)   __DEFINE_IID(pa_IID_##interfaceName, 0x##l, 0x##w1, 0x##w2, 0x##b1, 0x##b2, 0x##b3, 0x##b4, 0x##b5, 0x##b6, 0x##b7, 0x##b8)
 
#define CREATE_THREAD(PROC)   (HANDLE)_beginthreadex( NULL, 0, (PROC), stream, 0, &stream->dwThreadId )
 
#define PA_THREAD_FUNC   static unsigned WINAPI
 
#define PA_THREAD_ID   unsigned
 
#define AUDCLNT_E_BUFFER_ERROR   AUDCLNT_ERR(0x018)
 
#define AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED   AUDCLNT_ERR(0x019)
 
#define AUDCLNT_E_INVALID_DEVICE_PERIOD   AUDCLNT_ERR(0x020)
 
#define AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY   0x08000000
 
#define AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM   0x80000000
 
#define PA_WASAPI_DEVICE_ID_LEN   256
 
#define PA_WASAPI_DEVICE_NAME_LEN   128
 
#define STATIC_ARRAY_SIZE(array)   (sizeof(array)/sizeof(array[0]))
 
#define PRINT(x)   PA_DEBUG(x);
 
#define PA_SKELETON_SET_LAST_HOST_ERROR(errorCode, errorText)   PaUtil_SetLastHostErrorInfo( paWASAPI, errorCode, errorText )
 
#define PA_WASAPI__IS_FULLDUPLEX(STREAM)   ((STREAM)->in.clientProc && (STREAM)->out.clientProc)
 
#define IF_FAILED_JUMP(hr, label)   if(FAILED(hr)) goto label;
 
#define IF_FAILED_INTERNAL_ERROR_JUMP(hr, error, label)   if(FAILED(hr)) { error = paInternalError; goto label; }
 
#define SAFE_CLOSE(h)   if ((h) != NULL) { CloseHandle((h)); (h) = NULL; }
 
#define SAFE_RELEASE(punk)   if ((punk) != NULL) { (punk)->lpVtbl->Release((punk)); (punk) = NULL; }
 
#define _GetProc(fun, type, name)
 
#define LogHostError(HRES)   __LogHostError(HRES, __FUNCTION__, __FILE__, __LINE__)
 
#define LogPaError(PAERR)   __LogPaError(PAERR, __FUNCTION__, __FILE__, __LINE__)
 
#define HDA_PACKET_SIZE   (128)
 
#define REFTIMES_PER_SEC   10000000LL
 
#define REFTIMES_PER_MILLISEC   10000LL
 
#define REFTIMES_PER_SEC   10000000LL
 
#define REFTIMES_PER_MILLISEC   10000LL
 
#define NTSTATUS_SUCCESS   ((NTSTATUS)0x00000000L)
 
#define _WASAPI_MONO_TO_STEREO_MIXER_1_TO_2(TYPE)
 
#define _WASAPI_MONO_TO_STEREO_MIXER_2_TO_1_FLT32(TYPE)
 
#define _WASAPI_MONO_TO_STEREO_MIXER_2_TO_1_INT32(TYPE)
 
#define _WASAPI_MONO_TO_STEREO_MIXER_2_TO_1_INT64(TYPE)
 
#define _WASAPI_MONO_TO_STEREO_MIXER_2_TO_1_L(TYPE)
 

Typedefs

typedef enum _AVRT_PRIORITY AVRT_PRIORITY
 
typedef enum _AVRT_PRIORITYPAVRT_PRIORITY
 
typedef const GUID * LPCGUID
 
typedef GUID IID
 
typedef GUID CLSID
 
typedef struct _tagpropertykey PROPERTYKEY
 
typedef struct _BYTE_BLOB BYTE_BLOB
 
typedef __RPC_unique_pointer
BYTE_BLOB
UP_BYTE_BLOB
 
typedef LONGLONG REFERENCE_TIME
 
typedef LONG NTSTATUS
 
typedef void(* MixMonoToStereoF )(void *__to, const void *__from, UINT32 count)
 
typedef GUID PLARGE_INTEGER
 
typedef BOOL(WINAPIFAvRevertMmThreadCharacteristics )(HANDLE)
 
typedef struct PaWasapiDeviceInfo PaWasapiDeviceInfo
 
typedef struct
PaWasapiAudioClientParams 
PaWasapiAudioClientParams
 
typedef struct PaWasapiSubStream PaWasapiSubStream
 
typedef struct
PaWasapiHostProcessor 
PaWasapiHostProcessor
 
typedef struct PaWasapiStream PaWasapiStream
 
typedef struct ThreadIdleScheduler ThreadIdleScheduler
 
typedef struct _SystemTimer SystemTimer
 
typedef UINT32(* ALIGN_FUNC )(UINT32 v, UINT32 align)
 
typedef enum EWindowsVersion EWindowsVersion
 
typedef enum EMixDirection EMixDirection
 

Enumerations

enum  _AVRT_PRIORITY { AVRT_PRIORITY_LOW = -1, AVRT_PRIORITY_NORMAL, AVRT_PRIORITY_HIGH, AVRT_PRIORITY_CRITICAL }
 
enum  { S_INPUT = 0, S_OUTPUT = 1, S_COUNT = 2, S_FULLDUPLEX = 0 }
 
enum  { WASAPI_PACKETS_PER_INPUT_BUFFER = 6 }
 
enum  EWindowsVersion {
  WINDOWS_UNKNOWN = 0, WINDOWS_VISTA_SERVER2008, WINDOWS_7_SERVER2008R2, WINDOWS_8_SERVER2012,
  WINDOWS_8_1_SERVER2012R2, WINDOWS_10_SERVER2016, WINDOWS_FUTURE
}
 
enum  EMixDirection { MIX_DIR__1TO2, MIX_DIR__2TO1, MIX_DIR__2TO1_L }
 

Functions

 PA_DEFINE_IID (IAudioClient, 1cb9ad4c, dbfa, 4c32, b1, 78, c2, f5, 68, a7, 03, b2)
 
 PA_DEFINE_IID (IAudioClient2, 726778cd, f60a, 4eda, 82, de, e4, 76, 10, cd, 78, aa)
 
 PA_DEFINE_IID (IAudioClient3, 7ed4ee07, 8e67, 4cd4, 8c, 1a, 2b, 7a, 59, 87, ad, 42)
 
 PA_DEFINE_IID (IMMEndpoint, 1be09788, 6894, 4089, 85, 86, 9a, 2a, 6c, 26, 5a, c5)
 
 PA_DEFINE_IID (IMMDeviceEnumerator, a95664d2, 9614, 4f35, a7, 46, de, 8d, b6, 36, 17, e6)
 
 PA_DEFINE_CLSID (IMMDeviceEnumerator, bcde0395, e52f, 467c, 8e, 3d, c4, 57, 92, 91, 69, 2e)
 
 PA_DEFINE_IID (IAudioRenderClient, f294acfc, 3146, 4483, a7, bf, ad, dc, a7, c2, 60, e2)
 
 PA_DEFINE_IID (IAudioCaptureClient, c8adbd64, e71e, 48a0, a4, de, 18, 5c, 39, 5c, d3, 17)
 
 PA_DEFINE_IID (IDeviceTopology, 2A07407E, 6497, 4A18, 97, 87, 32, f7, 9b, d0, d9, 8f)
 
 PA_DEFINE_IID (IPart, AE2DE0E4, 5BCA, 4F2D, aa, 46, 5d, 13, f8, fd, b3, a9)
 
 PA_DEFINE_IID (IKsJackDescription, 4509F757, 2D46, 4637, 8e, 62, ce, 7d, b9, 44, f5, 7b)
 
 __DEFINE_GUID (pa_KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71)
 
 __DEFINE_GUID (pa_KSDATAFORMAT_SUBTYPE_ADPCM, 0x00000002, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71)
 
 __DEFINE_GUID (pa_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, 0x00000003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71)
 
PA_THREAD_FUNC ProcThreadEvent (void *param)
 
PA_THREAD_FUNC ProcThreadPoll (void *param)
 
typedef BOOL (WINAPI *FAvRtCreateThreadOrderingGroup)(PHANDLE
 
typedef HANDLE (WINAPI *FAvSetMmThreadCharacteristics)(LPCSTR
 
PaError PaWasapi_Initialize (PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index)
 
int PaWasapi_GetDeviceCurrentFormat (PaStream *pStream, void *pFormat, unsigned int formatSize, int bOutput)
 
int PaWasapi_GetDeviceDefaultFormat (void *pFormat, unsigned int formatSize, PaDeviceIndex device)
 
int PaWasapi_GetDeviceMixFormat (void *pFormat, unsigned int formatSize, PaDeviceIndex device)
 
int PaWasapi_GetDeviceRole (PaDeviceIndex device)
 
PaError PaWasapi_GetFramesPerHostBuffer (PaStream *pStream, unsigned int *pInput, unsigned int *pOutput)
 
unsigned long PaUtil_GetOutputFrameCount (PaUtilBufferProcessor *bp)
 
PaError PaWasapi_ThreadPriorityBoost (void **pTask, PaWasapiThreadPriority priorityClass)
 
PaError PaWasapi_ThreadPriorityRevert (void *pTask)
 
PaError PaWasapi_GetJackCount (PaDeviceIndex device, int *pJackCount)
 
PaError PaWasapi_GetJackDescription (PaDeviceIndex device, int jackIndex, PaWasapiJackDescription *pJackDescription)
 
PaError PaWasapi_GetAudioClient (PaStream *pStream, void **pAudioClient, int bOutput)
 
PaError PaWasapiWinrt_SetDefaultDeviceId (const unsigned short *pId, int bOutput)
 
PaError PaWasapiWinrt_PopulateDeviceList (const unsigned short **pId, const unsigned short **pName, const PaWasapiDeviceRole *pRole, unsigned int count, int bOutput)
 
PaError PaWasapi_SetStreamStateHandler (PaStream *pStream, PaWasapiStreamStateCallback fnStateHandler, void *pUserData)
 

Variables

typedef LPDWORD
 
FAvRtCreateThreadOrderingGroup pAvRtCreateThreadOrderingGroup = NULL
 
FAvRtDeleteThreadOrderingGroup pAvRtDeleteThreadOrderingGroup = NULL
 
FAvRtWaitOnThreadOrderingGroup pAvRtWaitOnThreadOrderingGroup = NULL
 
FAvSetMmThreadCharacteristics pAvSetMmThreadCharacteristics = NULL
 
FAvRevertMmThreadCharacteristics pAvRevertMmThreadCharacteristics = NULL
 
FAvSetMmThreadPriority pAvSetMmThreadPriority = NULL
 

Detailed Description

WASAPI implementation of support for a host API.

Note
pa_wasapi currently requires minimum VC 2005, and the latest Vista SDK

Macro Definition Documentation

#define __C89_NAMELESS
#define __DEFINE_CLSID (   n,
  l,
  w1,
  w2,
  b1,
  b2,
  b3,
  b4,
  b5,
  b6,
  b7,
  b8 
)    static const CLSID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
#define __DEFINE_GUID (   n,
  l,
  w1,
  w2,
  b1,
  b2,
  b3,
  b4,
  b5,
  b6,
  b7,
  b8 
)    static const GUID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
#define __DEFINE_IID (   n,
  l,
  w1,
  w2,
  b1,
  b2,
  b3,
  b4,
  b5,
  b6,
  b7,
  b8 
)    static const IID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
#define __LPCGUID_DEFINED__
#define __MIDL_CONST   const
#define __MINGW_EXTENSION
#define __unaligned
#define _GetProc (   fun,
  type,
  name 
)
Value:
{ \
fun = (type) GetProcAddress(hDInputDLL,name); \
if (fun == NULL) { \
PRINT(("GetProcAddr failed for %s" ,name)); \
return FALSE; \
} \
} \
#define FALSE
Definition: pa_jack.c:240
#define PRINT(x)
Definition: pa_win_wasapi.c:347
#define _WASAPI_MONO_TO_STEREO_MIXER_1_TO_2 (   TYPE)
Value:
TYPE * __restrict to = (TYPE *)__to;\
const TYPE * __restrict from = (const TYPE *)__from;\
const TYPE * __restrict end = from + count;\
while (from != end)\
{\
to[0] = to[1] = *from ++;\
to += 2;\
}
#define _WASAPI_MONO_TO_STEREO_MIXER_2_TO_1_FLT32 (   TYPE)
Value:
TYPE * __restrict to = (TYPE *)__to;\
const TYPE * __restrict from = (const TYPE *)__from;\
const TYPE * __restrict end = to + count;\
while (to != end)\
{\
*to ++ = (TYPE)((float)(from[0] + from[1]) * 0.5f);\
from += 2;\
}
#define _WASAPI_MONO_TO_STEREO_MIXER_2_TO_1_INT32 (   TYPE)
Value:
TYPE * __restrict to = (TYPE *)__to;\
const TYPE * __restrict from = (const TYPE *)__from;\
const TYPE * __restrict end = to + count;\
while (to != end)\
{\
*to ++ = (TYPE)(((INT32)from[0] + (INT32)from[1]) >> 1);\
from += 2;\
}
#define _WASAPI_MONO_TO_STEREO_MIXER_2_TO_1_INT64 (   TYPE)
Value:
TYPE * __restrict to = (TYPE *)__to;\
const TYPE * __restrict from = (const TYPE *)__from;\
const TYPE * __restrict end = to + count;\
while (to != end)\
{\
*to ++ = (TYPE)(((INT64)from[0] + (INT64)from[1]) >> 1);\
from += 2;\
}
#define _WASAPI_MONO_TO_STEREO_MIXER_2_TO_1_L (   TYPE)
Value:
TYPE * __restrict to = (TYPE *)__to;\
const TYPE * __restrict from = (const TYPE *)__from;\
const TYPE * __restrict end = to + count;\
while (to != end)\
{\
*to ++ = from[0];\
from += 2;\
}
#define _WIN32_WINNT   WINVER
#define AUDCLNT_E_BUFFER_ERROR   AUDCLNT_ERR(0x018)
#define AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED   AUDCLNT_ERR(0x019)
#define AUDCLNT_E_INVALID_DEVICE_PERIOD   AUDCLNT_ERR(0x020)
#define AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM   0x80000000
#define AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY   0x08000000
#define COBJMACROS
#define CREATE_THREAD (   PROC)    (HANDLE)_beginthreadex( NULL, 0, (PROC), stream, 0, &stream->dwThreadId )
#define GUID_SECT
#define HDA_PACKET_SIZE   (128)
#define IF_FAILED_INTERNAL_ERROR_JUMP (   hr,
  error,
  label 
)    if(FAILED(hr)) { error = paInternalError; goto label; }
#define IF_FAILED_JUMP (   hr,
  label 
)    if(FAILED(hr)) goto label;
#define INITGUID
#define LogHostError (   HRES)    __LogHostError(HRES, __FUNCTION__, __FILE__, __LINE__)
#define LogPaError (   PAERR)    __LogPaError(PAERR, __FUNCTION__, __FILE__, __LINE__)

Referenced by ProcThreadPoll().

#define NONAMELESSUNION
#define NTSTATUS_SUCCESS   ((NTSTATUS)0x00000000L)
#define PA_DEFINE_CLSID (   className,
  l,
  w1,
  w2,
  b1,
  b2,
  b3,
  b4,
  b5,
  b6,
  b7,
  b8 
)    __DEFINE_CLSID(pa_CLSID_##className, 0x##l, 0x##w1, 0x##w2, 0x##b1, 0x##b2, 0x##b3, 0x##b4, 0x##b5, 0x##b6, 0x##b7, 0x##b8)
#define PA_DEFINE_IID (   interfaceName,
  l,
  w1,
  w2,
  b1,
  b2,
  b3,
  b4,
  b5,
  b6,
  b7,
  b8 
)    __DEFINE_IID(pa_IID_##interfaceName, 0x##l, 0x##w1, 0x##w2, 0x##b1, 0x##b2, 0x##b3, 0x##b4, 0x##b5, 0x##b6, 0x##b7, 0x##b8)
#define PA_SKELETON_SET_LAST_HOST_ERROR (   errorCode,
  errorText 
)    PaUtil_SetLastHostErrorInfo( paWASAPI, errorCode, errorText )
#define PA_THREAD_FUNC   static unsigned WINAPI
#define PA_THREAD_ID   unsigned
#define PA_WASAPI__IS_FULLDUPLEX (   STREAM)    ((STREAM)->in.clientProc && (STREAM)->out.clientProc)

Referenced by ProcThreadPoll().

#define PA_WASAPI_DEVICE_ID_LEN   256
#define PA_WASAPI_DEVICE_NAME_LEN   128
#define PA_WASAPI_MAX_CONST_DEVICE_COUNT   0
#define PRINT (   x)    PA_DEBUG(x);
#define PROPERTYKEY_DEFINED
#define REFTIMES_PER_MILLISEC   10000LL
#define REFTIMES_PER_MILLISEC   10000LL
#define REFTIMES_PER_SEC   10000000LL
#define REFTIMES_PER_SEC   10000000LL
#define SAFE_CLOSE (   h)    if ((h) != NULL) { CloseHandle((h)); (h) = NULL; }
#define SAFE_RELEASE (   punk)    if ((punk) != NULL) { (punk)->lpVtbl->Release((punk)); (punk) = NULL; }
#define STATIC_ARRAY_SIZE (   array)    (sizeof(array)/sizeof(array[0]))
#define WAVE_FORMAT_IEEE_FLOAT   0x0003
#define WINAPI   __stdcall
#define WINVER   0x0600

Poll mode time slots logging.

Typedef Documentation

typedef UINT32(* ALIGN_FUNC)(UINT32 v, UINT32 align)
typedef AVRT_PRIORITY
typedef struct _BYTE_BLOB BYTE_BLOB
typedef GUID CLSID
typedef BOOL(WINAPI * FAvRevertMmThreadCharacteristics)(HANDLE)
typedef GUID IID
typedef const GUID* LPCGUID
typedef void(* MixMonoToStereoF)(void *__to, const void *__from, UINT32 count)
typedef LONG NTSTATUS
typedef PLARGE_INTEGER
typedef struct _tagpropertykey PROPERTYKEY
typedef LONGLONG REFERENCE_TIME
typedef struct _SystemTimer SystemTimer
typedef __RPC_unique_pointer BYTE_BLOB* UP_BYTE_BLOB

Enumeration Type Documentation

anonymous enum
Enumerator
S_INPUT 
S_OUTPUT 
S_COUNT 
S_FULLDUPLEX 
anonymous enum
Enumerator
WASAPI_PACKETS_PER_INPUT_BUFFER 
Enumerator
AVRT_PRIORITY_LOW 
AVRT_PRIORITY_NORMAL 
AVRT_PRIORITY_HIGH 
AVRT_PRIORITY_CRITICAL 
Enumerator
MIX_DIR__1TO2 

mix one channel to L and R

MIX_DIR__2TO1 

mix L and R channels to one channel

MIX_DIR__2TO1_L 

mix only L channel (of total 2 channels) to one channel

Enumerator
WINDOWS_UNKNOWN 
WINDOWS_VISTA_SERVER2008 
WINDOWS_7_SERVER2008R2 
WINDOWS_8_SERVER2012 
WINDOWS_8_1_SERVER2012R2 
WINDOWS_10_SERVER2016 
WINDOWS_FUTURE 

Function Documentation

__DEFINE_GUID ( pa_KSDATAFORMAT_SUBTYPE_PCM  ,
0x00000001  ,
0x0000  ,
0x0010  ,
0x80  ,
0x00  ,
0x00  ,
0xaa  ,
0x00  ,
0x38  ,
0x9b  ,
0x71   
)
__DEFINE_GUID ( pa_KSDATAFORMAT_SUBTYPE_ADPCM  ,
0x00000002  ,
0x0000  ,
0x0010  ,
0x80  ,
0x00  ,
0x00  ,
0xaa  ,
0x00  ,
0x38  ,
0x9b  ,
0x71   
)
__DEFINE_GUID ( pa_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT  ,
0x00000003  ,
0x0000  ,
0x0010  ,
0x80  ,
0x00  ,
0x00  ,
0xaa  ,
0x00  ,
0x38  ,
0x9b  ,
0x71   
)
typedef BOOL ( WINAPI FAvRtCreateThreadOrderingGroup)
typedef HANDLE ( WINAPI FAvSetMmThreadCharacteristics)
PA_DEFINE_CLSID ( IMMDeviceEnumerator  ,
bcde0395  ,
e52f  ,
467c  ,
8e  ,
3d  ,
c4  ,
57  ,
92  ,
91  ,
69  ,
2e   
)
PA_DEFINE_IID ( IAudioClient  ,
1cb9ad4c  ,
dbfa  ,
4c32  ,
b1  ,
78  ,
c2  ,
f5  ,
68  ,
a7  ,
03  ,
b2   
)
PA_DEFINE_IID ( IAudioClient2  ,
726778cd  ,
f60a  ,
4eda  ,
82  ,
de  ,
e4  ,
76  ,
10  ,
cd  ,
78  ,
aa   
)
PA_DEFINE_IID ( IAudioClient3  ,
7ed4ee07  ,
8e67  ,
4cd4  ,
8c  ,
1a  ,
2b  ,
7a  ,
59  ,
87  ,
ad  ,
42   
)
PA_DEFINE_IID ( IMMEndpoint  ,
1be09788  ,
6894  ,
4089  ,
85  ,
86  ,
9a  ,
2a  ,
6c  ,
26  ,
5a  ,
c5   
)
PA_DEFINE_IID ( IMMDeviceEnumerator  ,
a95664d2  ,
9614  ,
4f35  ,
a7  ,
46  ,
de  ,
8d  ,
b6  ,
36  ,
17  ,
e6   
)
PA_DEFINE_IID ( IAudioRenderClient  ,
f294acfc  ,
3146  ,
4483  ,
a7  ,
bf  ,
ad  ,
dc  ,
a7  ,
c2  ,
60  ,
e2   
)
PA_DEFINE_IID ( IAudioCaptureClient  ,
c8adbd64  ,
e71e  ,
48a0  ,
a4  ,
de  ,
18  ,
5c  ,
39  ,
5c  ,
d3  ,
17   
)
PA_DEFINE_IID ( IDeviceTopology  ,
2A07407E  ,
6497  ,
4A18  ,
97  ,
87  ,
32  ,
f7  ,
9b  ,
d0  ,
d9  ,
8f   
)
PA_DEFINE_IID ( IPart  ,
AE2DE0E4  ,
5BCA  ,
4F2D  ,
aa  ,
46  ,
5d  ,
13  ,
f8  ,
fd  ,
b3  ,
a9   
)
PA_DEFINE_IID ( IKsJackDescription  ,
4509F757  ,
2D46  ,
4637  ,
8e  ,
62  ,
ce  ,
7d  ,
b9  ,
44  ,
f5  ,
7b   
)
unsigned long PaUtil_GetOutputFrameCount ( PaUtilBufferProcessor bp)
PaError PaWasapi_GetAudioClient ( PaStream pStream,
void **  pAudioClient,
int  bOutput 
)

Returns pointer to WASAPI's IAudioClient object of the stream.

Parameters
pStreamPointer to PaStream object.
pAudioClientPointer to pointer of IAudioClient.
bOutputTRUE (1) for output stream, FALSE (0) for input stream.
Returns
Error code indicating success or failure.

References PaWasapiSubStream::clientParent, PaWasapiStream::in, PaWasapiStream::out, paBadStreamPtr, paNoError, paUnanticipatedHostError, and TRUE.

int PaWasapi_GetDeviceCurrentFormat ( PaStream pStream,
void *  pFormat,
unsigned int  formatSize,
int  bOutput 
)

Get current audio format of the device assigned to the opened stream.

Format is represented by PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure. Use this function to reconfirm format if PA's processor is overriden and paWinWasapiRedirectHostProcessor flag is specified.

Parameters
pStreamPointer to PaStream object.
pFormatPointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure.
formatSizeSize of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes.
bOutputTRUE (1) for output stream, FALSE (0) for input stream.
Returns
Non-negative value indicating the number of bytes copied into format decriptor or, a PaErrorCode (which is always negative) if PortAudio is not initialized or an error is encountered.

References PaWasapiStream::in, PaWasapiStream::out, paBadStreamPtr, TRUE, and PaWasapiSubStream::wavex.

int PaWasapi_GetDeviceDefaultFormat ( void *  pFormat,
unsigned int  formatSize,
PaDeviceIndex  device 
)

Get default audio format for the device in Shared Mode.

Format is represented by PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure and obtained by getting the device property with a PKEY_AudioEngine_DeviceFormat key.

Parameters
pFormatPointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure.
formatSizeSize of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes.
deviceDevice index.
Returns
Non-negative value indicating the number of bytes copied into format decriptor or, a PaErrorCode (which is always negative) if PortAudio is not initialized or an error is encountered.

References PaWasapiDeviceInfo::DefaultFormat, PaWasapiHostApiRepresentation::deviceCount, PaWasapiHostApiRepresentation::devInfo, PaWasapiHostApiRepresentation::inheritedHostApiRep, paBadBufferPtr, paBufferTooSmall, paInvalidDevice, paNoError, and PaUtil_DeviceIndexToHostApiDeviceIndex().

int PaWasapi_GetDeviceMixFormat ( void *  pFormat,
unsigned int  formatSize,
PaDeviceIndex  device 
)

Get mix audio format for the device in Shared Mode.

Format is represented by PaWinWaveFormat or WAVEFORMATEXTENSIBLE structureand obtained by IAudioClient::GetMixFormat.

Parameters
pFormatPointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure.
formatSizeSize of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes.
deviceDevice index.
Returns
Non-negative value indicating the number of bytes copied into format decriptor or, a PaErrorCode (which is always negative) if PortAudio is not initialized or an error is encountered.

References PaWasapiHostApiRepresentation::deviceCount, PaWasapiHostApiRepresentation::devInfo, PaWasapiHostApiRepresentation::inheritedHostApiRep, PaWasapiDeviceInfo::MixFormat, paBadBufferPtr, paBufferTooSmall, paInvalidDevice, paNoError, and PaUtil_DeviceIndexToHostApiDeviceIndex().

int PaWasapi_GetDeviceRole ( PaDeviceIndex  device)

Get device role (PaWasapiDeviceRole enum).

Parameters
deviceDevice index.
Returns
Non-negative value indicating device role or, a PaErrorCode (which is always negative) if PortAudio is not initialized or an error is encountered.

References PaWasapiHostApiRepresentation::deviceCount, PaWasapiHostApiRepresentation::devInfo, PaWasapiDeviceInfo::formFactor, PaWasapiHostApiRepresentation::inheritedHostApiRep, paInvalidDevice, paNoError, paNotInitialized, and PaUtil_DeviceIndexToHostApiDeviceIndex().

PaError PaWasapi_GetFramesPerHostBuffer ( PaStream pStream,
unsigned int *  pInput,
unsigned int *  pOutput 
)

Get number of frames per host buffer.

It is max value of frames of WASAPI buffer which can be locked for operations. Use this method as helper to findout max values of inputFrames/outputFrames of PaWasapiHostProcessorCallback.

Parameters
pStreamPointer to PaStream object.
pInputPointer to variable to receive number of input frames. Can be NULL.
pOutputPointer to variable to receive number of output frames. Can be NULL.
Returns
Error code indicating success or failure.
See Also
PaWasapiHostProcessorCallback

References PaWasapiSubStream::framesPerHostCallback, PaWasapiStream::in, PaWasapiStream::out, paBadStreamPtr, and paNoError.

PaError PaWasapi_GetJackCount ( PaDeviceIndex  device,
int *  pJackCount 
)

Get number of jacks associated with a WASAPI device.

Use this method to determine if there are any jacks associated with the provided WASAPI device. Not all audio devices will support this capability. This is valid for both input and output devices.

Note
Not available on UWP platform.
Parameters
deviceDevice index.
pJackCountPointer to variable to receive number of jacks.
Returns
Error code indicating success or failure.
See Also
PaWasapi_GetJackDescription

References PaWasapiDeviceInfo::device, PaWasapiHostApiRepresentation::deviceCount, PaWasapiHostApiRepresentation::devInfo, IF_FAILED_JUMP, PaWasapiHostApiRepresentation::inheritedHostApiRep, LogHostError, paInvalidDevice, paNoError, paNotInitialized, paUnanticipatedHostError, PaUtil_DeviceIndexToHostApiDeviceIndex(), and SAFE_RELEASE.

PaError PaWasapi_GetJackDescription ( PaDeviceIndex  device,
int  jackIndex,
PaWasapiJackDescription pJackDescription 
)

Get the jack description associated with a WASAPI device and jack number.

Before this function is called, use PaWasapi_GetJackCount to determine the number of jacks associated with device. If jcount is greater than zero, then each jack from 0 to jcount can be queried with this function to get the jack description.

Note
Not available on UWP platform.
Parameters
deviceDevice index.
jackIndexJack index.
pJackDescriptionPointer to PaWasapiJackDescription.
Returns
Error code indicating success or failure.
See Also
PaWasapi_GetJackCount

References PaWasapiJackDescription::channelMapping, PaWasapiJackDescription::color, PaWasapiJackDescription::connectionType, PaWasapiDeviceInfo::device, PaWasapiHostApiRepresentation::deviceCount, PaWasapiHostApiRepresentation::devInfo, PaWasapiJackDescription::genLocation, PaWasapiJackDescription::geoLocation, IF_FAILED_JUMP, PaWasapiHostApiRepresentation::inheritedHostApiRep, PaWasapiJackDescription::isConnected, LogHostError, paInvalidDevice, paNoError, paNotInitialized, paUnanticipatedHostError, PaUtil_DeviceIndexToHostApiDeviceIndex(), PaWasapiJackDescription::portConnection, and SAFE_RELEASE.

PaError PaWasapi_Initialize ( PaUtilHostApiRepresentation **  hostApi,
PaHostApiIndex  index 
)
PaError PaWasapi_SetStreamStateHandler ( PaStream pStream,
PaWasapiStreamStateCallback  fnStateHandler,
void *  pUserData 
)

Set stream state handler.

Parameters
pStreamPointer to PaStream object.
fnStateHandlerPointer to state handling function.
pUserDataPointer to user data.
Returns
Error code indicating success or failure.

References PaWasapiStream::fnStateHandler, paBadStreamPtr, paNoError, and PaWasapiStream::pStateHandlerUserData.

PaError PaWasapi_ThreadPriorityBoost ( void **  pTask,
PaWasapiThreadPriority  priorityClass 
)

Boost thread priority of calling thread (MMCSS).

Use it for Blocking Interface only inside the thread which makes calls to Pa_WriteStream/Pa_ReadStream.

Parameters
pTaskHandle to pointer to priority task. Must be used with PaWasapi_RevertThreadPriority method to revert thread priority to initial state.
priorityClassId of thread priority of PaWasapiThreadPriority type. Specifying eThreadPriorityNone does nothing.
Returns
Error code indicating success or failure.
See Also
PaWasapi_RevertThreadPriority

References eThreadPriorityAudio, eThreadPriorityProAudio, FALSE, HANDLE(), paNoError, and paUnanticipatedHostError.

Referenced by ProcThreadEvent(), and ProcThreadPoll().

PaError PaWasapi_ThreadPriorityRevert ( void *  pTask)

Boost thread priority of calling thread (MMCSS).

Use it for Blocking Interface only inside the thread which makes calls to Pa_WriteStream/Pa_ReadStream.

Parameters
pTaskTask handle obtained by PaWasapi_BoostThreadPriority method.
Returns
Error code indicating success or failure.
See Also
PaWasapi_BoostThreadPriority

References FALSE, paNoError, and paUnanticipatedHostError.

PaError PaWasapiWinrt_PopulateDeviceList ( const unsigned short **  pId,
const unsigned short **  pName,
const PaWasapiDeviceRole pRole,
unsigned int  count,
int  bOutput 
)

Populate the device list.

By default the implementation will rely on DEVINTERFACE_AUDIO_RENDER and DEVINTERFACE_AUDIO_CAPTURE as default devices. If device Id is provided by PaWasapiWinrt_SetDefaultDeviceId() then those device Ids will be used as default and only devices for the device list.

By populating the device list you can provide an additional available audio devices of the system to PA which are obtainable by: Windows::Devices::Enumeration::DeviceInformation::FindAllAsync(selector) where selector is obtainable by Windows::Media::Devices::MediaDevice::GetAudioRenderSelector() or Windows::Media::Devices::MediaDevice::GetAudioCaptureSelector() API.

After the call completes, memory referenced by pointers can be freed, as implementation keeps its own copy.

You must call PaWasapi_UpdateDeviceList() to update the internal device list of the implementation after calling this function.

See an example in the IMPORTANT notes.

Note
UWP/WinRT platform only.
Parameters
pIdArray of device Ids, pointer to the array of pointers of 16-bit Unicode string (WCHAR). If NULL and count is also 0 then device Ids will be reset to the default. Required.
pNameArray of device Names, pointer to the array of pointers of 16-bit Unicode string (WCHAR). Optional.
pRoleArray of device Roles, see PaWasapiDeviceRole and PaWasapi_GetDeviceRole() for more details. Optional.
countNumber of devices, the number of array elements (pId, pName, pRole). Maximum count of devices is limited by PA_WASAPI_DEVICE_MAX_COUNT.
bOutputTRUE (1) for output (render), FALSE (0) for input (capture).
Returns
Error code indicating success or failure. Will return paIncompatibleStreamHostApi if library is not compiled for UWP/WinRT platform. If Id is longer than PA_WASAPI_DEVICE_ID_LEN characters paBufferTooBig will be returned. If Name is longer than PA_WASAPI_DEVICE_NAME_LEN characters paBufferTooBig will be returned.

References PA_WASAPI_DEVICE_ID_LEN, PA_WASAPI_DEVICE_NAME_LEN, paBufferTooBig, paIncompatibleStreamHostApi, paInsufficientMemory, paNoError, and STATIC_ARRAY_SIZE.

PaError PaWasapiWinrt_SetDefaultDeviceId ( const unsigned short *  pId,
int  bOutput 
)

Set default device Id.

By default implementation will use the DEVINTERFACE_AUDIO_RENDER and DEVINTERFACE_AUDIO_CAPTURE Ids if device Id is not provided explicitly. These default Ids will not allow to use Exclusive mode on UWP/WinRT platform and thus you must provide device Id explicitly via this API before calling the Pa_OpenStream().

Device Ids on UWP platform are obtainable via: Windows::Media::Devices::MediaDevice::GetDefaultAudioRenderId() or Windows::Media::Devices::MediaDevice::GetDefaultAudioCaptureId() API.

After the call completes, memory referenced by pointers can be freed, as implementation keeps its own copy.

Call this function before calling Pa_IsFormatSupported() when Exclusive mode is requested.

See an example in the IMPORTANT notes.

Note
UWP/WinRT platform only.
Parameters
pIdDevice Id, pointer to the 16-bit Unicode string (WCHAR). If NULL then device Id will be reset to the default, e.g. DEVINTERFACE_AUDIO_RENDER or DEVINTERFACE_AUDIO_CAPTURE.
bOutputTRUE (1) for output (render), FALSE (0) for input (capture).
Returns
Error code indicating success or failure. Will return paIncompatibleStreamHostApi if library is not compiled for UWP/WinRT platform. If Id is longer than PA_WASAPI_DEVICE_ID_LEN characters paBufferTooBig will be returned.

References PA_WASAPI_DEVICE_ID_LEN, paBufferTooBig, paIncompatibleStreamHostApi, paNoError, and STATIC_ARRAY_SIZE.

PA_THREAD_FUNC ProcThreadEvent ( void *  param)
PA_THREAD_FUNC ProcThreadPoll ( void *  param)

Variable Documentation

typedef LPDWORD

Referenced by PaWinWdm_Initialize().

FAvRevertMmThreadCharacteristics pAvRevertMmThreadCharacteristics = NULL
FAvRtCreateThreadOrderingGroup pAvRtCreateThreadOrderingGroup = NULL
FAvRtDeleteThreadOrderingGroup pAvRtDeleteThreadOrderingGroup = NULL
FAvRtWaitOnThreadOrderingGroup pAvRtWaitOnThreadOrderingGroup = NULL
FAvSetMmThreadCharacteristics pAvSetMmThreadCharacteristics = NULL
FAvSetMmThreadPriority pAvSetMmThreadPriority = NULL