00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "../bitstream.h"
00024 #include "mpeg3audio.h"
00025
00026 static unsigned char mpeg3_first_bit_lut[256] =
00027 {
00028 0, 8, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5,
00029 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
00030 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00031 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00032 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00033 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00034 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00035 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00036 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00037 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00038 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00039 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00040 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00041 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00042 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00043 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
00044 };
00045
00046
00047
00048 static inline void mpeg3audio_ac3_convert_to_float(unsigned short exp,
00049 unsigned short mantissa,
00050 u_int32_t *dest)
00051 {
00052 int num;
00053 short exponent;
00054 int i;
00055
00056
00057 if(mantissa == 0)
00058 {
00059 *dest = 0;
00060 return;
00061 }
00062
00063
00064
00065 exponent = 127 - exp;
00066
00067
00068 if(mantissa == 0x8000)
00069 mantissa++;
00070
00071
00072
00073 if(mantissa & 0x8000)
00074 {
00075 mantissa *= -1;
00076 num = 0x80000000 + (exponent << 23);
00077 }
00078 else
00079 {
00080 mantissa *= 1;
00081 num = exponent << 23;
00082 }
00083
00084
00085 i = mpeg3_first_bit_lut[mantissa >> 8];
00086
00087 if(i == 0)
00088 i = mpeg3_first_bit_lut[mantissa & 0xff] + 8;
00089
00090 *dest = num - (i << 23) + (mantissa << (7 + i));
00091 return;
00092 }
00093
00094
00095 int mpeg3audio_ac3_uncouple(mpeg3audio_t *audio,
00096 mpeg3_ac3bsi_t *bsi,
00097 mpeg3_ac3audblk_t *audblk,
00098 mpeg3_stream_coeffs_t *coeffs)
00099 {
00100 int i, j;
00101
00102 for(i = 0; i < bsi->nfchans; i++)
00103 {
00104 for(j = 0; j < audblk->endmant[i]; j++)
00105 mpeg3audio_ac3_convert_to_float(audblk->fbw_exp[i][j],
00106 audblk->chmant[i][j],
00107 (u_int32_t*)&coeffs->fbw[i][j]);
00108 }
00109
00110 if(audblk->cplinu)
00111 {
00112 for(i = 0; i < bsi->nfchans; i++)
00113 {
00114 if(audblk->chincpl[i])
00115 {
00116 mpeg3audio_ac3_uncouple_channel(audio,
00117 coeffs,
00118 audblk,
00119 i);
00120 }
00121 }
00122
00123 }
00124
00125 if(bsi->lfeon)
00126 {
00127
00128 for(j = 0; j < 7 ; j++)
00129 mpeg3audio_ac3_convert_to_float(audblk->lfe_exp[j],
00130 audblk->lfemant[j],
00131 (u_int32_t*)&coeffs->lfe[j]);
00132
00133 }
00134 return 0;
00135 }