ltmmAudioFormats.Count Example for Visual Basic

' Having an IltmmCapture object, Cap:

Dim Count As Long
Dim Freq, Bits, Channels As Long
Dim FoundAt As Long
Dim Selection As Long
Dim Selected As Boolean

' get count of available audio formats
Count = Cap.AudioCaptureFormats.Count

For i=0 To Count
  
   ' do something with the item i, like viewing its information:
   Freq = Cap.AudioCaptureFormats.Item(i).SampleFrequency
   Bits = Cap.AudioCaptureFormats.Item(i).BitsPerSample  
   Channels = Cap.AudioCaptureFormats.Item(i).Channels
   Selected = Cap.AudioCaptureFormats.Item(i).Selected

   ' view information …

   ' you may select the format if it matches some criteria:
   If Freq = 8000 And Bits = 8 And Channels = 1Then
         Cap.AudioCaptureFormats.Item (i).Selected = TRUE
   End If

Next i

' you might use the Find method to search for a specific format:
FoundAt = Cap.AudioCaptureFormats.Find(96000, 16, 2)
If FoundAt <> -1 Then
   ' do something with it:
   ' check if it is already selected, and if not, select it:
   Selection = Cap.AudioCaptureFormats.Selection
   If Selection <> FoundAt Then
      Cap.AudioCaptureFormats.Selection = FoundAt
   End If
End If