More audio control corrections.

This commit is contained in:
rocky
2005-03-06 11:21:52 +00:00
parent 7b78b896f4
commit 1fe287e813
14 changed files with 290 additions and 133 deletions

View File

@@ -1,5 +1,5 @@
/* -*- c -*-
$Id: audio.h,v 1.5 2005/03/05 09:26:52 rocky Exp $
$Id: audio.h,v 1.6 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -121,6 +121,14 @@ extern "C" {
driver_return_code_t cdio_audio_set_volume (CdIo_t *p_cdio,
cdio_audio_volume_t *p_volume);
/*!
Stop playing an audio CD.
@param p_cdio the CD object to be acted upon.
*/
driver_return_code_t cdio_audio_stop (CdIo_t *p_cdio);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@@ -1,5 +1,5 @@
/* -*- c -*-
$Id: device.h,v 1.18 2005/03/05 10:48:41 rocky Exp $
$Id: device.h,v 1.19 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -216,6 +216,14 @@ extern "C" {
DRIVER_OP_BAD_POINTER = -6, /**< Bad pointer to memory area */
} driver_return_code_t;
/*!
Close media tray in CD drive if there is a routine to do so.
@param p_cdio the CD object to be acted upon.
If the CD is ejected *p_cdio is freed and p_cdio set to NULL.
*/
driver_return_code_t cdio_close_tray (CdIo_t *p_cdio);
/*!
Eject media in CD drive if there is a routine to do so.

View File

@@ -1,5 +1,5 @@
/*
$Id: sector.h,v 1.35 2005/02/06 04:20:25 rocky Exp $
$Id: sector.h,v 1.36 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -212,45 +212,45 @@
/*!
Convert an LBA into a string representation of the MSF.
\warning cdio_lba_to_msf_str returns new allocated string */
char *cdio_lba_to_msf_str (lba_t lba);
char *cdio_lba_to_msf_str (lba_t i_lba);
/*!
Convert an MSF into a string representation of the MSF.
\warning cdio_msf_to_msf_str returns new allocated string */
char *cdio_msf_to_str (const msf_t *msf);
char *cdio_msf_to_str (const msf_t *p_msf);
/*!
Convert an LBA into the corresponding LSN.
*/
lba_t cdio_lba_to_lsn (lba_t lba);
lba_t cdio_lba_to_lsn (lba_t i_lba);
/*!
Convert an LBA into the corresponding MSF.
*/
void cdio_lba_to_msf(lba_t lba, msf_t *msf);
void cdio_lba_to_msf(lba_t i_lba, msf_t *p_msf);
/*!
Convert an LSN into the corresponding LBA.
CDIO_INVALID_LBA is returned if there is an error.
*/
lba_t cdio_lsn_to_lba (lsn_t lsn);
lba_t cdio_lsn_to_lba (lsn_t i_lsn);
/*!
Convert an LSN into the corresponding MSF.
*/
void cdio_lsn_to_msf (lsn_t lsn, msf_t *msf);
void cdio_lsn_to_msf (lsn_t i_lsn, msf_t *p_msf);
/*!
Convert a MSF into the corresponding LBA.
CDIO_INVALID_LBA is returned if there is an error.
*/
lba_t cdio_msf_to_lba (const msf_t *msf);
lba_t cdio_msf_to_lba (const msf_t *p_msf);
/*!
Convert a MSF into the corresponding LSN.
CDIO_INVALID_LSN is returned if there is an error.
*/
lsn_t cdio_msf_to_lsn (const msf_t *msf);
lsn_t cdio_msf_to_lsn (const msf_t *p_msf);
/*!
Convert a MSF - broken out as 3 integer components into the

View File

@@ -1,5 +1,5 @@
/*
$Id: freebsd.c,v 1.20 2005/03/05 23:21:40 rocky Exp $
$Id: freebsd.c,v 1.21 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -27,7 +27,7 @@
# include "config.h"
#endif
static const char _rcsid[] = "$Id: freebsd.c,v 1.20 2005/03/05 23:21:40 rocky Exp $";
static const char _rcsid[] = "$Id: freebsd.c,v 1.21 2005/03/06 11:21:52 rocky Exp $";
#include "freebsd.h"
@@ -301,13 +301,13 @@ audio_play_msf_freebsd (void *p_user_data, msf_t *p_start_msf,
const _img_private_t *p_env = p_user_data;
struct ioc_play_msf freebsd_play_msf;
freebsd_play_msf.start_m = p_start_msf->m;
freebsd_play_msf.start_s = p_start_msf->s;
freebsd_play_msf.start_f = p_start_msf->f;
freebsd_play_msf.start_m = cdio_from_bcd8(p_start_msf->m);
freebsd_play_msf.start_s = cdio_from_bcd8(p_start_msf->s);
freebsd_play_msf.start_f = cdio_from_bcd8(p_start_msf->f);
freebsd_play_msf.end_m = p_end_msf->m;
freebsd_play_msf.end_s = p_end_msf->s;
freebsd_play_msf.end_f = p_end_msf->f;
freebsd_play_msf.end_m = cdio_from_bcd8(p_end_msf->m);
freebsd_play_msf.end_s = cdio_from_bcd8(p_end_msf->s);
freebsd_play_msf.end_f = cdio_from_bcd8(p_end_msf->f);
return ioctl(p_env->gen.fd, CDIOCPLAYMSF, &freebsd_play_msf);
}

View File

@@ -1,5 +1,5 @@
/*
$Id: win32_ioctl.c,v 1.18 2005/03/06 00:54:50 rocky Exp $
$Id: win32_ioctl.c,v 1.19 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -26,7 +26,7 @@
# include "config.h"
#endif
static const char _rcsid[] = "$Id: win32_ioctl.c,v 1.18 2005/03/06 00:54:50 rocky Exp $";
static const char _rcsid[] = "$Id: win32_ioctl.c,v 1.19 2005/03/06 11:21:52 rocky Exp $";
#ifdef HAVE_WIN32_CDROM
@@ -140,13 +140,13 @@ audio_play_msf_win32ioctl (void *p_user_data, msf_t *p_start_msf,
CDROM_PLAY_AUDIO_MSF play;
DWORD dw_bytes_returned;
play.StartingM = p_start_msf->m;
play.StartingS = p_start_msf->s;
play.StartingF = p_start_msf->f;
play.StartingM = cdio_from_bcd8(p_start_msf->m);
play.StartingS = cdio_from_bcd8(p_start_msf->s);
play.StartingF = cdio_from_bcd8(p_start_msf->f);
play.EndingM = p_end_msf->m;
play.EndingS = p_end_msf->s;
play.EndingF = p_end_msf->f;
play.EndingM = cdio_from_bcd8(p_end_msf->m);
play.EndingS = cdio_from_bcd8(p_end_msf->s);
play.EndingF = cdio_from_bcd8(p_end_msf->f);
bool b_success =
DeviceIoControl(p_env->h_device_handle, IOCTL_CDROM_PLAY_AUDIO_MSF,

View File

@@ -1,5 +1,5 @@
/*
$Id: audio.c,v 1.4 2005/03/05 09:26:52 rocky Exp $
$Id: audio.c,v 1.5 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -148,3 +148,30 @@ cdio_audio_set_volume (CdIo_t *p_cdio, cdio_audio_volume_t *p_volume)
return DRIVER_OP_UNSUPPORTED;
}
}
/*!
Resume playing an audio CD.
@param p_cdio the CD object to be acted upon.
*/
driver_return_code_t
cdio_audio_stop (CdIo_t *p_cdio)
{
if (!p_cdio) return DRIVER_OP_UNINIT;
if (!p_cdio->op.audio_stop) {
return p_cdio->op.audio_stop(p_cdio->env);
} else {
return DRIVER_OP_UNSUPPORTED;
}
}
/*
* Local variables:
* c-file-style: "gnu"
* tab-width: 8
* indent-tabs-mode: nil
* End:
*/

