home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD82587282000.psc / SoundMod.bas < prev   
Encoding:
BASIC Source File  |  2000-07-27  |  56.0 KB  |  903 lines

  1. Attribute VB_Name = "SoundMod"
  2. Public hmixer As Long                      ' mixer handle
  3. Public inputVolCtrl As MIXERCONTROL        ' waveout volume control
  4. Public outputVolCtrl As MIXERCONTROL       ' microphone volume control
  5. Public rc As Long                          ' return code
  6. Public OK As Boolean                       ' boolean return code
  7. Public mxcd As MIXERCONTROLDETAILS         ' control info
  8. Public vol As MIXERCONTROLDETAILS_SIGNED   ' control's signed value
  9. Public volume As Long                      ' volume value
  10. Public volHmem As Long                     ' Volume Buffer
  11.  
  12. Public VolValue As Double
  13.  
  14. ' Frequencies
  15.  
  16. Public Enum Frequency
  17.     Freq60hz = 60
  18.     Freq170hz = 170
  19.     Freq310hz = 310
  20.     Freq600hz = 600
  21.     Freq3khz = 3
  22.     Freq6khz = 6
  23.     Freq12khz = 12
  24.     Freq14khz = 14
  25.     Freq31hz = 32.3
  26.     Freq62hz = 62.5
  27.     Freq125hz = 125
  28.     Freq250hz = 250
  29.     Freq500hz = 500
  30.     Freq1khz = 1
  31.     Freq2khz = 2
  32.     Freq4khz = 4
  33.     Freq8khz = 8
  34.     Freq16khz = 16.1
  35. End Enum
  36.  
  37. ' Volume Unit Display(Number of Display) Values
  38.  
  39. Public Type VULights
  40.     VUOn As Boolean
  41.     InOutLev As Double
  42.     VolLev As Double
  43.     VULev As Double
  44.     VolUnit As Variant
  45.     VUArray As Long
  46.     Freq(0 To 9) As Double
  47.     FreqNum As Integer
  48.     FreqVal As Double
  49. End Type
  50.  
  51. Declare Sub ReleaseCapture Lib "user32" ()
  52. Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  53. Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  54.  
  55. Public Const HWND_TOPMOST = -1
  56. Public Const HWND_NOTOPMOST = -2
  57. '  Sound API┤s
  58. '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  59. Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
  60. Public Declare Function waveOutGetNumDevs Lib "winmm" () As Long
  61.  
  62. Global Const SND_SYNC = &H0 'just after the sound is ended exit function
  63. Global Const SND_ASYNC = &H1 'just after the beginning of the sound exit function
  64. Global Const SND_NODEFAULT = &H2 'if the sound cannot be found no error message
  65. Global Const SND_LOOP = &H8 'repeat the sound until the function is called again
  66. Global Const SND_NOSTOP = &H10 'if currently a sound is played the function will return without playing the selected sound
  67. Global Const Flags& = SND_ASYNC Or SND_NODEFAULT
  68. '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  69.  
  70. Public Const CALLBACK_FUNCTION = &H30000
  71. Public Const MM_WIM_DATA = &H3C0
  72. Public Const WHDR_DONE = &H1         '  done bit
  73. Public Const GMEM_FIXED = &H0         ' Global Memory Flag used by GlobalAlloc functin
  74.  
  75. Type WAVEHDR
  76. ' The WAVEHDR user-defined type defines the header used to identify a waveform-audio buffer.
  77.    lpData As Long          ' Address of the waveform buffer.
  78.    dwBufferLength As Long  ' Length, in bytes, of the buffer.
  79.    dwBytesRecorded As Long ' When the header is used in input, this member specifies how much
  80.                            ' data is in the buffer.
  81.  
  82.    dwUser As Long          ' User data.
  83.    dwFlags As Long         ' Flags supplying information about the buffer. Set equal to zero.
  84.    dwLoops As Long         ' Number of times to play the loop. Set equal to zero.
  85.    lpNext As Long          ' Not used
  86.    Reserved As Long        ' Not used
  87. End Type
  88.  
  89. Type WAVEINCAPS
  90. ' The WAVEINCAPS user-defined variable describes the capabilities of a waveform-audio input
  91. ' device.
  92.    wMid As Integer         ' Manufacturer identifier for the device driver for the
  93.                            ' waveform-audio input device. Manufacturer identifiers
  94.                            ' are defined in Manufacturer and Product Identifiers in
  95.                            ' the Platform SDK product documentation.
  96.    wPid As Integer         ' Product identifier for the waveform-audio input device.
  97.                            ' Product identifiers are defined in Manufacturer and Product
  98.                            ' Identifiers in the Platform SDK product documentation.
  99.    vDriverVersion As Long  ' Version number of the device driver for the
  100.                            ' waveform-audio input device. The high-order byte
  101.                            ' is the major version number, and the low-order byte
  102.                            ' is the minor version number.
  103.    szPname As String * 32  ' Product name in a null-terminated string.
  104.    dwFormats As Long       ' Standard formats that are supported. See the Platform
  105.                            ' SDK product documentation for more information.
  106.    wChannels As Integer    ' Number specifying whether the device supports
  107.                            ' mono (1) or stereo (2) input.
  108. End Type
  109.  
  110. Type WAVEFORMAT
  111. ' The WAVEFORMAT user-defined type describes the format of waveform-audio data. Only
  112. ' format information common to all waveform-audio data formats is included in this
  113. ' user-defined type.
  114.    wFormatTag As Integer      ' Format type. Use the constant WAVE_FORMAT_PCM Waveform-audio data
  115.                               ' to define the data as PCM.
  116.    nChannels As Integer       ' Number of channels in the waveform-audio data. Mono data uses one
  117.                               ' channel and stereo data uses two channels.
  118.    nSamplesPerSec As Long     ' Sample rate, in samples per second.
  119.    nAvgBytesPerSec As Long    ' Required average data transfer rate, in bytes per second. For
  120.                               ' example, 16-bit stereo at 44.1 kHz has an average data rate of
  121.                               ' 176,400 bytes per second (2 channels ù 2 bytes per sample per
  122.                               ' channel ù 44,100 samples per second).
  123.    nBlockAlign As Integer     ' Block alignment, in bytes. The block alignment is the minimum atomic unit of data. For PCM data, the block alignment is the number of bytes used by a single sample, including data for both channels if the data is stereo. For example, the block alignment for 16-bit stereo PCM is 4 bytes (2 channels ù 2 bytes per sample).
  124.    wBitsPerSample As Integer  ' For buffer estimation
  125.    cbSize As Integer          ' Block size of the data.
  126. End Type
  127.  
  128. Declare Function waveInOpen Lib "winmm.dll" (lphWaveIn As Long, _
  129.                                              ByVal uDeviceID As Long, _
  130.                                              lpFormat As WAVEFORMAT, _
  131.                                              ByVal dwCallback As Long, _
  132.                                              ByVal dwInstance As Long, _
  133.                                              ByVal dwFlags As Long) As Long
  134. ' The waveInOpen function opens the given waveform-audio input device for recording. The function
  135. ' uses the following parameters
  136. '     lphWaveIn-  a long value that is the handle identifying the open waveform-audio input
  137. '                 device. Use this handle to identify the device when calling other
  138. '                 waveform-audio input functions. This parameter can be NULL if WAVE_FORMAT_QUERY
  139. '                 is specified for fdwOpen.
  140. '     uDeviceID-  a long value that identifies the waveform-audio input device to open.
  141. '                 This parameter can be either a device identifier or a handle of an open
  142. '                 waveform-audio input device.
  143. '     lpFormat-   the WAVEFORMAT user-defined typed that identifies the desired format for
  144. '                 recording waveform-audio data.
  145. '     dwCallback- a long value that is an event handle, a handle to a window, or the identifier
  146. '                 of a thread to be called during waveform-audio recording to process messages
  147. '                 related to the progress of recording. If no callback function is required,
  148. '                 this value can be zero. For more information on the callback function,
  149. '                 see waveInProc.
  150. '     dwCallback- a long value that is the user-instance data passed to the callback mechanism.
  151. '                 This parameter is not used with the window callback mechanism.
  152. '     dwFlags-    Flags for opening the device. The following values are defined:
  153. '                 CALLBACK_EVENT (&H50000)-event handle.
  154. '                 CALLBACK_FUNCTION (&H30000)-callback procedure address.
  155. '                 CALLBACK_NULL (&H00000)-No callback mechanism. This is the default setting.
  156. '                 CALLBACK_THREAD (&H20000)-thread identifier.
  157. '                 CALLBACK_WINDOW (&H10000)-window handle.
  158. '                 WAVE_FORMAT_DIRECT (&H8)-ACM driver does not perform conversions on the
  159. '                                            audio data.
  160. '                 WAVE_FORMAT_QUERY (&H1)-queries the device to determine whether it supports
  161. '                                         the given format, but it does not open the device.
  162. '                 WAVE_MAPPED (&H4)-The uDeviceID parameter specifies a waveform-audio device
  163. '                                   to be mapped to by the wave mapper.
  164.  
  165. Declare Function waveInPrepareHeader Lib "winmm.dll" (ByVal hWaveIn As Long, _
  166.                                                       lpWaveInHdr As WAVEHDR, _
  167.                                                       ByVal uSize As Long) As Long
  168. ' The waveInPrepareHeader function prepares a buffer for waveform-audio input. The function
  169. ' uses the following parameters:
  170. '     hWaveIn-    a long value that is the handle of the waveform-audio input device.
  171. '     lpWaveInHdr-the WAVEHDR user-defined type variable.
  172. '     uSize-      the size in bytes of the WAVEHDR user-defined type variable. Use the
  173. '                 results of the Len function for this parameter.
  174.  
  175.  
  176. Declare Function waveInReset Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
  177. ' The waveInReset function stops input on the given waveform-audio input device and resets
  178. ' the current position to zero. All pending buffers are marked as done and returned to
  179. ' the application. The function requires the handle to the waveform-audio input device.
  180.  
  181. Declare Function waveInStart Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
  182. ' The waveInStart function starts input on the given waveform-audio input device. The function
  183. ' requires the handle of the waveform-audio input device.
  184.  
  185. Declare Function waveInStop Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
  186. ' The waveInStop function stops waveform-audio input. The function requires the handle of
  187. ' the waveform-audio input device.
  188.  
  189. Declare Function waveInUnprepareHeader Lib "winmm.dll" _
  190.                                           (ByVal hWaveIn As Long, _
  191.                                           lpWaveInHdr As WAVEHDR, _
  192.                                           ByVal uSize As Long) As Long
  193. ' The waveInUnprepareHeader function cleans up the preparation performed by the
  194. ' waveInPrepareHeader function. This function must be called after the device driver
  195. ' fills a buffer and returns it to the application. You must call this function before
  196. ' freeing the buffer. The function uses the following parameters:
  197. '     hWaveIn-       a long value that is the handle of the waveform-audio input device.
  198. '     lpWaveInHdr-   the variable typed as the WAVEHDR user-defined type identifying the
  199. '                    buffer to be cleaned up.
  200. '     uSize-         a long value that is the size in bytes, of the WAVEHDR varaible. Use
  201. '                    the Len function with the WAVEHDR variable as the argument to get this
  202. '                    value.
  203.  
  204. Declare Function waveInClose Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
  205. ' The waveInClose function closes the given waveform-audio input device. The function
  206. ' requires the handle of the waveform-audio input device. If the function succeeds,
  207. ' the handle is no longer valid after this call.
  208.  
  209. Declare Function waveInGetDevCaps Lib "winmm.dll" Alias "waveInGetDevCapsA" _
  210.                   (ByVal uDeviceID As Long, _
  211.                   lpCaps As WAVEINCAPS, _
  212.                   ByVal uSize As Long) As Long
  213. ' This function retrieves the capabilities of a given waveform-audio input device. You can
  214. ' use this function to determine the number of waveform-audio input devices present in the
  215. ' system. If the value specified by the uDeviceID parameter is a device identifier,
  216. ' it can vary from zero to one less than the number of devices present. The function uses
  217. ' the following parameters
  218. '     uDeviceID-     long value that identifies waveform-audio output device. This value can be
  219. '                    either a device identifier or a handle of an open waveform-audio input device.
  220. '     lpCaps-user-   defined variable containing information about the capabilities of the device.
  221. '     uSize-         the size in bytes of the user-defined variable used as the lpCaps parameter.
  222. '                    Use the Len function to get this value.
  223.  
  224. Declare Function waveInGetNumDevs Lib "winmm.dll" () As Long
  225. ' The waveInGetNumDevs function returns the number of waveform-audio input devices present in the system.
  226.  
  227. Declare Function waveInGetErrorText Lib "winmm.dll" Alias "waveInGetErrorTextA" _
  228.                      (ByVal err As Long, _
  229.                      ByVal lpText As String, _
  230.                      ByVal uSize As Long) As Long
  231. 'The waveInGetErrorText function retrieves a textual description of the error identified by
  232. ' the given error number. The function uses the following parameters:
  233. '     Err-     a long value that is the error number.
  234. '     lpText-  a string variable that contains the textual error description.
  235. '     uSize-   the size in characters of the lpText string variable.
  236.  
  237. Declare Function waveInAddBuffer Lib "winmm.dll" (ByVal hWaveIn As Long, _
  238.                                                    lpWaveInHdr As WAVEHDR, _
  239.                                                    ByVal uSize As Long) As Long
  240. ' The waveInAddBuffer function sends an input buffer to the given waveform-audio input device.
  241. ' The function uses the following parameters:
  242. '     hWaveIn-       a long value that is the handle of the waveform-audio input device.
  243. '     lpWaveInHdr-   the variable typed as the WAVEHDR user-defined type.
  244. '     uSize-         a long value that is the size in bytes of the variable typed as the
  245. '                    WAVEHDR user-defined variable. Use the Len function with the WAVEHDR
  246. '                    variable as the argument to get this value.
  247.  
  248.  
  249. Public Const MMSYSERR_NOERROR = 0
  250. Public Const MAXPNAMELEN = 32
  251.  
  252. Public Const MIXER_LONG_NAME_CHARS = 64
  253. Public Const MIXER_SHORT_NAME_CHARS = 16
  254. Public Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
  255. Public Const MIXER_GETCONTROLDETAILSF_VALUE = &H0&
  256. Public Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
  257.  
  258. Public Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
  259. Public Const MIXERLINE_COMPONENTTYPE_SRC_FIRST = &H1000&
  260. Public Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
  261. Public Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3)
  262. Public Const MIXERLINE_COMPONENTTYPE_SRC_LINE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2)
  263.  
  264. Public Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
  265. Public Const MIXERCONTROL_CT_UNITS_UNSIGNED = &H30000
  266. Public Const MIXERCONTROL_CT_UNITS_SIGNED = &H20000
  267. Public Const MIXERCONTROL_CT_CLASS_METER = &H10000000
  268. Public Const MIXERCONTROL_CT_SC_METER_POLLED = &H0&
  269. Public Const MIXERCONTROL_CONTROLTYPE_FADER = (MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
  270. Public Const MIXERCONTROL_CONTROLTYPE_VOLUME = (MIXERCONTROL_CONTROLTYPE_FADER + 1)
  271. Public Const MIXERLINE_COMPONENTTYPE_DST_WAVEIN = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 7)
  272. Public Const MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 8)
  273. Public Const MIXERCONTROL_CONTROLTYPE_SIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_SIGNED)
  274. Public Const MIXERCONTROL_CONTROLTYPE_PEAKMETER = (MIXERCONTROL_CONTROLTYPE_SIGNEDMETER + 1)
  275.  
  276. Declare Function mixerClose Lib "winmm.dll" (ByVal hmx As Long) As Long
  277. ' The mixerClose function closes the specified mixer device. The function requires the
  278. ' handle of the mixer device. This handle must have been returned successfully by the
  279. ' mixerOpen function. If mixerClose is successful, the handle is no longer valid.
  280.  
  281. Declare Function mixerGetControlDetails Lib "winmm.dll" Alias "mixerGetControlDetailsA" _
  282.             (ByVal hmxobj As Long, _
  283.             pMxcd As MIXERCONTROLDETAILS, _
  284.             ByVal fdwDetails As Long) As Long
  285. ' The mixerGetControlDetails function retrieves details about a single control associated
  286. ' with an audio line. the function uses the following parameters:
  287. '     hmxobj-     a long value that is the handle to the mixer device object being queried.
  288. '     pMxcd-      the variable defined as the MIXERCONTROLDETAILS user-defined type.
  289. '     fdwDetails- Flags for retrieving control details. The following values are defined:
  290. '                    MIXER_GETCONTROLDETAILSF_LISTTEXT-The paDetails member of the
  291. '                       MIXERCONTROLDETAILS user-defined variable points to one or more
  292. '                       MIXERCONTROLDETAILS_LISTTEXT user-defined variables to receive text
  293. '                       Displays for multiple-item controls. An application must get all list
  294. '                       text items for a multiple-item control at once. This flag cannot be
  295. '                       used with MIXERCONTROL_CONTROLTYPE_CUSTOM controls.
  296. '                    MIXER_GETCONTROLDETAILSF_VALUE-Current values for a control are
  297. '                       retrieved. The paDetails member of the MIXERCONTROLDETAILS user-defined
  298. '                       variable points to one or more details appropriate for the control class.
  299. '                    MIXER_OBJECTF_AUX (&H50000000)-The hmxobj parameter is an auxiliary device
  300. '                       identifier in the range of zero to one less than the number of devices
  301. '                       returned by the auxGetNumDevs function.
  302. '                    MIXER_OBJECTF_HMIDIIN (MIXER_OBJECTF_HANDLE or MIXER_OBJECTF_MIDIIN)-
  303. '                       The hmxobj parameter is the handle of a MIDI (Musical Instrument Digital
  304. '                       Interface) input device. This handle must have been returned by the
  305. '                       midiInOpen function.
  306. '                    MIXER_OBJECTF_HMIDIOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)-The
  307. '                       hmxobj parameter is the handle of a MIDI output device. This handle must
  308. '                       have been returned by the midiOutOpen function.
  309. '                    MIXER_OBJECTF_HMIXER (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)-The
  310. '                       hmxobj parameter is a mixer device handle returned by the mixerOpen
  311. '                       function. This flag is optional.
  312. '                    MIXER_OBJECTF_HWAVEIN (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)-The
  313. '                       hmxobj parameter is a waveform-audio input handle returned by the
  314. '                       waveInOpen function.
  315. '                    MIXER_OBJECTF_HWAVEOUT ((MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)-The
  316. '                       hmxobj parameter is a waveform-audio output handle returned by the
  317. '                       waveOutOpen function.
  318. '                    MIXER_OBJECTF_MIDIIN (&H40000000L)-The hmxobj parameter is the identifier
  319. '                       of a MIDI input device. This identifier must be in the range of zero to
  320. '                       one less than the number of devices returned by the midiInGetNumDevs
  321. '                       function.
  322. '                    MIXER_OBJECTF_MIDIOUT (&H30000000)-The hmxobj parameter is the identifier
  323. '                       of a MIDI output device. This identifier must be in the range of zero
  324. '                       to one less than the number of devices returned by the midiOutGetNumDevs
  325. '                       function.
  326. '                    MIXER_OBJECTF_MIXER (&H00000000)-The hmxobj parameter is the identifier of a
  327. '                       mixer device in the range of zero to one less than the number of devices
  328. '                       returned by the mixerGetNumDevs function. This flag is optional.
  329. '                    MIXER_OBJECTF_WAVEIN (&H20000000)-The hmxobj parameter is the identifier of a
  330. '                       waveform-audio input device in the range of zero to one less than the
  331. '                       number of devices returned by the waveInGetNumDevs function.
  332. '                    MIXER_OBJECTF_WAVEOUT (&H10000000)-The hmxobj parameter is the identifier of a
  333. '                       waveform-audio output device in the range of zero to one less than the
  334. '                       number of devices returned by the waveOutGetNumDevs function.
  335.  
  336. Declare Function mixerGetDevCaps Lib "winmm.dll" Alias "mixerGetDevCapsA" _
  337.                   (ByVal uMxId As Long, _
  338.                   ByVal pmxcaps As MIXERCAPS, _
  339.                   ByVal cbmxcaps As Long) As Long
  340. ' The mixerGetDevCaps function queries a specified mixer device to determine its capabilities.
  341. ' The function uses the following parameters:
  342. '     uMxId-      a long value that is the handle of an open mixer device.
  343. '     pmxcaps-    a variable defined as the MIXERCAPS user-defined type to contain information
  344. '                 about the capabilities of the device.
  345. '     cbmxcaps-   a long value that is the size in bytes, of the variable defined as the
  346. '                 MIXERCAPS user-defined type. Use the Len functions with the MIXERCAPS variable
  347. '                 as the argument to get this value.
  348.  
  349. Declare Function mixerGetID Lib "winmm.dll" (ByVal hmxobj As Long, _
  350.                                              pumxID As Long, _
  351.                                              ByVal fdwId As Long) As Long
  352. ' The mixerGetID function retrieves the device identifier for a mixer device associated
  353. ' with a specified device handle.The function uses the following parameters:
  354. '     hmxobj-  a long value that is the handle of the audio mixer object to map to a
  355. '              mixer device identifier.
  356. '     pumxID-  the long value to contain the mixer device identifier. If no mixer device
  357. '              is available for the hmxobj object, the value û 1 is placed in this location
  358. '              and the MMSYSERR_NODRIVER error value is returned.
  359. '     fdwId-   Flags for mapping the mixer object hmxobj. The following values are defined:
  360. '                 MIXER_OBJECTF_AUX (&H50000000)-The hmxobj parameter is an auxiliary device
  361. '                       identifier in the range of zero to one less than the number of devices
  362. '                       returned by the auxGetNumDevs function.
  363. '                 MIXER_OBJECTF_HMIDIIN (MIXER_OBJECTF_HANDLE or MIXER_OBJECTF_MIDIIN)-
  364. '                       the hmxobj parameter is the handle of a MIDI input device. This handle
  365. '                       must have been returned by the midiInOpen function.
  366. '                 MIXER_OBJECTF_HMIDIOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)-The
  367. '                       hmxobj parameter is the handle of a MIDI output device. This handle must
  368. '                       have been returned by the midiOutOpen function.
  369. '                 MIXER_OBJECTF_HMIXER (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)-The hmxobj
  370. '                       parameter is a mixer device handle returned by the mixerOpen function.
  371. '                       This flag is optional.
  372. '                 MIXER_OBJECTF_HWAVEIN (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)-The
  373. '                       hmxobj parameter is a waveform-audio input handle returned by the
  374. '                       waveInOpen function.
  375. '                 MIXER_OBJECTF_HWAVEOUT ((MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)-The
  376. '                       hmxobj parameter is a waveform-audio output handle returned by the
  377. '                       waveOutOpen function.
  378. '                 MIXER_OBJECTF_MIDIIN (&H40000000L)-The hmxobj parameter is the identifier of
  379. '                       a MIDI input device. This identifier must be in the range of zero to
  380. '                       one less than the number of devices returned by the midiInGetNumDevs
  381. '                       function.
  382. '                 MIXER_OBJECTF_MIDIOUT (&H30000000)-The hmxobj parameter is the identifier of
  383. '                       a MIDI output device. This identifier must be in the range of zero to
  384. '                       one less than the number of devices returned by the midiOutGetNumDevs
  385. '                       function.
  386. '                 MIXER_OBJECTF_MIXER (&H00000000)-The hmxobj parameter is the identifier of
  387. '                       a mixer device in the range of zero to one less than the number of
  388. '                       devices returned by the mixerGetNumDevs function. This flag is optional.
  389. '                 MIXER_OBJECTF_WAVEIN (&H20000000)-The hmxobj parameter is the identifier of a
  390. '                       waveform-audio input device in the range of zero to one less than the
  391. '                       number of devices returned by the waveInGetNumDevs function.
  392. '                 MIXER_OBJECTF_WAVEOUT (&H10000000)-The hmxobj parameter is the identifier of a
  393. '                       waveform-audio output device in the range of zero to one less than the
  394. '                       number of devices returned by the waveOutGetNumDevs function.
  395.  
  396. Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" _
  397.                   (ByVal hmxobj As Long, _
  398.                   pmxlc As MIXERLINECONTROLS, _
  399.                   ByVal fdwControls As Long) As Long
  400. ' The mixerGetLineControls function retrieves one or more controls associated with an audio
  401. ' line. The function uses the following parameters:
  402. '     hmxobj-        a long value that is the handle of the mixer device object that is being
  403. '                    queried.
  404. '     pmxlc-         the variable defined as the MIXERLINECONTROLS user-defined type used to
  405. '                    reference one or more variables defined as theMIXERCONTROL user-defined
  406. '                    types to be filled with information about the controls associated with
  407. '                    an audio line. The cbStruct member of the MIXERLINECONTROLS variable
  408. '                    must always be initialized to be the size, in bytes, of the
  409. '                    MIXERLINECONTROLS variable.
  410. '     fdwControls-   Flags for retrieving information about one or more controls associated w
  411. '                    with an audio line. The following values are defined:
  412. '                    MIXER_GETLINECONTROLSF_ALL-The pmxlc parameter references a list of
  413. '                       MIXERCONTROL variables that will receive information on all controls
  414. '                       associated with the audio line identified by the dwLineID member of
  415. '                       the MIXERLINECONTROLS structure. The cControls member must be initialized
  416. '                       to the number of controls associated with the line. This number is
  417. '                       retrieved from the cControls member of the MIXERLINE structure returned
  418. '                       by the mixerGetLineInfo function. The cbmxctrl member must be
  419. '                       initialized to the size, in bytes, of a single MIXERCONTROL variable.
  420. '                       The pamxctrl member must point to the first MIXERCONTROL variable to be
  421. '                       filled. The dwControlID and dwControlType members are ignored for this
  422. '                       query.
  423. '                    MIXER_GETLINECONTROLSF_ONEBYID-The pmxlc parameter references a single
  424. '                       MIXERCONTROL variable that will receive information on the control
  425. '                       identified by the dwControlID member of the MIXERLINECONTROLS variable.
  426. '                       The cControls member must be initialized to 1. The cbmxctrl member must
  427. '                       be initialized to the size, in bytes, of a single MIXERCONTROL variable.
  428. '                       The pamxctrl member must point to a MIXERCONTROL structure to be filled.
  429. '                       The dwLineID and dwControlType members are ignored for this query. This
  430. '                       query is usually used to refresh a control after receiving a
  431. '                       MM_MIXM_CONTROL_CHANGE control change notification message by the
  432. '                       user-defined callback (see mixerOpen).
  433. '                    MIXER_GETLINECONTROLSF_ONEBYTYPE-The mixerGetLineControls function
  434. '                       retrieves information about the first control of a specific class for
  435. '                       the audio line that is being queried. The pmxlc parameter references a
  436. '                       single MIXERCONTROL structure that will receive information about the
  437. '                       specific control. The audio line is identified by the dwLineID member.
  438. '                       The control class is specified in the dwControlType member of the
  439. '                       MIXERLINECONTROLS variable. The dwControlID member is ignored for this
  440. '                       query. This query can be used by an application to get information on
  441. '                       a single control associated with a line. For example, you might want
  442. '                       your application to use a peak meter only from a waveform-audio output
  443. '                       line.
  444. '                    MIXER_OBJECTF_AUX (&H50000000)-The hmxobj parameter is an auxiliary device
  445. '                       identifier in the range of zero to one less than the number of devices
  446. '                       returned by the auxGetNumDevs function.
  447. '                    MIXER_OBJECTF_HMIDIIN (MIXER_OBJECTF_HANDLE or MIXER_OBJECTF_MIDIIN)-The
  448. '                       hmxobj parameter is the handle of a MIDI input device. This handle must
  449. '                       have been returned by the midiInOpen function.
  450. '                    MIXER_OBJECTF_HMIDIOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)-The
  451. '                       hmxobj parameter is the handle of a MIDI output device. This handle must
  452. '                       have been returned by the midiOutOpen function.
  453. '                    MIXER_OBJECTF_HMIXER (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)-The
  454. '                       hmxobj parameter is a mixer device handle returned by the mixerOpen
  455. '                       function. This flag is optional.
  456. '                    MIXER_OBJECTF_HWAVEIN (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)-The
  457. '                       hmxobj parameter is a waveform-audio input handle returned by the
  458. '                       waveInOpen function.
  459. '                    MIXER_OBJECTF_HWAVEOUT ((MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)-The
  460. '                       hmxobj parameter is a waveform-audio output handle returned by the
  461. '                       waveOutOpen function.
  462. '                    MIXER_OBJECTF_MIDIIN (&H40000000L)-The hmxobj parameter is the identifier of
  463. '                       a MIDI input device. This identifier must be in the range of zero to one
  464. '                       less than the number of devices returned by the midiInGetNumDevs function.
  465. '                    MIXER_OBJECTF_MIDIOUT (&H30000000)-The hmxobj parameter is the identifier of
  466. '                       a MIDI output device. This identifier must be in the range of zero to one
  467. '                       less than the number of devices returned by the midiOutGetNumDevs function.
  468. '                    MIXER_OBJECTF_MIXER (&H00000000)-The hmxobj parameter is the identifier of a
  469. '                       mixer device in the range of zero to one less than the number of devices
  470. '                       returned by the mixerGetNumDevs function. This flag is optional.
  471. '                    MIXER_OBJECTF_WAVEIN (&H20000000)-The hmxobj parameter is the identifier of a
  472. '                       waveform-audio input device in the range of zero to one less than the
  473. '                       number of devices returned by the waveInGetNumDevs function.
  474. '                    MIXER_OBJECTF_WAVEOUT (&H10000000)-The hmxobj parameter is the identifier of a
  475. '                       waveform-audio output device in the range of zero to one less than the
  476. '                       number of devices returned by the waveOutGetNumDevs function.
  477.  
  478. Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" _
  479.                      (ByVal hmxobj As Long, _
  480.                      pmxl As MIXERLINE, _
  481.                      ByVal fdwInfo As Long) As Long
  482. ' The mixerGetLineInfo function retrieves information about a specific line of a mixer device.
  483. ' Uses the same parameters and constants as the mixerGetLineControls function.
  484.  
  485. Declare Function mixerGetNumDevs Lib "winmm.dll" () As Long
  486. ' The mixerGetNumDevs function retrieves the number of mixer devices present in the system.
  487.  
  488. Declare Function mixerMessage Lib "winmm.dll" (ByVal hmx As Long, _
  489.                                                 ByVal uMsg As Long, _
  490.                                                 ByVal dwParam1 As Long, _
  491.                                                 ByVal dwParam2 As Long) As Long
  492. ' The mixerMessage function sends a custom mixer driver message directly to a mixer driver.
  493. ' The function uses the following parameters:
  494. '     hmx-     a long value that is the handle of an open instance of a mixer device. This
  495. '              value is the result of the mixerOpen function.
  496. '     uMsg-    Custom mixer driver message to send to the mixer driver. This message must
  497. '              be above or equal to the MXDM_USER constant.
  498. '     dwParam1 and dwParam2-Arguments associated with the message being sent.
  499.  
  500. Declare Function mixerOpen Lib "winmm.dll" (phmx As Long, _
  501.                                              ByVal uMxId As Long, _
  502.                                              ByVal dwCallback As Long, _
  503.                                              ByVal dwInstance As Long, _
  504.                                              ByVal fdwOpen As Long) As Long
  505. ' The mixerOpen function opens a specified mixer device and ensures that the device will
  506. ' not be removed until the application closes the handle. the function uses the following
  507. ' parameters:
  508. '     phmx-       a long value that is the handle identifying the opened mixer device. Use
  509. '                 this handle to identify the device when calling other audio mixer functions.
  510. '                 This parameter cannot be NULL.
  511. '     uMxId-      a long value that identifies the mixer device to open. Use a valid device
  512. '                 identifier or any HMIXEROBJ (see the mixerGetID function for a description of
  513. '                 mixer object handles). A "mapper" for audio mixer devices does not currently
  514. '                 exist, so a mixer device identifier of û 1 is not valid.
  515. '     dwCallback- Handle of a window called when the state of an audio line and/or control
  516. '                 associated with the device being opened is changed. Specify zero for this
  517. '                 parameter if no callback mechanism is to be used.
  518. '     dwInstance- User instance data passed to the callback function. This parameter is not
  519. '                 used with window callback functions.
  520. '     fdwOpen-    Flags for opening the device. The following values are defined:
  521. '                    CALLBACK_WINDOW-  The dwCallback parameter is assumed to be a window handle.
  522. '                    MIXER_OBJECTF_AUX (&H50000000)-The uMxId parameter is an auxiliary device
  523. '                       identifier in the range of zero to one less than the number of devices
  524. '                       returned by the auxGetNumDevs function.
  525. '                    MIXER_OBJECTF_HMIDIIN (MIXER_OBJECTF_HANDLE or MIXER_OBJECTF_MIDIIN)-the
  526. '                       uMxId parameter is the handle of a MIDI input device. This handle must
  527. '                       have been returned by the midiInOpen function.
  528. '                    MIXER_OBJECTF_HMIDIOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)-The
  529. '                       uMxId parameter is the handle of a MIDI output device. This handle must
  530. '                       have been returned by the midiOutOpen function.
  531. '                    MIXER_OBJECTF_HMIXER (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)-The uMxId
  532. '                       parameter is a mixer device handle returned by the mixerOpen function.
  533. '                       This flag is optional.
  534. '                    MIXER_OBJECTF_HWAVEIN (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)-The
  535. '                       uMxId parameter is a waveform-audio input handle returned by the
  536. '                       waveInOpen function.
  537. '                    MIXER_OBJECTF_HWAVEOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)-The
  538. '                       uMxId parameter is a waveform-audio output handle returned by the
  539. '                       waveOutOpen function.
  540. '                    MIXER_OBJECTF_MIDIIN (&H40000000)-The uMxId parameter is the identifier of
  541. '                       a MIDI input device. This identifier must be in the range of zero to one
  542. '                       less than the number of devices returned by the midiInGetNumDevs function.
  543. '                    MIXER_OBJECTF_MIDIOUT (&H30000000)-The uMxId parameter is the identifier of
  544. '                       a MIDI output device. This identifier must be in the range of zero to one
  545. '                       less than the number of devices returned by the midiOutGetNumDevs function.
  546. '                    MIXER_OBJECTF_MIXER (&H00000000)-The uMxId parameter is a mixer device
  547. '                       identifier in the range of zero to one less than the number of devices
  548. '                       returned by the mixerGetNumDevs function. This flag is optional.
  549. '                    MIXER_OBJECTF_WAVEIN (&H20000000)-The uMxId parameter is the identifier of a
  550. '                       waveform-audio input device in the range of zero to one less than the
  551. '                       number of devices returned by the waveInGetNumDevs function.
  552. '                    MIXER_OBJECTF_WAVEOUT (&H10000000)-The uMxId parameter is the identifier of a
  553. '                       waveform-audio output device in the range of zero to one less than the
  554. '                       number of devices returned by the waveOutGetNumDevs function.
  555.  
  556. Declare Function mixerSetControlDetails Lib "winmm.dll" _
  557.          (ByVal hmxobj As Long, _
  558.          pMxcd As MIXERCONTROLDETAILS, _
  559.          ByVal fdwDetails As Long) As Long
  560. ' The mixerSetControlDetails function sets properties of a single control associated with an
  561. ' audio line. The function uses the following parameters
  562. '     hmxobj-        a long value that is the handle of the mixer device object for which
  563. '                    properties are being set.
  564. '     pMxcd-         the variable declares as the MIXERCONTROLDETAILS user-defined type.
  565. '                    This variable references the control detail structures that contain the
  566. '                    desired state for the control.
  567. '     fdwDetails-    Flags for setting properties for a control. The following values are
  568. '                    defined:
  569. '                    MIXER_OBJECTF_AUX (&H50000000)-The hmxobj parameter is an auxiliary device
  570. '                       identifier in the range of zero to one less than the number of devices
  571. '                       returned by the auxGetNumDevs function.
  572. '                    MIXER_OBJECTF_HMIDIIN (MIXER_OBJECTF_HANDLE or MIXER_OBJECTF_MIDIIN)-
  573. '                       The hmxobj parameter is the handle of a MIDI input device. This handle
  574. '                       must have been returned by the midiInOpen function.
  575. '                    MIXER_OBJECTF_HMIDIOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)-The
  576. '                       hmxobj parameter is the handle of a MIDI output device. This handle must
  577. '                       have been returned by the midiOutOpen function.
  578. '                    MIXER_OBJECTF_HMIXER (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)-The hmxobj
  579. '                       parameter is a mixer device handle returned by the mixerOpen function.
  580. '                       This flag is optional.
  581. '                    MIXER_OBJECTF_HWAVEIN (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)-The
  582. '                       hmxobj parameter is a waveform-audio input handle returned by the
  583. '                       waveInOpen function.
  584. '                    MIXER_OBJECTF_HWAVEOUT ((MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)-The
  585. '                       hmxobj parameter is a waveform-audio output handle returned by the
  586. '                       waveOutOpen function.
  587. '                    MIXER_OBJECTF_MIDIIN (&H40000000)-The hmxobj parameter is the identifier
  588. '                       of a MIDI inputdevice. This identifier must be in the range of zero to
  589. '                        one less than the number of devices returned by the midiInGetNumDevs
  590. '                        function.
  591. '                    MIXER_OBJECTF_MIDIOUT (&H30000000)-The hmxobj parameter is the identifier
  592. '                       of a MIDI output device. This identifier must be in the range of zero
  593. '                       to one less than the number of devices returned by the midiOutGetNumDevs
  594. '                       function.
  595. '                    MIXER_OBJECTF_MIXER (&H00000000)-The hmxobj parameter is a mixer device
  596. '                       identifier in the range of zero to one less than the number of devices
  597. '                       returned by the mixerGetNumDevs function. This flag is optional.
  598. '                    MIXER_OBJECTF_WAVEIN (&H20000000)-The hmxobj parameter is the identifier of a
  599. '                       waveform-audio input device in the range of zero to one less than the
  600. '                       number of devices returned by the waveInGetNumDevs function.
  601. '                    MIXER_OBJECTF_WAVEOUT (&H10000000)-The hmxobj parameter is the identifier of a
  602. '                       waveform-audio output device in the range of zero to one less than the
  603. '                       number of devices returned by the waveOutGetNumDevs function.
  604. '                    MIXER_SETCONTROLDETAILSF_CUSTOM-A custom dialog box for the specified
  605. '                       custom mixer control is displayed. The mixer device gathers the required
  606. '                       information from the user and returns the data in the specified buffer.
  607. '                       The handle for the owning window is specified in the hwndOwner member
  608. '                       of the MIXERCONTROLDETAILS structure. (This handle can be set to NULL.)
  609. '                       The application can then save the data from the dialog box and use it
  610. '                       later to reset the control to the same state by using the
  611. '                       MIXER_SETCONTROLDETAILSF_VALUE flag.
  612. '                    MIXER_SETCONTROLDETAILSF_VALUE (&H00000000)-The current value(s) for a control
  613. '                       are set. The paDetails member of the MIXERCONTROLDETAILS structure points
  614. '                       to one or more mixer-control details structures of the appropriate class for
  615. '                       the control.
  616.  
  617. Declare Sub CopyStructFromPtr Lib "kernel32" Alias "RtlMoveMemory" (struct As Any, ByVal ptr As Long, ByVal cb As Long)
  618. Declare Sub CopyPtrFromStruct Lib "kernel32" Alias "RtlMoveMemory" (ByVal ptr As Long, struct As Any, ByVal cb As Long)
  619. ' The CopyStructFromPtr and CopyPtrFromStruct functions are user-defined versions of the
  620. ' RtlMoveMemory function. RtlMoveMemory moves memory either forward or backward, aligned or
  621. ' unaligned, in 4-byte blocks, followed by any remaining bytes. The function requires the
  622. ' following parameters:
  623. '     Destination-   Pointer to the starting address of the copied block's destination.
  624. '     Source-        Pointer to the starting address of the block of memory to copy.
  625. '     Length-        Specifies the size, in bytes, of the block of memory to copy.
  626.  
  627. Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
  628.                                              ByVal dwBytes As Long) As Long
  629. ' The GlobalAlloc function allocates the specified number of bytes from the heap.
  630. ' Win32 memory management does not provide a separate local heap and global heap.
  631. ' This function is provided only for compatibility with 16-bit versions of Windows. The function
  632. ' uses the following parameters:
  633. '     wFlags-     a long value that specifies how to allocate memory. If zero is specified,
  634. '                 the default is allocate fixed memory. This value can be one or more of the
  635. '                 following flags:
  636. '                    GMEM_FIXED (&H0)- Allocates fixed memory. The return value is a pointer.
  637. '                    GMEM_MOVEABLE (&H2)- Allocates movable memory. In Win32, memory blocks are
  638. '                       never moved in physical memory, but they can be moved within the default .
  639. '                       The return value is the handle of the memory object. To translate the
  640. '                       heap handle into a pointer, use the GlobalLock function. This flag
  641. '                       cannot be combined with the GMEM_FIXED flag.
  642. '                    GPTR (GMEM_FIXED Or GMEM_ZEROINIT)-Combines the GMEM_FIXED and GMEM_ZEROINIT
  643. '                       flags.
  644. '                    GHND (GMEM_MOVEABLE Or GMEM_ZEROINIT)- Combines the GMEM_MOVEABLE and
  645. '                       GMEM_ZEROINIT flags.
  646. '                    GMEM_ZEROINIT (&H4)-Initializes memory contents to zero.
  647. '     dwBytes-    Specifies the number of bytes to allocate. If this parameter is zero and
  648. '                 the uFlags parameter specifies the GMEM_MOVEABLE flag, the function returns
  649. '                 a handle to a memory object that is marked as discarded.
  650.  
  651. Declare Function GlobalLock Lib "kernel32" (ByVal hmem As Long) As Long
  652. ' The GlobalLock function locks a global memory object and returns a pointer to the first
  653. ' byte of the object's memory block. This function is provided only for compatibility with
  654. ' 16-bit versions of Windows. The function requires a handle to the global memory object. This
  655. ' handle is returned by either the GlobalAlloc or GlobalReAlloc function.
  656.  
  657. Declare Function GlobalFree Lib "kernel32" (ByVal hmem As Long) As Long
  658. ' The GlobalFree function frees the specified global memory object and invalidates its handle.
  659. ' This function is provided only for compatibility with 16-bit versions of Windows. The function
  660. ' requires a h andle to the global memory object. This handle is returned by either the
  661. ' GlobalAlloc or GlobalReAlloc function.
  662.  
  663. Type MIXERCAPS
  664. ' The MIXERCAPS user-defined type contains information about the capabilites of the mixer device.
  665.    wMid As Integer                   '  manufacturer id
  666.    wPid As Integer                   '  product id
  667.    vDriverVersion As Long            '  version of the driver
  668.    szPname As String * MAXPNAMELEN   '  product name
  669.    fdwSupport As Long                '  misc. support bits
  670.    cDestinations As Long             '  count of destinations
  671. End Type
  672.  
  673. Type MIXERCONTROL
  674. ' The MIXERCONTROL user-defined type contains the state and metrics of a single control
  675. ' for an audio line.
  676.    cbStruct As Long           '  size in Byte of MIXERCONTROL
  677.    dwControlID As Long        '  unique control id for mixer device
  678.    dwControlType As Long      '  MIXERCONTROL_CONTROLTYPE_xxx
  679.    fdwControl As Long         '  MIXERCONTROL_CONTROLF_xxx
  680.    cMultipleItems As Long     '  if MIXERCONTROL_CONTROLF_MULTIPLE set
  681.    szShortName As String * MIXER_SHORT_NAME_CHARS  ' short name of control
  682.    szName As String * MIXER_LONG_NAME_CHARS        ' long name of control
  683.    lMinimum As Long           '  Minimum value
  684.    lMaximum As Long           '  Maximum value
  685.    Reserved(10) As Long       '  reserved structure space
  686. End Type
  687.  
  688. Type MIXERCONTROLDETAILS
  689. ' The MIXERCONTROLDETAILS user defined type refers to control-detail structures,
  690. ' retrieving or setting state information of an audio mixer control. All members of this
  691. ' user-defined type must be initialized before calling the mixerGetControlDetails and
  692. ' mixerSetControlDetails functions.
  693.    cbStruct As Long       '  size in Byte of MIXERCONTROLDETAILS
  694.    dwControlID As Long    '  control id to get/set details on
  695.    cChannels As Long      '  number of channels in paDetails array
  696.    item As Long           '  hwndOwner or cMultipleItems
  697.    cbDetails As Long      '  size of _one_ details_XX struct
  698.    paDetails As Long      '  pointer to array of details_XX structs
  699. End Type
  700.  
  701. Type MIXERCONTROLDETAILS_SIGNED
  702. ' The MIXERCONTROLDETAILS_SIGNED user-defined type retrieves and sets signed type control
  703. ' properties for an audio mixer control.
  704.    lValue As Long
  705. End Type
  706.  
  707. Type MIXERLINE
  708. ' The MIXERLINE user-defined type describes the state and metrics of an audio line.
  709.    cbStruct As Long        ' Size of MIXERLINE structure
  710.    dwDestination As Long   ' Zero based destination index
  711.    dwSource As Long        ' Zero based source index (if source)
  712.    dwLineID As Long        ' Unique line id for mixer device
  713.    fdwLine As Long         ' State/information about line
  714.    dwUser As Long          ' Driver specific information
  715.    dwComponentType As Long ' Component type for this audio line.
  716.    cChannels As Long       ' Maximum number of separate channels that can be
  717.                            ' manipulated independently for the audio line.
  718.    cConnections As Long    ' Number of connections that are associated with the
  719.                            ' audio line.
  720.    cControls As Long       ' Number of controls associated with the audio line.
  721.    szShortName As String * MIXER_SHORT_NAME_CHARS  ' Short string that describes
  722.                                                    ' the audio mixer line specified
  723.                                                    ' in the dwLineID member.
  724.    szName As String * MIXER_LONG_NAME_CHARS  ' String that describes the audio
  725.                                              ' mixer line specified in the dwLineID
  726.                                              ' member. This description should be
  727.                                              ' appropriate as a complete description
  728.                                              ' for the line.
  729.    dwType As Long          ' Target media device type associated with the audio
  730.                            ' line described in the MIXERLINE structure.
  731.    dwDeviceID As Long      ' Current device identifier of the target media device
  732.                            ' when the dwType member is a target type other than
  733.                            ' MIXERLINE_TARGETTYPE_UNDEFINED.
  734.    wMid  As Integer        ' Manufacturer identifier of the target media device
  735.                            ' when the dwType member is a target type other than
  736.                            ' MIXERLINE_TARGETTYPE_UNDEFINED.
  737.    wPid As Integer         ' Product identifier of the target media device when
  738.                            ' the dwType member is a target type other than
  739.                            ' MIXERLINE_TARGETTYPE_UNDEFINED.
  740.    vDriverVersion As Long  ' Driver version of the target media device when the
  741.                            ' dwType member is a target type other than
  742.                            ' MIXERLINE_TARGETTYPE_UNDEFINED.
  743.    szPname As String * MAXPNAMELEN  ' Product name of the target media device when
  744.                                     ' the dwType member is a target type other than
  745.                                     ' MIXERLINE_TARGETTYPE_UNDEFINED.
  746. End Type
  747.  
  748. Type MIXERLINECONTROLS
  749. ' The MIXERLINECONTROLS user-defined type contains information about the controls
  750. ' of an audio line.
  751.    cbStruct As Long     ' size in Byte of MIXERLINECONTROLS
  752.    dwLineID As Long     ' Line identifier for which controls are being queried.
  753.    dwControl As Long    ' Control identifier of the desired control
  754.    cControls As Long    ' Number of MIXERCONTROL structure elements to retrieve.
  755.    cbmxctrl As Long     ' Size, in bytes, of a single MIXERCONTROL structure.
  756.    pamxctrl As Long     ' Address of one or more MIXERCONTROL structures to receive
  757.                         '  the properties of the requested audio line controls.
  758. End Type
  759.  
  760. Public i As Integer
  761. Public j As Integer
  762. 'Public rc As Long
  763. Public msg As String * 200
  764. Public hWaveIn As Long
  765. Public format As WAVEFORMAT
  766.  
  767. Public Const NUM_BUFFERS = 2
  768. Public Const BUFFER_SIZE = 8192
  769. Public Const DEVICEID = 0
  770. Public hmem(NUM_BUFFERS) As Long
  771. Public inHdr(NUM_BUFFERS) As WAVEHDR
  772.  
  773. Public fRecording As Boolean
  774.  
  775. Function GetControl(ByVal hmixer As Long, ByVal componentType As Long, ByVal ctrlType As Long, ByRef mxc As MIXERCONTROL) As Boolean
  776. ' This function attempts to obtain a mixer control. Returns True if successful.
  777.  
  778.    Dim mxlc As MIXERLINECONTROLS
  779.    Dim mxl As MIXERLINE
  780.    Dim hmem As Long
  781.    Dim rc As Long
  782.        
  783.    mxl.cbStruct = Len(mxl)
  784.    mxl.dwComponentType = componentType
  785.    
  786.    ' Obtain a line corresponding to the component type
  787.    rc = mixerGetLineInfo(hmixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)
  788.    
  789.    If (MMSYSERR_NOERROR = rc) Then
  790.       mxlc.cbStruct = Len(mxlc)
  791.       mxlc.dwLineID = mxl.dwLineID
  792.       mxlc.dwControl = ctrlType
  793.       mxlc.cControls = 1
  794.       mxlc.cbmxctrl = Len(mxc)
  795.       mxlc.pamxctrl = 9
  796.       
  797.       ' Allocate a buffer for the control
  798.       'hmem = GlobalAlloc(&H40, Len(mxc))
  799.       hmem = GlobalAlloc(GMEM_FIXED, Len(mxc))
  800.       mxlc.pamxctrl = GlobalLock(hmem)
  801.       mxc.cbStruct = Len(mxc)
  802.       
  803.       ' Get the control
  804.       rc = mixerGetLineControls(hmixer, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
  805.             
  806.       If (MMSYSERR_NOERROR = rc) Then
  807.          GetControl = True
  808.          
  809.          ' Copy the control into the destination structure
  810.          CopyStructFromPtr mxc, mxlc.pamxctrl, Len(mxc)
  811.       Else
  812.          GetControl = False
  813.       End If
  814.       GlobalFree (hmem)
  815.       Exit Function
  816.    End If
  817.    
  818.    GetControl = False
  819. End Function
  820.  
  821. ' Function to process the wave recording notifications.
  822. Sub waveInProc(ByVal hwi As Long, ByVal uMsg As Long, ByVal dwInstance As Long, ByRef hdr As WAVEHDR, ByVal dwParam2 As Long)
  823.    If (uMsg = MM_WIM_DATA) Then
  824.       If fRecording Then
  825.          rc = waveInAddBuffer(hwi, hdr, Len(hdr))
  826.       End If
  827.    End If
  828. End Sub
  829.  
  830. ' This function starts recording from the soundcard. The soundcard must be recording in order to
  831. ' monitor the input level. Without starting the recording from this application, input level
  832. ' can still be monitored if another application is recording audio
  833. Function StartInput() As Boolean
  834.  
  835.     If fRecording Then
  836.         StartInput = True
  837.         Exit Function
  838.     End If
  839.     
  840.     format.wFormatTag = 1
  841.     format.nChannels = 1
  842.     format.wBitsPerSample = 8
  843.     format.nSamplesPerSec = 8000
  844.     format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8
  845.     format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign
  846.     format.cbSize = 0
  847.     
  848.     For i = 0 To NUM_BUFFERS - 1
  849.         hmem(i) = GlobalAlloc(&H40, BUFFER_SIZE)
  850.         inHdr(i).lpData = GlobalLock(hmem(i))
  851.         inHdr(i).dwBufferLength = BUFFER_SIZE
  852.         inHdr(i).dwFlags = 0
  853.         inHdr(i).dwLoops = 0
  854.     Next
  855.  
  856.     rc = waveInOpen(hWaveIn, DEVICEID, format, 0, 0, 0)
  857.     If rc <> 0 Then
  858.         waveInGetErrorText rc, msg, Len(msg)
  859.         MsgBox msg
  860.         StartInput = False
  861.         Exit Function
  862.     End If
  863.  
  864.     For i = 0 To NUM_BUFFERS - 1
  865.         rc = waveInPrepareHeader(hWaveIn, inHdr(i), Len(inHdr(i)))
  866.         If (rc <> 0) Then
  867.             waveInGetErrorText rc, msg, Len(msg)
  868.             MsgBox msg
  869.         End If
  870.     Next
  871.  
  872.     For i = 0 To NUM_BUFFERS - 1
  873.         rc = waveInAddBuffer(hWaveIn, inHdr(i), Len(inHdr(i)))
  874.         If (rc <> 0) Then
  875.             waveInGetErrorText rc, msg, Len(msg)
  876.             MsgBox msg
  877.         End If
  878.     Next
  879.  
  880.     fRecording = True
  881.     rc = waveInStart(hWaveIn)
  882.     StartInput = True
  883. End Function
  884.  
  885. ' Stop receiving audio input on the soundcard
  886. Sub StopInput()
  887.  
  888.     fRecording = False
  889.     waveInReset hWaveIn
  890.     waveInStop hWaveIn
  891.     For i = 0 To NUM_BUFFERS - 1
  892.         waveInUnprepareHeader hWaveIn, inHdr(i), Len(inHdr(i))
  893.         GlobalFree hmem(i)
  894.     Next
  895.     waveInClose hWaveIn
  896. End Sub
  897.  
  898. Sub StayOnTop(frm As Form)
  899.     Call SetWindowPos(frm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, Flags)
  900. End Sub
  901.  
  902.  
  903.