Jouer des sons sur le PC-Speaker

Windows NT:
Windows.Beep(dwFreq, dwDuration);

dwFreq : frequency, in hertz, of the sound.
dwDuration : duration, in milliseconds, of the sound.


Windows 95/98:
procedure 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 GetPort(address:word):word;
var
bValue: byte;

begin
asm
mov dx, address
in al, dx
mov bValue, al
end;
GetPort := bValue;
end;

Procedure Sound(aFreq, aDelay : integer);
procedure DoSound(Freq : Word);
var
B : Byte;

begin
if Freq > 18 then
begin
Freq := Word(1193181 div LongInt(Freq));
B := Byte(GetPort($61));
if (B and 3) = 0 then
begin
SetPort($61, Word(B or 3));
SetPort($43, $B6);
end;

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

procedure Delay(MSecs: Integer);
var
FirstTickCount : LongInt;

begin
FirstTickCount:=GetTickCount;
repeat
SleepEX(1, false);
until ((GetTickCount-FirstTickCount) >= LongInt(MSecs));
end;

begin
DoSound(aFreq);
Delay(aDelay);
end;

procedure NoSound;
var
Value: Word;

begin
Value := GetPort($61) and $FC;
SetPort($61, Value);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Sound(500,1000);
Sound(700,1000);
Sound(900,1000);
NoSound;
end;
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour13/11/2001
VisualisationVu 1868 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Multimedia
Auteur de l'article
SwissDelphiCenter SwissDelphiCenter
connecté le 02/11/2011
329 articles dans la section
Contacter l'auteur