2 * oss_api.c -- useful functions to record playback using oss driver
4 * author: hackbard@hackdaworld.dyndns.org
10 #include <sys/types.h>
12 #include <sys/soundcard.h>
19 int get_dsp_cap(int fd,dsp_set *set,unsigned char print) {
20 if(ioctl(fd,SNDCTL_DSP_GETCAPS,&(set->cap))==-1) {
21 perror("SNDCTL_DSP_GETCAPS");
26 printf("device capabilities:\n\n");
27 printf("revision: %x\n",set->cap&DSP_CAP_REVISION);
28 printf("full duplex:\t%c\n",set->cap&DSP_CAP_DUPLEX?'y':'n');
29 printf("real time:\t%c\n",set->cap&DSP_CAP_REALTIME?'y':'n');
30 printf("int. buf:\t%c\n",set->cap&DSP_CAP_BATCH?'y':'n');
31 printf("coprociessor:\t%c\n",set->cap&DSP_CAP_COPROC?'y':'n');
32 printf("trigger:\t%c\n",set->cap&DSP_CAP_TRIGGER?'y':'n');
33 printf("support mmap:\t%c\n",set->cap&DSP_CAP_MMAP?'y':'n');
34 printf("multiple open:\t%c\n",set->cap&DSP_CAP_MULTI?'y':'n');
35 printf("chan binding:\t%c\n",set->cap&DSP_CAP_BIND?'y':'n');
41 int set_dsp(int fd,dsp_set *set) {
45 if(ioctl(fd,SNDCTL_DSP_SETFMT,&(set->format))==-1) {
46 perror("SNDCTL_DSP_SETFMT");
49 if(set->format!=tmp) {
50 printf("format (%d) not supported!\n",tmp);
54 if(ioctl(fd,SNDCTL_DSP_CHANNELS,&(set->channel))==-1) {
55 perror("SNDCTL_DSP_CHANNELS");
58 if(set->channel!=tmp) {
59 printf("%d-channel use not supported!\n",tmp);
63 if(ioctl(fd,SNDCTL_DSP_SPEED,&(set->freq))==-1) {
64 perror("SNDCTL_DSP_SPEED");
68 printf("%d hz not suported!\n",tmp);
71 if(ioctl(fd,SNDCTL_DSP_GETBLKSIZE,&(set->bufsize))==-1) {
72 perror("SOUNDCTL_DSP_GETBLKSIZE");
75 printf("\n\nSOUNDCTL_DSP_GETBLKSIZE = %d\n\n",set->bufsize);
80 int open_sound_dev(char *dev,int mode) {
83 if((fd=open(dev,mode))==-1) {
91 int open_file(char *file,int mode) {
95 if((fd=open(file,mode,S_IRWXU))==-1) {
100 if((fd=open(file,mode))==-1) {
109 int close_it(int fd) {