unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses MMSystem;
//設備列表; 指定設備時經常使用 WAVE_MAPPER 參數, 這樣會自動選用合適的設備.
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
waveOutCaps: TWaveOutCaps;
waveInCaps: TWaveInCaps;
begin
ListBox1.Items.Add('音頻輸出設備列表:');
for i := 0 to waveOutGetNumDevs do
begin
ZeroMemory(@waveOutCaps, SizeOf(TWaveOutCaps));
waveOutGetDevCaps(i, @waveOutCaps, SizeOf(TWaveOutCaps));
ListBox1.Items.Add(waveOutCaps.szPname);
end;
ListBox2.Items.Add('音頻輸入設備列表:');
for i := 0 to waveInGetNumDevs do
begin
ZeroMemory(@waveInCaps, SizeOf(TWaveInCaps));
waveOutGetDevCaps(i, @waveInCaps, SizeOf(TWaveInCaps));
ListBox2.Items.Add(waveInCaps.szPname);
end;
end;
//判斷是否支持指定的 Wave 格式
procedure TForm1.Button2Click(Sender: TObject);
var
fmt: TPCMWaveFormat;
begin
fmt.wf.wFormatTag := WAVE_FORMAT_PCM;
fmt.wf.nChannels := 2;
fmt.wf.nSamplesPerSec := 22050;
fmt.wf.nAvgBytesPerSec := 88200;
fmt.wf.nBlockAlign := 4;
fmt.wBitsPerSample := 16;
if waveOutOpen(nil, 0, PWaveFormatEx(@fmt), 0, 0, WAVE_FORMAT_QUERY) = 0 then
ShowMessage('第一個輸出設備支持此格式');
if waveInOpen(nil, 0, PWaveFormatEx(@fmt), 0, 0, WAVE_FORMAT_QUERY) = 0 then
ShowMessage('第一個輸入設備支持此格式');
end;
end.
有把格式支持的判斷寫成函數的, 如:
function IsFormatSupported(fmt: Pointer; DeviceId: DWord): Boolean;
begin
Result := (waveOutOpen(nil, DeviceId, PWaveFormatEx(fmt), 0, 0, WAVE_FORMAT_QUERY) = 0);
end;