#include #include #include #include #include #include #include main(void) { const char *path = "/dev/dsp"; int fd, ret; int n_channels = 2; int format[] = { 4096, 4096, 262144 }; int rate[] = { 1000, 82934, 1000 }; int i; fd = open(path, O_WRONLY | O_NONBLOCK, 0); if (fd < 0) { printf("Failed to open %s: %s\n", path, strerror(errno)); exit(1); } for (i = 0; i < 3; i++) { int r = rate[i]; printf("Checking rate %d\n", r); ioctl (fd, SNDCTL_DSP_RESET, 0); ret = ioctl (fd, SNDCTL_DSP_SETFMT, &format[i]); if (ret < 0) { printf("Failed to set ioctl fmt: %s\n", strerror(errno)); exit(1); } ret = ioctl (fd, SNDCTL_DSP_CHANNELS, &n_channels); if (ret < 0) { printf("Failed to set ioctl channels: %s\n", strerror(errno)); exit(1); } ret = ioctl (fd, SNDCTL_DSP_SPEED, &r); if (ret < 0) { printf("Failed to set ioctl speed: %s\n", strerror(errno)); exit(1); } printf("Rate = %d\n", r); } close(fd); return 0; }