看板 C_and_CPP 關於我們 聯絡資訊
※ 引述《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
Bencrie:說是產生音樂,是從哪裡播啊 ? PC speaker ?? 03/13 00:38
VictorTom:印象中是從主機板接出來的那個PC Speaker發出聲音沒錯:) 03/13 00:47
typeotoco:我用別的compiler 可以run喔 兩隻老虎 03/13 00:48
a1013944:可以教我嗎?? 03/13 09:44