Module Name: src Committed By: mrg Date: Wed Aug 5 06:54:39 UTC 2015
Modified Files: src/usr.bin/audio/common: audio.c libaudio.h sun.c wav.c src/usr.bin/audio/play: play.c src/usr.bin/audio/record: record.c Log Message: rename struct write_info as struct track_info, and the variable name 'wi' as 'ti', as this info is useful for reading as well. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/audio/common/audio.c cvs rdiff -u -r1.19 -r1.20 src/usr.bin/audio/common/libaudio.h cvs rdiff -u -r1.8 -r1.9 src/usr.bin/audio/common/sun.c cvs rdiff -u -r1.12 -r1.13 src/usr.bin/audio/common/wav.c cvs rdiff -u -r1.54 -r1.55 src/usr.bin/audio/play/play.c cvs rdiff -u -r1.53 -r1.54 src/usr.bin/audio/record/record.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/audio/common/audio.c diff -u src/usr.bin/audio/common/audio.c:1.24 src/usr.bin/audio/common/audio.c:1.25 --- src/usr.bin/audio/common/audio.c:1.24 Sun Jun 21 06:06:01 2015 +++ src/usr.bin/audio/common/audio.c Wed Aug 5 06:54:39 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: audio.c,v 1.24 2015/06/21 06:06:01 mrg Exp $ */ +/* $NetBSD: audio.c,v 1.25 2015/08/05 06:54:39 mrg Exp $ */ /* * Copyright (c) 1999 Matthew R. Green @@ -32,7 +32,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: audio.c,v 1.24 2015/06/21 06:06:01 mrg Exp $"); +__RCSID("$NetBSD: audio.c,v 1.25 2015/08/05 06:54:39 mrg Exp $"); #endif @@ -178,21 +178,21 @@ audio_errstring(int errval) } void -write_header(struct write_info *wi) +write_header(struct track_info *ti) { struct iovec iv[3]; int veclen, left, tlen; void *hdr; size_t hdrlen; - switch (wi->format) { + switch (ti->format) { case AUDIO_FORMAT_DEFAULT: case AUDIO_FORMAT_SUN: - if (sun_prepare_header(wi, &hdr, &hdrlen, &left) != 0) + if (sun_prepare_header(ti, &hdr, &hdrlen, &left) != 0) return; break; case AUDIO_FORMAT_WAV: - if (wav_prepare_header(wi, &hdr, &hdrlen, &left) != 0) + if (wav_prepare_header(ti, &hdr, &hdrlen, &left) != 0) return; break; case AUDIO_FORMAT_NONE: @@ -209,9 +209,9 @@ write_header(struct write_info *wi) iv[veclen].iov_len = hdrlen; tlen += iv[veclen++].iov_len; } - if (wi->header_info) { - iv[veclen].iov_base = wi->header_info; - iv[veclen].iov_len = (int)strlen(wi->header_info) + 1; + if (ti->header_info) { + iv[veclen].iov_base = ti->header_info; + iv[veclen].iov_len = (int)strlen(ti->header_info) + 1; tlen += iv[veclen++].iov_len; } if (left) { @@ -223,20 +223,20 @@ write_header(struct write_info *wi) if (tlen == 0) return; - if (writev(wi->outfd, iv, veclen) != tlen) + if (writev(ti->outfd, iv, veclen) != tlen) err(1, "could not write audio header"); } write_conv_func -write_get_conv_func(struct write_info *wi) +write_get_conv_func(struct track_info *ti) { - switch (wi->format) { + switch (ti->format) { case AUDIO_FORMAT_DEFAULT: case AUDIO_FORMAT_SUN: - return sun_write_get_conv_func(wi); + return sun_write_get_conv_func(ti); case AUDIO_FORMAT_WAV: - return wav_write_get_conv_func(wi); + return wav_write_get_conv_func(ti); case AUDIO_FORMAT_NONE: return NULL; default: Index: src/usr.bin/audio/common/libaudio.h diff -u src/usr.bin/audio/common/libaudio.h:1.19 src/usr.bin/audio/common/libaudio.h:1.20 --- src/usr.bin/audio/common/libaudio.h:1.19 Tue Dec 30 01:22:09 2014 +++ src/usr.bin/audio/common/libaudio.h Wed Aug 5 06:54:39 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: libaudio.h,v 1.19 2014/12/30 01:22:09 mrg Exp $ */ +/* $NetBSD: libaudio.h,v 1.20 2015/08/05 06:54:39 mrg Exp $ */ /* * Copyright (c) 1999, 2009 Matthew R. Green @@ -157,7 +157,7 @@ typedef struct { } __packed wav_audiohdrextensible; /* returns size of header, or -ve for failure */ -ssize_t audio_wav_parse_hdr (void *, size_t, u_int *, u_int *, u_int *, u_int *, size_t *); +ssize_t audio_wav_parse_hdr (void *, size_t, u_int *, u_int *, u_int *, u_int *, off_t *); extern int verbose; @@ -185,34 +185,34 @@ void decode_time (const char *, struct t void decode_encoding (const char *, int *); /* - * Write a sun/wav header, shared between record and merge. + * Track info, for reading/writing sun/wav header. * * Note that write_header() may change the values of format, * encoding. */ -struct write_info { +struct track_info { int outfd; char *header_info; int format; int encoding; int precision; int qflag; - ssize_t total_size; + off_t total_size; int sample_rate; int channels; }; typedef void (*write_conv_func) (u_char *, int); -void write_header (struct write_info *); -write_conv_func write_get_conv_func(struct write_info *); +void write_header (struct track_info *); +write_conv_func write_get_conv_func(struct track_info *); /* backends for the above */ -int sun_prepare_header(struct write_info *wi, void **hdrp, size_t *lenp, int *leftp); -int wav_prepare_header(struct write_info *wi, void **hdrp, size_t *lenp, int *leftp); -write_conv_func sun_write_get_conv_func(struct write_info *wi); -write_conv_func wav_write_get_conv_func(struct write_info *wi); +int sun_prepare_header(struct track_info *ti, void **hdrp, size_t *lenp, int *leftp); +int wav_prepare_header(struct track_info *ti, void **hdrp, size_t *lenp, int *leftp); +write_conv_func sun_write_get_conv_func(struct track_info *ti); +write_conv_func wav_write_get_conv_func(struct track_info *ti); extern char audio_default_info[8]; Index: src/usr.bin/audio/common/sun.c diff -u src/usr.bin/audio/common/sun.c:1.8 src/usr.bin/audio/common/sun.c:1.9 --- src/usr.bin/audio/common/sun.c:1.8 Fri Aug 30 20:57:26 2013 +++ src/usr.bin/audio/common/sun.c Wed Aug 5 06:54:39 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: sun.c,v 1.8 2013/08/30 20:57:26 mrg Exp $ */ +/* $NetBSD: sun.c,v 1.9 2015/08/05 06:54:39 mrg Exp $ */ /* * Copyright (c) 2002 Matthew R. Green @@ -32,7 +32,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: sun.c,v 1.8 2013/08/30 20:57:26 mrg Exp $"); +__RCSID("$NetBSD: sun.c,v 1.9 2015/08/05 06:54:39 mrg Exp $"); #endif @@ -110,76 +110,76 @@ audio_encoding_to_sun(int encoding, int } int -sun_prepare_header(struct write_info *wi, void **hdrp, size_t *lenp, int *leftp) +sun_prepare_header(struct track_info *ti, void **hdrp, size_t *lenp, int *leftp) { static int warned = 0; static sun_audioheader auh; - int sunenc, oencoding = wi->encoding; + int sunenc, oencoding = ti->encoding; /* only perform conversions if we don't specify the encoding */ - switch (wi->encoding) { + switch (ti->encoding) { case AUDIO_ENCODING_ULINEAR_LE: #if BYTE_ORDER == LITTLE_ENDIAN case AUDIO_ENCODING_ULINEAR: #endif - if (wi->precision == 16 || wi->precision == 32) - wi->encoding = AUDIO_ENCODING_SLINEAR_BE; + if (ti->precision == 16 || ti->precision == 32) + ti->encoding = AUDIO_ENCODING_SLINEAR_BE; break; case AUDIO_ENCODING_ULINEAR_BE: #if BYTE_ORDER == BIG_ENDIAN case AUDIO_ENCODING_ULINEAR: #endif - if (wi->precision == 16 || wi->precision == 32) - wi->encoding = AUDIO_ENCODING_SLINEAR_BE; + if (ti->precision == 16 || ti->precision == 32) + ti->encoding = AUDIO_ENCODING_SLINEAR_BE; break; case AUDIO_ENCODING_SLINEAR_LE: #if BYTE_ORDER == LITTLE_ENDIAN case AUDIO_ENCODING_SLINEAR: #endif - if (wi->precision == 16 || wi->precision == 32) - wi->encoding = AUDIO_ENCODING_SLINEAR_BE; + if (ti->precision == 16 || ti->precision == 32) + ti->encoding = AUDIO_ENCODING_SLINEAR_BE; break; #if BYTE_ORDER == BIG_ENDIAN case AUDIO_ENCODING_SLINEAR: - wi->encoding = AUDIO_ENCODING_SLINEAR_BE; + ti->encoding = AUDIO_ENCODING_SLINEAR_BE; break; #endif } /* if we can't express this as a Sun header, don't write any */ - if (audio_encoding_to_sun(wi->encoding, wi->precision, &sunenc) != 0) { - if (!wi->qflag && !warned) { + if (audio_encoding_to_sun(ti->encoding, ti->precision, &sunenc) != 0) { + if (!ti->qflag && !warned) { const char *s = audio_enc_from_val(oencoding); if (s == NULL) s = "(unknown)"; warnx("failed to convert to sun encoding from %s " "(precision %d);\nSun audio header not written", - s, wi->precision); + s, ti->precision); } - wi->format = AUDIO_FORMAT_NONE; + ti->format = AUDIO_FORMAT_NONE; warned = 1; return -1; } auh.magic = htonl(AUDIO_FILE_MAGIC); - if (wi->outfd == STDOUT_FILENO) + if (ti->outfd == STDOUT_FILENO) auh.data_size = htonl(AUDIO_UNKNOWN_SIZE); - else if (wi->total_size != -1) - auh.data_size = htonl(wi->total_size); + else if (ti->total_size != -1) + auh.data_size = htonl(ti->total_size); else auh.data_size = 0; auh.encoding = htonl(sunenc); - auh.sample_rate = htonl(wi->sample_rate); - auh.channels = htonl(wi->channels); - if (wi->header_info) { + auh.sample_rate = htonl(ti->sample_rate); + auh.channels = htonl(ti->channels); + if (ti->header_info) { int len, infolen; - infolen = ((len = strlen(wi->header_info)) + 7) & 0xfffffff8; + infolen = ((len = strlen(ti->header_info)) + 7) & 0xfffffff8; *leftp = infolen - len; auh.hdr_size = htonl(sizeof(auh) + infolen); } else { @@ -192,20 +192,20 @@ sun_prepare_header(struct write_info *wi } write_conv_func -sun_write_get_conv_func(struct write_info *wi) +sun_write_get_conv_func(struct track_info *ti) { write_conv_func conv_func = NULL; /* only perform conversions if we don't specify the encoding */ - switch (wi->encoding) { + switch (ti->encoding) { case AUDIO_ENCODING_ULINEAR_LE: #if BYTE_ORDER == LITTLE_ENDIAN case AUDIO_ENCODING_ULINEAR: #endif - if (wi->precision == 16) + if (ti->precision == 16) conv_func = change_sign16_swap_bytes_le; - else if (wi->precision == 32) + else if (ti->precision == 32) conv_func = change_sign32_swap_bytes_le; break; @@ -213,9 +213,9 @@ sun_write_get_conv_func(struct write_inf #if BYTE_ORDER == BIG_ENDIAN case AUDIO_ENCODING_ULINEAR: #endif - if (wi->precision == 16) + if (ti->precision == 16) conv_func = change_sign16_be; - else if (wi->precision == 32) + else if (ti->precision == 32) conv_func = change_sign32_be; break; @@ -223,9 +223,9 @@ sun_write_get_conv_func(struct write_inf #if BYTE_ORDER == LITTLE_ENDIAN case AUDIO_ENCODING_SLINEAR: #endif - if (wi->precision == 16) + if (ti->precision == 16) conv_func = swap_bytes; - else if (wi->precision == 32) + else if (ti->precision == 32) conv_func = swap_bytes32; break; } Index: src/usr.bin/audio/common/wav.c diff -u src/usr.bin/audio/common/wav.c:1.12 src/usr.bin/audio/common/wav.c:1.13 --- src/usr.bin/audio/common/wav.c:1.12 Fri Oct 18 20:47:06 2013 +++ src/usr.bin/audio/common/wav.c Wed Aug 5 06:54:39 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: wav.c,v 1.12 2013/10/18 20:47:06 christos Exp $ */ +/* $NetBSD: wav.c,v 1.13 2015/08/05 06:54:39 mrg Exp $ */ /* * Copyright (c) 2002, 2009 Matthew R. Green @@ -33,7 +33,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: wav.c,v 1.12 2013/10/18 20:47:06 christos Exp $"); +__RCSID("$NetBSD: wav.c,v 1.13 2015/08/05 06:54:39 mrg Exp $"); #endif @@ -93,7 +93,7 @@ wav_enc_from_val(int encoding) */ ssize_t audio_wav_parse_hdr(void *hdr, size_t sz, u_int *enc, u_int *prec, - u_int *sample, u_int *channels, size_t *datasize) + u_int *sample, u_int *channels, off_t *datasize) { char *where = hdr, *owhere; wav_audioheaderpart part; @@ -206,7 +206,7 @@ audio_wav_parse_hdr(void *hdr, size_t sz if (prec) *prec = newprec; if (datasize) - *datasize = (size_t)getle32(part.len); + *datasize = (off_t)getle32(part.len); return (owhere - (char *)hdr + 8); } return (AUDIO_EWAVNODATA); @@ -218,7 +218,7 @@ audio_wav_parse_hdr(void *hdr, size_t sz * and expect our caller (wav_write_header()) to use them. */ int -wav_prepare_header(struct write_info *wi, void **hdrp, size_t *lenp, int *leftp) +wav_prepare_header(struct track_info *ti, void **hdrp, size_t *lenp, int *leftp) { /* * WAV header we write looks like this: @@ -263,11 +263,11 @@ wav_prepare_header(struct write_info *wi u_int32_t filelen, fmtsz, sps, abps, factsz = 4, nsample, datalen; u_int16_t fmttag, nchan, align, extln = 0; - if (wi->header_info) + if (ti->header_info) warnx("header information not supported for WAV"); *leftp = 0; - switch (wi->precision) { + switch (ti->precision) { case 8: break; case 16: @@ -279,24 +279,24 @@ wav_prepare_header(struct write_info *wi static int warned = 0; if (warned == 0) { - warnx("can not support precision of %d", wi->precision); + warnx("can not support precision of %d", ti->precision); warned = 1; } } return (-1); } - switch (wi->encoding) { + switch (ti->encoding) { case AUDIO_ENCODING_ULAW: fmttag = WAVE_FORMAT_MULAW; fmtsz = 18; - align = wi->channels; + align = ti->channels; break; case AUDIO_ENCODING_ALAW: fmttag = WAVE_FORMAT_ALAW; fmtsz = 18; - align = wi->channels; + align = ti->channels; break; /* @@ -315,7 +315,7 @@ wav_prepare_header(struct write_info *wi #endif fmttag = WAVE_FORMAT_PCM; fmtsz = 16; - align = wi->channels * (wi->precision / 8); + align = ti->channels * (ti->precision / 8); break; default: @@ -324,28 +324,28 @@ wav_prepare_header(struct write_info *wi static int warned = 0; if (warned == 0) { - const char *s = wav_enc_from_val(wi->encoding); + const char *s = wav_enc_from_val(ti->encoding); if (s == NULL) warnx("can not support encoding of %s", s); else - warnx("can not support encoding of %d", wi->encoding); + warnx("can not support encoding of %d", ti->encoding); warned = 1; } } #endif - wi->format = AUDIO_FORMAT_NONE; + ti->format = AUDIO_FORMAT_NONE; return (-1); } - nchan = wi->channels; - sps = wi->sample_rate; + nchan = ti->channels; + sps = ti->sample_rate; /* data length */ - if (wi->outfd == STDOUT_FILENO) + if (ti->outfd == STDOUT_FILENO) datalen = 0; - else if (wi->total_size != -1) - datalen = wi->total_size; + else if (ti->total_size != -1) + datalen = ti->total_size; else datalen = 0; @@ -354,9 +354,9 @@ wav_prepare_header(struct write_info *wi if (fmttag != WAVE_FORMAT_PCM) filelen += 8 + factsz; - abps = (double)align*wi->sample_rate / (double)1 + 0.5; + abps = (double)align*ti->sample_rate / (double)1 + 0.5; - nsample = (datalen / wi->precision) / wi->sample_rate; + nsample = (datalen / ti->precision) / ti->sample_rate; /* * now we've calculated the info, write it out! @@ -389,7 +389,7 @@ wav_prepare_header(struct write_info *wi p += 4; /* 32 */ put16(align); p += 2; /* 34 */ - put16(wi->precision); + put16(ti->precision); p += 2; /* 36 */ /* NON PCM formats have an extended chunk; write it */ if (fmttag != WAVE_FORMAT_PCM) { @@ -416,11 +416,11 @@ wav_prepare_header(struct write_info *wi } write_conv_func -wav_write_get_conv_func(struct write_info *wi) +wav_write_get_conv_func(struct track_info *ti) { write_conv_func conv_func = NULL; - switch (wi->encoding) { + switch (ti->encoding) { /* * we could try to support RIFX but it seems to be more portable @@ -430,9 +430,9 @@ wav_write_get_conv_func(struct write_inf #if BYTE_ORDER == BIG_ENDIAN case AUDIO_ENCODING_ULINEAR: #endif - if (wi->precision == 16) + if (ti->precision == 16) conv_func = change_sign16_swap_bytes_be; - else if (wi->precision == 32) + else if (ti->precision == 32) conv_func = change_sign32_swap_bytes_be; break; @@ -440,11 +440,11 @@ wav_write_get_conv_func(struct write_inf #if BYTE_ORDER == BIG_ENDIAN case AUDIO_ENCODING_SLINEAR: #endif - if (wi->precision == 8) + if (ti->precision == 8) conv_func = change_sign8; - else if (wi->precision == 16) + else if (ti->precision == 16) conv_func = swap_bytes; - else if (wi->precision == 32) + else if (ti->precision == 32) conv_func = swap_bytes32; break; @@ -452,9 +452,9 @@ wav_write_get_conv_func(struct write_inf #if BYTE_ORDER == LITTLE_ENDIAN case AUDIO_ENCODING_ULINEAR: #endif - if (wi->precision == 16) + if (ti->precision == 16) conv_func = change_sign16_le; - else if (wi->precision == 32) + else if (ti->precision == 32) conv_func = change_sign32_le; break; @@ -463,12 +463,12 @@ wav_write_get_conv_func(struct write_inf #if BYTE_ORDER == LITTLE_ENDIAN case AUDIO_ENCODING_SLINEAR: #endif - if (wi->precision == 8) + if (ti->precision == 8) conv_func = change_sign8; break; default: - wi->format = AUDIO_FORMAT_NONE; + ti->format = AUDIO_FORMAT_NONE; } return conv_func; Index: src/usr.bin/audio/play/play.c diff -u src/usr.bin/audio/play/play.c:1.54 src/usr.bin/audio/play/play.c:1.55 --- src/usr.bin/audio/play/play.c:1.54 Sun Aug 28 01:17:48 2011 +++ src/usr.bin/audio/play/play.c Wed Aug 5 06:54:39 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: play.c,v 1.54 2011/08/28 01:17:48 joerg Exp $ */ +/* $NetBSD: play.c,v 1.55 2015/08/05 06:54:39 mrg Exp $ */ /* * Copyright (c) 1999, 2000, 2001, 2002, 2010 Matthew R. Green @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: play.c,v 1.54 2011/08/28 01:17:48 joerg Exp $"); +__RCSID("$NetBSD: play.c,v 1.55 2015/08/05 06:54:39 mrg Exp $"); #endif @@ -54,7 +54,7 @@ __RCSID("$NetBSD: play.c,v 1.54 2011/08/ static void usage(void) __dead; static void play(char *); static void play_fd(const char *, int); -static ssize_t audioctl_write_fromhdr(void *, size_t, int, size_t *, const char *); +static ssize_t audioctl_write_fromhdr(void *, size_t, int, off_t *, const char *); static void cleanup(int) __dead; static audio_info_t info; @@ -221,7 +221,7 @@ play(char *file) void *addr, *oaddr; off_t filesize; size_t sizet_filesize; - size_t datasize = 0; + off_t datasize = 0; ssize_t hdrlen; int fd; @@ -276,19 +276,19 @@ play(char *file) filesize -= hdrlen; addr = (char *)addr + hdrlen; - if ((uint64_t)filesize < datasize || datasize == 0) { - if ((uint64_t)filesize < datasize) + if (filesize < datasize || datasize == 0) { + if (filesize < datasize) warnx("bogus datasize: %ld", (u_long)datasize); datasize = filesize; } - while (datasize > bufsize) { + while ((uint64_t)datasize > bufsize) { if ((size_t)write(audiofd, addr, bufsize) != bufsize) err(1, "write failed"); addr = (char *)addr + bufsize; datasize -= bufsize; } - if ((size_t)write(audiofd, addr, datasize) != datasize) + if ((off_t)write(audiofd, addr, datasize) != datasize) err(1, "final write failed"); if (ioctl(audiofd, AUDIO_DRAIN) < 0 && !qflag) @@ -308,8 +308,8 @@ play_fd(const char *file, int fd) char *buffer = malloc(bufsize); ssize_t hdrlen; int nr, nw; - size_t datasize = 0; - size_t dataout = 0; + off_t datasize = 0; + off_t dataout = 0; if (buffer == NULL) err(1, "malloc of read buffer failed"); @@ -367,7 +367,7 @@ write_error: * uses the local "info" variable. blah... fix me! */ static ssize_t -audioctl_write_fromhdr(void *hdr, size_t fsz, int fd, size_t *datasize, const char *file) +audioctl_write_fromhdr(void *hdr, size_t fsz, int fd, off_t *datasize, const char *file) { sun_audioheader *sunhdr; ssize_t hdr_len = 0; @@ -389,7 +389,7 @@ audioctl_write_fromhdr(void *hdr, size_t info.play.channels = ntohl(sunhdr->channels); hdr_len = ntohl(sunhdr->hdr_size); - *datasize = ntohl(sunhdr->data_size); + *datasize = (off_t)ntohl(sunhdr->data_size); goto set_audio_mode; } Index: src/usr.bin/audio/record/record.c diff -u src/usr.bin/audio/record/record.c:1.53 src/usr.bin/audio/record/record.c:1.54 --- src/usr.bin/audio/record/record.c:1.53 Fri Aug 30 20:57:26 2013 +++ src/usr.bin/audio/record/record.c Wed Aug 5 06:54:39 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: record.c,v 1.53 2013/08/30 20:57:26 mrg Exp $ */ +/* $NetBSD: record.c,v 1.54 2015/08/05 06:54:39 mrg Exp $ */ /* * Copyright (c) 1999, 2002, 2003, 2005, 2010 Matthew R. Green @@ -32,7 +32,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: record.c,v 1.53 2013/08/30 20:57:26 mrg Exp $"); +__RCSID("$NetBSD: record.c,v 1.54 2015/08/05 06:54:39 mrg Exp $"); #endif @@ -65,7 +65,7 @@ static int gain; static int balance; static int port; static char *encoding_str; -static struct write_info wi; +static struct track_info ti; static struct timeval record_time; static struct timeval start_time; @@ -85,10 +85,10 @@ main(int argc, char *argv[]) const char *defdevice = _PATH_SOUND; /* - * Initialise the write_info. + * Initialise the track_info. */ - wi.format = AUDIO_FORMAT_DEFAULT; - wi.total_size = -1; + ti.format = AUDIO_FORMAT_DEFAULT; + ti.total_size = -1; while ((ch = getopt(argc, argv, "ab:B:C:F:c:d:e:fhi:m:P:p:qt:s:Vv:")) != -1) { switch (ch) { @@ -108,14 +108,14 @@ main(int argc, char *argv[]) /* Ignore, compatibility */ break; case 'F': - wi.format = audio_format_from_str(optarg); - if (wi.format < 0) + ti.format = audio_format_from_str(optarg); + if (ti.format < 0) errx(1, "Unknown audio format; supported " "formats: \"sun\", \"wav\", and \"none\""); break; case 'c': - decode_int(optarg, &wi.channels); - if (wi.channels < 0 || wi.channels > 16) + decode_int(optarg, &ti.channels); + if (ti.channels < 0 || ti.channels > 16) errx(1, "channels must be between 0 and 16"); break; case 'd': @@ -128,7 +128,7 @@ main(int argc, char *argv[]) fflag++; break; case 'i': - wi.header_info = optarg; + ti.header_info = optarg; break; case 'm': decode_int(optarg, &monitor_gain); @@ -136,10 +136,10 @@ main(int argc, char *argv[]) errx(1, "monitor volume must be between 0 and 255"); break; case 'P': - decode_int(optarg, &wi.precision); - if (wi.precision != 4 && wi.precision != 8 && - wi.precision != 16 && wi.precision != 24 && - wi.precision != 32) + decode_int(optarg, &ti.precision); + if (ti.precision != 4 && ti.precision != 8 && + ti.precision != 16 && ti.precision != 24 && + ti.precision != 32) errx(1, "precision must be between 4, 8, 16, 24 or 32"); break; case 'p': @@ -157,11 +157,11 @@ main(int argc, char *argv[]) "port must be `cd', `internal-cd', `mic', or `line'"); break; case 'q': - wi.qflag++; + ti.qflag++; break; case 's': - decode_int(optarg, &wi.sample_rate); - if (wi.sample_rate < 0 || wi.sample_rate > 48000 * 2) /* XXX */ + decode_int(optarg, &ti.sample_rate); + if (ti.sample_rate < 0 || ti.sample_rate > 48000 * 2) /* XXX */ errx(1, "sample rate must be between 0 and 96000"); break; case 't': @@ -192,8 +192,8 @@ main(int argc, char *argv[]) * convert the encoding string into a value. */ if (encoding_str) { - wi.encoding = audio_enc_to_val(encoding_str); - if (wi.encoding == -1) + ti.encoding = audio_enc_to_val(encoding_str); + if (ti.encoding == -1) errx(1, "unknown encoding, bailing..."); } @@ -202,21 +202,21 @@ main(int argc, char *argv[]) */ if (argv[0][0] != '-' || argv[0][1] != '\0') { /* intuit the file type from the name */ - if (wi.format == AUDIO_FORMAT_DEFAULT) + if (ti.format == AUDIO_FORMAT_DEFAULT) { size_t flen = strlen(*argv); const char *arg = *argv; if (strcasecmp(arg + flen - 3, ".au") == 0) - wi.format = AUDIO_FORMAT_SUN; + ti.format = AUDIO_FORMAT_SUN; else if (strcasecmp(arg + flen - 4, ".wav") == 0) - wi.format = AUDIO_FORMAT_WAV; + ti.format = AUDIO_FORMAT_WAV; } - wi.outfd = open(*argv, O_CREAT|(aflag ? O_APPEND : O_TRUNC)|O_WRONLY, 0666); - if (wi.outfd < 0) + ti.outfd = open(*argv, O_CREAT|(aflag ? O_APPEND : O_TRUNC)|O_WRONLY, 0666); + if (ti.outfd < 0) err(1, "could not open %s", *argv); } else - wi.outfd = STDOUT_FILENO; + ti.outfd = STDOUT_FILENO; /* * open the audio device @@ -262,7 +262,7 @@ main(int argc, char *argv[]) info.record.y = x; \ else \ info.record.y = x = oinfo.record.y; -#define SETINFO(x) SETINFO2(wi.x, x) +#define SETINFO(x) SETINFO2(ti.x, x) SETINFO (sample_rate) SETINFO (channels) @@ -285,12 +285,12 @@ main(int argc, char *argv[]) signal(SIGINT, cleanup); - wi.total_size = 0; + ti.total_size = 0; - write_header(&wi); - if (wi.format == AUDIO_FORMAT_NONE) + write_header(&ti); + if (ti.format == AUDIO_FORMAT_NONE) errx(1, "unable to determine audio format"); - conv_func = write_get_conv_func(&wi); + conv_func = write_get_conv_func(&ti); if (verbose && conv_func) { const char *s = NULL; @@ -341,9 +341,9 @@ main(int argc, char *argv[]) err(1, "read failed"); if (conv_func) (*conv_func)(buffer, bufsize); - if ((size_t)write(wi.outfd, buffer, bufsize) != bufsize) + if ((size_t)write(ti.outfd, buffer, bufsize) != bufsize) err(1, "write failed"); - wi.total_size += bufsize; + ti.total_size += bufsize; } cleanup(0); } @@ -365,7 +365,7 @@ cleanup(int signo) { rewrite_header(); - close(wi.outfd); + close(ti.outfd); if (omonitor_gain) { AUDIO_INITINFO(&info); info.monitor_gain = omonitor_gain; @@ -384,12 +384,12 @@ rewrite_header(void) { /* can't do this here! */ - if (wi.outfd == STDOUT_FILENO) + if (ti.outfd == STDOUT_FILENO) return; - if (lseek(wi.outfd, (off_t)0, SEEK_SET) == (off_t)-1) + if (lseek(ti.outfd, (off_t)0, SEEK_SET) == (off_t)-1) err(1, "could not seek to start of file for header rewrite"); - write_header(&wi); + write_header(&ti); } static void