📄 scal_dec_frame.c
字号:
/**********************************************************************MPEG-4 Audio VMBit stream moduleThis software module was originally developed byBodo Teichmann (FhG)and edited byBernhard Grill (University of Erlangen)Takashi koike (Sony Corporation)in the course of development of the MPEG-2 NBC/MPEG-4 Audio standardISO/IEC 13818-7, 14496-1,2 and 3. This software module is animplementation of a part of one or more MPEG-2 NBC/MPEG-4 Audio toolsas specified by the MPEG-2 NBC/MPEG-4 Audio standard. ISO/IEC givesusers of the MPEG-2 NBC/MPEG-4 Audio standards free license to thissoftware module or modifications thereof for use in hardware orsoftware products claiming conformance to the MPEG-2 NBC/ MPEG-4 Audiostandards. Those intending to use this software module in hardware orsoftware products are advised that this use may infringe existingpatents. The original developer of this software module and his/hercompany, the subsequent editors and their companies, and ISO/IEC haveno liability for use of this software module or modifications thereofin an implementation. Copyright is not released for non MPEG-2NBC/MPEG-4 Audio conforming products. The original developer retainsfull right to use the code for his/her own purpose, assign or donatethe code to a third party and to inhibit third party from using thecode for non MPEG-2 NBC/MPEG-4 Audio conforming products. Thiscopyright notice must be included in all copies or derivative works.Copyright (c) 1997.*/#include <memory.h>#include <math.h>#include <stdio.h>#include <string.h>#include <assert.h>#include "block.h" /* handler, defines, enums */#include "buffersHandle.h" /* handler, defines, enums */#include "concealmentHandle.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 "bitstreamStruct.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 "dec_lpc.h"#include "mod_buf.h"#include "port.h"#include "flex_mux.h"#include "lpc_common.h"#include "dec_tf.h"#include "bitstream.h"#include "common_m4a.h"/* --- AAC --- */#include "aac.h"#include "huffdec2.h"#include "nok_lt_prediction.h"#include "scal_dec.h"#include "plotmtv.h"#include "util.h"#include "flex_mux.h"#include "ntt_conf.h"#include "ntt_scale_conf.h"#include "plotmtv.h"#include "interface.h"#include "buffers.h"#include "mp4_tf.h"/* ***************************************************************************//* scalable decoding : bitstream has 3 subframes (called granules) per frame */static void vcopy( double src[], double dest[], int inc_src, int inc_dest, int vlen ){ int i; for( i=0; i<vlen-1; i++ ) { *dest = *src; dest += inc_dest; src += inc_src; } if (vlen) /* just for bounds-checkers sake */ *dest = *src;}/* compute scalar product of two vectors */static double scalprod( double src1[], double src2[], int inc_src1, int inc_src2, int vlen){ int i; double sum=0.0; for (i=0;i<vlen; i++) { sum += (*src1)*(*src2); src1 += inc_src1; src2 += inc_src2; } return (sum);}static void vmult( double src1[], double src2[], double dest[], int inc_src1, int inc_src2, int inc_dest, int vlen ){ int i; for( i=0; i<vlen-1; i++ ) { *dest = *src1 * *src2; dest += inc_dest; src1 += inc_src1; src2 += inc_src2; } if (i<vlen) *dest = *src1 * *src2;}static void vadd( double src1[], double src2[], double dest[], int inc_src1, int inc_src2, int inc_dest, int vlen ){ int i; for( i=0; i<vlen; i++ ) { *dest = *src1 + *src2; dest += inc_dest; src1 += inc_src1; src2 += inc_src2; }}static void vsub( double src1[], double src2[], double dest[], int inc_src1, int inc_src2, int inc_dest, int vlen ){ int i; for( i=0; i<vlen; i++ ) { *dest = *src1 - *src2; dest += inc_dest; src1 += inc_src1; src2 += inc_src2; }}static void dec_lowpass(double spectrum[], int lopLong, int lopShort, int maxLine, int iblen, int windowSequence, int nr_of_sbk){ int bl, block_len, lop, i; float slope; double zero = 0.0; if (windowSequence != EIGHT_SHORT_SEQUENCE) { lop = lopLong; } else { lop = lopShort; } block_len = iblen /nr_of_sbk; if (lop > maxLine) { lop = maxLine; } slope = (1.0F /(float)lop); for (bl=0;bl<nr_of_sbk;bl++){ vcopy( &zero, &spectrum[bl*block_len+maxLine], 0, 1, block_len - maxLine); for (i=1; i<lop; i++) { spectrum[bl*block_len+maxLine-i] *= (i*slope); } }}/* get_tns_vm does exactly the same as get_tns in huffdec2.c. Just the VM bitstream handling functions replace the AAC-type functions */static void doInverseMsMatrix( Info *p_sb_info, double *p_l_spec, double *p_r_spec, int msMask[8][60] ){ int sb, win; int sfbw; double tmp_buffer[1024]; for( win=0; win<p_sb_info->nsbk; win++ ) { int sboffs = win*p_sb_info->bins_per_sbk[win]; for( sb=0; sb<p_sb_info->sfb_per_sbk[win]; sb++ ) { if (p_sb_info->islong==0){ sfbw = p_sb_info->sfb_width_short[sb]; }else { if (sb==0) sfbw = p_sb_info->bk_sfb_top[sb]; else sfbw = p_sb_info->bk_sfb_top[sb]-p_sb_info->bk_sfb_top[sb-1]; } if(msMask[win][sb] != 0 ) { vadd( &p_l_spec[sboffs], &p_r_spec[sboffs], &tmp_buffer[sboffs], 1, 1, 1, sfbw ); /* -> L */ vsub( &p_l_spec[sboffs], &p_r_spec[sboffs], &p_r_spec[sboffs], 1, 1, 1, sfbw ); /* -> R */ vcopy(&tmp_buffer[sboffs], &p_l_spec[sboffs], 1, 1, sfbw ); } sboffs += sfbw; } }}void doMsMatrix(Info *p_sb_info, double *p_l_spec, double *p_r_spec, int msMask[8][60]){ int sb, win, i; int sfbw; double sum[1024]; double diff[1024]; for( win=0; win<p_sb_info->nsbk; win++ ) { int sboffs = win*p_sb_info->bins_per_sbk[win]; for( sb=0; sb<p_sb_info->sfb_per_sbk[win]; sb++ ) { if (p_sb_info->islong==0){ sfbw = p_sb_info->sfb_width_short[sb]; }else { if (sb==0) sfbw = p_sb_info->bk_sfb_top[sb]; else sfbw = p_sb_info->bk_sfb_top[sb]-p_sb_info->bk_sfb_top[sb-1]; } if(msMask[win][sb] != 0 ) { vadd(&p_l_spec[sboffs], &p_r_spec[sboffs], &sum[sboffs], 1, 1, 1, sfbw); for(i = 0; i < sfbw; i++) p_l_spec[sboffs + i] = 0.5 * sum[sboffs + i]; vsub(&p_l_spec[sboffs], &p_r_spec[sboffs], &diff[sboffs], 1, 1, 1, sfbw); for(i = 0; i < sfbw; i++) p_r_spec[sboffs + i] = 0.5 * diff[sboffs + i]; } sboffs += sfbw; } } }static void multCoreSpecMsFac( Info *p_sb_info, int msMask[8][60], double *core_spec, double *out_spec ){ int sb, win; int sfbw; double ms_fac=2; for( win=0; win<p_sb_info->nsbk; win++ ) { int sboffs = win*p_sb_info->bins_per_sbk[win]; for( sb=0; sb<p_sb_info->sfb_per_sbk[win]; sb++ ) { if (p_sb_info->islong==0){ sfbw = p_sb_info->sfb_width_short[sb]; }else { if (sb==0) sfbw = p_sb_info->bk_sfb_top[sb]; else sfbw = p_sb_info->bk_sfb_top[sb]-p_sb_info->bk_sfb_top[sb-1]; } if( msMask[win][sb] == 0 ) { vmult( &core_spec[sboffs], &ms_fac,&out_spec[sboffs] ,1, 0, 1, sfbw ); /* if no ms core = core * fac */ }else{ vcopy( &core_spec[sboffs],&out_spec[sboffs] ,1, 1, sfbw ); /* if ms core = core */ } sboffs += sfbw; } }}static int get_tns_vm( BsBitStream *fixed_stream, Info *info, TNS_frame_info *tns_frame_info,int* decoded_bits ){ int f, t, top, res, res2, compress; int short_flag, s; short *sp, tmp, s_mask, n_mask; TNSfilt *tns_filt; TNSinfo *tns_info; static short sgn_mask[] = { 0x2, 0x4, 0x8 }; static short neg_mask[] = { (short) 0xfffc, (short)0xfff8, (short)0xfff0 }; unsigned long ultmp, numBits; short_flag = (!info->islong); tns_frame_info->n_subblocks = info->nsbk; for (s=0; s<tns_frame_info->n_subblocks; s++) { tns_info = &tns_frame_info->info[s]; numBits = (short_flag ? 1 : 2); BsGetBit( fixed_stream, &ultmp,numBits ); *decoded_bits += numBits; if (!(tns_info->n_filt = ultmp) ) continue; BsGetBit( fixed_stream, &ultmp, 1 ); *decoded_bits += 1; tns_info -> coef_res = res = ultmp + 3; top = info->sfb_per_sbk[s]; tns_filt = &tns_info->filt[ 0 ]; for (f=tns_info->n_filt; f>0; f--) { tns_filt->stop_band = top; numBits = ( short_flag ? 4 : 6); BsGetBit( fixed_stream, &ultmp,numBits ); *decoded_bits += numBits; top = tns_filt->start_band = top - ultmp; numBits = ( short_flag ? 3 : 5); BsGetBit( fixed_stream, &ultmp, numBits ); *decoded_bits += numBits; tns_filt->order = ultmp; if (tns_filt->order) { BsGetBit( fixed_stream, &ultmp, 1 ); *decoded_bits += 1; tns_filt->direction = ultmp; BsGetBit( fixed_stream, &ultmp, 1 ); *decoded_bits += 1; compress = ultmp; res2 = res - compress; s_mask = sgn_mask[ res2 - 2 ]; n_mask = neg_mask[ res2 - 2 ]; sp = tns_filt -> coef; for (t=tns_filt->order; t>0; t--) { BsGetBit( fixed_stream, &ultmp, res2 ); *decoded_bits += res2; tmp = ultmp; *sp++ = (tmp & s_mask) ? (tmp | n_mask) : tmp; } } tns_filt++; } } /* subblock loop */ return 1;}static BsBitBuffer *dynBitBuf;static int gran;static BsBitStream *dyn_stream_read;int testDebug=0;void aacScaleableDecodeInit( void ){ dynBitBuf = BsAllocBuffer( 64000 ); /* just some large number. For AAC: required ca. 6000 */ gran = 0; dyn_stream_read = BsOpenBufferRead( dynBitBuf );} static void FSSwitch( double p_core[], double p_rest[], double p_out[],
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -