arm9终于可以发音了,
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include<linux/soundcard.h>
#define length 1
#define rate 11025
#define size 16
#define channels 1
unsigned char buf[length*rate*size*channels/8];
int main(){
int fd ,fr;
int status;
int arg;
fd=open("/dev/dsp",O_WRONLY);//浠ュ彧鍐欐柟寮忔墦寮€鏂囦欢
fr=open("china.wav",O_RDWR);
if(fd<0){
perror("open of /dev/dsp failed");
exit(1);
}
printf("1\n");
arg=size;//璁剧疆姣忕鐨勬瘮鐗规暟
status=ioctl( fd,SOUND_PCM_WRITE_BITS,&arg);
if(status==-1){
perror("sound_pcm_write_btts ioctl failed");
close(fd);
close(fr);
exit(1);
}
printf("2\n");
if(arg!=size){
perror("unable to set sample size");
exit(1);
}
arg=channels;//璁剧疆棰戦亾
printf("3\n");
status=ioctl((int)fd,SOUND_PCM_WRITE_CHANNELS,&arg);
if(status==-1){
perror("sound_pcm_write_channels ioctl failed");
exit(1);
}
if(arg!=channels){
perror("unable to set number of channels");
exit(1);
}
arg=rate;//璁剧疆閲囨牱鐜�
status=ioctl((int)fd,SOUND_PCM_WRITE_RATE,&arg);
if(status==-1){
perror("sound_pcm_write_rate failed");
exit(1);
}
printf("4\n");
FILE * fdr=fdopen(fr,"r");//io鍙ユ焺鍒癷o娴佺殑杞崲
FILE* fdw=fdopen(fd,"w");//
printf("5\n");
int tag=fread(buf,sizeof(buf),1,fdr);
while(!feof(fdr)){
printf("6\n");
status=fread(buf,sizeof(buf),1,fdr);
if(status <0){
printf("staus error");
goto tt;
}
status= fwrite(buf,sizeof(buf),1,fdw);
// ioctl(fd,I_FLUSH,FLUSHR);
}
tt:
fclose(fdr);
fclose(fdw);
close(fd);
close(fr);
}