WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Sound and Media

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Adjust Audio Levels

Keywords: 	  Adjust Audio Levels   waveInGetNumDevs  waveOutGetVolume  waveOutSetVolume volume control sound 

;***Notes: This code makes a potentially dangerous assumption that the AUDIO device is stereo!
;**For safer code you are supposed to make a call to check the audio device's settings
;**Another assumption - uses first audio device it comes across, rather than going through all possible

:Startup
Gosub Initialize
NumDevices = DllCall(DaDll, long:"waveInGetNumDevs")
;Message("Number of wave devices", NumDevices)
:Process
  BoxesUp("300,400,700,500", @normal)
  BoxText("%NumDevices% audio devices found, first one used")
  Gosub GetVolume
  TimeDelay(2)
;  Pause("","")
  LeftVolumeAmount = LeftVolumeAmount + VolumeAdjustAmount
  RightVolumeAmount = RightVolumeAmount - VolumeAdjustAmount
  if LeftVolumeAmount > MaxVolume then LeftVolumeAmount = MaxVolume
  if LeftVolumeAmount < 0 then LeftVolumeAmount = 0
  if RightVolumeAmount > MaxVolume then RightVolumeAmount = MaxVolume
  if RightVolumeAmount < 0 then RightVolumeAmount = 0
  Gosub SetVolume
  Gosub GetVolume
;  Pause("","")
  TimeDelay(2)
  LeftVolumeAmount = LeftVolumeAmount + VolumeAdjustAmount
  RightVolumeAmount = RightVolumeAmount - VolumeAdjustAmount
  if LeftVolumeAmount > MaxVolume then LeftVolumeAmount = MaxVolume
  if LeftVolumeAmount < 0 then LeftVolumeAmount = 0
  if RightVolumeAmount > MaxVolume then RightVolumeAmount = MaxVolume
  if RightVolumeAmount < 0 then RightVolumeAmount = 0
  Gosub SetVolume
  Gosub GetVolume
  TimeDelay(2)

:Shutdown
BinaryFree(bin1)
EXIT
;*********************************


****************************Initialize*****************************************
:Initialize
MMSYSERR_BASE = 0
MMSYSERR_ALLOCATED = (MMSYSERR_BASE + 4)  ;  device already allocated
MMSYSERR_BADDEVICEID = (MMSYSERR_BASE + 2)  ;  device ID out of range
MMSYSERR_BADERRNUM = (MMSYSERR_BASE + 9)  ;  error value out of range
MMSYSERR_ERROR = (MMSYSERR_BASE + 1)  ;  unspecified error
MMSYSERR_HANDLEBUSY = (MMSYSERR_BASE + 12) ;  handle being used
MMSYSERR_INVALFLAG = (MMSYSERR_BASE + 10) ;  invalid flag passed
MMSYSERR_INVALHANDLE = (MMSYSERR_BASE + 5)  ;  device handle is invalid
MMSYSERR_INVALIDALIAS = (MMSYSERR_BASE + 13) ;  "Specified alias not found in WIN.INI
MMSYSERR_INVALPARAM = (MMSYSERR_BASE + 11) ;  invalid parameter passed
MMSYSERR_LASTERROR = (MMSYSERR_BASE + 13) ;  last error in range
MMSYSERR_NODRIVER = (MMSYSERR_BASE + 6)  ;  no device driver present
MMSYSERR_NOERROR = 0  ;  no error
MMSYSERR_NOMEM = (MMSYSERR_BASE + 7)  ;  memory allocation error
MMSYSERR_NOTENABLED = (MMSYSERR_BASE + 3)  ;  driver failed enable
MMSYSERR_NOTSUPPORTED = (MMSYSERR_BASE + 8)  ;  function isn't supported
DaDll=strcat(DirWindows(1),"WINMM.DLL")
bin1 = BinaryAlloc(4)
LeftVolumeAmount = 0
RightVolumeAmount = 0
VolumeAdjustAmount = 3000
MaxVolume = 65535
RETURN



****************************GetVolume******************************************
:GetVolume
WaveErr = DllCall(DaDll, long:"waveOutGetVolume",long:0, lpbinary:bin1)
if WaveErr != 0
  Message("error in waveOutGetVolume:", WaveErr)
  exit
endif
BinaryEODSet(bin1, 4)
binval = BinaryPeek4(bin1, 0)
RightVolumeAmount = binval >> 16
LeftVolumeAmount = binval - (RightVolumeAmount << 16)
WinTitle("", StrCat(LeftVolumeAmount, " , ", RightVolumeAmount))
RETURN

****************************SetVolume******************************************
:SetVolume
binval = (RightVolumeAmount << 16) + LeftVolumeAmount
BinaryPoke4(bin1, 0, binval)

NewVolume = BinaryPeek4(bin1, 0)
WaveErr = DllCall(DaDll, long:"waveOutSetVolume",long:0, long:NewVolume)
if WaveErr != 0
  Message("error in waveOutSetVolume:", WaveErr)
  exit
endif
RETURN

*******************************************************************************

Article ID:   W14732
Filename:   Adjust Audio.txt
File Created: 2001:05:11:15:07:20
Last Updated: 2001:05:11:15:07:20