Detect Win XP and Win 2K properly when determining latency.

This commit is contained in:
philburk 2002-04-19 18:31:54 +00:00
commit 18d252bbfe

View file

@ -33,6 +33,7 @@
/* Modifications
* 7/19/01 Mike Berry - casts for compiling with __MWERKS__ CodeWarrior
* 9/27/01 Phil Burk - use number of frames instead of real-time for CPULoad calculation.
* 4/19/02 Phil Burk - Check for Win XP for system latency calculation.
*/
/* Compiler flags:
SUPPORT_AUDIO_CAPTURE - define this flag if you want to SUPPORT_AUDIO_CAPTURE
@ -49,10 +50,12 @@
#include "pa_host.h"
#include "pa_trace.h"
#include "dsound_wrapper.h"
#define PRINT(x) { printf x; fflush(stdout); }
#define ERR_RPT(x) PRINT(x)
#define DBUG(x) /* PRINT(x) */
#define DBUGX(x) /* PRINT(x) */
#define PA_USE_HIGH_LATENCY (0)
#if PA_USE_HIGH_LATENCY
#define PA_WIN_9X_LATENCY (500)
@ -61,6 +64,9 @@
#define PA_WIN_9X_LATENCY (140)
#define PA_WIN_NT_LATENCY (280)
#endif
#define PA_WIN_WDM_LATENCY (120)
/* Trigger an underflow for testing purposes. Should normally be (0). */
#define PA_SIMULATE_UNDERFLOW (0)
#if PA_SIMULATE_UNDERFLOW
@ -68,6 +74,7 @@ static gUnderCallbackCounter = 0;
#define UNDER_START_GAP (10)
#define UNDER_STOP_GAP (UNDER_START_GAP + 4)
#endif
/************************************************* Definitions ********/
typedef struct internalPortAudioStream internalPortAudioStream;
typedef struct internalPortAudioDevice
@ -78,6 +85,7 @@ typedef struct internalPortAudioDevice
PaDeviceInfo pad_Info;
}
internalPortAudioDevice;
/* Define structure to contain all DirectSound and Windows specific data. */
typedef struct PaHostSoundControl
{
@ -93,6 +101,7 @@ typedef struct PaHostSoundControl
double pahsc_InverseTicksPerUserBuffer;
}
PaHostSoundControl;
/************************************************* Shared Data ********/
/* FIXME - put Mutex around this shared data. */
static int sNumDevices = 0;
@ -115,6 +124,7 @@ static BOOL CALLBACK Pa_CountDevProc(LPGUID lpGUID,
static Pa_QueryDevices( void );
static void CALLBACK Pa_TimerCallback(UINT uID, UINT uMsg,
DWORD dwUser, DWORD dw1, DWORD dw2);
/********************************* BEGIN CPU UTILIZATION MEASUREMENT ****/
static void Pa_StartUsageCalculation( internalPortAudioStream *past )
{
@ -123,6 +133,7 @@ static void Pa_StartUsageCalculation( internalPortAudioStream *past )
/* Query system timer for usage analysis and to prevent overuse of CPU. */
QueryPerformanceCounter( &pahsc->pahsc_EntryCount );
}
static void Pa_EndUsageCalculation( internalPortAudioStream *past )
{
LARGE_INTEGER CurrentCount = { 0, 0 };
@ -142,6 +153,7 @@ static void Pa_EndUsageCalculation( internalPortAudioStream *past )
(LOWPASS_COEFFICIENT_1 * newUsage);
}
}
/****************************************** END CPU UTILIZATION *******/
static PaError Pa_QueryDevices( void )
{
@ -873,6 +885,38 @@ PaError PaHost_CloseStream( internalPortAudioStream *past )
past->past_DeviceData = NULL;
return paNoError;
}
/* Set minimal latency based on whether NT or Win95.
* NT has higher latency.
*/
static int PaHost_GetMinSystemLatency( void )
{
int minLatencyMsec;
/* Set minimal latency based on whether NT or other OS.
* NT has higher latency.
*/
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof( osvi );
GetVersionEx( &osvi );
DBUG(("PA - PlatformId = 0x%x\n", osvi.dwPlatformId ));
DBUG(("PA - MajorVersion = 0x%x\n", osvi.dwMajorVersion ));
DBUG(("PA - MinorVersion = 0x%x\n", osvi.dwMinorVersion ));
/* Check for NT */
if( (osvi.dwMajorVersion == 4) && (osvi.dwPlatformId == 2) )
{
minLatencyMsec = PA_WIN_NT_LATENCY;
}
else if(osvi.dwMajorVersion >= 5)
{
minLatencyMsec = PA_WIN_WDM_LATENCY;
}
else
{
minLatencyMsec = PA_WIN_9X_LATENCY;
}
return minLatencyMsec;
}
/*************************************************************************
** Determine minimum number of buffers required for this host based
** on minimum latency. Latency can be optionally set by user by setting
@ -888,7 +932,6 @@ PaError PaHost_CloseStream( internalPortAudioStream *past )
int Pa_GetMinNumBuffers( int framesPerBuffer, double sampleRate )
{
char envbuf[PA_ENV_BUF_SIZE];
DWORD hostVersion;
DWORD hresult;
int minLatencyMsec = 0;
double msecPerBuffer = (1000.0 * framesPerBuffer) / sampleRate;
@ -901,12 +944,7 @@ int Pa_GetMinNumBuffers( int framesPerBuffer, double sampleRate )
}
else
{
/* Set minimal latency based on whether NT or Win95.
* NT has higher latency.
*/
hostVersion = GetVersion();
/* High bit clear if NT */
minLatencyMsec = ( (hostVersion & 0x80000000) == 0 ) ? PA_WIN_NT_LATENCY : PA_WIN_9X_LATENCY ;
minLatencyMsec = PaHost_GetMinSystemLatency();
#if PA_USE_HIGH_LATENCY
PRINT(("PA - Minimum Latency set to %d msec!\n", minLatencyMsec ));
#endif