33#define SPEAKER_RESPONSE 200
35#define MIN_AUDIBLE_FREQ 20
36#define MAX_AUDIBLE_FREQ 20000
47 static ULONG LastFrequency = 0, LastDuration = 0;
59 if (
Frequency == LastFrequency && Duration == LastDuration)
return;
73 LastDuration = Duration;
78 BeepSetParameters.
Duration = Duration;
87 sizeof(BeepSetParameters),
95 static ULONG Pulses = 0, CountStartTick = 0, LastPulsesFreq = 0;
96 ULONG LastPulseTickCount, CurrPulsesFreq;
138 if (Elapsed == 0) ++Elapsed;
149 CurrPulsesFreq = 10000 * Pulses / Elapsed;
152 if ((CurrPulsesFreq & 0x0F) > 7) CurrPulsesFreq += 0x10;
153 CurrPulsesFreq &= ~0x0F;
156 if (LastPulsesFreq == 0) LastPulsesFreq = CurrPulsesFreq;
160 if (LastPulsesFreq != 0 && CurrPulsesFreq == 0)
161 CurrPulsesFreq = LastPulsesFreq;
166#define UABS(x) (ULONG)((LONG)(x) < 0 ? -(LONG)(x) : (x))
167 if (
UABS(CurrPulsesFreq - LastPulsesFreq) > 7)
173 CurrPulsesFreq = (CurrPulsesFreq + LastPulsesFreq) >> 1;
178 FreqPulses = ((FreqPulses << 1) + LastPulsesFreq + CurrPulsesFreq) >> 2;
185 DPRINT(
"FreqPulses = %d, LastPulsesFreq = %d, CurrPulsesFreq = %d, Pulses = %d, Elapsed = %d\n",
186 FreqPulses, LastPulsesFreq, CurrPulsesFreq, Pulses, Elapsed);
188 LastPulsesFreq = CurrPulsesFreq;
200 BOOLEAN Timer2Gate = !!(Port61hValue & 0x01);
201 BOOLEAN SpeakerOn = !!(Port61hValue & 0x02);
203 DPRINT(
"SpeakerChange -- Timer2Gate == %s ; SpeakerOn == %s\n",
204 Timer2Gate ?
"true" :
"false", SpeakerOn ?
"true" :
"false");
229 OldSpeakerOff =
FALSE;
242 OldSpeakerOff =
TRUE;
271 wprintf(
L"FATAL: Performance counter not available\n");
290 DPRINT1(
"Failed to open the Beep driver, Status 0x%08lx\n",
Status);
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
DWORD WINAPI GetTickCount(VOID)
static OUT PIO_STATUS_BLOCK IoStatusBlock
#define InitializeObjectAttributes(p, n, a, r, s)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
NTSTATUS NTAPI NtCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG CreateDisposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength)
NTSTATUS NTAPI NtQueryPerformanceCounter(OUT PLARGE_INTEGER PerformanceCounter, OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL)
WORD PitGetReloadValue(BYTE Channel)
static LARGE_INTEGER Frequency
static LARGE_INTEGER Counter
#define PIT_BASE_FREQUENCY
static LARGE_INTEGER FreqCount
static VOID MakeBeep(ULONG Frequency, ULONG Duration)
VOID SpeakerChange(UCHAR Port61hValue)
static VOID PulseSample(VOID)
static LARGE_INTEGER CountStart
static ULONG PulseTickCount
VOID SpeakerCleanup(VOID)
VOID SpeakerInitialize(VOID)