红联Linux门户
Linux帮助

linux音频设备驱动问题

发布时间:2008-05-06 11:29:58来源:红联作者:cc-liuwei
#include
#include
#include
#include
#include
#include
#include
#include

#define BUF_LENGTH 2000
#define CHANNELS 0 /*0--single channel;2--double channel*/
#define SAMPLE_RATE 8000

int set_fmt(int audio_fd, int bits, int rate, int channel)
{
int status = -1;

if( -1 == ioctl(audio_fd, SNDCTL_DSP_SAMPLESIZE, &bits))
{
perror("ioctl SNDCTL_DSP_SAMPLESIZE");
exit(1);
}

if(-1 == ioctl(audio_fd, SNDCTL_DSP_SPEED, &rate))
{
perror("ioctl SNDCTL_DSP_SPEED");
exit(1);
}

if(-1 == ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channel))
{
perror("ioctl SNDCTL_DSP_CHANNELS");
exit(1);
}

return(0);
}

main()
{
int audio_fd = 0;
int bytes = 0;
int i = 0;
char buf[BUF_LENGTH];


audio_fd = open("/dev/dsp", O_RDWR);
if(audio_fd < 0)
{
perror("open /dev/dsp");
exit(1);
}

if(-1 == (set_fmt(audio_fd, AFMT_U8, SAMPLE_RATE, CHANNELS)))
{
perror("set_fmt");
exit(1);
}

for(i=0; i<5000; i++)
{
if(-1 == (bytes = read(audio_fd, buf, BUF_LENGTH)))
{
perror("read");
exit(1);
}
if(-1 == write(audio_fd, buf, bytes))
{
perror("write");
exit(1);
}

}

printf("It'll be closed\n");
close(audio_fd);
}
编译后无法使用,无错误信息,但是不出声,为什么阿??
文章评论

共有 0 条评论