uses
Windows, MMSystem;
....................................
function GetControl(Mixer: DWORD; Control: LPMIXERCONTROL; CtlType: DWORD): DWORD;
var
Line: MIXERLINE;
Controls: MIXERLINECONTROLS;
begin
ZeroMemory(@Line, sizeof(Line));
ZeroMemory(@Controls, sizeof(Controls));
Line.cbStruct:= sizeof(Line);
Line.dwComponentType:= MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
Result:= mixerGetLineInfo(Mixer, @Line, MIXER_GETLINEINFOF_COMPONENTTYPE);
if Result = MMSYSERR_NOERROR then
begin
Controls.cbStruct:= sizeof(Controls);
Controls.dwLineID:= Line.dwLineID;
Controls.cControls:= 1;
Controls.dwControlType:= CtlType;
Controls.cbmxctrl:= sizeof(MIXERCONTROL);
Controls.pamxctrl:= Control;
Result:= mixerGetLineControls(Mixer, @Controls, MIXER_GETLINECONTROLSF_ONEBYTYPE);
end;
end;
function SetMasterVolume(Mixer: HMIXEROBJ; Value: DWORD): DWORD;
var
MasterVolume: MIXERCONTROL;
Details: TMIXERCONTROLDETAILS;
UnsignedDetails: MIXERCONTROLDETAILS_UNSIGNED;
begin
ZeroMemory(@Details, sizeof(Details));
Result:= GetControl(0, @MasterVolume, MIXERCONTROL_CONTROLTYPE_VOLUME);
if Result = MMSYSERR_NOERROR then
begin
Details.cbStruct:= sizeof(MIXERCONTROLDETAILS);
Details.dwControlID:= MasterVolume.dwControlID;
Details.cChannels:= 1;
Details.cMultipleItems:= 0;
Details.cbDetails:= sizeof(MIXERCONTROLDETAILS_UNSIGNED);
Details.paDetails:= @UnsignedDetails;
UnsignedDetails.dwValue:= Value;
Result:= mixerSetControlDetails(Mixer, @Details, MIXER_SETCONTROLDETAILSF_VALUE);
end;
end;
function GetMasterVolume(Mixer: HMIXEROBJ; Value: LPDWORD): DWORD;
var
MasterVolume: MIXERCONTROL;
Details: TMIXERCONTROLDETAILS;
UnsignedDetails: MIXERCONTROLDETAILS_UNSIGNED;
begin
Value^:= 0;
Result:= GetControl(0, @MasterVolume, MIXERCONTROL_CONTROLTYPE_VOLUME);
if Result = MMSYSERR_NOERROR then
begin
Details.cbStruct:= sizeof(MIXERCONTROLDETAILS);
Details.dwControlID:= MasterVolume.dwControlID;
Details.cChannels:= 1;
Details.cMultipleItems:= 0;
Details.cbDetails:= sizeof(MIXERCONTROLDETAILS_UNSIGNED);
Details.paDetails:= @UnsignedDetails;
mixerGetControlDetails(Mixer, @Details, MIXER_SETCONTROLDETAILSF_VALUE);
end;
Value^:= UnsignedDetails.dwValue;
end;