4 * audio-pcm.c - Scope out the PCM audio stuff
10 #if defined(HAVE_MACHINE_SOUNDCARD_H) || defined(HAVE_SYS_SOUNDCARD_H)
13 #include "ntp_stdlib.h"
14 #include "ntp_syslog.h"
19 #include "ntp_string.h"
21 #ifdef HAVE_SYS_IOCTL_H
22 #include <sys/ioctl.h>
23 #endif /* HAVE_SYS_IOCTL_H */
27 #ifdef HAVE_MACHINE_SOUNDCARD_H
28 # include <machine/soundcard.h>
29 # define PCM_STYLE_SOUND
31 # ifdef HAVE_SYS_SOUNDCARD_H
32 # include <sys/soundcard.h>
33 # define PCM_STYLE_SOUND
40 static int ctl_fd
; /* audio control file descriptor */
42 const char *m_names
[SOUND_MIXER_NRDEVICES
] = SOUND_DEVICE_NAMES
;
50 if (format
& AFMT_MU_LAW
) printf("MU_LAW ");
51 if (format
& AFMT_A_LAW
) printf("A_LAW ");
52 if (format
& AFMT_IMA_ADPCM
) printf("IMA_ADPCM ");
53 if (format
& AFMT_U8
) printf("U8 ");
54 if (format
& AFMT_S16_LE
) printf("S16_LE ");
55 if (format
& AFMT_S16_BE
) printf("S16_BE ");
56 if (format
& AFMT_S8
) printf("S8 ");
57 if (format
& AFMT_U16_LE
) printf("U16_LE ");
58 if (format
& AFMT_U16_BE
) printf("U16_BE ");
59 if (format
& AFMT_MPEG
) printf("MPEG ");
60 if (format
& AFMT_AC3
) printf("AC3 ");
72 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; ++i
)
73 if ((1 << i
) & mixer
) {
76 printf("%s", m_names
[i
]);
85 int unit
= 0; /* device unit (0-3) */
86 # define AI_DEV "/dev/audio%d"
87 # define AC_DEV "/dev/mixer%d"
90 struct snd_size s_size
;
95 char *dname
= ai_dev
; /* device name */
97 int devmask
= 0, recmask
= 0, recsrc
= 0;
99 (void)sprintf(ai_dev
, AI_DEV
, unit
);
100 (void)sprintf(ac_dev
, AC_DEV
, unit
);
103 * Open audio device. Do not complain if not there.
105 fd
= open(dname
, O_RDWR
| O_NONBLOCK
, 0777);
110 * Open audio control device.
112 ctl_fd
= open(actl
, O_RDWR
);
114 fprintf(stderr
, "invalid control device <%s>\n", actl
);
119 printf("input: <%s> %d\n", dname
, fd
);
120 printf("control: <%s> %d\n", actl
, ctl_fd
);
122 if (ioctl(ctl_fd
, SOUND_MIXER_READ_DEVMASK
, &devmask
) == -1)
123 printf("SOUND_MIXER_READ_DEVMASK: %s\n", strerror(errno
));
124 if (ioctl(ctl_fd
, SOUND_MIXER_READ_RECMASK
, &recmask
) == -1)
125 printf("SOUND_MIXER_READ_RECMASK: %s\n", strerror(errno
));
126 if (ioctl(ctl_fd
, SOUND_MIXER_READ_RECSRC
, &recsrc
) == -1)
127 printf("SOUND_MIXER_READ_RECSRC: %s\n", strerror(errno
));
129 printf("devmask: %#x recmask: %#x recsrc: %#x\n",
130 devmask
, recmask
, recsrc
);
131 printf("Devmask: "); d_mixer(devmask
);
132 printf("Recmask: "); d_mixer(recmask
);
133 printf("RecSrc: "); d_mixer(recsrc
);
136 * Set audio device parameters.
140 if (ioctl(fd
, AIOGSIZE
, &s_size
) == -1)
141 printf("AIOGSIZE: %s\n", strerror(errno
));
143 printf("play_size %d, rec_size %d\n",
144 s_size
.play_size
, s_size
.rec_size
);
146 if (ioctl(fd
, AIOGFMT
, &s_c_p
) == -1)
147 printf("AIOGFMT: %s\n", strerror(errno
));
149 printf("play_rate %lu, rec_rate %lu, play_format %#lx, rec_format %#lx\n",
150 s_c_p
.play_rate
, s_c_p
.rec_rate
, s_c_p
.play_format
, s_c_p
.rec_format
);
151 printf("Play format: "); d_fmt(s_c_p
.play_format
);
152 printf("Rec format: "); d_fmt(s_c_p
.rec_format
);
156 #endif /* HAVE_{MACHINE_SOUNDCARD,SYS_SOUNDCARD}_H */