Sound: Lautstärke geschrieben am 25.09.2005
Anbei ein paar gesammelte Funktionen zum Thema Sound in Delphi.
Benötigt werden folgende Units:
Delphi/Pascal
uses
MMSystem,Windows,sysutils,classes,Dialogs;
Mixer öffnen
Delphi/Pascalfunction InitMixer: HMixer;
var
Err: MMRESULT;
begin
Err := mixerOpen(@Result, 0, 0, 0, 0);
if Err <> MMSYSERR_NOERROR then Result := 0;
Mixer:=result;
end;
Delphi/Pascalfunction GetMixerControlID(CompType: DWORD): DWORD;
var mxl: TMIXERLINE;
mxc: TMIXERCONTROL;
mxlc: TMIXERLINECONTROLS;
begin
Result := 0;
mxl.cbStruct := Sizeof(mxl);
mxl.dwComponentType := CompType;
if (mixerGetLineInfo(0, @mxl, MIXER_GETLINEINFof_COMPONENTTYPE) = MMSYSERR_NOERROR) then
begin
mxlc.cbStruct := Sizeof(mxlc);
mxlc.dwLineID := mxl.dwLineID;
mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlc.cControls := mxl.cControls;
mxlc.cbmxctrl := sizeof(mxc);
mxlc.pamxctrl := @mxc;
if (mixerGetLineControls(0, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE) = MMSYSERR_NOERROR)
then Result := mxc.dwControlID;
end;
end;
function SetVolume(ID, Value: DWord): Boolean;
var
Volume : Array[0..1] of TMixerControlDetailsUnsigned;
mxcd: TMixerControlDetails;
begin
Volume[0].dwValue := Value;
Volume[1].dwValue := Value;
with mxcd Do
begin
cbStruct := Sizeof(mxcd);
dwControlID := ID;
cChannels := 2;
cMultipleItems := 0;
cbDetails := Sizeof(TMixerControlDetailsUnsigned) * 2;
paDetails := @Volume;
Result := (mixerSetControlDetails(0, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR);
end;
end;
function GetVolume(ID:DWord) : Cardinal; //0..65535
var
MasterVolume : TMixerControl;
Details : TMixerControlDetails;
UnsignedDetails : TMixerControlDetailsUnsigned;
Code : MMResult;
begin
Result :=0;
//if Mixer=0 then exit;
MasterVolume.dwControlID:=id;
Code := GetMasterVolumeControl(MasterVolume);
if(Code = MMSYSERR_NOERROR)then begin
with Details do begin
cbStruct := Sizeof(Details);
dwControlID := ID;
cChannels := 1; // set all channels
cMultipleItems := 0;
cbDetails := Sizeof(UnsignedDetails);
paDetails := @UnsignedDetails;
end;
if(mixerGetControlDetails(Mixer,
@Details,
MIXER_GETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR)then
result := UnsignedDetails.dwValue;
end;
end;
{
- waveOutSetVolume
- auxSetVolume
- mixerSetControlDetails
MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE
MIXERLINE_COMPONENTTYPE_SRC_LINE
MIXERCONTROL_CONTROLTYPE_VOLUME
MIXERCONTROL_CONTROLTYPE_FADER
}
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcewave/html/_wcesdk_am_mixerline.asp