int AACQuantize(CoderInfo *coderInfo, PsyInfo *psyInfo, ChannelInfo *channelInfo, int *cb_width, int num_cb, double *xr, AACQuantCfg *aacquantCfg) { int sb, i, do_q = 0; int bits = 0, sign; double xr_pow[FRAME_LEN]; double xmin[MAX_SCFAC_BANDS]; int xi[FRAME_LEN]; /* Use local copy's */ int *scale_factor = coderInfo->scale_factor; /* Set all scalefactors to 0 */ coderInfo->global_gain = 0; for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) scale_factor[sb] = 0; /* Compute xr_pow */ for (i = 0; i < FRAME_LEN; i++) { double temp = fabs(xr[i]); xr_pow[i] = sqrt(temp * sqrt(temp)); do_q += (temp > 1E-20); } if (do_q) { CalcAllowedDist(coderInfo, psyInfo, xr, xmin, aacquantCfg->quality); coderInfo->global_gain = 0; FixNoise(coderInfo, xr, xr_pow, xi, xmin, aacquantCfg->pow43, aacquantCfg->adj43); BalanceEnergy(coderInfo, xr, xi, aacquantCfg->pow43); UpdateRequant(coderInfo, xi, aacquantCfg->pow43); for ( i = 0; i < FRAME_LEN; i++ ) { sign = (xr[i] < 0) ? -1 : 1; xi[i] *= sign; coderInfo->requantFreq[i] *= sign; } } else { coderInfo->global_gain = 0; SetMemory(xi, 0, FRAME_LEN*sizeof(int)); } BitSearch(coderInfo, xi); /* offset the difference of common_scalefac and scalefactors by SF_OFFSET */ for (i = 0; i < coderInfo->nr_of_sfb; i++) { if ((coderInfo->book_vector[i]!=INTENSITY_HCB)&&(coderInfo->book_vector[i]!=INTENSITY_HCB2)) { scale_factor[i] = coderInfo->global_gain - scale_factor[i] + SF_OFFSET; } } coderInfo->global_gain = scale_factor[0]; #if 0 printf("global gain: %d\n", coderInfo->global_gain); for (i = 0; i < coderInfo->nr_of_sfb; i++) printf("sf %d: %d\n", i, coderInfo->scale_factor[i]); #endif /* place the codewords and their respective lengths in arrays data[] and len[] respectively */ /* there are 'counter' elements in each array, and these are variable length arrays depending on the input */ #ifdef DRM coderInfo->iLenReordSpData = 0; /* init length of reordered spectral data */ coderInfo->iLenLongestCW = 0; /* init length of longest codeword */ coderInfo->cur_cw = 0; /* init codeword counter */ #endif coderInfo->spectral_count = 0; sb = 0; for(i = 0; i < coderInfo->nr_of_sfb; i++) { OutputBits( coderInfo, #ifdef DRM &coderInfo->book_vector[i], /* needed for VCB11 */ #else coderInfo->book_vector[i], #endif xi, coderInfo->sfb_offset[i], coderInfo->sfb_offset[i+1]-coderInfo->sfb_offset[i]); if (coderInfo->book_vector[i]) sb = i; } // FIXME: Check those max_sfb/nr_of_sfb. Isn't it the same? coderInfo->max_sfb = coderInfo->nr_of_sfb = sb + 1; return bits; }
void AACQuantize(CoderInfo *coderInfo, ChannelInfo *channelInfo, int32_t *cb_width, int32_t num_cb, coef_t *xr, pow_t *xr2, AACQuantCfg *aacquantCfg) { register int32_t sb, i; coef_t xr_pow[FRAME_LEN]; real_32_t xmin[MAX_SCFAC_BANDS]; int32_t xi[FRAME_LEN]; int32_t *scale_factor; /* Use local copy's */ scale_factor = coderInfo->scale_factor; /* Set all scalefactors to 0 */ coderInfo->global_gain = 0; for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) scale_factor[sb] = 0; /* Compute xr_pow */ for (i = 0; i < FRAME_LEN; i++) { xr_pow[i] = faac_pow34(xr[i]); #ifdef DUMP_XR_POW printf("xr_pow[%d] = %.8f\n",i,COEF2FLOAT(xr_pow[i])); #endif } #ifdef DUMP_XR_POW // exit(1); #endif CalcAllowedDist(coderInfo, xr2, xmin, aacquantCfg->quality); coderInfo->global_gain = 0; FixNoise(coderInfo, xr_pow, xi, xmin); for ( i = 0; i < FRAME_LEN; i++ ) { if ( xr[i] < 0 ) xi[i] = -xi[i]; } BitSearch(coderInfo, xi); /* offset the difference of common_scalefac and scalefactors by SF_OFFSET */ for (i = 0; i < coderInfo->nr_of_sfb; i++) { if ( (coderInfo->book_vector[i]!=INTENSITY_HCB) && (coderInfo->book_vector[i]!=INTENSITY_HCB2) ) { scale_factor[i] = coderInfo->global_gain - scale_factor[i] + SF_OFFSET; } } coderInfo->global_gain = scale_factor[0]; /* place the codewords and their respective lengths in arrays data[] and len[] respectively */ /* there are 'counter' elements in each array, and these are variable length arrays depending on the input */ coderInfo->spectral_count = 0; sb = 0; for(i = 0; i < coderInfo->nr_of_sfb; i++) { OutputBits( coderInfo, coderInfo->book_vector[i], xi, coderInfo->sfb_offset[i], coderInfo->sfb_offset[i+1]-coderInfo->sfb_offset[i]); if (coderInfo->book_vector[i]) sb = i; } // FIXME: Check those max_sfb/nr_of_sfb. Isn't it the same? coderInfo->max_sfb = coderInfo->nr_of_sfb = sb + 1; }