=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/cdio/rip.c,v retrieving revision 1.8 retrieving revision 1.9 diff -c -r1.8 -r1.9 *** src/usr.bin/cdio/rip.c 2008/06/30 23:35:39 1.8 --- src/usr.bin/cdio/rip.c 2008/11/29 08:57:10 1.9 *************** *** 1,4 **** ! /* $OpenBSD: rip.c,v 1.8 2008/06/30 23:35:39 av Exp $ */ /* * Copyright (c) 2007 Alexey Vatchenko --- 1,4 ---- ! /* $OpenBSD: rip.c,v 1.9 2008/11/29 08:57:10 jakemsr Exp $ */ /* * Copyright (c) 2007 Alexey Vatchenko *************** *** 19,25 **** #include #include - #include #include #include #include --- 19,24 ---- *************** *** 34,39 **** --- 33,39 ---- #include #include #include + #include #include #include #include *************** *** 86,91 **** --- 86,93 ---- struct track_info { int fd; /* descriptor of output file */ + struct sio_hdl *hdl; /* sndio handle */ + struct sio_par par; /* sndio parameters */ u_int track; /* track number */ char name[12]; /* output file name, i.e. trackXX.wav/trackXX.dat */ u_char isaudio; /* true if audio track, otherwise it's data track */ *************** *** 93,99 **** u_int32_t end_lba; /* starting address of the next track */ }; ! int read_track(int, struct track_info *); int rip_next_track(struct track_info *); int play_next_track(struct track_info *); --- 95,101 ---- u_int32_t end_lba; /* starting address of the next track */ }; ! int read_track(struct track_info *); int rip_next_track(struct track_info *); int play_next_track(struct track_info *); *************** *** 356,362 **** } int ! read_track(int fd, struct track_info *ti) { struct timeval tv, otv, atv; u_int32_t i, blksize, n_sec; --- 358,364 ---- } int ! read_track(struct track_info *ti) { struct timeval tv, otv, atv; u_int32_t i, blksize, n_sec; *************** *** 385,396 **** error = read_data_sector(i + ti->start_lba, sec, blksize); if (error == 0) { ! if (write_sector(ti->fd, sec, blksize) != 0) { free(sec); warnx("\nerror while writing to the %s file", ti->name); return (-1); } i++; } else if (error != EAGAIN) { --- 387,406 ---- error = read_data_sector(i + ti->start_lba, sec, blksize); if (error == 0) { ! if (ti->fd >= 0 && ! (write_sector(ti->fd, sec, blksize) != 0)) { free(sec); warnx("\nerror while writing to the %s file", ti->name); return (-1); } + if (ti->hdl != NULL && + (sio_write(ti->hdl, sec, blksize) == 0)) { + sio_close(ti->hdl); + ti->hdl = NULL; + warnx("\nerror while writing to audio output"); + return (-1); + } i++; } else if (error != EAGAIN) { *************** *** 441,479 **** int play_next_track(struct track_info *info) { ! int fd, error; ! audio_info_t ai; if (!info->isaudio) return (NXTRACK_SKIP); ! info->fd = open("/dev/audio", O_CREAT | O_TRUNC | O_RDWR, ! S_IRUSR | S_IWUSR); ! if (info->fd == -1) { ! warnx("can't open /dev/audio"); ! return (NXTRACK_FAIL); } ! fd = open("/dev/audioctl", O_RDWR); ! if (fd != -1) { ! AUDIO_INITINFO(&ai); ! ai.play.sample_rate = 44100; ! ai.play.channels = 2; ! ai.play.precision = 16; ! ai.play.encoding = AUDIO_ENCODING_SLINEAR_LE; ! error = ioctl(fd, AUDIO_SETINFO, &ai); ! close(fd); ! } else ! error = -1; ! if (error == -1) { ! warnx("can't configure audio device"); ! close(info->fd); ! info->fd = -1; ! return (NXTRACK_FAIL); } return (NXTRACK_OK); } static int --- 451,511 ---- int play_next_track(struct track_info *info) { ! char *dev; if (!info->isaudio) return (NXTRACK_SKIP); ! if (info->hdl != NULL) ! return (NXTRACK_OK); ! ! dev = getenv("AUDIODEVICE"); ! ! info->hdl = sio_open(dev, SIO_PLAY, 0); ! if (info->hdl == NULL) { ! warnx("could not open audio backend"); ! goto bad; } ! sio_initpar(&info->par); ! info->par.rate = 44100; ! info->par.pchan = 2; ! info->par.bits = 16; ! info->par.sig = 1; ! info->par.le = 1; ! info->par.bufsz = info->par.rate * 3 / 4; ! ! if (sio_setpar(info->hdl, &info->par) == 0) { ! warnx("could not set audio parameters"); ! goto bad; } + if (sio_getpar(info->hdl, &info->par) == 0) { + warnx("could not get audio parameters"); + goto bad; + } + + if (info->par.le != 1 || + info->par.sig != 1 || + info->par.bits != 16 || + info->par.pchan != 2 || + (info->par.rate > 44100 * 1.05 || info->par.rate < 44100 * 0.95)) { + warnx("could not configure audio parameters as desired"); + goto bad; + } + + if (sio_start(info->hdl) == 0) { + warnx("could not start audio output"); + goto bad; + } + return (NXTRACK_OK); + + bad: + sio_close(info->hdl); + info->hdl = NULL; + return (NXTRACK_FAIL); } static int *************** *** 486,491 **** --- 518,526 ---- char order; int error; + info.fd = -1; + info.hdl = NULL; + order = (tp->start > tp->end) ? -1 : 1; trk = tp->start; for (;;) { *************** *** 522,530 **** error = -1; break; } else if (error != NXTRACK_SKIP) { ! error = read_track(fd, &info); ! close(info.fd); ! if (error != 0) { warnx("can't rip %u track", toc_buffer[i].track); --- 557,567 ---- error = -1; break; } else if (error != NXTRACK_SKIP) { ! error = read_track(&info); ! if (info.fd >= 0) { ! close(info.fd); ! info.fd = -1; ! } if (error != 0) { warnx("can't rip %u track", toc_buffer[i].track); *************** *** 536,541 **** --- 573,583 ---- if (trk == tp->end) break; trk += order; + } + + if (info.hdl != NULL) { + sio_close(info.hdl); + info.hdl = NULL; } return (error);