views:

246

answers:

1

I need to mute and unmute sounds from other processes in Windows XP. I am looking for the best strategy. It is possible to write a Kernel Mode mixer that will filter the inputs to the output device? My other approach would be set Hooks for the various API's to intercept their Win32 calls. I would strongly prefer the less invasive approach.

Some considerations: Covering applications that use the WinMM and DirectSound System Componenets would probably be sufficient (i.e. I don't need to worry about other audio interfaces).

This will eventually need to be used from a C# app. I am reasonably skilled with interop, but don't have internal knowledge of Win32 to make this happen.

It would be possible to list all the applications that would need to be muted and approach each application separately, although the list is expected to grow.

P.S. In case anyone is concerned, these operations will be performed with the users consent (no shady business).

A: 

The problem with kernel mode drivers is that they are generally not process-aware. This is part of a clean layered architecture. Dealing with processes is the responsibility of the OS itself. The audio driver should handle audio. Now, the mixer should definitely handle multiple audiostreams, and may give them unequal weight, but it should not particularly care where the came from. Also, the built-in mixer is not designed to be replacable, so you'd have to intercept the audiostreams before they're mixed.

For that reason, on XP it makes much more sense to use Microsoft Detours to intercept the calls at API level. You have the calling process info there. Detours basically injects assembly into the user-mode parts of the OS, so I would advice using C++ rather than C# with Detours.

As I understand it, on Vista the audiostack is rewritten such that it is possible to associate audiostreams with applications, but this is a system-wide feature.

MSalters