diff options
author | av <av@cvs.openbsd.org> | 2008-06-22 21:04:02 +0000 |
---|---|---|
committer | av <av@cvs.openbsd.org> | 2008-06-22 21:04:02 +0000 |
commit | 34814a12a84a67f8a9ef81726b21f4924550ce65 (patch) | |
tree | 4f7be5729655873b24d95707d4b92b8860c95796 /usr.bin/cdio | |
parent | 8af57fdf574da8b61433ede4ae2b3b17f6d9cb5c (diff) |
Automatically distinguish between CD-DA track and WAVE audio file writing them
in TAO mode. For WAVE files we should skip header.
ok and comments by fgsch
Diffstat (limited to 'usr.bin/cdio')
-rw-r--r-- | usr.bin/cdio/cdio.1 | 8 | ||||
-rw-r--r-- | usr.bin/cdio/cdio.c | 31 | ||||
-rw-r--r-- | usr.bin/cdio/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/cdio/mmc.c | 8 |
4 files changed, 38 insertions, 12 deletions
diff --git a/usr.bin/cdio/cdio.1 b/usr.bin/cdio/cdio.1 index ded7a720282..72500f0e17e 100644 --- a/usr.bin/cdio/cdio.1 +++ b/usr.bin/cdio/cdio.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cdio.1,v 1.47 2007/11/12 20:37:42 jmc Exp $ +.\" $OpenBSD: cdio.1,v 1.48 2008/06/22 21:04:01 av Exp $ .\" .\" Copyright (c) 1995 Serge V. Vakulenko .\" All rights reserved. @@ -29,7 +29,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: November 12 2007 $ +.Dd $Mdocdate: June 22 2008 $ .Dt CDIO 1 .Os .Sh NAME @@ -220,7 +220,9 @@ The options are as follows: .Pp .Bl -tag -width Ds -compact .It Fl a -Write files as audio tracks. +Write files as audio tracks. Acceptable formats of audio track are CD-DA track +and WAVE audio with 2 channels of PCM audio, each signed 16-bit (little endian) +values sampled at 44100 Hz. .It Fl d Write files as data tracks (the default). .El diff --git a/usr.bin/cdio/cdio.c b/usr.bin/cdio/cdio.c index 1bee99b7eab..bbe157f6b18 100644 --- a/usr.bin/cdio/cdio.c +++ b/usr.bin/cdio/cdio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cdio.c,v 1.61 2008/06/11 21:59:25 av Exp $ */ +/* $OpenBSD: cdio.c,v 1.62 2008/06/22 21:04:01 av Exp $ */ /* Copyright (c) 1995 Serge V. Vakulenko * All rights reserved. @@ -166,6 +166,7 @@ int play_msf(int, int, int, int, int, int); int play_track(int, int, int, int); int get_vol(int *, int *); int status(int *, int *, int *, int *); +int is_wave(int fd); __dead void tao(int argc, char **argv); int play(char *arg); int info(char *arg); @@ -546,6 +547,25 @@ run(int cmd, char *arg) } } +/* + * Check if audio file has RIFF WAVE format. If not, we assume it's just PCM. + */ +int +is_wave(int fd) +{ + char buf[WAVHDRLEN]; + int rv; + + rv = 0; + if (read(fd, buf, sizeof(buf)) == sizeof(buf)) { + if (memcmp(buf, "RIFF", 4) == 0 && + memcmp(buf + 8, "WAVE", 4) == 0) + rv = 1; + } + + return (rv); +} + __dead void tao(int argc, char **argv) { @@ -601,8 +621,13 @@ tao(int argc, char **argv) if (fstat(tr->fd, &sb) == -1) err(1, "cannot stat file %s", tr->file); tr->sz = sb.st_size; - if (tr->type == 'a') - tr->sz -= WAVHDRLEN; + tr->off = 0; + if (tr->type == 'a') { + if (is_wave(tr->fd)) { + tr->sz -= WAVHDRLEN; + tr->off = WAVHDRLEN; + } + } if (SLIST_EMPTY(&tracks)) SLIST_INSERT_HEAD(&tracks, tr, track_list); else diff --git a/usr.bin/cdio/extern.h b/usr.bin/cdio/extern.h index 818e9c78164..90c33cebf04 100644 --- a/usr.bin/cdio/extern.h +++ b/usr.bin/cdio/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.10 2008/06/08 21:01:24 av Exp $ */ +/* $OpenBSD: extern.h,v 1.11 2008/06/22 21:04:01 av Exp $ */ /* * Copyright (c) 2002 Marc Espie. * @@ -29,6 +29,7 @@ struct cd_toc_entry; struct track_info { off_t sz; + off_t off; u_int blklen; int fd; char *file; diff --git a/usr.bin/cdio/mmc.c b/usr.bin/cdio/mmc.c index cd4850a6c25..42b7d3845b6 100644 --- a/usr.bin/cdio/mmc.c +++ b/usr.bin/cdio/mmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mmc.c,v 1.20 2008/06/08 21:01:24 av Exp $ */ +/* $OpenBSD: mmc.c,v 1.21 2008/06/22 21:04:01 av Exp $ */ /* * Copyright (c) 2006 Michael Coulter <mjc@openbsd.org> @@ -261,10 +261,8 @@ writetrack(struct track_info *tr, int track) } else { end_lba = tr->sz / tr->blklen + lba; } - if (tr->type == 'a') { - if (lseek(tr->fd, WAVHDRLEN, SEEK_SET) == -1) - err(1, "seek failed for file %s", tr->file); - } + if (lseek(tr->fd, tr->off, SEEK_SET) == -1) + err(1, "seek failed for file %s", tr->file); while (lba < end_lba && nblk != 0) { while (lba + nblk <= end_lba) { read(tr->fd, databuf, nblk * tr->blklen); |