#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/soundcard.h>
#include <termios.h>
#define RATE 16000 //采样频率
#define SIZE 16 //量化位数
#define CHANNELS 1 //声道数目
#define RSIZE 80 //buf的大小,
int main(void)
{
int fd_dev_r;
int fd_dev_w;
int fd_f;
int arg;
int status;
char choice;
int i;
unsigned char buf[RSIZE]; //每次循环取得RSIZE大小的容量,放入buf,然后写入文件;
//打开声卡设备,只读方式;并对声卡进行设置
fd_dev_r= open("/dev/dsp", O_RDONLY,0777);
if (fd_dev_r < 0)
{
perror("Cannot open /dev/dsp device");
return 1;
}
arg = SIZE;
status = ioctl(fd_dev_r, SOUND_PCM_WRITE_BITS, &arg);//设置量化位数
if (status == -1)
{
perror("Cannot set SOUND_PCM_WRITE_BITS ");
return 1;
}
arg = CHANNELS;
status = ioctl(fd_dev_r, SOUND_PCM_WRITE_CHANNELS, &arg);//设置声道数
if (status == -1)
{
perror("Cannot set SOUND_PCM_WRITE_CHANNELS");
return 1;
}
arg = RATE;
status = ioctl(fd_dev_r, SOUND_PCM_WRITE_RATE, &arg);//设置采样率
if (status == -1)
{
perror("Cannot set SOUND_PCM_WRITE_WRITE");
return 1;
}
//打开声卡设备,只写方式;并对声卡进行设置
fd_dev_w = open("/dev/dsp", O_WRONLY,0777);
LINUX下实时录放音(OSS)—解决时延问题
最新推荐文章于 2024-05-29 17:33:36 发布