Solved

delphi: how to get input audio list ?

Posted on 2011-09-05
1
915 Views
Last Modified: 2012-05-12
Hello experts
How can I retrieve the list of installed input devices ? (input = microphone, not audio output)

regards
0
Comment
Question by:yarekGmail
1 Comment
 
LVL 12

Accepted Solution

by:
Hypo earned 500 total points
ID: 36484702
There is a unit called MMSystems that contains most of the functionality you need... if you search through the windows sdk for functions that begin with waveIn, you will find the functions that are used with audio input devices on the system...

see the example below...

/Hypo
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, MMSystem, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    FWaveInDevices : array of TWaveInCaps;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure CheckIfError(AResult : MMRESULT);
var aText : String;
    aRes : Cardinal;
begin
  if AResult <> MMSYSERR_NOERROR then begin
    SetLength(aText, 255);
    aRes := waveInGetErrorText(AResult, @aText[1], 255);
    if aRes <> MMSYSERR_NOERROR then
      waveInGetErrorText(aRes, @aText[1], 255);
    aText := PChar(aText);
    raise Exception.Create(aText + ' - Error code: ' + IntToStr(AResult));
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FWaveInDevices := nil;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i, aCount : integer;
begin
  aCount := waveInGetNumDevs;
  SetLength(FWaveInDevices, aCount);
  for i := 0 to aCount-1 do begin
    CheckIfError(waveInGetDevCaps(i, @FWaveInDevices[i], SizeOf(FWaveInDevices[i])));
    ListBox1.Items.Add(FWaveInDevices[i].szPname);
  end;
end;

end.

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question