2009. február 7., szombat

How to restore the original volume settings after changing the volume of a wave


Problem/Question/Abstract:

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.


procedure TClockForm.mm_wom_open(var Msg: TMessage);
{This code handles the WaveOutOpen message by writing two buffers of data
to the wave device.  Plus other miscellaneous housekeeping.}
begin
  waveOutGetVolume(hWave_out, @saved_volumes);
  waveOutSetVolume(hWave_out, volumes);
  waveOutPrepareHeader(hWave_out, p_wave_hdr, SizeOf(TWaveHdr));
  waveOutWrite(hWave_out, p_wave_hdr, SizeOf(TWaveHdr));
end;

procedure TClockForm.mm_wom_done(var Msg: TMessage);
{Handle the wave out done message}
begin
  waveOutSetVolume(hWave_out, saved_volumes);
  waveOutReset(hWave_out);
  waveOutClose(hWave_out);
end;

Nincsenek megjegyzések:

Megjegyzés küldése