[ZLG-ARM] 嵌入式linux下S3C2410录音

[复制链接]
2239|1
 楼主| initer 发表于 2009-4-7 15:05 | 显示全部楼层 |阅读模式
现在我用S3C2410在linux环境下开发音频部分,播放功能可以正常实现,但是录音部分有问题,具体问题是把PC上Linux环境下的录音程序移植到ARM上,它的执行速度要比PC上快10倍左右,不知道是哪里出现了问题?有相关经历的请指点一下。谢谢~<br /><br />录音程序如下:<br />#include&ltunistd.h&gt &nbsp;<br />#include&ltfcntl.h&gt &nbsp;<br />#include&ltsys/types.h&gt &nbsp;<br />#include&ltsys/ioctl.h&gt &nbsp;<br />#include&ltstdlib.h&gt &nbsp;<br />#include&ltstdio.h&gt &nbsp;<br />#include&ltlinux/soundcard.h&gt &nbsp;<br /> <br />#define&nbsp;RATE&nbsp;8000 &nbsp;<br />#define&nbsp;SIZE&nbsp;16 &nbsp;<br />#define&nbsp;CHANNELS&nbsp;1 <br />#define&nbsp;AUDIO_DEVICE &quot;/dev/dsp&quot;<br /><br />void&nbsp;delay(int&nbsp;i)<br />{<br />  while(i--);<br />}<br /> <br />int&nbsp;main(int&nbsp;argc,char&nbsp;*&nbsp;argv[]) <br />{ <br />  int&nbsp;fd,id,i=50,j=0; <br />  int&nbsp;arg; <br />  int&nbsp;status; <br />  char&nbsp;filename[30]&nbsp;=&quot;record.wav&quot;;<br />  char&nbsp;buf[1024]; <br /><br />  if((id&nbsp;=&nbsp;open(filename,&nbsp;O_RDWR&nbsp;|&nbsp;O_CREAT))&nbsp;&lt&nbsp;0) <br />  { <br />    printf(&quot;Can't&nbsp;open&nbsp;output&nbsp;file!\n&quot;); <br />    exit&nbsp;(1); <br />  } <br />  if&nbsp;((fd&nbsp;=&nbsp;open(AUDIO_DEVICE,&nbsp;O_RDWR&nbsp;|&nbsp;O_NONBLOCK))&nbsp;&lt&nbsp;0) <br />  { <br />    printf(&quot;open&nbsp;of&nbsp;/dev/dsp&nbsp;failed&quot;); <br />    exit(1); <br />  } <br />  fcntl&nbsp;(fd,&nbsp;F_SETFL,&nbsp;fcntl&nbsp;(fd,&nbsp;F_GETFL)&nbsp;&&nbsp;~O_NONBLOCK);<br />  <br />  arg&nbsp;=&nbsp;SIZE; <br />  status&nbsp;=&nbsp;ioctl(fd,SOUND_PCM_WRITE_BITS,&arg); <br />  if(status&nbsp;==&nbsp;-1) <br />    printf(&quot;SOUND_PCM_WRITE_BITS&nbsp;ioctl&nbsp;failed&quot;); <br />  if(arg&nbsp;!=&nbsp;SIZE) <br />    printf(&quot;unable&nbsp;to&nbsp;set&nbsp;sample&nbsp;size&quot;); <br />   <br />  arg&nbsp;=&nbsp;CHANNELS; &nbsp;<br />  status&nbsp;=&nbsp;ioctl(fd,SOUND_PCM_WRITE_CHANNELS,&arg); <br />  if(status&nbsp;==&nbsp;-1) <br />    printf(&quot;SOUND_PCM_WRITE_CHANNELS&nbsp;ioctl&nbsp;failed&quot;); <br />  if(arg&nbsp;!=&nbsp;CHANNELS) <br />    printf(&quot;unable&nbsp;to&nbsp;set&nbsp;number&nbsp;of&nbsp;channels&quot;); <br />   <br />  arg&nbsp;=&nbsp;RATE; <br />  status&nbsp;=&nbsp;ioctl(fd,SOUND_PCM_WRITE_RATE,&arg); <br />  if(status&nbsp;==&nbsp;-1) <br />    printf(&quot;SOUND_PCM_WRITE_RATE&nbsp;ioctl&nbsp;failed&quot;); <br /><br />  printf(&quot;Say&nbsp;something:\n&quot;); <br />  while(i--) <br />  { <br />    read(fd,buf,sizeof(buf)); <br />    write(id,buf,sizeof(buf)); <br />    printf(&quot;you&nbsp;are&nbsp;saying&nbsp;%d\n&quot;,j++);<br />  } <br />  close(id); <br />  close(fd); <br />  return&nbsp;0; <br />}
msleep 发表于 2009-4-7 16:02 | 显示全部楼层

看看时钟,你说快很多,那很显然就是时钟的问题了

  
您需要登录后才可以回帖 登录 | 注册

本版积分规则

16

主题

111

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部