|
--------------------------------------------------------------------------------
#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
好象参数不能设置
请高手帮忙 |
|