Set sound volume

Posted in Others

To change sound volume, use WaveOutSetVolume function. A value of 0xFFFF represents full volume, and a value of 0x0000 is silence.

uses mmsystem;

procedure TForm1.Button1Click(Sender: TObject);
var
  MyWaveOutCaps: TWaveOutCaps;
  Volume: Integer;
begin
  Volume:=Scrollbar1.Position;
  if WaveOutGetDevCaps(
    WAVE_MAPPER, 
    @MyWaveOutCaps, 
    sizeof(MyWaveOutCaps))=MMSYSERR_NOERROR then
      WaveOutSetVolume(WAVE_MAPPER, MakeLong(Volume, Volume));
end;