📄 nok_lt_prediction.c
字号:
/**************************************************************************This software module was originally developed byNokia in the course of development of the MPEG-2 AAC/MPEG-4 Audio standard ISO/IEC13818-7, 14496-1, 2 and 3.This software module is an implementation of a partof one or more MPEG-2 AAC/MPEG-4 Audio tools as specified by theMPEG-2 aac/MPEG-4 Audio standard. ISO/IEC gives users of theMPEG-2aac/MPEG-4 Audio standards free license to this software moduleor modifications thereof for use in hardware or software productsclaiming conformance to the MPEG-2 aac/MPEG-4 Audio standards. Thoseintending to use this software module in hardware or software productsare advised that this use may infringe existing patents. The originaldeveloper of this software module, the subsequenteditors and their companies, and ISO/IEC have no liability for use ofthis software module or modifications thereof in animplementation. Copyright is not released for non MPEG-2 aac/MPEG-4Audio conforming products. The original developer retains full right touse the code for the developer's own purpose, assign or donate the code to athird party and to inhibit third party from using the code for nonMPEG-2 aac/MPEG-4 Audio conforming products. This copyright noticemust be included in all copies or derivative works.Copyright (c)1997. ***************************************************************************//************************************************************************** nok_lt_prediction.c - Performs Long Term Prediction for the MPEG-4 T/F Decoder. Author(s): Mikko Suonio, Juha Ojanpera Nokia Research Center, Speech and Audio Systems, 1997. *************************************************************************//************************************************************************** Version Control Information Method: CVS Identifiers: $Revision: 1.22 $ $Date: 1999/05/20 17:29:15 $ (check in) $Author: purnhage $ *************************************************************************//************************************************************************** External Objects Needed *************************************************************************/#include <stdio.h>#include "block.h" /* handler, defines, enums */#include "buffersHandle.h" /* handler, defines, enums */#include "concealmentHandle.h" /* handler, defines, enums */#include "interface.h" /* handler, defines, enums */#include "mod_bufHandle.h" /* handler, defines, enums */#include "monopredHandle.h" /* handler, defines, enums */#include "reorderspecHandle.h" /* handler, defines, enums */#include "resilienceHandle.h" /* handler, defines, enums */#include "tf_mainHandle.h" /* handler, defines, enums */#include "all.h" /* structs */#include "monopredStruct.h" /* structs */#include "nok_ltp_common.h" /* structs */#include "nok_prediction.h" /* structs */#include "obj_descr.h" /* structs */#include "tf_mainStruct.h" /* structs */#include "tns.h" /* structs */#include "allVariables.h" /* variables */#include "nttNew.h"#include "tf_main.h"#include "block.h"#include "nok_ltp_common.h"#include "buffers.h"/* Enum constant:MAX_SHORT_WINDOWS Purpose: Gives the maximum number of subblocks (short windows). Explanation: - *//* Variable: debug Purpose: Provided debug options. Explanation: If element debug['p'] is true, we give debug information on long term prediction. *//* Function: buffer2freq Call: buffer2freq (p_in_data, p_out_mdct, p_overlap, windowSequence, wfun_select, nlong, nmed, nshort, overlap_select, num_short_win, save_window); Purpose: Modified discrete cosine transform Input: p_in_data[] - input signal (length: 2*shift length) p_overlap[] - buffer containing the previous frame in OVERLAPPED_MODE (length: 2*shift length) windowSequence - selects the type of window to use wfun_select - select window function nlong - shift length for long windows nmed - shift length for medium windows nshort - shift length for short windows overlap_select - OVERLAPPED_MODE select num_short_win - number of short windows to transform save_window - if true, save the windowSequence for future use Output: p_out_mdct[] - transformed signal (length: shift length) p_overlap[] - a copy of p_in_data in OVERLAPPED_MODE (length: shift length) Explanation: - *//* Function: freq2buffer Call: freq2buffer (p_in_data, p_out_data, p_overlap, windowSequence, nlong, nmed, nshort, wfun_select, fun_select_prev, overlap_select, num_short_win); Purpose: Inverse of modified discrete cosine transform Input: p_in_data[] - input signal (length: shift length) p_overlap[] - the overlap buffer; does not have an effect in NON_OVERLAPPED_MODE, but have to be allocated (length: shift length) windowSequence - selects the type of window to use nlong - shift length for long windows nmed - shift length for medium windows nshort - shift length for short windows wfun_select - select window function overlap_select - OVERLAPPED_MODE select num_short_win - number of short windows to transform save_window - if true, save windowSequence for future use Output: p_out_data[] - transformed signal (length: 2*shift length) p_overlap[] - the overlap buffer; always modified (length: shift length) Explanation: - *//* Function: GetBits Purpose: Reads specified number of bits from the open input bitstream. *//************************************************************************** External Objects Provided *************************************************************************/#include "nok_lt_prediction.h"/************************************************************************** Internal Objects *************************************************************************/#include "nok_ltp_common_internal.h"static short double_to_int (double sig_in);/************************************************************************** Object Definitions *************************************************************************//************************************************************************** Title: nok_init_lt_pred Purpose: Initialize the history buffer for long term prediction Usage: nok_init_lt_pred (lt_status) Input: lt_status - buffer: history buffer Output: lt_status - buffer: filled with 0 References: - Explanation: - Author(s): Mikko Suonio *************************************************************************/voidnok_init_lt_pred (NOK_LT_PRED_STATUS *lt_status){ int i; for (i = 0; i < NOK_LT_BLEN; i++) lt_status->buffer[i] = 0;}/************************************************************************** Title: nok_lt_predict Purpose: Adds the LTP contribution to the reconstructed spectrum. Usage: y = nok_ltp_predict(info, win_type, win_shape, win_shape_prev, sbk_prediction_used, sfb_prediction_used, lt_status, weight, delay, current_frame, block_size_long, block_size_medium, block_size_short, tns_frame_info, qc_select) Input: info: nsbk - number of subblocks in a block bins_per_sbk - number of spectral coefficients in each subblock; currently we assume that they are of equal size sfb_per_bk - total # scalefactor bands in a block sfb_per_sbk - # scalefactor bands in each subblock win_type - window sequence (frame, block) type win_shape - shape of the mdct window win_shape_prev - shape from previous block 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 lt_status : buffer - history buffer for prediction weight - a weight factor to apply to all subblocks delay - array of delays to apply to each subblock current_frame - the dequantized spectral coeffients and prediction errors where prediction is used block_size_long - size of the long block block_size_medium - size of the medium block block_size_short - size of the short block tns_frame_info - TNS parameters qc_select - MPEG4/TF codec type Output: y - reconstructed spectrum containing also LTP contribution References: 1.) buffer2freq 2.) tns_encode_subblock in tns2.c 3.) double_to_int 4.) freq2buffer Explanation: - Author(s): Mikko Suonio, Juha Ojanpera *************************************************************************/voidnok_lt_predict ( Info* info, WINDOW_SEQUENCE win_type, WINDOW_SHAPE win_shape, WINDOW_SHAPE win_shape_prev, int* sbk_prediction_used, int* sfb_prediction_used, NOK_LT_PRED_STATUS* lt_status, Float weight, int* delay, Float* current_frame, int block_size_long, int block_size_medium, int block_size_short, TNS_frame_info* tns_frame_info, QC_MOD_SELECT qc_select){ int i, j, subblock, last_band, start_band; int num_samples; double mdct_predicted[2 * NOK_MAX_BLOCK_LEN_LONG]; double predicted_samples[2 * NOK_MAX_BLOCK_LEN_LONG]; Float tmpBuffer[2 * NOK_MAX_BLOCK_LEN_LONG]; switch(win_type) { case ONLY_LONG_SEQUENCE: case LONG_START_SEQUENCE: case LONG_STOP_SEQUENCE: if (sbk_prediction_used[0]) { /* Prediction for time domain signal */ num_samples = 2 * block_size_long; { j = NOK_LT_BLEN - 2 * block_size_long - (delay[0] - DELAY / 2); if(NOK_LT_BLEN - j < 2 * block_size_long) num_samples = NOK_LT_BLEN - j; } for(i = 0; i < num_samples; i++) predicted_samples[i] = weight * lt_status->buffer[i + j]; for( ; i < 2 * block_size_long; i++) predicted_samples[i] = 0.0f; /* Transform prediction to frequency domain. */ buffer2freq (predicted_samples, mdct_predicted, NULL, win_type, win_shape, win_shape_prev, block_size_long, block_size_medium, block_size_short, NON_OVERLAPPED_MODE, 1); /* * TNS analysis filter the predicted spectrum. */ if(tns_frame_info != NULL) { for(i = 0; i < block_size_long; i++) tmpBuffer[i] = mdct_predicted[i]; tns_encode_subblock(tmpBuffer, info->sfb_per_bk, info->sbk_sfb_top[0], 1, &(tns_frame_info->info[0]), qc_select); for(i = 0; i < block_size_long; i++) mdct_predicted[i] = tmpBuffer[i]; } /* Clean those sfb's where prediction is not used. */ for (i = 0, j = 0; i < info->sfb_per_bk; i++) if (sfb_prediction_used[i + 1] == 0) for (; j < info->sbk_sfb_top[0][i]; j++) mdct_predicted[j] = 0.0; else j = info->sbk_sfb_top[0][i]; /* Add the prediction to dequantized spectrum. */ for (i = 0; i < block_size_long; i++) current_frame[i] = current_frame[i] + mdct_predicted[i]; } break; case EIGHT_SHORT_SEQUENCE: last_band = NOK_MAX_LT_PRED_SHORT_SFB; if(sbk_prediction_used[0] ){ /**TM */ for (subblock = 0; subblock < info->nsbk; subblock++) { if (sbk_prediction_used[0] && sbk_prediction_used[subblock + 1]) { /* * Prediction for time domain signal. The buffer shift * causes an additional delay depending on the subblock * number. */ num_samples = 2 * block_size_short; j = NOK_LT_BLEN - num_samples - delay[subblock]; if(NOK_LT_BLEN - j < 2 * block_size_short) num_samples = NOK_LT_BLEN - j; for(i = 0; i < num_samples; i++) predicted_samples[i] = weight * lt_status->buffer[i + j]; for( ; i < 2 * block_size_long /**TM block_size_short */; i++) predicted_samples[i] = 0.0f; /* Transform prediction to frequency domain. */ buffer2freq (predicted_samples, mdct_predicted, NULL, win_type, win_shape, win_shape_prev, block_size_long, block_size_medium, block_size_short, NON_OVERLAPPED_MODE, 1); /* * TNS analysis filter the predicted subblock spectrum. */ if(tns_frame_info != NULL) { if(subblock < tns_frame_info->n_subblocks) { for(i = 0; i < block_size_short; i++) tmpBuffer[i] = mdct_predicted[i]; tns_encode_subblock(tmpBuffer, last_band, info->sbk_sfb_top[subblock], 0, &(tns_frame_info->info[subblock]), qc_select); for(i = 0; i < block_size_short; i++) mdct_predicted[i] = tmpBuffer[i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -