亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標題:
linux音頻設備驅(qū)動問題
[打印本頁]
作者:
cc-liuwei
時間:
2008-05-06 11:20
標題:
linux音頻設備驅(qū)動問題
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>
#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);
}
使用這段代碼編譯后,為什么不能使用阿?沒有任何錯誤信息,就是不出聲!
作者:
zt868
時間:
2008-05-06 13:02
標題:
回復 #1 cc-liuwei 的帖子
請分開些,打開設備的時候不要用O_RDWR!
O_RDONLY - record
O_WRONLY - playback
OSS里面好像建議這樣做
作者:
cc-liuwei
時間:
2008-05-06 14:08
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>
#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_RDONLY);
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<500; i++)
{
if(-1 == (bytes = read(audio_fd, buf, BUF_LENGTH)))
{
perror("read");
exit(1);
}
}
close(audio_fd);
audio_fd = open("/dev/dsp", O_WRONLY);
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<500; i++)
{
if(-1 == write(audio_fd, buf, bytes))
{
perror("write");
exit(1);
}
}
printf("It'll be closed\n");
close(audio_fd);
}
是這樣寫馬?不行阿,好像打開設備就有問題……程序就是到open這里就運行不了了……
作者:
zt868
時間:
2008-05-06 19:23
標題:
回復 #3 cc-liuwei 的帖子
我用你的代碼編譯過,試過了, 代碼邏輯沒有問題。但是運行時間可能有些久,是不是你說的運行不了就是指的程序沒有結(jié)束呢?如果是這樣,那請你多等一會,如果不是,就再說了。反正在我這邊是沒有問題的.
時間久的原因:低采樣率和采樣精度,因為8K 8bit的采樣率每秒產(chǎn)生的數(shù)據(jù)量是很低的。填充總長是2K*500的buffer需要一定時間?梢赃x擇小的循環(huán)次數(shù)來做測試。
作者:
gordonyui
時間:
2008-05-23 12:37
我也用你的編程試過,是可以跑的,只是時間會比較久。
歡迎光臨 Chinaunix (http://www.72891.cn/)
Powered by Discuz! X3.2