First commit after CVS conversion. Should be just administrative changes.
This commit is contained in:
8
lib/cdda_interface/.cvsignore
Normal file
8
lib/cdda_interface/.cvsignore
Normal file
@@ -0,0 +1,8 @@
|
||||
.deps
|
||||
.libs
|
||||
Makefile
|
||||
Makefile.in
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
*.la.ver
|
||||
3
lib/cdda_interface/.gitignore
vendored
Normal file
3
lib/cdda_interface/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/.deps
|
||||
/Makefile
|
||||
/Makefile.in
|
||||
152
lib/cdda_interface/Makefile.am
Normal file
152
lib/cdda_interface/Makefile.am
Normal file
@@ -0,0 +1,152 @@
|
||||
# $Id: Makefile.am,v 1.16 2008/10/20 01:25:10 rocky Exp $
|
||||
#
|
||||
# Copyright (C) 2004, 2005, 2006, 2007, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
########################################################
|
||||
# Things to make the cdda_interface library
|
||||
########################################################
|
||||
|
||||
#
|
||||
# From libtool documentation amended with guidance from N. Boullis:
|
||||
#
|
||||
# 1. Start with version information of `0:0:0' for each libtool library.
|
||||
#
|
||||
# 2. It is probably not a good idea to update the version information
|
||||
# several times between public releases, but rather once per public
|
||||
# release. (This seems to be more an aesthetic consideration than
|
||||
# a hard technical one.)
|
||||
#
|
||||
# 3. If the library source code has changed at all since the last
|
||||
# update, then increment REVISION (`C:R:A' becomes `C:R+1:A').
|
||||
#
|
||||
# 4. If any interfaces have been added, removed, or changed since the
|
||||
# last update, increment CURRENT, and set REVISION to 0.
|
||||
#
|
||||
# 5. If any interfaces have been added since the last public release,
|
||||
# then increment AGE.
|
||||
#
|
||||
# 6. If any interfaces have been removed or changed since the last
|
||||
# public release, then set AGE to 0. A changed interface means an
|
||||
# incompatibility with previous versions.
|
||||
|
||||
EXTRA_DIST = libcdio_cdda.sym
|
||||
|
||||
libcdio_cdda_la_CURRENT = 0
|
||||
libcdio_cdda_la_REVISION = 5
|
||||
libcdio_cdda_la_AGE = 0
|
||||
|
||||
noinst_HEADERS = common_interface.h drive_exceptions.h low_interface.h \
|
||||
smallft.h utils.h
|
||||
|
||||
libcdio_cdda_sources = common_interface.c cddap_interface.c interface.c \
|
||||
scan_devices.c smallft.c toc.c utils.c drive_exceptions.c
|
||||
|
||||
lib_LTLIBRARIES = libcdio_cdda.la
|
||||
|
||||
libcdio_cdda_la_SOURCES = $(libcdio_cdda_sources)
|
||||
libcdio_cdda_la_ldflags = -version-info $(libcdio_cdda_la_CURRENT):$(libcdio_cdda_la_REVISION):$(libcdio_cdda_la_AGE) @LT_NO_UNDEFINED@
|
||||
|
||||
INCLUDES = $(LIBCDIO_CFLAGS)
|
||||
|
||||
FLAGS=@LIBCDIO_CFLAGS@ @UCDROM_H@ @TYPESIZES@ @CFLAGS@
|
||||
|
||||
OPT=$(FLAGS)
|
||||
DEBUG=$(FLAGS) -DCDDA_TEST
|
||||
|
||||
## test:
|
||||
## $(MAKE) libcdio_cdda.a CFLAGS="$(DEBUG)"
|
||||
## $(CC) $(DEBUG) -c test_interface.c
|
||||
## $(LD) $(DEBUG) test_interface.o $(LDFLAGS) -o cdda_test $(LIBS) libcdio_cdda.a
|
||||
|
||||
LIBS = $(LIBCDIO_LIBS) @COS_LIB@
|
||||
|
||||
|
||||
########################################################
|
||||
# Things to version the symbols in the libraries
|
||||
########################################################
|
||||
|
||||
# An explanation of the versioning problem from Nicolas Boullis and
|
||||
# the versioned symbol solution he uses below...
|
||||
#
|
||||
# Currently, libvcdinfo uses the cdio_open function from libcdio.
|
||||
# Let's imagine a program foobar that uses both the vcdinfo_open
|
||||
# function from libvcdinfo and the cdio_open function from libcdio.
|
||||
|
||||
# Currently, libcdio has SONAME libcdio.so.0, libvcdinfo has SONAME
|
||||
# libvcdinfo.so.0 and requires libcdio.so.0, and foobar requires both
|
||||
# libvcdinfo.so.0 and libcdio.so.0. Everything looks fine.
|
||||
#
|
||||
# Now, for some reason, you decide to change the cdio_open function.
|
||||
# That's your right, but you have to bump the CURRENT version and (if I
|
||||
# understand it correctly, athough this is not that clear in libtool's
|
||||
# documentation) set the AGE to 0. Anyway, this bumps the SONAME, which is
|
||||
# sane since the interface changes incompatibly.
|
||||
|
||||
# Now, you have a new libcdio with SONAME libcdio.so.1. But libvcdinfo and
|
||||
# foobar still require libcdio.so.0. Everything is still fine.
|
||||
|
||||
# Now, after some minor changes, the author of foobar recompiles foobar.
|
||||
# Then, foobar now requires libvcdinfo.so.0 and libcdio.so.1. And foobar
|
||||
# now segfaults...
|
||||
|
||||
# What is happening? When you run foobar, if brings both libvcdinfo.so.0
|
||||
# and libcdio.so.1, but libvcdinfo.so.0 also brings libcdio.so.0. So you
|
||||
# have both libcdio.so.0 and libcdio.so.1 that bring their symbols to the
|
||||
# global namespace. Hence, you have to incompatible versions of the
|
||||
# cdio_open function in the name space. When foobar calls cdio_open, it
|
||||
# may choose the wrong function, and segfaults...
|
||||
|
||||
# With versioned symbols, the cdio_open function from libcdio.so.0 may be
|
||||
# known as (something that looks like) cdio_open@@CDIO_0. An the cdio_open
|
||||
# function from libcdio.so.1 as cdio_open@@CDIO_1. Both versions of
|
||||
# libcdio would still be brought in by the most recent foobar, but foobar
|
||||
# (and libvcdinfo) know which versioned function to use and then use the
|
||||
# good one.
|
||||
|
||||
|
||||
# This is some simple versioning where every symbol is versioned with
|
||||
# something that looks like the SONAME of the library. More complex (and
|
||||
# better) versioning is possible; it is for example what is used by glibc.
|
||||
# But good complex versioning is something that requires much more
|
||||
# work...
|
||||
|
||||
|
||||
# The below is a impliments symbol versioning. First of all, I
|
||||
# compute MAJOR as CURENT - AGE; that is what is used within libtool
|
||||
# (at least on GNU/Linux systems) for the number in the SONAME. The
|
||||
# nm command gives the list of symbols known in each of the object
|
||||
# files that will be part of the shared library. And the sed command
|
||||
# extracts from this list those symbols that will be shared. (This sed
|
||||
# command comes from libtool.)
|
||||
|
||||
libcdio_cdda_la_MAJOR = $(shell expr $(libcdio_cdda_la_CURRENT) - $(libcdio_cdda_la_AGE))
|
||||
if BUILD_VERSIONED_LIBS
|
||||
libcdio_cdda_la_LDFLAGS = $(libcdio_cdda_la_ldflags) -Wl,--version-script=libcdio_cdda.la.ver
|
||||
libcdio_cdda_la_DEPENDENCIES = libcdio_cdda.la.ver
|
||||
|
||||
libcdio_cdda.la.ver: $(libcdio_cdda_la_OBJECTS) $(srcdir)/libcdio_cdda.sym
|
||||
echo 'CDIO_CDDA_$(libcdio_cdda_la_MAJOR) { ' > $@
|
||||
objs=`for obj in $(libcdio_cdda_la_OBJECTS); do sed -ne "s/^pic_object='\(.*\)'$$/\1/p" $$obj; done`; \
|
||||
if test -n "$$objs" ; then \
|
||||
nm $${objs} | sed -n -e 's/^.*[ ][ABCDGIRSTW][ABCDGIRSTW]*[ ][ ]*\([_A-Za-z][_A-Za-z0-9]*\)$$/\1/p' | sort -u | { first=true; while read symbol; do if grep -q "^$${symbol}\$$" $(srcdir)/libcdio_cdda.sym; then if test $$first = true; then echo " global:"; first=false; fi; echo " $${symbol};"; fi; done; } >> $@; \
|
||||
nm $${objs} | sed -n -e 's/^.*[ ][ABCDGIRSTW][ABCDGIRSTW]*[ ][ ]*\([_A-Za-z][_A-Za-z0-9]*\)$$/\1/p' | sort -u | { first=true; while read symbol; do if grep -q "^$${symbol}\$$" $(srcdir)/libcdio_cdda.sym; then :; else if test $$first = true; then echo " local:"; first=false; fi; echo " $${symbol};"; fi; done; } >> $@; \
|
||||
fi
|
||||
echo '};' >> $@
|
||||
else
|
||||
libcdio_cdda_la_LDFLAGS = $(libcdio_cdda_la_ldflags)
|
||||
endif
|
||||
|
||||
MOSTLYCLEANFILES = libcdio_cdda.la.ver
|
||||
401
lib/cdda_interface/cddap_interface.c
Normal file
401
lib/cdda_interface/cddap_interface.c
Normal file
@@ -0,0 +1,401 @@
|
||||
/*
|
||||
$Id: cddap_interface.c,v 1.8 2008/06/13 19:26:22 flameeyes Exp $
|
||||
|
||||
Copyright (C) 2004, 2005, 2007, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Original interface.c Copyright (C) 1994-1997
|
||||
Eissfeldt heiko@colossus.escape.de
|
||||
Current blenderization Copyright (C) 1998-1999 Monty xiphmont@mit.edu
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
|
||||
CD-ROM code which interfaces between user-level visible CD paranoia
|
||||
routines and libddio routines. (There is some GNU/Linux-specific
|
||||
code here too that should probably be removed.
|
||||
|
||||
**/
|
||||
|
||||
#include "config.h"
|
||||
#include "common_interface.h"
|
||||
#include "low_interface.h"
|
||||
#include "utils.h"
|
||||
|
||||
/** The below variables are trickery to force the above enum symbol
|
||||
values to be recorded in debug symbol tables. They are used to
|
||||
allow one to refer to the enumeration value names in the typedefs
|
||||
above in a debugger and debugger expressions
|
||||
*/
|
||||
|
||||
paranoia_jitter_t debug_paranoia_jitter;
|
||||
paranoia_cdda_enums_t debug_paranoia_cdda_enums;
|
||||
|
||||
/*! reads TOC via libcdio and returns the number of tracks in the disc.
|
||||
0 is returned if there was an error.
|
||||
*/
|
||||
static int
|
||||
cddap_readtoc (cdrom_drive_t *d)
|
||||
{
|
||||
int i;
|
||||
track_t i_track;
|
||||
|
||||
/* Save TOC Entries */
|
||||
d->tracks = cdio_get_num_tracks(d->p_cdio) ;
|
||||
|
||||
if (CDIO_INVALID_TRACK == d->tracks) return 0;
|
||||
|
||||
i_track = cdio_get_first_track_num(d->p_cdio);
|
||||
|
||||
for ( i=0; i < d->tracks; i++) {
|
||||
d->disc_toc[i].bTrack = i_track;
|
||||
d->disc_toc[i].dwStartSector = cdio_get_track_lsn(d->p_cdio, i_track);
|
||||
i_track++;
|
||||
}
|
||||
|
||||
d->disc_toc[i].bTrack = i_track;
|
||||
d->disc_toc[i].dwStartSector = cdio_get_track_lsn(d->p_cdio,
|
||||
CDIO_CDROM_LEADOUT_TRACK);
|
||||
|
||||
d->cd_extra=FixupTOC(d, i_track);
|
||||
return --i_track; /* without lead-out */
|
||||
}
|
||||
|
||||
|
||||
/* Set operating speed */
|
||||
static int
|
||||
cddap_setspeed(cdrom_drive_t *d, int i_speed)
|
||||
{
|
||||
return cdio_set_speed(d->p_cdio, i_speed);
|
||||
}
|
||||
|
||||
/* read 'i_sector' adjacent audio sectors
|
||||
* into buffer '*p' beginning at sector 'begin'
|
||||
*/
|
||||
|
||||
static long int
|
||||
read_blocks (cdrom_drive_t *d, void *p, lsn_t begin, long i_sectors)
|
||||
{
|
||||
int retry_count = 0;
|
||||
int err;
|
||||
char *buffer=(char *)p;
|
||||
|
||||
do {
|
||||
err = cdio_read_audio_sectors( d->p_cdio, buffer, begin, i_sectors);
|
||||
|
||||
if ( DRIVER_OP_SUCCESS != err ) {
|
||||
if (!d->error_retry) return -7;
|
||||
|
||||
if (i_sectors==1) {
|
||||
/* *Could* be I/O or media error. I think. If we're at
|
||||
30 retries, we better skip this unhappy little
|
||||
sector. */
|
||||
if (retry_count>MAX_RETRIES-1) {
|
||||
char b[256];
|
||||
snprintf(b, sizeof(b),
|
||||
"010: Unable to access sector %ld: skipping...\n",
|
||||
(long int) begin);
|
||||
cderror(d, b);
|
||||
return -10;
|
||||
}
|
||||
}
|
||||
|
||||
if(retry_count>4)
|
||||
if(i_sectors>1)
|
||||
i_sectors=i_sectors*3/4;
|
||||
retry_count++;
|
||||
if (retry_count>MAX_RETRIES) {
|
||||
cderror(d,"007: Unknown, unrecoverable error reading data\n");
|
||||
return(-7);
|
||||
}
|
||||
} else
|
||||
break;
|
||||
} while (err);
|
||||
|
||||
return(i_sectors);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
JITTER_NONE = 0,
|
||||
JITTER_SMALL= 1,
|
||||
JITTER_LARGE= 2,
|
||||
JITTER_MASSIVE=3
|
||||
} jitter_baddness_t;
|
||||
|
||||
/* read 'i_sector' adjacent audio sectors
|
||||
* into buffer '*p' beginning at sector 'begin'
|
||||
*/
|
||||
|
||||
static long int
|
||||
jitter_read (cdrom_drive_t *d, void *p, lsn_t begin, long i_sectors,
|
||||
jitter_baddness_t jitter_badness)
|
||||
{
|
||||
static int i_jitter=0;
|
||||
int jitter_flag;
|
||||
long i_sectors_orig = i_sectors;
|
||||
long i_jitter_offset = 0;
|
||||
|
||||
char *p_buf=malloc(CDIO_CD_FRAMESIZE_RAW*(i_sectors+1));
|
||||
|
||||
if (d->i_test_flags & CDDA_TEST_ALWAYS_JITTER)
|
||||
jitter_flag = 1;
|
||||
else
|
||||
#ifdef HAVE_DRAND48
|
||||
jitter_flag = (drand48() > .9) ? 1 : 0;
|
||||
#else
|
||||
jitter_flag = (rand() > .9) ? 1 : 0;
|
||||
#endif
|
||||
|
||||
if (jitter_flag) {
|
||||
int i_coeff = 0;
|
||||
int i_jitter_sectors = 0;
|
||||
switch(jitter_badness) {
|
||||
case JITTER_SMALL : i_coeff = 4; break;
|
||||
case JITTER_LARGE : i_coeff = 32; break;
|
||||
case JITTER_MASSIVE: i_coeff = 128; break;
|
||||
case JITTER_NONE :
|
||||
default : ;
|
||||
}
|
||||
#ifdef HAVE_DRAND48
|
||||
i_jitter = i_coeff * (int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
#else
|
||||
i_jitter = i_coeff * (int)((rand()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
#endif
|
||||
|
||||
/* We may need to add another sector to compensate for the bytes that
|
||||
will be dropped off when jittering, and the begin location may
|
||||
be a little different.
|
||||
*/
|
||||
i_jitter_sectors = i_jitter / CDIO_CD_FRAMESIZE_RAW;
|
||||
|
||||
if (i_jitter >= 0)
|
||||
i_jitter_offset = i_jitter % CDIO_CD_FRAMESIZE_RAW;
|
||||
else {
|
||||
i_jitter_offset = CDIO_CD_FRAMESIZE_RAW -
|
||||
(-i_jitter % CDIO_CD_FRAMESIZE_RAW);
|
||||
i_jitter_sectors--;
|
||||
}
|
||||
|
||||
|
||||
if (begin + i_jitter_sectors > 0) {
|
||||
#if !TRACE_PARANOIA
|
||||
char buffer[256];
|
||||
sprintf(buffer, "jittering by %d, offset %ld\n", i_jitter,
|
||||
i_jitter_offset);
|
||||
cdmessage(d,buffer);
|
||||
#endif
|
||||
|
||||
begin += i_jitter_sectors;
|
||||
i_sectors ++;
|
||||
} else
|
||||
i_jitter_offset = 0;
|
||||
|
||||
}
|
||||
|
||||
i_sectors = read_blocks(d, p_buf, begin, i_sectors);
|
||||
|
||||
if (i_sectors < 0) return i_sectors;
|
||||
|
||||
if (i_sectors < i_sectors_orig)
|
||||
/* Had to reduce # of sectors due to read errors. So give full amount,
|
||||
with no jittering. */
|
||||
memcpy(p, p_buf, i_sectors*CDIO_CD_FRAMESIZE_RAW);
|
||||
else {
|
||||
/* Got full amount, but now adjust size for jittering. */
|
||||
memcpy(p, p_buf+i_jitter_offset, i_sectors_orig*CDIO_CD_FRAMESIZE_RAW);
|
||||
i_sectors = i_sectors_orig;
|
||||
}
|
||||
|
||||
free(p_buf);
|
||||
return(i_sectors);
|
||||
}
|
||||
|
||||
/* read 'i_sector' adjacent audio sectors
|
||||
* into buffer '*p' beginning at sector 'begin'
|
||||
*/
|
||||
|
||||
static long int
|
||||
cddap_read (cdrom_drive_t *d, void *p, lsn_t begin, long i_sectors)
|
||||
{
|
||||
jitter_baddness_t jitter_badness = d->i_test_flags & 0x3;
|
||||
|
||||
/* read d->nsectors at a time, max. */
|
||||
i_sectors = ( i_sectors > d->nsectors && d->nsectors > 0 )
|
||||
? d->nsectors : i_sectors;
|
||||
|
||||
/* If we are testing under-run correction, we will deliberately set
|
||||
what we read a frame short. */
|
||||
if (d->i_test_flags & CDDA_TEST_UNDERRUN )
|
||||
i_sectors--;
|
||||
|
||||
if (jitter_badness) {
|
||||
return jitter_read(d, p, begin, i_sectors, jitter_badness);
|
||||
} else
|
||||
return read_blocks(d, p, begin, i_sectors);
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
verify_read_command(cdrom_drive_t *d)
|
||||
{
|
||||
int i;
|
||||
int16_t *buff=malloc(CDIO_CD_FRAMESIZE_RAW);
|
||||
int audioflag=0;
|
||||
int i_test_flags = d->i_test_flags;
|
||||
|
||||
d->i_test_flags = 0;
|
||||
|
||||
cdmessage(d,"Verifying drive can read CDDA...\n");
|
||||
|
||||
d->enable_cdda(d,1);
|
||||
|
||||
for(i=1;i<=d->tracks;i++){
|
||||
if(cdda_track_audiop(d,i)==1){
|
||||
long firstsector=cdda_track_firstsector(d,i);
|
||||
long lastsector=cdda_track_lastsector(d,i);
|
||||
long sector=(firstsector+lastsector)>>1;
|
||||
audioflag=1;
|
||||
|
||||
if(d->read_audio(d,buff,sector,1)>0){
|
||||
cdmessage(d,"\tExpected command set reads OK.\n");
|
||||
d->enable_cdda(d,0);
|
||||
free(buff);
|
||||
d->i_test_flags = i_test_flags;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
d->enable_cdda(d,0);
|
||||
|
||||
if(!audioflag){
|
||||
cdmessage(d,"\tCould not find any audio tracks on this disk.\n");
|
||||
return(-403);
|
||||
}
|
||||
|
||||
cdmessage(d,"\n\tUnable to read any data; "
|
||||
"drive probably not CDDA capable.\n");
|
||||
|
||||
cderror(d,"006: Could not read any data from drive\n");
|
||||
|
||||
free(buff);
|
||||
return(-6);
|
||||
}
|
||||
|
||||
#include "drive_exceptions.h"
|
||||
|
||||
#ifdef HAVE_LINUX_MAJOR_H
|
||||
static void
|
||||
check_exceptions(cdrom_drive_t *d, const exception_t *list)
|
||||
{
|
||||
|
||||
int i=0;
|
||||
while(list[i].model){
|
||||
if(!strncmp(list[i].model,d->drive_model,strlen(list[i].model))){
|
||||
if(list[i].bigendianp!=-1)d->bigendianp=list[i].bigendianp;
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_LINUX_MAJOR_H */
|
||||
|
||||
/* set function pointers to use the ioctl routines */
|
||||
int
|
||||
cddap_init_drive (cdrom_drive_t *d)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#if HAVE_LINUX_MAJOR_H
|
||||
switch(d->drive_type){
|
||||
case MATSUSHITA_CDROM_MAJOR: /* sbpcd 1 */
|
||||
case MATSUSHITA_CDROM2_MAJOR: /* sbpcd 2 */
|
||||
case MATSUSHITA_CDROM3_MAJOR: /* sbpcd 3 */
|
||||
case MATSUSHITA_CDROM4_MAJOR: /* sbpcd 4 */
|
||||
/* don't make the buffer too big; this sucker don't preempt */
|
||||
|
||||
cdmessage(d,"Attempting to set sbpcd buffer size...\n");
|
||||
|
||||
d->nsectors=8;
|
||||
|
||||
#if BUFSIZE_DETERMINATION_FIXED
|
||||
while(1){
|
||||
|
||||
/* this ioctl returns zero on error; exactly wrong, but that's
|
||||
what it does. */
|
||||
|
||||
if (ioctl(d->ioctl_fd, CDROMAUDIOBUFSIZ, d->nsectors)==0) {
|
||||
d->nsectors>>=1;
|
||||
if(d->nsectors==0){
|
||||
char buffer[256];
|
||||
d->nsectors=8;
|
||||
sprintf(buffer,"\tTrouble setting buffer size. Defaulting to %d sectors.\n",
|
||||
d->nsectors);
|
||||
cdmessage(d,buffer);
|
||||
break; /* Oh, well. Try to read anyway.*/
|
||||
}
|
||||
} else {
|
||||
char buffer[256];
|
||||
sprintf(buffer,"\tSetting read block size at %d sectors (%ld bytes).\n",
|
||||
d->nsectors,(long)d->nsectors*CDIO_CD_FRAMESIZE_RAW);
|
||||
cdmessage(d,buffer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* BUFSIZE_DETERMINATION_FIXED */
|
||||
|
||||
break;
|
||||
case IDE0_MAJOR:
|
||||
case IDE1_MAJOR:
|
||||
case IDE2_MAJOR:
|
||||
case IDE3_MAJOR:
|
||||
d->nsectors=8; /* it's a define in the linux kernel; we have no
|
||||
way of determining other than this guess tho */
|
||||
d->bigendianp=0;
|
||||
d->is_atapi=1;
|
||||
|
||||
check_exceptions(d, atapi_list);
|
||||
|
||||
break;
|
||||
default:
|
||||
d->nsectors=25; /* The max for SCSI MMC2 */
|
||||
}
|
||||
#else
|
||||
{
|
||||
char buffer[256];
|
||||
d->nsectors = 8;
|
||||
sprintf(buffer,"\tSetting read block size at %d sectors (%ld bytes).\n",
|
||||
d->nsectors,(long)d->nsectors*CDIO_CD_FRAMESIZE_RAW);
|
||||
cdmessage(d,buffer);
|
||||
}
|
||||
#endif /*HAVE_LINUX_MAJOR_H*/
|
||||
|
||||
d->enable_cdda = dummy_exception;
|
||||
d->set_speed = cddap_setspeed;
|
||||
d->read_toc = cddap_readtoc;
|
||||
d->read_audio = cddap_read;
|
||||
|
||||
ret = d->tracks = d->read_toc(d);
|
||||
if(d->tracks<1)
|
||||
return(ret);
|
||||
|
||||
d->opened=1;
|
||||
|
||||
if( (ret=verify_read_command(d)) ) return(ret);
|
||||
|
||||
d->error_retry=1;
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
271
lib/cdda_interface/common_interface.c
Normal file
271
lib/cdda_interface/common_interface.c
Normal file
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
$Id: common_interface.c,v 1.17 2008/04/16 17:00:40 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2005, 2007, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998, 2002 Monty monty@xiph.org
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/******************************************************************
|
||||
*
|
||||
* CDROM communication common to all interface methods is done here
|
||||
* (mostly ioctl stuff, but not ioctls specific to the 'cooked'
|
||||
* interface)
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include <math.h>
|
||||
#include "common_interface.h"
|
||||
#include "utils.h"
|
||||
#include "smallft.h"
|
||||
|
||||
/* Variables to hold debugger-helping enumerations */
|
||||
enum paranoia_cdda_enums;
|
||||
enum paranoia_jitter_enums;
|
||||
|
||||
/*! Determine Endian-ness of the CD-drive based on reading data from
|
||||
it. Some drives return audio data Big Endian while some (most)
|
||||
return data Little Endian. Drives known to return data bigendian are
|
||||
SCSI drives from Kodak, Ricoh, HP, Philips, Plasmon, Grundig
|
||||
CDR100IPW, and Mitsumi CD-R. ATAPI and MMC drives are little endian.
|
||||
|
||||
rocky: As someone who didn't write the code, I have to say this is
|
||||
nothing less than brilliant. An FFT is done both ways and the the
|
||||
transform is looked at to see which has data in the FFT (or audible)
|
||||
portion. (Or so that's how I understand it.)
|
||||
|
||||
@return 1 if big-endian, 0 if little-endian, -1 if we couldn't
|
||||
figure things out or some error.
|
||||
*/
|
||||
int
|
||||
data_bigendianp(cdrom_drive_t *d)
|
||||
{
|
||||
float lsb_votes=0;
|
||||
float msb_votes=0;
|
||||
int i,checked;
|
||||
int endiancache=d->bigendianp;
|
||||
float *a=calloc(1024,sizeof(float));
|
||||
float *b=calloc(1024,sizeof(float));
|
||||
long readsectors=5;
|
||||
int16_t *buff=malloc(readsectors*CDIO_CD_FRAMESIZE_RAW);
|
||||
memset(buff, 0, readsectors*CDIO_CD_FRAMESIZE_RAW);
|
||||
|
||||
/* look at the starts of the audio tracks */
|
||||
/* if real silence, tool in until some static is found */
|
||||
|
||||
/* Force no swap for now */
|
||||
d->bigendianp=-1;
|
||||
|
||||
cdmessage(d,"\nAttempting to determine drive endianness from data...");
|
||||
d->enable_cdda(d,1);
|
||||
for(i=0,checked=0;i<d->tracks;i++){
|
||||
float lsb_energy=0;
|
||||
float msb_energy=0;
|
||||
if(cdda_track_audiop(d,i+1)==1){
|
||||
long firstsector=cdda_track_firstsector(d,i+1);
|
||||
long lastsector=cdda_track_lastsector(d,i+1);
|
||||
int zeroflag=-1;
|
||||
long beginsec=0;
|
||||
|
||||
/* find a block with nonzero data */
|
||||
|
||||
while(firstsector+readsectors<=lastsector){
|
||||
int j;
|
||||
|
||||
if(d->read_audio(d,buff,firstsector,readsectors)>0){
|
||||
|
||||
/* Avoid scanning through jitter at the edges */
|
||||
for(beginsec=0;beginsec<readsectors;beginsec++){
|
||||
int offset=beginsec*CDIO_CD_FRAMESIZE_RAW/2;
|
||||
/* Search *half* */
|
||||
for(j=460;j<128+460;j++)
|
||||
if(buff[offset+j]!=0){
|
||||
zeroflag=0;
|
||||
break;
|
||||
}
|
||||
if(!zeroflag)break;
|
||||
}
|
||||
if(!zeroflag)break;
|
||||
firstsector+=readsectors;
|
||||
}else{
|
||||
d->enable_cdda(d,0);
|
||||
free(a);
|
||||
free(b);
|
||||
free(buff);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
|
||||
beginsec*=CDIO_CD_FRAMESIZE_RAW/2;
|
||||
|
||||
/* un-interleave for an FFT */
|
||||
if(!zeroflag){
|
||||
int j;
|
||||
|
||||
for(j=0;j<128;j++)
|
||||
a[j] = le16_to_cpu(buff[j*2+beginsec+460]);
|
||||
for(j=0;j<128;j++)
|
||||
b[j] = le16_to_cpu(buff[j*2+beginsec+461]);
|
||||
|
||||
fft_forward(128,a,NULL,NULL);
|
||||
fft_forward(128,b,NULL,NULL);
|
||||
|
||||
for(j=0;j<128;j++)
|
||||
lsb_energy+=fabs(a[j])+fabs(b[j]);
|
||||
|
||||
for(j=0;j<128;j++)
|
||||
a[j] = be16_to_cpu(buff[j*2+beginsec+460]);
|
||||
|
||||
for(j=0;j<128;j++)
|
||||
b[j] = be16_to_cpu(buff[j*2+beginsec+461]);
|
||||
|
||||
fft_forward(128,a,NULL,NULL);
|
||||
fft_forward(128,b,NULL,NULL);
|
||||
|
||||
for(j=0;j<128;j++)
|
||||
msb_energy+=fabs(a[j])+fabs(b[j]);
|
||||
}
|
||||
}
|
||||
if(lsb_energy<msb_energy){
|
||||
lsb_votes+=msb_energy/lsb_energy;
|
||||
checked++;
|
||||
}else
|
||||
if(lsb_energy>msb_energy){
|
||||
msb_votes+=lsb_energy/msb_energy;
|
||||
checked++;
|
||||
}
|
||||
|
||||
if(checked==5 && (lsb_votes==0 || msb_votes==0))break;
|
||||
cdmessage(d,".");
|
||||
}
|
||||
|
||||
free(buff);
|
||||
free(a);
|
||||
free(b);
|
||||
d->bigendianp=endiancache;
|
||||
d->enable_cdda(d,0);
|
||||
|
||||
/* How did we vote? Be potentially noisy */
|
||||
if (lsb_votes>msb_votes) {
|
||||
char buffer[256];
|
||||
cdmessage(d,"\n\tData appears to be coming back Little Endian.\n");
|
||||
sprintf(buffer,"\tcertainty: %d%%\n",(int)
|
||||
(100.*lsb_votes/(lsb_votes+msb_votes)+.5));
|
||||
cdmessage(d,buffer);
|
||||
return(0);
|
||||
} else {
|
||||
if(msb_votes>lsb_votes){
|
||||
char buffer[256];
|
||||
cdmessage(d,"\n\tData appears to be coming back Big Endian.\n");
|
||||
sprintf(buffer,"\tcertainty: %d%%\n",(int)
|
||||
(100.*msb_votes/(lsb_votes+msb_votes)+.5));
|
||||
cdmessage(d,buffer);
|
||||
return(1);
|
||||
}
|
||||
|
||||
cdmessage(d,"\n\tCannot determine CDROM drive endianness.\n");
|
||||
return(bigendianp());
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
/*! Here we fix up a couple of things that will never happen. yeah,
|
||||
right.
|
||||
|
||||
The multisession stuff is from Hannu code; it assumes it knows the
|
||||
leadout/leadin size. [I think Hannu refers to Hannu Savolainen
|
||||
from GNU/Linux Kernel code.]
|
||||
|
||||
@return -1 if we can't get multisession info, 0 if there is one
|
||||
session only or the last session LBA is the same as the first audio
|
||||
track and 1 if the multi-session lba is higher than first audio track
|
||||
*/
|
||||
int
|
||||
FixupTOC(cdrom_drive_t *d, track_t i_tracks)
|
||||
{
|
||||
int j;
|
||||
|
||||
/* First off, make sure the 'starting sector' is >=0 */
|
||||
|
||||
for( j=0; j<i_tracks; j++){
|
||||
if (d->disc_toc[j].dwStartSector<0 ) {
|
||||
cdmessage(d,"\n\tTOC entry claims a negative start offset: massaging"
|
||||
".\n");
|
||||
d->disc_toc[j].dwStartSector=0;
|
||||
}
|
||||
if( j<i_tracks-1 && d->disc_toc[j].dwStartSector>
|
||||
d->disc_toc[j+1].dwStartSector ) {
|
||||
cdmessage(d,"\n\tTOC entry claims an overly large start offset: massaging"
|
||||
".\n");
|
||||
d->disc_toc[j].dwStartSector=0;
|
||||
}
|
||||
|
||||
}
|
||||
/* Make sure the listed 'starting sectors' are actually increasing.
|
||||
Flag things that are blatant/stupid/wrong */
|
||||
{
|
||||
lsn_t last=d->disc_toc[0].dwStartSector;
|
||||
for ( j=1; j<i_tracks; j++){
|
||||
if ( d->disc_toc[j].dwStartSector<last ) {
|
||||
cdmessage(d,"\n\tTOC entries claim non-increasing offsets: massaging"
|
||||
".\n");
|
||||
d->disc_toc[j].dwStartSector=last;
|
||||
|
||||
}
|
||||
last=d->disc_toc[j].dwStartSector;
|
||||
}
|
||||
}
|
||||
|
||||
d->audio_last_sector = CDIO_INVALID_LSN;
|
||||
|
||||
{
|
||||
lsn_t last_ses_lsn;
|
||||
if (cdio_get_last_session (d->p_cdio, &last_ses_lsn) < 0)
|
||||
return -1;
|
||||
|
||||
/* A Red Book Disc must have only one session, otherwise this is a
|
||||
* CD Extra */
|
||||
if (last_ses_lsn > d->disc_toc[0].dwStartSector) {
|
||||
/* CD Extra discs have two session, the first one ending after
|
||||
* the last audio track
|
||||
* Thus the need to fix the length of the the audio data portion to
|
||||
* not cross the lead-out of this session */
|
||||
for (j = i_tracks-1; j > 1; j--) {
|
||||
if (cdio_get_track_format(d->p_cdio, j+1) != TRACK_FORMAT_AUDIO &&
|
||||
cdio_get_track_format(d->p_cdio, j) == TRACK_FORMAT_AUDIO) {
|
||||
/* First session lead-out is 1:30
|
||||
* Lead-ins are 1:00
|
||||
* Every session's first track have a 0:02 pregap
|
||||
*
|
||||
* That makes a control data section of (90+60+2)*75 sectors in the
|
||||
* last audio track */
|
||||
const int gap = ((90+60+2) * CDIO_CD_FRAMES_PER_SEC);
|
||||
|
||||
if ((last_ses_lsn - gap >= d->disc_toc[j-1].dwStartSector) &&
|
||||
(last_ses_lsn - gap < d->disc_toc[j].dwStartSector)) {
|
||||
d->audio_last_sector = last_ses_lsn - gap - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
54
lib/cdda_interface/common_interface.h
Normal file
54
lib/cdda_interface/common_interface.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
$Id: common_interface.h,v 1.7 2008/04/16 17:00:40 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _CDDA_COMMON_INTERFACE_H_
|
||||
#define _CDDA_COMMON_INTERFACE_H_
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <cdio/types.h>
|
||||
#include "low_interface.h"
|
||||
|
||||
#if defined(HAVE_LSTAT) && !defined(HAVE_WIN32_CDROM)
|
||||
/* Define this if the CD-ROM device is a file in the filesystem
|
||||
that can be lstat'd
|
||||
*/
|
||||
#define DEVICE_IN_FILESYSTEM 1
|
||||
#else
|
||||
#undef DEVICE_IN_FILESYSTEM
|
||||
#endif
|
||||
|
||||
/** Test for presence of a cdrom by pinging with the 'CDROMVOLREAD' ioctl() */
|
||||
extern int ioctl_ping_cdrom(int fd);
|
||||
|
||||
extern char *atapi_drive_info(int fd);
|
||||
|
||||
/*! Here we fix up a couple of things that will never happen. yeah,
|
||||
right.
|
||||
|
||||
rocky OMITTED FOR NOW:
|
||||
The multisession stuff is from Hannu's code; it assumes it knows
|
||||
the leadout/leadin size.
|
||||
*/
|
||||
extern int FixupTOC(cdrom_drive_t *d, track_t tracks);
|
||||
|
||||
#endif /*_CDDA_COMMON_INTERFACE_H_*/
|
||||
84
lib/cdda_interface/drive_exceptions.c
Normal file
84
lib/cdda_interface/drive_exceptions.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
$Id: drive_exceptions.c,v 1.1 2008/06/14 10:36:49 flameeyes Exp $
|
||||
|
||||
Copyright (C) 2004, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "common_interface.h"
|
||||
#include "drive_exceptions.h"
|
||||
|
||||
int dummy_exception (cdrom_drive_t *d,int Switch)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
#if HAVE_LINUX_MAJOR_H
|
||||
/* list of drives that affect autosensing in ATAPI specific portions of code
|
||||
(force drives to detect as ATAPI or SCSI, force ATAPI read command */
|
||||
|
||||
const exception_t atapi_list[]={
|
||||
{"SAMSUNG SCR-830 REV 2.09 2.09 ", 1, 0, dummy_exception,scsi_read_mmc2,0},
|
||||
{"Memorex CR-622", 1, 0, dummy_exception, NULL,0},
|
||||
{"SONY CD-ROM CDU-561", 0, 0, dummy_exception, NULL,0},
|
||||
{"Chinon CD-ROM CDS-525", 0, 0, dummy_exception, NULL,0},
|
||||
{NULL,0,0,NULL,NULL,0}};
|
||||
#endif /*HAVE_LINUX_MAJOR_H*/
|
||||
|
||||
/* list of drives that affect MMC default settings */
|
||||
|
||||
#ifdef NEED_MMC_LIST
|
||||
static exception_t mmc_list[]={
|
||||
{"SAMSUNG SCR-830 REV 2.09 2.09 ", 1, 0, dummy_exception,scsi_read_mmc2,0},
|
||||
{"Memorex CR-622", 1, 0, dummy_exception, NULL,0},
|
||||
{"SONY CD-ROM CDU-561", 0, 0, dummy_exception, NULL,0},
|
||||
{"Chinon CD-ROM CDS-525", 0, 0, dummy_exception, NULL,0},
|
||||
{"KENWOOD CD-ROM UCR", -1, 0, NULL,scsi_read_D8, 0},
|
||||
{NULL,0,0,NULL,NULL,0}};
|
||||
#endif /*NEED_MMC_LIST*/
|
||||
|
||||
/* list of drives that affect SCSI default settings */
|
||||
|
||||
#ifdef NEED_SCSI_LIST
|
||||
static exception_t scsi_list[]={
|
||||
{"TOSHIBA", -1,0x82,scsi_enable_cdda,scsi_read_28, 0},
|
||||
{"IBM", -1,0x82,scsi_enable_cdda,scsi_read_28, 0},
|
||||
{"DEC", -1,0x82,scsi_enable_cdda,scsi_read_28, 0},
|
||||
|
||||
{"IMS", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"KODAK", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"RICOH", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"HP", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"PHILIPS", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"PLASMON", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"GRUNDIG CDR100IPW", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"MITSUMI CD-R ", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"KENWOOD CD-ROM UCR", -1, 0, NULL,scsi_read_D8, 0},
|
||||
|
||||
{"YAMAHA", -1, 0,scsi_enable_cdda, NULL, 0},
|
||||
|
||||
{"PLEXTOR", -1, 0, NULL, NULL, 0},
|
||||
{"SONY", -1, 0, NULL, NULL, 0},
|
||||
|
||||
{"NEC", -1, 0, NULL,scsi_read_D4_10,0},
|
||||
|
||||
/* the 7501 locks up if hit with the 10 byte version from the
|
||||
autoprobe first */
|
||||
{"MATSHITA CD-R CW-7501", -1, 0, NULL,scsi_read_D4_12,-1},
|
||||
|
||||
{NULL,0,0,NULL,NULL,0}};
|
||||
|
||||
#endif /* NEED_SCSI_LIST*/
|
||||
58
lib/cdda_interface/drive_exceptions.h
Normal file
58
lib/cdda_interface/drive_exceptions.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
$Id: drive_exceptions.h,v 1.6 2008/06/13 19:26:23 flameeyes Exp $
|
||||
|
||||
Copyright (C) 2004, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
extern int scsi_enable_cdda(cdrom_drive_t *d, int);
|
||||
extern long scsi_read_mmc(cdrom_drive_t *d, void *,long,long);
|
||||
extern long scsi_read_D4_10(cdrom_drive_t *, void *,long,long);
|
||||
extern long scsi_read_D4_12(cdrom_drive_t *, void *,long,long);
|
||||
extern long scsi_read_D8(cdrom_drive_t *, void *,long,long);
|
||||
extern long scsi_read_28(cdrom_drive_t *, void *,long,long);
|
||||
extern long scsi_read_A8(cdrom_drive_t *, void *,long,long);
|
||||
|
||||
typedef struct exception {
|
||||
const char *model;
|
||||
int atapi; /* If the ioctl doesn't work */
|
||||
unsigned char density;
|
||||
int (*enable)(cdrom_drive_t *,int);
|
||||
long (*read)(cdrom_drive_t *,void *, long, long);
|
||||
int bigendianp;
|
||||
} exception_t;
|
||||
|
||||
/* specific to general */
|
||||
|
||||
#ifdef FINISHED_DRIVE_EXCEPTIONS
|
||||
extern long scsi_read_mmc2(cdrom_drive_t *d, void *,long,long);
|
||||
#else
|
||||
#define scsi_read_mmc2 NULL
|
||||
#endif
|
||||
|
||||
int dummy_exception (cdrom_drive_t *d,int Switch);
|
||||
|
||||
#if HAVE_LINUX_MAJOR_H
|
||||
extern const exception_t atapi_list[];
|
||||
#endif
|
||||
|
||||
#ifdef NEED_MMC_LIST
|
||||
extern const exception_t mmc_list[];
|
||||
#endif
|
||||
|
||||
#ifdef NEED_SCSI_LIST
|
||||
extern const exception_t scsi_list[];
|
||||
#endif
|
||||
188
lib/cdda_interface/interface.c
Normal file
188
lib/cdda_interface/interface.c
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
$Id: interface.c,v 1.26 2008/04/16 17:00:40 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/******************************************************************
|
||||
* Top-level interface module for cdrom drive access. SCSI, ATAPI, etc
|
||||
* specific stuff are in other modules. Note that SCSI does use
|
||||
* specialized ioctls; these appear in common_interface.c where the
|
||||
* generic_scsi stuff is in scsi_interface.c.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include "common_interface.h"
|
||||
#include "low_interface.h"
|
||||
#include "utils.h"
|
||||
#include <cdio/bytesex.h>
|
||||
#include <cdio/mmc.h>
|
||||
|
||||
static void _clean_messages(cdrom_drive_t *d)
|
||||
{
|
||||
if(d){
|
||||
if(d->messagebuf)free(d->messagebuf);
|
||||
if(d->errorbuf)free(d->errorbuf);
|
||||
d->messagebuf=NULL;
|
||||
d->errorbuf=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Closes d and releases all storage associated with it except
|
||||
the internal p_cdio pointer.
|
||||
|
||||
@param d cdrom_drive_t object to be closed.
|
||||
@return 0 if passed a null pointer and 1 if not in which case
|
||||
some work was probably done.
|
||||
|
||||
@see cdio_cddap_close
|
||||
*/
|
||||
bool
|
||||
cdio_cddap_close_no_free_cdio(cdrom_drive_t *d)
|
||||
{
|
||||
if(d){
|
||||
if(d->opened)
|
||||
d->enable_cdda(d,0);
|
||||
|
||||
_clean_messages(d);
|
||||
if (d->cdda_device_name) free(d->cdda_device_name);
|
||||
if (d->drive_model) free(d->drive_model);
|
||||
d->cdda_device_name = d->drive_model = NULL;
|
||||
free(d);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
Closes d and releases all storage associated with it.
|
||||
Doubles as "cdrom_drive_free()".
|
||||
|
||||
@param d cdrom_drive_t object to be closed.
|
||||
@return 0 if passed a null pointer and 1 if not in which case
|
||||
some work was probably done.
|
||||
|
||||
@see cdio_cddap_close_no_free_cdio
|
||||
*/
|
||||
int
|
||||
cdio_cddap_close(cdrom_drive_t *d)
|
||||
{
|
||||
if (d) {
|
||||
CdIo_t *p_cdio = d->p_cdio;
|
||||
cdio_cddap_close_no_free_cdio(d);
|
||||
cdio_destroy (p_cdio);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* finish initializing the drive! */
|
||||
int
|
||||
cdio_cddap_open(cdrom_drive_t *d)
|
||||
{
|
||||
int ret;
|
||||
if(d->opened)return(0);
|
||||
|
||||
if ( (ret=cddap_init_drive(d)) )
|
||||
return(ret);
|
||||
|
||||
/* Check TOC, enable for CDDA */
|
||||
|
||||
/* Some drives happily return a TOC even if there is no disc... */
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<d->tracks; i++)
|
||||
if(d->disc_toc[i].dwStartSector<0 ||
|
||||
d->disc_toc[i+1].dwStartSector==0){
|
||||
d->opened=0;
|
||||
cderror(d,"009: CDROM reporting illegal table of contents\n");
|
||||
return(-9);
|
||||
}
|
||||
}
|
||||
|
||||
if((ret=d->enable_cdda(d,1)))
|
||||
return(ret);
|
||||
|
||||
/* d->select_speed(d,d->maxspeed); most drives are full speed by default */
|
||||
|
||||
if ( -1 == d->bigendianp ) {
|
||||
d->bigendianp = data_bigendianp(d);
|
||||
}
|
||||
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
int
|
||||
cdio_cddap_speed_set(cdrom_drive_t *d, int speed)
|
||||
{
|
||||
return d->set_speed ? d->set_speed(d, speed) : 0;
|
||||
}
|
||||
|
||||
long
|
||||
cdio_cddap_read(cdrom_drive_t *d, void *buffer, lsn_t beginsector,
|
||||
long sectors)
|
||||
{
|
||||
if (d->opened) {
|
||||
if (sectors>0) {
|
||||
sectors=d->read_audio(d, buffer, beginsector, sectors);
|
||||
|
||||
if (sectors > 0) {
|
||||
/* byteswap? */
|
||||
if ( d->bigendianp == -1 ) /* not determined yet */
|
||||
d->bigendianp = data_bigendianp(d);
|
||||
|
||||
if ( d->b_swap_bytes && d->bigendianp != bigendianp() ) {
|
||||
int i;
|
||||
uint16_t *p=(uint16_t *)buffer;
|
||||
long els=sectors*CDIO_CD_FRAMESIZE_RAW/2;
|
||||
|
||||
for(i=0;i<els;i++)
|
||||
p[i]=UINT16_SWAP_LE_BE_C(p[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(sectors);
|
||||
}
|
||||
|
||||
cderror(d,"400: Device not open\n");
|
||||
return(-400);
|
||||
}
|
||||
|
||||
void
|
||||
cdio_cddap_verbose_set(cdrom_drive_t *d,int err_action, int mes_action)
|
||||
{
|
||||
d->messagedest=mes_action;
|
||||
d->errordest=err_action;
|
||||
}
|
||||
|
||||
extern char *
|
||||
cdio_cddap_messages(cdrom_drive_t *d)
|
||||
{
|
||||
char *ret=d->messagebuf;
|
||||
d->messagebuf=NULL;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
extern char *
|
||||
cdio_cddap_errors(cdrom_drive_t *d)
|
||||
{
|
||||
char *ret=d->errorbuf;
|
||||
d->errorbuf=NULL;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
22
lib/cdda_interface/libcdio_cdda.sym
Normal file
22
lib/cdda_interface/libcdio_cdda.sym
Normal file
@@ -0,0 +1,22 @@
|
||||
cdio_cddap_find_a_cdrom
|
||||
cdio_cddap_identify
|
||||
cdio_cddap_identify_cdio
|
||||
cdio_cddap_speed_set
|
||||
cdio_cddap_verbose_set
|
||||
cdio_cddap_messages
|
||||
cdio_cddap_errors
|
||||
cdio_cddap_close_no_free_cdio
|
||||
cdio_cddap_close
|
||||
cdio_cddap_open
|
||||
cdio_cddap_read
|
||||
cdio_cddap_track_firstsector
|
||||
cdio_cddap_track_lastsector
|
||||
cdio_cddap_tracks
|
||||
cdio_cddap_sector_gettrack
|
||||
cdio_cddap_track_channels
|
||||
cdio_cddap_track_audiop
|
||||
cdio_cddap_track_copyp
|
||||
cdio_cddap_track_preemp
|
||||
cdio_cddap_disc_firstsector
|
||||
cdio_cddap_disc_lastsector
|
||||
data_bigendianp
|
||||
66
lib/cdda_interface/low_interface.h
Normal file
66
lib/cdda_interface/low_interface.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
$Id: low_interface.h,v 1.9 2008/04/16 17:00:40 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** internal include file for cdda interface kit for Linux */
|
||||
|
||||
#ifndef _CDDA_LOW_INTERFACE_
|
||||
#define _CDDA_LOW_INTERFACE_
|
||||
|
||||
#ifdef HAVE_STDIO_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LINUX_VERSION_H
|
||||
#include <linux/version.h>
|
||||
#endif
|
||||
|
||||
#include <cdio/paranoia.h>
|
||||
#include <cdio/cdda.h>
|
||||
|
||||
/* some include file locations have changed with newer kernels */
|
||||
|
||||
#ifndef CDROMAUDIOBUFSIZ
|
||||
#define CDROMAUDIOBUFSIZ 0x5382 /* set the audio buffer size */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LINUX_CDROM_H
|
||||
#include <linux/cdrom.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LINUX_MAJOR_H
|
||||
#include <linux/major.h>
|
||||
#endif
|
||||
|
||||
#define MAX_RETRIES 8
|
||||
#define MAX_BIG_BUFF_SIZE 65536
|
||||
#define MIN_BIG_BUFF_SIZE 4096
|
||||
#define SG_OFF sizeof(struct sg_header)
|
||||
|
||||
extern int cddap_init_drive (cdrom_drive_t *d);
|
||||
#endif /*_CDDA_LOW_INTERFACE_*/
|
||||
|
||||
335
lib/cdda_interface/scan_devices.c
Normal file
335
lib/cdda_interface/scan_devices.c
Normal file
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
$Id: scan_devices.c,v 1.33 2008/06/16 19:45:44 flameeyes Exp $
|
||||
|
||||
Copyright (C) 2004, 2005, 2007, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* Autoscan for or verify presence of a CD-ROM device
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include "common_interface.h"
|
||||
#include "low_interface.h"
|
||||
#include "utils.h"
|
||||
#include "cdio/mmc.h"
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef HAVE_PWD_H
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#define MAX_DEV_LEN 20 /* Safe because strings only come from below */
|
||||
/* must be absolute paths! */
|
||||
static const char scsi_cdrom_prefixes[][16]={
|
||||
"/dev/scd",
|
||||
"/dev/sr",
|
||||
""};
|
||||
static const char scsi_generic_prefixes[][16]={
|
||||
"/dev/sg",
|
||||
""};
|
||||
|
||||
static const char devfs_scsi_test[]="/dev/scsi/";
|
||||
static const char devfs_scsi_cd[]="cd";
|
||||
static const char devfs_scsi_generic[]="generic";
|
||||
|
||||
static const char cdrom_devices[][32]={
|
||||
"/dev/cdrom",
|
||||
"/dev/cdroms/cdrom?",
|
||||
"/dev/hd?",
|
||||
"/dev/sg?",
|
||||
"/dev/cdu31a",
|
||||
"/dev/cdu535",
|
||||
"/dev/sbpcd",
|
||||
"/dev/sbpcd?",
|
||||
"/dev/sonycd",
|
||||
"/dev/mcd",
|
||||
"/dev/sjcd",
|
||||
/* "/dev/aztcd", timeout is too long */
|
||||
"/dev/cm206cd",
|
||||
"/dev/gscd",
|
||||
"/dev/optcd",
|
||||
""};
|
||||
|
||||
static cdrom_drive_t *
|
||||
cdda_identify_device_cdio(CdIo_t *p_cdio, const char *psz_device,
|
||||
int messagedest, char **ppsz_messages);
|
||||
|
||||
/* Functions here look for a cdrom drive; full init of a drive type
|
||||
happens in interface.c */
|
||||
|
||||
cdrom_drive_t *
|
||||
cdio_cddap_find_a_cdrom(int messagedest, char **ppsz_messages){
|
||||
/* Brute force... */
|
||||
|
||||
int i=0;
|
||||
cdrom_drive_t *d;
|
||||
|
||||
while(*cdrom_devices[i]!='\0'){
|
||||
|
||||
/* is it a name or a pattern? */
|
||||
char *pos;
|
||||
if((pos=strchr(cdrom_devices[i],'?'))){
|
||||
int j;
|
||||
/* try first eight of each device */
|
||||
for(j=0;j<4;j++){
|
||||
char *buffer=strdup(cdrom_devices[i]);
|
||||
|
||||
/* number, then letter */
|
||||
|
||||
buffer[pos-(cdrom_devices[i])]=j+48;
|
||||
if((d=cdda_identify(buffer, messagedest, ppsz_messages)))
|
||||
return(d);
|
||||
idmessage(messagedest, ppsz_messages, "", NULL);
|
||||
buffer[pos-(cdrom_devices[i])]=j+97;
|
||||
if((d=cdda_identify(buffer, messagedest, ppsz_messages)))
|
||||
return(d);
|
||||
idmessage(messagedest, ppsz_messages, "", NULL);
|
||||
}
|
||||
}else{
|
||||
/* Name. Go for it. */
|
||||
if((d=cdda_identify(cdrom_devices[i], messagedest, ppsz_messages)))
|
||||
return(d);
|
||||
|
||||
idmessage(messagedest, ppsz_messages, "", NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
{
|
||||
#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
|
||||
struct passwd *temp;
|
||||
temp=getpwuid(geteuid());
|
||||
idmessage(messagedest, ppsz_messages,
|
||||
"\n\nNo cdrom drives accessible to %s found.\n",
|
||||
temp->pw_name);
|
||||
#else
|
||||
idmessage(messagedest, ppsz_messages,
|
||||
"\n\nNo cdrom drives accessible found.\n", NULL);
|
||||
#endif
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#ifdef DEVICE_IN_FILESYSTEM
|
||||
static char *
|
||||
test_resolve_symlink(const char *file, int messagedest, char **ppsz_messages)
|
||||
{
|
||||
char resolved[PATH_MAX];
|
||||
struct stat st;
|
||||
if (lstat(file,&st)){
|
||||
idperror(messagedest, ppsz_messages, "\t\tCould not stat %s",file);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (realpath(file,resolved))
|
||||
return(strdup(resolved));
|
||||
|
||||
idperror(messagedest, ppsz_messages, "\t\tCould not resolve symlink %s",
|
||||
file);
|
||||
return(NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Returns a paranoia CD-ROM drive object with a CD-DA in it or NULL
|
||||
if there was an error.
|
||||
@see cdio_cddap_identify_cdio
|
||||
*/
|
||||
cdrom_drive_t *
|
||||
cdio_cddap_identify(const char *psz_dev, int messagedest,
|
||||
char **ppsz_messages)
|
||||
{
|
||||
CdIo_t *p_cdio = NULL;
|
||||
|
||||
if (psz_dev)
|
||||
idmessage(messagedest, ppsz_messages, "Checking %s for cdrom...",
|
||||
psz_dev);
|
||||
else
|
||||
idmessage(messagedest, ppsz_messages, "Checking for cdrom...", NULL);
|
||||
|
||||
#ifdef DEVICE_IN_FILESYSTEM
|
||||
if (psz_dev) {
|
||||
char *psz_device = test_resolve_symlink(psz_dev, messagedest,
|
||||
ppsz_messages);
|
||||
if ( psz_device ) {
|
||||
cdrom_drive_t *d=NULL;
|
||||
p_cdio = cdio_open(psz_device, DRIVER_UNKNOWN);
|
||||
d = cdda_identify_device_cdio(p_cdio, psz_device, messagedest,
|
||||
ppsz_messages);
|
||||
free(psz_device);
|
||||
return d;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
p_cdio = cdio_open(psz_dev, DRIVER_UNKNOWN);
|
||||
if (p_cdio) {
|
||||
if (!psz_dev) {
|
||||
psz_dev = cdio_get_arg(p_cdio, "source");
|
||||
}
|
||||
return cdda_identify_device_cdio(p_cdio, psz_dev, messagedest,
|
||||
ppsz_messages);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Returns a paranoia CD-ROM drive object with a CD-DA in it or NULL
|
||||
if there was an error. In contrast to cdio_cddap_identify, we
|
||||
start out with an initialized p_cdio object. For example you may
|
||||
have used that for other purposes such as to get CDDB/CD-Text
|
||||
information. @see cdio_cddap_identify
|
||||
*/
|
||||
cdrom_drive_t *
|
||||
cdio_cddap_identify_cdio(CdIo_t *p_cdio, int messagedest, char **ppsz_messages)
|
||||
{
|
||||
if (!p_cdio) return NULL;
|
||||
{
|
||||
const char *psz_device = cdio_get_arg(p_cdio, "source");
|
||||
idmessage(messagedest, ppsz_messages, "Checking %s for cdrom...",
|
||||
psz_device);
|
||||
return cdda_identify_device_cdio(p_cdio, psz_device, messagedest,
|
||||
ppsz_messages);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static cdrom_drive_t *
|
||||
cdda_identify_device_cdio(CdIo_t *p_cdio, const char *psz_device,
|
||||
int messagedest, char **ppsz_messages)
|
||||
{
|
||||
cdrom_drive_t *d=NULL;
|
||||
int drive_type = 0;
|
||||
char *description=NULL;
|
||||
#ifdef HAVE_LINUX_MAJOR_H
|
||||
struct stat st;
|
||||
#endif
|
||||
|
||||
if (!p_cdio) {
|
||||
idperror(messagedest, ppsz_messages, "\t\tUnable to open %s", psz_device);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LINUX_MAJOR_H
|
||||
if ( 0 == stat(psz_device, &st) ) {
|
||||
if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
|
||||
drive_type=(int)(st.st_rdev>>8);
|
||||
switch (drive_type) {
|
||||
case IDE0_MAJOR:
|
||||
case IDE1_MAJOR:
|
||||
case IDE2_MAJOR:
|
||||
case IDE3_MAJOR:
|
||||
/* Yay, ATAPI... */
|
||||
description=strdup("ATAPI compatible ");
|
||||
break;
|
||||
case CDU31A_CDROM_MAJOR:
|
||||
/* major indicates this is a cdrom; no ping necessary. */
|
||||
description=strdup("Sony CDU31A or compatible");
|
||||
break;
|
||||
case CDU535_CDROM_MAJOR:
|
||||
/* major indicates this is a cdrom; no ping necessary. */
|
||||
description=strdup("Sony CDU535 or compatible");
|
||||
break;
|
||||
|
||||
case MATSUSHITA_CDROM_MAJOR:
|
||||
case MATSUSHITA_CDROM2_MAJOR:
|
||||
case MATSUSHITA_CDROM3_MAJOR:
|
||||
case MATSUSHITA_CDROM4_MAJOR:
|
||||
/* major indicates this is a cdrom; no ping necessary. */
|
||||
description=strdup("non-ATAPI IDE-style Matsushita/Panasonic CR-5xx or compatible");
|
||||
break;
|
||||
case SANYO_CDROM_MAJOR:
|
||||
description=strdup("Sanyo proprietary or compatible: NOT CDDA CAPABLE");
|
||||
break;
|
||||
case MITSUMI_CDROM_MAJOR:
|
||||
case MITSUMI_X_CDROM_MAJOR:
|
||||
description=strdup("Mitsumi proprietary or compatible: NOT CDDA CAPABLE");
|
||||
break;
|
||||
case OPTICS_CDROM_MAJOR:
|
||||
description=strdup("Optics Dolphin or compatible: NOT CDDA CAPABLE");
|
||||
break;
|
||||
case AZTECH_CDROM_MAJOR:
|
||||
description=strdup("Aztech proprietary or compatible: NOT CDDA CAPABLE");
|
||||
break;
|
||||
case GOLDSTAR_CDROM_MAJOR:
|
||||
description=strdup("Goldstar proprietary: NOT CDDA CAPABLE");
|
||||
break;
|
||||
case CM206_CDROM_MAJOR:
|
||||
description=strdup("Philips/LMS CM206 proprietary: NOT CDDA CAPABLE");
|
||||
break;
|
||||
|
||||
case SCSI_CDROM_MAJOR:
|
||||
case SCSI_GENERIC_MAJOR:
|
||||
/* Nope nope nope */
|
||||
description=strdup("SCSI CD-ROM");
|
||||
break;
|
||||
default:
|
||||
/* What the hell is this? */
|
||||
idmessage(messagedest, ppsz_messages,
|
||||
"\t\t%s is not a cooked ioctl CDROM.",
|
||||
psz_device);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /*HAVE_LINUX_MAJOR_H*/
|
||||
|
||||
/* Minimum init */
|
||||
|
||||
d=calloc(1, sizeof(cdrom_drive_t));
|
||||
d->p_cdio = p_cdio;
|
||||
d->cdda_device_name = strdup(psz_device);
|
||||
d->drive_type = drive_type;
|
||||
d->bigendianp = -1; /* We don't know yet... */
|
||||
d->nsectors = -1; /* We don't know yet... */
|
||||
d->messagedest = messagedest;
|
||||
d->b_swap_bytes = true;
|
||||
|
||||
{
|
||||
cdio_hwinfo_t hw_info = {
|
||||
"UNKNOWN", "Unknown model", "????"
|
||||
};
|
||||
|
||||
if ( mmc_get_hwinfo( p_cdio, &hw_info ) ) {
|
||||
unsigned int i_len = strlen(hw_info.psz_vendor)
|
||||
+ strlen(hw_info.psz_model)
|
||||
+ strlen(hw_info.psz_revision) + 5;
|
||||
|
||||
if (description) {
|
||||
i_len += strlen(description);
|
||||
d->drive_model=malloc( i_len );
|
||||
snprintf( d->drive_model, i_len, "%s %s %s %s",
|
||||
hw_info.psz_vendor, hw_info.psz_model, hw_info.psz_revision,
|
||||
description );
|
||||
free(description);
|
||||
} else {
|
||||
d->drive_model=malloc( i_len );
|
||||
snprintf( d->drive_model, i_len, "%s %s %s",
|
||||
hw_info.psz_vendor, hw_info.psz_model, hw_info.psz_revision
|
||||
);
|
||||
}
|
||||
idmessage(messagedest, ppsz_messages, "\t\tCDROM sensed: %s\n",
|
||||
d->drive_model);
|
||||
}
|
||||
}
|
||||
|
||||
return(d);
|
||||
}
|
||||
1574
lib/cdda_interface/scsi_interface.c
Normal file
1574
lib/cdda_interface/scsi_interface.c
Normal file
File diff suppressed because it is too large
Load Diff
563
lib/cdda_interface/smallft.c
Normal file
563
lib/cdda_interface/smallft.c
Normal file
@@ -0,0 +1,563 @@
|
||||
/*
|
||||
$Id: smallft.c,v 1.2 2008/04/16 17:00:40 karl Exp $
|
||||
|
||||
Copyright (C) 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
* FFT implementation from OggSquish, minus cosine transforms,
|
||||
* minus all but radix 2/4 case
|
||||
*
|
||||
* See OggSquish or NetLib for the version that can do other than just
|
||||
* power-of-two sized vectors.
|
||||
******************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "smallft.h"
|
||||
|
||||
static void drfti1(int n, float *wa, int *ifac){
|
||||
static int ntryh[4] = { 4,2,3,5 };
|
||||
static float tpi = 6.28318530717958647692528676655900577;
|
||||
float arg,argh,argld,fi;
|
||||
int ntry=0,i,j=-1;
|
||||
int k1, l1, l2, ib;
|
||||
int ld, ii, ip, is, nq, nr;
|
||||
int ido, ipm, nfm1;
|
||||
int nl=n;
|
||||
int nf=0;
|
||||
|
||||
L101:
|
||||
j++;
|
||||
if (j < 4)
|
||||
ntry=ntryh[j];
|
||||
else
|
||||
ntry+=2;
|
||||
|
||||
L104:
|
||||
nq=nl/ntry;
|
||||
nr=nl-ntry*nq;
|
||||
if (nr!=0) goto L101;
|
||||
|
||||
nf++;
|
||||
ifac[nf+1]=ntry;
|
||||
nl=nq;
|
||||
if(ntry!=2)goto L107;
|
||||
if(nf==1)goto L107;
|
||||
|
||||
for (i=1;i<nf;i++){
|
||||
ib=nf-i+1;
|
||||
ifac[ib+1]=ifac[ib];
|
||||
}
|
||||
ifac[2] = 2;
|
||||
|
||||
L107:
|
||||
if(nl!=1)goto L104;
|
||||
ifac[0]=n;
|
||||
ifac[1]=nf;
|
||||
argh=tpi/n;
|
||||
is=0;
|
||||
nfm1=nf-1;
|
||||
l1=1;
|
||||
|
||||
if(nfm1==0)return;
|
||||
|
||||
for (k1=0;k1<nfm1;k1++){
|
||||
ip=ifac[k1+2];
|
||||
ld=0;
|
||||
l2=l1*ip;
|
||||
ido=n/l2;
|
||||
ipm=ip-1;
|
||||
|
||||
for (j=0;j<ipm;j++){
|
||||
ld+=l1;
|
||||
i=is;
|
||||
argld=(float)ld*argh;
|
||||
fi=0.;
|
||||
for (ii=2;ii<ido;ii+=2){
|
||||
fi+=1.;
|
||||
arg=fi*argld;
|
||||
wa[i++]=cos(arg);
|
||||
wa[i++]=sin(arg);
|
||||
}
|
||||
is+=ido;
|
||||
}
|
||||
l1=l2;
|
||||
}
|
||||
}
|
||||
|
||||
static void fdrffti(int n, float *wsave, int *ifac){
|
||||
|
||||
if (n == 1) return;
|
||||
drfti1(n, wsave+n, ifac);
|
||||
}
|
||||
|
||||
static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
|
||||
int i,k;
|
||||
float ti2,tr2;
|
||||
int t0,t1,t2,t3,t4,t5,t6;
|
||||
|
||||
t1=0;
|
||||
t0=(t2=l1*ido);
|
||||
t3=ido<<1;
|
||||
for(k=0;k<l1;k++){
|
||||
ch[t1<<1]=cc[t1]+cc[t2];
|
||||
ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
|
||||
t1+=ido;
|
||||
t2+=ido;
|
||||
}
|
||||
|
||||
if(ido<2)return;
|
||||
if(ido==2)goto L105;
|
||||
|
||||
t1=0;
|
||||
t2=t0;
|
||||
for(k=0;k<l1;k++){
|
||||
t3=t2;
|
||||
t4=(t1<<1)+(ido<<1);
|
||||
t5=t1;
|
||||
t6=t1+t1;
|
||||
for(i=2;i<ido;i+=2){
|
||||
t3+=2;
|
||||
t4-=2;
|
||||
t5+=2;
|
||||
t6+=2;
|
||||
tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
|
||||
ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
|
||||
ch[t6]=cc[t5]+ti2;
|
||||
ch[t4]=ti2-cc[t5];
|
||||
ch[t6-1]=cc[t5-1]+tr2;
|
||||
ch[t4-1]=cc[t5-1]-tr2;
|
||||
}
|
||||
t1+=ido;
|
||||
t2+=ido;
|
||||
}
|
||||
|
||||
if(ido%2==1)return;
|
||||
|
||||
L105:
|
||||
t3=(t2=(t1=ido)-1);
|
||||
t2+=t0;
|
||||
for(k=0;k<l1;k++){
|
||||
ch[t1]=-cc[t2];
|
||||
ch[t1-1]=cc[t3];
|
||||
t1+=ido<<1;
|
||||
t2+=ido;
|
||||
t3+=ido;
|
||||
}
|
||||
}
|
||||
|
||||
static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
|
||||
float *wa2,float *wa3){
|
||||
static float hsqt2 = .70710678118654752440084436210485;
|
||||
int i,k,t0,t1,t2,t3,t4,t5,t6;
|
||||
float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
|
||||
t0=l1*ido;
|
||||
|
||||
t1=t0;
|
||||
t4=t1<<1;
|
||||
t2=t1+(t1<<1);
|
||||
t3=0;
|
||||
|
||||
for(k=0;k<l1;k++){
|
||||
tr1=cc[t1]+cc[t2];
|
||||
tr2=cc[t3]+cc[t4];
|
||||
|
||||
ch[t5=t3<<2]=tr1+tr2;
|
||||
ch[(ido<<2)+t5-1]=tr2-tr1;
|
||||
ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
|
||||
ch[t5]=cc[t2]-cc[t1];
|
||||
|
||||
t1+=ido;
|
||||
t2+=ido;
|
||||
t3+=ido;
|
||||
t4+=ido;
|
||||
}
|
||||
|
||||
if(ido<2)return;
|
||||
if(ido==2)goto L105;
|
||||
|
||||
|
||||
t1=0;
|
||||
for(k=0;k<l1;k++){
|
||||
t2=t1;
|
||||
t4=t1<<2;
|
||||
t5=(t6=ido<<1)+t4;
|
||||
for(i=2;i<ido;i+=2){
|
||||
t3=(t2+=2);
|
||||
t4+=2;
|
||||
t5-=2;
|
||||
|
||||
t3+=t0;
|
||||
cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
|
||||
ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
|
||||
t3+=t0;
|
||||
cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
|
||||
ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
|
||||
t3+=t0;
|
||||
cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
|
||||
ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
|
||||
|
||||
tr1=cr2+cr4;
|
||||
tr4=cr4-cr2;
|
||||
ti1=ci2+ci4;
|
||||
ti4=ci2-ci4;
|
||||
|
||||
ti2=cc[t2]+ci3;
|
||||
ti3=cc[t2]-ci3;
|
||||
tr2=cc[t2-1]+cr3;
|
||||
tr3=cc[t2-1]-cr3;
|
||||
|
||||
ch[t4-1]=tr1+tr2;
|
||||
ch[t4]=ti1+ti2;
|
||||
|
||||
ch[t5-1]=tr3-ti4;
|
||||
ch[t5]=tr4-ti3;
|
||||
|
||||
ch[t4+t6-1]=ti4+tr3;
|
||||
ch[t4+t6]=tr4+ti3;
|
||||
|
||||
ch[t5+t6-1]=tr2-tr1;
|
||||
ch[t5+t6]=ti1-ti2;
|
||||
}
|
||||
t1+=ido;
|
||||
}
|
||||
if(ido&1)return;
|
||||
|
||||
L105:
|
||||
|
||||
t2=(t1=t0+ido-1)+(t0<<1);
|
||||
t3=ido<<2;
|
||||
t4=ido;
|
||||
t5=ido<<1;
|
||||
t6=ido;
|
||||
|
||||
for(k=0;k<l1;k++){
|
||||
ti1=-hsqt2*(cc[t1]+cc[t2]);
|
||||
tr1=hsqt2*(cc[t1]-cc[t2]);
|
||||
|
||||
ch[t4-1]=tr1+cc[t6-1];
|
||||
ch[t4+t5-1]=cc[t6-1]-tr1;
|
||||
|
||||
ch[t4]=ti1-cc[t1+t0];
|
||||
ch[t4+t5]=ti1+cc[t1+t0];
|
||||
|
||||
t1+=ido;
|
||||
t2+=ido;
|
||||
t4+=t3;
|
||||
t6+=ido;
|
||||
}
|
||||
}
|
||||
|
||||
static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
|
||||
int i,k1,l1,l2;
|
||||
int na,kh,nf;
|
||||
int ip,iw,ido,idl1,ix2,ix3;
|
||||
|
||||
nf=ifac[1];
|
||||
na=1;
|
||||
l2=n;
|
||||
iw=n;
|
||||
|
||||
for(k1=0;k1<nf;k1++){
|
||||
kh=nf-k1;
|
||||
ip=ifac[kh+1];
|
||||
l1=l2/ip;
|
||||
ido=n/l2;
|
||||
idl1=ido*l1;
|
||||
iw-=(ip-1)*ido;
|
||||
na=1-na;
|
||||
|
||||
if(ip!=4)goto L102;
|
||||
|
||||
ix2=iw+ido;
|
||||
ix3=ix2+ido;
|
||||
if(na!=0)
|
||||
dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
|
||||
else
|
||||
dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
|
||||
goto L110;
|
||||
|
||||
L102:
|
||||
if(ip!=2)goto L104;
|
||||
if(na!=0)goto L103;
|
||||
|
||||
dradf2(ido,l1,c,ch,wa+iw-1);
|
||||
goto L110;
|
||||
|
||||
L103:
|
||||
dradf2(ido,l1,ch,c,wa+iw-1);
|
||||
goto L110;
|
||||
|
||||
L104:
|
||||
return; /* We're restricted to powers of two. just fail */
|
||||
|
||||
L110:
|
||||
l2=l1;
|
||||
}
|
||||
|
||||
if(na==1)return;
|
||||
|
||||
for(i=0;i<n;i++)c[i]=ch[i];
|
||||
}
|
||||
|
||||
static void fdrfftf(int n,float *r,float *wsave,int *ifac){
|
||||
if(n==1)return;
|
||||
drftf1(n,r,wsave,wsave+n,ifac);
|
||||
}
|
||||
|
||||
static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
|
||||
int i,k,t0,t1,t2,t3,t4,t5,t6;
|
||||
float ti2,tr2;
|
||||
|
||||
t0=l1*ido;
|
||||
|
||||
t1=0;
|
||||
t2=0;
|
||||
t3=(ido<<1)-1;
|
||||
for(k=0;k<l1;k++){
|
||||
ch[t1]=cc[t2]+cc[t3+t2];
|
||||
ch[t1+t0]=cc[t2]-cc[t3+t2];
|
||||
t2=(t1+=ido)<<1;
|
||||
}
|
||||
|
||||
if(ido<2)return;
|
||||
if(ido==2)goto L105;
|
||||
|
||||
t1=0;
|
||||
t2=0;
|
||||
for(k=0;k<l1;k++){
|
||||
t3=t1;
|
||||
t5=(t4=t2)+(ido<<1);
|
||||
t6=t0+t1;
|
||||
for(i=2;i<ido;i+=2){
|
||||
t3+=2;
|
||||
t4+=2;
|
||||
t5-=2;
|
||||
t6+=2;
|
||||
ch[t3-1]=cc[t4-1]+cc[t5-1];
|
||||
tr2=cc[t4-1]-cc[t5-1];
|
||||
ch[t3]=cc[t4]-cc[t5];
|
||||
ti2=cc[t4]+cc[t5];
|
||||
ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
|
||||
ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
|
||||
}
|
||||
t2=(t1+=ido)<<1;
|
||||
}
|
||||
|
||||
if(ido%2==1)return;
|
||||
|
||||
L105:
|
||||
t1=ido-1;
|
||||
t2=ido-1;
|
||||
for(k=0;k<l1;k++){
|
||||
ch[t1]=cc[t2]+cc[t2];
|
||||
ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
|
||||
t1+=ido;
|
||||
t2+=ido<<1;
|
||||
}
|
||||
}
|
||||
|
||||
static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
|
||||
float *wa2,float *wa3){
|
||||
static float sqrt2=1.4142135623730950488016887242097;
|
||||
int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
|
||||
float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
|
||||
t0=l1*ido;
|
||||
|
||||
t1=0;
|
||||
t2=ido<<2;
|
||||
t3=0;
|
||||
t6=ido<<1;
|
||||
for(k=0;k<l1;k++){
|
||||
t4=t3+t6;
|
||||
t5=t1;
|
||||
tr3=cc[t4-1]+cc[t4-1];
|
||||
tr4=cc[t4]+cc[t4];
|
||||
tr1=cc[t3]-cc[(t4+=t6)-1];
|
||||
tr2=cc[t3]+cc[t4-1];
|
||||
ch[t5]=tr2+tr3;
|
||||
ch[t5+=t0]=tr1-tr4;
|
||||
ch[t5+=t0]=tr2-tr3;
|
||||
ch[t5+=t0]=tr1+tr4;
|
||||
t1+=ido;
|
||||
t3+=t2;
|
||||
}
|
||||
|
||||
if(ido<2)return;
|
||||
if(ido==2)goto L105;
|
||||
|
||||
t1=0;
|
||||
for(k=0;k<l1;k++){
|
||||
t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
|
||||
t7=t1;
|
||||
for(i=2;i<ido;i+=2){
|
||||
t2+=2;
|
||||
t3+=2;
|
||||
t4-=2;
|
||||
t5-=2;
|
||||
t7+=2;
|
||||
ti1=cc[t2]+cc[t5];
|
||||
ti2=cc[t2]-cc[t5];
|
||||
ti3=cc[t3]-cc[t4];
|
||||
tr4=cc[t3]+cc[t4];
|
||||
tr1=cc[t2-1]-cc[t5-1];
|
||||
tr2=cc[t2-1]+cc[t5-1];
|
||||
ti4=cc[t3-1]-cc[t4-1];
|
||||
tr3=cc[t3-1]+cc[t4-1];
|
||||
ch[t7-1]=tr2+tr3;
|
||||
cr3=tr2-tr3;
|
||||
ch[t7]=ti2+ti3;
|
||||
ci3=ti2-ti3;
|
||||
cr2=tr1-tr4;
|
||||
cr4=tr1+tr4;
|
||||
ci2=ti1+ti4;
|
||||
ci4=ti1-ti4;
|
||||
|
||||
ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
|
||||
ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
|
||||
ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
|
||||
ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
|
||||
ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
|
||||
ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
|
||||
}
|
||||
t1+=ido;
|
||||
}
|
||||
|
||||
if(ido%2 == 1)return;
|
||||
|
||||
L105:
|
||||
|
||||
t1=ido;
|
||||
t2=ido<<2;
|
||||
t3=ido-1;
|
||||
t4=ido+(ido<<1);
|
||||
for(k=0;k<l1;k++){
|
||||
t5=t3;
|
||||
ti1=cc[t1]+cc[t4];
|
||||
ti2=cc[t4]-cc[t1];
|
||||
tr1=cc[t1-1]-cc[t4-1];
|
||||
tr2=cc[t1-1]+cc[t4-1];
|
||||
ch[t5]=tr2+tr2;
|
||||
ch[t5+=t0]=sqrt2*(tr1-ti1);
|
||||
ch[t5+=t0]=ti2+ti2;
|
||||
ch[t5+=t0]=-sqrt2*(tr1+ti1);
|
||||
|
||||
t3+=ido;
|
||||
t1+=t2;
|
||||
t4+=t2;
|
||||
}
|
||||
}
|
||||
|
||||
static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
|
||||
int i,k1,l1,l2;
|
||||
int na;
|
||||
int nf,ip,iw,ix2,ix3,ido,idl1;
|
||||
|
||||
nf=ifac[1];
|
||||
na=0;
|
||||
l1=1;
|
||||
iw=1;
|
||||
|
||||
for(k1=0;k1<nf;k1++){
|
||||
ip=ifac[k1 + 2];
|
||||
l2=ip*l1;
|
||||
ido=n/l2;
|
||||
idl1=ido*l1;
|
||||
if(ip!=4)goto L103;
|
||||
ix2=iw+ido;
|
||||
ix3=ix2+ido;
|
||||
|
||||
if(na!=0)
|
||||
dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
|
||||
else
|
||||
dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
|
||||
na=1-na;
|
||||
goto L115;
|
||||
|
||||
L103:
|
||||
if(ip!=2)goto L106;
|
||||
|
||||
if(na!=0)
|
||||
dradb2(ido,l1,ch,c,wa+iw-1);
|
||||
else
|
||||
dradb2(ido,l1,c,ch,wa+iw-1);
|
||||
na=1-na;
|
||||
goto L115;
|
||||
|
||||
L106:
|
||||
return; /* silently fail. we only do powers of two in this version */
|
||||
|
||||
L115:
|
||||
l1=l2;
|
||||
iw+=(ip-1)*ido;
|
||||
}
|
||||
|
||||
if(na==0)return;
|
||||
|
||||
for(i=0;i<n;i++)c[i]=ch[i];
|
||||
}
|
||||
|
||||
static void fdrfftb(int n, float *r, float *wsave, int *ifac){
|
||||
if (n == 1)return;
|
||||
drftb1(n, r, wsave, wsave+n, ifac);
|
||||
}
|
||||
|
||||
void fft_forward(int n, float *buf,float *trigcache,int *splitcache){
|
||||
int flag=0;
|
||||
|
||||
if(!trigcache || !splitcache){
|
||||
trigcache=calloc(3*n,sizeof(float));
|
||||
splitcache=calloc(32,sizeof(int));
|
||||
fdrffti(n, trigcache, splitcache);
|
||||
flag=1;
|
||||
}
|
||||
|
||||
fdrfftf(n, buf, trigcache, splitcache);
|
||||
|
||||
if(flag){
|
||||
free(trigcache);
|
||||
free(splitcache);
|
||||
}
|
||||
}
|
||||
|
||||
void fft_backward(int n, float *buf, float *trigcache,int *splitcache){
|
||||
int i;
|
||||
int flag=0;
|
||||
|
||||
if(!trigcache || !splitcache){
|
||||
trigcache=calloc(3*n,sizeof(float));
|
||||
splitcache=calloc(32,sizeof(int));
|
||||
fdrffti(n, trigcache, splitcache);
|
||||
flag=1;
|
||||
}
|
||||
|
||||
fdrfftb(n, buf, trigcache, splitcache);
|
||||
|
||||
for(i=0;i<n;i++)buf[i]/=n;
|
||||
|
||||
if(flag){
|
||||
free(trigcache);
|
||||
free(splitcache);
|
||||
}
|
||||
}
|
||||
|
||||
void fft_i(int n, float **trigcache, int **splitcache){
|
||||
*trigcache=calloc(3*n,sizeof(float));
|
||||
*splitcache=calloc(32,sizeof(int));
|
||||
fdrffti(n, *trigcache, *splitcache);
|
||||
}
|
||||
28
lib/cdda_interface/smallft.h
Normal file
28
lib/cdda_interface/smallft.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
$Id: smallft.h,v 1.2 2008/04/16 17:00:40 karl Exp $
|
||||
|
||||
Copyright (C) 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
* FFT implementation from OggSquish, minus cosine transforms.
|
||||
* Only convenience functions exposed
|
||||
******************************************************************/
|
||||
|
||||
extern void fft_forward(int n, float *buf, float *trigcache, int *sp);
|
||||
extern void fft_backward(int n, float *buf, float *trigcache, int *sp);
|
||||
extern void fft_i(int n, float **trigcache, int **splitcache);
|
||||
235
lib/cdda_interface/test_interface.c
Normal file
235
lib/cdda_interface/test_interface.c
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
$Id: test_interface.c,v 1.4 2008/06/13 19:26:23 flameeyes Exp $
|
||||
|
||||
Copyright (C) 2004, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/******************************************************************
|
||||
*
|
||||
* Fake interface backend for testing paranoia layer
|
||||
* NOTE: THIS CODE HAVE BEEN FOLDED INTO THE MAINLINE CODE SO IT IS
|
||||
* NOT USED ANYMORE. (It's not clear that it had been used
|
||||
* for a while in the non-libcdio cdparaonoia either.)
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#ifdef CDDA_TEST
|
||||
#include "low_interface.h"
|
||||
#include "utils.h"
|
||||
|
||||
/* Build which test model? */
|
||||
#define CDDA_TEST_OK
|
||||
#undef CDDA_TEST_JITTER_SMALL
|
||||
#undef CDDA_TEST_JITTER_LARGE
|
||||
#undef CDDA_TEST_JITTER_MASSIVE
|
||||
#undef CDDA_TEST_FRAG_SMALL
|
||||
#undef CDDA_TEST_FRAG_LARGE
|
||||
#undef CDDA_TEST_FRAG_MASSIVE
|
||||
#undef CDDA_TEST_BOGUS_BYTES
|
||||
#undef CDDA_TEST_DROPDUPE_BYTES
|
||||
#undef CDDA_TEST_SCRATCH
|
||||
#undef CDDA_TEST_UNDERRUN
|
||||
|
||||
#undef CDDA_TEST_ALLJITTER
|
||||
#undef CDDA_TEST_SOMEJITTER
|
||||
#undef CDDA_TEST_SEEKJITTER
|
||||
|
||||
static int test_readtoc (cdrom_drive *d){
|
||||
int tracks=0;
|
||||
long bytes;
|
||||
long sectors;
|
||||
|
||||
/* only one track, as many sectors as the file */
|
||||
|
||||
bytes=lseek(d->cdda_fd,0,SEEK_END);
|
||||
lseek(d->cdda_fd,0,SEEK_SET);
|
||||
sectors=bytes/CDIO_CD_FRAMESIZE_RAW;
|
||||
|
||||
d->disc_toc[0].bFlags = 0;
|
||||
d->disc_toc[0].bTrack = 1;
|
||||
d->disc_toc[0].dwStartSector = 37;
|
||||
|
||||
d->disc_toc[1].bFlags = 0x4;
|
||||
d->disc_toc[1].bTrack = CDROM_LEADOUT;
|
||||
d->disc_toc[1].dwStartSector = sectors+37;
|
||||
|
||||
tracks=2;
|
||||
d->cd_extra=0;
|
||||
return(--tracks); /* without lead-out */
|
||||
}
|
||||
|
||||
/* we emulate jitter, scratches, atomic jitter and bogus bytes on
|
||||
boundaries, etc */
|
||||
|
||||
static long
|
||||
test_read(cdrom_drive *d, void *p, long begin, long sectors)
|
||||
{
|
||||
|
||||
#if defined(CDDA_TEST_SEEKJITTER) \
|
||||
|| defined(CDDA_TEST_ALLJITTER) \
|
||||
|| defined(CDDA_TEST_SOMEJITTER)
|
||||
int jitter_flag=0;
|
||||
#endif
|
||||
|
||||
int los_flag=0;
|
||||
static int jitter=0;
|
||||
int bytes_so_far=0;
|
||||
long bytestotal;
|
||||
static FILE *fd=NULL;
|
||||
static long lastread=0;
|
||||
|
||||
if(!fd)fd=fdopen(d->cdda_fd,"r");
|
||||
|
||||
#ifdef CDDA_TEST_UNDERRUN
|
||||
sectors-=1;
|
||||
#endif
|
||||
|
||||
#ifdef CDDA_TEST_SEEKJITTER
|
||||
if(lastread!=begin)jitter_flag=1;
|
||||
#else
|
||||
#ifdef CDDA_TEST_ALLJITTER
|
||||
jitter_flag=1;
|
||||
#else
|
||||
#ifdef CDDA_TEST_SOMEJITTER
|
||||
jitter_flag=(drand48()>.9?1:0);
|
||||
los_flag=(drand48()>.9?1:0);
|
||||
#else
|
||||
los_flag=1;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
lastread=begin+sectors;
|
||||
bytestotal=sectors*CDIO_CD_FRAMESIZE_RAW;
|
||||
|
||||
begin*=CDIO_CD_FRAMESIZE_RAW;
|
||||
|
||||
while(bytes_so_far<bytestotal){
|
||||
int inner_bytes=bytestotal-bytes_so_far;
|
||||
char *inner_buf=(char *)p + bytes_so_far;
|
||||
long seeki;
|
||||
long rbytes;
|
||||
long this_bytes=inner_bytes;
|
||||
|
||||
#ifdef CDDA_TEST_OK
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_JITTER_SMALL
|
||||
if(jitter_flag)jitter=4*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_JITTER_LARGE
|
||||
if(jitter_flag)jitter=32*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_JITTER_MASSIVE
|
||||
if(jitter_flag)jitter=128*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_FRAG_SMALL
|
||||
if(los_flag)this_bytes=256*(int)(drand48()*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
if(jitter_flag)jitter=4*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_FRAG_LARGE
|
||||
if(los_flag)this_bytes=16*(int)(drand48()*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
if(jitter_flag)jitter=4*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_FRAG_MASSIVE
|
||||
if(los_flag)this_bytes=8*(int)(drand48()*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
if(jitter_flag)jitter=32*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_DROPDUPE_BYTES
|
||||
if(los_flag)this_bytes=CDIO_CD_FRAMESIZE_RAW;
|
||||
if(jitter_flag)
|
||||
if (drand48()>.8)
|
||||
this_jitter=32;
|
||||
else
|
||||
this_jitter=0;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
if(this_bytes>inner_bytes)this_bytes=inner_bytes;
|
||||
if(begin+jitter+bytes_so_far<0)jitter=0;
|
||||
seeki=begin+bytes_so_far+jitter;
|
||||
|
||||
if(fseek(fd,seeki,SEEK_SET)<0){
|
||||
return(0);
|
||||
}
|
||||
rbytes=fread(inner_buf,1,this_bytes,fd);
|
||||
bytes_so_far+=rbytes;
|
||||
if(rbytes==0)break;
|
||||
|
||||
#ifdef CDDA_TEST_SEEKJITTER
|
||||
jitter_flag=0;
|
||||
los_flag=0;
|
||||
#else
|
||||
#ifdef CDDA_TEST_ALLJITTER
|
||||
jitter_flag=1;
|
||||
los_flag=0;
|
||||
#else
|
||||
#ifdef CDDA_TEST_SOMEJITTER
|
||||
jitter_flag=(drand48()>.9?1:0);
|
||||
los_flag=(drand48()>.9?1:0);
|
||||
#else
|
||||
los_flag=1;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#ifdef CDDA_TEST_SCRATCH
|
||||
{
|
||||
long location=300*CDIO_CD_FRAMESIZE_RAW+(drand48()*56)+512;
|
||||
|
||||
if(begin<=location && begin+bytestotal>location){
|
||||
memset(p+location-begin,(int)(drand48()*256),1100);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return(sectors);
|
||||
}
|
||||
|
||||
/* set function pointers to use the ioctl routines */
|
||||
int test_init_drive (cdrom_drive *d){
|
||||
|
||||
d->nsectors=13;
|
||||
d->enable_cdda = dummy_exception;
|
||||
d->read_audio = test_read;
|
||||
d->read_toc = test_readtoc;
|
||||
d->set_speed = dummy_exception;
|
||||
d->tracks=d->read_toc(d);
|
||||
if(d->tracks==-1)
|
||||
return(d->tracks);
|
||||
d->opened=1;
|
||||
srand48(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
210
lib/cdda_interface/toc.c
Normal file
210
lib/cdda_interface/toc.c
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
$Id: toc.c,v 1.7 2008/04/16 17:00:40 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/******************************************************************
|
||||
* Table of contents convenience functions
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "low_interface.h"
|
||||
#include "utils.h"
|
||||
|
||||
/*! Return the lsn for the start of track i_track */
|
||||
lsn_t
|
||||
cdda_track_firstsector(cdrom_drive_t *d, track_t i_track)
|
||||
{
|
||||
if(!d->opened){
|
||||
cderror(d,"400: Device not open\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (i_track == 0) {
|
||||
if (d->disc_toc[0].dwStartSector == 0) {
|
||||
/* first track starts at lsn 0 -> no pre-gap */
|
||||
cderror(d,"401: Invalid track number\n");
|
||||
return(-1);
|
||||
}
|
||||
else {
|
||||
return 0; /* pre-gap of first track always starts at lba 0 */
|
||||
}
|
||||
}
|
||||
|
||||
if( i_track>d->tracks) {
|
||||
cderror(d,"401: Invalid track number\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
{
|
||||
const track_t i_first_track = cdio_get_first_track_num(d->p_cdio);
|
||||
return(d->disc_toc[i_track-i_first_track].dwStartSector);
|
||||
}
|
||||
}
|
||||
|
||||
/*! Get first lsn of the first audio track. -1 is returned on error. */
|
||||
lsn_t
|
||||
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 */
|
||||
for ( i=0; i<d->tracks; i++ )
|
||||
if( cdda_track_audiop(d, i+1)==1 ) {
|
||||
if (i == 0) /* disc starts at lba 0 if first track is an audio track */
|
||||
return 0;
|
||||
else
|
||||
return cdda_track_firstsector(d, i+1);
|
||||
}
|
||||
|
||||
cderror(d,"403: No audio tracks on disc\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*! 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)
|
||||
{
|
||||
if (!d->opened) {
|
||||
cderror(d,"400: Device not open\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (i_track == 0) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if ( i_track<1 || i_track>d->tracks ) {
|
||||
cderror(d,"401: Invalid track number\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* CD Extra have their first session ending at the last audio track */
|
||||
if (d->cd_extra > 0 && i_track+1 <= d->tracks) {
|
||||
if (d->audio_last_sector >= d->disc_toc[i_track-1].dwStartSector &&
|
||||
d->audio_last_sector < d->disc_toc[i_track].dwStartSector) {
|
||||
return d->audio_last_sector;
|
||||
}
|
||||
}
|
||||
|
||||
/* Safe, we've always the leadout at disc_toc[tracks] */
|
||||
return(d->disc_toc[i_track].dwStartSector-1);
|
||||
}
|
||||
|
||||
/*! 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
|
||||
cdda_disc_lastsector(cdrom_drive_t *d)
|
||||
{
|
||||
if (!d->opened) {
|
||||
cderror(d,"400: Device not open\n");
|
||||
return -1;
|
||||
} else {
|
||||
/* look for an audio track */
|
||||
const track_t i_first_track = cdio_get_first_track_num(d->p_cdio);
|
||||
track_t i = cdio_get_last_track_num(d->p_cdio);
|
||||
for ( ; i >= i_first_track; i-- )
|
||||
if ( cdda_track_audiop(d,i) )
|
||||
return (cdda_track_lastsector(d,i));
|
||||
}
|
||||
cderror(d,"403: No audio tracks on disc\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! Return the number of tracks on the CD. */
|
||||
track_t
|
||||
cdda_tracks(cdrom_drive_t *d)
|
||||
{
|
||||
if (!d->opened){
|
||||
cderror(d,"400: Device not open\n");
|
||||
return -1;
|
||||
}
|
||||
return(d->tracks);
|
||||
}
|
||||
|
||||
/*! 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.
|
||||
*/
|
||||
int
|
||||
cdda_sector_gettrack(cdrom_drive_t *d, lsn_t lsn)
|
||||
{
|
||||
if (!d->opened) {
|
||||
cderror(d,"400: Device not open\n");
|
||||
return -1;
|
||||
} else {
|
||||
if (lsn < d->disc_toc[0].dwStartSector)
|
||||
return 0; /* We're in the pre-gap of first track */
|
||||
|
||||
return cdio_get_track(d->p_cdio, lsn);
|
||||
}
|
||||
}
|
||||
|
||||
/*! Return the 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
|
||||
cdda_track_channels(cdrom_drive_t *d, track_t i_track)
|
||||
{
|
||||
return(cdio_get_track_channels(d->p_cdio, i_track));
|
||||
}
|
||||
|
||||
/*! Return 1 is track is an audio track, 0 otherwise. */
|
||||
int
|
||||
cdda_track_audiop(cdrom_drive_t *d, track_t i_track)
|
||||
{
|
||||
track_format_t track_format = cdio_get_track_format(d->p_cdio, i_track);
|
||||
return TRACK_FORMAT_AUDIO == track_format ? 1 : 0;
|
||||
}
|
||||
|
||||
/*! Return 1 is track is an audio track, 0 otherwise. */
|
||||
int
|
||||
cdda_track_copyp(cdrom_drive_t *d, track_t i_track)
|
||||
{
|
||||
track_flag_t track_flag = cdio_get_track_copy_permit(d->p_cdio, i_track);
|
||||
return CDIO_TRACK_FLAG_TRUE == track_flag ? 1 : 0;
|
||||
}
|
||||
|
||||
/*! Return 1 is audio track has linear preemphasis set, 0 otherwise.
|
||||
Only makes sense for audio tracks.
|
||||
*/
|
||||
int
|
||||
cdda_track_preemp(cdrom_drive_t *d, track_t i_track)
|
||||
{
|
||||
track_flag_t track_flag = cdio_get_track_preemphasis(d->p_cdio, i_track);
|
||||
return CDIO_TRACK_FLAG_TRUE == track_flag ? 1 : 0;
|
||||
}
|
||||
|
||||
152
lib/cdda_interface/utils.c
Normal file
152
lib/cdda_interface/utils.c
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
$Id: utils.c,v 1.4 2008/04/16 17:00:41 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "common_interface.h"
|
||||
#include "utils.h"
|
||||
void
|
||||
cderror(cdrom_drive_t *d,const char *s)
|
||||
{
|
||||
if(s && d){
|
||||
switch(d->errordest){
|
||||
case CDDA_MESSAGE_PRINTIT:
|
||||
write(STDERR_FILENO,s,strlen(s));
|
||||
break;
|
||||
case CDDA_MESSAGE_LOGIT:
|
||||
d->errorbuf=catstring(d->errorbuf,s);
|
||||
break;
|
||||
case CDDA_MESSAGE_FORGETIT:
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cdmessage(cdrom_drive_t *d, const char *s)
|
||||
{
|
||||
if(s && d){
|
||||
switch(d->messagedest){
|
||||
case CDDA_MESSAGE_PRINTIT:
|
||||
write(STDERR_FILENO,s,strlen(s));
|
||||
break;
|
||||
case CDDA_MESSAGE_LOGIT:
|
||||
d->messagebuf=catstring(d->messagebuf,s);
|
||||
break;
|
||||
case CDDA_MESSAGE_FORGETIT:
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
idperror(int messagedest,char **messages,const char *f,
|
||||
const char *s)
|
||||
{
|
||||
|
||||
char *buffer;
|
||||
int malloced=0;
|
||||
if(!f)
|
||||
buffer=(char *)s;
|
||||
else
|
||||
if(!s)
|
||||
buffer=(char *)f;
|
||||
else{
|
||||
buffer=malloc(strlen(f)+strlen(s)+9);
|
||||
sprintf(buffer,f,s);
|
||||
malloced=1;
|
||||
}
|
||||
|
||||
if(buffer){
|
||||
switch(messagedest){
|
||||
case CDDA_MESSAGE_PRINTIT:
|
||||
write(STDERR_FILENO,buffer,strlen(buffer));
|
||||
if(errno){
|
||||
write(STDERR_FILENO,": ",2);
|
||||
write(STDERR_FILENO,strerror(errno),strlen(strerror(errno)));
|
||||
write(STDERR_FILENO,"\n",1);
|
||||
}
|
||||
break;
|
||||
case CDDA_MESSAGE_LOGIT:
|
||||
if(messages){
|
||||
*messages=catstring(*messages,buffer);
|
||||
if(errno){
|
||||
*messages=catstring(*messages,": ");
|
||||
*messages=catstring(*messages,strerror(errno));
|
||||
*messages=catstring(*messages,"\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CDDA_MESSAGE_FORGETIT:
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
if(malloced)free(buffer);
|
||||
}
|
||||
|
||||
void
|
||||
idmessage(int messagedest,char **messages,const char *f,
|
||||
const char *s)
|
||||
{
|
||||
char *buffer;
|
||||
int malloced=0;
|
||||
if(!f)
|
||||
buffer=(char *)s;
|
||||
else
|
||||
if(!s)
|
||||
buffer=(char *)f;
|
||||
else{
|
||||
const unsigned int i_buffer=strlen(f)+strlen(s)+10;
|
||||
buffer=malloc(i_buffer);
|
||||
sprintf(buffer,f,s);
|
||||
strncat(buffer,"\n", i_buffer);
|
||||
malloced=1;
|
||||
}
|
||||
|
||||
if(buffer){
|
||||
switch(messagedest){
|
||||
case CDDA_MESSAGE_PRINTIT:
|
||||
write(STDERR_FILENO,buffer,strlen(buffer));
|
||||
if(!malloced)write(STDERR_FILENO,"\n",1);
|
||||
break;
|
||||
case CDDA_MESSAGE_LOGIT:
|
||||
if(messages){
|
||||
*messages=catstring(*messages,buffer);
|
||||
if(!malloced)*messages=catstring(*messages,"\n");
|
||||
}
|
||||
break;
|
||||
case CDDA_MESSAGE_FORGETIT:
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
if(malloced)free(buffer);
|
||||
}
|
||||
|
||||
char *
|
||||
catstring(char *buff, const char *s) {
|
||||
if (s) {
|
||||
const unsigned int add_len = strlen(s) + 9;
|
||||
if(buff) {
|
||||
buff = realloc(buff, strlen(buff) + add_len);
|
||||
} else {
|
||||
buff=calloc(add_len, 1);
|
||||
}
|
||||
strncat(buff, s, add_len);
|
||||
}
|
||||
return(buff);
|
||||
}
|
||||
79
lib/cdda_interface/utils.h
Normal file
79
lib/cdda_interface/utils.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
$Id: utils.h,v 1.8 2008/04/16 17:00:41 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cdio/bytesex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* I wonder how many alignment issues this is gonna trip in the
|
||||
future... it shouldn't trip any... I guess we'll find out :) */
|
||||
|
||||
static inline int
|
||||
bigendianp(void)
|
||||
{
|
||||
int test=1;
|
||||
char *hack=(char *)(&test);
|
||||
if(hack[0])return(0);
|
||||
return(1);
|
||||
}
|
||||
|
||||
extern char *catstring(char *buff, const char *s);
|
||||
|
||||
|
||||
/*#if BYTE_ORDER == LITTLE_ENDIAN*/
|
||||
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
|
||||
static inline int16_t be16_to_cpu(int16_t x){
|
||||
return(UINT16_SWAP_LE_BE_C(x));
|
||||
}
|
||||
|
||||
static inline int16_t le16_to_cpu(int16_t x){
|
||||
return(x);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static inline int16_t be16_to_cpu(int16_t x){
|
||||
return(x);
|
||||
}
|
||||
|
||||
static inline int16_t le16_to_cpu(int16_t x){
|
||||
return(UINT16_SWAP_LE_BE_C(x));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
static inline int16_t cpu_to_be16(int16_t x){
|
||||
return(be16_to_cpu(x));
|
||||
}
|
||||
|
||||
static inline int16_t cpu_to_le16(int16_t x){
|
||||
return(le16_to_cpu(x));
|
||||
}
|
||||
|
||||
void cderror(cdrom_drive_t *d, const char *s);
|
||||
|
||||
void cdmessage(cdrom_drive_t *d,const char *s);
|
||||
|
||||
void idperror(int messagedest, char **messages, const char *f, const char *s);
|
||||
|
||||
void idmessage(int messagedest, char **messages, const char *f, const char *s);
|
||||
|
||||
Reference in New Issue
Block a user