home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Da Capo
/
da_capo_vol1.bin
/
programs
/
amiga
/
misc
/
mpegaudio
/
common.c
next >
Wrap
C/C++ Source or Header
|
1994-03-21
|
48KB
|
1,540 lines
/**********************************************************************
Copyright (c) 1991 MPEG/audio software simulation group, All Rights Reserved
common.c
**********************************************************************/
/**********************************************************************
* MPEG/audio coding/decoding software, work in progress *
* NOT for public distribution until verified and approved by the *
* MPEG/audio committee. For further information, please contact *
* Davis Pan, 508-493-2241, e-mail: pan@3d.enet.dec.com *
* *
* VERSION 4.0 *
* changes made since last update: *
* date programmers comment *
* 2/25/91 Doulas Wong, start of version 1.0 records *
* Davis Pan *
* 5/10/91 W. Joseph Carter Created this file for all common *
* functions and global variables. *
* Ported to Macintosh and Unix. *
* Added Jean-Georges Fritsch's *
* "bitstream.c" package. *
* Added routines to handle AIFF PCM *
* sound files. *
* Added "mem_alloc()" and "mem_free()" *
* routines for memory allocation *
* portability. *
* Added routines to convert between *
* Apple SANE extended floating point *
* format and IEEE double precision *
* floating point format. For AIFF. *
* 02jul91 dpwe (Aware Inc) Moved allocation table input here; *
* Tables read from subdir TABLES_PATH. *
* Added some debug printout fns (Write*)*
* 7/10/91 Earle Jennings replacement of the one float by FLOAT *
* port to MsDos from MacIntosh version *
* 8/ 5/91 Jean-Georges Fritsch fixed bug in open_bit_stream_r() *
*10/ 1/91 S.I. Sudharsanan, Ported to IBM AIX platform. *
* Don H. Lee, *
* Peter W. Farrett *
*10/3/91 Don H. Lee implemented CRC-16 error protection *
* newly introduced functions are *
* I_CRC_calc, II_CRC_calc and *
* update_CRC. Additions and revisions *
* are marked with dhl for clarity *
*10/18/91 Jean-Georges Fritsch fixed bug in update_CRC(), *
* II_CRC_calc() and I_CRC_calc() *
* 2/11/92 W. Joseph Carter Ported new code to Macintosh. Most *
* important fixes involved changing *
* 16-bit ints to long or unsigned in *
* bit alloc routines for quant of 65535 *
* and passing proper function args. *
* Removed "Other Joint Stereo" option *
* and made bitrate be total channel *
* bitrate, irrespective of the mode. *
* Fixed many small bugs & reorganized. *
* 3/20/92 Jean-Georges Fritsch fixed bug in start-of-frame search *
* 6/15/92 Juan Pineda added refill_buffer(bs) "n" *
* initialization *
* 7/08/92 Susanne Ritscher MS-DOS, MSC6.0 port fixes *
* 7/27/92 Mike Li (re-)Port to MS-DOS *
* 8/19/92 Soren H. Nielsen Fixed bug in I_CRC_calc and in *
* II_CRC_calc. Added function: new_ext *
* for better MS-DOS compatability *
* 3/10/93 Kevin Peterson changed aiff_read_headers to handle *
* chunks in any order. now returns *
* position of sound data in file. *
* 3/31/93 Jens Spille changed IFF_* string compares to use *
* strcmp() *
* 5/30/93 Masahiro Iwadare ?? the previous modification does not *
* work. recovered to the original. ?? *
* 8/27/93 Seymour Shlien, Fixes in Unix and MSDOS ports, *
* Daniel Lauzon, and *
* Bill Truerniet *
**********************************************************************/
/***********************************************************************
*
* Global Include Files
*
***********************************************************************/
#include "common.h"
#ifdef MACINTOSH
#include <SANE.h>
#include <pascal.h>
#endif
#include <ctype.h>
/***********************************************************************
*
* Global Variable Definitions
*
***********************************************************************/
char *mode_names[4] = { "stereo", "j-stereo", "dual-ch", "single-ch" };
char *layer_names[3] = { "I", "II", "III" };
double s_freq[4] = {44.1, 48, 32, 0};
int bitrate[3][15] = {
{0,32,64,96,128,160,192,224,256,288,320,352,384,416,448},
{0,32,48,56,64,80,96,112,128,160,192,224,256,320,384},
{0,32,40,48,56,64,80,96,112,128,160,192,224,256,320}
};
double FAR multiple[64] = {
2.00000000000000, 1.58740105196820, 1.25992104989487,
1.00000000000000, 0.79370052598410, 0.62996052494744, 0.50000000000000,
0.39685026299205, 0.31498026247372, 0.25000000000000, 0.19842513149602,
0.15749013123686, 0.12500000000000, 0.09921256574801, 0.07874506561843,
0.06250000000000, 0.04960628287401, 0.03937253280921, 0.03125000000000,
0.02480314143700, 0.01968626640461, 0.01562500000000, 0.01240157071850,
0.00984313320230, 0.00781250000000, 0.00620078535925, 0.00492156660115,
0.00390625000000, 0.00310039267963, 0.00246078330058, 0.00195312500000,
0.00155019633981, 0.00123039165029, 0.00097656250000, 0.00077509816991,
0.00061519582514, 0.00048828125000, 0.00038754908495, 0.00030759791257,
0.00024414062500, 0.00019377454248, 0.00015379895629, 0.00012207031250,
0.00009688727124, 0.00007689947814, 0.00006103515625, 0.00004844363562,
0.00003844973907, 0.00003051757813, 0.00002422181781, 0.00001922486954,
0.00001525878906, 0.00001211090890, 0.00000961243477, 0.00000762939453,
0.00000605545445, 0.00000480621738, 0.00000381469727, 0.00000302772723,
0.00000240310869, 0.00000190734863, 0.00000151386361, 0.00000120155435,
1E-20
};
/***********************************************************************
*
* Global Function Definitions
*
***********************************************************************/
/* The system uses a variety of data files. By opening them via this
function, we can accommodate various locations. */
FILE *OpenTableFile(name)
char *name;
{
char fulname[80];
char *envdir;
FILE *f;
fulname[0] = '\0';
#ifdef TABLES_PATH
strcpy(fulname, TABLES_PATH); /* default relative path for tables */
#endif /* TABLES_PATH */ /* (includes terminal path seperator */
#ifdef UNIX /* envir. variables for UNIX only */
{
char *getenv();
envdir = getenv(MPEGTABENV); /* check for environment */
if(envdir != NULL)
strcpy(fulname, envdir);
strcat(fulname, PATH_SEPARATOR); /* add a "/" on the end */
}
#endif /* UNIX */
strcat(fulname, name);
if( (f=fopen(fulname,"r