⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.c

📁 ISO mp3 sources (distribution 10) Layer 1/2/3, C Source, 512 k Sources of the Mpeg 1,2 layer 1,2
💻 C
📖 第 1 页 / 共 4 页
字号:
    /* Bug corrected by SWKim060695 */    br_per_ch = bitrate[lay][bsp] / (fr_ps->stereo /* + fr_ps->stereomc */);    ws = fr_ps->header->sampling_frequency;    sfrq = s_freq[ws];    /* decision rules refer to per-channel bitrates (kbits/sec/chan) */    if ((sfrq == 48 && br_per_ch >= 56) ||	(br_per_ch >= 56 && br_per_ch <= 80))	table = 0;    else if (sfrq != 48 && br_per_ch >= 96)	table = 1;    else if (sfrq != 32 && br_per_ch <= 48)	table = 2;    else	table = 3;    if (fr_ps->tab_num != table)    {	if (fr_ps->tab_num >= 0)	    mem_free ((void **) &(fr_ps->alloc));	fr_ps->alloc = (al_table *) mem_alloc (sizeof (al_table), "alloc");	sblim = read_bit_alloc (fr_ps->tab_num = table, fr_ps->alloc);    }    if (verbosity >= 2)	printf("sblim = %d,  table = %d,  br_per_ch = %d\n", sblim, table, br_per_ch);    return (sblim);}/* choose MC and ML tables, load if necess, return # sb's */void mc_pick_table (frame_params *fr_ps)   {   int tablemc, tableml, ws, sfrq;   /* BUG corrected SWKim060695 */   ws = fr_ps->header->sampling_frequency;   sfrq = s_freq[ws];   /* decision rules refer to sampling frequency */   if (sfrq == 48)      tablemc = 0;   else      tablemc = 1;   if (fr_ps->tab_num_mc != tablemc)   {      if (fr_ps->tab_num >= 0)	 mem_free ((void **)& (fr_ps->alloc_mc));      fr_ps->alloc_mc = (al_table *) mem_alloc (sizeof(al_table), "alloc_mc");      fr_ps->sblimit_mc = read_bit_alloc (fr_ps->tab_num_mc = tablemc, fr_ps->alloc_mc);   }    if (fr_ps->header->multiling_ch > 0)    {	/* LSF MultiLingual 7/8/95 WtK */	if (fr_ps->header->multiling_fs == 0)	{	    fr_ps->tab_num_ml = fr_ps->tab_num_mc;	    fr_ps->alloc_ml   = fr_ps->alloc_mc;	    fr_ps->sblimit_ml = fr_ps->sblimit_mc;	}	else	{	    tableml = 4;	    if (fr_ps->tab_num_ml != tableml)	    {		if (fr_ps->tab_num_ml >= 0)		    mem_free ((void **) &(fr_ps->alloc_ml));		fr_ps->alloc_ml = (al_table *) mem_alloc (sizeof (al_table), "alloc_ml");		fr_ps->sblimit_ml = read_bit_alloc (fr_ps->tab_num_ml = tableml, fr_ps->alloc_ml);	    }	} /* ml_fs==0 */    } /* ml_ch>0 */    if (verbosity >= 2)    {	printf("Multchannel uses : sblim = %d,  table = %d\n", fr_ps->sblimit_mc, fr_ps->tab_num_mc);	if (fr_ps->header->multiling_ch > 0) 	    printf ("Multilingual uses : sblim = %d, table = %d\n", fr_ps->sblimit_ml, fr_ps->tab_num_ml);    }}int js_bound (int lay, int m_ext){    static int jsb_table[3][4] =  { { 4, 8, 12, 16 }, { 4, 8, 12, 16},				    { 0, 4, 8, 16} };  /* lay+m_e -> jsbound */    if (lay < 1 || lay > 3 || m_ext < 0 || m_ext > 3)    {        fprintf (stderr, "js_bound bad layer/modext (%d/%d)\n", lay, m_ext);        exit (1);    }    return (jsb_table[lay-1][m_ext]);}void hdr_to_frps (frame_params *fr_ps) /* interpret data in hdr str to fields in fr_ps */{    layer *hdr = fr_ps->header;     /* (or pass in as arg?) */    fr_ps->actual_mode = hdr->mode;    if (hdr->mode != MPG_MD_NONE)	fr_ps->stereo = (hdr->mode == MPG_MD_MONO) ? 1 : 2;    else    	fr_ps->stereo = 0;    if (verbosity >= 2)        printf ("stereo = %d stereomc = %d stereoaug = %d\n",		fr_ps->stereo, fr_ps->stereomc, fr_ps->stereoaug);    if (hdr->lay == 2)	fr_ps->sblimit = pick_table (fr_ps);    else	fr_ps->sblimit = SBLIMIT;    if (hdr->mode == MPG_MD_JOINT_STEREO)	fr_ps->jsbound = js_bound (hdr->lay, hdr->mode_ext);    else	fr_ps->jsbound = fr_ps->sblimit;    if (hdr->multiling_ch > 0 && hdr->multiling_lay > 0)    {	fprintf (stderr, "MultiLingual not in Layer 2!\n exit.\n");	exit (1);    }    if (fr_ps->stereomc > 0 || hdr->lfe || hdr->multiling_ch > 0)		mc_pick_table (fr_ps);}int BitrateIndex(int layr, int bRate)   /* convert bitrate in kbps to index */                        /* 1 or 2 */                        /* legal rates from 32 to 448 */{int     index = 0;int     found = 0;    while(!found && index<15)   {        if(bitrate[layr-1][index] == bRate)            found = 1;        else            ++index;    }    if(found)        return(index);    else {        fprintf(stderr, "BitrateIndex: %d (layer %d) is not a legal bitrate\n",                bRate, layr);        return(-1);     /* Error! */    }}int SmpFrqIndex(long int sRate)  /* convert samp frq in Hz to index *//* for MultiLingual LSF                                                       *//* Note this function differs from the one called upon MPEG2 Audio-LSF coding *//* The value '16' is used to detect half sample rate of ML wrt. MC            *//* 7/8/95 WtK                                                                 */{    switch (sRate) {      case    44100    :   return( 0);     break;      case    48000    :   return( 1);     break;      case    32000    :   return( 2);     break;      case    22050    :   return(16);     break;      case    24000    :   return(17);     break;      case    16000    :   return(18);     break;      default          :   fprintf(stderr, "SmpFrqIndex: %ld is not a legal sample rate\n", sRate);                           return(-1);     /* Error! */    }}/*********************************************************************************  Allocate number of bytes of memory equal to "block".********************************************************************************/void *mem_alloc (long unsigned int block, char *item){#ifndef MSDOS    void *ptr;#else    void _far *ptr;#endif#ifdef MACINTOSH    ptr = NewPtr (block);#endif#ifdef MSDOS    ptr = (void _far *) _fmalloc ((unsigned int) block); /* far memory, 92-07-08 sr */#endif#if ! defined (MACINTOSH) && ! defined (MSDOS)    ptr = (void *) malloc (block);#endif    if (ptr != NULL)    {#ifdef MSDOS	_fmemset (ptr, 0, (unsigned int) block); /* far memory, 92-07-08 sr */#else        memset (ptr, 0, block);#endif    }    else    {        printf ("Unable to allocate %s\n", item);        exit (1);    }    return (ptr);}/******************************************************************************  Free memory pointed to by "*ptr_addr".******************************************************************************/void    mem_free (void **ptr_addr){    if (*ptr_addr != NULL)    {#ifdef  MACINTOSH	DisposPtr (*ptr_addr);#else	free (*ptr_addr);#endif	*ptr_addr = NULL;    }}/******************************************************************************  Routines to convert between the Apple SANE extended floating point format*  and the IEEE double precision floating point format.  These routines are*  called from within the Audio Interchange File Format (AIFF) routines.******************************************************************************//**** Apple's 80-bit SANE extended has the following format: 1       15      1            63+-+-------------+-+-----------------------------+|s|       e     |i|            f                |+-+-------------+-+-----------------------------+  msb        lsb   msb                       lsbThe value v of the number is determined by these fields as follows:If 0 <= e < 32767,              then v = (-1)^s * 2^(e-16383) * (i.f).If e == 32767 and f == 0,       then v = (-1)^s * (infinity), regardless of i.If e == 32767 and f != 0,       then v is a NaN, regardless of i.*** IEEE Draft Standard 754 Double Precision has the following format:MSB+-+---------+-----------------------------+|1| 11 Bits |           52 Bits           |+-+---------+-----------------------------+ ^     ^                ^ |     |                | Sign  Exponent         Mantissa*//*******************************************************************************  double_to_extended()**  Purpose:     Convert from IEEE double precision format to SANE extended*               format.**  Passed:      Pointer to the double precision number and a pointer to what*               will hold the Apple SANE extended format value.**  Outputs:     The SANE extended format pointer will be filled with the*               converted value.**  Returned:    Nothing.******************************************************************************/void    double_to_extended(double *pd, char *ps){#ifdef  MACINTOSH        x96tox80(pd, (extended *) ps);#else/* fixed bus alignment error, HP 27-may-93 */register unsigned long  top2bits;register unsigned short *ps2;register IEEE_DBL       *p_dbl;register SANE_EXT       *p_ext;SANE_EXT ext_align;char *c_align;int i;   p_dbl = (IEEE_DBL *) pd;   p_ext = &ext_align;   top2bits = p_dbl->hi & 0xc0000000;   p_ext->l1 = ((p_dbl->hi >> 4) & 0x3ff0000) | top2bits;   p_ext->l1 |= ((p_dbl->hi >> 5) & 0x7fff) | 0x8000;   p_ext->l2 = (p_dbl->hi << 27) & 0xf8000000;   p_ext->l2 |= ((p_dbl->lo >> 5) & 0x07ffffff);   ps2 = (unsigned short *) & (p_dbl->lo);   ps2++;   p_ext->s1 = (*ps2 << 11) & 0xf800;   c_align = (char *) p_ext;   for (i=0;i<10;i++)     ps[i] = c_align[i];#endif}/*******************************************************************************  extended_to_double()**  Purpose:     Convert from SANE extended format to IEEE double precision*               format.**  Passed:      Pointer to the Apple SANE extended format value and a pointer*               to what will hold the the IEEE double precision number.**  Outputs:     The IEEE double precision format pointer will be filled with*               the converted value.**  Returned:    Nothing.******************************************************************************/void    extended_to_double(char *ps, double *pd){#ifdef  MACINTOSH   x80tox96((extended *) ps, pd);#else/* fixed bus alignment error, HP 27-may-93 */register unsigned long  top2bits;register IEEE_DBL       *p_dbl;register SANE_EXT       *p_ext;SANE_EXT ext_align;char *c_align;int i;   p_dbl = (IEEE_DBL *) pd;   p_ext = &ext_align;   c_align = (char *) p_ext;   for (i=0;i<10;i++)     c_align[i] = ps[i];   top2bits = p_ext->l1 & 0xc0000000;   p_dbl->hi = ((p_ext->l1 << 4) & 0x3ff00000) | top2bits;   p_dbl->hi |= (p_ext->l1 << 5) & 0xffff0;   p_dbl->hi |= (p_ext->l2 >> 27) & 0x1f;   p_dbl->lo = (p_ext->l2 << 5) & 0xffffffe0;   p_dbl->lo |= (unsigned long) ((p_ext->s1 >> 11) & 0x1f);#endif}/*******************************************************************************  Read Audio Interchange File Format (AIFF) headers.******************************************************************************/int aiff_read_headers (FILE *file_ptr, IFF_AIFF *aiff_ptr, int *byte_per_sample){    register char   i;    register long   seek_offset;        char				 temp_sampleRate[10];    char				 *dummy;    char				 holder;    Chunk           FormChunk;    CommonChunk     CommChunk;    SoundDataChunk  SndDChunk;    identifier		 ident;    if (fseek (file_ptr, 0, SEEK_SET) != 0)	return (-1);    if (fread (&FormChunk, sizeof (Chunk), 1, file_ptr) != 1)	return (-1);#ifdef MSDOS    holder = FormChunk.ckID[0];    FormChunk.ckID[0] = FormChunk.ckID[3];    FormChunk.ckID[3] = holder;    holder = FormChunk.ckID[1];    FormChunk.ckID[1] = FormChunk.ckID[2];    FormChunk.ckID[2] = holder;/* fixed bug in next line, HP 27-may-93 */    holder = FormChunk.formType[0];    FormChunk.formType[0] = FormChunk.formType[3];    FormChunk.formType[3] = holder;    holder = FormChunk.formType[1];    FormChunk.formType[1] = FormChunk.formType[2];    FormChunk.formType[2] = holder;    FormChunk.ckSize = _lrotl(FormChunk.ckSize, 8);#endif/* fixed bug in next line, HP 27-may-93 */    if (strncmp (FormChunk.ckID, IFF_ID_FORM, 4) != 0 ||	strncmp (FormChunk.formType, IFF_ID_AIFF, 4) != 0)	return (-1); 	/* warning: different levels of indirection.7/8/92.sr*/    if (fread (&ident, sizeof (identifier), 1, file_ptr) != 1)	return (-1);#ifdef MSDOS    holder = ident.name[0];    ident.name[0] = ident.name[3];    ident.name[3] = holder;    holder = ident.name[1];    ident.name[1] = ident.name[2];    ident.name[2] = holder;    ident.ck_length = _lrotl (ident.ck_length, 8);#endif/* fixed bug in next line, HP 27-may-93 */    while (strncmp (ident.name, IFF_ID_COMM, 4) != 0)    {	dummy = (char *) mem_alloc (ident.ck_length * sizeof (char),  "dummy");	if (fread (dummy, ident.ck_length, 1, file_ptr) != 1)	    return (-1);	mem_free ((void **) &dummy);/* fixed bug in next line, HP 27-may-93 */	if (fread (&ident, sizeof (identifier), 1, file_ptr) != 1)	   return (-1);#ifdef MSDOS	holder = ident.name[0];	ident.name[0] = ident.name[3];	ident.name[3] = holder;	holder = ident.name[1];	ident.name[1] = ident.name[2];	ident.name[2] = holder;	ident.ck_length = _lrotl(ident.ck_length, 8);#endif    }    for (i = 0; i < 4; ++i)	CommChunk.ckID[i] = ident.name[i];    CommChunk.ckSize = ident.ck_length;    if (fread (&CommChunk.numChannels, sizeof (short), 1, file_ptr) != 1)	return (-1);    if (fread (&CommChunk.numSampleFrames, sizeof (unsigned long), 1, file_ptr) != 1)	return (-1);    if (fread (&CommChunk.sampleSize, sizeof (short), 1, file_ptr) != 1)	return (-1);    if (fread (CommChunk.sampleRate, sizeof (char[10]), 1, file_ptr) != 1)	return (-1);#ifdef MSDOS    CommChunk.sampleSize = _rotl (CommChunk.sampleSize, 8);    CommChunk.ckSize = _lrotl (CommChunk.ckSize, 8);    CommChunk.numChannels = _rotl (CommChunk.numChannels, 8);    CommChunk.numSampleFrames = _lrotl (CommChunk.numSampleFrames, 8);#endif    *byte_per_sample = ceil ((double) CommChunk.sampleSize / 8);    for (i = 0; i < sizeof (char[10]); i++)	temp_sampleRate[i] = CommChunk.sampleRate[i];    extended_to_double (temp_sampleRate, &aiff_ptr->sampleRate);/* to start the search again from the beginning, HP 27-may-93 */    fseek (file_ptr, sizeof (Chunk), SEEK_SET);    if (fread (&ident, sizeof (identifier), 1, file_ptr) != 1)	return (-1);#ifdef MSDOS    holder = ident.name[0];

⌨️ 快捷键说明

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