On 8/16/21, Chris Angelico <ros...@gmail.com> wrote:
> On Tue, Aug 17, 2021 at 11:44 AM Eryk Sun <eryk...@gmail.com> wrote:
>
>> Yes, the PC speaker beep does not get used in Windows 7+. The beep
>> device object is retained for compatibility, but it redirects the
>> request to a task in the user's session (which could be a remote
>> desktop session) that generates a WAV buffer in memory and plays it
>> via PlaySound().
>
> That seems a bizarre way to handle it.

Check the documentation [1]:

    In Windows 7, Beep was rewritten to pass the beep to the default sound
    device for the session. This is normally the sound card, except when
    run under Terminal Services, in which case the beep is rendered on the
    client.

I didn't just take their word for it, however. I checked the code for
"\Device\Beep" in a kernel debugger. It gets the session ID to find
and complete the I/O Request Packet (IRP) that was queued up by the
per-session multimedia task (in Windows device drivers, this is called
an inverted call [2]). I attached a debugger to the taskhostw.exe
process that's hosting the multimedia task -- in particular the
PlaySoundSrv.dll module -- and followed what it did to play a beep.
The implementation is in a CBeepRedirector class, in particular its
WorkThread() method handles the completed IOCTL from the beep device
by calling the DoPlaySound() method, which calls
Generate16bitMonoTone() to create a sine wave in WAV format, and plays
it via PlaySound() with the SND_MEMORY flag.

> multiple sound cards?

PlaySound() and system sounds use the default audio output device. If
it's an RDP session, the audio is redirected to the client-side device
stack.

> attention despite headphones being connected to the sound card?

An application that wants the user's attention can also flash the
window caption and/or taskbar button via FlashWindowEx().

---

[1] 
https://docs.microsoft.com/en-us/windows/win32/api/utilapiset/nf-utilapiset-beep
[2] https://www.osr.com/nt-insider/2013-issue1/inverted-call-model-kmdf
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to