static uint8_t inverse_quantization(real_t *x_invquant, const int16_t *x_quant, const uint16_t frame_len) { int16_t i; uint8_t error = 0; /* Init error flag */ const real_t *tab = iq_table; for (i = 0; i < frame_len; i+=4) { x_invquant[i] = iquant(x_quant[i], tab, &error); x_invquant[i+1] = iquant(x_quant[i+1], tab, &error); x_invquant[i+2] = iquant(x_quant[i+2], tab, &error); x_invquant[i+3] = iquant(x_quant[i+3], tab, &error); } return error; }
static uint8_t quant_to_spec(NeAACDecHandle hDecoder, ic_stream *ics, int16_t *quant_data, real_t *spec_data, uint16_t frame_len) { const real_t *tab = iq_table; (void)frame_len; uint8_t g, sfb, win; uint16_t width, bin, k, gindex, wa, wb; uint8_t error = 0; /* Init error flag */ real_t scf; k = 0; gindex = 0; for (g = 0; g < ics->num_window_groups; g++) { uint16_t j = 0; uint16_t gincrease = 0; uint16_t win_inc = ics->swb_offset[ics->num_swb]; for (sfb = 0; sfb < ics->num_swb; sfb++) { int32_t exp, frac; width = ics->swb_offset[sfb+1] - ics->swb_offset[sfb]; /* this could be scalefactor for IS or PNS, those can be negative or bigger then 255 */ /* just ignore them */ if (ics->scale_factors[g][sfb] < 0 || ics->scale_factors[g][sfb] > 255) { exp = 0; frac = 0; } else { /* ics->scale_factors[g][sfb] must be between 0 and 255 */ exp = (ics->scale_factors[g][sfb] /* - 100 */) >> 2; /* frac must always be > 0 */ frac = (ics->scale_factors[g][sfb] /* - 100 */) & 3; } #ifdef FIXED_POINT exp -= 25; /* IMDCT pre-scaling */ if (hDecoder->object_type == LD) { exp -= 6 /*9*/; } else { if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) exp -= 4 /*7*/; else exp -= 7 /*10*/; } #endif wa = gindex + j; #ifndef FIXED_POINT scf = pow2sf_tab[exp/*+25*/] * pow2_table[frac]; #else scf = pow2_table[frac]; #endif for (win = 0; win < ics->window_group_length[g]; win++) { for (bin = 0; bin < width; bin += 4) { #ifndef FIXED_POINT wb = wa + bin; spec_data[wb+0] = iquant(quant_data[k+0], tab, &error) * scf; spec_data[wb+1] = iquant(quant_data[k+1], tab, &error) * scf; spec_data[wb+2] = iquant(quant_data[k+2], tab, &error) * scf; spec_data[wb+3] = iquant(quant_data[k+3], tab, &error) * scf; #else wb = wa + bin; if (exp>=0) { spec_data[wb+0] = MUL_C((iquant(quant_data[k+0], tab, &error)<< exp), scf); spec_data[wb+1] = MUL_C((iquant(quant_data[k+1], tab, &error)<< exp), scf); spec_data[wb+2] = MUL_C((iquant(quant_data[k+2], tab, &error)<< exp), scf); spec_data[wb+3] = MUL_C((iquant(quant_data[k+3], tab, &error)<< exp), scf); } else { spec_data[wb+0] = MUL_C((iquant(quant_data[k+0], tab, &error)>>-exp), scf); spec_data[wb+1] = MUL_C((iquant(quant_data[k+1], tab, &error)>>-exp), scf); spec_data[wb+2] = MUL_C((iquant(quant_data[k+2], tab, &error)>>-exp), scf); spec_data[wb+3] = MUL_C((iquant(quant_data[k+3], tab, &error)>>-exp), scf); } //#define SCFS_PRINT #ifdef SCFS_PRINT printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+0]); printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+1]); printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+2]); printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+3]); //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+0]); //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+1]); //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+2]); //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+3]); #endif #endif gincrease += 4; k += 4; } wa += win_inc; } j += width; } gindex += gincrease; } return error; }
/* For ONLY_LONG_SEQUENCE windows (num_window_groups = 1, window_group_length[0] = 1) the spectral data is in ascending spectral order. For the EIGHT_SHORT_SEQUENCE window, the spectral order depends on the grouping in the following manner: - Groups are ordered sequentially - Within a group, a scalefactor band consists of the spectral data of all grouped SHORT_WINDOWs for the associated scalefactor window band. To clarify via example, the length of a group is in the range of one to eight SHORT_WINDOWs. - If there are eight groups each with length one (num_window_groups = 8, window_group_length[0..7] = 1), the result is a sequence of eight spectra, each in ascending spectral order. - If there is only one group with length eight (num_window_groups = 1, window_group_length[0] = 8), the result is that spectral data of all eight SHORT_WINDOWs is interleaved by scalefactor window bands. - Within a scalefactor window band, the coefficients are in ascending spectral order. */ static uint8_t quant_to_spec(NeAACDecHandle hDecoder, ic_stream *ics, int16_t *quant_data, real_t *spec_data, uint16_t frame_len) { ALIGN static const real_t pow2_table[] = { COEF_CONST(1.0), COEF_CONST(1.1892071150027210667174999705605), /* 2^0.25 */ COEF_CONST(1.4142135623730950488016887242097), /* 2^0.5 */ COEF_CONST(1.6817928305074290860622509524664) /* 2^0.75 */ }; const real_t *tab = iq_table; uint8_t g, sfb, win; uint16_t width, bin, k, gindex, wa, wb; uint8_t error = 0; /* Init error flag */ #ifndef FIXED_POINT real_t scf; #endif k = 0; gindex = 0; for (g = 0; g < ics->num_window_groups; g++) { uint16_t j = 0; uint16_t gincrease = 0; uint16_t win_inc = ics->swb_offset[ics->num_swb]; for (sfb = 0; sfb < ics->num_swb; sfb++) { int32_t exp, frac; width = ics->swb_offset[sfb+1] - ics->swb_offset[sfb]; /* this could be scalefactor for IS or PNS, those can be negative or bigger then 255 */ /* just ignore them */ if (ics->scale_factors[g][sfb] < 0 || ics->scale_factors[g][sfb] > 255) { exp = 0; frac = 0; } else { /* ics->scale_factors[g][sfb] must be between 0 and 255 */ exp = (ics->scale_factors[g][sfb] /* - 100 */) >> 2; /* frac must always be > 0 */ frac = (ics->scale_factors[g][sfb] /* - 100 */) & 3; } #ifdef FIXED_POINT exp -= 25; /* IMDCT pre-scaling */ if (hDecoder->object_type == LD) { exp -= 6 /*9*/; } else { if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) exp -= 4 /*7*/; else exp -= 7 /*10*/; } #endif wa = gindex + j; #ifndef FIXED_POINT scf = pow2sf_tab[exp/*+25*/] * pow2_table[frac]; #endif for (win = 0; win < ics->window_group_length[g]; win++) { for (bin = 0; bin < width; bin += 4) { #ifndef FIXED_POINT wb = wa + bin; spec_data[wb+0] = iquant(quant_data[k+0], tab, &error) * scf; spec_data[wb+1] = iquant(quant_data[k+1], tab, &error) * scf; spec_data[wb+2] = iquant(quant_data[k+2], tab, &error) * scf; spec_data[wb+3] = iquant(quant_data[k+3], tab, &error) * scf; #else real_t iq0 = iquant(quant_data[k+0], tab, &error); real_t iq1 = iquant(quant_data[k+1], tab, &error); real_t iq2 = iquant(quant_data[k+2], tab, &error); real_t iq3 = iquant(quant_data[k+3], tab, &error); wb = wa + bin; if (exp < 0) { spec_data[wb+0] = iq0 >>= -exp; spec_data[wb+1] = iq1 >>= -exp; spec_data[wb+2] = iq2 >>= -exp; spec_data[wb+3] = iq3 >>= -exp; } else { spec_data[wb+0] = iq0 <<= exp; spec_data[wb+1] = iq1 <<= exp; spec_data[wb+2] = iq2 <<= exp; spec_data[wb+3] = iq3 <<= exp; } if (frac != 0) { spec_data[wb+0] = MUL_C(spec_data[wb+0],pow2_table[frac]); spec_data[wb+1] = MUL_C(spec_data[wb+1],pow2_table[frac]); spec_data[wb+2] = MUL_C(spec_data[wb+2],pow2_table[frac]); spec_data[wb+3] = MUL_C(spec_data[wb+3],pow2_table[frac]); } //#define SCFS_PRINT #ifdef SCFS_PRINT printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+0]); printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+1]); printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+2]); printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+3]); //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+0]); //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+1]); //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+2]); //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+3]); #endif #endif gincrease += 4; k += 4; } wa += win_inc; } j += width; }
int blockIntra(bitstream *bs, mp4_private_t *priv, int block_num, int coded) { int i; int dct_dc_size, dct_dc_diff; event_t event; vop_header_t *h = &priv->vop_header; //clearblock(ld->block); // clearblock // dc coeff setDCscaler(priv, block_num); // calculate DC scaler if (block_num < 4) { dct_dc_size = getDCsizeLum(bs); if (dct_dc_size != 0) dct_dc_diff = getDCdiff(bs, dct_dc_size); else dct_dc_diff = 0; if (dct_dc_size > 8) get_bits(bs, 1); // marker bit } else { dct_dc_size = getDCsizeChr(bs); if (dct_dc_size != 0) dct_dc_diff = getDCdiff(bs, dct_dc_size); else dct_dc_diff = 0; if (dct_dc_size > 8) get_bits(bs, 1); // marker bit } //ld->block[0] = (short) dct_dc_diff; // dc reconstruction, prediction direction //dc_recon(block_num, &ld->block[0]); if (coded) { #if 0 unsigned int * zigzag; // zigzag scan dir if (h->ac_pred_flag == 1) { if (priv->coeff_pred.predict_dir == TOP) zigzag = priv->tables.alternate_horizontal_scan; else zigzag = priv->tables.alternate_vertical_scan; } else { zigzag = priv->tables.zig_zag_scan; } #endif i = 1; do // event vld { event = vld_intra_dct(bs, priv); /*** if (event.run == -1) { printf("Error: invalid vld code\n"); exit(201); } ***/ i+= event.run; //ld->block[zigzag[i]] = (short) event.level; // _Print("Vld Event: Run Level Last %d %d %d\n", event.run, event.level, event.last); i++; } while (! event.last); } #if 0 // ac reconstruction h->intrablock_rescaled = ac_rescaling(block_num, &ld->block[0]); if (! h->intrablock_rescaled) { ac_recon(block_num, &ld->block[0]); } ac_store(block_num, &ld->block[0]); if (h->quant_type == 0) { iquant(ld->block, 1); } else { iquant_typefirst(ld->block); } // inverse dct idct(ld->block); #endif return 1; }