现在我用S3C2410在linux环境下开发音频部分,播放功能可以正常实现,但是录音部分有问题,具体问题是把PC上Linux环境下的录音程序移植到ARM上,它的执行速度要比PC上快10倍左右,不知道是哪里出现了问题?有相关经历的请指点一下。谢谢~
录音程序如下: #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 RATE 8000 #define SIZE 16 #define CHANNELS 1 #define AUDIO_DEVICE "/dev/dsp"
void delay(int i) { while(i--); } int main(int argc,char * argv[]) { int fd,id,i=50,j=0; int arg; int status; char filename[30] ="record.wav"; char buf[1024];
if((id = open(filename, O_RDWR | O_CREAT)) < 0) { printf("Can't open output file!\n"); exit (1); } if ((fd = open(AUDIO_DEVICE, O_RDWR | O_NONBLOCK)) < 0) { printf("open of /dev/dsp failed"); exit(1); } fcntl (fd, F_SETFL, fcntl (fd, F_GETFL) & ~O_NONBLOCK); arg = SIZE; status = ioctl(fd,SOUND_PCM_WRITE_BITS,&arg); if(status == -1) printf("SOUND_PCM_WRITE_BITS ioctl failed"); if(arg != SIZE) printf("unable to set sample size"); arg = CHANNELS; status = ioctl(fd,SOUND_PCM_WRITE_CHANNELS,&arg); if(status == -1) printf("SOUND_PCM_WRITE_CHANNELS ioctl failed"); if(arg != CHANNELS) printf("unable to set number of channels"); arg = RATE; status = ioctl(fd,SOUND_PCM_WRITE_RATE,&arg); if(status == -1) printf("SOUND_PCM_WRITE_RATE ioctl failed");
printf("Say something:\n"); while(i--) { read(fd,buf,sizeof(buf)); write(id,buf,sizeof(buf)); printf("you are saying %d\n",j++); } close(id); close(fd); return 0; } |