00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #define MIN(x, y) ((x) > (y) ? (y) : (x))
00025
00026 #include "mpeg3audio.h"
00027 #include <stdio.h>
00028
00029
00030 #define UNPACK_FBW 1
00031 #define UNPACK_CPL 2
00032 #define UNPACK_LFE 4
00033
00034 static inline int mpeg3audio_ac3_exp_unpack_ch(unsigned int type,
00035 unsigned int expstr,
00036 unsigned int ngrps,
00037 unsigned int initial_exp,
00038 unsigned short exps[],
00039 unsigned short *dest)
00040 {
00041 int i, j;
00042 int exp_acc;
00043 int exp_1, exp_2, exp_3;
00044
00045 if(expstr == MPEG3_EXP_REUSE)
00046 return 0;
00047
00048
00049 exp_acc = initial_exp;
00050 j = 0;
00051
00052
00053
00054 if(type != UNPACK_CPL)
00055 dest[j++] = exp_acc;
00056
00057
00058 for(i = 0; i < ngrps; i++)
00059 {
00060 if(exps[i] > 124)
00061 {
00062
00063 return 1;
00064 }
00065
00066 exp_1 = exps[i] / 25;
00067 exp_2 = (exps[i] % 25) / 5;
00068 exp_3 = (exps[i] % 25) % 5;
00069
00070 exp_acc += (exp_1 - 2);
00071
00072 switch(expstr)
00073 {
00074 case MPEG3_EXP_D45:
00075 j = MIN(255, j);
00076 dest[j++] = exp_acc;
00077 j = MIN(255, j);
00078 dest[j++] = exp_acc;
00079 case MPEG3_EXP_D25:
00080 j = MIN(255, j);
00081 dest[j++] = exp_acc;
00082 case MPEG3_EXP_D15:
00083 j = MIN(255, j);
00084 dest[j++] = exp_acc;
00085 }
00086
00087 exp_acc += (exp_2 - 2);
00088
00089 switch(expstr)
00090 {
00091 case MPEG3_EXP_D45:
00092 j = MIN(255, j);
00093 dest[j++] = exp_acc;
00094 j = MIN(255, j);
00095 dest[j++] = exp_acc;
00096 case MPEG3_EXP_D25:
00097 j = MIN(255, j);
00098 dest[j++] = exp_acc;
00099 case MPEG3_EXP_D15:
00100 j = MIN(255, j);
00101 dest[j++] = exp_acc;
00102 }
00103
00104 exp_acc += (exp_3 - 2);
00105
00106 switch(expstr)
00107 {
00108 case MPEG3_EXP_D45:
00109 j = MIN(255, j);
00110 dest[j++] = exp_acc;
00111 j = MIN(255, j);
00112 dest[j++] = exp_acc;
00113 case MPEG3_EXP_D25:
00114 j = MIN(255, j);
00115 dest[j++] = exp_acc;
00116 case MPEG3_EXP_D15:
00117 j = MIN(255, j);
00118 dest[j++] = exp_acc;
00119 }
00120 }
00121 return 0;
00122 }
00123
00124 int mpeg3audio_ac3_exponent_unpack(mpeg3audio_t *audio,
00125 mpeg3_ac3bsi_t *bsi,
00126 mpeg3_ac3audblk_t *audblk)
00127 {
00128 int i, result = 0;
00129
00130 for(i = 0; i < bsi->nfchans; i++)
00131 result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_FBW,
00132 audblk->chexpstr[i],
00133 audblk->nchgrps[i],
00134 audblk->exps[i][0],
00135 &audblk->exps[i][1],
00136 audblk->fbw_exp[i]);
00137
00138 if(audblk->cplinu && !result)
00139 result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_CPL,
00140 audblk->cplexpstr,
00141 audblk->ncplgrps,
00142 audblk->cplabsexp << 1,
00143 audblk->cplexps,
00144 &audblk->cpl_exp[audblk->cplstrtmant]);
00145
00146 if(bsi->lfeon && !result)
00147 result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_LFE,
00148 audblk->lfeexpstr,
00149 2,
00150 audblk->lfeexps[0],
00151 &audblk->lfeexps[1],
00152 audblk->lfe_exp);
00153 return result;
00154 }