Author: Udo Nesshoever
How do I get the soundcard's volume? How to set it ?
Answer:
1 procedure GetVolume(var volL, volR: Word);
2 var
3 hWO: HWAVEOUT;
4 waveF: TWAVEFORMATEX;
5 vol: DWORD;
6 begin
7 volL := 0;
8 volR := 0;
9 // init TWAVEFORMATEX
10 FillChar(waveF, SizeOf(waveF), 0);
11 // open WaveMapper = std output of playsound
12 waveOutOpen(@hWO, WAVE_MAPPER, @waveF, 0, 0, 0);
13 // get volume
14 waveOutGetVolume(hWO, @vol);
15 volL := vol and $FFFF;
16 volR := vol shr 16;
17 waveOutClose(hWO);
18 end;
19
20 procedure SetVolume(const volL, volR: Word);
21 var
22 hWO: HWAVEOUT;
23 waveF: TWAVEFORMATEX;
24 vol: DWORD;
25 begin
26 // init TWAVEFORMATEX
27 FillChar(waveF, SizeOf(waveF), 0);
28 // open WaveMapper = std output of playsound
29 waveOutOpen(@hWO, WAVE_MAPPER, @waveF, 0, 0, 0);
30 vol := volL + volR shl 16;
31 // set volume
32 waveOutSetVolume(hWO, vol);
33 waveOutClose(hWO);
34 end;
|