Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "windows.bi"
- #include "win\mmsystem.bi"
- #include "crt.bi"
- type SimpleDevIDs
- ID as uInteger
- szName as zString * MAXPNAMELEN
- end type
- Declare Sub OpenMixer()
- Declare Sub EnumInputDevices()
- Declare Sub SetMuteState(dwMuteState as DWORD)
- Declare Sub SetVolume(dwVolumeLevel as DWORD)
- Dim shared as HWAVEIN WaveInHandle 'Handle for wave in device
- Dim shared as HMIXER MixerHandle 'Handle of mixer for wave in device
- Dim shared as MIXERLINE mixerLine 'Mixer line info
- Dim shared as uInteger SelectedDevice = 0
- 'Make a list of all avalible devices
- Dim shared as uInteger TotalDevs
- TotalDevs = waveInGetNumDevs() 'Get number of input devices
- Dim shared as SimpleDevIDs DevIDs(TotalDevs-1) 'Create array to store device IDs
- EnumInputDevices()
- OpenMixer()
- Do
- SetVolume(&HFFFF)
- SetMuteState(0)
- Sleep 1,1
- Loop until inkey <> ""
- Sub SetMuteState(dwMuteState as DWORD)
- Dim as MIXERCONTROL mixerControl
- Dim as MIXERLINECONTROLS mixerLineControls
- Dim as MIXERCONTROLDETAILS mixerControlDetails
- Dim as MIXERCONTROLDETAILS_UNSIGNED value(1)
- Dim as MMRESULT result
- mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS)
- mixerLineControls.dwLineID = mixerLine.dwLineID
- mixerLineControls.cControls = 1 'Only get info for one control
- 'Check for mute switch
- mixerLineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE
- mixerLineControls.pamxctrl = @mixerControl
- mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL)
- result = mixerGetLineControls(cast(HMIXEROBJ, MixerHandle), @mixerLineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE)
- if (result <> MMSYSERR_NOERROR) then
- print mixerLine.szName; " has no mute control!"
- else
- mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS)
- mixerControlDetails.dwControlID = mixerControl.dwControlID
- mixerControlDetails.cChannels = mixerLine.cChannels
- if (mixerControlDetails.cChannels > 2) then mixerControlDetails.cChannels = 2
- if (mixerControl.fdwControl AND MIXERCONTROL_CONTROLF_UNIFORM) then mixerControlDetails.cChannels = 1
- mixerControlDetails.cMultipleItems = 0
- mixerControlDetails.paDetails = @value(0)
- mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED)
- 'Store mute state for both channels
- value(0).dwValue = dwMuteState
- value(1).dwValue = dwMuteState
- result = mixerSetControlDetails(cast(HMIXEROBJ, MixerHandle), @mixerControlDetails, MIXER_SETCONTROLDETAILSF_VALUE)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " setting mute for "; mixerLine.szName
- end if
- end if
- End Sub
- Sub SetVolume(dwVolumeLevel as DWORD)
- Dim as MIXERCONTROL mixerControl
- Dim as MIXERLINECONTROLS mixerLineControls
- Dim as MIXERCONTROLDETAILS mixerControlDetails
- Dim as MIXERCONTROLDETAILS_UNSIGNED value(1)
- Dim as MMRESULT result
- mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS)
- mixerLineControls.dwLineID = mixerLine.dwLineID
- mixerLineControls.cControls = 1 'Only get info for one control
- 'Check for mute switch
- mixerLineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME
- mixerLineControls.pamxctrl = @mixerControl
- mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL)
- result = mixerGetLineControls(cast(HMIXEROBJ, MixerHandle), @mixerLineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE)
- if (result <> MMSYSERR_NOERROR) then
- print mixerLine.szName; " has no volume control!"
- else
- mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS)
- mixerControlDetails.dwControlID = mixerControl.dwControlID
- mixerControlDetails.cChannels = mixerLine.cChannels
- if (mixerControlDetails.cChannels > 2) then mixerControlDetails.cChannels = 2
- if (mixerControl.fdwControl AND MIXERCONTROL_CONTROLF_UNIFORM) then mixerControlDetails.cChannels = 1
- mixerControlDetails.cMultipleItems = 0
- mixerControlDetails.paDetails = @value(0)
- mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED)
- 'Store mute state for both channels
- value(0).dwValue = dwVolumeLevel
- value(1).dwValue = dwVolumeLevel
- result = mixerSetControlDetails(cast(HMIXEROBJ, MixerHandle), @mixerControlDetails, MIXER_SETCONTROLDETAILSF_VALUE)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " setting volume for "; mixerLine.szName
- end if
- end if
- End Sub
- Sub EnumInputDevices()
- Dim as WAVEINCAPS caps
- if TotalDevs = 0 then
- print "Error no wave input devices found!"
- sleep: system
- 'MessageBox(
- end if
- for dev as uInteger = 0 to TotalDevs-1
- Dim as MMRESULT result = waveInGetDevCaps(dev, @caps, sizeof(caps))
- if (result <> MMSYSERR_NOERROR) then
- print "waveInGetDevCaps failed: returned 0x"+hex(result)
- sleep: system
- end if
- 'Store ID and name in array
- DevIDs(dev).ID = dev 'Store ID
- strcpy(DevIDs(dev).szName, caps.szPname) 'Store name
- next dev
- End Sub
- Sub OpenMixer()
- Dim as integer result
- 'Open default input device
- dim as WAVEFORMATEX pwfx
- pwfx.wFormatTag = WAVE_FORMAT_PCM
- pwfx.nChannels = 1
- pwfx.nSamplesPerSec = 8000
- pwfx.wBitsPerSample = 8
- pwfx.nBlockAlign = (pwfx.nChannels * pwfx.wBitsPerSample) \ 8
- pwfx.nAvgBytesPerSec = pwfx.nBlockAlign * pwfx.nSamplesPerSec
- pwfx.cbSize = 0
- 'Open wave input device
- result = waveInOpen(cast(LPHWAVEIN, @WaveInHandle), SelectedDevice, @pwfx, NULL, NULL, CALLBACK_NULL)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " opening wave input device!"
- sleep: system
- end if
- 'Open mixer for selected input
- result = mixerOpen(@MixerHandle, cast(DWORD, WaveInHandle), 0, 0, MIXER_OBJECTF_HWAVEIN)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " opening input mixer!"
- sleep: system
- end if
- 'Get line info for selected mixer
- mixerLine.cbStruct = sizeof(MIXERLINE)
- mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN
- result = mixerGetLineInfo(cast(HMIXEROBJ, MixerHandle), @mixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " reading line recording control!"
- sleep: system
- end if
- 'Unmute line
- mixerLine.dwSource = mixerLine.dwDestination
- SetMuteState(0)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement