On Windows, Beep calls the Windows API MessageBeep.
BOOL Beep(
DWORD dwFreq, // sound frequency, in hertz
DWORD dwDuration // sound duration, in milliseconds
);
所以,完全有可能用beep函数拼出节奏和歌曲(当然了,你也可以写个循环发出让人心烦的声音来恶搞别人……)。以下是网上找来的两个例子:
uses
SysUtils, Windows;
//送别
procedure beepValediction;
const
ONE_BEEP = 600;
HALF_BEEP = 300;
NOTE_1 = 440;
NOTE_2 = 495;
NOTE_3 = 550;
NOTE_4 = 587;
NOTE_5 = 660;
NOTE_6 = 733;
NOTE_7 = 825;
begin
try
//长亭外
Beep(NOTE_5, ONE_BEEP);
Beep(NOTE_3, HALF_BEEP);
Beep(NOTE_5, HALF_BEEP);
Beep(NOTE_1 * 2, ONE_BEEP * 2);
//古道边
Beep(NOTE_6, ONE_BEEP);
Beep(NOTE_1 * 2, ONE_BEEP);
Beep(NOTE_5, ONE_BEEP * 2);
//芳草碧连天
Beep(NOTE_5, ONE_BEEP);
Beep(NOTE_1, HALF_BEEP);
Beep(NOTE_2, HALF_BEEP);
Beep(NOTE_3, ONE_BEEP);
Beep(NOTE_2, HALF_BEEP);
Beep(NOTE_1, HALF_BEEP);
Beep(NOTE_2, ONE_BEEP * 4);
//晚风扶柳笛声残
Beep(NOTE_5, ONE_BEEP);
Beep(NOTE_3, HALF_BEEP);
Beep(NOTE_5, HALF_BEEP);
Beep(NOTE_1 * 2, HALF_BEEP * 3);
Beep(NOTE_7, HALF_BEEP);
Beep(NOTE_6, ONE_BEEP);
Beep(NOTE_1 * 2, ONE_BEEP);
Beep(NOTE_5, ONE_BEEP * 2);
//夕阳山外山
Beep(NOTE_5, ONE_BEEP);
Beep(NOTE_2, HALF_BEEP);
Beep(NOTE_3, HALF_BEEP);
Beep(NOTE_4, HALF_BEEP * 3);
Beep(round(NOTE_7 / 2), HALF_BEEP);
Beep(NOTE_1, ONE_BEEP * 4);
//天之涯
Beep(NOTE_6, ONE_BEEP);
Beep(NOTE_1 * 2, ONE_BEEP);
Beep(NOTE_1 * 2, ONE_BEEP * 2);
//地之角
Beep(NOTE_7, ONE_BEEP);
Beep(NOTE_6, HALF_BEEP);
Beep(NOTE_7, HALF_BEEP);
Beep(NOTE_1 * 2, ONE_BEEP * 2);
//知交半零落
Beep(NOTE_6, HALF_BEEP);
Beep(NOTE_7, HALF_BEEP);
Beep(NOTE_1 * 2, HALF_BEEP);
Beep(NOTE_6, HALF_BEEP);
Beep(NOTE_6, HALF_BEEP);
Beep(NOTE_5, HALF_BEEP);
Beep(NOTE_3, HALF_BEEP);
Beep(NOTE_1, HALF_BEEP);
Beep(NOTE_2, ONE_BEEP * 4);
//一壶浊酒尽余欢
Beep(NOTE_5, ONE_BEEP);
Beep(NOTE_3, HALF_BEEP);
Beep(NOTE_5, HALF_BEEP);
Beep(NOTE_1 * 2, HALF_BEEP * 3);
Beep(NOTE_7, HALF_BEEP);
Beep(NOTE_6, ONE_BEEP);
Beep(NOTE_1 * 2, ONE_BEEP);
Beep(NOTE_5, ONE_BEEP * 2);
//今宵别梦寒
Beep(NOTE_5, ONE_BEEP);
Beep(NOTE_2, HALF_BEEP);
Beep(NOTE_3, HALF_BEEP);
Beep(NOTE_4, HALF_BEEP * 3);
Beep(round(NOTE_7 / 2), HALF_BEEP);
Beep(NOTE_1, ONE_BEEP * 3);
except
end;
end;
//油和米
procedure beepYouAndMe;
const
ONE_BEEP = 800;
NOTE_1 = 196;
NOTE_2 = 262;
NOTE_3 = 294;
NOTE_4 = 330;
NOTE_5 = 392;
begin
Beep(NOTE_4, ONE_BEEP);
Beep(NOTE_5, ONE_BEEP);
Beep(NOTE_2, ONE_BEEP*2);
Beep(NOTE_3, ONE_BEEP);
Beep(NOTE_4, ONE_BEEP);
Beep(NOTE_1, ONE_BEEP*2);
Beep(NOTE_2, ONE_BEEP);
Beep(NOTE_3, ONE_BEEP);
Beep(NOTE_4, ONE_BEEP);
Beep(NOTE_5, ONE_BEEP);
Beep(NOTE_3, ONE_BEEP*4);
end;
请发表评论