DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: lisz2024
今日帖子: 3
在线用户: 4
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 qingyun (qingyun) ★☆☆☆☆ -
盒子活跃会员
2003/12/14 17:56:50
标题:
如何让pc喇叭发声??? 浏览:1616
加入我的收藏
楼主: 找到一段让pc喇叭发声音的代码

PC喇叭发声 




:sunstone 时间:00-9-3 7:51:42 ID:325632  
送你一个控件

unit PCSpk;

{* Program : PCSpk.Pas
  Purpose : TPCSpeaker Component

  Author        Version  Last Changed  Comments
  ------        -------  ------------  --------
  Song Weng Sam 1.01     Aug. 28, 96   Initial Release (Version set to 1.01
                                       to match the 16bit version which is
                                       currently 1.01 too.)
*}

interface

uses
  Classes, WinProcs, Forms;

type
  TPCSpeaker = class(TComponent)
  private
     { Private declarations }
     procedure NoSound;
     procedure Sound(Freq: Word);
     procedure SetPort(address, value: Word);
     function GetPort(address: Word): Word;
  protected
     { Protected declarations }
  public
     { Public declarations }
     procedure Delay(MSecs: Integer);
     procedure Play(Freq: Word; MSecs: Integer);
     procedure Stop;
  published
     { Published declarations }
  end;

procedure Register;

implementation

procedure TPCSpeaker.NoSound;
var
  wvalue: Word;
begin
  wvalue := GetPort($61);
  wvalue := wvalue and $FC;
  SetPort($61, wvalue);
end;

procedure TPCSpeaker.Sound(Freq: Word);
var
  B: Word;
begin
  if Freq > 18 then begin
     Freq := Word(1193181 div LongInt(Freq));

     B := GetPort($61);

     if (B and 3) = 0 then begin
        SetPort($61, B or 3);
        SetPort($43, $B6);
     end;

     SetPort($42, Freq);
     SetPort($42, (Freq SHR 8));
  end;
end;

procedure TPCSpeaker.Delay(MSecs: Integer);
var
  FirstTickCount : LongInt;
begin
  FirstTickCount:=GetTickCount;
  repeat
     Application.ProcessMessages; {allowing access to other controls, etc.}
  until ((GetTickCount-FirstTickCount) >= LongInt(MSecs));
end;

procedure TPCSpeaker.Play(Freq: Word; MSecs: Integer);
begin
  Sound(Freq);
  Delay(MSecs);
  NoSound;
end;

procedure TPCSpeaker.Stop;
begin
  NoSound;
end;

procedure TPCSpeaker.SetPort(address, value: Word);
var
  bvalue: Byte;
begin
  bvalue := trunc(value and 255);
  asm
     mov DX, address
     mov AL, bvalue
     out DX, AL
  end;
end;

function TPCSpeaker.GetPort(address: Word): Word;
var
  bvalue: Byte;
begin
  asm
     mov DX, address
     in  AL, DX
     mov bvalue, AL
  end;
  result := bvalue;
end;

procedure Register;
begin
  RegisterComponents('Sun', [TPCSpeaker]);
end;

end.

出自:
http://www.yzsoftware.com/bbs/show.asp?id=177&bd=2&totable=1

但是只能在98下面使用,2000下不行,怎么修改???  


----------------------------------------------
青云论坛
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行60.05859毫秒 RSS