/*____________________________________________________________________________
MP3 Decoding Libraries
Lanuguages used: C, C++, ASM
As much as I would love to, I cannot take
full credit for writing this code.
Xing Technology made MPEG-Layer 3 for us
to decode. =)
- ULTiMaTuM -
MPEG-Layer 3 (MP3)
Copyright (C) 1995-1997 Xing Technology
NOTE: I only edited the bare-minimum. 90%
of this is original decoding code...
Hmm... that sounds strange =)
____________________________________________________________________________*/
/**** cupL3.c ***************************************************
unpack Layer III
mod 8/18/97 bugfix crc problem
mod 10/9/97 add band_limit12 for short blocks
mod 10/22/97 zero buf_ptrs in init
mod 5/15/98 mpeg 2.5
mod 8/19/98 decode 22 sf bands
******************************************************************/
/*---------------------------------------
TO DO: Test mixed blocks (mixed long/short)
No mixed blocks in mpeg-1 test stream being used for development
-----------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <float.h>
#include <math.h>
#include <memory.h>
#include <string.h>
#include <assert.h>
#include "mhead.h" /* mpeg header structure */
#include "L3.h"
#include "jdw.h"
/*====================================================================*/
static int mp_sr20_table[2][4] =
{{441, 480, 320, -999}, {882, 960, 640, -999}};
static int mp_br_tableL3[2][16] =
{{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0}, /* mpeg 2 */
{0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0}};
/*====================================================================*/
/*-- global band tables */
/*-- short portion is 3*x !! --*/
int nBand[2][22]; /* [long/short][cb] */
int sfBandIndex[2][22]; /* [long/short][cb] */
/*====================================================================*/
/*----------------*/
extern DEC_INFO decinfo;
/*----------------*/
static int mpeg25_flag;
int iframe;
/*-------*/
static int band_limit = (576);
static int band_limit21 = (576); // limit for sf band 21
static int band_limit12 = (576); // limit for sf band 12 short
int band_limit_nsb = 32; /* global for hybrid */
static int nsb_limit = 32;
static int gain_adjust = 0; /* adjust gain e.g. cvt to mono */
static int id;
static int ncbl_mixed; /* number of long cb's in mixed block 8 or 6 */
static int sr_index;
static int outvalues;
static int outbytes;
static int half_outbytes;
static int framebytes;
static int padframebytes;
static int crcbytes;
static int pad;
static int stereo_flag;
static int nchan;
static int ms_mode;
static int is_mode;
static unsigned int zero_level_pcm = 0;
/* cb_info[igr][ch], compute by dequant, used by joint */
static CB_INFO cb_info[2][2];
static IS_SF_INFO is_sf_info; /* MPEG-2 intensity stereo */
/*---------------------------------*/
/* main data bit buffer */
#define NBUF (8*1024)
#define BUF_TRIGGER (NBUF-1500)
static unsigned char buf[NBUF];
static int buf_ptr0 = 0;
static int buf_ptr1 = 0;
static int main_pos_bit;
/*---------------------------------*/
static SIDE_INFO side_info;
static SCALEFACT sf[2][2]; /* [gr][ch] */
static int nsamp[2][2]; /* must start = 0, for nsamp[igr_prev] */
/*- sample union of int/float sample[ch][gr][576] */
/* static SAMPLE sample[2][2][576]; */
extern SAMPLE sample[2][2][576];
static float yout[576]; /* hybrid out, sbt in */
typedef void (*SBT_FUNCTION) (float *sample, short *pcm, int ch);
void sbt_dual_L3(float *sample, short *pcm, int n);
static SBT_FUNCTION sbt_L3 = sbt_dual_L3;
typedef void (*XFORM_FUNCTION) (void *pcm, int igr);
static void Xform_dual(void *pcm, int igr);
static XFORM_FUNCTION Xform = Xform_dual;
IN_OUT L3audio_decode_MPEG1(unsigned char *bs, unsigned char *pcm);
IN_OUT L3audio_decode_MPEG2(unsigned char *bs, unsigned char *pcm);
typedef IN_OUT(*DECODE_FUNCTION) (unsigned char *bs, unsigned char *pcm);
static DECODE_FUNCTION decode_function = L3audio_decode_MPEG1;
/*====================================================================*/
int hybrid(void *xin, void *xprev, float *y,
int btype, int nlong, int ntot, int nprev);
int hybrid_sum(void *xin, void *xin_left, float *y,
int btype, int nlong, int ntot);
void sum_f_bands(void *a, void *b, int n);
void FreqInvert(float *y, int n);
void antialias(void *x, int n);
void ms_process(void *x, int n); /* sum-difference stereo */
void is_process_MPEG1(void *x, /* intensity stereo */
SCALEFACT * sf,
CB_INFO cb_info[2], /* [ch] */
int nsamp, int ms_mode);
void is_process_MPEG2(void *x, /* intensity stereo */
SCALEFACT * sf,
CB_INFO cb_info[2], /* [ch] */
IS_SF_INFO * is_sf_info,
int nsamp, int ms_mode);
void unpack_huff(void *xy, int n, int ntable);
int unpack_huff_quad(void *vwxy, int n, int nbits, int ntable);
void dequant(SAMPLE sample[], int *nsamp,
SCALEFACT * sf,
GR * gr,
CB_INFO * cb_info, int ncbl_mixed);
void unpack_sf_sub_MPEG1(SCALEFACT * scalefac, GR * gr,
int scfsi, /* bit flag */
int igr);
void unpack_sf_sub_MPEG2(SCALEFACT sf[], /* return intensity scale */
GR * grdat,
int is_and_ch, IS_SF_INFO * is_sf_info);
/*====================================================================*/
/* get bits from bitstream in endian independent way */
BITDAT bitdat; /* global for inline use by Huff */
/*------------- initialize bit getter -------------*/
static void bitget_init(unsigned char *buf)
{
bitdat.bs_ptr0 = bitdat.bs_ptr = buf;
bitdat.bits = 0;
bitdat.bitbuf = 0;
}
/*------------- initialize bit getter -------------*/
static void bitget_init_end(unsigned char *buf_end)
{
bitdat.bs_ptr_end = buf_end;
}
/*------------- get n bits from bitstream -------------*/
int bitget_bits_used()
{
int n; /* compute bits used from last init call */
n = ((bitdat.bs_ptr - bitdat.bs_ptr0) << 3) - bitdat.bits;
return n;
}
/*------------- check for n bits in bitbuf -------------*/
void bitget_check(int n)
{
if (bitdat.bits < n)
{
while (bitdat.bits <= 24)
{
bitdat.bitbuf = (bitdat.bitbuf << 8) | *bitdat.bs_ptr++;
bitdat.bits += 8;
}
}
}
/*------------- get n bits from bitstream -------------*/
unsigned int bitget(int n)
{
unsigned int x;
if (bitdat.bits < n)
{ /* refill bit buf if necessary */
while (bitdat.bits <= 24)
{
bitdat.bitbuf = (bitdat.bitbuf << 8) | *bitdat.bs_ptr++;
bitdat.bits += 8;
}
}
bitdat.bits -= n;
x = bitdat.bitbuf >> bitdat.bits;
bitdat.bitbuf -= x << bitdat.bits;
return x;
}
/*------------- get 1 bit from bitstream -------------*/
unsigned int bitget_1bit()
{
unsigned int x;
if (bitdat.bits <= 0)
{ /* refill bit buf if necessary */
while (bitdat.bits <= 24)
{
bitdat.bitbuf = (bitdat.bitbuf << 8) | *bitdat.bs_ptr++;
bitdat.bits += 8;
}
}
bitdat.bits--;
x = bitdat.bitbuf >> bitdat.bits;
bitdat.bitbuf -= x << bitdat.bits;
return x;
}
/*====================================================================*/
static void Xform_mono(void *pcm, int igr)
{
int igr_prev, n1, n2;
/*--- hybrid + sbt ---*/
n1 = n2 = nsamp[igr][0]; /* total number bands */
if (side_info.gr[igr][0].block_type == 2)
{ /* long bands */
n1 = 0;
if (side_info.gr[igr][0].mixed_block_flag)
n1 = sfBandIndex[0][ncbl_mixed - 1];
}
if (n1 > band_limit)
n1 = band_limit;
if (n2 > band_limit)
n2 = band_limit;
igr_prev = igr ^ 1;
nsamp[igr][0] = hybrid(sample[0][igr], sample[0][igr_prev],
yout, side_info.gr[igr][0].block_type, n1, n2, nsamp[igr_prev][0]);
FreqInve
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
MP3解码演示,本程序演示了MPEG-Layer 3 (MP3)格式的文件是如何被诸如WinAmp和Windows Media Player这样的程序读出来的。请注意,该代码没有调用Windows API,DLL或者OCX。该源代码阅读和播放MP3文件,没有包含例子,但它基于FreeAmp。最初的MP3解码算法是由Xing Technologies编写的.
资源推荐
资源详情
资源评论
收起资源包目录
MPEG-Layer.rar (59个子文件)
MPEG-Layer
wavep.c 4KB
cup.c 17KB
l3dq.c 6KB
msisasm.asm 2KB
xing.opt 49KB
mdct.c 6KB
xing.plg 7KB
isbt.c 11KB
cupL1.c 8KB
xinglmc.cpp 27KB
xing.def 148B
towave.c 19KB
csbtL3.c 7KB
xing.001 16KB
upsf.c 9KB
htable.h 71KB
iup.c 19KB
uph.c 12KB
xing.dsw 531B
wcvt.c 3KB
isbtb.c 8KB
csbtb.c 7KB
cdct.c 9KB
x86intel.c 11KB
cdctasm.asm 10KB
cupl3.c 35KB
iwinQ.c 18KB
cwin.c 10KB
icdct.c 10KB
port.h 2KB
xing.aps 32KB
iwinbQ.c 18KB
l3init.c 10KB
xing.dsp 16KB
hwin.c 7KB
iupini.c 11KB
mhead.h 2KB
xinglmc.h 5KB
mhead.c 8KB
cwin8asm.asm 14KB
x86gas.s 9KB
cwinb.c 11KB
cwinasm.asm 13KB
msis.c 7KB
x86intel.asm 12KB
jdw.h 631B
L3.h 4KB
cupini.c 12KB
iwinm.c 2KB
xing.mak 51KB
mdctasm.asm 74KB
iupL1.c 8KB
xing.ncb 249KB
tableawd.h 4KB
xing.rc 3KB
cwinm.c 1KB
csbt.c 9KB
itype.h 4KB
dec8.c 8KB
共 59 条
- 1
资源评论
钱亚锋
- 粉丝: 86
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功