#include "int_types.h"
#include "ac3_decoder.h"
-#include "ac3_imdct.h"
+#include "ac3_internal.h"
void imdct_do_256(float x[],float y[],float delay[]);
void imdct_do_512(float x[],float y[],float delay[]);
-typedef struct complex_s
-{
+typedef struct complex_s {
float real;
float imag;
} complex_t;
return ret;
}
-void imdct_init(void)
+static void imdct_init(void) __attribute__ ((__constructor__));
+static void imdct_init(void)
{
int i,k;
complex_t angle_step;
complex_t current_angle;
/* Twiddle factors to turn IFFT into IMDCT */
- for( i=0; i < N/4; i++)
- {
+ for (i=0; i < N/4; i++) {
xcos1[i] = -cos(2 * M_PI * (8*i+1)/(8*N)) ;
xsin1[i] = -sin(2 * M_PI * (8*i+1)/(8*N)) ;
}
/* More twiddle factors to turn IFFT into IMDCT */
- for( i=0; i < N/8; i++)
- {
+ for (i=0; i < N/8; i++) {
xcos2[i] = -cos(2 * M_PI * (8*i+1)/(4*N)) ;
xsin2[i] = -sin(2 * M_PI * (8*i+1)/(4*N)) ;
}
w[5] = w_32;
w[6] = w_64;
- for( i = 0; i < 7; i++)
- {
+ for (i = 0; i < 7; i++) {
angle_step.real = cos(-2.0f * M_PI / (1 << (i+1)));
angle_step.imag = sin(-2.0f * M_PI / (1 << (i+1)));
current_angle.real = 1.0f;
current_angle.imag = 0.0f;
- for (k = 0; k < 1 << i; k++)
- {
+ for (k = 0; k < 1 << i; k++) {
w[i][k] = current_angle;
current_angle = cmplx_mult(current_angle,angle_step);
}
}
}
-void imdct( ac3dec_t * p_ac3dec )
+void imdct (ac3dec_t * p_ac3dec)
{
int i;
- for(i=0; i<p_ac3dec->bsi.nfchans;i++)
- {
- if(p_ac3dec->audblk.blksw[i])
+ for (i=0; i<p_ac3dec->bsi.nfchans;i++) {
+ if (p_ac3dec->audblk.blksw[i])
imdct_do_256(p_ac3dec->coeffs.fbw[i],p_ac3dec->samples.channel[i],delay[i]);
else
imdct_do_512(p_ac3dec->coeffs.fbw[i],p_ac3dec->samples.channel[i],delay[i]);
float *window_ptr;
/* Pre IFFT complex multiply plus IFFT cmplx conjugate */
- for( i=0; i < N/4; i++)
- {
+ for (i=0; i < N/4; i++) {
/* z[i] = (X[N/2-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */
- buf[i].real = (x[N/2-2*i-1] * xcos1[i]) - (x[2*i] * xsin1[i]);
- buf[i].imag = -((x[2*i] * xcos1[i]) + (x[N/2-2*i-1] * xsin1[i]));
+ buf[i].real = (x[N/2-2*i-1] * xcos1[i]) - (x[2*i] * xsin1[i]);
+ buf[i].imag = -((x[2*i] * xcos1[i]) + (x[N/2-2*i-1] * xsin1[i]));
}
/* Bit reversed shuffling */
- for(i=0; i<N/4; i++)
- {
+ for (i=0; i<N/4; i++) {
k = bit_reverse_512[i];
if (k < i)
swap_cmplx(&buf[i],&buf[k]);
}
/* FFT Merge */
- for (m=0; m < 7; m++)
- {
+ for (m=0; m < 7; m++) {
two_m = (1 << m);
two_m_plus_one = (1 << (m+1));
- for(k = 0; k < two_m; k++)
- {
- for(i = 0; i < 128; i += two_m_plus_one)
- {
+ for (k = 0; k < two_m; k++) {
+ for (i = 0; i < 128; i += two_m_plus_one) {
p = k + i;
q = p + two_m;
tmp_a_r = buf[p].real;
buf[p].imag = tmp_a_i + tmp_b_i;
buf[q].real = tmp_a_r - tmp_b_r;
buf[q].imag = tmp_a_i - tmp_b_i;
-
}
}
}
/* Post IFFT complex multiply plus IFFT complex conjugate*/
- for( i=0; i < N/4; i++)
- {
+ for (i=0; i < N/4; i++) {
/* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
tmp_a_r = buf[i].real;
tmp_a_i = - buf[i].imag;
- buf[i].real =(tmp_a_r * xcos1[i]) - (tmp_a_i * xsin1[i]);
- buf[i].imag =(tmp_a_r * xsin1[i]) + (tmp_a_i * xcos1[i]);
+ buf[i].real =(tmp_a_r * xcos1[i]) - (tmp_a_i * xsin1[i]);
+ buf[i].imag =(tmp_a_r * xsin1[i]) + (tmp_a_i * xcos1[i]);
}
- y_ptr = y;
+ y_ptr = y;
delay_ptr = delay;
window_ptr = window;
/* Window and convert to real valued signal */
- for(i=0; i<N/8; i++)
- {
+ for (i=0; i<N/8; i++) {
*y_ptr++ = 2.0f * (-buf[N/8+i].imag * *window_ptr++ + *delay_ptr++);
- *y_ptr++ = 2.0f * ( buf[N/8-i-1].real * *window_ptr++ + *delay_ptr++);
+ *y_ptr++ = 2.0f * (buf[N/8-i-1].real * *window_ptr++ + *delay_ptr++);
}
- for(i=0; i<N/8; i++)
- {
+ for (i=0; i<N/8; i++) {
*y_ptr++ = 2.0f * (-buf[i].real * *window_ptr++ + *delay_ptr++);
- *y_ptr++ = 2.0f * ( buf[N/4-i-1].imag * *window_ptr++ + *delay_ptr++);
+ *y_ptr++ = 2.0f * (buf[N/4-i-1].imag * *window_ptr++ + *delay_ptr++);
}
/* The trailing edge of the window goes into the delay line */
delay_ptr = delay;
- for(i=0; i<N/8; i++)
- {
+ for (i=0; i<N/8; i++) {
*delay_ptr++ = -buf[N/8+i].real * *--window_ptr;
*delay_ptr++ = buf[N/8-i-1].imag * *--window_ptr;
}
- for(i=0; i<N/8; i++)
- {
+ for (i=0; i<N/8; i++) {
*delay_ptr++ = buf[i].imag * *--window_ptr;
*delay_ptr++ = -buf[N/4-i-1].real * *--window_ptr;
}
buf_2 = &buf[64];
/* Pre IFFT complex multiply plus IFFT cmplx conjugate */
- for(k=0; k<N/8; k++)
- {
+ for (k=0; k<N/8; k++) {
/* X1[k] = X[2*k] */
/* X2[k] = X[2*k+1] */
}
/* IFFT Bit reversed shuffling */
- for(i=0; i<N/8; i++)
- {
+ for (i=0; i<N/8; i++) {
k = bit_reverse_256[i];
- if (k < i)
- {
+ if (k < i) {
swap_cmplx(&buf_1[i],&buf_1[k]);
swap_cmplx(&buf_2[i],&buf_2[k]);
}
}
/* FFT Merge */
- for (m=0; m < 6; m++)
- {
+ for (m=0; m < 6; m++) {
two_m = (1 << m);
two_m_plus_one = (1 << (m+1));
- for(k = 0; k < two_m; k++)
- {
- for(i = 0; i < 64; i += two_m_plus_one)
- {
+ for (k = 0; k < two_m; k++) {
+ for (i = 0; i < 64; i += two_m_plus_one) {
p = k + i;
q = p + two_m;
/* Do block 1 */
buf_2[p].imag = tmp_a_i + tmp_b_i;
buf_2[q].real = tmp_a_r - tmp_b_r;
buf_2[q].imag = tmp_a_i - tmp_b_i;
-
}
}
}
/* Post IFFT complex multiply */
- for( i=0; i < N/8; i++)
- {
+ for (i=0; i < N/8; i++) {
/* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
tmp_a_r = buf_1[i].real;
tmp_a_i = - buf_1[i].imag;
- buf_1[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]);
- buf_1[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]);
+ buf_1[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]);
+ buf_1[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]);
/* y2[n] = z2[n] * (xcos2[n] + j * xsin2[n]) ; */
tmp_a_r = buf_2[i].real;
tmp_a_i = - buf_2[i].imag;
- buf_2[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]);
- buf_2[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]);
+ buf_2[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]);
+ buf_2[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]);
}
/* Window and convert to real valued signal */
- for(i=0; i<N/8; i++)
- {
+ for (i=0; i<N/8; i++) {
y[2*i] = -buf_1[i].imag * window[2*i];
y[2*i+1] = buf_1[N/8-i-1].real * window[2*i+1];
y[N/4+2*i] = -buf_1[i].real * window[N/4+2*i];
}
/* Overlap and add */
- for(i=0; i<N/2; i++)
- {
+ for (i=0; i<N/2; i++) {
y[i] = 2 * (y[i] + delay[i]);
delay[i] = y[N/2+i];
}