#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/soundcard.h>
#define LENGTH 3 /* 存储秒数 */
#define RATE 8000 /* 采样频率 */
#define SIZE 8 /* 量化位数 */
#define CHANNELS 1 /* 声道数目 */
int main()
{
int fd; /* 声音设备的文件描述符 */
int arg; /* 用于ioctl调用的参数 */
int status; /* 系统调用的返回值 */
/* 打开声音设备 */
fd = open("/dev/dsp", O_WRONLY);
if (fd < 0)
{
perror("open of /dev/dsp failed");
exit(1);
}
arg = CHANNELS;
status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
if (status == - 1)
perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
arg = RATE;
status = ioctl(fd, SNDCTL_DSP_SPEED, &arg);
arg = SIZE;
status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
arg = 0x0002000a;
status = ioctl(fd,SNDCTL_DSP_SETFRAGMENT,&arg);
status = ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &arg);
printf(" \nblk%d\n",arg );
status = ioctl(fd, SOUND_PCM_READ_RATE, &arg);
printf(" \nblk%d\n",arg );
}
在MINI6410上设置缓冲块大小不成功,在8000速率,1通道,16位的情况下,最低的缓冲块大小为2K,为什么不能设置更小,而且设置各个参数后,读出的结果会不一致,请部为什么,在开发板上它又正常。