void mpeg3audio_ac3_ba_compute_psd(int start, int end, short exps[], short psd[], short bndpsd[]) { int bin,i,j,k; int lastbin = 0; /* Map the exponents into dBs */ for (bin = start; bin < end; bin++) { psd[bin] = (3072 - (exps[bin] << 7)); } /* Integrate the psd function over each bit allocation band */ j = start; k = mpeg3_masktab[start]; do { lastbin = mpeg3_min(mpeg3_bndtab[k] + mpeg3_bndsz[k], end); bndpsd[k] = psd[j]; j++; for(i = j; i < lastbin; i++) { bndpsd[k] = logadd(bndpsd[k], psd[j]); j++; } k++; }while(end > lastbin); }
/* This routine simply does stereo rematrixing for the 2 channel * stereo mode */ int mpeg3audio_ac3_rematrix(mpeg3_ac3audblk_t *audblk, mpeg3ac3_stream_samples_t samples) { int num_bands; int start; int end; int i, j; float left, right; if(audblk->cplinu || audblk->cplbegf > 2) num_bands = 4; else if (audblk->cplbegf > 0) num_bands = 3; else num_bands = 2; for(i = 0; i < num_bands; i++) { if(!audblk->rematflg[i]) continue; start = mpeg3_rematrix_band[i].start; end = mpeg3_min(mpeg3_rematrix_band[i].end, 12 * audblk->cplbegf + 36); for(j = start; j < end; j++) { left = samples[0][j] + samples[1][j]; right = samples[0][j] - samples[1][j]; samples[0][j] = left; samples[1][j] = right; } } return 0; }
void mpeg3audio_ac3_ba_compute_excitation(mpeg3audio_t *audio, int start, int end, int fgain, int fastleak, int slowleak, int is_lfe, short bndpsd[], short excite[]) { int bin; int bndstrt; int bndend; int lowcomp = 0; int begin = 0; /* Compute excitation function */ bndstrt = mpeg3_masktab[start]; bndend = mpeg3_masktab[end - 1] + 1; if(bndstrt == 0) /* For fbw and lfe channels */ { lowcomp = mpeg3audio_ac3_calc_lowcomp(lowcomp, bndpsd[0], bndpsd[1], 0); excite[0] = bndpsd[0] - fgain - lowcomp; lowcomp = mpeg3audio_ac3_calc_lowcomp(lowcomp, bndpsd[1], bndpsd[2], 1); excite[1] = bndpsd[1] - fgain - lowcomp; begin = 7 ; /* Note: Do not call mpeg3audio_ac3_calc_lowcomp() for the last band of the lfe channel, (bin = 6) */ for (bin = 2; bin < 7; bin++) { if(!(is_lfe && (bin == 6))) lowcomp = mpeg3audio_ac3_calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin); fastleak = bndpsd[bin] - fgain; slowleak = bndpsd[bin] - audio->ac3_bit_allocation.sgain; excite[bin] = fastleak - lowcomp; if(!(is_lfe && (bin == 6))) { if(bndpsd[bin] <= bndpsd[bin+1]) { begin = bin + 1 ; break; } } } for (bin = begin; bin < mpeg3_min(bndend, 22); bin++) { if (!(is_lfe && (bin == 6))) lowcomp = mpeg3audio_ac3_calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin); fastleak -= audio->ac3_bit_allocation.fdecay; fastleak = mpeg3_max(fastleak, bndpsd[bin] - fgain); slowleak -= audio->ac3_bit_allocation.sdecay; slowleak = mpeg3_max(slowleak, bndpsd[bin] - audio->ac3_bit_allocation.sgain); excite[bin] = mpeg3_max(fastleak - lowcomp, slowleak); } begin = 22; } else /* For coupling channel */ { begin = bndstrt; } for (bin = begin; bin < bndend; bin++) { fastleak -= audio->ac3_bit_allocation.fdecay; fastleak = mpeg3_max(fastleak, bndpsd[bin] - fgain); slowleak -= audio->ac3_bit_allocation.sdecay; slowleak = mpeg3_max(slowleak, bndpsd[bin] - audio->ac3_bit_allocation.sgain); excite[bin] = mpeg3_max(fastleak, slowleak) ; } }