home *** CD-ROM | disk | FTP | other *** search
/ Microsoft DirectX SDK 7.0 / Dx7.bin / DXF / samples / multimedia / vbsamples / dsound / src / fullduplex / bashelper.bas next >
Encoding:
BASIC Source File  |  1999-06-16  |  4.5 KB  |  175 lines

  1. Attribute VB_Name = "basHelper"
  2. Public Type FD
  3.     CaptureGUID As String
  4.     SoundGUID As String
  5.     SoundDesc As String
  6.     CaptureDesc As String
  7.     SoundFormatDesc As String
  8.     CaptureFormatDesc As String
  9.     CaptureFMT As WAVEFORMATEX
  10.     SoundFMT As WAVEFORMATEX
  11. End Type
  12.  
  13. Global Full As FD
  14.  
  15. Public Const NUM_FORMATCODES = 16
  16.  
  17. Public Type Formats
  18.     lCode As Long
  19.     bEnabled  As Boolean
  20.     sDesc As String
  21. End Type
  22.  
  23.  
  24. Public aOutputFormats(NUM_FORMATCODES - 1) As Formats
  25. Public aInputFormats(NUM_FORMATCODES - 1) As Formats
  26. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  27.  
  28.  
  29.  
  30.  
  31.  
  32. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  33. 'FormatCodeToWFX()
  34. '
  35. ' This function reads format codes and fills most of the fields of a
  36. ' WAVEFORMATEX structure based on the values read.  It does not fill the
  37. ' wFormatTag or cbSize members.
  38. '
  39.  
  40.  
  41. Public Function FormatCodeToWFX(lFormat As Long, wf As WAVEFORMATEX) As Boolean
  42.  
  43.  
  44.     Dim lFreq As Long
  45.  
  46. '    If wf Is Nothing Then
  47. '        FormatCodeToWFX = False
  48. '        Exit Function
  49. '    End If
  50. '
  51.  
  52.     ' Extract the sample rate
  53.     lFreq = FC_GETFREQCODE(lFormat)
  54.     
  55.     If lFreq = 8 Then
  56.         wf.lSamplesPerSec = 8000
  57.     Else
  58.         wf.lSamplesPerSec = (lFreq / 11) * 11025
  59.     End If
  60.     
  61.     wf.nBitsPerSample = FC_GETBITS(lFormat)
  62.     wf.nChannels = FC_GETCHANNELS(lFormat)
  63.  
  64.     ' The nBlockAlign calculation below only works for whole-byte samples
  65.      If wf.nBitsPerSample Mod 8 = 0 Then
  66.         wf.nBlockAlign = wf.nChannels * (wf.nBitsPerSample / 8)
  67.         wf.lAvgBytesPerSec = wf.nBlockAlign * wf.lSamplesPerSec
  68.     End If
  69.     
  70.     FormatCodeToWFX = True
  71.  
  72. End Function
  73.  
  74. Private Function FC_GETFREQCODE(fc) As Long
  75.     FC_GETFREQCODE = ((fc) / 1000)
  76. End Function
  77.  
  78.  
  79. Private Function FC_GETBITS(fc) As Long
  80.     FC_GETBITS = ((fc) Mod 100)
  81. End Function
  82.  
  83. Private Function FC_GETCHANNELS(fc) As Long
  84.     FC_GETCHANNELS = (((fc) Mod 1000) / 100)
  85. End Function
  86.  
  87.  
  88. Public Sub GetFormatInfo(InputOutPut As Boolean)
  89.  
  90. Dim ConstForm(NUM_FORMATCODES - 1) As Formats
  91. Dim cnt As Integer
  92.  
  93. ConstForm(0).bEnabled = True
  94. ConstForm(0).lCode = 8108
  95. ConstForm(0).sDesc = "8000 Hz 8-bit Mono"
  96.  
  97. ConstForm(1).bEnabled = True
  98. ConstForm(1).lCode = 8208
  99. ConstForm(1).sDesc = "8000 Hz 8-bit Stereo"
  100.  
  101. ConstForm(2).bEnabled = True
  102. ConstForm(2).lCode = 8116
  103. ConstForm(2).sDesc = "8000 Hz 16-bit Mono"
  104.  
  105. ConstForm(3).bEnabled = True
  106. ConstForm(3).lCode = 8216
  107. ConstForm(3).sDesc = "8000 Hz 16-bit Stereo"
  108.  
  109. ConstForm(4).bEnabled = True
  110. ConstForm(4).lCode = 11108
  111. ConstForm(4).sDesc = "11025 Hz 8-bit Mono"
  112.  
  113. ConstForm(5).bEnabled = True
  114. ConstForm(5).lCode = 11208
  115. ConstForm(5).sDesc = "11025 Hz 8-bit Stereo"
  116.  
  117. ConstForm(6).bEnabled = True
  118. ConstForm(6).lCode = 11116
  119. ConstForm(6).sDesc = "11025 Hz 16-bit Mono"
  120.  
  121. ConstForm(7).bEnabled = True
  122. ConstForm(7).lCode = 11216
  123. ConstForm(7).sDesc = "11025 Hz 16-bit Stereo"
  124.  
  125. ConstForm(8).bEnabled = True
  126. ConstForm(8).lCode = 22108
  127. ConstForm(8).sDesc = "22050 Hz 8-bit Mono"
  128.  
  129. ConstForm(9).bEnabled = True
  130. ConstForm(9).lCode = 22208
  131. ConstForm(9).sDesc = "22050 Hz 8-bit Stereo"
  132.  
  133. ConstForm(10).bEnabled = True
  134. ConstForm(10).lCode = 22116
  135. ConstForm(10).sDesc = "22050 Hz 16-bit Mono"
  136.  
  137. ConstForm(11).bEnabled = True
  138. ConstForm(11).lCode = 22216
  139. ConstForm(11).sDesc = "22050 Hz 16-bit Stereo"
  140.  
  141. ConstForm(12).bEnabled = True
  142. ConstForm(12).lCode = 44108
  143. ConstForm(12).sDesc = "44100 Hz 8-bit Mono"
  144.  
  145. ConstForm(13).bEnabled = True
  146. ConstForm(13).lCode = 44208
  147. ConstForm(13).sDesc = "44100 Hz 8-bit Stereo"
  148.  
  149. ConstForm(14).bEnabled = True
  150. ConstForm(14).lCode = 44116
  151. ConstForm(14).sDesc = "44100 Hz 16-bit Mono"
  152.  
  153. ConstForm(15).bEnabled = True
  154. ConstForm(15).lCode = 44216
  155. ConstForm(15).sDesc = "44100 Hz 16-bit Stereo"
  156.  
  157. Select Case InputOutPut
  158.     Case True
  159.         While (cnt <> UBound(ConstForm) + 1)
  160.             aOutputFormats(cnt).bEnabled = ConstForm(cnt).bEnabled
  161.             aOutputFormats(cnt).lCode = ConstForm(cnt).lCode
  162.             aOutputFormats(cnt).sDesc = ConstForm(cnt).sDesc
  163.             cnt = cnt + 1
  164.         Wend
  165.     Case False
  166.         While (cnt <> UBound(ConstForm) + 1)
  167.             aInputFormats(cnt).bEnabled = ConstForm(cnt).bEnabled
  168.             aInputFormats(cnt).lCode = ConstForm(cnt).lCode
  169.             aInputFormats(cnt).sDesc = ConstForm(cnt).sDesc
  170.             cnt = cnt + 1
  171.         Wend
  172. End Select
  173. End Sub
  174.  
  175.