cd.c

来自「ESS3890+SL原代码(1*16内存)」· C语言 代码 · 共 160 行

C
160
字号
/* Copyright 1996, ESS Technology, Inc.					*//* SCCSID @(#)cd.c	4.6 11/04/03 *//* * $Log$ */#include "vcxi.h"#include "const.h"#include "constvar.h"#include "util.h"#include "cd.h"#ifdef PLAY20/************************************************************************ * Utility routine to adjust the CD time.				* ************************************************************************//*------------------------------------------------------------------------  Description:      return (time1 - time0) / 9.      This function is used for track digest.  ------------------------------------------------------------------------*/unsigned int deltaCDtime(unsigned int time1, unsigned int time0){    int delta;    int mmss00 = 0xffff00;        delta = msf2sectors(time1) - msf2sectors(time0);    delta /= 9;    mmss00 &= logical2physical(delta); /* remove frames info */        return(mmss00);}#endif /* PLAY20 *//*  * Translate sector number into mm:ss:ff. Since division and mod are * rather expensive in MIPS-X, we'll use multiplication instead. * * Input:	num is the sector number * Return:	MMSSFF in CD time format where each of MM/SS/FF is a BCD */int logical2physical(int num){    int min=0, sec=0;        /* limit to max. CD time: 99:59:74 */    if (num > 449999) return (xMAX_CDTIME);    /* get minutes */    while (num >= 4500) {	num -= 4500;	min++;    }        /* get seconds */    while (num >= 75) {	num -= 75;	sec++;    }    /* "num" has frames now */    return ( (hex2bcd[min]<<16) | (hex2bcd[sec]<<8) | hex2bcd[num] );}/* * This routine operates on 2 CD-format time and return the result. * CD-format time is MMSSFF where each of MM/SS/FF is in BCD * * Inputs: *	time:		CD format time to be adjusted *	amount:		Amount to adjust with in CD format time *	direction:  	1: to add the two numbers together *		    other: time - amount * * Return: *	result:		in CD format time * * I assume the sum and difference are all within CD range. I.e. this * routine is defined to do fine grain adjustment arount a given time. */unsigned int adjCDtime(uint time, uint amount, int direction){    int new_sector;        new_sector = msf2sectors(time);    if (direction > 0) {	new_sector += msf2sectors(amount);	/* check for overflow..	 * limit to max. CD time: 99:59:74	 */	if (new_sector > 449999) return (xMAX_CDTIME);    } else {	new_sector -= msf2sectors(amount);	/* check for underflow */	if (new_sector < 0) return (0);    }        return (logical2physical(new_sector));}/*  * Translate mm:ss:ff into sector number. * * Input:	MMSSFF in CD time format where each of MM/SS/FF is a BCD * Return:	num is the sector number */int msf2sectors(unsigned int msf){    int time_in_frames;    /* Translate BCD time to frames..75 frames/sec */    time_in_frames = (int)bcd2hex[msf & 0xff]; /* frames */    msf >>= 8;    time_in_frames += (int)(75 * bcd2hex[msf & 0xff]); /* seconds */    msf >>= 8;    time_in_frames += (int)(4500 * bcd2hex[msf & 0xff]); /* minutes */        return (time_in_frames);}/* * Sanity check for valid BCD mm:ss:ff values in time_msf.  * * input:  *	time_msf - time in BCD mm:ss:ff format. *	           (examples of "bad" mm, ss, ff, are: 0xA7, 0x2B) * * output:  *	non-zero - invalid "time_msf", i.e. non-BCD msf. *	zero - valid BCD msf format. *  * NOTE: This function does not check if the time value is "correct". * It only determines if the values for mm, ss and ff are valid BCD * numbers. For severely scratched discs, we have found that * values like: 0xa02544, 0x092b32, were coming in for "currCDtime". */int CDtime_check(uint time_msf) {#ifdef CDTIME_FILTER    unsigned int msf0,msf1;	        msf0=time_msf;    msf1=(hex2bcd[bcd2hex[(msf0>>16)&0xff]])<<16;    msf1|=(hex2bcd[bcd2hex[(msf0>>8)&0xff]])<<8;    msf1|=hex2bcd[bcd2hex[msf0&0xff]];    return (msf0^msf1); /* 0: good, non-zero: bad */#else    return (0); /* "good"..no checking */#endif}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?