Re: [問題] 用C寫音樂程式
※ 引述《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
03/13 00:38, 1F
推
03/13 00:47, , 2F
03/13 00:47, 2F
推
03/13 00:48, , 3F
03/13 00:48, 3F
→
03/13 09:44, , 4F
03/13 09:44, 4F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章