DelphiFAQ Home Search:

Beep/ Sound in Delphi

 

comments2 comments. Current rating: 5 stars (1 votes). Leave comments and/ or rate it.

The following assembler Routines implement sound output via port access and work therefore only with Win3.x and Win95/98.
Simply call Sound(hz) with hz as frequency in Hz, and stop the sound output with NoSound().

If your application will run under Windows NT, you may use the operating system routine:
Windows.Beep(Frequency, Duration);

function InPort(PortAddr:word): byte; assembler; stdcall;
asm
  mov dx,PortAddr
  in al,dx
end;

procedure OutPort(PortAddr: word; Databyte: byte); assembler; stdcall;
asm
  mov al,Databyte
  mov dx,PortAddr
  out dx,al
end;

procedure Sound(Hz : Word);
var TmpW : Word;
begin
  OutPort($43,182);
  TmpW :=InPort($61);
  OutPort($61,TmpW or 3);
  OutPort($42,lo(1193180 div hz));
  OutPort($42, hi(1193180 div hz));
end;

procedure NoSound;
var TmpW : Word;
begin
  OutPort($43,182);
  TmpW := InPort($61);
  OutPort($61,TmpW and 3);
end;

Comments:

2006-11-24, 03:52:58
anonymous from Germany  
rating
This solved my problem with WinMe.
2007-04-04, 01:25:25   (updated: 2007-04-04, 01:28:20)
anonymous from Iran  
thank you but I could not find my answer in your website


Keywords:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: