<font face=Courier New><SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Function</SPAN> OpenMixer(<SPAN style="color:darkblue">ByVal</SPAN> MixerNumber <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> ret <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:green">' is there a mixer available?</SPAN>
<SPAN style="color:darkblue">If</SPAN> MixerNumber < 0 <SPAN style="color:darkblue">Or</SPAN> MixerNumber > mixerGetNumDevs - 1 <SPAN style="color:darkblue">Then</SPAN> <SPAN style="color:darkblue">Exit</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:green">' open the mixer</SPAN>
ret = mixerOpen(hMixerHandle, MixerNumber, 0, 0, 0)
<SPAN style="color:darkblue">If</SPAN> ret <> MMSYSERR_NOERROR <SPAN style="color:darkblue">Then</SPAN> <SPAN style="color:darkblue">Exit</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:green">' get the primary line controls by name, (this does not get all of the controls).</SPAN>
<SPAN style="color:green">' speaker (master) volume</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, _
MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(Speaker))
<SPAN style="color:green">' microphone volume</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, _
MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(MICROPHONE))
<SPAN style="color:green">' Line volume</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY, _
MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(AUXILIARY))
<SPAN style="color:green">' CD volume</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC, _
MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(COMPACTDISC))
<SPAN style="color:green">' Synthesizer volume</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER, _
MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(SYNTHESIZER))
<SPAN style="color:green">' wave volume</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT, _
MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(WAVEOUT))
<SPAN style="color:green">' Aux volume</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_LINE, _
MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(LINEIN))
<SPAN style="color:green">' speaker (master) mute</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, _
MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(SPEAKER_MUTE))
<SPAN style="color:green">' microphone mute</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, _
MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(MICROPHONE_MUTE))
<SPAN style="color:green">' Line mute</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY, _
MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(AUXILIARY_MUTE))
<SPAN style="color:green">' CD mute</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC, _
MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(COMPACTDISC_MUTE))
<SPAN style="color:green">' Synthesizer mute</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER, _
MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(SYNTHESIZER_MUTE))
<SPAN style="color:green">' wave mute</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT, _
MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(WAVEOUT_MUTE))
<SPAN style="color:green">' Aux mute</SPAN>
ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_LINE, _
MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(LINEIN_MUTE))
<SPAN style="color:green">' return the mixer handle</SPAN>
OpenMixer = <SPAN style="color:darkblue">True</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Function</SPAN> CloseMixer() <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
CloseMixer = mixerClose(hMixerHandle)
hMixerHandle = 0
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Function</SPAN> SetVolume(Control <SPAN style="color:darkblue">As</SPAN> VOL_CONTROL, <SPAN style="color:darkblue">ByVal</SPAN> NewVolume <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
SetVolume = SetControlValue(hMixerHandle, uMixerControls(Control), NewVolume)
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Function</SPAN> GetVolume(Control <SPAN style="color:darkblue">As</SPAN> VOL_CONTROL) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
GetVolume = GetControlValue(hMixerHandle, uMixerControls(Control))
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Function</SPAN> SetMute(Control <SPAN style="color:darkblue">As</SPAN> MUTE_CONTROL, _
<SPAN style="color:darkblue">ByVal</SPAN> MuteState <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Boolean</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Boolean</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> Mute <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
Mute = Abs(MuteState)
SetMute = SetControlValue(hMixerHandle, uMixerControls(Control), Mute)
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Function</SPAN> GetMute(Control <SPAN style="color:darkblue">As</SPAN> MUTE_CONTROL) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Boolean</SPAN>
GetMute = <SPAN style="color:darkblue">CBool</SPAN>(-GetControlValue(hMixerHandle, uMixerControls(Control)))
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Function</SPAN> GetMixerControl(<SPAN style="color:darkblue">ByVal</SPAN> hMixer <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, <SPAN style="color:darkblue">ByVal</SPAN> componentType _
<SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, <SPAN style="color:darkblue">ByVal</SPAN> ctrlType <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, <SPAN style="color:darkblue">ByRef</SPAN> mxc <SPAN style="color:darkblue">As</SPAN> MIXERCONTROL) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:green">' This function attempts to obtain a mixer control. Returns True if successful.</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> mxlc <SPAN style="color:darkblue">As</SPAN> MIXERLINECONTROLS
<SPAN style="color:darkblue">Dim</SPAN> mxl <SPAN style="color:darkblue">As</SPAN> MIXERLINE
<SPAN style="color:darkblue">Dim</SPAN> hMem <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> ret <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
mxl.cbStruct = Len(mxl)
mxl.dwComponentType = componentType
<SPAN style="color:green">' Obtain a line corresponding to the component type</SPAN>
ret = mixerGetLineInfo(hMixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)
<SPAN style="color:darkblue">If</SPAN> ret = MMSYSERR_NOERROR <SPAN style="color:darkblue">Then</SPAN>
mxlc.cbStruct = Len(mxlc)
mxlc.dwLineID = mxl.dwLineID
mxlc.dwControl = ctrlType
mxlc.cControls = 1
mxlc.cbmxctrl = Len(mxc)
<SPAN style="color:green">' Allocate a buffer for the control</SPAN>
hMem = GlobalAlloc(&H40, Len(mxc))
mxlc.pamxctrl = GlobalLock(hMem)
mxc.cbStruct = Len(mxc)
<SPAN style="color:green">' Get the control</SPAN>
ret = mixerGetLineControls(hMixer, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
<SPAN style="color:darkblue">If</SPAN> ret = MMSYSERR_NOERROR <SPAN style="color:darkblue">Then</SPAN>
GetMixerControl = <SPAN style="color:darkblue">True</SPAN>
<SPAN style="color:green">' Copy the control into the destination structure</SPAN>
CopyStructFromPtr mxc, mxlc.pamxctrl, Len(mxc)
<SPAN style="color:darkblue">Else</SPAN>
GetMixerControl = <SPAN style="color:darkblue">False</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
GlobalFree (hMem)
<SPAN style="color:darkblue">Exit</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
GetMixerControl = <SPAN style="color:darkblue">False</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Function</SPAN> SetControlValue(<SPAN style="color:darkblue">ByVal</SPAN> hMixer <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
mxc <SPAN style="color:darkblue">As</SPAN> MIXERCONTROL, <SPAN style="color:darkblue">ByVal</SPAN> NewVolume <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Boolean</SPAN>
<SPAN style="color:green">'This function sets the value for a control. Returns True if successful</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> mxcd <SPAN style="color:darkblue">As</SPAN> MIXERCONTROLDETAILS
<SPAN style="color:darkblue">Dim</SPAN> vol <SPAN style="color:darkblue">As</SPAN> MIXERCONTROLDETAILS_UNSIGNED
<SPAN style="color:darkblue">Dim</SPAN> hMem <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> ret <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
mxcd.item = 0
mxcd.dwControlID = mxc.dwControlID
mxcd.cbStruct = Len(mxcd)
mxcd.cbDetails = Len(vol)
<SPAN style="color:green"><SPAN style="color:green">' Allocate a buffer for the control</SPAN> value buffer</SPAN>
hMem = GlobalAlloc(&H40, Len(vol))
mxcd.paDetails = GlobalLock(hMem)
mxcd.cChannels = 1
<SPAN style="color:green">' setup value, use percent of range if max is greater than 100</SPAN>
<SPAN style="color:darkblue">If</SPAN> mxc.lMaximum > 100 <SPAN style="color:darkblue">Then</SPAN>
vol.dwValue = NewVolume * (mxc.lMaximum \ 100)
<SPAN style="color:darkblue">Else</SPAN>
vol.dwValue = NewVolume
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">If</SPAN> vol.dwValue > mxc.lMaximum <SPAN style="color:darkblue">Then</SPAN> vol.dwValue = mxc.lMaximum
<SPAN style="color:darkblue">If</SPAN> vol.dwValue < mxc.lMinimum <SPAN style="color:darkblue">Then</SPAN> vol.dwValue = mxc.lMinimum
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">' Copy the data into the control value buffer</SPAN></SPAN></SPAN>
CopyPtrFromStruct mxcd.paDetails, vol, Len(vol)
<SPAN style="color:green">' Set the control value</SPAN>
ret = mixerSetControlDetails(hMixer, mxcd, MIXER_SETCONTROLDETAILSF_VALUE)
GlobalFree (hMem)
<SPAN style="color:darkblue">If</SPAN> ret = MMSYSERR_NOERROR <SPAN style="color:darkblue">Then</SPAN> SetControlValue = <SPAN style="color:darkblue">True</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Function</SPAN> GetControlValue(<SPAN style="color:darkblue">ByVal</SPAN> hMixer <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, mxc <SPAN style="color:darkblue">As</SPAN> MIXERCONTROL) _
<SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:green">'This function gets the value for a control.</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> mxcd <SPAN style="color:darkblue">As</SPAN> MIXERCONTROLDETAILS
<SPAN style="color:darkblue">Dim</SPAN> vol <SPAN style="color:darkblue">As</SPAN> MIXERCONTROLDETAILS_UNSIGNED
<SPAN style="color:darkblue">Dim</SPAN> hMem <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> ret <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
mxcd.item = 0
mxcd.dwControlID = mxc.dwControlID
mxcd.cbStruct = Len(mxcd)
mxcd.cbDetails = Len(vol)
hMem = GlobalAlloc(&H40, Len(vol))
mxcd.paDetails = GlobalLock(hMem)
mxcd.cChannels = 1
<SPAN style="color:green"><SPAN style="color:green">' Get the control</SPAN> value</SPAN>
ret = mixerGetControlDetails(hMixer, mxcd, MIXER_GETCONTROLDETAILSF_VALUE)
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">' Copy the data into the control value buffer</SPAN></SPAN></SPAN>
CopyStructFromPtr vol, mxcd.paDetails, Len(vol)
<SPAN style="color:darkblue">If</SPAN> mxc.lMaximum > 100 <SPAN style="color:darkblue">Then</SPAN>
GetControlValue = (vol.dwValue * 100) / mxc.lMaximum - mxc.lMinimum
<SPAN style="color:darkblue">Else</SPAN>
GetControlValue = vol.dwValue
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
GlobalFree (hMem)
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN></FONT>
________________________________________________________________________
<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> AdjVolume()
<SPAN style="color:darkblue">Dim</SPAN> y <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Boolean</SPAN>, z <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Boolean</SPAN>, a <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, b <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Call</SPAN> OpenMixer(0)
<SPAN style="color:darkblue">Let</SPAN> y = GetMute(SPEAKER_MUTE): <SPAN style="color:darkblue">Let</SPAN> z = GetMute(WAVEOUT_MUTE)
<SPAN style="color:darkblue">Let</SPAN> a = GetVolume(WAVEOUT): <SPAN style="color:darkblue">Let</SPAN> b = GetVolume(Speaker)
<SPAN style="color:darkblue">Call</SPAN> SetMute(SPEAKER_MUTE, <SPAN style="color:darkblue">False</SPAN>): <SPAN style="color:darkblue">Call</SPAN> SetMute(WAVEOUT_MUTE, <SPAN style="color:darkblue">False</SPAN>)
<SPAN style="color:darkblue">Call</SPAN> SetVolume(Speaker, 100): <SPAN style="color:darkblue">Call</SPAN> SetVolume(WAVEOUT, 100)
<SPAN style="color:green">'Play Your Song Here</SPAN>
Application.Wait Now + TimeSerial(0, 0, 5)
<SPAN style="color:green">'Delay before resetting sound settings</SPAN>
<SPAN style="color:darkblue">Call</SPAN> SetMute(SPEAKER_MUTE, y): <SPAN style="color:darkblue">Call</SPAN> SetMute(WAVEOUT_MUTE, z)
<SPAN style="color:darkblue">Call</SPAN> SetVolume(WAVEOUT, a): <SPAN style="color:darkblue">Call</SPAN> SetVolume(Speaker, b)
<SPAN style="color:darkblue">Call</SPAN> CloseMixer
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN>
</FONT>