View File

@@ -1,5 +1,5 @@
/*
$Id: cdio_private.h,v 1.21 2005/03/05 10:48:41 rocky Exp $
$Id: cdio_private.h,v 1.22 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -111,14 +111,30 @@ extern "C" {
*/
driver_return_code_t (*audio_set_volume)
( void *p_env, cdio_audio_volume_t *p_volume );
/*!
Stop playing an audio CD.
@param p_env the CD object to be acted upon.
*/
driver_return_code_t (*audio_stop) ( void *p_env );
/*!
Close media tray in CD drive if there is a routine to do so.
@param p_env the CD object to be acted upon.
*/
driver_return_code_t (*close_tray) ( void *p_env );
/*!
Eject media in CD drive. If successful, as a side effect we
also free obj. Return 0 if success and 1 for failure.
also free p_env.
@param p_env the CD object to be acted upon.
If the CD is ejected *p_env is freed and p_env set to NULL.
*/
int (*eject_media) (void *p_env);
driver_return_code_t (*eject_media) ( void *p_env );
/*!
Release and free resources associated with cd.
@@ -134,7 +150,7 @@ extern "C" {
Get the block size for subsequest read requests, via a SCSI MMC
MODE_SENSE 6 command.
*/
int (*get_blocksize) (void *p_env);
int (*get_blocksize) ( void *p_env );
/*!
Get cdtext information for a CdIo object.
@@ -146,7 +162,7 @@ extern "C" {
If i_track is 0 or CDIO_CDROM_LEADOUT_TRACK the track returned
is the information assocated with the CD.
*/
cdtext_t * (*get_cdtext) (void *p_env, track_t i_track);
cdtext_t * (*get_cdtext) ( void *p_env, track_t i_track );
/*!
Return an array of device names. if CdIo is NULL (we haven't
@@ -155,7 +171,7 @@ extern "C" {
NULL is returned if we couldn't return a list of devices.
*/
char ** (*get_devices) (void);
char ** (*get_devices) ( void );
/*!
Get the default CD device.
@@ -167,18 +183,18 @@ extern "C" {
there is no media in it and it is possible for this routine to return
NULL even though there may be a hardware CD-ROM.
*/
char * (*get_default_device)(void);
char * (*get_default_device) ( void );
/*!
Return the size of the CD in logical block address (LBA) units.
@return the lsn. On error 0 or CDIO_INVALD_LSN.
*/
lsn_t (*get_disc_last_lsn) (void *p_env);
lsn_t (*get_disc_last_lsn) ( void *p_env );
/*!
Get disc mode associated with cd_obj.
*/
discmode_t (*get_discmode) (void *p_env);
discmode_t (*get_discmode) ( void *p_env );
/*!
Return the what kind of device we've got.
@@ -193,7 +209,7 @@ extern "C" {
Return the number of of the first track.
CDIO_INVALID_TRACK is returned on error.
*/
track_t (*get_first_track_num) (void *p_env);
track_t (*get_first_track_num) ( void *p_env );
/*!
Get the CD-ROM hardware info via a SCSI MMC INQUIRY command.
@@ -209,7 +225,7 @@ extern "C" {
@param i_last_session pointer to the session number to be returned.
*/
driver_return_code_t (*get_last_session)
(void *p_env, /*out*/ lsn_t *i_last_session);
( void *p_env, /*out*/ lsn_t *i_last_session );
/*!
Find out if media has changed since the last call.
@@ -217,31 +233,31 @@ extern "C" {
@return 1 if media has changed since last call, 0 if not. Error
return codes are the same as driver_return_code_t
*/
int (*get_media_changed) (const void *p_env);
int (*get_media_changed) ( const void *p_env );
/*!
Return the media catalog number MCN from the CD or NULL if
there is none or we don't have the ability to get it.
*/
char * (*get_mcn) (const void *p_env);
char * (*get_mcn) ( const void *p_env );
/*!
Return the number of tracks in the current medium.
CDIO_INVALID_TRACK is returned on error.
*/
track_t (*get_num_tracks) (void *p_env);
track_t (*get_num_tracks) ( void *p_env );
/*! Return number of channels in track: 2 or 4; -2 if not
implemented or -1 for error.
Not meaningful if track is not an audio track.
*/
int (*get_track_channels) (const void *p_env, track_t i_track);
int (*get_track_channels) ( const void *p_env, track_t i_track );
/*! Return 0 if track is copy protected, 1 if not, or -1 for error
or -2 if not implimented (yet). Is this meaningful if not an
audio track?
*/
track_flag_t (*get_track_copy_permit) (void *p_env, track_t i_track);
track_flag_t (*get_track_copy_permit) ( void *p_env, track_t i_track );
/*!
Return the starting LBA for track number
@@ -250,12 +266,12 @@ extern "C" {
using track_num LEADOUT_TRACK or the total tracks+1.
CDIO_INVALID_LBA is returned on error.
*/
lba_t (*get_track_lba) (void *p_env, track_t i_track);
lba_t (*get_track_lba) ( void *p_env, track_t i_track );
/*!
Get format of track.
*/
track_format_t (*get_track_format) (void *p_env, track_t i_track);
track_format_t (*get_track_format) ( void *p_env, track_t i_track );
/*!
Return true if we have XA data (green, mode2 form1) or
@@ -265,7 +281,7 @@ extern "C" {
FIXME: there's gotta be a better design for this and get_track_format?
*/
bool (*get_track_green) (void *p_env, track_t i_track);
bool (*get_track_green) ( void *p_env, track_t i_track );
/*!
Return the starting MSF (minutes/secs/frames) for track number
@@ -274,7 +290,7 @@ extern "C" {
using i_track LEADOUT_TRACK or the total tracks+1.
False is returned on error.
*/
bool (*get_track_msf) (void *p_env, track_t i_track, msf_t *p_msf);
bool (*get_track_msf) ( void *p_env, track_t i_track, msf_t *p_msf );
/*! Return 1 if track has pre-emphasis, 0 if not, or -1 for error
or -2 if not implimented (yet). Is this meaningful if not an
@@ -288,21 +304,21 @@ extern "C" {
Returns (off_t) -1 on error.
Similar to libc's lseek()
*/
off_t (*lseek) (void *p_env, off_t offset, int whence);
off_t (*lseek) ( void *p_env, off_t offset, int whence );
/*!
Reads into buf the next size bytes.
Returns -1 on error.
Similar to libc's read()
*/
ssize_t (*read) (void *p_env, void *p_buf, size_t i_size);
ssize_t (*read) ( void *p_env, void *p_buf, size_t i_size );
/*!
Reads a single mode2 sector from cd device into buf starting
from lsn. Returns 0 if no error.
*/
int (*read_audio_sectors) (void *p_env, void *p_buf, lsn_t i_lsn,
unsigned int i_blocks);
int (*read_audio_sectors) ( void *p_env, void *p_buf, lsn_t i_lsn,
unsigned int i_blocks );
/*!
Read a data sector
@@ -380,7 +396,7 @@ extern "C" {
/*!
Set the arg "key" with "value" in the source device.
*/
int (*set_arg) (void *p_env, const char key[], const char value[]);
int (*set_arg) ( void *p_env, const char key[], const char value[] );
/*!
Set the blocksize for subsequent reads.

View File

@@ -1,5 +1,5 @@
/*
$Id: device.c,v 1.12 2005/03/05 10:48:41 rocky Exp $
$Id: device.c,v 1.13 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -288,12 +288,30 @@ cdio_destroy (CdIo_t *p_cdio)
free (p_cdio);
}
/*!
/*!
Close media tray in CD drive if there is a routine to do so.
@param p_cdio the CD object to be acted upon.
If the CD is ejected *p_cdio is freed and p_cdio set to NULL.
*/
driver_return_code_t
cdio_close_tray (CdIo_t *p_cdio)
{
if (!p_cdio) return DRIVER_OP_UNINIT;
if (!p_cdio->op.close_tray) {
return p_cdio->op.close_tray(p_cdio->env);
} else {
return DRIVER_OP_UNSUPPORTED;
}
}
/*!
Eject media in CD drive if there is a routine to do so.
@param p_cdio the CD object to be acted upon.
If the CD is ejected *p_cdio is freed and p_cdio set to NULL.
*/
*/
driver_return_code_t
cdio_eject_media (CdIo_t **pp_cdio)
{

View File

@@ -1,5 +1,5 @@
/*
$Id: gnu_linux.c,v 1.4 2005/03/06 00:03:53 rocky Exp $
$Id: gnu_linux.c,v 1.5 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2002, 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -27,7 +27,7 @@
# include "config.h"
#endif
static const char _rcsid[] = "$Id: gnu_linux.c,v 1.4 2005/03/06 00:03:53 rocky Exp $";
static const char _rcsid[] = "$Id: gnu_linux.c,v 1.5 2005/03/06 11:21:52 rocky Exp $";
#include <string.h>
@@ -233,13 +233,13 @@ audio_play_msf_linux (void *p_user_data, msf_t *p_start_msf, msf_t *p_end_msf)
const _img_private_t *p_env = p_user_data;
struct cdrom_msf cdrom_msf;
cdrom_msf.cdmsf_min0 = p_start_msf->m;
cdrom_msf.cdmsf_sec0 = p_start_msf->s;
cdrom_msf.cdmsf_frame0 = p_start_msf->f;
cdrom_msf.cdmsf_min0 = cdio_from_bcd8(p_start_msf->m);
cdrom_msf.cdmsf_sec0 = cdio_from_bcd8(p_start_msf->s);
cdrom_msf.cdmsf_frame0 = cdio_from_bcd8(p_start_msf->f);
cdrom_msf.cdmsf_min1 = p_end_msf->m;
cdrom_msf.cdmsf_sec1 = p_end_msf->s;
cdrom_msf.cdmsf_frame1 = p_end_msf->f;
cdrom_msf.cdmsf_min1 = cdio_from_bcd8(p_end_msf->m);
cdrom_msf.cdmsf_sec1 = cdio_from_bcd8(p_end_msf->s);
cdrom_msf.cdmsf_frame1 = cdio_from_bcd8(p_end_msf->f);
return ioctl(p_env->gen.fd, CDROMPLAYMSF, &cdrom_msf);
}
@@ -283,7 +283,6 @@ audio_read_subchannel_linux (void *p_user_data,
static driver_return_code_t
audio_resume_linux (void *p_user_data)
{
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDROMRESUME, 0);
}
@@ -291,17 +290,42 @@ audio_resume_linux (void *p_user_data)
/*!
Set the volume of an audio CD.
@param p_cdio the CD object to be acted upon.
@param p_user_data the CD object to be acted upon.
*/
static driver_return_code_t
audio_set_volume_linux (void *p_user_data, cdio_audio_volume_t *p_volume)
{
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDROMVOLCTRL, p_volume);
}
/*!
Stop playing an audio CD.
@param p_user_data the CD object to be acted upon.
*/
static driver_return_code_t
audio_stop_linux (void *p_user_data)
{
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDROMSTOP);
}
/*!
Stop playing an audio CD.
@param p_user_data the CD object to be acted upon.
*/
static driver_return_code_t
close_tray_linux (void *p_user_data)
{
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDROMCLOSETRAY);
}
/*!
Return the value associated with the key "arg".
*/
@@ -1329,6 +1353,8 @@ cdio_open_am_linux (const char *psz_orig_source, const char *access_mode)
#endif
.audio_resume = audio_resume_linux,
.audio_set_volume = audio_set_volume_linux,
.audio_stop = audio_stop_linux,
.close_tray = close_tray_linux,
.eject_media = eject_media_linux,
.free = cdio_generic_free,
.get_arg = get_arg_linux,

