home *** CD-ROM | disk | FTP | other *** search
/ Microsoft DirectX SDK 7.0 / Dx7.bin / DXF / samples / multimedia / vbsamples / dsound / src / fullduplex / frmformats.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-07  |  7.7 KB  |  264 lines

  1. VERSION 5.00
  2. Begin VB.Form frmFormats 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Select Formats"
  5.    ClientHeight    =   2925
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   6330
  9.    Icon            =   "frmFormats.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   2925
  14.    ScaleWidth      =   6330
  15.    StartUpPosition =   2  'CenterScreen
  16.    Begin VB.CommandButton cmdCancel 
  17.       Caption         =   "Cancel"
  18.       Height          =   375
  19.       Left            =   3480
  20.       TabIndex        =   6
  21.       Top             =   2280
  22.       Width           =   1215
  23.    End
  24.    Begin VB.CommandButton cmdOK 
  25.       Caption         =   "OK"
  26.       Height          =   375
  27.       Left            =   1560
  28.       TabIndex        =   5
  29.       Top             =   2280
  30.       Width           =   1335
  31.    End
  32.    Begin VB.ListBox lstInput 
  33.       Height          =   1425
  34.       Left            =   3960
  35.       TabIndex        =   1
  36.       Top             =   600
  37.       Width           =   2175
  38.    End
  39.    Begin VB.ListBox lstOutput 
  40.       Height          =   1425
  41.       Left            =   240
  42.       TabIndex        =   0
  43.       Top             =   600
  44.       Width           =   2175
  45.    End
  46.    Begin VB.Label lblToDO 
  47.       Caption         =   "Choose an output format, then select from the available input formats.  Click OK to accept the combination."
  48.       Height          =   1335
  49.       Left            =   2520
  50.       TabIndex        =   4
  51.       Top             =   600
  52.       Width           =   1335
  53.    End
  54.    Begin VB.Label lblInputFormat 
  55.       Caption         =   "Input Format:"
  56.       Height          =   375
  57.       Left            =   3960
  58.       TabIndex        =   3
  59.       Top             =   240
  60.       Width           =   2175
  61.    End
  62.    Begin VB.Label lblOutPut 
  63.       Caption         =   "Output Format:"
  64.       Height          =   255
  65.       Left            =   240
  66.       TabIndex        =   2
  67.       Top             =   240
  68.       Width           =   2175
  69.    End
  70. Attribute VB_Name = "frmFormats"
  71. Attribute VB_GlobalNameSpace = False
  72. Attribute VB_Creatable = False
  73. Attribute VB_PredeclaredId = True
  74. Attribute VB_Exposed = False
  75. Private DX As New DirectX7
  76. Private DS As DirectSound
  77. Private DSC As DirectSoundCapture
  78. Private DSCD As DSCBUFFERDESC
  79. Private sCaps As DSCAPS
  80. Private cCaps As DSCCAPS
  81. Private dsb_ As DirectSoundBuffer
  82. Private dsbd_ As DSBUFFERDESC
  83. Private tWFX As WAVEFORMATEX
  84. Sub INIT_SND()
  85.     On Local Error GoTo errOut
  86.     Set DSC = DX.DirectSoundCaptureCreate(Full.CaptureGUID)
  87.     DSC.GetCaps cCaps
  88.     Set DS = DX.DirectSoundCreate(Full.SoundGUID)
  89.     DS.SetCooperativeLevel hWnd, DSSCL_PRIORITY
  90.     DS.GetCaps sCaps
  91.     Exit Sub
  92. errOut:
  93.     MsgBox "Could not initialize this device", vbOKOnly Or vbCritical, "Could not init"
  94.     End
  95. End Sub
  96. Private Sub Term()
  97.     Set DX = Nothing
  98.     Set DS = Nothing
  99.     Set DSC = Nothing
  100.     Set dsb_ = Nothing
  101.     Set gDSCB = Nothing
  102.     Set gDSB = Nothing
  103. End Sub
  104. Private Sub cmdCancel_Click()
  105.     End
  106. End Sub
  107. Private Sub cmdOK_Click()
  108.     Unload Me
  109.     frmMain.Show
  110. End Sub
  111. Private Sub form_load()
  112.     GetFormatInfo True
  113.     INIT_SND
  114.         
  115.     ScanAvailableDSFormats
  116.     Dim i As Integer
  117.     For i = 0 To UBound(aOutputFormats)
  118.         If aOutputFormats(i).bEnabled = True Then
  119.             lstOutput.AddItem aOutputFormats(i).sDesc
  120.         End If
  121.     Next
  122.     cmdOK.Enabled = False
  123. End Sub
  124. Sub ScanAvailableDSFormats()
  125.     On Error Resume Next
  126.     Dim dsrval As Long
  127.     Dim i As Integer
  128.     For i = 0 To NUM_FORMATCODES - 1
  129.         aOutputFormats(i).bEnabled = False
  130.     Next
  131.     ' This might take a second or two, so throw up the hourglass
  132.     Screen.MousePointer = vbHourglass
  133.     For i = 0 To NUM_FORMATCODES - 1
  134.         Dim wfx As WAVEFORMATEX
  135.         wfx.nFormatTag = WAVE_FORMAT_PCM
  136.         FormatCodeToWFX aOutputFormats(i).lCode, wfx
  137.         Dim HLD As Long
  138.         
  139.         
  140.         Set dsb_ = Nothing
  141.         
  142.         With dsbd_
  143.             .lFlags = DSBCAPS_PRIMARYBUFFER
  144.             .lReserved = 0
  145.         End With
  146.         
  147.         Set dsb_ = DS.CreateSoundBuffer(dsbd_, tWFX)
  148.         
  149.         
  150.         
  151.         
  152.         dsb_.SetFormat wfx
  153.         
  154.         
  155.         Dim kwEmpty As WAVEFORMATEX
  156.         Dim kW As WAVEFORMATEX
  157.         kW = kwEmpty
  158.         dsb_.GetFormat kW
  159.         
  160.         Debug.Print kW.lSamplesPerSec
  161.         
  162.         
  163.         If kW.lAvgBytesPerSec = wfx.lAvgBytesPerSec Then
  164.             If kW.lSamplesPerSec = wfx.lSamplesPerSec Then
  165.                 If kW.nChannels = wfx.nChannels Then
  166.                     aOutputFormats(i).bEnabled = True
  167.                 End If
  168.             End If
  169.         Else
  170.             aOutputFormats(i).bEnabled = False
  171.         End If
  172.         'Set wfx = Nothing
  173.         
  174.         
  175.     Next
  176.     Screen.MousePointer = vbNormal
  177. End Sub
  178. Private Sub Form_Unload(Cancel As Integer)
  179.     Term
  180. End Sub
  181. Private Sub lstInput_Click()
  182.     Dim FMT As WAVEFORMATEX, lCode As Long, cnt As Integer
  183.     Dim InputCnt As Integer
  184.     While (cnt <> UBound(aInputFormats) + 1)
  185.         If aInputFormats(cnt).sDesc = lstInput.Text Then
  186.             FormatCodeToWFX aInputFormats(cnt).lCode, FMT
  187.         End If
  188.         cnt = cnt + 1
  189.     Wend
  190.         
  191.     Full.CaptureFMT = FMT
  192.     Full.CaptureFormatDesc = lstInput.Text
  193.     cmdOK.Enabled = True
  194. End Sub
  195. Private Sub lstOutput_Click()
  196.     Dim FMT As WAVEFORMATEX, lCode As Long, cnt As Integer
  197.     Dim InputCnt As Integer
  198.     lstInput.Clear
  199.     While (cnt <> UBound(aOutputFormats) + 1)
  200.         If aOutputFormats(cnt).sDesc = lstOutput.Text Then
  201.             FormatCodeToWFX aOutputFormats(cnt).lCode, FMT
  202.         End If
  203.         cnt = cnt + 1
  204.     Wend
  205.         
  206.     Full.SoundFMT = FMT
  207.     Full.SoundFormatDesc = lstOutput.Text
  208.     GetFormatInfo False
  209.     ScanAvailableDSCFormats
  210.     While (InputCnt <> UBound(aInputFormats) + 1)
  211.         If aInputFormats(InputCnt).bEnabled = True Then
  212.             lstInput.AddItem aInputFormats(InputCnt).sDesc
  213.         End If
  214.         InputCnt = InputCnt + 1
  215.     Wend
  216. End Sub
  217. Sub ScanAvailableDSCFormats()
  218.     On Error Resume Next
  219.     Dim dsrval As Long
  220.     Dim i As Integer
  221.     For i = 0 To NUM_FORMATCODES - 1
  222.         aInputFormats(i).bEnabled = False
  223.     Next
  224.     ' This might take a second or two, so throw up the hourglass
  225.     Screen.MousePointer = vbHourglass
  226.     For i = 0 To NUM_FORMATCODES - 1
  227.         Dim wfx As WAVEFORMATEX
  228.         wfx.nFormatTag = WAVE_FORMAT_PCM
  229.         FormatCodeToWFX aInputFormats(i).lCode, wfx
  230.         Dim HLD As Long
  231.         
  232.         Set gDSCB = Nothing
  233.         
  234.         
  235.         With DSCD
  236.             .lFlags = DSCBCAPS_WAVEMAPPED
  237.             .fxFormat = wfx
  238.             .lBufferBytes = wfx.lAvgBytesPerSec
  239.         End With
  240.         
  241.         Set gDSCB = DSC.CreateCaptureBuffer(DSCD)
  242.         
  243.         Debug.Print Err.Number
  244.         
  245.         Dim fw As WAVEFORMATEX
  246.         Dim fwEmpty As WAVEFORMATEX
  247.         fw = fwEmpty
  248.         
  249.         gDSCB.GetFormat fw
  250.         
  251.         If fw.lAvgBytesPerSec = wfx.lAvgBytesPerSec Then
  252.             If fw.lSamplesPerSec = wfx.lSamplesPerSec Then
  253.                 If fw.nChannels = wfx.nChannels Then
  254.                     aInputFormats(i).bEnabled = True
  255.                 End If
  256.             End If
  257.         Else
  258.             aInputFormats(i).bEnabled = False
  259.         End If
  260.         
  261.     Next
  262.     Screen.MousePointer = vbNormal
  263. End Sub
  264.