Enumerating Audio Devices

Audio Input Devices

In the previous section, we added audio to our AVI file-writer but "cheated" by specifying the audio device at design time in Filter2's BaseFilter. Here, we'll enumerate the input devices in code and display them in a ListBox so that users can select the device.

Here's the Form we've been using for our project. I've resized ListBox1 to give us a bit more space and added a second ListBox which we'll populate with the system's audio input devices.


We'll enumerate the audio input devices in the Form's FormCreate event in much the same way as we did with the video:

  Form1: TForm1;
  SysDev: TSysDevEnum;
  AudioDevEnum: TSysDevEnum; 


{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
    i: Integer;
// Video SysDev enumeration here
// Create an Audio Input Device Enumerator
    AudioDevEnum:= TSysDevEnum.Create(CLSID_AudioInputDeviceCategory);
    if AudioDevEnum.CountFilters > 0 then
      for i := 0 to AudioDevEnum.CountFilters - 1 do

So, we now have ListBox2 populated with the system's Audio Input Devices' FriendlyNames. My system just has one - the audio on the motherboard - called 'SoundMaxDigitalAudio'.

Let's have a look at some of the properties and functions of the AudioDevEnum structure by using Delphi's 'code insight'

We've already used the CountFilters property to determine the number of input devices for our for...do loop and we've used the Filters property in order to retrieve each Filter's FriendlyName to display in the ListBox.

Recalling that Filter2 is the audio filter in our project, what we now need to do is assign our Filter2.BaseFilter.Moniker property by retrieving the Moniker for our selected input device.

By clicking on its FriendyName in the ListBox we specify the input device's index in the AudioDevEnum structure. We can use the GetMoniker(index: Integer) function to retrieve the Moniker, where index is the same as the selected FriendlyName's ItemIndex in ListBox2.

The obvious place to do this is in the ListBox2Click even.

procedure TForm1.ListBox2Click(Sender: TObject);
    if ListBox2.ItemIndex = -1 then Exit;
    Filter2.BaseFilter.Moniker:= AudioDevEnum.GetMoniker(ListBox2.ItemIndex);


Ok, we've enumerated the audio input devices, listed them in a ListBox and set our Filter2.BaseFilter.Moniker to our selected device. So far, this is very similar to the way we set up the video filter (Filter1). But, from here, audio becomes a little more complicated.

Have another look at the audio input filter of the Filter Graph in our previous project:

Our application should list the various input options (CD Player, Microphone, Aux, etc) and allow the user to select one. We'll look at this in the next part.

previous page | next page

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12

This site and its contents are © Copyright 2005 - All Rights Reserved.