Board index » delphi » Beep with the PC speaker

Beep with the PC speaker

This is a bit of code I used to sound a note whose frequency was held in
an array.
The bones of it will show you how to sound the beeper at a frequency

Alan Lloyd

procedure TNoteItForm.Sound(NoteID : TNote);
{ sounds note on PC's internal speaker }
var
  PortFreq, NoteFreq : integer;
  Port61 : byte;
begin
  case SignType of     {type of key signature}
    ktNatural : NoteFreq := FreqList[NoteId];
    ktFlat : NoteFreq := (FreqList[NoteId] + FreqList[NoteId-1]) div 2;
    ktSharp : NoteFreq := (FreqList[NoteId] + FreqList[NoteId+1]) div 2;
  end;
  PortFreq := 1193181 div NoteFreq;
  Port61 := Port[$61];
  SoundTimer.Enabled := false;
  NoSound;
  if (Port61 and 3) = 0 then begin
    Port[$61] := Port61 or 3;
    Port[$43] := $b6;
  end;
  Port[$42] := byte(PortFreq);
  Port[$42] := byte(PortFreq shr 8);
  SoundTimer.Enabled := true;
end;

procedure TNoteItForm.SoundTimerTimer(Sender: TObject);
begin
  SoundTimer.Enabled := false;
  NoSound;
end;

procedure TNoteItForm.NoSound;
begin
  Port[$61] := Port[$61] and $FC;
end;

 

Re:Beep with the PC speaker


Quote
Jean-Pol DUPONT wrote:

> I need a "beep" by the PC speaker
> without pass by the SoundBlaster.

> " MessageBeep (word (-1));  "
> ("- 1" as indicated in API)

> do not works.  Why?

MessageBeep(0) works fine for me.

Quote
> ========================================================
> "Write (Chr (7)); " = error 105
> ========================================================

You try writing to file output, which seems not to be open.

Quote
> In TIPS I have found the following code that functions but
> that is enough unstable :

> procedure TForm1.NoSound;
> begin
>    Port[$61] := Port[$61] and $FC;
> end;

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

>          B := Port[$61];

>          if (B and 3) = 0 then
>             begin
>                Port[$61] := B or 3;
>                Port[$43] := $B6;
>             end;

>          Port[$42] := Byte(Freq);
>          Port[$42] := Byte(Freq shr 8);
>       end;
> end;

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

Looks way too much like DOS, better do it the windows way.

Regards
--
Achim Richter
office: arich...@hzd.hessen.de
athome: arich...@t-online.de

Re:Beep with the PC speaker


On 5 Sep 1997 19:07:23 GMT, alangll...@aol.com (AlanGLLoyd) wrote:

Quote

>This is a bit of code I used to sound a note whose frequency was held in
>an array.
>The bones of it will show you how to sound the beeper at a frequency

This looks pretty cool, but I bet it doesn't work properly under Win95
with D2 or D3, where I don't think you have access to the Port[] array
anymore.

Quote
>procedure TNoteItForm.Sound(NoteID : TNote);
>{ sounds note on PC's internal speaker }

You also didn't include the definition of NoteID nor the FreqList[]
array, I'd like to see these please.

Regards,

Stephen Posey
slpo...@concentric.net

Re:Beep with the PC speaker


or you could go to the delphi deli and get a non-visual component
xprocs.pas
which has alot of other useful functions in it and
use the
sysbeep; fucntion from it

hdashti

Other Threads