2004-12-18 17:29:32 +00:00
|
|
|
/*
|
2005-01-06 23:32:58 +00:00
|
|
|
$Id: toc.c,v 1.4 2005/01/06 23:32:58 rocky Exp $
|
2004-12-18 17:29:32 +00:00
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
|
2004-12-18 17:29:32 +00:00
|
|
|
Copyright (C) 1998 Monty xiphmont@mit.edu
|
|
|
|
|
derived from code (C) 1994-1996 Heiko Eissfeldt
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* Table of contents convenience functions
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
2005-01-06 03:38:58 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-12-18 17:29:32 +00:00
|
|
|
#include "low_interface.h"
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
/*! Return the lsn for the start of track i_track */
|
|
|
|
|
lsn_t
|
|
|
|
|
cdda_track_firstsector(cdrom_drive_t *d, track_t i_track)
|
2004-12-18 17:29:32 +00:00
|
|
|
{
|
|
|
|
|
if(!d->opened){
|
|
|
|
|
cderror(d,"400: Device not open\n");
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
if (i_track == 0) {
|
2004-12-18 17:29:32 +00:00
|
|
|
if (d->disc_toc[0].dwStartSector == 0) {
|
2005-01-05 04:16:11 +00:00
|
|
|
/* first track starts at lsn 0 -> no pre-gap */
|
2004-12-18 17:29:32 +00:00
|
|
|
cderror(d,"401: Invalid track number\n");
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return 0; /* pre-gap of first track always starts at lba 0 */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
if( i_track>d->tracks) {
|
2004-12-18 17:29:32 +00:00
|
|
|
cderror(d,"401: Invalid track number\n");
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
2005-01-05 04:16:11 +00:00
|
|
|
return(d->disc_toc[i_track-1].dwStartSector);
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
/*! Get first lsn of the first audio track. -1 is returned on error. */
|
|
|
|
|
lsn_t
|
2004-12-18 17:29:32 +00:00
|
|
|
cdda_disc_firstsector(cdrom_drive_t *d)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
if(!d->opened){
|
|
|
|
|
cderror(d,"400: Device not open\n");
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* look for an audio track */
|
2005-01-05 04:16:11 +00:00
|
|
|
for ( i=0; i<d->tracks; i++ )
|
|
|
|
|
if( cdda_track_audiop(d, i+1)==1 ) {
|
2004-12-18 17:29:32 +00:00
|
|
|
if (i == 0) /* disc starts at lba 0 if first track is an audio track */
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
2005-01-05 04:16:11 +00:00
|
|
|
return cdda_track_firstsector(d, i+1);
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cderror(d,"403: No audio tracks on disc\n");
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
/*! Get last lsn of the track. The lsn is generally one less than the
|
|
|
|
|
start of the next track. -1 is returned on error. */
|
|
|
|
|
lsn_t
|
|
|
|
|
cdda_track_lastsector(cdrom_drive_t *d, track_t i_track)
|
2004-12-18 17:29:32 +00:00
|
|
|
{
|
2005-01-05 04:16:11 +00:00
|
|
|
if (!d->opened) {
|
2004-12-18 17:29:32 +00:00
|
|
|
cderror(d,"400: Device not open\n");
|
2005-01-05 04:16:11 +00:00
|
|
|
return -1;
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
if (i_track == 0) {
|
2004-12-18 17:29:32 +00:00
|
|
|
if (d->disc_toc[0].dwStartSector == 0) {
|
|
|
|
|
/* first track starts at lba 0 -> no pre-gap */
|
|
|
|
|
cderror(d,"401: Invalid track number\n");
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return d->disc_toc[0].dwStartSector-1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
if ( i_track<1 || i_track>d->tracks ) {
|
2004-12-18 17:29:32 +00:00
|
|
|
cderror(d,"401: Invalid track number\n");
|
2005-01-05 04:16:11 +00:00
|
|
|
return -1;
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
/* Safe, we've always the leadout at disc_toc[tracks] */
|
2005-01-05 04:16:11 +00:00
|
|
|
return(d->disc_toc[i_track].dwStartSector-1);
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
/*! Get last lsn of the last audio track. The last lssn generally one
|
|
|
|
|
less than the start of the next track after the audio track. -1 is
|
|
|
|
|
returned on error. */
|
|
|
|
|
lsn_t
|
2004-12-18 17:29:32 +00:00
|
|
|
cdda_disc_lastsector(cdrom_drive_t *d)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2005-01-05 04:16:11 +00:00
|
|
|
if (!d->opened) {
|
2004-12-18 17:29:32 +00:00
|
|
|
cderror(d,"400: Device not open\n");
|
2005-01-05 04:16:11 +00:00
|
|
|
return -1;
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* look for an audio track */
|
2005-01-05 04:16:11 +00:00
|
|
|
for ( i=d->tracks-1; i>=0; i-- )
|
|
|
|
|
if ( cdda_track_audiop(d,i+1) == 1 )
|
|
|
|
|
return (cdda_track_lastsector(d,i+1));
|
2004-12-18 17:29:32 +00:00
|
|
|
|
|
|
|
|
cderror(d,"403: No audio tracks on disc\n");
|
2005-01-05 04:16:11 +00:00
|
|
|
return -1;
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-06 23:32:58 +00:00
|
|
|
/*! Return the number of tracks on the CD. */
|
2005-01-05 04:16:11 +00:00
|
|
|
track_t
|
2004-12-18 17:29:32 +00:00
|
|
|
cdda_tracks(cdrom_drive_t *d)
|
|
|
|
|
{
|
2005-01-05 04:16:11 +00:00
|
|
|
if (!d->opened){
|
2004-12-18 17:29:32 +00:00
|
|
|
cderror(d,"400: Device not open\n");
|
2005-01-05 04:16:11 +00:00
|
|
|
return -1;
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
return(d->tracks);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-06 23:32:58 +00:00
|
|
|
/*! Return the track containing the given LSN. If the LSN is before
|
|
|
|
|
the first track (in the pregap), 0 is returned. If there was an
|
|
|
|
|
error or the LSN after the LEADOUT (beyond the end of the CD), then
|
|
|
|
|
CDIO_INVALID_TRACK is returned.
|
|
|
|
|
*/
|
2004-12-18 17:29:32 +00:00
|
|
|
int
|
2005-01-05 04:16:11 +00:00
|
|
|
cdda_sector_gettrack(cdrom_drive_t *d, lsn_t lsn)
|
2004-12-18 17:29:32 +00:00
|
|
|
{
|
2005-01-05 04:16:11 +00:00
|
|
|
if (!d->opened) {
|
2004-12-18 17:29:32 +00:00
|
|
|
cderror(d,"400: Device not open\n");
|
|
|
|
|
return -1;
|
2005-01-05 04:16:11 +00:00
|
|
|
} else {
|
|
|
|
|
if (lsn < d->disc_toc[0].dwStartSector)
|
|
|
|
|
return 0; /* We're in the pre-gap of first track */
|
2004-12-18 17:29:32 +00:00
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
return cdio_get_track(d->p_cdio, lsn);
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-06 23:32:58 +00:00
|
|
|
/*! Return the number of channels in track: 2 or 4; -2 if not
|
2005-01-05 04:16:11 +00:00
|
|
|
implemented or -1 for error.
|
|
|
|
|
Not meaningful if track is not an audio track.
|
|
|
|
|
*/
|
2004-12-18 17:29:32 +00:00
|
|
|
int
|
2005-01-05 04:16:11 +00:00
|
|
|
cdda_track_channels(cdrom_drive_t *d, track_t i_track)
|
2004-12-18 17:29:32 +00:00
|
|
|
{
|
2005-01-05 04:16:11 +00:00
|
|
|
return(cdio_get_track_channels(d->p_cdio, i_track));
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
/*! Return 1 is track is an audio track, 0 otherwise. */
|
2004-12-18 17:29:32 +00:00
|
|
|
int
|
2005-01-05 04:16:11 +00:00
|
|
|
cdda_track_audiop(cdrom_drive_t *d, track_t i_track)
|
2004-12-18 17:29:32 +00:00
|
|
|
{
|
2005-01-05 04:16:11 +00:00
|
|
|
track_format_t track_format = cdio_get_track_format(d->p_cdio, i_track);
|
|
|
|
|
return TRACK_FORMAT_AUDIO == track_format ? 1 : 0;
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
/*! Return 1 is track is an audio track, 0 otherwise. */
|
2004-12-18 17:29:32 +00:00
|
|
|
int
|
2005-01-05 04:16:11 +00:00
|
|
|
cdda_track_copyp(cdrom_drive_t *d, track_t i_track)
|
2004-12-18 17:29:32 +00:00
|
|
|
{
|
2005-01-05 04:16:11 +00:00
|
|
|
track_flag_t track_flag = cdio_get_track_copy_permit(d->p_cdio, i_track);
|
|
|
|
|
return CDIO_TRACK_FLAG_TRUE == track_flag ? 1 : 0;
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-05 04:16:11 +00:00
|
|
|
/*! Return 1 is audio track has linear preemphasis set, 0 otherwise.
|
|
|
|
|
Only makes sense for audio tracks.
|
|
|
|
|
*/
|
2004-12-18 17:29:32 +00:00
|
|
|
int
|
2005-01-05 04:16:11 +00:00
|
|
|
cdda_track_preemp(cdrom_drive_t *d, track_t i_track)
|
2004-12-18 17:29:32 +00:00
|
|
|
{
|
2005-01-05 04:16:11 +00:00
|
|
|
track_flag_t track_flag = cdio_get_track_preemphasis(d->p_cdio, i_track);
|
|
|
|
|
return CDIO_TRACK_FLAG_TRUE == track_flag ? 1 : 0;
|
2004-12-18 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|