static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTSRHFG][64], uint8_t bd, uint8_t len) { real_t r01 = 0, r02 = 0, r11 = 0; real_t tmp1, tmp2; int8_t j; uint8_t offset = sbr->tHFAdj; const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f); for (j = offset; j < len + offset; j++) { real_t buf_j = ACDET_PRE(QMF_RE(buffer[j ][bd])); real_t buf_j_1 = ACDET_PRE(QMF_RE(buffer[j-1][bd])); real_t buf_j_2 = ACDET_PRE(QMF_RE(buffer[j-2][bd])); r01 += MUL_F(buf_j , buf_j_1); r02 += MUL_F(buf_j , buf_j_2); r11 += MUL_F(buf_j_1, buf_j_1); } tmp1 = ACDET_PRE(QMF_RE(buffer[len+offset-1][bd])); tmp2 = ACDET_PRE(QMF_RE(buffer[ offset-1][bd])); RE(ac->r12) = r01 - MUL_F(tmp1, tmp1) + MUL_F(tmp2, tmp2); tmp1 = ACDET_PRE(QMF_RE(buffer[len+offset-2][bd])); tmp2 = ACDET_PRE(QMF_RE(buffer[ offset-2][bd])); RE(ac->r22) = r11 - MUL_F(tmp1, tmp1) + MUL_F(tmp2, tmp2); RE(ac->r01) = r01; RE(ac->r02) = r02; RE(ac->r11) = r11; ac->det = MUL_F(RE(ac->r11), RE(ac->r22)) - MUL_F(MUL_F(RE(ac->r12), RE(ac->r12)), rel); ac->det = ACDET_POST(ac->det); }
mdct_info *faad_mdct_init(uint16_t N) { uint16_t k; #ifdef FIXED_POINT uint16_t N_idx; real_t cangle, sangle, c, s, cold; #endif real_t scale; mdct_info *mdct = (mdct_info*)faad_malloc(sizeof(mdct_info)); assert(N % 8 == 0); mdct->N = N; mdct->sincos = (complex_t*)faad_malloc(N/4*sizeof(complex_t)); #ifdef FIXED_POINT N_idx = map_N_to_idx(N); scale = const_tab[N_idx][0]; cangle = const_tab[N_idx][1]; sangle = const_tab[N_idx][2]; c = const_tab[N_idx][3]; s = const_tab[N_idx][4]; #else scale = (real_t)sqrt(2.0 / (real_t)N); #endif /* (co)sine table build using recurrence relations */ /* this can also be done using static table lookup or */ /* some form of interpolation */ for (k = 0; k < N/4; k++) { #ifdef FIXED_POINT RE(mdct->sincos[k]) = c; //MUL_C_C(c,scale); IM(mdct->sincos[k]) = s; //MUL_C_C(s,scale); cold = c; c = MUL_F(c,cangle) - MUL_F(s,sangle); s = MUL_F(s,cangle) + MUL_F(cold,sangle); #else /* no recurrence, just sines */ RE(mdct->sincos[k]) = scale*(real_t)(cos(2.0*M_PI*(k+1./8.) / (real_t)N)); IM(mdct->sincos[k]) = scale*(real_t)(sin(2.0*M_PI*(k+1./8.) / (real_t)N)); #endif } /* initialise fft */ mdct->cfft = cffti(N/4); #ifdef PROFILE mdct->cycles = 0; mdct->fft_cycles = 0; #endif return mdct; }
static void AAC_AddNMul(real_t* Dst,const real_t* a,const real_t* b,const real_t* c,int n) { do { Dst[0] = a[0]+MUL_F(-b[-1],c[0]); Dst[1] = a[1]+MUL_F(-b[-2],c[1]); Dst[2] = a[2]+MUL_F(-b[-3],c[2]); Dst[3] = a[3]+MUL_F(-b[-4],c[3]); a += 4; b -= 4; c += 4; Dst += 4; n -= 4; } while (n>0); }
static void AAC_MulR(real_t* Dst,const real_t* a,const real_t* b,int n) { do { Dst[0] = MUL_F(a[-1],b[-1]); Dst[1] = MUL_F(a[-2],b[-2]); Dst[2] = MUL_F(a[-3],b[-3]); Dst[3] = MUL_F(a[-4],b[-4]); a -= 4; b -= 4; Dst += 4; n -= 4; } while (n>0); }
void* downMix( NeAACDecHandle hDecoder, real_t **input, uint16_t frame_len, uint8_t channel) { real_t *a,*b,*c; int n; a = hDecoder->time_out[hDecoder->internal_channel[0]]; //C b = hDecoder->time_out[hDecoder->internal_channel[channel?4:3]]; //S c = hDecoder->time_out[hDecoder->internal_channel[channel?2:1]]; //cum for (n=0;n<frame_len;++n) { real_t cum = c[n] + MUL_F(a[n],RSQRT2) + MUL_F(b[n],RSQRT2); c[n] = MUL_F(cum, DM_MUL); } return c; }
/* * Parameter: * coderInfo(IO)(O:coderInfo->scale_factor) * xr(unused) * xr_pow(IO) * xi(O) * xmin(I) */ static int32_t FixNoise(CoderInfo *coderInfo, coef_t *xr_pow, int32_t *xi, real_32_t *xmin) { register int32_t i, sb; int32_t start, end; static real_32_t log_ifqstep = REAL_CONST(7.6943735514); // 1.0 / log(ifqstep) static real_32_t realconst1 = REAL_CONST(0.6931471806); //log2 static real_32_t realconst2 = REAL_CONST(0.5); for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) { eng_t eng = 0; frac_t maxfixstep; start = coderInfo->sfb_offset[sb]; end = coderInfo->sfb_offset[sb+1]; for ( i=start; i< end; i++) eng += (int64_t)(COEF2INT(xr_pow[i]))*COEF2INT(xr_pow[i]); if ( (eng == 0) || (xmin[sb]==0) ) maxfixstep = FRAC_ICONST(1); else { maxfixstep = faac_sqrt(eng/(end-start)* MUL_R(xmin[sb],faac_sqrt(xmin[sb])) ); if ( maxfixstep == 0 ) maxfixstep = FRAC_ICONST(1); else maxfixstep = ((real_t)1<<(FRAC_BITS+REAL_BITS))/maxfixstep; } #ifdef DUMP_MAXFIXSTEP printf("sb = %d, maxfixstep = %.8f\n",sb, FRAC2FLOAT(maxfixstep)); #endif for (i = start; i < end; i++) { #ifdef DUMP_MAXFIXSTEP printf("xr_pow[%d] = %.8f\t",i,COEF2FLOAT(xr_pow[i])); #endif xr_pow[i] = MUL_F(xr_pow[i],maxfixstep); #ifdef DUMP_MAXFIXSTEP printf("xr_pow[%d]*fix = %.8f\n",i,COEF2FLOAT(xr_pow[i])); #endif } QuantizeBand(xr_pow, xi, start, end); coderInfo->scale_factor[sb] = (int32_t)REAL2INT(MUL_R(faac_log(maxfixstep)-FRAC2REAL_BIT*realconst1, log_ifqstep) - realconst2)+1; #ifdef DUMP_MAXFIXSTEP printf("scale_factor = %d\n", coderInfo->scale_factor[sb]); #endif } #ifdef DUMP_MAXFIXSTEP exit(1); #endif return 0; }
static void AAC_MulNMul(real_t* Dst,const real_t* b1,const real_t* c1,const real_t* b2,const real_t* c2,int n) { do { Dst[0] = MUL_F(b1[-1],c1[-1])+MUL_F(-b2[-1],c2[0]); Dst[1] = MUL_F(b1[-2],c1[-2])+MUL_F(-b2[-2],c2[1]); Dst[2] = MUL_F(b1[-3],c1[-3])+MUL_F(-b2[-3],c2[2]); Dst[3] = MUL_F(b1[-4],c1[-4])+MUL_F(-b2[-4],c2[3]); b1 -= 4; b2 -= 4; c1 -= 4; c2 += 4; Dst += 4; n -= 4; } while (n>0); }
static void AAC_AddMulMul(real_t* Dst,const real_t* a,const real_t* b1,const real_t* c1,const real_t* b2,const real_t* c2,int n) { do { Dst[0] = a[0]+MUL_F(b1[0],c1[-1])+MUL_F(b2[0],c2[0]); Dst[1] = a[1]+MUL_F(b1[1],c1[-2])+MUL_F(b2[1],c2[1]); Dst[2] = a[2]+MUL_F(b1[2],c1[-3])+MUL_F(b2[2],c2[2]); Dst[3] = a[3]+MUL_F(b1[3],c1[-4])+MUL_F(b2[3],c2[3]); a += 4; b1 += 4; b2 += 4; c1 -= 4; c2 += 4; Dst += 4; n -= 4; } while (n>0); }
/* FIXED POINT: bwArray = COEF */ static void calc_chirp_factors(sbr_info *sbr, uint8_t ch) { uint8_t i; for (i = 0; i < sbr->N_Q; i++) { sbr->bwArray[ch][i] = mapNewBw(sbr->bs_invf_mode[ch][i], sbr->bs_invf_mode_prev[ch][i]); if (sbr->bwArray[ch][i] < sbr->bwArray_prev[ch][i]) sbr->bwArray[ch][i] = MUL_F(sbr->bwArray[ch][i], FRAC_CONST(0.75)) + MUL_F(sbr->bwArray_prev[ch][i], FRAC_CONST(0.25)); else sbr->bwArray[ch][i] = MUL_F(sbr->bwArray[ch][i], FRAC_CONST(0.90625)) + MUL_F(sbr->bwArray_prev[ch][i], FRAC_CONST(0.09375)); if (sbr->bwArray[ch][i] < COEF_CONST(0.015625)) sbr->bwArray[ch][i] = COEF_CONST(0.0); if (sbr->bwArray[ch][i] > COEF_CONST(0.99609375)) sbr->bwArray[ch][i] = COEF_CONST(0.99609375); sbr->bwArray_prev[ch][i] = sbr->bwArray[ch][i]; sbr->bs_invf_mode_prev[ch][i] = sbr->bs_invf_mode[ch][i]; } }
static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample, uint8_t down_matrix, uint8_t *internal_channel) { if (!down_matrix) return input[internal_channel[channel]][sample]; if (channel == 0) { real_t C = MUL_F(input[internal_channel[0]][sample], RSQRT2); real_t L_S = MUL_F(input[internal_channel[3]][sample], RSQRT2); real_t cum = input[internal_channel[1]][sample] + C + L_S; return MUL_F(cum, DM_MUL); } else { real_t C = MUL_F(input[internal_channel[0]][sample], RSQRT2); real_t R_S = MUL_F(input[internal_channel[4]][sample], RSQRT2); real_t cum = input[internal_channel[2]][sample] + C + R_S; return MUL_F(cum, DM_MUL); } }
static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTSRHFG][64], uint8_t bd, uint8_t len) { real_t r01r = 0, r01i = 0, r02r = 0, r02i = 0, r11r = 0; real_t temp1_r, temp1_i, temp2_r, temp2_i, temp3_r, temp3_i; real_t temp4_r, temp4_i, temp5_r, temp5_i; int8_t j; uint8_t offset = sbr->tHFAdj; const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f); temp2_r = ACDET_PRE(QMF_RE(buffer[offset-2][bd])); temp2_i = ACDET_PRE(QMF_IM(buffer[offset-2][bd])); temp3_r = ACDET_PRE(QMF_RE(buffer[offset-1][bd])); temp3_i = ACDET_PRE(QMF_IM(buffer[offset-1][bd])); // Save these because they are needed after loop temp4_r = temp2_r; temp4_i = temp2_i; temp5_r = temp3_r; temp5_i = temp3_i; for (j = offset; j < len + offset; j++) { temp1_r = temp2_r; temp1_i = temp2_i; temp2_r = temp3_r; temp2_i = temp3_i; temp3_r = ACDET_PRE(QMF_RE(buffer[j][bd])); temp3_i = ACDET_PRE(QMF_IM(buffer[j][bd])); r01r += MUL_F(temp3_r, temp2_r) + MUL_F(temp3_i, temp2_i); r01i += MUL_F(temp3_i, temp2_r) - MUL_F(temp3_r, temp2_i); r02r += MUL_F(temp3_r, temp1_r) + MUL_F(temp3_i, temp1_i); r02i += MUL_F(temp3_i, temp1_r) - MUL_F(temp3_r, temp1_i); r11r += MUL_F(temp2_r, temp2_r) + MUL_F(temp2_i, temp2_i); } RE(ac->r12) = r01r - (MUL_F(temp3_r, temp2_r) + MUL_F(temp3_i, temp2_i)) + (MUL_F(temp5_r, temp4_r) + MUL_F(temp5_i, temp4_i)); IM(ac->r12) = r01i - (MUL_F(temp3_i, temp2_r) - MUL_F(temp3_r, temp2_i)) + (MUL_F(temp5_i, temp4_r) - MUL_F(temp5_r, temp4_i)); RE(ac->r22) = r11r - (MUL_F(temp2_r, temp2_r) + MUL_F(temp2_i, temp2_i)) + (MUL_F(temp4_r, temp4_r) + MUL_F(temp4_i, temp4_i)); RE(ac->r01) = r01r; IM(ac->r01) = r01i; RE(ac->r02) = r02r; IM(ac->r02) = r02i; RE(ac->r11) = r11r; ac->det = MUL_F(RE(ac->r11), RE(ac->r22)) - MUL_F((MUL_F(RE(ac->r12), RE(ac->r12)) + MUL_F(IM(ac->r12), IM(ac->r12))), rel); ac->det = ACDET_POST(ac->det); }
void reorder_ch_pcm(int16_t *pcmBuf, int nSamps, int nChans) { int i, ch, chanMap[6]; int16_t tmpBuf[6], *outbuf; switch (nChans) { case 3: chanMap[0] = 1; /* L */ chanMap[1] = 2; /* R */ chanMap[2] = 0; /* C */ break; case 4: chanMap[0] = 1; /* L */ chanMap[1] = 2; /* R */ chanMap[2] = 0; /* C */ chanMap[3] = 3; /* S */ break; case 5: chanMap[0] = 1; /* L */ chanMap[1] = 2; /* R */ chanMap[2] = 0; /* C */ chanMap[3] = 3; /* LS */ chanMap[4] = 4; /* RS */ break; case 6: chanMap[0] = 1; /* L */ chanMap[1] = 2; /* R */ chanMap[2] = 0; /* C */ chanMap[3] = 5; /* LFE */ chanMap[4] = 3; /* LS */ chanMap[5] = 4; /* RS */ break; default: return; } if(audio_output_channels < nChans){ #if 0 int32_t C, L_S, cum; outbuf = pcmBuf; for (i = 0; i < nSamps; i += nChans) { C = MUL_F(pcmBuf[0], RSQRT2); L_S = MUL_F(pcmBuf[3], RSQRT2); cum = pcmBuf[1] + C + L_S; outbuf[0] = MUL_F(cum, DM_MUL); C = MUL_F(pcmBuf[0], RSQRT2); L_S = MUL_F(pcmBuf[4], RSQRT2); cum = pcmBuf[2] + C + L_S; outbuf[1] = MUL_F(cum, DM_MUL); outbuf += 2; pcmBuf += nChans; } #else outbuf = pcmBuf; for (i = 0; i < nSamps; i += nChans) { outbuf[0] = pcmBuf[0]+pcmBuf[3]+pcmBuf[1]; outbuf[1] = pcmBuf[0]+pcmBuf[4]+pcmBuf[2]; outbuf += 2; pcmBuf += nChans; } #endif }else { for (i = 0; i < nSamps; i += nChans) { for (ch = 0; ch < nChans; ch++) tmpBuf[ch] = pcmBuf[chanMap[ch]]; for (ch = 0; ch < nChans; ch++) pcmBuf[ch] = tmpBuf[ch]; pcmBuf += nChans; } } }
/* only works for LTP -> no overlapping, no short blocks */ void filter_bank_ltp(fb_info *fb, uint8_t window_sequence, uint8_t window_shape, uint8_t window_shape_prev, real_t *in_data, real_t *out_mdct, uint8_t object_type, uint16_t frame_len) { int16_t i; ALIGN real_t windowed_buf[2*1024] = {0}; const real_t *window_long = NULL; const real_t *window_long_prev = NULL; const real_t *window_short = NULL; const real_t *window_short_prev = NULL; uint16_t nlong = frame_len; uint16_t nshort = frame_len/8; uint16_t nflat_ls = (nlong-nshort)/2; assert(window_sequence != EIGHT_SHORT_SEQUENCE); #ifdef LD_DEC if (object_type == LD) { window_long = fb->ld_window[window_shape]; window_long_prev = fb->ld_window[window_shape_prev]; } else { #endif window_long = fb->long_window[window_shape]; window_long_prev = fb->long_window[window_shape_prev]; window_short = fb->short_window[window_shape]; window_short_prev = fb->short_window[window_shape_prev]; #ifdef LD_DEC } #endif switch(window_sequence) { case ONLY_LONG_SEQUENCE: for (i = nlong-1; i >= 0; i--) { windowed_buf[i] = MUL_F(in_data[i], window_long_prev[i]); windowed_buf[i+nlong] = MUL_F(in_data[i+nlong], window_long[nlong-1-i]); } mdct(fb, windowed_buf, out_mdct, 2*nlong); break; case LONG_START_SEQUENCE: for (i = 0; i < nlong; i++) windowed_buf[i] = MUL_F(in_data[i], window_long_prev[i]); for (i = 0; i < nflat_ls; i++) windowed_buf[i+nlong] = in_data[i+nlong]; for (i = 0; i < nshort; i++) windowed_buf[i+nlong+nflat_ls] = MUL_F(in_data[i+nlong+nflat_ls], window_short[nshort-1-i]); for (i = 0; i < nflat_ls; i++) windowed_buf[i+nlong+nflat_ls+nshort] = 0; mdct(fb, windowed_buf, out_mdct, 2*nlong); break; case LONG_STOP_SEQUENCE: for (i = 0; i < nflat_ls; i++) windowed_buf[i] = 0; for (i = 0; i < nshort; i++) windowed_buf[i+nflat_ls] = MUL_F(in_data[i+nflat_ls], window_short_prev[i]); for (i = 0; i < nflat_ls; i++) windowed_buf[i+nflat_ls+nshort] = in_data[i+nflat_ls+nshort]; for (i = 0; i < nlong; i++) windowed_buf[i+nlong] = MUL_F(in_data[i+nlong], window_long[nlong-1-i]); mdct(fb, windowed_buf, out_mdct, 2*nlong); break; } }
void ifilter_bank(fb_info *fb, uint8_t window_sequence, uint8_t window_shape, uint8_t window_shape_prev, real_t *freq_in, real_t *time_out, real_t *overlap, uint8_t object_type, uint16_t frame_len) { int16_t i; ALIGN real_t transf_buf[2*1024] = {0}; const real_t *window_long = NULL; const real_t *window_long_prev = NULL; const real_t *window_short = NULL; const real_t *window_short_prev = NULL; uint16_t nlong = frame_len; uint16_t nshort = frame_len/8; uint16_t trans = nshort/2; uint16_t nflat_ls = (nlong-nshort)/2; #ifdef PROFILE int64_t count = faad_get_ts(); #endif #ifdef LD_DEC if (object_type == LD) { window_long = fb->ld_window[window_shape]; window_long_prev = fb->ld_window[window_shape_prev]; } else { #endif window_long = fb->long_window[window_shape]; window_long_prev = fb->long_window[window_shape_prev]; window_short = fb->short_window[window_shape]; window_short_prev = fb->short_window[window_shape_prev]; #ifdef LD_DEC } #endif switch (window_sequence) { case ONLY_LONG_SEQUENCE: imdct_long(fb, freq_in, transf_buf, 2*nlong); for (i = 0; i < nlong; i+=4) { time_out[i] = overlap[i] + MUL_F(transf_buf[i],window_long_prev[i]); time_out[i+1] = overlap[i+1] + MUL_F(transf_buf[i+1],window_long_prev[i+1]); time_out[i+2] = overlap[i+2] + MUL_F(transf_buf[i+2],window_long_prev[i+2]); time_out[i+3] = overlap[i+3] + MUL_F(transf_buf[i+3],window_long_prev[i+3]); } for (i = 0; i < nlong; i+=4) { overlap[i] = MUL_F(transf_buf[nlong+i],window_long[nlong-1-i]); overlap[i+1] = MUL_F(transf_buf[nlong+i+1],window_long[nlong-2-i]); overlap[i+2] = MUL_F(transf_buf[nlong+i+2],window_long[nlong-3-i]); overlap[i+3] = MUL_F(transf_buf[nlong+i+3],window_long[nlong-4-i]); } break; case LONG_START_SEQUENCE: imdct_long(fb, freq_in, transf_buf, 2*nlong); for (i = 0; i < nlong; i+=4) { time_out[i] = overlap[i] + MUL_F(transf_buf[i],window_long_prev[i]); time_out[i+1] = overlap[i+1] + MUL_F(transf_buf[i+1],window_long_prev[i+1]); time_out[i+2] = overlap[i+2] + MUL_F(transf_buf[i+2],window_long_prev[i+2]); time_out[i+3] = overlap[i+3] + MUL_F(transf_buf[i+3],window_long_prev[i+3]); } for (i = 0; i < nflat_ls; i++) overlap[i] = transf_buf[nlong+i]; for (i = 0; i < nshort; i++) overlap[nflat_ls+i] = MUL_F(transf_buf[nlong+nflat_ls+i],window_short[nshort-i-1]); for (i = 0; i < nflat_ls; i++) overlap[nflat_ls+nshort+i] = 0; break; case EIGHT_SHORT_SEQUENCE: faad_imdct(fb->mdct256, freq_in+0*nshort, transf_buf+2*nshort*0); faad_imdct(fb->mdct256, freq_in+1*nshort, transf_buf+2*nshort*1); faad_imdct(fb->mdct256, freq_in+2*nshort, transf_buf+2*nshort*2); faad_imdct(fb->mdct256, freq_in+3*nshort, transf_buf+2*nshort*3); faad_imdct(fb->mdct256, freq_in+4*nshort, transf_buf+2*nshort*4); faad_imdct(fb->mdct256, freq_in+5*nshort, transf_buf+2*nshort*5); faad_imdct(fb->mdct256, freq_in+6*nshort, transf_buf+2*nshort*6); faad_imdct(fb->mdct256, freq_in+7*nshort, transf_buf+2*nshort*7); for (i = 0; i < nflat_ls; i++) time_out[i] = overlap[i]; for(i = 0; i < nshort; i++) { time_out[nflat_ls+ i] = overlap[nflat_ls+ i] + MUL_F(transf_buf[nshort*0+i],window_short_prev[i]); time_out[nflat_ls+1*nshort+i] = overlap[nflat_ls+nshort*1+i] + MUL_F(transf_buf[nshort*1+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*2+i],window_short[i]); time_out[nflat_ls+2*nshort+i] = overlap[nflat_ls+nshort*2+i] + MUL_F(transf_buf[nshort*3+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*4+i],window_short[i]); time_out[nflat_ls+3*nshort+i] = overlap[nflat_ls+nshort*3+i] + MUL_F(transf_buf[nshort*5+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*6+i],window_short[i]); if (i < trans) time_out[nflat_ls+4*nshort+i] = overlap[nflat_ls+nshort*4+i] + MUL_F(transf_buf[nshort*7+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*8+i],window_short[i]); } for(i = 0; i < nshort; i++) { if (i >= trans) overlap[nflat_ls+4*nshort+i-nlong] = MUL_F(transf_buf[nshort*7+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*8+i],window_short[i]); overlap[nflat_ls+5*nshort+i-nlong] = MUL_F(transf_buf[nshort*9+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*10+i],window_short[i]); overlap[nflat_ls+6*nshort+i-nlong] = MUL_F(transf_buf[nshort*11+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*12+i],window_short[i]); overlap[nflat_ls+7*nshort+i-nlong] = MUL_F(transf_buf[nshort*13+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*14+i],window_short[i]); overlap[nflat_ls+8*nshort+i-nlong] = MUL_F(transf_buf[nshort*15+i],window_short[nshort-1-i]); } for (i = 0; i < nflat_ls; i++) overlap[nflat_ls+nshort+i] = 0; break; case LONG_STOP_SEQUENCE: imdct_long(fb, freq_in, transf_buf, 2*nlong); for (i = 0; i < nflat_ls; i++) time_out[i] = overlap[i]; for (i = 0; i < nshort; i++) time_out[nflat_ls+i] = overlap[nflat_ls+i] + MUL_F(transf_buf[nflat_ls+i],window_short_prev[i]); for (i = 0; i < nflat_ls; i++) time_out[nflat_ls+nshort+i] = overlap[nflat_ls+nshort+i] + transf_buf[nflat_ls+nshort+i]; for (i = 0; i < nlong; i++) overlap[i] = MUL_F(transf_buf[nlong+i],window_long[nlong-1-i]); break; } #ifdef PROFILE count = faad_get_ts() - count; fb->cycles += count; #endif }
void ifilter_bank(fb_info *fb, uint8_t window_sequence, uint8_t window_shape, uint8_t window_shape_prev, real_t *freq_in, real_t *time_out, real_t *overlap, uint8_t object_type, uint16_t frame_len) { int16_t i; ALIGN real_t transf_buf[2*1024] = {0}; const real_t *window_long = NULL; const real_t *window_long_prev = NULL; const real_t *window_short = NULL; const real_t *window_short_prev = NULL; uint16_t nlong = frame_len; uint16_t nshort = frame_len/8; uint16_t trans = nshort/2; uint16_t nflat_ls = (nlong-nshort)/2; #ifdef PROFILE int64_t count = faad_get_ts(); #endif /* select windows of current frame and previous frame (Sine or KBD) */ #ifdef LD_DEC if (object_type == LD) { window_long = fb->ld_window[window_shape]; window_long_prev = fb->ld_window[window_shape_prev]; } else { #endif window_long = fb->long_window[window_shape]; window_long_prev = fb->long_window[window_shape_prev]; window_short = fb->short_window[window_shape]; window_short_prev = fb->short_window[window_shape_prev]; #ifdef LD_DEC } #endif #if 0 for (i = 0; i < 1024; i++) { printf("%d\n", freq_in[i]); } #endif #if 0 printf("%d %d\n", window_sequence, window_shape); #endif switch (window_sequence) { case ONLY_LONG_SEQUENCE: /* perform iMDCT */ imdct_long(fb, freq_in, transf_buf, 2*nlong); /* add second half output of previous frame to windowed output of current frame */ for (i = 0; i < nlong; i+=4) { time_out[i] = overlap[i] + MUL_F(transf_buf[i],window_long_prev[i]); time_out[i+1] = overlap[i+1] + MUL_F(transf_buf[i+1],window_long_prev[i+1]); time_out[i+2] = overlap[i+2] + MUL_F(transf_buf[i+2],window_long_prev[i+2]); time_out[i+3] = overlap[i+3] + MUL_F(transf_buf[i+3],window_long_prev[i+3]); } /* window the second half and save as overlap for next frame */ for (i = 0; i < nlong; i+=4) { overlap[i] = MUL_F(transf_buf[nlong+i],window_long[nlong-1-i]); overlap[i+1] = MUL_F(transf_buf[nlong+i+1],window_long[nlong-2-i]); overlap[i+2] = MUL_F(transf_buf[nlong+i+2],window_long[nlong-3-i]); overlap[i+3] = MUL_F(transf_buf[nlong+i+3],window_long[nlong-4-i]); } break; case LONG_START_SEQUENCE: /* perform iMDCT */ imdct_long(fb, freq_in, transf_buf, 2*nlong); /* add second half output of previous frame to windowed output of current frame */ for (i = 0; i < nlong; i+=4) { time_out[i] = overlap[i] + MUL_F(transf_buf[i],window_long_prev[i]); time_out[i+1] = overlap[i+1] + MUL_F(transf_buf[i+1],window_long_prev[i+1]); time_out[i+2] = overlap[i+2] + MUL_F(transf_buf[i+2],window_long_prev[i+2]); time_out[i+3] = overlap[i+3] + MUL_F(transf_buf[i+3],window_long_prev[i+3]); } /* window the second half and save as overlap for next frame */ /* construct second half window using padding with 1's and 0's */ for (i = 0; i < nflat_ls; i++) overlap[i] = transf_buf[nlong+i]; for (i = 0; i < nshort; i++) overlap[nflat_ls+i] = MUL_F(transf_buf[nlong+nflat_ls+i],window_short[nshort-i-1]); for (i = 0; i < nflat_ls; i++) overlap[nflat_ls+nshort+i] = 0; break; case EIGHT_SHORT_SEQUENCE: /* perform iMDCT for each short block */ faad_imdct(fb->mdct256, freq_in+0*nshort, transf_buf+2*nshort*0); faad_imdct(fb->mdct256, freq_in+1*nshort, transf_buf+2*nshort*1); faad_imdct(fb->mdct256, freq_in+2*nshort, transf_buf+2*nshort*2); faad_imdct(fb->mdct256, freq_in+3*nshort, transf_buf+2*nshort*3); faad_imdct(fb->mdct256, freq_in+4*nshort, transf_buf+2*nshort*4); faad_imdct(fb->mdct256, freq_in+5*nshort, transf_buf+2*nshort*5); faad_imdct(fb->mdct256, freq_in+6*nshort, transf_buf+2*nshort*6); faad_imdct(fb->mdct256, freq_in+7*nshort, transf_buf+2*nshort*7); /* add second half output of previous frame to windowed output of current frame */ for (i = 0; i < nflat_ls; i++) time_out[i] = overlap[i]; for(i = 0; i < nshort; i++) { time_out[nflat_ls+ i] = overlap[nflat_ls+ i] + MUL_F(transf_buf[nshort*0+i],window_short_prev[i]); time_out[nflat_ls+1*nshort+i] = overlap[nflat_ls+nshort*1+i] + MUL_F(transf_buf[nshort*1+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*2+i],window_short[i]); time_out[nflat_ls+2*nshort+i] = overlap[nflat_ls+nshort*2+i] + MUL_F(transf_buf[nshort*3+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*4+i],window_short[i]); time_out[nflat_ls+3*nshort+i] = overlap[nflat_ls+nshort*3+i] + MUL_F(transf_buf[nshort*5+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*6+i],window_short[i]); if (i < trans) time_out[nflat_ls+4*nshort+i] = overlap[nflat_ls+nshort*4+i] + MUL_F(transf_buf[nshort*7+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*8+i],window_short[i]); } /* window the second half and save as overlap for next frame */ for(i = 0; i < nshort; i++) { if (i >= trans) overlap[nflat_ls+4*nshort+i-nlong] = MUL_F(transf_buf[nshort*7+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*8+i],window_short[i]); overlap[nflat_ls+5*nshort+i-nlong] = MUL_F(transf_buf[nshort*9+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*10+i],window_short[i]); overlap[nflat_ls+6*nshort+i-nlong] = MUL_F(transf_buf[nshort*11+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*12+i],window_short[i]); overlap[nflat_ls+7*nshort+i-nlong] = MUL_F(transf_buf[nshort*13+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*14+i],window_short[i]); overlap[nflat_ls+8*nshort+i-nlong] = MUL_F(transf_buf[nshort*15+i],window_short[nshort-1-i]); } for (i = 0; i < nflat_ls; i++) overlap[nflat_ls+nshort+i] = 0; break; case LONG_STOP_SEQUENCE: /* perform iMDCT */ imdct_long(fb, freq_in, transf_buf, 2*nlong); /* add second half output of previous frame to windowed output of current frame */ /* construct first half window using padding with 1's and 0's */ for (i = 0; i < nflat_ls; i++) time_out[i] = overlap[i]; for (i = 0; i < nshort; i++) time_out[nflat_ls+i] = overlap[nflat_ls+i] + MUL_F(transf_buf[nflat_ls+i],window_short_prev[i]); for (i = 0; i < nflat_ls; i++) time_out[nflat_ls+nshort+i] = overlap[nflat_ls+nshort+i] + transf_buf[nflat_ls+nshort+i]; /* window the second half and save as overlap for next frame */ for (i = 0; i < nlong; i++) overlap[i] = MUL_F(transf_buf[nlong+i],window_long[nlong-1-i]); break; } #if 0 for (i = 0; i < 1024; i++) { printf("%d\n", time_out[i]); //printf("0x%.8X\n", time_out[i]); } #endif #ifdef PROFILE count = faad_get_ts() - count; fb->cycles += count; #endif }
static void passf3(const uint16_t ido, const uint16_t l1, const complex_t *cc, complex_t *ch, const complex_t *wa1, const complex_t *wa2, const int8_t isign) { static real_t taur = FRAC_CONST(-0.5); static real_t taui = FRAC_CONST(0.866025403784439); uint16_t i, k, ac, ah; complex_t c2, c3, d2, d3, t2; if (ido == 1) { if (isign == 1) { for (k = 0; k < l1; k++) { ac = 3*k+1; ah = k; RE(t2) = RE(cc[ac]) + RE(cc[ac+1]); IM(t2) = IM(cc[ac]) + IM(cc[ac+1]); RE(c2) = RE(cc[ac-1]) + MUL_F(RE(t2),taur); IM(c2) = IM(cc[ac-1]) + MUL_F(IM(t2),taur); RE(ch[ah]) = RE(cc[ac-1]) + RE(t2); IM(ch[ah]) = IM(cc[ac-1]) + IM(t2); RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+1])), taui); IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+1])), taui); RE(ch[ah+l1]) = RE(c2) - IM(c3); IM(ch[ah+l1]) = IM(c2) + RE(c3); RE(ch[ah+2*l1]) = RE(c2) + IM(c3); IM(ch[ah+2*l1]) = IM(c2) - RE(c3); } } else { for (k = 0; k < l1; k++) { ac = 3*k+1; ah = k; RE(t2) = RE(cc[ac]) + RE(cc[ac+1]); IM(t2) = IM(cc[ac]) + IM(cc[ac+1]); RE(c2) = RE(cc[ac-1]) + MUL_F(RE(t2),taur); IM(c2) = IM(cc[ac-1]) + MUL_F(IM(t2),taur); RE(ch[ah]) = RE(cc[ac-1]) + RE(t2); IM(ch[ah]) = IM(cc[ac-1]) + IM(t2); RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+1])), taui); IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+1])), taui); RE(ch[ah+l1]) = RE(c2) + IM(c3); IM(ch[ah+l1]) = IM(c2) - RE(c3); RE(ch[ah+2*l1]) = RE(c2) - IM(c3); IM(ch[ah+2*l1]) = IM(c2) + RE(c3); } } } else { if (isign == 1) { for (k = 0; k < l1; k++) { for (i = 0; i < ido; i++) { ac = i + (3*k+1)*ido; ah = i + k * ido; RE(t2) = RE(cc[ac]) + RE(cc[ac+ido]); RE(c2) = RE(cc[ac-ido]) + MUL_F(RE(t2),taur); IM(t2) = IM(cc[ac]) + IM(cc[ac+ido]); IM(c2) = IM(cc[ac-ido]) + MUL_F(IM(t2),taur); RE(ch[ah]) = RE(cc[ac-ido]) + RE(t2); IM(ch[ah]) = IM(cc[ac-ido]) + IM(t2); RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+ido])), taui); IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+ido])), taui); RE(d2) = RE(c2) - IM(c3); IM(d3) = IM(c2) - RE(c3); RE(d3) = RE(c2) + IM(c3); IM(d2) = IM(c2) + RE(c3); #if 1 ComplexMult(&IM(ch[ah+l1*ido]), &RE(ch[ah+l1*ido]), IM(d2), RE(d2), RE(wa1[i]), IM(wa1[i])); ComplexMult(&IM(ch[ah+2*l1*ido]), &RE(ch[ah+2*l1*ido]), IM(d3), RE(d3), RE(wa2[i]), IM(wa2[i])); #else ComplexMult(&RE(ch[ah+l1*ido]), &IM(ch[ah+l1*ido]), RE(d2), IM(d2), RE(wa1[i]), IM(wa1[i])); ComplexMult(&RE(ch[ah+2*l1*ido]), &IM(ch[ah+2*l1*ido]), RE(d3), IM(d3), RE(wa2[i]), IM(wa2[i])); #endif } } } else { for (k = 0; k < l1; k++) { for (i = 0; i < ido; i++) { ac = i + (3*k+1)*ido; ah = i + k * ido; RE(t2) = RE(cc[ac]) + RE(cc[ac+ido]); RE(c2) = RE(cc[ac-ido]) + MUL_F(RE(t2),taur); IM(t2) = IM(cc[ac]) + IM(cc[ac+ido]); IM(c2) = IM(cc[ac-ido]) + MUL_F(IM(t2),taur); RE(ch[ah]) = RE(cc[ac-ido]) + RE(t2); IM(ch[ah]) = IM(cc[ac-ido]) + IM(t2); RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+ido])), taui); IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+ido])), taui); RE(d2) = RE(c2) + IM(c3); IM(d3) = IM(c2) + RE(c3); RE(d3) = RE(c2) - IM(c3); IM(d2) = IM(c2) - RE(c3); #if 1 ComplexMult(&RE(ch[ah+l1*ido]), &IM(ch[ah+l1*ido]), RE(d2), IM(d2), RE(wa1[i]), IM(wa1[i])); ComplexMult(&RE(ch[ah+2*l1*ido]), &IM(ch[ah+2*l1*ido]), RE(d3), IM(d3), RE(wa2[i]), IM(wa2[i])); #else ComplexMult(&IM(ch[ah+l1*ido]), &RE(ch[ah+l1*ido]), IM(d2), RE(d2), RE(wa1[i]), IM(wa1[i])); ComplexMult(&IM(ch[ah+2*l1*ido]), &RE(ch[ah+2*l1*ido]), IM(d3), RE(d3), RE(wa2[i]), IM(wa2[i])); #endif } } } } }
static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj, qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch) { static real_t h_smooth[] = { COEF_CONST(0.03183050093751), COEF_CONST(0.11516383427084), COEF_CONST(0.21816949906249), COEF_CONST(0.30150283239582), COEF_CONST(0.33333333333333) }; static int8_t phi_re[] = { 1, 0, -1, 0 }; static int8_t phi_im[] = { 0, 1, 0, -1 }; uint8_t m, l, i, n; uint16_t fIndexNoise = 0; uint8_t fIndexSine = 0; uint8_t assembly_reset = 0; real_t *temp; real_t G_filt, Q_filt; uint8_t h_SL; if (sbr->Reset == 1) { assembly_reset = 1; fIndexNoise = 0; } else { fIndexNoise = sbr->index_noise_prev[ch]; } fIndexSine = sbr->psi_is_prev[ch]; for (l = 0; l < sbr->L_E[ch]; l++) { uint8_t no_noise = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 1 : 0; #ifdef SBR_LOW_POWER h_SL = 0; #else h_SL = (sbr->bs_smoothing_mode == 1) ? 0 : 4; h_SL = (no_noise ? 0 : h_SL); #endif if (assembly_reset) { for (n = 0; n < 4; n++) { memcpy(sbr->G_temp_prev[ch][n], adj->G_lim_boost[l], sbr->M*sizeof(real_t)); memcpy(sbr->Q_temp_prev[ch][n], adj->Q_M_lim_boost[l], sbr->M*sizeof(real_t)); } assembly_reset = 0; } for (i = sbr->t_E[ch][l]; i < sbr->t_E[ch][l+1]; i++) { #ifdef SBR_LOW_POWER uint8_t i_min1, i_plus1; uint8_t sinusoids = 0; #endif memcpy(sbr->G_temp_prev[ch][4], adj->G_lim_boost[l], sbr->M*sizeof(real_t)); memcpy(sbr->Q_temp_prev[ch][4], adj->Q_M_lim_boost[l], sbr->M*sizeof(real_t)); for (m = 0; m < sbr->M; m++) { uint8_t j; qmf_t psi; G_filt = 0; Q_filt = 0; j = 0; if (h_SL != 0) { for (n = 0; n <= 4; n++) { G_filt += MUL_C(sbr->G_temp_prev[ch][n][m], h_smooth[j]); Q_filt += MUL_C(sbr->Q_temp_prev[ch][n][m], h_smooth[j]); j++; } } else { G_filt = sbr->G_temp_prev[ch][4][m]; Q_filt = sbr->Q_temp_prev[ch][4][m]; } Q_filt = (adj->S_M_boost[l][m] != 0 || no_noise) ? 0 : Q_filt; /* add noise to the output */ fIndexNoise = (fIndexNoise + 1) & 511; /* the smoothed gain values are applied to Xsbr */ /* V is defined, not calculated */ QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = MUL_R(G_filt, QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx])) + MUL_F(Q_filt, RE(V[fIndexNoise])); if (sbr->bs_extension_id == 3 && sbr->bs_extension_data == 42) QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = 16428320; #ifndef SBR_LOW_POWER QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = MUL_R(G_filt, QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx])) + MUL_F(Q_filt, IM(V[fIndexNoise])); #endif //if (adj->S_index_mapped[m][l]) { int8_t rev = (((m + sbr->kx) & 1) ? -1 : 1); QMF_RE(psi) = MUL_R(adj->S_M_boost[l][m], phi_re[fIndexSine]); QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) += QMF_RE(psi); #ifndef SBR_LOW_POWER QMF_IM(psi) = rev * MUL_R(adj->S_M_boost[l][m], phi_im[fIndexSine]); QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) += QMF_IM(psi); #else i_min1 = (fIndexSine - 1) & 3; i_plus1 = (fIndexSine + 1) & 3; if (m == 0) { QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx - 1]) -= (-1*rev * MUL_C(MUL_R(adj->S_M_boost[l][0], phi_re[i_plus1]), COEF_CONST(0.00815))); if(m < sbr->M - 1) { QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -= (rev * MUL_C(MUL_R(adj->S_M_boost[l][1], phi_re[i_plus1]), COEF_CONST(0.00815))); } } if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16)) { QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -= (rev * MUL_C(MUL_R(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815))); QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -= (rev * MUL_C(MUL_R(adj->S_M_boost[l][m + 1], phi_re[i_plus1]), COEF_CONST(0.00815))); } if ((m == sbr->M - 1) && (sinusoids < 16)) { if (m > 0) { QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -= (rev * MUL_C(MUL_R(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815))); } if (m + sbr->kx < 64) { QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx + 1]) -= (-1*rev * MUL_C(MUL_R(adj->S_M_boost[l][m], phi_re[i_min1]), COEF_CONST(0.00815))); } } if (adj->S_M_boost[l][m] != 0) sinusoids++; #endif } } fIndexSine = (fIndexSine + 1) & 3; temp = sbr->G_temp_prev[ch][0]; for (n = 0; n < 4; n++) sbr->G_temp_prev[ch][n] = sbr->G_temp_prev[ch][n+1]; sbr->G_temp_prev[ch][4] = temp; temp = sbr->Q_temp_prev[ch][0]; for (n = 0; n < 4; n++) sbr->Q_temp_prev[ch][n] = sbr->Q_temp_prev[ch][n+1]; sbr->Q_temp_prev[ch][4] = temp; } } sbr->index_noise_prev[ch] = fIndexNoise; sbr->psi_is_prev[ch] = fIndexSine; }