📄 syntax.c
字号:
g->sect[i].sect_start = k; g->sect[i].sect_end = k + sect_len;#if 0 printf("%d\n", ics->group[g].sect[i].sect_start);#endif#if 0 printf("%d\n", ics->group[g].sect[i].sect_end);#endif if (k + sect_len > MAX_SFB) return 15; if (i > MAX_SFB) return 15; for (sfb = k; sfb < k + sect_len; sfb++) { g->sfb[sfb].sfb_cb = g->sect[i].sect_cb;#if 0 printf("%d\n", g->sfb[sfb].sfb_cb);#endif }#if 0 printf(" %6d %6d %6d\n", i, g->sect[i].sect_end, g->sect[i].sect_cb);#endif k += sect_len; i++; } g->num_sec = i;#if 0 printf("%d\n", ics->group[g].num_sec);#endif }#if 0 printf("\n");#endif return 0;}/* * decode_scale_factors() * decodes the scalefactors from the bitstream *//* * All scalefactors (and also the stereo positions and pns energies) are * transmitted using Huffman coded DPCM relative to the previous active * scalefactor (respectively previous stereo position or previous pns energy, * see subclause 4.6.2 and 4.6.3). The first active scalefactor is * differentially coded relative to the global gain. */static uint8_t decode_scale_factors(ic_stream *ics, bitfile *ld){ uint8_t sfb; int16_t t; int8_t noise_pcm_flag = 1; int16_t scale_factor = ics->global_gain; int16_t is_position = 0; int16_t noise_energy = ics->global_gain - 90;
ic_group *g; for (g = ics->group; g != ics->group_end; g++) { for (sfb = 0; sfb < ics->max_sfb; sfb++) { switch (g->sfb[sfb].sfb_cb) { case ZERO_HCB: /* zero book */ g->sfb[sfb].scale_factors = 0;//#define SF_PRINT#ifdef SF_PRINT printf("%d\n", g->sfb[sfb].scale_factors);#endif break; case INTENSITY_HCB: /* intensity books */ case INTENSITY_HCB2: /* decode intensity position */ t = huffman_scale_factor(ld); is_position += (t - 60); g->sfb[sfb].scale_factors = is_position;#ifdef SF_PRINT printf("%d\n", g->sfb[sfb].scale_factors);#endif break; case NOISE_HCB: /* noise books */ /* decode noise energy */ if (noise_pcm_flag) { noise_pcm_flag = 0; t = (int16_t)faad_getbits(ld, 9 DEBUGVAR(1,73,"scale_factor_data(): first noise")) - 256; } else { t = huffman_scale_factor(ld); t -= 60; } noise_energy += t; g->sfb[sfb].scale_factors = noise_energy;#ifdef SF_PRINT printf("%d\n", g->sfb[sfb].scale_factors);#endif break; default: /* spectral books */ /* ics->scale_factors[g][sfb] must be between 0 and 255 */ g->sfb[sfb].scale_factors = 0; /* decode scale factor */ t = huffman_scale_factor(ld); scale_factor += (t - 60); if (scale_factor < 0 || scale_factor > 255) return 4; g->sfb[sfb].scale_factors = scale_factor;#ifdef SF_PRINT printf("%d\n", g->sfb[sfb].scale_factors);#endif break; } } } return 0;}/* Table 4.4.26 */static uint8_t scale_factor_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld){ uint8_t ret = 0;#ifdef PROFILE int64_t count = faad_get_ts();#endif#ifdef ERROR_RESILIENCE if (!hDecoder->aacScalefactorDataResilienceFlag) {#endif ret = decode_scale_factors(ics, ld);#ifdef ERROR_RESILIENCE } else { /* In ER AAC the parameters for RVLC are seperated from the actual data that holds the scale_factors. Strangely enough, 2 parameters for HCR are put inbetween them. */ ret = rvlc_scale_factor_data(ics, ld); }#endif#ifdef PROFILE count = faad_get_ts() - count; hDecoder->scalefac_cycles += count;#endif return ret;}/* Table 4.4.27 */static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld){ uint8_t w, filt, i, start_coef_bits, coef_bits; uint8_t n_filt_bits = 2; uint8_t length_bits = 6; uint8_t order_bits = 5; if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) { n_filt_bits = 1; length_bits = 4; order_bits = 3; } for (w = 0; w < ics->num_windows; w++) { tns->n_filt[w] = (uint8_t)faad_getbits(ld, n_filt_bits DEBUGVAR(1,74,"tns_data(): n_filt"));#if 0 printf("%d\n", tns->n_filt[w]);#endif if (tns->n_filt[w]) { if ((tns->coef_res[w] = faad_get1bit(ld DEBUGVAR(1,75,"tns_data(): coef_res"))) & 1) { start_coef_bits = 4; } else { start_coef_bits = 3; }#if 0 printf("%d\n", tns->coef_res[w]);#endif } for (filt = 0; filt < tns->n_filt[w]; filt++) { tns->length[w][filt] = (uint8_t)faad_getbits(ld, length_bits DEBUGVAR(1,76,"tns_data(): length"));#if 0 printf("%d\n", tns->length[w][filt]);#endif tns->order[w][filt] = (uint8_t)faad_getbits(ld, order_bits DEBUGVAR(1,77,"tns_data(): order"));#if 0 printf("%d\n", tns->order[w][filt]);#endif if (tns->order[w][filt]) { tns->direction[w][filt] = faad_get1bit(ld DEBUGVAR(1,78,"tns_data(): direction"));#if 0 printf("%d\n", tns->direction[w][filt]);#endif tns->coef_compress[w][filt] = faad_get1bit(ld DEBUGVAR(1,79,"tns_data(): coef_compress"));#if 0 printf("%d\n", tns->coef_compress[w][filt]);#endif coef_bits = start_coef_bits - tns->coef_compress[w][filt]; for (i = 0; i < tns->order[w][filt]; i++) { tns->coef[w][filt][i] = (uint8_t)faad_getbits(ld, coef_bits DEBUGVAR(1,80,"tns_data(): coef"));#if 0 printf("%d\n", tns->coef[w][filt][i]);#endif } } } }}#ifdef LTP_DEC/* Table 4.4.28 */static uint8_t ltp_data(NeAACDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld){ uint8_t sfb, w; ltp->lag = 0;#ifdef LD_DEC if (hDecoder->object_type == LD) { ltp->lag_update = (uint8_t)faad_getbits(ld, 1 DEBUGVAR(1,142,"ltp_data(): lag_update")); if (ltp->lag_update) { ltp->lag = (uint16_t)faad_getbits(ld, 10 DEBUGVAR(1,81,"ltp_data(): lag")); } } else {#endif ltp->lag = (uint16_t)faad_getbits(ld, 11 DEBUGVAR(1,81,"ltp_data(): lag"));#ifdef LD_DEC }#endif /* Check length of lag */ if (ltp->lag > (hDecoder->frameLength << 1)) return 18; ltp->coef = (uint8_t)faad_getbits(ld, 3 DEBUGVAR(1,82,"ltp_data(): coef")); if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) { for (w = 0; w < ics->num_windows; w++) { if ((ltp->short_used[w] = faad_get1bit(ld DEBUGVAR(1,83,"ltp_data(): short_used"))) & 1) { ltp->short_lag_present[w] = faad_get1bit(ld DEBUGVAR(1,84,"ltp_data(): short_lag_present")); if (ltp->short_lag_present[w]) { ltp->short_lag[w] = (uint8_t)faad_getbits(ld, 4 DEBUGVAR(1,85,"ltp_data(): short_lag")); } } } } else { ltp->last_band = (ics->max_sfb < MAX_LTP_SFB ? ics->max_sfb : MAX_LTP_SFB); for (sfb = 0; sfb < ltp->last_band; sfb++) { ltp->long_used[sfb] = faad_get1bit(ld DEBUGVAR(1,86,"ltp_data(): long_used")); } } return 0;}#endif
static uint8_t fillzero(bitfile *ld, int16_t *sp, int16_t *spe)
{
for (;sp!=spe;++sp)
*sp = 0;
return 0;
}
static huffmanfunc const huffman[16] =
{
fillzero,
huffman_spectral_data1,
huffman_spectral_data2,
huffman_spectral_data3,
huffman_spectral_data4,
huffman_spectral_data5,
huffman_spectral_data6,
huffman_spectral_data7,
huffman_spectral_data8,
huffman_spectral_data9,
huffman_spectral_data10,
huffman_spectral_data11,
huffman_spectral_data12,
fillzero,
fillzero,
fillzero,
};
/* Table 4.4.29 */static uint8_t spectral_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld, int16_t *spectral_data){ ic_group *g; uint16_t inc, k, p = 0; uint8_t groups = 0; uint8_t sect_cb; uint8_t result; uint16_t nshort = hDecoder->frameLength/8;
int16_t *data1 = spectral_data;
#ifdef PROFILE int64_t count = faad_get_ts();#endif
for(g = ics->group; g != ics->group_end; g++) {
ic_group_sect *i,*ie = g->sect+g->num_sec;
int16_t *data2 = data1;
for (i = g->sect; i != ie; i++) {
int16_t *data3 = data2 + (g->sfb[i->sect_end].sect_sfb_offset - g->sfb[i->sect_start].sect_sfb_offset);
if (data3 < data2)
return 1;
if (i->sect_cb < 16)
result = huffman[i->sect_cb](ld, data2, data3);
else
result = huffman_spectral_data(i->sect_cb, ld, data2, data3 );
if (result > 0)
return result;
data2 = data3;
}
data1 += g->window_group_length*nshort;
while (data2<data1)
*(data2++) = 0;
data1 = data2;
}#ifdef PROFILE count = faad_get_ts() - count; hDecoder->spectral_cycles += count;#endif
spectral_data += 1024;
while (data1<spectral_data)
*(data1++) = 0;
return 0;}/* Table 4.4.30 */static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count){ uint16_t i, n, dataElementLength; uint8_t dataElementLengthPart; uint8_t align = 4, data_element_version, loopCounter; uint8_t extension_type = (uint8_t)faad_getbits(ld, 4 DEBUGVAR(1,87,"extension_payload(): extension_type")); switch (extension_type) { case EXT_DYNAMIC_RANGE: drc->present = 1; n = dynamic_range_info(ld, drc); return n; case EXT_FILL_DATA: /* fill_nibble = */ faad_getbits(ld, 4 DEBUGVAR(1,136,"extension_payload(): fill_nibble")); /* must be
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -