Hi.
I give a short explanation how to use the new IMixer interface from your scripts in order to control (mute, unmute, set volume) the Windows mixer. This can be used for automatic rebroadcast.
The number of mixers available usually corresponds to the number of sound cards installed in your system. You can determine this number with the global function
function GetMixerCount: integer;
To obtain the IMixer interface of a specific Mixer, use the following function. All indexes start with 0, so when GetMixerCount reports 3 mixers, these have the indexes 0, 1 and 2.
function GetMixer(iIndex: integer): IMixer;
The IMixer interface is defined as follows:
type
IMixer = interface
function GetProductName: string;
function GetDestinationCount: integer;
procedure Mute(iDestination, iConnection: integer);
procedure Unmute(iDestination, iConnection: integer);
function IsMuted(iDestination, iConnection: integer): boolean;
procedure GetVolume(iDestination, iConnection: integer; var oLeft, oRight: integer);
procedure SetVolume(iDestination, iConnection: integer; iLeft, iRight: integer);
end;
GetProductName returns the name of the device, corresponds to the name of your sound card.
GetDestinationCount determines the number of “destinations” on that mixer device. Most have two, “Playback” and “Recording”. Unfortunately, you cannot determine which one is which, so you have to do trial-and-error.
Mute, Unmute, GetVolume and SetVolume affect the setting of a certain “connection” (Wave, Line In, …) on a specific destination. At this time, it is not possible to determine the names of the connections, trial-and-error again Apparently, the order is the same as displayed in the Windows Mixer program, 0 is the leftmost connection. Master volume can be controlled by setting connection to -1.
Volume values go from 0 (virtually muted) to 65535 (full).
Note that, for the Recording destination, most sound cards have “Select” options instead of “Mute” buttons. The Mute/Unmute functions will then set this “Select” option, however, with inverse semantics (calling “Mute” sets “Select”, so the channel is not muted, but all other channels are).
Here’s an example: Let’s first determine the number of mixers and write their names to the system log:
[code]var i: integer;
begin
for i := 0 to GetMixerCount - 1 do
SystemLog('Mixer ’ + IntToStr(i)+ ': ’ + GetMixer(i).GetProductName);
end.[/code]
Assume that we want to control the first sound card, “Playback” is destination #0, “Line In” is connection #3. Then you can unmute Line In with
begin
GetMixer(0).Unmute(0, 3);
end.
Torben