C模拟电子琴程序
时间:2008-05-12 13:49:07
来源:论坛整理 作者: 编辑:chinaitzhe
希望给点思路
网友回复:最简单的思路,找到某个平台的下的发声函数(比如古老的TC下的sound(int frequency))
然后得到键盘输入,按的是c就发c的音,并持续一定时间.
cdefgab
1234567
^^
网友回复:就是用tc的sound,俺家里没准还有这种程序。
网友回复:以前玩过这个,在TC下的一个发音程序,希望对LZ有点用
#include <stdio.h>
#include <dos.h>
#define L1 1000
#define L2 L1/2
#define L3 L1/4
void interrupt(*old_int9)();
int HZ[4][7]={ {131,147,165,175,196,220,247},
{262,294,330,349,392,440,494},
{523,587,659,698,784,880,988},
{1047,1174,1319,1568,1760,1976}};
int *s;
int buf[100]={11,L1,12,L3,13,L2,14,L2,15,L2,16,L2,17,L2,21,L2,22,L2,23,L2,24,L2,25,L2,26,L2,27,L2,31,L2,0,0,0};
void Sound(int freq)
{
asm{
mov al, 0B6h
out 43h, al
mov dx, 12h
mov ax, 34DEh
div freq
out 42h, al
mov al, ah
out 42h, al
in al, 61h
or al, 3
out 61h, al
}
}
void Nosound(void)
{
asm{
in al, 61h
and al, 252
out 61h, al
}
}
void Delay(int clicks)
{
unsigned int far *clock=(unsigned int far *)0x0000046CL;
unsigned int now;
now=*clock;
while(abs(*clock-now) <clicks){}
}
void interrupt new_int9()
{
static int count,tt=0;
count ;
if(*s!=0)
{
if(count>=tt)
{
Sound(HZ[*s/10][*s-1]);
s ;
tt=*s*18.2/1000;
s ;
count=0;
}
}
else
Nosound();
(*old_int9)();
}
void play(int *ms)
{
s=ms;
old_int9=getvect(0x1c);
setvect(0x1c,new_int9);
}
void main(void)
{
int i;
play(buf);
for(i=0;i <20000;i )
printf("%d,",i);
while(*s!=0&&!bioskey(0));
Nosound();
setvect(0x1c,*old_int9);
}
网友回复:谢谢大家的帮助,我现在用的是VC6。0没有用TC那几个发生函数还可以使用吗?
网友回复:UP
等人来解释下
网友回复:UP!
网友回复:VC下有Windows SDK下的函数可以用.
PlaySound
The PlaySound function plays a sound specified by the given filename, resource, or system event. (A system event may be associated with a sound in the registry or in the WIN.INI file.)
BOOL PlaySound(
LPCSTR pszSound,
HMODULE hmod,
DWORD fdwSound
);
sndPlaySound
The sndPlaySound function plays a waveform sound specified either by a filename or by an entry in the registry or the WIN.INI file. This function offers a subset of the functionality of the PlaySound function; sndPlaySound is being maintained for backward compatibility.
BOOL sndPlaySound(
LPCSTR lpszSound,
UINT fuSound
);
自己Google下吧,用VC要多用MSDN(什么,不知道MSDN,那也Google下吧).
在Windows下还可以用DirectSound提供个函数,还是自己Google.
网友回复:似乎没那么简单,呵呵.
关键字:模拟,电子琴,程序,
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面