LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1076|回复: 1

请教语音编程问题?

[复制链接]
发表于 2005-3-16 09:18:27 | 显示全部楼层 |阅读模式
--------------------------------------------------------------------------------

#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/ioctl.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/soundcard.h>

#define LENGTH 3
#define RATE 8000
#define SIZE 8
#define CHANNELS 1

unsigned char buf[LENGTH*RATE*SIZE*CHANNELS/8];

int main()
{
int fd;
int arg;
int status;
fd=open("/dev/dsp",0_RDWR);
if(fd<0)
{
printf("open of dev failed\n");
exit(1);
}

arg=SIZE;
status=ioctl(fd,SOUND_PCM_WRITE_BITS,&arg);
if(status==-1)
printf("SOUND_PCM_WRITE_BITS,ioctl\n");
if(arg!=SIZE)
printf("unable to set SOUND_PCM_WRITE_BITS\n");

arg=CHANNELS;
status=ioctl(fd,SOUND_PCM_WRITE_CHANNELS,&arg);
if(status==-1)
printf("SOUND_PCM_WRITE_CHANNELS,ioctl\n");
if(arg!=CHANNELS)
printf("unable to set SOUND_PCM_WRITE_CHANNELS\n");


arg=RATE;
status=ioctl(fd,SOUND_PCM_WRITE_RATE,&arg);
if(status==-1)
printf("SOUND_PCM_WRITE_RATE,ioctl\n");
//if(arg!=RATE)
//printf("unable to set SOUND_PCM_WRITE_RATE\n");
while(1)
{
printf("say something\n");
status=read(fd,buf,sizeof(buf));
if(status!=sizeof(buf))
printf("read wrong number of bytes\n");
printf("You said\n");
status=write(fd,buf,sizeof(buf));
if(status!=sizeof(buf))
printf("wrote wrong number of bytes\n");
status=ioctl(fd,SOUND_PCM_SYNC,0);
if(status==-1)
printf("SOUND_PCM_SYNC,ioctl\n");

}


}

交叉编译后在xscal pxa255能运行,但是
结果:
unable to set SOUND_PCM_WRITE_BITS
unable to set SOUND_PCM_WRITE_CHANNELS
然后就是不停的显示wrote wrong number of bytes
好象参数不能设置
请高手帮忙
发表于 2005-3-16 13:21:48 | 显示全部楼层
建议看一下这个:
Linux音频编程指南
http://www-900.ibm.com/developer ... l-audio/index.shtml
回复 支持 反对

使用道具 举报

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

本版积分规则

快速回复 返回顶部 返回列表