Re: [問題] 用C寫音樂程式

看板C_and_CPP (C/C++)作者 (ㄚ春)時間16年前 (2009/03/12 23:08), 編輯推噓3(301)
留言4則, 4人參與, 最新討論串2/3 (看更多)
※ 引述《a1013944 (ㄚ春)》之銘言: : #include<stdio.h> : #include<time.h> : #include<stdlib.h> : void delay(secs) : float secs; : { : clock_t end; : end=(int)(secs*CLOCKS_PER_SEC)+clock(); : while(clock()<end); : } : static int portvalue=0; : void sound(unsigned freq) : { : int portdata; : _outp(0x43,0xb6); : freq=(unsigned)(1193180L/freq); : _outp(0x42,(char)freq); : _outp(0x42,(char)(freq>>8)); : portdata=_inp(0x61); : if(portvalue==0) : portvalue=portdata; : _outp(0x61,portvalue | 0x3); : } : void nosound() : { : _outp(0x61,portvalue) ; : } : int main() : { : unsigned freq[]={523,587,659,523,523,587,659,523, : 659,698,784, 0,659,698,784, 0, : 784,880,784,698,659,523, : 784,880,784,698,659,523, : 523,329,523, 0,523,392,523, 0}; : double duration[]={0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5, : 0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5, : 0.25,0.25,0.25,0.25,0.5,0.5, : 0.25,0.25,0.25,0.25,0.5,0.5, : 0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5 }; : int i; : for(i=0;i<36;i++) : { : if(freq[i]>0) : sound(freq[i]); : delay(duration[i]); : } : nosound(); : system("pause"); : return 0; } 這個是我在書中看到的範例檔 年代已久 雖然沒有錯誤 可是卻沒有音樂產生@@ 我是在dev c++ 跑的 請問要怎麼讓它可以正確的執行出功能呢?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.123.237.33

03/13 00:38, , 1F
說是產生音樂,是從哪裡播啊 ? PC speaker ??
03/13 00:38, 1F

03/13 00:47, , 2F
印象中是從主機板接出來的那個PC Speaker發出聲音沒錯:)
03/13 00:47, 2F

03/13 00:48, , 3F
我用別的compiler 可以run喔 兩隻老虎
03/13 00:48, 3F

03/13 09:44, , 4F
可以教我嗎??
03/13 09:44, 4F
文章代碼(AID): #19kIL-Bm (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #19kIL-Bm (C_and_CPP)