home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / audiol1a / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-04-14  |  5.4 KB  |  162 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "Comctl32.ocx"
  3. Begin VB.Form Form1 
  4.    Caption         =   "volume meter"
  5.    ClientHeight    =   1770
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   4695
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   1770
  11.    ScaleWidth      =   4695
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin ComctlLib.ProgressBar ProgressBar2 
  14.       Height          =   255
  15.       Left            =   1200
  16.       TabIndex        =   4
  17.       Top             =   1320
  18.       Width           =   3375
  19.       _ExtentX        =   5953
  20.       _ExtentY        =   450
  21.       _Version        =   327682
  22.       Appearance      =   1
  23.    End
  24.    Begin ComctlLib.ProgressBar ProgressBar1 
  25.       Height          =   255
  26.       Left            =   1200
  27.       TabIndex        =   3
  28.       Top             =   240
  29.       Width           =   3375
  30.       _ExtentX        =   5953
  31.       _ExtentY        =   450
  32.       _Version        =   327682
  33.       Appearance      =   1
  34.    End
  35.    Begin VB.CheckBox Check1 
  36.       Caption         =   "get input"
  37.       Height          =   375
  38.       Left            =   1200
  39.       Style           =   1  'Graphical
  40.       TabIndex        =   2
  41.       Top             =   600
  42.       Width           =   975
  43.    End
  44.    Begin VB.Timer Timer1 
  45.       Interval        =   50
  46.       Left            =   4200
  47.       Top             =   600
  48.    End
  49.    Begin VB.Label Label2 
  50.       Caption         =   "output level"
  51.       Height          =   255
  52.       Left            =   120
  53.       TabIndex        =   1
  54.       Top             =   1320
  55.       Width           =   855
  56.    End
  57.    Begin VB.Label Label1 
  58.       Caption         =   "input level"
  59.       Height          =   255
  60.       Left            =   120
  61.       TabIndex        =   0
  62.       Top             =   240
  63.       Width           =   855
  64.    End
  65. Attribute VB_Name = "Form1"
  66. Attribute VB_GlobalNameSpace = False
  67. Attribute VB_Creatable = False
  68. Attribute VB_PredeclaredId = True
  69. Attribute VB_Exposed = False
  70. Option Explicit
  71. Dim hmixer As Long                  ' mixer handle
  72. Dim inputVolCtrl As MIXERCONTROL    ' waveout volume control
  73. Dim outputVolCtrl As MIXERCONTROL   ' microphone volume control
  74. Dim rc As Long                      ' return code
  75. Dim ok As Boolean                   ' boolean return code
  76. Dim mxcd As MIXERCONTROLDETAILS         ' control info
  77. Dim vol As MIXERCONTROLDETAILS_SIGNED   ' control's signed value
  78. Dim volume As Long                      ' volume value
  79. Dim volHmem As Long                     ' handle to volume memory
  80. Private Sub Form_Load()
  81.    ' Open the mixer specified by DEVICEID
  82.    rc = mixerOpen(hmixer, DEVICEID, 0, 0, 0)
  83.    If ((MMSYSERR_NOERROR <> rc)) Then
  84.        MsgBox "Couldn't open the mixer."
  85.        Exit Sub
  86.    End If
  87.        
  88.    ' Get the input volume meter
  89.    ok = GetControl(hmixer, MIXERLINE_COMPONENTTYPE_DST_WAVEIN, MIXERCONTROL_CONTROLTYPE_PEAKMETER, inputVolCtrl)
  90.    If (ok <> True) Then
  91.        ok = GetControl(hmixer, MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, MIXERCONTROL_CONTROLTYPE_PEAKMETER, inputVolCtrl)
  92.    End If
  93.    If (ok = True) Then
  94.       ProgressBar1.Min = 0
  95.       ProgressBar1.Max = inputVolCtrl.lMaximum
  96.    Else
  97.       ProgressBar1.Enabled = False
  98.       MsgBox "Couldn't get wavein meter"
  99.    End If
  100.        
  101.    ' Get the output volume meter
  102.    ok = GetControl(hmixer, MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT, MIXERCONTROL_CONTROLTYPE_PEAKMETER, outputVolCtrl)
  103.    If (ok = True) Then
  104.       ProgressBar2.Min = 0
  105.       ProgressBar2.Max = outputVolCtrl.lMaximum
  106.    Else
  107.       ProgressBar2.Enabled = False
  108.       MsgBox "Couldn't get waveout meter"
  109.    End If
  110.    ' Initialize mixercontrol structure
  111.    mxcd.cbStruct = Len(mxcd)
  112.    volHmem = GlobalAlloc(&H0, Len(volume))  ' Allocate a buffer for the volume value
  113.    mxcd.paDetails = GlobalLock(volHmem)
  114.    mxcd.cbDetails = Len(volume)
  115.    mxcd.cChannels = 1
  116. End Sub
  117. Private Sub Check1_Click()
  118.    If (Check1.Value = 1) Then
  119.       StartInput  ' Start receiving audio input
  120.    Else
  121.       StopInput   ' Stop receiving audio input
  122.    End If
  123. End Sub
  124. Private Sub Timer1_Timer()
  125.    On Error Resume Next
  126.    ' Process sound buffer if recording
  127.    If (fRecording) Then
  128.       For i = 0 To (NUM_BUFFERS - 1)
  129.          If inHdr(i).dwFlags And WHDR_DONE Then
  130.             rc = waveInAddBuffer(hWaveIn, inHdr(i), Len(inHdr(i)))
  131.          End If
  132.       Next
  133.    End If
  134.    ' Get the current input level
  135.    If (ProgressBar1.Enabled = True) Then
  136.       mxcd.dwControlID = inputVolCtrl.dwControlID
  137.       mxcd.item = inputVolCtrl.cMultipleItems
  138.       rc = mixerGetControlDetails(hmixer, mxcd, MIXER_GETCONTROLDETAILSF_VALUE)
  139.       CopyStructFromPtr volume, mxcd.paDetails, Len(volume)
  140.       If (volume < 0) Then
  141.          volume = -volume
  142.          End If
  143.       ProgressBar1.Value = volume
  144.    End If
  145.    ' Get the current output level
  146.    If (ProgressBar2.Enabled = True) Then
  147.       mxcd.dwControlID = outputVolCtrl.dwControlID
  148.       mxcd.item = outputVolCtrl.cMultipleItems
  149.       rc = mixerGetControlDetails(hmixer, mxcd, MIXER_GETCONTROLDETAILSF_VALUE)
  150.       CopyStructFromPtr volume, mxcd.paDetails, Len(volume)
  151.       
  152.       If (volume < 0) Then volume = -volume
  153.       ProgressBar2.Value = volume
  154.    End If
  155. End Sub
  156. Private Sub Form_Unload(Cancel As Integer)
  157.    If (fRecording = True) Then
  158.        StopInput
  159.    End If
  160.    GlobalFree volHmem
  161. End Sub
  162.