作者a1013944 (ㄚ春)
看板C_and_CPP
标题Re: [问题] 用C写音乐程式
时间Thu Mar 12 23:08:45 2009
※ 引述《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
1F:推 Bencrie:说是产生音乐,是从哪里播啊 ? PC speaker ?? 03/13 00:38
2F:推 VictorTom:印象中是从主机板接出来的那个PC Speaker发出声音没错:) 03/13 00:47
3F:推 typeotoco:我用别的compiler 可以run喔 两只老虎 03/13 00:48
4F:→ a1013944:可以教我吗?? 03/13 09:44