全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1666
推到 Plurk!
推到 Facebook!

Beep()

尚未結案
avalokita
一般會員


發表:29
回覆:35
積分:12
註冊:2003-09-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-03-28 13:00:56 IP:203.70.xxx.xxx 未訂閱
請問Delphi中, 有沒有什麼函數,可播放出Do Re Me 等低階的音頻。 我記得有,也看過別人的範例,只是系統重灌後, 檔案就不見了。有誰知道的嗎?? 此外API中有BEEP(Para1,Para2)的函數.... 我用Delphi的Help也可以看到說明... 可是在程式碼中..不能用耶.... 會出現Error:Too Many parameters.. 好像Delphi中也有另一個只有一參數Beep(Para)的吧..
geniustom
版主


發表:100
回覆:303
積分:260
註冊:2003-01-03

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-03-28 16:30:35 IP:163.26.xxx.xxx 未訂閱
我以前寫過利用配合8255跟電腦連接..用IO控制PC喇叭發聲的 有以下幾個我寫好的函數..供參考.. procedure sound(freq:word); //持續發出一個頻率的聲音 procedure nosound; //停止 procedure tone(t:string); //發出一個音符 procedure MusicOut(song:string); //用輸入字串來普一首歌 範例歌譜如下... 1235446551.71.531234565432317,125,7,243231235446551.71.531236,543215,17,1- 程式如下:
unit MUSIC;    interface
uses  Windows,Forms, SysUtils, Messages,Classes,shellapi,access;    procedure MusicOut(song:string);    var
  StopSound:boolean;
  onesound:integer=100;    implementation    // windows 98時用I/O Port發音
procedure sound(freq:word);
begin
asm
   in al,61h
   or al,3
   out 61h,al
   mov al,0b6h
   out 43h,al
   mov bx,freq
   mov al,bl
   out 42h,al
   mov al,bh
   out 42h,al
end;
end;    // windows 98時用I/O Port停止發音
procedure nosound;
begin
asm
   in al,61h
   and al,0fch
   out 61h,al
end;
end;    // 發一個音的程式
procedure tone(t:string);
var f,w:integer;
begin
   f:=2400; // 設定頻率值
   t:=uppercase(t);
   if (win32platform=VER_PLATFORM_WIN32_NT) then // NT時
   begin
     if pos('7',t)>0 then f:=1976*2;
     if pos('6',t)>0 then f:=1760*2;
     if pos('5',t)>0 then f:=1568*2;
     if pos('4',t)>0 then f:=1480*2;
     if pos('3',t)>0 then f:=1319*2;
     if pos('2',t)>0 then f:=1175*2;
     if pos('1',t)>0 then f:=1047*2;
     f:=(f *57) div 100;
     if pos('.',t)>0 then f:=f * 2;
     if pos(',',t)>0 then f:=f div 2;
   end
   else // Win98時
   begin
     if pos('1',t)>0 then f:=1976 div 2;
     if pos('2',t)>0 then f:=1760 div 2;
     if pos('3',t)>0 then f:=1568 div 2;
     if pos('4',t)>0 then f:=1480 div 2;
     if pos('5',t)>0 then f:=1319 div 2;
     if pos('6',t)>0 then f:=1175 div 2;
     if pos('7',t)>0 then f:=1047 div 2;
     if pos('.',t)>0 then f:=f div 2;
     if pos(',',t)>0 then f:=f * 2;
   end;       w:=2;
   if pos('--',t)>0 then w:=8
   else if pos('-',t)>0 then w:=4
   else if pos('=',t)>0 then w:=1;
   if (win32platform=VER_PLATFORM_WIN32_NT) then // NT時用Beep函數
   begin
     windows.beep(f,w*(onesound div 2));
   end
   else // win98用I/O Port函數
   begin
;     sound(f);
     access.delay(w*(onesound div 2));
     nosound()
   end;
    access.delay(onesound div 2);
end;
// 唱一首歌的函數
procedure MusicOut(song:string);
var c:char;
    i:integer;
    t:string;
begin
   t:='';
   for i:=1 to length(song) do
   if not StopSound then
   begin
      Application.ProcessMessages;
      c:=song[i];
      if (C>='0') and (C<='9')then
      begin
         if t='' then t:=t c
         else
         begin
            tone(t);
            t:=c;
         end;
      end
      else t:=t c;
   end
   else break;
   if t<>'' then tone(t);
   StopSound:=False;
end;    end.
  
系統時間:2024-07-01 2:57:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!