View File

@@ -20,6 +20,8 @@ cdio_audio_play_track_index
cdio_audio_read_subchannel
cdio_audio_resume
cdio_audio_set_volume
cdio_audio_stop
cdio_close_tray
cdio_debug
cdio_destroy
cdio_driver_describe

View File

@@ -1,5 +1,5 @@
/*
$Id: solaris.c,v 1.3 2005/03/06 00:55:42 rocky Exp $
$Id: solaris.c,v 1.4 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2002, 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -38,7 +38,7 @@
#ifdef HAVE_SOLARIS_CDROM
static const char _rcsid[] = "$Id: solaris.c,v 1.3 2005/03/06 00:55:42 rocky Exp $";
static const char _rcsid[] = "$Id: solaris.c,v 1.4 2005/03/06 11:21:52 rocky Exp $";
#ifdef HAVE_GLOB_H
#include <glob.h>
@@ -144,12 +144,12 @@ audio_play_msf_solaris (void *p_user_data, msf_t *p_start_msf,
const _img_private_t *p_env = p_user_data;
struct cdrom_msf solaris_msf;
solaris_msf.cdmsf_min0 = p_start_msf->m;
solaris_msf.cdmsf_sec0 = p_start_msf->s;
solaris_msf.cdmsf_frame0 = p_start_msf->f;
solaris_msf.cdmsf_min1 = p_end_msf->m;
solaris_msf.cdmsf_sec1 = p_end_msf->s;
solaris_msf.cdmsf_frame1 = p_end_msf->f;
solaris_msf.cdmsf_min0 = cdio_from_bcd8(p_start_msf->m);
solaris_msf.cdmsf_sec0 = cdio_from_bcd8(p_start_msf->s);
solaris_msf.cdmsf_frame0 = cdio_from_bcd8(p_start_msf->f);
solaris_msf.cdmsf_min1 = cdio_from_bcd8(p_end_msf->m);
solaris_msf.cdmsf_sec1 = cdio_from_bcd8(p_end_msf->s);
solaris_msf.cdmsf_frame1 = cdio_from_bcd8(p_end_msf->f);
return ioctl(p_env->gen.fd, CDROMPLAYMSF, &solaris_msf);
}

View File

@@ -1,5 +1,5 @@
/*
$Id: cd-info.c,v 1.131 2005/03/06 02:59:26 rocky Exp $
$Id: cd-info.c,v 1.132 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1996, 1997, 1998 Gerd Knorr <kraxel@bytesex.org>
@@ -26,6 +26,7 @@
*/
#include "util.h"
#include "cddb.h"
#include <stdarg.h>
#ifdef HAVE_CDDB
@@ -349,60 +350,6 @@ parse_options (int argc, const char *argv[])
return true;
}
/* ------------------------------------------------------------------------ */
/* CDDB */
/*
Returns the sum of the decimal digits in a number. Eg. 1955 = 20
*/
static int
cddb_dec_digit_sum(int n)
{
int ret=0;
for (;;) {
ret += n%10;
n = n/10;
if (!n)
return ret;
}
}
/* Return the number of seconds (discarding frame portion) of an MSF */
static inline unsigned int
msf_seconds(msf_t *msf)
{
return cdio_from_bcd8(msf->m)*CDIO_CD_SECS_PER_MIN + cdio_from_bcd8(msf->s);
}
/*
Compute the CDDB disk ID for an Audio disk. This is a funny checksum
consisting of the concatenation of 3 things:
the sum of the decimal digits of sizes of all tracks,
the total length of the disk, and
the number of tracks.
*/
static unsigned long
cddb_discid(CdIo_t *p_cdio, int i_tracks)
{
int i,t,n=0;
msf_t start_msf;
msf_t msf;
for (i = 1; i <= i_tracks; i++) {
cdio_get_track_msf(p_cdio, i, &msf);
n += cddb_dec_digit_sum(msf_seconds(&msf));
}
cdio_get_track_msf(p_cdio, 1, &start_msf);
cdio_get_track_msf(p_cdio, CDIO_CDROM_LEADOUT_TRACK, &msf);
t = msf_seconds(&msf) - msf_seconds(&start_msf);
return ((n % 0xff) << 24 | t << 8 | i_tracks);
}
/* CDIO logging routines */
static cdio_log_handler_t gl_default_cdio_log_handler = NULL;

