📄 ic_predict.c
字号:
DPF(("VAR[1] %f %lld, ", VAR[1], i_VAR[1])); FLCOMP((COR[1] = ALPHA*COR[1] + r[1]*e1)) i_COR[1] = (MUL_L(i_ALPHA, i_COR[1])>>REAL_BITS) + (MUL_L(i_r[1], i_e1)>>4);DPF(("COR[1] %f %lld, ", COR[1], i_COR[1]));// Doing this causes only a few small errors// i_COR[0] &= 0xfffffffffffe0000ll;// i_COR[1] &= 0xfffffffffffe0000ll;// i_VAR[0] &= 0xfffffffffffe0000ll;// i_VAR[1] &= 0xfffffffffffe0000ll; FLCOMP((r[1] = A * (r[0]-dr1))) i_r[1] = MUL_R(i_A, (i_r[0]-(i_dr1>>4)));DPF(("r[1] %f %d, ", r[1], i_r[1])); FLCOMP((r[0] = A * e0)) i_r[0] = MUL_R(i_A, (i_e0>>4));DPF(("r[0] %f %d\n", r[0], i_r[0]));DPF(("I %d %d %lld %lld %lld %lld\n", i_r[0], i_r[1], i_COR[0], i_COR[1], i_VAR[0], i_VAR[1]));DPF(("F %d %d %lld %lld %lld %lld\n", (int32_t)r[0], (int32_t)r[1], (int64_t)COR[0], (int64_t)COR[1], (int64_t)VAR[0], (int64_t)VAR[1]));//DPF(("F %f %f %f %f %f %f\n", r[0], r[1], COR[0], COR[1], VAR[0], VAR[1])); state->r[0] = i_quant_pred(i_r[0]); state->r[1] = i_quant_pred(i_r[1]); state->COR[0] = i_quant_pred(i_COR[0]); state->COR[1] = i_quant_pred(i_COR[1]); state->VAR[0] = i_quant_pred(i_VAR[0]); state->VAR[1] = i_quant_pred(i_VAR[1]);DPF(("I %4x %4x %4x %4x %4x %4x\n", state->r[0]&0xffff, state->r[1]&0xffff, state->COR[0]&0xffff, state->COR[1]&0xffff, state->VAR[0]&0xffff, state->VAR[1]&0xffff)); FLCOMP((state->r[0] = quant_pred((float)r[0]))) FLCOMP((state->r[1] = quant_pred((float)r[1]))) FLCOMP((state->COR[0] = quant_pred((float)COR[0]))) FLCOMP((state->COR[1] = quant_pred((float)COR[1]))) FLCOMP((state->VAR[0] = quant_pred((float)VAR[0]))) FLCOMP((state->VAR[1] = quant_pred((float)VAR[1])))DPF(("F %4x %4x %4x %4x %4x %4x\n", state->r[0]&0xffff, state->r[1]&0xffff, state->COR[0]&0xffff, state->COR[1]&0xffff, state->VAR[0]&0xffff, state->VAR[1]&0xffff));debug_count++;}static void reset_pred_state(pred_state *state){ state->r[0] = 0; state->r[1] = 0; state->COR[0] = 0; state->COR[1] = 0; state->VAR[0] = 0x3F80; state->VAR[1] = 0x3F80;}void pns_reset_pred_state(ic_stream *ics, pred_state *state){ uint8_t sfb, g, b; uint16_t i, offs, offs2; /* prediction only for long blocks */ if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) return; for (g = 0; g < ics->num_window_groups; g++) { for (b = 0; b < ics->window_group_length[g]; b++) { for (sfb = 0; sfb < ics->max_sfb; sfb++) { if (is_noise(ics, g, sfb)) { offs = ics->swb_offset[sfb]; offs2 = ics->swb_offset[sfb+1]; for (i = offs; i < offs2; i++) reset_pred_state(&state[i]); } } } }}void reset_all_predictors(pred_state *state, uint16_t frame_len){ uint16_t i; for (i = 0; i < frame_len; i++) reset_pred_state(&state[i]);}/* intra channel prediction */void ic_prediction(ic_stream *ics, real_t *spec, pred_state *state, uint16_t frame_len, uint8_t sf_index){ uint8_t sfb; uint16_t bin; if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) { reset_all_predictors(state, frame_len); } else { for (sfb = 0; sfb < max_pred_sfb(sf_index); sfb++) { uint16_t low = ics->swb_offset[sfb]; uint16_t high = ics->swb_offset[sfb+1]; for (bin = low; bin < high; bin++) { ic_predict(&state[bin], spec[bin], &spec[bin], (uint8_t)(ics->predictor_data_present && ics->pred.prediction_used[sfb])); } } if (ics->predictor_data_present) { if (ics->pred.predictor_reset) { for (bin = ics->pred.predictor_reset_group_number - 1; bin < frame_len; bin += 30) { reset_pred_state(&state[bin]); } } } }}#else /* ] f loating point [ */#define ALPHA 0.90625#define A 0.953125static void flt_round(float32_t *pf){ int32_t flg; uint32_t tmp, tmp1, tmp2; tmp = *(uint32_t*)pf; flg = tmp & (uint32_t)0x00008000; tmp &= (uint32_t)0xffff0000; tmp1 = tmp; /* round 1/2 lsb toward infinity */ if (flg) { tmp &= (uint32_t)0xff800000; /* extract exponent and sign */ tmp |= (uint32_t)0x00010000; /* insert 1 lsb */ tmp2 = tmp; /* add 1 lsb and elided one */ tmp &= (uint32_t)0xff800000; /* extract exponent and sign */ *pf = *(float32_t*)&tmp1 + *(float32_t*)&tmp2 - *(float32_t*)&tmp; } else { *pf = *(float32_t*)&tmp; }}static int16_t quant_pred(float32_t x){ int16_t q; uint32_t *tmp = (uint32_t*)&x; q = (int16_t)(*tmp>>16); return q;}static float32_t inv_quant_pred(int32_t q){ float32_t x; uint32_t *tmp = (uint32_t *)&x; *tmp = ((uint32_t)q)<<16;//DPF(("%d %x %x %f\n", q, q, *tmp, x)); return x;}static void ic_predict(pred_state *state, real_t input, real_t *output, uint8_t pred){ uint32_t tmp; int32_t i, j; real_t dr1, predictedvalue; real_t e0, e1; real_t k1, k2 = 0; real_t r[2]; real_t COR[2]; real_t VAR[2];DPF(("count %d, r[0] before inv_quant_pred %d \n", debug_count, state->r[0])); r[0] = inv_quant_pred(state->r[0]);DPF(("r[0] after inv_quant_pred %f \n", r[0]));DPF(("r[1] before inv_quant_pred %d \n", state->r[1])); r[1] = inv_quant_pred(state->r[1]);DPF(("r[1] after inv_quant_pred %f \n", r[1])); /* r[0] and r[1] numbers range from 6752 to 16384000 and -2752 to -15204352 */ COR[0] = inv_quant_pred(state->COR[0]); COR[1] = inv_quant_pred(state->COR[1]); VAR[0] = inv_quant_pred(state->VAR[0]); VAR[1] = inv_quant_pred(state->VAR[1]);DPF(("%f %f %f %f %f %f\n", r[0], r[1], COR[0], COR[1], VAR[0], VAR[1])); tmp = state->VAR[0]; j = (tmp >> 7); /* what about the sign bit ? */ i = tmp & 0x7f; /* COR[0] 20709376 to 101704825569280 -34603008 to -114898965102592 */DPF(("state->VAR[0] %d COR[0] %f\n", state->VAR[0], COR[0])); if (j >= 128) { j -= 128;DPF(("j %d, i %d mt %f\n", j, i, mnt_table[i])); k1 = COR[0] * exp_table[j] * mnt_table[i]; } else { k1 = COEF_CONST(0); }DPF(("k1 %f\n", k1));DPF(("do pred %d\n", pred)); if (pred) { tmp = state->VAR[1]; j = (tmp >> 7); i = tmp & 0x7f; if (j >= 128) { j -= 128;DPF(("j %d, i %d mt %f\n", j, i, mnt_table[i])); k2 = COR[1] * exp_table[j] * mnt_table[i]; } else { k2 = COEF_CONST(0); }DPF(("k2 %f, r[0] %f r[1] %f\n", k2, r[0], r[1])); predictedvalue = k1*r[0] + k2*r[1];ODPF(("count %d, ", debug_count)); // flt_round(&predictedvalue);//ODPF(("ROUND predictedvalue %f ", predictedvalue));ODPF(("input %f, ", input)); *output = input + predictedvalue;ODPF(("output %f\n", *output)); }//if (mf < COR[0]) { mf = COR[0]; printf("\nMAX %f\n", mf); }//if (nf > COR[0]) { nf = COR[0]; printf("\nMIN %f\n", nf); } /* k1 range .5 to .934570 -.5 to -0.928650 */ /* k2 range 0.440598 to 0.863770 -0.000927 to -0.915161 */ /* calculate new state data */ /* r[0] and r[1] numbers range from 6752 to 16384000 and -2752 to -15204352 */ /* e0 7093 to 17234306 -5030 to -15960412 can shift 6 bits */ e0 = *output;DPF(("e0 %f, ", e0)); /* e1 7093 to 17234306 -5030 to -15960412 can shift 6 bits */ e1 = e0 - k1*r[0];DPF(("e1 %f, ", e1)); dr1 = k1*e0; /* dr1 4897 to 6576848 -3298 to -5804094 can shift 8 bits */DPF(("dr1 %f\n", dr1)); /* VAR and COR get really big, but they get squashed by quant_pred to 16 bits */ VAR[0] = (float)(ALPHA*VAR[0] + 0.5f * (r[0]*r[0] + e0*e0));DPF(("VAR[0] %f, ", VAR[0])); COR[0] = (float)(ALPHA*COR[0] + r[0]*e0);DPF(("COR[0] %f, ", COR[0])); VAR[1] = (float)(ALPHA*VAR[1] + 0.5f * (r[1]*r[1] + e1*e1));DPF(("VAR[1] %f, ", VAR[1])); COR[1] = (float)(ALPHA*COR[1] + r[1]*e1);DPF(("COR[1] %f, ", COR[1])); r[1] = (float)(A * (r[0]-dr1));DPF(("r[1] %f, ", r[1])); r[0] = (float)(A * e0);DPF(("r[0] %f\n", r[0])); state->r[0] = quant_pred(r[0]); state->r[1] = quant_pred(r[1]); state->COR[0] = quant_pred(COR[0]); state->COR[1] = quant_pred(COR[1]); state->VAR[0] = quant_pred(VAR[0]); state->VAR[1] = quant_pred(VAR[1]);DPF(("%d %d %d %d %d %d\n", state->r[0], state->r[1], state->COR[0], state->COR[1], state->VAR[0], state->VAR[1]));debug_count++;}static void reset_pred_state(pred_state *state){ state->r[0] = 0; state->r[1] = 0; state->COR[0] = 0; state->COR[1] = 0; state->VAR[0] = 0x3F80; state->VAR[1] = 0x3F80;}void pns_reset_pred_state(ic_stream *ics, pred_state *state){ uint8_t sfb, g, b; uint16_t i, offs, offs2; /* prediction only for long blocks */ if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) return; for (g = 0; g < ics->num_window_groups; g++) { for (b = 0; b < ics->window_group_length[g]; b++) { for (sfb = 0; sfb < ics->max_sfb; sfb++) { if (is_noise(ics, g, sfb)) { offs = ics->swb_offset[sfb]; offs2 = ics->swb_offset[sfb+1]; for (i = offs; i < offs2; i++) reset_pred_state(&state[i]); } } } }}void reset_all_predictors(pred_state *state, uint16_t frame_len){ uint16_t i; for (i = 0; i < frame_len; i++) reset_pred_state(&state[i]);}/* intra channel prediction */void ic_prediction(ic_stream *ics, real_t *spec, pred_state *state, uint16_t frame_len, uint8_t sf_index){ uint8_t sfb; uint16_t bin; if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) { reset_all_predictors(state, frame_len); } else { for (sfb = 0; sfb < max_pred_sfb(sf_index); sfb++) { uint16_t low = ics->swb_offset[sfb]; uint16_t high = ics->swb_offset[sfb+1]; for (bin = low; bin < high; bin++) { ic_predict(&state[bin], spec[bin], &spec[bin], (uint8_t)(ics->predictor_data_present && ics->pred.prediction_used[sfb])); } } if (ics->predictor_data_present) { if (ics->pred.predictor_reset) { for (bin = ics->pred.predictor_reset_group_number - 1; bin < frame_len; bin += 30) { reset_pred_state(&state[bin]); } } } }}#endif /* ] */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -