📄 ps_syntax.c
字号:
{ /*5*/ -26, 10 }, /* index 9: 10 bits: 111111111x */ { /*-5*/ -36, 11 }, /* index 10: 11 bits: 1111111111x */ { /*6*/ -25, 12 }, /* index 11: 12 bits: 11111111111x */ { /*-6*/ -37, 13 }, /* index 12: 13 bits: 111111111111x */ { /*-7*/ -38, /*7*/ -24 } /* index 13: 14 bits: 1111111111111x */};static const int8_t f_huff_ipd[][2] = { { 1, /*0*/ -31 }, /* index 0: 1 bits: x */ { 2, 3 }, /* index 1: 2 bits: 0x */ { /*1*/ -30, 4 }, /* index 2: 3 bits: 00x */ { 5, 6 }, /* index 3: 3 bits: 01x */ { /*4*/ -27, /*5*/ -26 }, /* index 4: 4 bits: 001x */ { /*3*/ -28, /*6*/ -25 }, /* index 5: 4 bits: 010x */ { /*2*/ -29, /*7*/ -24 } /* index 6: 4 bits: 011x */};static const int8_t t_huff_ipd[][2] = { { 1, /*0*/ -31 }, /* index 0: 1 bits: x */ { 2, 3 }, /* index 1: 2 bits: 0x */ { 4, 5 }, /* index 2: 3 bits: 00x */ { /*1*/ -30, /*7*/ -24 }, /* index 3: 3 bits: 01x */ { /*5*/ -26, 6 }, /* index 4: 4 bits: 000x */ { /*2*/ -29, /*6*/ -25 }, /* index 5: 4 bits: 001x */ { /*4*/ -27, /*3*/ -28 } /* index 6: 5 bits: 0001x */};static const int8_t f_huff_opd[][2] = { { 1, /*0*/ -31 }, /* index 0: 1 bits: x */ { 2, 3 }, /* index 1: 2 bits: 0x */ { /*7*/ -24, /*1*/ -30 }, /* index 2: 3 bits: 00x */ { 4, 5 }, /* index 3: 3 bits: 01x */ { /*3*/ -28, /*6*/ -25 }, /* index 4: 4 bits: 010x */ { /*2*/ -29, 6 }, /* index 5: 4 bits: 011x */ { /*5*/ -26, /*4*/ -27 } /* index 6: 5 bits: 0111x */};static const int8_t t_huff_opd[][2] = { { 1, /*0*/ -31 }, /* index 0: 1 bits: x */ { 2, 3 }, /* index 1: 2 bits: 0x */ { 4, 5 }, /* index 2: 3 bits: 00x */ { /*1*/ -30, /*7*/ -24 }, /* index 3: 3 bits: 01x */ { /*5*/ -26, 6 }, /* index 4: 4 bits: 000x */ { /*2*/ -29, /*6*/ -25 }, /* index 5: 4 bits: 001x */ { /*4*/ -27, /*3*/ -28 } /* index 6: 5 bits: 0001x */};/* static function declarations */static uint16_t ps_extension(ps_info *ps, bitfile *ld, const uint8_t ps_extension_id, const uint16_t num_bits_left);static void huff_data(bitfile *ld, const uint8_t dt, const uint8_t nr_par, ps_huff_tab t_huff, ps_huff_tab f_huff, int8_t *par);static INLINE int8_t ps_huff_dec(bitfile *ld, ps_huff_tab t_huff);uint16_t ps_data(ps_info *ps, bitfile *ld){ uint8_t tmp, n; uint16_t bits = (uint16_t)faad_get_processed_bits(ld); /* check for new PS header */ if (faad_get1bit(ld DEBUGVAR(1,1000,"ps_data(): enable_ps_header"))) { ps->use34hybrid_bands = 0; /* Inter-channel Intensity Difference (IID) parameters enabled */ ps->enable_iid = (uint8_t)faad_get1bit(ld DEBUGVAR(1,1001,"ps_data(): enable_iid")); if (ps->enable_iid) { ps->iid_mode = (uint8_t)faad_getbits(ld, 3 DEBUGVAR(1,1002,"ps_data(): iid_mode")); ps->nr_iid_par = nr_iid_par_tab[ps->iid_mode]; ps->nr_ipdopd_par = nr_ipdopd_par_tab[ps->iid_mode]; if (ps->iid_mode == 2 || ps->iid_mode == 5) ps->use34hybrid_bands = 1; /* IPD freq res equal to IID freq res */ ps->ipd_mode = ps->iid_mode; } /* Inter-channel Coherence (ICC) parameters enabled */ ps->enable_icc = (uint8_t)faad_get1bit(ld DEBUGVAR(1,1003,"ps_data(): enable_icc")); if (ps->enable_icc) { ps->icc_mode = (uint8_t)faad_getbits(ld, 3 DEBUGVAR(1,1004,"ps_data(): icc_mode")); ps->nr_icc_par = nr_icc_par_tab[ps->icc_mode]; if (ps->icc_mode == 2 || ps->icc_mode == 5) ps->use34hybrid_bands = 1; } /* PS extension layer enabled */ ps->enable_ext = (uint8_t)faad_get1bit(ld DEBUGVAR(1,1005,"ps_data(): enable_ext")); } ps->frame_class = (uint8_t)faad_get1bit(ld DEBUGVAR(1,1006,"ps_data(): frame_class")); tmp = (uint8_t)faad_getbits(ld, 2 DEBUGVAR(1,1007,"ps_data(): num_env_idx")); ps->num_env = num_env_tab[ps->frame_class][tmp]; if (ps->frame_class) { for (n = 1; n < ps->num_env+1; n++) { ps->border_position[n] = (uint8_t)faad_getbits(ld, 5 DEBUGVAR(1,1008,"ps_data(): border_position")); } } if (ps->enable_iid) { for (n = 0; n < ps->num_env; n++) { ps->iid_dt[n] = (uint8_t)faad_get1bit(ld DEBUGVAR(1,1009,"ps_data(): iid_dt")); /* iid_data */ if (ps->iid_mode < 3) { huff_data(ld, ps->iid_dt[n], ps->nr_iid_par, t_huff_iid_def, f_huff_iid_def, ps->iid_index[n]); } else { huff_data(ld, ps->iid_dt[n], ps->nr_iid_par, t_huff_iid_fine, f_huff_iid_fine, ps->iid_index[n]); } } } if (ps->enable_icc) { for (n = 0; n < ps->num_env; n++) { ps->icc_dt[n] = (uint8_t)faad_get1bit(ld DEBUGVAR(1,1010,"ps_data(): icc_dt")); /* icc_data */ huff_data(ld, ps->icc_dt[n], ps->nr_icc_par, t_huff_icc, f_huff_icc, ps->icc_index[n]); } } if (ps->enable_ext) { uint16_t num_bits_left; uint16_t cnt = (uint16_t)faad_getbits(ld, 4 DEBUGVAR(1,1011,"ps_data(): ps_extension_size")); if (cnt == 15) { cnt += (uint16_t)faad_getbits(ld, 8 DEBUGVAR(1,1012,"ps_data(): esc_count")); } num_bits_left = 8 * cnt; while (num_bits_left > 7) { uint8_t ps_extension_id = (uint8_t)faad_getbits(ld, 2 DEBUGVAR(1,1013,"ps_data(): ps_extension_size")); num_bits_left -= 2; num_bits_left -= ps_extension(ps, ld, ps_extension_id, num_bits_left); } faad_getbits(ld, num_bits_left DEBUGVAR(1,1014,"ps_data(): fill_bits")); } bits = (uint16_t)faad_get_processed_bits(ld) - bits; ps->ps_data_available = 1; return bits;}static uint16_t ps_extension(ps_info *ps, bitfile *ld, const uint8_t ps_extension_id, const uint16_t num_bits_left){ uint8_t n; uint16_t bits = (uint16_t)faad_get_processed_bits(ld); if (ps_extension_id == 0) { ps->enable_ipdopd = (uint8_t)faad_get1bit(ld DEBUGVAR(1,1015,"ps_extension(): enable_ipdopd")); if (ps->enable_ipdopd) { for (n = 0; n < ps->num_env; n++) { ps->ipd_dt[n] = (uint8_t)faad_get1bit(ld DEBUGVAR(1,1016,"ps_extension(): ipd_dt")); /* ipd_data */ huff_data(ld, ps->ipd_dt[n], ps->nr_ipdopd_par, t_huff_ipd, f_huff_ipd, ps->ipd_index[n]); ps->opd_dt[n] = (uint8_t)faad_get1bit(ld DEBUGVAR(1,1017,"ps_extension(): opd_dt")); /* opd_data */ huff_data(ld, ps->opd_dt[n], ps->nr_ipdopd_par, t_huff_opd, f_huff_opd, ps->opd_index[n]); } } faad_get1bit(ld DEBUGVAR(1,1018,"ps_extension(): reserved_ps")); } /* return number of bits read */ bits = (uint16_t)faad_get_processed_bits(ld) - bits; return bits;}/* read huffman data coded in either the frequency or the time direction */static void huff_data(bitfile *ld, const uint8_t dt, const uint8_t nr_par, ps_huff_tab t_huff, ps_huff_tab f_huff, int8_t *par){ uint8_t n; if (dt) { /* coded in time direction */ for (n = 0; n < nr_par; n++) { par[n] = ps_huff_dec(ld, t_huff); } } else { /* coded in frequency direction */ par[0] = ps_huff_dec(ld, f_huff); for (n = 1; n < nr_par; n++) { par[n] = ps_huff_dec(ld, f_huff); } }}/* binary search huffman decoding */static INLINE int8_t ps_huff_dec(bitfile *ld, ps_huff_tab t_huff){ uint8_t bit; int16_t index = 0; while (index >= 0) { bit = (uint8_t)faad_get1bit(ld); index = t_huff[index][bit]; } return index + 31;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -