| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 665 人关注过本帖
标题:[原创]音乐程序
只看楼主 加入收藏
fangqiao
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2005-10-8
收藏
 问题点数:0 回复次数:3 
[原创]音乐程序

#include<stdio.h> #include<dos.h> #define N1 32 #define N2 16 #define N4 8 #define N8 4 #define N16 2 #define END 0 enum NOTES { C10=131,D10=147,E10=165,F10=175,G10=196,A10=220,B10=247, C0=262,D0=286,E0=330,F0=349,G0=440,A0=440,B0=494, C1=523,D1=158,E1=659,F1=698,G1=784,A1=880,B1=998, C2=1047,D2=1175,E2=1319,F2=1397,G2=1568,A2=1760,B2=1976 } song1[]={ G0,N16,G0,N8,A0,N8,G0,N8,C1,N8,B0,N4,G0,N16,G0, N8,A0,N8,G0,N8,D1,N8,C1,N4,G0,N16,G0,N8,G1,N8,E1, N8,C1,N8,B0,N16,B0,N8,A0,N4,F1,N16,F1,N8,E1,N8,C1,N8,D1,N8,C1,N4, END,END }; song2[]={ C0,N8,D0,N8,E0,N8,F0,N8,G0,N8,A0,N8,B0,N8, C1,N8,D1,N8,E1,N8,F1,N8,G1,N8,A1,N8,B1,N8,END,END}; song[]= { C0,N8,C0,N8,G0,N8,G0,N8,A0,N8,A0,N8,G0,N4, F0,N8,F0,N8,E0,N8,E0,N8,D0,N8,D0,N8,C0,N4, G0,N8,G0,N8,F0,N4,E0,N8,E0,N8,D0,N4, G0,N8,G0,N8,F0,N8,F0,N8,E0,N8,E0,N8,D0,N4, C0,N8,E0,N8,G0,N4,A0,N8,C1,N8,G0,N4, F0,N8,F0,N8,E0,N8,E0,D0,N8,D0,N8,C0,N4,END,END};

void ss1() { int note=0,fre,dur,control; clock_t goal; while(song1[note]!=0) { fre=song1[note]; dur=song1[note+1]; if(kbhit()) break; if(fre) { outpurtb(0x43,0xb6); fre=(unsigned)(1193180L/fre); outportb(0x42,(char)(fre>>8)); outportb(0x42,(char)(fre>>8)); control=inportb(0x61); outportb(0x61,(control)|0x3); } goal=(clock_t)dur+clock(); while(goal>clock()); if(fre) outportb(0x61,control); goal=(clock_t)0; note=note+2; } }

void ss2() { int note=0,fre,dur,control; clock-t goal; while(song2[note]!=0) { fre=song2[note]; dur=song2[note+1]; if(kbhit()) break; if(fre) { outpurtb(0x43,0xb6); fre=(unsigned)(1193180L/fre); outportb(0x42,(char)(fre>>8)); outportb(0x42,(char)(fre>>8)); control=inportb(0x61); outportb(0x61,(control)|0x3); } goal=(clock-t)dur+clock(); while(goal>clock()); if(fre) outportb(0x61,control); goal=(clock-t)0; note=note+2; } } void ss() { int note=0,fre,dur,control; clock-t goal; while(song[note]!=0) { fre=song[note]; dur=song[note+1]; if(kbhit()) break; if(fre) { outpurtb(0x43,0xb6); fre=(unsigned)(1193180L/fre); outportb(0x42,(char)(fre>>8)); outportb(0x42,(char)(fre>>8)); control=inportb(0x61); outportb(0x61,(control)|0x3); } goal=(clock-t)dur+clock(); while(goal>clock()); if(fre) outportb(0x61,control); goal=(clock-t)0; note=note+2; } } main() { int n; printf("Enter input number(1-3):"); scanf("%d",&n); swith(n); { case 1:ss1(); break; case 2:ss2(); break; case 3:ss(); break; default:printf("input error \n"); } } 不过有错误!!

搜索更多相关主题的帖子: 音乐 
2005-10-19 20:22
猪也聪明
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2005-5-16
收藏
得分:0 
呵,有错误还发...

虽然我没有翅膀,可是我希望飞的高点
2005-10-21 13:53
yk87458410
Rank: 1
等 级:新手上路
帖 子:65
专家分:0
注 册:2005-9-26
收藏
得分:0 
是在51单片机单片机上运行的程序吗?

2005-10-21 15:30
socks
Rank: 1
等 级:新手上路
帖 子:79
专家分:0
注 册:2005-10-13
收藏
得分:0 
哪个编译环境下的程序?我在vc++6.0下编译有55个错误,6个警告。

虔诚的初学者~~~
2005-10-21 17:46
快速回复:[原创]音乐程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014404 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved