📄 cupl3.c
字号:
nbytes = m->cupl.padframebytes - side_bytes - m->cupl.crcbytes;
// RAK: This is no bueno. :-(
if (nbytes < 0 || nbytes > NBUF)
{
in_out.in_bytes = 0;
return in_out;
}
memmove(m->cupl.buf + m->cupl.buf_ptr1, bs + side_bytes + m->cupl.crcbytes, nbytes);
m->cupl.buf_ptr1 += nbytes;
/*-----------------------*/
if (m->cupl.buf_ptr0 >= 0)
{
m->cupl.main_pos_bit = m->cupl.buf_ptr0 << 3;
unpack_main(m,pcm, igr);
in_out.out_bytes = m->cupl.outbytes;
}
else
{
memset(pcm, m->cupl.zero_level_pcm, m->cupl.outbytes); /* fill out skipped frames */
in_out.out_bytes = m->cupl.outbytes;
// iframe--; in_out.out_bytes = 0; return in_out;// test test */
}
igr = igr ^ 1;
return in_out;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
static int const sr_table[8] =
{22050, 24000, 16000, 1,
44100, 48000, 32000, 1};
static const struct
{
int l[23];
int s[14];
}
sfBandIndexTable[3][3] =
{
/* mpeg-2 */
{
{
{
0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
}
,
{
0, 4, 8, 12, 18, 24, 32, 42, 56, 74, 100, 132, 174, 192
}
}
,
{
{
0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232, 278, 332, 394, 464, 540, 576
}
,
{
0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 136, 180, 192
}
}
,
{
{
0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
}
,
{
0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192
}
}
,
}
,
/* mpeg-1 */
{
{
{
0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, 196, 238, 288, 342, 418, 576
}
,
{
0, 4, 8, 12, 16, 22, 30, 40, 52, 66, 84, 106, 136, 192
}
}
,
{
{
0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, 190, 230, 276, 330, 384, 576
}
,
{
0, 4, 8, 12, 16, 22, 28, 38, 50, 64, 80, 100, 126, 192
}
}
,
{
{
0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, 240, 296, 364, 448, 550, 576
}
,
{
0, 4, 8, 12, 16, 22, 30, 42, 58, 78, 104, 138, 180, 192
}
}
}
,
/* mpeg-2.5, 11 & 12 KHz seem ok, 8 ok */
{
{
{
0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
}
,
{
0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192
}
}
,
{
{
0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
}
,
{
0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192
}
}
,
// this 8khz table, and only 8khz, from mpeg123)
{
{
0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, 400, 476, 566, 568, 570, 572, 574, 576
}
,
{
0, 8, 16, 24, 36, 52, 72, 96, 124, 160, 162, 164, 166, 192
}
}
,
}
,
};
void sbt_mono_L3(MPEG *m, float *sample, signed short *pcm, int ch);
void sbt_dual_L3(MPEG *m, float *sample, signed short *pcm, int ch);
void sbt16_mono_L3(MPEG *m, float *sample, signed short *pcm, int ch);
void sbt16_dual_L3(MPEG *m, float *sample, signed short *pcm, int ch);
void sbt8_mono_L3(MPEG *m, float *sample, signed short *pcm, int ch);
void sbt8_dual_L3(MPEG *m, float *sample, signed short *pcm, int ch);
void sbtB_mono_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
void sbtB_dual_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
void sbtB16_mono_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
void sbtB16_dual_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
void sbtB8_mono_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
void sbtB8_dual_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
static SBT_FUNCTION_F sbt_table[2][3][2] =
{
{{ (SBT_FUNCTION_F) sbt_mono_L3,
(SBT_FUNCTION_F) sbt_dual_L3 } ,
{ (SBT_FUNCTION_F) sbt16_mono_L3,
(SBT_FUNCTION_F) sbt16_dual_L3 } ,
{ (SBT_FUNCTION_F) sbt8_mono_L3,
(SBT_FUNCTION_F) sbt8_dual_L3 }} ,
/*-- 8 bit output -*/
{{ (SBT_FUNCTION_F) sbtB_mono_L3,
(SBT_FUNCTION_F) sbtB_dual_L3 },
{ (SBT_FUNCTION_F) sbtB16_mono_L3,
(SBT_FUNCTION_F) sbtB16_dual_L3 },
{ (SBT_FUNCTION_F) sbtB8_mono_L3,
(SBT_FUNCTION_F) sbtB8_dual_L3 }}
};
void Xform_mono(void *mv, void *pcm, int igr);
void Xform_dual(void *mv, void *pcm, int igr);
void Xform_dual_mono(void *mv, void *pcm, int igr);
void Xform_dual_right(void *mv, void *pcm, int igr);
static XFORM_FUNCTION xform_table[5] =
{
Xform_mono,
Xform_dual,
Xform_dual_mono,
Xform_mono, /* left */
Xform_dual_right,
};
int L3table_init(MPEG *m);
void msis_init(MPEG *m);
void sbt_init(MPEG *m);
#if 0
typedef int iARRAY22[22];
#endif
iARRAY22 *quant_init_band_addr();
iARRAY22 *msis_init_band_addr();
/*---------------------------------------------------------*/
/* mpeg_head defined in mhead.h frame bytes is without pad */
int L3audio_decode_init(void *mv, MPEG_HEAD * h, int framebytes_arg,
int reduction_code, int transform_code, int convert_code,
int freq_limit)
{
MPEG *m = mv;
int i, j, k;
// static int first_pass = 1;
int samprate;
int limit;
int bit_code;
int out_chans;
m->cupl.buf_ptr0 = 0;
m->cupl.buf_ptr1 = 0;
/* check if code handles */
if (h->option != 1)
return 0; /* layer III only */
if (h->id)
m->cupl.ncbl_mixed = 8; /* mpeg-1 */
else
m->cupl.ncbl_mixed = 6; /* mpeg-2 */
m->cupl.framebytes = framebytes_arg;
transform_code = transform_code; /* not used, asm compatability */
bit_code = 0;
if (convert_code & 8)
bit_code = 1;
convert_code = convert_code & 3; /* higher bits used by dec8 freq cvt */
if (reduction_code < 0)
reduction_code = 0;
if (reduction_code > 2)
reduction_code = 2;
if (freq_limit < 1000)
freq_limit = 1000;
samprate = sr_table[4 * h->id + h->sr_index];
if ((h->sync & 1) == 0)
samprate = samprate / 2; // mpeg 2.5
/*----- compute nsb_limit --------*/
m->cupl.nsb_limit = (freq_limit * 64L + samprate / 2) / samprate;
/*- caller limit -*/
limit = (32 >> reduction_code);
if (limit > 8)
limit--;
if (m->cupl.nsb_limit > limit)
m->cupl.nsb_limit = limit;
limit = 18 * m->cupl.nsb_limit;
k = h->id;
if ((h->sync & 1) == 0)
k = 2; // mpeg 2.5
if (k == 1)
{
m->cupl.band_limit12 = 3 * sfBandIndexTable[k][h->sr_index].s[13];
m->cupl.band_limit = m->cupl.band_limit21 = sfBandIndexTable[k][h->sr_index].l[22];
}
else
{
m->cupl.band_limit12 = 3 * sfBandIndexTable[k][h->sr_index].s[12];
m->cupl.band_limit = m->cupl.band_limit21 = sfBandIndexTable[k][h->sr_index].l[21];
}
m->cupl.band_limit += 8; /* allow for antialias */
if (m->cupl.band_limit > limit)
m->cupl.band_limit = limit;
if (m->cupl.band_limit21 > m->cupl.band_limit)
m->cupl.band_limit21 = m->cupl.band_limit;
if (m->cupl.band_limit12 > m->cupl.band_limit)
m->cupl.band_limit12 = m->cupl.band_limit;
m->cupl.band_limit_nsb = (m->cupl.band_limit + 17) / 18; /* limit nsb's rounded up */
/*----------------------------------------------*/
m->cupl.gain_adjust = 0; /* adjust gain e.g. cvt to mono sum channel */
if ((h->mode != 3) && (convert_code == 1))
m->cupl.gain_adjust = -4;
m->cupl.outvalues = 1152 >> reduction_code;
if (h->id == 0)
m->cupl.outvalues /= 2;
out_chans = 2;
if (h->mode == 3)
out_chans = 1;
if (convert_code)
out_chans = 1;
m->cupl.sbt_L3 = sbt_table[bit_code][reduction_code][out_chans - 1];
k = 1 + convert_code;
if (h->mode == 3)
k = 0;
m->cupl.Xform = xform_table[k];
m->cupl.outvalues *= out_chans;
if (bit_code)
m->cupl.outbytes = m->cupl.outvalues;
else
m->cupl.outbytes = sizeof(short) * m->cupl.outvalues;
if (bit_code)
m->cupl.zero_level_pcm = 128; /* 8 bit output */
else
m->cupl.zero_level_pcm = 0;
m->cup.decinfo.channels = out_chans;
m->cup.decinfo.outvalues = m->cupl.outvalues;
m->cup.decinfo.samprate = samprate >> reduction_code;
if (bit_code)
m->cup.decinfo.bits = 8;
else
m->cup.decinfo.bits = sizeof(short) * 8;
m->cup.decinfo.framebytes = m->cupl.framebytes;
m->cup.decinfo.type = 0;
m->cupl.half_outbytes = m->cupl.outbytes / 2;
/*------------------------------------------*/
/*- init band tables --*/
k = h->id;
if ((h->sync & 1) == 0)
k = 2; // mpeg 2.5
for (i = 0; i < 22; i++)
m->cupl.sfBandIndex[0][i] = sfBandIndexTable[k][h->sr_index].l[i + 1];
for (i = 0; i < 13; i++)
m->cupl.sfBandIndex[1][i] = 3 * sfBandIndexTable[k][h->sr_index].s[i + 1];
for (i = 0; i < 22; i++)
m->cupl.nBand[0][i] =
sfBandIndexTable[k][h->sr_index].l[i + 1]
- sfBandIndexTable[k][h->sr_index].l[i];
for (i = 0; i < 13; i++)
m->cupl.nBand[1][i] =
sfBandIndexTable[k][h->sr_index].s[i + 1]
- sfBandIndexTable[k][h->sr_index].s[i];
/* init tables */
L3table_init(m);
/* init ms and is stereo modes */
msis_init(m);
/*----- init sbt ---*/
sbt_init(m);
/*--- clear buffers --*/
for (i = 0; i < 576; i++)
m->cupl.yout[i] = 0.0f;
for (j = 0; j < 2; j++)
{
for (k = 0; k < 2; k++)
{
for (i = 0; i < 576; i++)
{
m->cupl.sample[j][k][i].x = 0.0f;
m->cupl.sample[j][k][i].s = 0;
}
}
}
if (h->id == 1)
m->cupl.decode_function = L3audio_decode_MPEG1;
else
m->cupl.decode_function = L3audio_decode_MPEG2;
return 1;
}
/*---------------------------------------------------------*/
/*==========================================================*/
void cup3_init(MPEG *m)
{
m->cupl.sbt_L3 = sbt_dual_L3;
m->cupl.Xform = Xform_dual;
m->cupl.sbt_L3 = sbt_dual_L3;
m->cupl.decode_function = L3audio_decode_MPEG1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -