QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 945|回复: 4

【求助】一个mpg123的解码程序,高手帮忙看看。

[复制链接]
发表于 2004-5-16 18:29:21 | 显示全部楼层 |阅读模式
最近需要分析xmms的源代码,在输入中有mpg123的信号。下面是解码程序。
/*
* Mpeg Layer-1,2,3 audio decoder /*请问Mpeg Layer-1,2,3具体是什么含义?*/
* ------------------------------
* copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
* See also 'README'
*
*/

#include <stdlib.h>
#include <math.h>
#include <string.h>

#include "mpg123.h"

#define WRITE_SAMPLE(samples,sum,clip) \
if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
else { *(samples) = sum; }

/*下面分别定义了几个函数*/
int mpg123_synth_1to1_8bit(real * bandPtr, int channel, unsigned char *samples, int *pnt)
{
short samples_tmp[64];
short *tmp1 = samples_tmp + channel;
int i, ret;
int pnt1 = 0;

ret = mpg123_synth_1to1(bandPtr, channel, (unsigned char *) samples_tmp, &pnt1);
samples += channel + *pnt;

for (i = 0; i < 32; i++)
{
*samples = (*tmp1 >>  ^ 128;
samples += 2;
tmp1 += 2;
}
*pnt += 64;

return ret;
}

int mpg123_synth_1to1_8bit_mono(real * bandPtr, unsigned char *samples, int *pnt)
{
short samples_tmp[64];
short *tmp1 = samples_tmp;
int i, ret;
int pnt1 = 0;

ret = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1);
samples += *pnt;

for (i = 0; i < 32; i++)
{
*samples++ = (*tmp1 >>  ^ 128;
tmp1 += 2;
}
*pnt += 32;

return ret;
}

#if 0
int mpg123_synth_1to1_8bit_mono2stereo(real * bandPtr, unsigned char *samples, int *pnt)
{
short samples_tmp[64];
short *tmp1 = samples_tmp;
int i, ret;
int pnt1 = 0;

ret = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1);
samples += *pnt;

for (i = 0; i < 32; i++)
{
*samples++ = (*tmp1 >>  ^ 128;
*samples++ = (*tmp1 >>  ^ 128;
tmp1 += 2;
}
*pnt += 64;

return ret;
}
#endif

int mpg123_synth_1to1_mono(real * bandPtr, unsigned char *samples, int *pnt)
{
short samples_tmp[64];
short *tmp1 = samples_tmp;
int i, ret;
int pnt1 = 0;

ret = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1);
samples += *pnt;

for (i = 0; i < 32; i++)
{
*((short *) samples) = *tmp1;
samples += 2;
tmp1 += 2;
}
*pnt += 64;

return ret;
}

#if 0
int mpg123_synth_1to1_mono2stereo(real * bandPtr, unsigned char *samples, int *pnt)
{
int i, ret;

ret = mpg123_synth_1to1(bandPtr, 0, samples, pnt);
samples = samples + *pnt - 128;

for (i = 0; i < 32; i++)
{
((short *) samples)[1] = ((short *) samples)[0];
samples += 4;
}

return ret;
}
#endif


/*上面的几个函数中都调用了下面的这个函数*/
int mpg123_synth_1to1(real * bandPtr, int channel, unsigned char *out, int *pnt)
{
static real buffs[2][2][0x110];
static const int step = 2;
static int bo = 1;
short *samples = (short *) (out + *pnt);

real *b0, (*buf)[0x110];
int clip = 0;
int bo1;
int i = 0;

/* if(param.equalizer)
do_equalizer(bandPtr,channel); */

if (!channel)
{
bo--;
bo &= 0xf;
buf = buffs[0];
}
else
{
samples++;
buf = buffs[1];
}

if (bo & 0x1)
{
b0 = buf[0];
bo1 = bo;
mpg123_dct64(buf[1] + ((bo + 1) & 0xf), buf[0] + bo, bandPtr);
}
else
{
b0 = buf[1];
bo1 = bo + 1;
mpg123_dct64(buf[0] + bo, buf[1] + bo + 1, bandPtr);
}

{
register int j;
real *window = mpg123_decwin + 16 - bo1;

for (j = 16; j; j--, window += 0x10, samples += step)
{
real sum;

sum = *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
i++;
WRITE_SAMPLE(samples, sum, clip);
}

{
real sum;

sum = window[0x0] * b0[0x0];
sum += window[0x2] * b0[0x2];
sum += window[0x4] * b0[0x4];
sum += window[0x6] * b0[0x6];
sum += window[0x8] * b0[0x8];
sum += window[0xA] * b0[0xA];
sum += window[0xC] * b0[0xC];
sum += window[0xE] * b0[0xE];
WRITE_SAMPLE(samples, sum, clip);

b0 -= 0x10, window -= 0x20, samples += step;
}
window += bo1 << 1;

for (j = 15; j; j--, b0 -= 0x20, window -= 0x10, samples += step)
{
real sum;

sum = -*(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
WRITE_SAMPLE(samples, sum, clip);
}
}

*pnt += 128;

return clip;
}


请问各位大侠:
1、主要的函数int mpg123_synth_1to1,是怎么实现的?它的实现的思路是什么?
2、int mpg123_synth_1to1_8bit
int mpg123_synth_1to1_8bit_mono
int mpg123_synth_1to1_8bit_mono2stereo
int mpg123_synth_1to1_mono
int mpg123_synth_1to1_mono
int mpg123_synth_1to1_mono2stereo
这几个函数名分别是什么含义?即他们各实现的是什么功能?

希望各位大侠帮忙!!!
发表于 2004-5-16 20:45:34 | 显示全部楼层
。。。。查看相关源代码
回复

使用道具 举报

 楼主| 发表于 2004-5-16 23:10:39 | 显示全部楼层
[quote:6d1ebe3b1c="默难"]。。。。查看相关源代码[/quote]
我发的就是源代码啊。
就是看不懂它是怎么实现的。
回复

使用道具 举报

发表于 2004-5-17 09:42:08 | 显示全部楼层
咋没个注释啊
回复

使用道具 举报

 楼主| 发表于 2004-5-17 22:34:47 | 显示全部楼层
[quote:325b86e5e7="_z_"]咋没个注释啊 [/quote]
我看不懂,所以没有注释,哈。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-8 08:52 , Processed in 0.060184 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表