Z zhaixiaobo Unregistered / Unconfirmed GUEST, unregistred user! 2002-07-23 #1 向大家请教一个问题,用Delphi编程怎样使PC喇叭发声,不胜感谢!
S SanDao Unregistered / Unconfirmed GUEST, unregistred user! 2002-07-23 #3 Beep是没错啦! 我的天,300分!你不会真的想听音乐吧??
S softdog Unregistered / Unconfirmed GUEST, unregistred user! 2002-07-23 #4 windows.beep(Freq, Delay)
P peng_qs Unregistered / Unconfirmed GUEST, unregistred user! 2002-07-23 #5 { Windows NT/2000/XP: Windows.Beep(dwFreq, dwDuration); dwFreq : frequency, in hertz, of the sound. dwDuration : duration, in milliseconds, of the sound. } // Windows 9x/NT-Platforms: 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 do Sound(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 Sleep(1); //or use Application.ProcessMessages instead of Sleep until ((GetTickCount - FirstTickCount) >= Longint(MSecs)); end; begin if Win32Platform = VER_PLATFORM_WIN32_NT then begin Windows.Beep(aFreq, aDelay); end else begin do Sound(aFreq); Delay(aDelay); end; end; procedure NoSound; var Value: Word; begin if not (Win32Platform = VER_PLATFORM_WIN32_NT) then begin Value := GetPort($61) and $FC; SetPort($61, Value); end; end; // Example: procedure TForm1.Button1Click(Sender: TObject); begin Sound(500, 1000); Sound(700, 1000); Sound(900, 1000); NoSound; end;
{ Windows NT/2000/XP: Windows.Beep(dwFreq, dwDuration); dwFreq : frequency, in hertz, of the sound. dwDuration : duration, in milliseconds, of the sound. } // Windows 9x/NT-Platforms: 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 do Sound(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 Sleep(1); //or use Application.ProcessMessages instead of Sleep until ((GetTickCount - FirstTickCount) >= Longint(MSecs)); end; begin if Win32Platform = VER_PLATFORM_WIN32_NT then begin Windows.Beep(aFreq, aDelay); end else begin do Sound(aFreq); Delay(aDelay); end; end; procedure NoSound; var Value: Word; begin if not (Win32Platform = VER_PLATFORM_WIN32_NT) then begin Value := GetPort($61) and $FC; SetPort($61, Value); end; end; // Example: procedure TForm1.Button1Click(Sender: TObject); begin Sound(500, 1000); Sound(700, 1000); Sound(900, 1000); NoSound; end;
J jomee Unregistered / Unconfirmed GUEST, unregistred user! 2002-07-23 #6 编一个超CPU的程序。超烧了CPU后,就会有动听的报警声。
Z zhaixiaobo Unregistered / Unconfirmed GUEST, unregistred user! 2002-07-23 #8 谢谢peng_qs, 也谢谢:娃娃,SanDao,softdog如此热心.