📄 nok_lt_prediction.c
字号:
} } /* Clean those sfb's where prediction is not used. */ start_band = (info->sfb_per_sbk[subblock] < last_band) ? info->sfb_per_sbk[subblock] : last_band; for (i = info->sbk_sfb_top[subblock][start_band - 1]; i < block_size_short; i++) mdct_predicted[i] = 0.0; /* Add the prediction to dequantized spectrum. */ for (i = 0; i < info->bins_per_sbk[subblock]; i++) current_frame[subblock * block_size_short + i] += mdct_predicted[i]; } } } break; default: break; }}/************************************************************************** Title: nok_ltp_buf_update Purpose: Updates the time domain buffer of LTP. Usage: nok_ltp_buf_update(win_type, win_shape,win_shape_prev, lt_status, current_frame, block_size_long, block_size_medium, block_size_short, num_short_block) Input: win_type - window sequence (frame, block) type win_shape - shape of the mdct window win_shape_prev - shape from previous block current_frame - fully reconstructed spectrum block_size_long - size of the long block block_size_medium - size of the medium block block_size_short - size of the short block num_short_block - number of subblocks in a block Output: lt_status : buffer - history buffer for prediction References: 1.) freq2buffer in imdct.c 2.) double_to_int Explanation: - Author(s): Mikko Suonio, Juha Ojanpera *************************************************************************/voidnok_ltp_buf_update (WINDOW_SEQUENCE win_type, WINDOW_SHAPE win_shape, WINDOW_SHAPE win_shape_prev, NOK_LT_PRED_STATUS* lt_status, Float* current_frame, int block_size_long, int block_size_medium, int block_size_short, int num_short_block){ int i, j, subblock; double current_frame_double[2*NOK_MAX_BLOCK_LEN_LONG]; double overlap_buffer[2 * NOK_MAX_BLOCK_LEN_LONG]; double predicted_samples[2 * NOK_MAX_BLOCK_LEN_LONG]; for (i = 0; i < NOK_LT_BLEN - block_size_long; i++) lt_status->buffer[i] = lt_status->buffer[i + block_size_long]; switch(win_type) { case ONLY_LONG_SEQUENCE: case LONG_START_SEQUENCE: case LONG_STOP_SEQUENCE: for (i = 0; i < block_size_long; i++) current_frame_double[i] = current_frame[i]; for (i = 0; i < block_size_long; i++){ current_frame_double[i+block_size_long] = 0; overlap_buffer[i] = 0.; overlap_buffer[i+block_size_long] = 0.; predicted_samples[i] = 0.; predicted_samples[i+block_size_long] = 0.; } /* Finally update the time domain history buffer. */ freq2buffer (current_frame_double, predicted_samples, overlap_buffer, win_type, block_size_long, block_size_medium, block_size_short, win_shape, win_shape_prev, NON_OVERLAPPED_MODE, -1); j = NOK_LT_BLEN - 2 * block_size_long; for (i = 0; i < block_size_long; i++) { lt_status->buffer[i + j] = double_to_int (predicted_samples[i] + lt_status->buffer[i + j]); lt_status->buffer[NOK_LT_BLEN - block_size_long + i] = double_to_int (predicted_samples[i + block_size_long]); } break; case EIGHT_SHORT_SEQUENCE: for (i = NOK_LT_BLEN - block_size_long; i < NOK_LT_BLEN; i++) lt_status->buffer[i] = 0; for (i = 0; i < block_size_long; i++){ /**TM */ current_frame_double[i+block_size_long] = 0; overlap_buffer[i] = 0.; overlap_buffer[i+block_size_long] = 0.; predicted_samples[i] = 0.; predicted_samples[i+block_size_long] = 0.; } for (subblock = 0; subblock < num_short_block; subblock++) { for (i = 0; i < block_size_short; i++) current_frame_double[i] = current_frame[subblock * block_size_short + i]; /* * Finally update the time domain history buffer by adding this window. */ freq2buffer (current_frame_double, predicted_samples, overlap_buffer, win_type, block_size_long, block_size_medium, block_size_short, win_shape, win_shape_prev, NON_OVERLAPPED_MODE, 1); i = NOK_LT_BLEN - 2 * block_size_long + SHORT_SQ_OFFSET + subblock * block_size_short; for (j = 0; j < 2 * block_size_short; j++) lt_status->buffer[i + j] = double_to_int (predicted_samples[j] + lt_status->buffer[i + j]); } break; default: break; }}/************************************************************************** Title: double_to_int Purpose: Converts floating point format to integer (16-bit). Usage: y = double_to_int(sig_in) Input: sig_in - floating point number Output: y - integer number References: - Explanation: - Author(s): Juha Ojanpera *************************************************************************/static shortdouble_to_int (double sig_in){ short sig_out = 0; if (sig_in > 32767) sig_out = 32767; else if (sig_in < -32768) sig_out = -32768; else if (sig_in > 0.0) sig_out = (short) (sig_in + 0.5); else if (sig_in <= 0.0) sig_out = (short) (sig_in - 0.5); return (sig_out);}/************************************************************************** Title: nok_lt_decode Purpose: Decode the bitstream elements for long term prediction Usage: y = nok_lt_decode(win_type, max_sfb, sbk_prediction_used, sfb_prediction_used, weight, delay, hResilience, hVm, hEpInfo, qc_select, coreCodecIdx, max_sfb_tvq_set) Input: win_type - window sequence (frame, block) type max_sfb - # scalefactor bands used in the current frame hResilience - error resilience stuff hVm - same as above hEpInfo - same as above qc_select - MPEG4/TF codec type coreCodecIdx - core codec (used only in scaleable mode) max_sfb_tvq_set - 1 if max_sfb need not to be read from the bit stream, 0 otherwise (used only in scaleable mode) Output: y - # bits read from the stream sbk_prediction_used - first item toggles prediction on(1)/off(0) for all subblocks, next items toggle it on/off on each subblock separately sfb_prediction_used - first item is not used, but the following items toggle prediction on(1)/off(0) on each scalefactor-band of every subblock weight - a weight factor to apply to all subblocks delay - array of delays to apply to each subblock References: 1.) GetBits Explanation: - Author(s): Mikko Suonio, Juha Ojanpera *************************************************************************/int nok_lt_decode ( WINDOW_SEQUENCE win_type, byte* max_sfb, int* sbk_prediction_used, int* sfb_prediction_used, Float* weight, int* delay, HANDLE_RESILIENCE hResilience, HANDLE_BUFFER hVm, HANDLE_EP_INFO hEpInfo, QC_MOD_SELECT qc_select, enum CORE_CODEC coreCodecIdx, int max_sfb_tvq_set){ int i; int last_band = 0; int prev_subblock; int read_bits; *weight = 0.0; read_bits = LEN_LTP_DATA_PRESENT; sbk_prediction_used[0] = GetBits ( LTP_DATA, LEN_LTP_DATA_PRESENT, hResilience, hVm, hEpInfo ); if ((sbk_prediction_used[0])) { if(coreCodecIdx == NTT_TVQ && !max_sfb_tvq_set) { *max_sfb = GetBits(LTP_DATA, 6, hResilience, hVm, hEpInfo); read_bits += 6; } { read_bits += LEN_LTP_LAG; delay[0] = GetBits ( LTP_DATA, LEN_LTP_LAG, hResilience, hVm, hEpInfo ); } *weight = codebook[GetBits ( LTP_DATA, LEN_LTP_COEF, hResilience, hVm, hEpInfo )]; read_bits += LEN_LTP_COEF; if (win_type != EIGHT_SHORT_SEQUENCE) { last_band = (*max_sfb < NOK_MAX_LT_PRED_LONG_SFB ? *max_sfb : NOK_MAX_LT_PRED_LONG_SFB) + 1; read_bits += last_band - 1; sfb_prediction_used[0] = sbk_prediction_used[0]; for (i = 1; i < last_band; i++) sfb_prediction_used[i] = GetBits ( LTP_DATA, LEN_LTP_LONG_USED, hResilience, hVm, hEpInfo ); for (; i < MAX_SCFAC_BANDS; i++) sfb_prediction_used[i] = 0; } else { read_bits += NSHORT; sfb_prediction_used[0] = sbk_prediction_used[0]; prev_subblock = -1; for (i = 0; i < NSHORT; i++) { if(i>0) delay[i] = 0; if ((sbk_prediction_used[i+1] = GetBits ( LTP_DATA, LEN_LTP_SHORT_USED, hResilience, hVm, hEpInfo ))) { if(prev_subblock == -1) { delay[i] = delay[0]; prev_subblock = i; } else { read_bits++; if (GetBits ( LTP_DATA, LEN_LTP_SHORT_LAG_PRESENT, hResilience, hVm, hEpInfo )) { read_bits += LEN_LTP_SHORT_LAG; delay[i] = GetBits ( LTP_DATA, LEN_LTP_SHORT_LAG, hResilience, hVm, hEpInfo ); delay[i] -= NOK_LTP_LAG_OFFSET; delay[i] = delay[prev_subblock] - delay[i]; } else delay[i] = delay[prev_subblock]; } prev_subblock = i; } } } } if (debug['p']) { if (sbk_prediction_used[0]) { fprintf(stderr, "long term prediction enabled (%2d): ", last_band); for (i = 1; i < *max_sfb + 1; i++) fprintf(stderr, " %d", sfb_prediction_used[i]); fprintf(stderr, "\n"); for (i = 1; i < MAX_SHORT_WINDOWS + 1; i++) fprintf(stderr, " %d", sbk_prediction_used[i]); fprintf(stderr, "\n"); } } return (read_bits);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -