Advertisement
Ham62

SetWaveInFull.bas

Nov 30th, 2017
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "windows.bi"
  2. #include "win\mmsystem.bi"
  3. #include "crt.bi"
  4. type SimpleDevIDs
  5.     ID as uInteger
  6.     szName as zString * MAXPNAMELEN
  7. end type
  8. Declare Sub OpenMixer()
  9. Declare Sub EnumInputDevices()
  10. Declare Sub SetMuteState(dwMuteState as DWORD)
  11. Declare Sub SetVolume(dwVolumeLevel as DWORD)
  12. Dim shared as HWAVEIN   WaveInHandle 'Handle for wave in device
  13. Dim shared as HMIXER    MixerHandle  'Handle of mixer for wave in device
  14. Dim shared as MIXERLINE mixerLine    'Mixer line info
  15.  
  16. Dim shared as uInteger SelectedDevice = 0
  17. 'Make a list of all avalible devices
  18. Dim shared as uInteger TotalDevs
  19. TotalDevs = waveInGetNumDevs()       'Get number of input devices
  20. Dim shared as SimpleDevIDs DevIDs(TotalDevs-1) 'Create array to store device IDs
  21. EnumInputDevices()
  22.  
  23. OpenMixer()
  24.  
  25. Do
  26.     SetVolume(&HFFFF)
  27.     SetMuteState(0)
  28.     Sleep 1,1
  29. Loop until inkey <> ""
  30.  
  31.  
  32. Sub SetMuteState(dwMuteState as DWORD)
  33.     Dim as MIXERCONTROL                 mixerControl
  34.     Dim as MIXERLINECONTROLS            mixerLineControls
  35.     Dim as MIXERCONTROLDETAILS          mixerControlDetails
  36.     Dim as MIXERCONTROLDETAILS_UNSIGNED value(1)
  37.     Dim as MMRESULT                     result
  38.    
  39.     mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS)
  40.     mixerLineControls.dwLineID = mixerLine.dwLineID
  41.    
  42.     mixerLineControls.cControls = 1 'Only get info for one control
  43.    
  44.     'Check for mute switch
  45.     mixerLineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE
  46.     mixerLineControls.pamxctrl = @mixerControl
  47.    
  48.     mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL)
  49.    
  50.     result = mixerGetLineControls(cast(HMIXEROBJ, MixerHandle), @mixerLineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE)
  51.     if (result <> MMSYSERR_NOERROR) then
  52.         print mixerLine.szName; " has no mute control!"
  53.     else
  54.         mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS)
  55.    
  56.         mixerControlDetails.dwControlID = mixerControl.dwControlID
  57.        
  58.         mixerControlDetails.cChannels = mixerLine.cChannels
  59.         if (mixerControlDetails.cChannels > 2) then mixerControlDetails.cChannels = 2
  60.         if (mixerControl.fdwControl AND MIXERCONTROL_CONTROLF_UNIFORM) then mixerControlDetails.cChannels = 1
  61.        
  62.         mixerControlDetails.cMultipleItems = 0
  63.         mixerControlDetails.paDetails = @value(0)
  64.         mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED)
  65.        
  66.         'Store mute state for both channels
  67.         value(0).dwValue = dwMuteState
  68.         value(1).dwValue = dwMuteState
  69.        
  70.         result = mixerSetControlDetails(cast(HMIXEROBJ, MixerHandle), @mixerControlDetails, MIXER_SETCONTROLDETAILSF_VALUE)
  71.         if (result <> MMSYSERR_NOERROR) then
  72.             print "Error #"; result; " setting mute for "; mixerLine.szName
  73.         end if
  74.     end if
  75. End Sub
  76.  
  77. Sub SetVolume(dwVolumeLevel as DWORD)
  78.     Dim as MIXERCONTROL                 mixerControl
  79.     Dim as MIXERLINECONTROLS            mixerLineControls
  80.     Dim as MIXERCONTROLDETAILS          mixerControlDetails
  81.     Dim as MIXERCONTROLDETAILS_UNSIGNED value(1)
  82.     Dim as MMRESULT                     result
  83.    
  84.     mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS)
  85.     mixerLineControls.dwLineID = mixerLine.dwLineID
  86.    
  87.     mixerLineControls.cControls = 1 'Only get info for one control
  88.    
  89.     'Check for mute switch
  90.     mixerLineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME
  91.     mixerLineControls.pamxctrl = @mixerControl
  92.    
  93.     mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL)
  94.    
  95.     result = mixerGetLineControls(cast(HMIXEROBJ, MixerHandle), @mixerLineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE)
  96.     if (result <> MMSYSERR_NOERROR) then
  97.         print mixerLine.szName; " has no volume control!"
  98.     else
  99.         mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS)
  100.    
  101.         mixerControlDetails.dwControlID = mixerControl.dwControlID
  102.        
  103.         mixerControlDetails.cChannels = mixerLine.cChannels
  104.         if (mixerControlDetails.cChannels > 2) then mixerControlDetails.cChannels = 2
  105.         if (mixerControl.fdwControl AND MIXERCONTROL_CONTROLF_UNIFORM) then mixerControlDetails.cChannels = 1
  106.        
  107.         mixerControlDetails.cMultipleItems = 0
  108.         mixerControlDetails.paDetails = @value(0)
  109.         mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED)
  110.        
  111.         'Store mute state for both channels
  112.         value(0).dwValue = dwVolumeLevel
  113.         value(1).dwValue = dwVolumeLevel
  114.        
  115.         result = mixerSetControlDetails(cast(HMIXEROBJ, MixerHandle), @mixerControlDetails, MIXER_SETCONTROLDETAILSF_VALUE)
  116.         if (result <> MMSYSERR_NOERROR) then
  117.             print "Error #"; result; " setting volume for "; mixerLine.szName
  118.         end if
  119.     end if
  120. End Sub
  121.  
  122. Sub EnumInputDevices()
  123.     Dim as WAVEINCAPS caps
  124.    
  125.     if TotalDevs = 0 then
  126.         print "Error no wave input devices found!"
  127.         sleep: system
  128.         'MessageBox(
  129.     end if
  130.    
  131.     for dev as uInteger = 0 to TotalDevs-1
  132.         Dim as MMRESULT result = waveInGetDevCaps(dev, @caps, sizeof(caps))
  133.        
  134.         if (result <> MMSYSERR_NOERROR) then
  135.             print "waveInGetDevCaps failed: returned 0x"+hex(result)
  136.             sleep: system
  137.         end if
  138.        
  139.         'Store ID and name in array
  140.         DevIDs(dev).ID = dev                     'Store ID
  141.         strcpy(DevIDs(dev).szName, caps.szPname) 'Store name
  142.     next dev
  143. End Sub
  144.  
  145. Sub OpenMixer()
  146.     Dim as integer result
  147.     'Open default input device
  148.     dim as WAVEFORMATEX pwfx
  149.     pwfx.wFormatTag = WAVE_FORMAT_PCM
  150.     pwfx.nChannels = 1
  151.     pwfx.nSamplesPerSec = 8000
  152.     pwfx.wBitsPerSample = 8
  153.     pwfx.nBlockAlign = (pwfx.nChannels * pwfx.wBitsPerSample) \ 8
  154.     pwfx.nAvgBytesPerSec = pwfx.nBlockAlign * pwfx.nSamplesPerSec
  155.     pwfx.cbSize = 0
  156.    
  157.     'Open wave input device
  158.     result = waveInOpen(cast(LPHWAVEIN, @WaveInHandle), SelectedDevice, @pwfx, NULL, NULL, CALLBACK_NULL)
  159.     if (result <> MMSYSERR_NOERROR) then
  160.         print "Error #"; result; " opening wave input device!"
  161.         sleep: system
  162.     end if
  163.    
  164.     'Open mixer for selected input
  165.     result = mixerOpen(@MixerHandle, cast(DWORD, WaveInHandle), 0, 0, MIXER_OBJECTF_HWAVEIN)
  166.     if (result <> MMSYSERR_NOERROR) then
  167.         print "Error #"; result; " opening input mixer!"
  168.         sleep: system
  169.     end if
  170.    
  171.     'Get line info for selected mixer
  172.     mixerLine.cbStruct = sizeof(MIXERLINE)
  173.     mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN
  174.     result = mixerGetLineInfo(cast(HMIXEROBJ, MixerHandle), @mixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE)
  175.     if (result <> MMSYSERR_NOERROR) then
  176.         print "Error #"; result; " reading line recording control!"
  177.         sleep: system
  178.     end if
  179.    
  180.     'Unmute line
  181.     mixerLine.dwSource = mixerLine.dwDestination
  182.     SetMuteState(0)
  183. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement