void __stdcall ac3_init(ac3_state *state) { state->frame_count=0; bitstream_init(state); imdct_init(); sanity_check_init(&state->syncinfo,&state->bsi,&state->audblk); }
void InitialAC3() { error_flag = buffer_size = 0; ZeroMemory(&syncinfo, sizeof(syncinfo)); ZeroMemory(&bsi, sizeof(bsi)); ZeroMemory(&audblk, sizeof(audblk)); drc_init(); imdct_init(); exponent_init(); mantissa_init(); srand(0); }
/*=============================================================*/ int L3table_init(MPEG *m) { int i; float *x; LS *ls; int scalefact_scale, preemp, scalefac; double tmp; PAIR *csa; /*================ quant ===============================*/ /* 8 bit plus 2 lookup x = pow(2.0, 0.25*(global_gain-210)) */ /* extra 2 for ms scaling by 1/sqrt(2) */ /* extra 4 for cvt to mono scaling by 1/2 */ x = quant_init_global_addr(m); for (i = 0; i < 256 + 2 + 4; i++) x[i] = (float) pow(2.0, 0.25 * ((i - (2 + 4)) - 210 + GLOBAL_GAIN_SCALE)); /* x = pow(2.0, -0.5*(1+scalefact_scale)*scalefac + preemp) */ ls = quant_init_scale_addr(m); for (scalefact_scale = 0; scalefact_scale < 2; scalefact_scale++) { for (preemp = 0; preemp < 4; preemp++) { for (scalefac = 0; scalefac < 32; scalefac++) { ls[scalefact_scale][preemp][scalefac] = (float) pow(2.0, -0.5 * (1 + scalefact_scale) * (scalefac + preemp)); } } } /*--- iSample**(4/3) lookup, -32<=i<=31 ---*/ x = quant_init_pow_addr(m); for (i = 0; i < 64; i++) { tmp = i - 32; x[i] = (float) (tmp * pow(fabs(tmp), (1.0 / 3.0))); } /*-- pow(2.0, -0.25*8.0*subblock_gain) 3 bits --*/ x = quant_init_subblock_addr(m); for (i = 0; i < 8; i++) { x[i] = (float) pow(2.0, 0.25 * -8.0 * i); } /*-------------------------*/ // quant_init_sf_band(sr_index); replaced by code in sup.c /*================ antialias ===============================*/ csa = alias_init_addr(m); for (i = 0; i < 8; i++) { csa[i][0] = (float) (1.0 / sqrt(1.0 + Ci[i] * Ci[i])); csa[i][1] = (float) (Ci[i] / sqrt(1.0 + Ci[i] * Ci[i])); } /*================ msis ===============================*/ msis_init(m); msis_init_MPEG2(m); /*================ imdct ===============================*/ imdct_init(m); /*--- hybrid windows ------------*/ hwin_init(m); return 0; }
int AC3_SampleConvert(sint_16 *pPcmData, uint_32 *pnPcmDataLen, uint_8* pAc3Buf, uint_32 nAc3DataLen) { int i; bitstream_t *bs; long SampleRate = 0; /* bitstream sample-rate */ uint_32 cbErrors = 0; /* bitstream error count returned by decode_sanity_check() */ uint_32 cbMantErrors, cbExpErrors; /* error counters for mantissa & exponent unpacking errors */ bsi_t bsi_blank = {0}; static audblk_t audblk_blank = {0}; bs = bitstream_open(pAc3Buf, pAc3Buf+nAc3DataLen); imdct_init(); /* initialize decoder and counter variables */ (bsi) = bsi_blank; (audblk) = audblk_blank; decode_sanity_check_init(); bsi_blank = bsi; audblk_blank = audblk; cbErrors = 0; audblk = audblk_blank; /* clear out audioblock */ if(!(decode_resync(bs))) { return 0; } bsi = bsi_blank; /* v0.04 wipe bsi clear, not really necessary */ parse_syncinfo(&syncinfo,bs); parse_bsi(&bsi,bs); switch (syncinfo.fscod) { case 2: SampleRate = 32000; break; case 1: SampleRate = 44100; break; case 0: SampleRate = 48000; break; default: return 0; } /* reset bitstream error counters */ cbErrors = cbExpErrors = cbMantErrors = 0; memset(pPcmData, 0, BUFFER_SIZE1*2); *pnPcmDataLen = 0; for(i=0; i < 6; i++) { long buf_offset; parse_audblk(&bsi,&audblk,bs,i); // CPU time 10% cbExpErrors = exponent_unpack(&bsi,&audblk); if(cbExpErrors > 0) { return 0; cbExpErrors =0; } bit_allocate(syncinfo.fscod,&bsi,&audblk); // CPU TIME 1.2% if ( bsi.nfchans > 6 ) { bsi.nfchans = 0; return 0;//(LPBYTE) out_buf; } cbMantErrors = mantissa_unpack(&bsi,&audblk,bs); // CPU TIME 62.0% if( cbMantErrors > 0) { return 0; cbMantErrors = 0; } uncouple(&bsi,&audblk,&stream_coeffs); // CPU TIME 1.7% if(bsi.acmod == 0x2) rematrix(&audblk,&stream_coeffs); // CPU TIME 0.1% imdct(&bsi,&audblk,&stream_coeffs,&stream_samples); // CPU TIME 11.2% buf_offset = i * 512; downmix( &stream_samples, pPcmData+buf_offset, &bsi, 0 ); } /* endfor ( i = 0 ... ) */ *pnPcmDataLen = 6*512*2; cbErrors = decode_sanity_check(); if(cbErrors > 0) { return 0; } parse_auxdata(&syncinfo,bs); // CPU TIME 2.0% if(!crc_validate()) { return 0; } return 1; }
/* call this once at the beginning */ void initialise_decoder(void) { premultiply(); imdct_init(); calculate_t43(); }