网站首页/技术开发列表/内容

DELPHI操纵声卡

技术开发2022-05-08阅读
检查声卡是否安装
uses mmsystem;
...
function Soundkarte:Boolean;
begin
Result := WaveOutGetNumDevs >0;
end;
检测声卡存在
如果你是做一些多媒体播放器之类的程序时,为了完善系统的容错性,就必须用到一些检测系统的功能,其中检测声卡是否存在就是一个问题,下列程序帮你忙,首先需要在uses部分加入mmsystem ,接着在窗体创建时检测声卡:
procedure TForm1.FormCreate(Sender: TObject);
var i:Integer;
begin
i := auxGetNumDevs();
if i<= then
label1.Caption :='系统没有发现声卡';
end;
控制声音音量
当你做一个多媒体播放器时,难免少不了控制音量的大小和左右声道的播放,下面就介绍一种控制Wave波形输出设备音量的方法,该方法不是设置主音量。先在窗体上放两个TTrackBar,分别命名为TrackBar1,TrackBar2,属性Max都设置为65535,如果觉得刻度太密了,可以把Frequency属性值设置大一些,然后在Uses段加入MMSystem,并在TrackBar1和TrackBar2的OnChange事件都写上下列语句:
procedure TForm1.TrackBar1Change(Sender: TObject);
var Wave:string;
begin
Wave:='$'+inttohex(TrackBar1.Position
4)+inttohex(TrackBar2.Position
4);
waveoutsetvolume(0
strtoint(Wave));
end;
获得和控制音量
unit uMain;
interface
uses
Windows
Messages
SysUtils
Classes
Controls
Forms
Dialogs
ExtCtrls
StdCtrls
mmsystem; //You must add this in the uses line
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
myvolume: array[0..10] of longint;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
Count
i: integer;
begin
Count := auxGetNumDevs;
for i := 0 to Count do
begin//The i is the device: I.E. 0=Wav Volume
auxgetvolume(i
addr(myvolume[i])); //Gets the values that the user has set
auxsetvolume(i
longint(9000)*65536+longint(9000)); //Sets the volume very very low
end; //The reason for the 9000*65536 + 9000 is if you wanted to do left and right channels
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
Count
i: integer;
begin
Count := auxGetNumDevs;
for i := 0 to Count do
begin
auxsetvolume(i
myvolume[i]); //Sets the volume back to the users old settings
end;
end;

……

相关阅读