DOS下DSP播音的编程毕业论文(3)
2015-06-03 01:35
导读:unsigned n,r,nn,i,j; char name[32]; long fermem,rr,datasize; unsigned char huge *data,huge *p; if(argc2)errexit(miss file name\n); strcpy(name,argv[1]);strcat(name,.wav); fp=-open(name,0-RDONLY);if(fp
unsigned n,r,nn,i,j;
char name[32];
long fermem,rr,datasize;
unsigned char huge *data,huge *p;
if(argc<2)errexit("miss file name\n");
strcpy(name,argv[1]);strcat(name,".wav");
fp=-open(name,0-RDONLY);if(fp=-1)errexit("Error open fil
e\n");
-read(fp,&whead,sizeof(WavHead));
if(whead.blockalign=1 && strncmp(whead.flg,"data",4)==0)
{
-read(fp,&datasize,4);//单声道WAV数据
}
else if(whead.blockalign=2 && strncmp(whead.flg,"fact"
,4)==0)
{
lseek(fp,12l,1);
-read(fp,&datasize,4);//双声道WAV数据
}
else errexit("Error file struct\n");
farmem=farcoreleft();
PortReset();//初始化DSP端口
Counter=0;//开始计时
SetTimer(NewTimer,44100);//调整时间中断频率
WritePortC(0xd1);//接通喇叭
if(farmem≥datasize)//数据量不超过内存容量
{
p=data=(unsigned char huge *)farmalloc(datasize);
n=datasize/32768;r=datasize%32768;
for(i=0;i-read(fp,p,r);
outwave(data,datasize);
}
else//数据量超过内存容量
{
nn=datasize/farmem;//分块操作的块数
rr=datasize%farmem;//最后一块的大小
n=farmem/32768;//每块read次数
r=farmem%32768;//read余零尾数
data=(unsigned char huge *)farmalloc(farmem);
for(i=0;i{
p=data;
for(j=0;j-read(fp,p,r);
//读入内存
outwave(data,farmem);//发送声音数据
}
p=data;
n=rr/32768;r=rr%32768;//最后块的操作
for(i=0;i-read(fp,p,r);
//读入
outwave(data,rr);//发送
}
WritePortC(0xd3);//断开喇叭
RestoreTimer();//恢复时间中断
farfree(data);
-close(fp);
}
void PortReset()//初始化DSP端口
{
cnt1=n1;