Author: Tomas Rutkauskas
I'm trying to control the left/ right channel volume of a wave. I've checked with
WaveOutGetDevCaps that volume and left/ right control is supported. When I try to
read the volume with WaveOutGetVolume (using "word (Wave_Mapper)" as the device), I
get MMSysErr_NotSupported. I need the original volume setting in order to restore
it later. WaveOutSetVolume also returns the same error.
Answer:
The code below worked for me. You will see that it is in message handlers for
WaveOutOpen etc. messages. The key might be that you need the handle to an open
wave device rather than simply the constant for wave_mapper.
1 procedure TClockForm.mm_wom_open(var Msg: TMessage);
2 {This code handles the WaveOutOpen message by writing two buffers of data3 to the wave device. Plus other miscellaneous housekeeping.}4 begin5 waveOutGetVolume(hWave_out, @saved_volumes);
6 waveOutSetVolume(hWave_out, volumes);
7 waveOutPrepareHeader(hWave_out, p_wave_hdr, SizeOf(TWaveHdr));
8 waveOutWrite(hWave_out, p_wave_hdr, SizeOf(TWaveHdr));
9 end;
10 11 procedure TClockForm.mm_wom_done(var Msg: TMessage);
12 {Handle the wave out done message}13 begin14 waveOutSetVolume(hWave_out, saved_volumes);
15 waveOutReset(hWave_out);
16 waveOutClose(hWave_out);
17 end;