Subject: audio{record|play}: why audioctl device?
To: None <tech-userlevel@netbsd.org>
From: Jaromir Dolecek <jdolecek@netbsd.org>
List: tech-userlevel
Date: 01/24/2002 21:28:20
--ELM717629203-855-0_
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII
Hi,
I've been using audiorecord and audioplay with audio1.
I've bumped into fact that the program sets the device parameters
via audioctl device, and thus one needs to call the program like
'audioplay -d /dev/audio1 -C /dev/audioctl1 foo.au'.
This is, well, quite inconvenient.
I've started to implement some code to try to "guess" the appropriate
audioctl device for give audio device. Hoever, I realized it seems
there is actually no need for this. All the ioctls can be done with
audio device directly.
So I wonder if the usage of audioctl there is actually necessary?
I'm appending patch (not tested, ATM).
Jarda
--
Jaromir Dolecek <jdolecek@NetBSD.org> http://www.NetBSD.org/Ports/i386/ps2.html
-= Those who would give up liberty for a little temporary safety deserve =-
-= neither liberty nor safety, and will lose both. -- Benjamin Franklin =-
--ELM717629203-855-0_
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=ISO-8859-2
Content-Disposition: attachment; filename=ee
Index: play/play.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/audio/play/play.c,v
retrieving revision 1.31
diff -u -p -r1.31 play.c
--- play/play.c 2002/01/15 17:00:53 1.31
+++ play/play.c 2002/01/24 20:24:29
@@ -67,7 +67,7 @@ int channels;
char const *play_errstring = NULL;
size_t bufsize;
-int audiofd, ctlfd;
+int audiofd;
int exitstatus = EXIT_SUCCESS;
int
@@ -80,9 +80,8 @@ main(argc, argv)
int iflag = 0;
int verbose = 0;
const char *device = 0;
- const char *ctldev = 0;
- while ((ch = getopt(argc, argv, "b:C:c:d:e:fhip:P:qs:Vv:")) != -1) {
+ while ((ch = getopt(argc, argv, "b:c:d:e:fhip:P:qs:Vv:")) != -1) {
switch (ch) {
case 'b':
decode_int(optarg, &balance);
@@ -94,9 +93,6 @@ main(argc, argv)
if (channels < 0)
errx(1, "channels must be positive");
break;
- case 'C':
- ctldev = optarg;
- break;
case 'd':
device = optarg;
break;
@@ -163,25 +159,19 @@ main(argc, argv)
if (device == NULL && (device = getenv("AUDIODEVICE")) == NULL &&
(device = getenv("AUDIODEV")) == NULL) /* Sun compatibility */
device = _PATH_AUDIO;
- if (ctldev == NULL && (ctldev = getenv("AUDIOCTLDEVICE")) == NULL)
- ctldev = _PATH_AUDIOCTL;
audiofd = open(device, O_WRONLY);
#ifdef _PATH_OAUDIO
/* Allow the non-unit device to be used. */
if (audiofd < 0 && device == _PATH_AUDIO) {
device = _PATH_OAUDIO;
- ctldev = _PATH_OAUDIOCTL;
audiofd = open(device, O_WRONLY);
}
#endif
if (audiofd < 0)
err(1, "failed to open %s", device);
- ctlfd = open(ctldev, O_RDWR);
- if (ctlfd < 0)
- err(1, "failed to open %s", ctldev);
- if (ioctl(ctlfd, AUDIO_GETINFO, &info) < 0)
+ if (ioctl(audiofd, AUDIO_GETINFO, &info) < 0)
err(1, "failed to get audio info");
bufsize = info.play.buffer_size;
if (bufsize < 32 * 1024)
@@ -208,7 +198,7 @@ cleanup(signo)
close(audiofd);
(void)ioctl(audiofd, AUDIO_FLUSH, NULL);
- (void)ioctl(ctlfd, AUDIO_SETINFO, &info);
+ (void)ioctl(audiofd, AUDIO_SETINFO, &info);
exit(exitstatus);
}
@@ -266,7 +256,7 @@ play(file)
* get the header length and set up the audio device
*/
if ((hdrlen = audioctl_write_fromhdr(addr,
- (size_t)filesize, ctlfd, &datasize)) < 0) {
+ (size_t)filesize, audiofd, &datasize)) < 0) {
if (play_errstring)
errx(1, "%s: %s", play_errstring, file);
else
@@ -322,7 +312,7 @@ play_fd(file, fd)
return;
err(1, "unexpected EOF");
}
- hdrlen = audioctl_write_fromhdr(buffer, nr, ctlfd, &datasize);
+ hdrlen = audioctl_write_fromhdr(buffer, nr, audiofd, &datasize);
if (hdrlen < 0) {
if (play_errstring)
errx(1, "%s: %s", play_errstring, file);
Index: record/record.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/audio/record/record.c,v
retrieving revision 1.21
diff -u -p -r1.21 record.c
--- record/record.c 2002/01/15 23:48:53 1.21
+++ record/record.c 2002/01/24 20:24:29
@@ -53,11 +53,10 @@
audio_info_t info, oinfo;
ssize_t total_size = -1;
const char *device;
-const char *ctldev;
int format = AUDIO_FORMAT_SUN;
char *header_info;
char default_info[8] = { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' };
-int audiofd, ctlfd, outfd;
+int audiofd, outfd;
int qflag, aflag, fflag;
int verbose;
int monitor_gain, omonitor_gain;
@@ -92,7 +91,7 @@ main(argc, argv)
size_t len, bufsize;
int ch, no_time_limit = 1;
- while ((ch = getopt(argc, argv, "ab:C:F:c:d:e:fhi:m:P:p:qt:s:Vv:")) != -1) {
+ while ((ch = getopt(argc, argv, "ab:F:c:d:e:fhi:m:P:p:qt:s:Vv:")) != -1) {
switch (ch) {
case 'a':
aflag++;
@@ -102,9 +101,6 @@ main(argc, argv)
if (balance < 0 || balance > 63)
errx(1, "balance must be between 0 and 63\n");
break;
- case 'C':
- ctldev = optarg;
- break;
case 'F':
format = audio_format_from_str(optarg);
if (format < 0)
@@ -189,21 +185,16 @@ main(argc, argv)
if (device == NULL && (device = getenv("AUDIODEVICE")) == NULL &&
(device = getenv("AUDIODEV")) == NULL) /* Sun compatibility */
device = _PATH_AUDIO;
- if (ctldev == NULL && (ctldev = getenv("AUDIOCTLDEVICE")) == NULL)
- ctldev = _PATH_AUDIOCTL;
audiofd = open(device, O_RDONLY);
if (audiofd < 0)
err(1, "failed to open %s", device);
- ctlfd = open(ctldev, O_RDWR);
- if (ctlfd < 0)
- err(1, "failed to open %s", ctldev);
/*
* work out the buffer size to use, and allocate it. also work out
* what the old monitor gain value is, so that we can reset it later.
*/
- if (ioctl(ctlfd, AUDIO_GETINFO, &oinfo) < 0)
+ if (ioctl(audiofd, AUDIO_GETINFO, &oinfo) < 0)
err(1, "failed to get audio info");
bufsize = oinfo.record.buffer_size;
if (bufsize < 32 * 1024)
@@ -261,7 +252,7 @@ main(argc, argv)
monitor_gain = oinfo.monitor_gain;
info.mode = AUMODE_RECORD;
- if (ioctl(ctlfd, AUDIO_SETINFO, &info) < 0)
+ if (ioctl(audiofd, AUDIO_SETINFO, &info) < 0)
err(1, "failed to reset audio info");
signal(SIGINT, cleanup);
@@ -300,16 +291,15 @@ cleanup(signo)
int signo;
{
- close(audiofd);
rewrite_header();
close(outfd);
if (omonitor_gain) {
AUDIO_INITINFO(&info);
info.monitor_gain = omonitor_gain;
- if (ioctl(ctlfd, AUDIO_SETINFO, &info) < 0)
+ if (ioctl(audiofd, AUDIO_SETINFO, &info) < 0)
err(1, "failed to reset audio info");
}
- close(ctlfd);
+ close(audiofd);
exit(0);
}
@@ -650,7 +640,6 @@ usage()
fprintf(stderr, "Usage: %s [-afhqV] [options] {files ...|-}\n",
getprogname());
fprintf(stderr, "Options:\n\t"
- "-C audio control device\n\t"
"-F format\n\t"
"-b balance (0-63)\n\t"
"-c channels\n\t"
--ELM717629203-855-0_--