layer1.c
来自「从FFMPEG转换而来的H264解码程序,VC下编译..」· C语言 代码 · 共 163 行
C
163 行
/*
* Mpeg Layer-1 audio decoder
* --------------------------
* copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
* near unoptimzed ...
*
* may have a few bugs after last optimization ...
*
*/
//#include "mpg123.h"
static void I_step_one(mp3lib_ctx *ctx,unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)
{
unsigned int *ba=balloc;
unsigned int *sca = (unsigned int *) scale_index;
if(fr->stereo==2) {
int i;
int jsbound = fr->jsbound;
for (i=0;i<jsbound;i++) {
*ba++ = getbits(ctx,4);
*ba++ = getbits(ctx,4);
}
for (i=jsbound;i<SBLIMIT;i++)
*ba++ = getbits(ctx,4);
ba = balloc;
for (i=0;i<jsbound;i++) {
if ((*ba++))
*sca++ = getbits(ctx,6);
if ((*ba++))
*sca++ = getbits(ctx,6);
}
for (i=jsbound;i<SBLIMIT;i++)
if ((*ba++)) {
*sca++ = getbits(ctx,6);
*sca++ = getbits(ctx,6);
}
}
else {
int i;
for (i=0;i<SBLIMIT;i++)
*ba++ = getbits(ctx,4);
ba = balloc;
for (i=0;i<SBLIMIT;i++)
if ((*ba++))
*sca++ = getbits(ctx,6);
}
}
static void I_step_two(mp3lib_ctx *ctx,real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
unsigned int scale_index[2][SBLIMIT],struct frame *fr)
{
int i,n;
int smpb[2*SBLIMIT]; /* values: 0-65535 */
int *sample;
register unsigned int *ba;
register unsigned int *sca = (unsigned int *) scale_index;
if(fr->stereo==2) {
int jsbound = fr->jsbound;
register real *f0 = fraction[0];
register real *f1 = fraction[1];
ba = balloc;
for (sample=smpb,i=0;i<jsbound;i++) {
if ((n = *ba++))
*sample++ = getbits(ctx,n+1);
if ((n = *ba++))
*sample++ = getbits(ctx,n+1);
}
for (i=jsbound;i<SBLIMIT;i++)
if ((n = *ba++))
*sample++ = getbits(ctx,n+1);
ba = balloc;
for (sample=smpb,i=0;i<jsbound;i++) {
if((n=*ba++))
*f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
else
*f0++ = 0.0;
if((n=*ba++))
*f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
else
*f1++ = 0.0;
}
for (i=jsbound;i<SBLIMIT;i++) {
if ((n=*ba++)) {
real samp = (real)( ((-1)<<n) + (*sample++) + 1);
*f0++ = samp * muls[n+1][*sca++];
*f1++ = samp * muls[n+1][*sca++];
}
else
*f0++ = *f1++ = 0.0;
}
for(i=fr->down_sample_sblimit;i<32;i++)
fraction[0][i] = fraction[1][i] = 0.0;
}
else {
register real *f0 = fraction[0];
ba = balloc;
for (sample=smpb,i=0;i<SBLIMIT;i++)
if ((n = *ba++))
*sample++ = getbits(ctx,n+1);
ba = balloc;
for (sample=smpb,i=0;i<SBLIMIT;i++) {
if((n=*ba++))
*f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
else
*f0++ = 0.0;
}
for(i=fr->down_sample_sblimit;i<32;i++)
fraction[0][i] = 0.0;
}
}
static int do_layer1(mp3lib_ctx *ctx,int single)
{
struct frame *fr=&ctx->fr;
int clip=0;
int i,stereo = fr->stereo;
unsigned int balloc[2*SBLIMIT];
unsigned int scale_index[2][SBLIMIT];
real fraction[2][SBLIMIT];
// int single = fr->single;
// printf("do_layer1(0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X )\n",
// wordpointer[0],wordpointer[1],wordpointer[2],wordpointer[3],wordpointer[4],wordpointer[5],wordpointer[6],wordpointer[7]);
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
(fr->mode_ext<<2)+4 : 32;
if(stereo == 1 || single == 3)
single = 0;
I_step_one(ctx,balloc,scale_index,fr);
for (i=0;i<SCALE_BLOCK;i++)
{
I_step_two(ctx,fraction,balloc,scale_index,fr);
if(single >= 0)
{
clip += (fr->synth_mono)( ctx,(real *) fraction[single],ctx->pcm_sample,&ctx->pcm_point);
}
else {
int p1 = ctx->pcm_point;
clip += (fr->synth)( ctx,(real *) fraction[0],0,ctx->pcm_sample,&p1);
clip += (fr->synth)( ctx,(real *) fraction[1],1,ctx->pcm_sample,&ctx->pcm_point);
}
}
return clip;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?