www.pudn.com > mediator15src.zip > common.c
/* All modifications to the original file common.c are * Copyright (C) 2001 Arno Hornberger*/ #include "mpg123.h" static const int tabsel_123[2][3][16] = { { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0}, {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,0}, {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,0} }, { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,0}, {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0}, {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0} } }; static const int freqs[9] = { 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000 }; /* * decode a header and write the information * into the frame structure */ int decode_header(struct frame *fr, unsigned long header) { if (header & (1 << 20)) { fr->lsf = (header & (1 << 19)) ? 0x0 : 0x1; fr->mpeg25 = 0; } else { fr->lsf = 1; fr->mpeg25 = 1; } fr->lay = 4 - ((header >> 17) & 3); if (((header >> 10) & 0x3) == 0x3) return 0; /* illegal sample rate frequency index */ if (fr->mpeg25) fr->sampling_frequency = 6 + ((header >> 10) & 0x3); else fr->sampling_frequency = ((header >> 10) & 0x3) + (fr->lsf * 3); fr->sample_rate = freqs[fr->sampling_frequency]; fr->error_protection = ((header >> 16) & 0x1) ^ 0x1; fr->bitrate_index = ((header>>12)&0xf); fr->padding = ((header>>9)&0x1); fr->extension = ((header>>8)&0x1); fr->mode = ((header>>6)&0x3); fr->mode_ext = ((header>>4)&0x3); fr->copyright = ((header>>3)&0x1); fr->original = ((header>>2)&0x1); fr->emphasis = header & 0x3; fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2; /* free format ought to report a 'not supported' */ /* but afaik free format MPEG-audio is not used */ /* in video streams anyway... (?) */ if (!fr->bitrate_index || (fr->bitrate_index == 15)) return 0; /* free format not supported or bad format */ /* calc size of the audio-frame (including */ /* an optional 16-bit CRC-sum, excluding header) */ switch (fr->lay) { case 1: fr->framesize = tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000; fr->framesize /= freqs[fr->sampling_frequency]; fr->framesize = ((fr->framesize+fr->padding) << 2) - 4; break; case 2: fr->framesize = tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000; fr->framesize /= freqs[fr->sampling_frequency]; fr->framesize += fr->padding - 4; break; case 3: fr->framesize = tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000; fr->framesize /= freqs[fr->sampling_frequency] << (fr->lsf); fr->framesize += fr->padding - 4; break; default: return 0; /* Unknown layer type */ } return fr->framesize; }