77
src/cddb.c Normal file
View File

@@ -0,0 +1,77 @@
/*
$Id: cddb.c,v 1.1 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
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
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <cdio/cdio.h>
#include <cdio/util.h>
#include "cddb.h"
/* Return the number of seconds (discarding frame portion) of an MSF */
static inline unsigned int
msf_seconds(msf_t *p_msf)
{
return
cdio_from_bcd8(p_msf->m)*CDIO_CD_SECS_PER_MIN + cdio_from_bcd8(p_msf->s);
}
/*!
Returns the sum of the decimal digits in a number. Eg. 1955 = 20
*/
static int
cddb_dec_digit_sum(int n)
{
int ret=0;
for (;;) {
ret += n%10;
n = n/10;
if (!n) return ret;
}
}
/*!
Compute the CDDB disk ID for an Audio disk. This is a funny checksum
consisting of the concatenation of 3 things:
the sum of the decimal digits of sizes of all tracks,
the total length of the disk, and
the number of tracks.
*/
unsigned long
cddb_discid(CdIo_t *p_cdio, track_t i_tracks)
{
int i,t,n=0;
msf_t start_msf;
msf_t msf;
for (i = 1; i <= i_tracks; i++) {
cdio_get_track_msf(p_cdio, i, &msf);
n += cddb_dec_digit_sum(msf_seconds(&msf));
}
cdio_get_track_msf(p_cdio, 1, &start_msf);
cdio_get_track_msf(p_cdio, CDIO_CDROM_LEADOUT_TRACK, &msf);
t = msf_seconds(&msf) - msf_seconds(&start_msf);
return ((n % 0xff) << 24 | t << 8 | i_tracks);
}

28
src/cddb.h Normal file
View File

@@ -0,0 +1,28 @@
/*
$Id: cddb.h,v 1.1 2005/03/06 11:21:52 rocky Exp $
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
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
*/
/*!
Compute the CDDB disk ID for an Audio disk. This is a funny checksum
consisting of the concatenation of 3 things:
the sum of the decimal digits of sizes of all tracks,
the total length of the disk, and
the number of tracks.
*/
unsigned long cddb_discid(CdIo_t *p_cdio, track_t i_tracks);