Commit 6ab6f7ac authored by Renaud Dartus's avatar Renaud Dartus

* Follow of the new ac3_decoder ;)

  - New ac3_imdct
  - New ac3_downmix
parent cd74cb2c
......@@ -70,6 +70,8 @@ AC3_DECODER = src/ac3_decoder/ac3_decoder_thread.o \
src/ac3_decoder/ac3_mantissa.o \
src/ac3_decoder/ac3_rematrix.o \
src/ac3_decoder/ac3_imdct.o \
src/ac3_decoder/ac3_imdct_c.o \
src/ac3_decoder/ac3_srfft.o \
src/ac3_decoder/ac3_downmix.o \
src/ac3_decoder/ac3_downmix_c.o
......
......@@ -2,7 +2,7 @@
* ac3_decoder.c: core ac3 decoder
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: ac3_decoder.c,v 1.29 2001/04/20 12:14:34 reno Exp $
* $Id: ac3_decoder.c,v 1.30 2001/04/30 21:04:20 reno Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Michel Lespinasse <walken@zoy.org>
......@@ -45,6 +45,10 @@
#include <stdio.h>
void imdct_init (imdct_t * p_imdct);
void downmix_init (downmix_t * p_downmix);
static float cmixlev_lut[4] = { 0.707, 0.595, 0.500, 0.707 };
static float smixlev_lut[4] = { 0.707, 0.500, 0.0 , 0.500 };
int ac3_init (ac3dec_t * p_ac3dec)
{
......@@ -52,6 +56,7 @@ int ac3_init (ac3dec_t * p_ac3dec)
// p_ac3dec->bit_stream.i_available = 0;
p_ac3dec->mantissa.lfsr_state = 1; /* dither_gen initialization */
imdct_init(&p_ac3dec->imdct);
downmix_init(&p_ac3dec->downmix);
return 0;
}
......@@ -68,7 +73,27 @@ int ac3_decode_frame (ac3dec_t * p_ac3dec, s16 * buffer)
return 1;
}
/* compute downmix parameters
* downmix to tow channels for now */
p_ac3dec->dm_par.clev = 0.0;
p_ac3dec->dm_par.slev = 0.0;
p_ac3dec->dm_par.unit = 1.0;
if (p_ac3dec->bsi.acmod & 0x1) /* have center */
p_ac3dec->dm_par.clev = cmixlev_lut[p_ac3dec->bsi.cmixlev];
if (p_ac3dec->bsi.acmod & 0x4) /* have surround channels */
p_ac3dec->dm_par.slev = smixlev_lut[p_ac3dec->bsi.surmixlev];
p_ac3dec->dm_par.unit /= 1.0 + p_ac3dec->dm_par.clev + p_ac3dec->dm_par.slev;
p_ac3dec->dm_par.clev *= p_ac3dec->dm_par.unit;
p_ac3dec->dm_par.slev *= p_ac3dec->dm_par.unit;
for (i = 0; i < 6; i++) {
/* Initialize freq/time sample storage */
memset(p_ac3dec->samples, 0, sizeof(float) * 256 *
(p_ac3dec->bsi.nfchans + p_ac3dec->bsi.lfeon));
if ((p_ac3dec_t->p_fifo->b_die) && (p_ac3dec_t->p_fifo->b_error))
{
return 1;
......
......@@ -2,7 +2,7 @@
* ac3_decoder.h : ac3 decoder interface
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: ac3_decoder.h,v 1.6 2001/04/26 00:12:19 reno Exp $
* $Id: ac3_decoder.h,v 1.7 2001/04/30 21:04:20 reno Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Renaud Dartus <reno@videolan.org>
......@@ -308,6 +308,7 @@ typedef struct audblk_s {
} audblk_t;
/* Everything you wanted to know about band structure */
/*
* The entire frequency domain is represented by 256 real
* floating point fourier coefficients. Only the lower 253
......@@ -326,17 +327,6 @@ typedef struct audblk_s {
* approximate a 1/6 octave scale.
*/
typedef struct stream_coeffs_s
{
float fbw[5][256];
float lfe[256];
} stream_coeffs_t;
typedef struct stream_samples_s
{
float channel[6][256];
} stream_samples_t;
typedef struct bit_allocate_s
{
s16 psd[256];
......@@ -375,6 +365,7 @@ typedef struct imdct_s
/* Delay buffer for time domain interleaving */
float delay[6][256];
float delay1[6][256];
/* Twiddle factors for IMDCT */
float xcos1[N/4];
......@@ -392,8 +383,32 @@ typedef struct imdct_s
complex_t w_32[32];
complex_t w_64[64];
float xcos_sin_sse[128 * 4] __attribute__((aligned(16)));
/* Functions */
void (*fft_64p) (complex_t *a);
void (*imdct_do_512)(struct imdct_s * p_imdct, float data[], float delay[]);
void (*imdct_do_512_nol)(struct imdct_s * p_imdct, float data[], float delay[]);
} imdct_t;
typedef struct dm_par_s {
float unit;
float clev;
float slev;
} dm_par_t;
typedef struct downmix_s {
void (*downmix_3f_2r_to_2ch)(float *samples, dm_par_t * dm_par);
void (*downmix_3f_1r_to_2ch)(float *samples, dm_par_t * dm_par);
void (*downmix_2f_2r_to_2ch)(float *samples, dm_par_t * dm_par);
void (*downmix_2f_1r_to_2ch)(float *samples, dm_par_t * dm_par);
void (*downmix_3f_0r_to_2ch)(float *samples, dm_par_t * dm_par);
void (*stream_sample_2ch_to_s16)(s16 *s16_samples, float *left, float *right);
void (*stream_sample_1ch_to_s16)(s16 *s16_samples, float *center);
} downmix_t;
struct ac3dec_s
{
/*
......@@ -412,10 +427,12 @@ struct ac3dec_s
bsi_t bsi;
audblk_t audblk;
stream_coeffs_t coeffs;
stream_samples_t samples;
float samples[6][256];
dm_par_t dm_par;
bit_allocate_t bit_allocate;
mantissa_t mantissa;
imdct_t imdct;
downmix_t downmix;
};
......@@ -2,7 +2,7 @@
* ac3_decoder_thread.c: ac3 decoder thread
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: ac3_decoder_thread.c,v 1.29 2001/04/25 10:22:32 massiot Exp $
* $Id: ac3_decoder_thread.c,v 1.30 2001/04/30 21:04:20 reno Exp $
*
* Authors: Michel Lespinasse <walken@zoy.org>
*
......@@ -170,6 +170,7 @@ static void RunThread (ac3dec_thread_t * p_ac3dec_t)
{
s16 * buffer;
ac3_sync_info_t sync_info;
int ptr;
if (!sync) {
do {
......@@ -177,6 +178,14 @@ static void RunThread (ac3dec_thread_t * p_ac3dec_t)
} while ((!p_ac3dec_t->sync_ptr) && (!p_ac3dec_t->p_fifo->b_die)
&& (!p_ac3dec_t->p_fifo->b_error));
ptr = p_ac3dec_t->sync_ptr;
while(ptr-- && (!p_ac3dec_t->p_fifo->b_die)
&& (!p_ac3dec_t->p_fifo->b_error))
{
p_ac3dec_t->ac3_decoder.bit_stream.p_byte++;
}
/* we are in sync now */
sync = 1;
}
......
......@@ -2,7 +2,7 @@
* ac3_downmix.c: ac3 downmix functions
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: ac3_downmix.c,v 1.20 2001/04/20 12:14:34 reno Exp $
* $Id: ac3_downmix.c,v 1.21 2001/04/30 21:04:20 reno Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Aaron Holtzman <aholtzma@engr.uvic.ca>
......@@ -29,72 +29,36 @@
#include "threads.h"
#include "mtime.h"
#include "tests.h"
#include "stream_control.h"
#include "input_ext-dec.h"
#include "ac3_decoder.h"
#include "ac3_internal.h"
#include "ac3_downmix.h"
/* Pre-scaled downmix coefficients */
static const float cmixlev_lut[4] = { 0.2928, 0.2468, 0.2071, 0.2468 };
static const float smixlev_lut[4] = { 0.2928, 0.2071, 0.0 , 0.2071 };
/* Downmix into _two_ channels...other downmix modes aren't implemented
* to reduce complexity. Realistically, there aren't many machines around
* with > 2 channel output anyways */
int __inline__ downmix (ac3dec_t * p_ac3dec, float * channel, s16 * out_buf)
void downmix_init (downmix_t * p_downmix)
{
dm_par_t dm_par;
dm_par.clev = 0.0;
dm_par.slev = 0.0;
dm_par.unit = 1.0;
if (p_ac3dec->bsi.acmod & 0x1) /* have center */
dm_par.clev = cmixlev_lut[p_ac3dec->bsi.cmixlev];
if (p_ac3dec->bsi.acmod & 0x4) /* have surround channels */
dm_par.slev = smixlev_lut[p_ac3dec->bsi.surmixlev];
dm_par.unit /= 1.0 + dm_par.clev + dm_par.slev;
dm_par.clev *= dm_par.unit;
dm_par.slev *= dm_par.unit;
/*
if (p_ac3dec->bsi.acmod > 7)
intf_ErrMsg( "ac3dec: (downmix) invalid acmod number" );
*/
switch(p_ac3dec->bsi.acmod)
#if 0
if ( TestCPU (CPU_CAPABILITY_MMX) )
{
fprintf(stderr,"Using MMX for downmix\n");
p_downmix->downmix_3f_2r_to_2ch = downmix_3f_2r_to_2ch_kni;
p_downmix->downmix_2f_2r_to_2ch = downmix_2f_2r_to_2ch_kni;
p_downmix->downmix_3f_1r_to_2ch = downmix_3f_1r_to_2ch_kni;
p_downmix->downmix_2f_1r_to_2ch = downmix_2f_1r_to_2ch_kni;
p_downmix->downmix_3f_0r_to_2ch = downmix_3f_0r_to_2ch_kni;
p_downmix->stream_sample_2ch_to_s16 = stream_sample_2ch_to_s16_kni;
p_downmix->stream_sample_1ch_to_s16 = stream_sample_1ch_to_s16_kni;
} else
#endif
{
case 7: // 3/2
downmix_3f_2r_to_2ch_c (channel, &dm_par);
break;
case 6: // 2/2
downmix_2f_2r_to_2ch_c (channel, &dm_par);
break;
case 5: // 3/1
downmix_3f_1r_to_2ch_c (channel, &dm_par);
break;
case 4: // 2/1
downmix_2f_1r_to_2ch_c (channel, &dm_par);
break;
case 3: // 3/0
downmix_3f_0r_to_2ch_c (channel, &dm_par);
break;
case 2:
break;
default: // 1/0
/* FIXME
if (p_ac3dec->bsi.acmod == 1)
center = p_ac3dec->samples.channel[0];
else if (p_ac3dec->bsi.acmod == 0)
center = p_ac3dec->samples.channel[0]; */
return 1;
p_downmix->downmix_3f_2r_to_2ch = downmix_3f_2r_to_2ch_c;
p_downmix->downmix_2f_2r_to_2ch = downmix_2f_2r_to_2ch_c;
p_downmix->downmix_3f_1r_to_2ch = downmix_3f_1r_to_2ch_c;
p_downmix->downmix_2f_1r_to_2ch = downmix_2f_1r_to_2ch_c;
p_downmix->downmix_3f_0r_to_2ch = downmix_3f_0r_to_2ch_c;
p_downmix->stream_sample_2ch_to_s16 = stream_sample_2ch_to_s16_c;
p_downmix->stream_sample_1ch_to_s16 = stream_sample_1ch_to_s16_c;
}
return 0;
}
......@@ -2,7 +2,7 @@
* ac3_downmix.h: ac3 downmix functions
*****************************************************************************
* Copyright (C) 2000, 2001 VideoLAN
* $Id: ac3_downmix.h,v 1.5 2001/03/21 13:42:34 sam Exp $
* $Id: ac3_downmix.h,v 1.6 2001/04/30 21:04:20 reno Exp $
*
* Authors: Renaud Dartus <reno@videolan.org>
*
......@@ -21,14 +21,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#define NORM 16384
typedef struct dm_par_s {
float unit;
float clev;
float slev;
} dm_par_t;
/* C functions */
void downmix_3f_2r_to_2ch_c(float *samples, dm_par_t * dm_par);
void downmix_3f_1r_to_2ch_c(float *samples, dm_par_t * dm_par);
void downmix_2f_2r_to_2ch_c(float *samples, dm_par_t * dm_par);
......@@ -36,3 +29,14 @@ void downmix_2f_1r_to_2ch_c(float *samples, dm_par_t * dm_par);
void downmix_3f_0r_to_2ch_c(float *samples, dm_par_t * dm_par);
void stream_sample_2ch_to_s16_c(s16 *s16_samples, float *left, float *right);
void stream_sample_1ch_to_s16_c(s16 *s16_samples, float *center);
#if 0
/* Kni functions */
void downmix_3f_2r_to_2ch_kni(float *samples, dm_par_t * dm_par);
void downmix_3f_1r_to_2ch_kni(float *samples, dm_par_t * dm_par);
void downmix_2f_2r_to_2ch_kni(float *samples, dm_par_t * dm_par);
void downmix_2f_1r_to_2ch_kni(float *samples, dm_par_t * dm_par);
void downmix_3f_0r_to_2ch_kni(float *samples, dm_par_t * dm_par);
void stream_sample_2ch_to_s16_kni(s16 *s16_samples, float *left, float *right);
void stream_sample_1ch_to_s16_kni(s16 *s16_samples, float *center);
#endif
......@@ -2,7 +2,7 @@
* ac3_downmix_c.c: ac3 downmix functions
*****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id: ac3_downmix_c.c,v 1.5 2001/04/20 12:14:34 reno Exp $
* $Id: ac3_downmix_c.c,v 1.6 2001/04/30 21:04:20 reno Exp $
*
* Authors: Renaud Dartus <reno@videolan.org>
* Aaron Holtzman <aholtzma@engr.uvic.ca>
......@@ -36,6 +36,7 @@
#include "ac3_internal.h"
#include "ac3_downmix.h"
void __inline__ downmix_3f_2r_to_2ch_c (float *samples, dm_par_t *dm_par)
{
int i;
......@@ -137,8 +138,8 @@ void __inline__ stream_sample_2ch_to_s16_c (s16 *out_buf, float *left, float *ri
{
int i;
for (i=0; i < 256; i++) {
*out_buf++ = (s16) (*left++ * NORM);
*out_buf++ = (s16) (*right++ * NORM);
*out_buf++ = (s16) (*left++);
*out_buf++ = (s16) (*right++);
}
}
......@@ -149,7 +150,7 @@ void __inline__ stream_sample_1ch_to_s16_c (s16 *out_buf, float *center)
float tmp;
for (i=0; i < 256; i++) {
*out_buf++ = tmp = (s16) (0.7071f * *center++ * NORM);
*out_buf++ = tmp = (s16) (0.7071f * *center++);
*out_buf++ = tmp;
}
}
......@@ -2,7 +2,7 @@
* ac3_imdct.c: ac3 DCT
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: ac3_imdct.c,v 1.16 2001/04/26 11:23:16 sam Exp $
* $Id: ac3_imdct.c,v 1.17 2001/04/30 21:04:20 reno Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Aaron Holtzman <aholtzma@engr.uvic.ca>
......@@ -40,154 +40,65 @@
#include "ac3_internal.h"
#include "ac3_downmix.h"
#include "ac3_imdct_c.h"
#if 0
#include "ac3_imdct_kni.h"
#endif
#include "tests.h"
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
void imdct_do_256(imdct_t * p_imdct, float x[],float y[], int id);
void imdct_do_512(imdct_t * p_imdct, float x[],float y[], int id);
/* 128 point bit-reverse LUT */
static const u8 bit_reverse_512[] = {
0x00, 0x40, 0x20, 0x60, 0x10, 0x50, 0x30, 0x70,
0x08, 0x48, 0x28, 0x68, 0x18, 0x58, 0x38, 0x78,
0x04, 0x44, 0x24, 0x64, 0x14, 0x54, 0x34, 0x74,
0x0c, 0x4c, 0x2c, 0x6c, 0x1c, 0x5c, 0x3c, 0x7c,
0x02, 0x42, 0x22, 0x62, 0x12, 0x52, 0x32, 0x72,
0x0a, 0x4a, 0x2a, 0x6a, 0x1a, 0x5a, 0x3a, 0x7a,
0x06, 0x46, 0x26, 0x66, 0x16, 0x56, 0x36, 0x76,
0x0e, 0x4e, 0x2e, 0x6e, 0x1e, 0x5e, 0x3e, 0x7e,
0x01, 0x41, 0x21, 0x61, 0x11, 0x51, 0x31, 0x71,
0x09, 0x49, 0x29, 0x69, 0x19, 0x59, 0x39, 0x79,
0x05, 0x45, 0x25, 0x65, 0x15, 0x55, 0x35, 0x75,
0x0d, 0x4d, 0x2d, 0x6d, 0x1d, 0x5d, 0x3d, 0x7d,
0x03, 0x43, 0x23, 0x63, 0x13, 0x53, 0x33, 0x73,
0x0b, 0x4b, 0x2b, 0x6b, 0x1b, 0x5b, 0x3b, 0x7b,
0x07, 0x47, 0x27, 0x67, 0x17, 0x57, 0x37, 0x77,
0x0f, 0x4f, 0x2f, 0x6f, 0x1f, 0x5f, 0x3f, 0x7f};
static const u8 bit_reverse_256[] = {
0x00, 0x20, 0x10, 0x30, 0x08, 0x28, 0x18, 0x38,
0x04, 0x24, 0x14, 0x34, 0x0c, 0x2c, 0x1c, 0x3c,
0x02, 0x22, 0x12, 0x32, 0x0a, 0x2a, 0x1a, 0x3a,
0x06, 0x26, 0x16, 0x36, 0x0e, 0x2e, 0x1e, 0x3e,
0x01, 0x21, 0x11, 0x31, 0x09, 0x29, 0x19, 0x39,
0x05, 0x25, 0x15, 0x35, 0x0d, 0x2d, 0x1d, 0x3d,
0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b,
0x07, 0x27, 0x17, 0x37, 0x0f, 0x2f, 0x1f, 0x3f};
/* Windowing function for Modified DCT - Thank you acroread */
static float window[] = {
0.00014, 0.00024, 0.00037, 0.00051, 0.00067, 0.00086, 0.00107, 0.00130,
0.00157, 0.00187, 0.00220, 0.00256, 0.00297, 0.00341, 0.00390, 0.00443,
0.00501, 0.00564, 0.00632, 0.00706, 0.00785, 0.00871, 0.00962, 0.01061,
0.01166, 0.01279, 0.01399, 0.01526, 0.01662, 0.01806, 0.01959, 0.02121,
0.02292, 0.02472, 0.02662, 0.02863, 0.03073, 0.03294, 0.03527, 0.03770,
0.04025, 0.04292, 0.04571, 0.04862, 0.05165, 0.05481, 0.05810, 0.06153,
0.06508, 0.06878, 0.07261, 0.07658, 0.08069, 0.08495, 0.08935, 0.09389,
0.09859, 0.10343, 0.10842, 0.11356, 0.11885, 0.12429, 0.12988, 0.13563,
0.14152, 0.14757, 0.15376, 0.16011, 0.16661, 0.17325, 0.18005, 0.18699,
0.19407, 0.20130, 0.20867, 0.21618, 0.22382, 0.23161, 0.23952, 0.24757,
0.25574, 0.26404, 0.27246, 0.28100, 0.28965, 0.29841, 0.30729, 0.31626,
0.32533, 0.33450, 0.34376, 0.35311, 0.36253, 0.37204, 0.38161, 0.39126,
0.40096, 0.41072, 0.42054, 0.43040, 0.44030, 0.45023, 0.46020, 0.47019,
0.48020, 0.49022, 0.50025, 0.51028, 0.52031, 0.53033, 0.54033, 0.55031,
0.56026, 0.57019, 0.58007, 0.58991, 0.59970, 0.60944, 0.61912, 0.62873,
0.63827, 0.64774, 0.65713, 0.66643, 0.67564, 0.68476, 0.69377, 0.70269,
0.71150, 0.72019, 0.72877, 0.73723, 0.74557, 0.75378, 0.76186, 0.76981,
0.77762, 0.78530, 0.79283, 0.80022, 0.80747, 0.81457, 0.82151, 0.82831,
0.83496, 0.84145, 0.84779, 0.85398, 0.86001, 0.86588, 0.87160, 0.87716,
0.88257, 0.88782, 0.89291, 0.89785, 0.90264, 0.90728, 0.91176, 0.91610,
0.92028, 0.92432, 0.92822, 0.93197, 0.93558, 0.93906, 0.94240, 0.94560,
0.94867, 0.95162, 0.95444, 0.95713, 0.95971, 0.96217, 0.96451, 0.96674,
0.96887, 0.97089, 0.97281, 0.97463, 0.97635, 0.97799, 0.97953, 0.98099,
0.98236, 0.98366, 0.98488, 0.98602, 0.98710, 0.98811, 0.98905, 0.98994,
0.99076, 0.99153, 0.99225, 0.99291, 0.99353, 0.99411, 0.99464, 0.99513,
0.99558, 0.99600, 0.99639, 0.99674, 0.99706, 0.99736, 0.99763, 0.99788,
0.99811, 0.99831, 0.99850, 0.99867, 0.99882, 0.99895, 0.99908, 0.99919,
0.99929, 0.99938, 0.99946, 0.99953, 0.99959, 0.99965, 0.99969, 0.99974,
0.99978, 0.99981, 0.99984, 0.99986, 0.99988, 0.99990, 0.99992, 0.99993,
0.99994, 0.99995, 0.99996, 0.99997, 0.99998, 0.99998, 0.99998, 0.99999,
0.99999, 0.99999, 0.99999, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000,
1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000 };
static __inline__ void swap_cmplx(complex_t *a, complex_t *b)
{
complex_t tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
static __inline__ complex_t cmplx_mult(complex_t a, complex_t b)
{
complex_t ret;
ret.real = a.real * b.real - a.imag * b.imag;
ret.imag = a.real * b.imag + a.imag * b.real;
return ret;
}
void imdct_init(imdct_t * p_imdct)
{
int i,k;
complex_t angle_step;
complex_t current_angle;
int i;
float scale = 255.99609372;
/* Twiddle factors to turn IFFT into IMDCT */
for (i=0; i < N/4; i++) {
p_imdct->xcos1[i] = -cos(2 * M_PI * (8*i+1)/(8*N)) ;
p_imdct->xsin1[i] = -sin(2 * M_PI * (8*i+1)/(8*N)) ;
#if 0
if ( TestCPU (CPU_CAPABILITY_MMX) )
{
imdct_init_kni (p_imdct);
} else
#endif
{
imdct_init_c (p_imdct);
}
/* More twiddle factors to turn IFFT into IMDCT */
for (i=0; i < N/8; i++) {
p_imdct->xcos2[i] = -cos(2 * M_PI * (8*i+1)/(4*N)) ;
p_imdct->xsin2[i] = -sin(2 * M_PI * (8*i+1)/(4*N)) ;
}
/* Canonical twiddle factors for FFT */
p_imdct->w[0] = p_imdct->w_1;
p_imdct->w[1] = p_imdct->w_2;
p_imdct->w[2] = p_imdct->w_4;
p_imdct->w[3] = p_imdct->w_8;
p_imdct->w[4] = p_imdct->w_16;
p_imdct->w[5] = p_imdct->w_32;
p_imdct->w[6] = p_imdct->w_64;
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++) {
p_imdct->w[i][k] = current_angle;
current_angle = cmplx_mult(current_angle,angle_step);
}
for (i=0; i < 64; i++) {
p_imdct->xcos2[i] = cos(2.0f * M_PI * (8*i+1)/(4*N)) * scale;
p_imdct->xsin2[i] = sin(2.0f * M_PI * (8*i+1)/(4*N)) * scale;
}
}
void imdct (ac3dec_t * p_ac3dec, s16 * buffer)
{
int i, i_stream_done;
int i;
int doable = 0;
void (*do_imdct)(imdct_t * p_imdct, float x[],float y[], int id);
/* Test if dm in frequency is doable */
if ( !(doable = p_ac3dec->audblk.blksw[0]) )
do_imdct = imdct_do_512;
float *center=NULL, *left, *right, *left_sur, *right_sur;
float *delay_left, *delay_right;
float *delay1_left, *delay1_right, *delay1_center, *delay1_sr, *delay1_sl;
float right_tmp, left_tmp;
void (*do_imdct)(imdct_t * p_imdct, float data[], float delay[]);
/* test if dm in frequency is doable */
if (!(doable = p_ac3dec->audblk.blksw[0]))
{
do_imdct = p_ac3dec->imdct.imdct_do_512;
}
else
do_imdct = imdct_do_256;
{
do_imdct = imdct_do_256; /* There is only a C function */
}
/* Downmix in the frequency domain if all the channes use the same imdct */
/* downmix in the frequency domain if all the channels
* use the same imdct */
for (i=0; i < p_ac3dec->bsi.nfchans; i++)
{
if ( doable != p_ac3dec->audblk.blksw[i] )
if (doable != p_ac3dec->audblk.blksw[i])
{
do_imdct = NULL;
break;
......@@ -196,227 +107,168 @@ void imdct (ac3dec_t * p_ac3dec, s16 * buffer)
if (do_imdct)
{
i_stream_done = downmix(p_ac3dec, p_ac3dec->coeffs.fbw[0], buffer);
do_imdct(&p_ac3dec->imdct,p_ac3dec->coeffs.fbw[0],p_ac3dec->samples.channel[0], 0);
do_imdct(&p_ac3dec->imdct, p_ac3dec->coeffs.fbw[1],p_ac3dec->samples.channel[1], 1);
} else {
for (i=0; i<p_ac3dec->bsi.nfchans;i++) {
if (p_ac3dec->audblk.blksw[i])
imdct_do_256(&p_ac3dec->imdct, p_ac3dec->coeffs.fbw[i],p_ac3dec->samples.channel[i], i);
else
imdct_do_512(&p_ac3dec->imdct, p_ac3dec->coeffs.fbw[i],p_ac3dec->samples.channel[i], i);
}
i_stream_done = downmix(p_ac3dec, p_ac3dec->samples.channel[0], buffer);
}
if ( !i_stream_done ) /* We have to stream sample */
/* dowmix first and imdct */
switch(p_ac3dec->bsi.acmod)
{
stream_sample_2ch_to_s16_c(buffer, p_ac3dec->samples.channel[0],
p_ac3dec->samples.channel[1]);
} else {
stream_sample_1ch_to_s16_c(buffer, p_ac3dec->samples.channel[0]);
}
/* XXX?? We don't bother with the IMDCT for the LFE as it's currently
* unused. */
//if (bsi->lfeon)
// imdct_do_512(coeffs->lfe,samples->channel[5],delay[5]);
}
void imdct_do_512(imdct_t * p_imdct, float x[], float y[], int id)
{
int i,k;
int p,q;
int m;
int two_m;
int two_m_plus_one;
float tmp_a_i;
float tmp_a_r;
float tmp_b_i;
float tmp_b_r;
float *y_ptr;
float *delay_ptr;
float *window_ptr;
/* Pre IFFT complex multiply plus IFFT cmplx conjugate */
for (i=0; i < N/4; i++) {
/* z[i] = (X[N/2-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */
p_imdct->buf[i].real = (x[N/2-2*i-1] * p_imdct->xcos1[i]) - (x[2*i] * p_imdct->xsin1[i]);
p_imdct->buf[i].imag = -((x[2*i] * p_imdct->xcos1[i]) + (x[N/2-2*i-1] * p_imdct->xsin1[i]));
}
/* Bit reversed shuffling */
for (i=0; i<N/4; i++) {
k = bit_reverse_512[i];
if (k < i)
swap_cmplx(&p_imdct->buf[i],&p_imdct->buf[k]);
}
/* FFT Merge */
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) {
p = k + i;
q = p + two_m;
tmp_a_r = p_imdct->buf[p].real;
tmp_a_i = p_imdct->buf[p].imag;
tmp_b_r = p_imdct->buf[q].real * p_imdct->w[m][k].real - p_imdct->buf[q].imag * p_imdct->w[m][k].imag;
tmp_b_i = p_imdct->buf[q].imag * p_imdct->w[m][k].real + p_imdct->buf[q].real * p_imdct->w[m][k].imag;
p_imdct->buf[p].real = tmp_a_r + tmp_b_r;
p_imdct->buf[p].imag = tmp_a_i + tmp_b_i;
p_imdct->buf[q].real = tmp_a_r - tmp_b_r;
p_imdct->buf[q].imag = tmp_a_i - tmp_b_i;
}
}
}
/* Post IFFT complex multiply plus IFFT complex conjugate*/
for (i=0; i < N/4; i++) {
/* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
tmp_a_r = p_imdct->buf[i].real;
tmp_a_i = - p_imdct->buf[i].imag;
p_imdct->buf[i].real =(tmp_a_r * p_imdct->xcos1[i]) - (tmp_a_i * p_imdct->xsin1[i]);
p_imdct->buf[i].imag =(tmp_a_r * p_imdct->xsin1[i]) + (tmp_a_i * p_imdct->xcos1[i]);
}
y_ptr = y;
delay_ptr = p_imdct->delay[id];
window_ptr = window;
/* Window and convert to real valued signal */
for (i=0; i<N/8; i++) {
*y_ptr++ = 2.0f * (-p_imdct->buf[N/8+i].imag * *window_ptr++ + *delay_ptr++);
*y_ptr++ = 2.0f * (p_imdct->buf[N/8-i-1].real * *window_ptr++ + *delay_ptr++);
}
for (i=0; i<N/8; i++) {
*y_ptr++ = 2.0f * (-p_imdct->buf[i].real * *window_ptr++ + *delay_ptr++);
*y_ptr++ = 2.0f * (p_imdct->buf[N/4-i-1].imag * *window_ptr++ + *delay_ptr++);
}
/* The trailing edge of the window goes into the delay line */
delay_ptr = p_imdct->delay[id];
case 7: /* 3/2 */
p_ac3dec->downmix.downmix_3f_2r_to_2ch (p_ac3dec->samples[0], &p_ac3dec->dm_par);
break;
case 6: /* 2/2 */
p_ac3dec->downmix.downmix_2f_2r_to_2ch (p_ac3dec->samples[0], &p_ac3dec->dm_par);
break;
case 5: /* 3/1 */
p_ac3dec->downmix.downmix_3f_1r_to_2ch (p_ac3dec->samples[0], &p_ac3dec->dm_par);
break;
case 4: /* 2/1 */
p_ac3dec->downmix.downmix_2f_1r_to_2ch (p_ac3dec->samples[0], &p_ac3dec->dm_par);
break;
case 3: /* 3/0 */
p_ac3dec->downmix.downmix_3f_0r_to_2ch (p_ac3dec->samples[0], &p_ac3dec->dm_par);
break;
case 2:
break;
default: /* 1/0 */
// if (p_ac3dec->bsi.acmod == 1)
center = p_ac3dec->samples[0];
// else if (p_ac3dec->bsi.acmod == 0)
// center = samples[ac3_config.dual_mono_ch_sel];
do_imdct(&p_ac3dec->imdct, center, p_ac3dec->imdct.delay[0]); /* no downmix*/
for (i=0; i<N/8; i++) {
*delay_ptr++ = -p_imdct->buf[N/8+i].real * *--window_ptr;
*delay_ptr++ = p_imdct->buf[N/8-i-1].imag * *--window_ptr;
}
p_ac3dec->downmix.stream_sample_1ch_to_s16 (buffer, center);
for (i=0; i<N/8; i++) {
*delay_ptr++ = p_imdct->buf[i].imag * *--window_ptr;
*delay_ptr++ = -p_imdct->buf[N/4-i-1].real * *--window_ptr;
return;
break;
}
}
void imdct_do_256(imdct_t * p_imdct,float x[],float y[], int id)
{
int i,k;
int p,q;
int m;
int two_m;
int two_m_plus_one;
do_imdct (&p_ac3dec->imdct, p_ac3dec->samples[0], p_ac3dec->imdct.delay[0]);
do_imdct (&p_ac3dec->imdct, p_ac3dec->samples[1], p_ac3dec->imdct.delay[1]);
p_ac3dec->downmix.stream_sample_2ch_to_s16(buffer, p_ac3dec->samples[0], p_ac3dec->samples[1]);
float tmp_a_i;
float tmp_a_r;
float tmp_b_i;
float tmp_b_r;
complex_t *buf_1, *buf_2;
buf_1 = &p_imdct->buf[0];
buf_2 = &p_imdct->buf[64];
/* Pre IFFT complex multiply plus IFFT cmplx conjugate */
for (k=0; k<N/8; k++) {
/* X1[k] = X[2*k] */
/* X2[k] = X[2*k+1] */
p = 2 * (N/4-2*k-1);
q = 2 * (2 * k);
/* Z1[k] = (X1[N/4-2*k-1] + j * X1[2*k]) * (xcos2[k] + j * xsin2[k]); */
buf_1[k].real = x[p] * p_imdct->xcos2[k] - x[q] * p_imdct->xsin2[k];
buf_1[k].imag = - (x[q] * p_imdct->xcos2[k] + x[p] * p_imdct->xsin2[k]);
/* Z2[k] = (X2[N/4-2*k-1] + j * X2[2*k]) * (xcos2[k] + j * xsin2[k]); */
buf_2[k].real = x[p + 1] * p_imdct->xcos2[k] - x[q + 1] * p_imdct->xsin2[k];
buf_2[k].imag = - (x[q + 1] * p_imdct->xcos2[k] + x[p + 1] * p_imdct->xsin2[k]);
} else {
/* imdct and then downmix
* delay and samples should be saved and mixed
* fprintf(stderr, "time domain downmix\n"); */
for (i=0; i<p_ac3dec->bsi.nfchans; i++)
{
if (p_ac3dec->audblk.blksw[i])
/* There is only a C function */
imdct_do_256_nol (&p_ac3dec->imdct, p_ac3dec->samples[i], p_ac3dec->imdct.delay1[i]);
else
p_ac3dec->imdct.imdct_do_512_nol (&p_ac3dec->imdct, p_ac3dec->samples[i], p_ac3dec->imdct.delay1[i]);
}
/* IFFT Bit reversed shuffling */
for (i=0; i<N/8; i++) {
k = bit_reverse_256[i];
if (k < i) {
swap_cmplx(&buf_1[i],&buf_1[k]);
swap_cmplx(&buf_2[i],&buf_2[k]);
/* mix the sample, overlap */
switch(p_ac3dec->bsi.acmod)
{
case 7: /* 3/2 */
left = p_ac3dec->samples[0];
center = p_ac3dec->samples[1];
right = p_ac3dec->samples[2];
left_sur = p_ac3dec->samples[3];
right_sur = p_ac3dec->samples[4];
delay_left = p_ac3dec->imdct.delay[0];
delay_right = p_ac3dec->imdct.delay[1];
delay1_left = p_ac3dec->imdct.delay1[0];
delay1_center = p_ac3dec->imdct.delay1[1];
delay1_right = p_ac3dec->imdct.delay1[2];
delay1_sl = p_ac3dec->imdct.delay1[3];
delay1_sr = p_ac3dec->imdct.delay1[4];
for (i = 0; i < 256; i++) {
left_tmp = p_ac3dec->dm_par.unit * *left++ + p_ac3dec->dm_par.clev * *center + p_ac3dec->dm_par.slev * *left_sur++;
right_tmp= p_ac3dec->dm_par.unit * *right++ + p_ac3dec->dm_par.clev * *center++ + p_ac3dec->dm_par.slev * *right_sur++;
*buffer++ = (s16)(left_tmp + *delay_left);
*buffer++ = (s16)(right_tmp + *delay_right);
*delay_left++ = p_ac3dec->dm_par.unit * *delay1_left++ + p_ac3dec->dm_par.clev * *delay1_center + p_ac3dec->dm_par.slev * *delay1_sl++;
*delay_right++ = p_ac3dec->dm_par.unit * *delay1_right++ + p_ac3dec->dm_par.clev * *center++ + p_ac3dec->dm_par.slev * *delay1_sr++;
}
break;
case 6: /* 2/2 */
left = p_ac3dec->samples[0];
right = p_ac3dec->samples[1];
left_sur = p_ac3dec->samples[2];
right_sur = p_ac3dec->samples[3];
delay_left = p_ac3dec->imdct.delay[0];
delay_right = p_ac3dec->imdct.delay[1];
delay1_left = p_ac3dec->imdct.delay1[0];
delay1_right = p_ac3dec->imdct.delay1[1];
delay1_sl = p_ac3dec->imdct.delay1[2];
delay1_sr = p_ac3dec->imdct.delay1[3];
for (i = 0; i < 256; i++) {
left_tmp = p_ac3dec->dm_par.unit * *left++ + p_ac3dec->dm_par.slev * *left_sur++;
right_tmp= p_ac3dec->dm_par.unit * *right++ + p_ac3dec->dm_par.slev * *right_sur++;
*buffer++ = (s16)(left_tmp + *delay_left);
*buffer++ = (s16)(right_tmp + *delay_right);
*delay_left++ = p_ac3dec->dm_par.unit * *delay1_left++ + p_ac3dec->dm_par.slev * *delay1_sl++;
*delay_right++ = p_ac3dec->dm_par.unit * *delay1_right++ + p_ac3dec->dm_par.slev * *delay1_sr++;
}
/* FFT Merge */
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) {
p = k + i;
q = p + two_m;
/* Do block 1 */
tmp_a_r = buf_1[p].real;
tmp_a_i = buf_1[p].imag;
tmp_b_r = buf_1[q].real * p_imdct->w[m][k].real - buf_1[q].imag * p_imdct->w[m][k].imag;
tmp_b_i = buf_1[q].imag * p_imdct->w[m][k].real + buf_1[q].real * p_imdct->w[m][k].imag;
buf_1[p].real = tmp_a_r + tmp_b_r;
buf_1[p].imag = tmp_a_i + tmp_b_i;
buf_1[q].real = tmp_a_r - tmp_b_r;
buf_1[q].imag = tmp_a_i - tmp_b_i;
/* Do block 2 */
tmp_a_r = buf_2[p].real;
tmp_a_i = buf_2[p].imag;
tmp_b_r = buf_2[q].real * p_imdct->w[m][k].real - buf_2[q].imag * p_imdct->w[m][k].imag;
tmp_b_i = buf_2[q].imag * p_imdct->w[m][k].real + buf_2[q].real * p_imdct->w[m][k].imag;
buf_2[p].real = tmp_a_r + tmp_b_r;
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;
break;
case 5: /* 3/1 */
left = p_ac3dec->samples[0];
center = p_ac3dec->samples[1];
right = p_ac3dec->samples[2];
right_sur = p_ac3dec->samples[3];
delay_left = p_ac3dec->imdct.delay[0];
delay_right = p_ac3dec->imdct.delay[1];
delay1_left = p_ac3dec->imdct.delay1[0];
delay1_center = p_ac3dec->imdct.delay1[1];
delay1_right = p_ac3dec->imdct.delay1[2];
delay1_sl = p_ac3dec->imdct.delay1[3];
for (i = 0; i < 256; i++) {
left_tmp = p_ac3dec->dm_par.unit * *left++ + p_ac3dec->dm_par.clev * *center - p_ac3dec->dm_par.slev * *right_sur;
right_tmp= p_ac3dec->dm_par.unit * *right++ + p_ac3dec->dm_par.clev * *center++ + p_ac3dec->dm_par.slev * *right_sur++;
*buffer++ = (s16)(left_tmp + *delay_left);
*buffer++ = (s16)(right_tmp + *delay_right);
*delay_left++ = p_ac3dec->dm_par.unit * *delay1_left++ + p_ac3dec->dm_par.clev * *delay1_center + p_ac3dec->dm_par.slev * *delay1_sl;
*delay_right++ = p_ac3dec->dm_par.unit * *delay1_right++ + p_ac3dec->dm_par.clev * *center++ + p_ac3dec->dm_par.slev * *delay1_sl++;
}
break;
case 4: /* 2/1 */
left = p_ac3dec->samples[0];
right = p_ac3dec->samples[1];
right_sur = p_ac3dec->samples[2];
delay_left = p_ac3dec->imdct.delay[0];
delay_right = p_ac3dec->imdct.delay[1];
delay1_left = p_ac3dec->imdct.delay1[0];
delay1_right = p_ac3dec->imdct.delay1[1];
delay1_sl = p_ac3dec->imdct.delay1[2];
for (i = 0; i < 256; i++) {
left_tmp = p_ac3dec->dm_par.unit * *left++ - p_ac3dec->dm_par.slev * *right_sur;
right_tmp= p_ac3dec->dm_par.unit * *right++ + p_ac3dec->dm_par.slev * *right_sur++;
*buffer++ = (s16)(left_tmp + *delay_left);
*buffer++ = (s16)(right_tmp + *delay_right);
*delay_left++ = p_ac3dec->dm_par.unit * *delay1_left++ + p_ac3dec->dm_par.slev * *delay1_sl;
*delay_right++ = p_ac3dec->dm_par.unit * *delay1_right++ + p_ac3dec->dm_par.slev * *delay1_sl++;
}
break;
case 3: /* 3/0 */
left = p_ac3dec->samples[0];
center = p_ac3dec->samples[1];
right = p_ac3dec->samples[2];
delay_left = p_ac3dec->imdct.delay[0];
delay_right = p_ac3dec->imdct.delay[1];
delay1_left = p_ac3dec->imdct.delay1[0];
delay1_center = p_ac3dec->imdct.delay1[1];
delay1_right = p_ac3dec->imdct.delay1[2];
for (i = 0; i < 256; i++) {
left_tmp = p_ac3dec->dm_par.unit * *left++ + p_ac3dec->dm_par.clev * *center;
right_tmp= p_ac3dec->dm_par.unit * *right++ + p_ac3dec->dm_par.clev * *center++;
*buffer++ = (s16)(left_tmp + *delay_left);
*buffer++ = (s16)(right_tmp + *delay_right);
*delay_left++ = p_ac3dec->dm_par.unit * *delay1_left++ + p_ac3dec->dm_par.clev * *delay1_center;
*delay_right++ = p_ac3dec->dm_par.unit * *delay1_right++ + p_ac3dec->dm_par.clev * *center++;
}
/* Post IFFT complex multiply */
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 * p_imdct->xcos2[i]) - (tmp_a_i * p_imdct->xsin2[i]);
buf_1[i].imag =(tmp_a_r * p_imdct->xsin2[i]) + (tmp_a_i * p_imdct->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 * p_imdct->xcos2[i]) - (tmp_a_i * p_imdct->xsin2[i]);
buf_2[i].imag =(tmp_a_r * p_imdct->xsin2[i]) + (tmp_a_i * p_imdct->xcos2[i]);
break;
case 2: /* copy to output */
for (i = 0; i < 256; i++) {
*buffer++ = (s16)p_ac3dec->samples[0][i];
*buffer++ = (s16)p_ac3dec->samples[1][i];
}
/* Window and convert to real valued signal */
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];
y[N/4+2*i+1] = buf_1[N/8-i-1].imag * window[N/4+2*i+1];
y[N/2+2*i] = -buf_2[i].real * window[N/2-2*i-1];
y[N/2+2*i+1] = buf_2[N/8-i-1].imag * window[N/2-2*i-2];
y[3*N/4+2*i] = buf_2[i].imag * window[N/4-2*i-1];
y[3*N/4+2*i+1] = -buf_2[N/8-i-1].real * window[N/4-2*i-2];
break;
}
/* Overlap and add */
for (i=0; i<N/2; i++) {
y[i] = 2 * (y[i] + p_imdct->delay[id][i]);
p_imdct->delay[id][i] = y[N/2+i];
}
}
/*****************************************************************************
* ac3_imdct_c.c: ac3 DCT
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: ac3_imdct_c.c,v 1.1 2001/04/30 21:04:20 reno Exp $
*
* Authors: Renaud Dartus <reno@videolan.org>
* Aaron Holtzman <aholtzma@engr.uvic.ca>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "defs.h"
#include <math.h>
#include <stdio.h>
#include "config.h"
#include "common.h"
#include "threads.h"
#include "mtime.h"
#include "stream_control.h"
#include "input_ext-dec.h"
#include "ac3_decoder.h"
#include "ac3_internal.h"
void fft_64p_c (complex_t *x);
void fft_128p_c (complex_t *x);
void imdct_do_512_c (imdct_t * p_imdct, float data[], float delay[]);
void imdct_do_512_nol_c (imdct_t * p_imdct, float data[], float delay[]);
static float window[] = {
0.00014, 0.00024, 0.00037, 0.00051, 0.00067, 0.00086, 0.00107, 0.00130,
0.00157, 0.00187, 0.00220, 0.00256, 0.00297, 0.00341, 0.00390, 0.00443,
0.00501, 0.00564, 0.00632, 0.00706, 0.00785, 0.00871, 0.00962, 0.01061,
0.01166, 0.01279, 0.01399, 0.01526, 0.01662, 0.01806, 0.01959, 0.02121,
0.02292, 0.02472, 0.02662, 0.02863, 0.03073, 0.03294, 0.03527, 0.03770,
0.04025, 0.04292, 0.04571, 0.04862, 0.05165, 0.05481, 0.05810, 0.06153,
0.06508, 0.06878, 0.07261, 0.07658, 0.08069, 0.08495, 0.08935, 0.09389,
0.09859, 0.10343, 0.10842, 0.11356, 0.11885, 0.12429, 0.12988, 0.13563,
0.14152, 0.14757, 0.15376, 0.16011, 0.16661, 0.17325, 0.18005, 0.18699,
0.19407, 0.20130, 0.20867, 0.21618, 0.22382, 0.23161, 0.23952, 0.24757,
0.25574, 0.26404, 0.27246, 0.28100, 0.28965, 0.29841, 0.30729, 0.31626,
0.32533, 0.33450, 0.34376, 0.35311, 0.36253, 0.37204, 0.38161, 0.39126,
0.40096, 0.41072, 0.42054, 0.43040, 0.44030, 0.45023, 0.46020, 0.47019,
0.48020, 0.49022, 0.50025, 0.51028, 0.52031, 0.53033, 0.54033, 0.55031,
0.56026, 0.57019, 0.58007, 0.58991, 0.59970, 0.60944, 0.61912, 0.62873,
0.63827, 0.64774, 0.65713, 0.66643, 0.67564, 0.68476, 0.69377, 0.70269,
0.71150, 0.72019, 0.72877, 0.73723, 0.74557, 0.75378, 0.76186, 0.76981,
0.77762, 0.78530, 0.79283, 0.80022, 0.80747, 0.81457, 0.82151, 0.82831,
0.83496, 0.84145, 0.84779, 0.85398, 0.86001, 0.86588, 0.87160, 0.87716,
0.88257, 0.88782, 0.89291, 0.89785, 0.90264, 0.90728, 0.91176, 0.91610,
0.92028, 0.92432, 0.92822, 0.93197, 0.93558, 0.93906, 0.94240, 0.94560,
0.94867, 0.95162, 0.95444, 0.95713, 0.95971, 0.96217, 0.96451, 0.96674,
0.96887, 0.97089, 0.97281, 0.97463, 0.97635, 0.97799, 0.97953, 0.98099,
0.98236, 0.98366, 0.98488, 0.98602, 0.98710, 0.98811, 0.98905, 0.98994,
0.99076, 0.99153, 0.99225, 0.99291, 0.99353, 0.99411, 0.99464, 0.99513,
0.99558, 0.99600, 0.99639, 0.99674, 0.99706, 0.99736, 0.99763, 0.99788,
0.99811, 0.99831, 0.99850, 0.99867, 0.99882, 0.99895, 0.99908, 0.99919,
0.99929, 0.99938, 0.99946, 0.99953, 0.99959, 0.99965, 0.99969, 0.99974,
0.99978, 0.99981, 0.99984, 0.99986, 0.99988, 0.99990, 0.99992, 0.99993,
0.99994, 0.99995, 0.99996, 0.99997, 0.99998, 0.99998, 0.99998, 0.99999,
0.99999, 0.99999, 0.99999, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000,
1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000
};
static const int pm128[128] =
{
0, 16, 32, 48, 64, 80, 96, 112, 8, 40, 72, 104, 24, 56, 88, 120,
4, 20, 36, 52, 68, 84, 100, 116, 12, 28, 44, 60, 76, 92, 108, 124,
2, 18, 34, 50, 66, 82, 98, 114, 10, 42, 74, 106, 26, 58, 90, 122,
6, 22, 38, 54, 70, 86, 102, 118, 14, 46, 78, 110, 30, 62, 94, 126,
1, 17, 33, 49, 65, 81, 97, 113, 9, 41, 73, 105, 25, 57, 89, 121,
5, 21, 37, 53, 69, 85, 101, 117, 13, 29, 45, 61, 77, 93, 109, 125,
3, 19, 35, 51, 67, 83, 99, 115, 11, 43, 75, 107, 27, 59, 91, 123,
7, 23, 39, 55, 71, 87, 103, 119, 15, 31, 47, 63, 79, 95, 111, 127
};
static const int pm64[64] =
{
0, 8, 16, 24, 32, 40, 48, 56,
4, 20, 36, 52, 12, 28, 44, 60,
2, 10, 18, 26, 34, 42, 50, 58,
6, 14, 22, 30, 38, 46, 54, 62,
1, 9, 17, 25, 33, 41, 49, 57,
5, 21, 37, 53, 13, 29, 45, 61,
3, 11, 19, 27, 35, 43, 51, 59,
7, 23, 39, 55, 15, 31, 47, 63
};
int imdct_init_c (imdct_t * p_imdct)
{
int i;
float scale = 255.99609372;
p_imdct->imdct_do_512 = imdct_do_512_c;
p_imdct->imdct_do_512_nol = imdct_do_512_nol_c;
p_imdct->fft_64p = fft_64p_c;
/* Twiddle factors to turn IFFT into IMDCT */
for (i=0; i < 128; i++) {
p_imdct->xcos1[i] = cos(2.0f * M_PI * (8*i+1)/(8*N)) * scale;
p_imdct->xsin1[i] = sin(2.0f * M_PI * (8*i+1)/(8*N)) * scale;
}
return 0;
}
void imdct_do_256 (imdct_t * p_imdct, float data[],float delay[])
{
int i, j, k;
int p, q;
float tmp_a_i;
float tmp_a_r;
float *data_ptr;
float *delay_ptr;
float *window_ptr;
complex_t *buf1, *buf2;
buf1 = &p_imdct->buf[0];
buf2 = &p_imdct->buf[64];
/* Pre IFFT complex multiply plus IFFT complex conjugate */
for (k=0; k<64; k++) {
/* X1[k] = X[2*k]
* X2[k] = X[2*k+1] */
j = pm64[k];
p = 2 * (128-2*j-1);
q = 2 * (2 * j);
/* Z1[k] = (X1[128-2*k-1] + j * X1[2*k]) * (xcos2[k] + j * xsin2[k]); */
buf1[k].real = data[p] * p_imdct->xcos2[j] - data[q] * p_imdct->xsin2[j];
buf1[k].imag = -1.0f*(data[q] * p_imdct->xcos2[j] + data[p] * p_imdct->xsin2[j]);
/* Z2[k] = (X2[128-2*k-1] + j * X2[2*k]) * (xcos2[k] + j * xsin2[k]); */
buf2[k].real = data[p + 1] * p_imdct->xcos2[j] - data[q + 1] * p_imdct->xsin2[j];
buf2[k].imag = -1.0f*(data[q + 1] * p_imdct->xcos2[j] + data[p + 1] * p_imdct->xsin2[j]);
}
p_imdct->fft_64p(&buf1[0]);
p_imdct->fft_64p(&buf2[0]);
/* Post IFFT complex multiply */
for( i=0; i < 64; i++) {
tmp_a_r = buf1[i].real;
tmp_a_i = -buf1[i].imag;
buf1[i].real = (tmp_a_r * p_imdct->xcos2[i]) - (tmp_a_i * p_imdct->xsin2[i]);
buf1[i].imag = (tmp_a_r * p_imdct->xsin2[i]) + (tmp_a_i * p_imdct->xcos2[i]);
tmp_a_r = buf2[i].real;
tmp_a_i = -buf2[i].imag;
buf2[i].real = (tmp_a_r * p_imdct->xcos2[i]) - (tmp_a_i * p_imdct->xsin2[i]);
buf2[i].imag = (tmp_a_r * p_imdct->xsin2[i]) + (tmp_a_i * p_imdct->xcos2[i]);
}
data_ptr = data;
delay_ptr = delay;
window_ptr = window;
/* Window and convert to real valued signal */
for(i=0; i< 64; i++) {
*data_ptr++ = -buf1[i].imag * *window_ptr++ + *delay_ptr++;
*data_ptr++ = buf1[64-i-1].real * *window_ptr++ + *delay_ptr++;
}
for(i=0; i< 64; i++) {
*data_ptr++ = -buf1[i].real * *window_ptr++ + *delay_ptr++;
*data_ptr++ = buf1[64-i-1].imag * *window_ptr++ + *delay_ptr++;
}
delay_ptr = delay;
for(i=0; i< 64; i++) {
*delay_ptr++ = -buf2[i].real * *--window_ptr;
*delay_ptr++ = buf2[64-i-1].imag * *--window_ptr;
}
for(i=0; i< 64; i++) {
*delay_ptr++ = buf2[i].imag * *--window_ptr;
*delay_ptr++ = -buf2[64-i-1].real * *--window_ptr;
}
}
void imdct_do_256_nol (imdct_t * p_imdct, float data[], float delay[])
{
int i, j, k;
int p, q;
float tmp_a_i;
float tmp_a_r;
float *data_ptr;
float *delay_ptr;
float *window_ptr;
complex_t *buf1, *buf2;
buf1 = &p_imdct->buf[0];
buf2 = &p_imdct->buf[64];
/* Pre IFFT complex multiply plus IFFT cmplx conjugate */
for(k=0; k<64; k++) {
/* X1[k] = X[2*k]
* X2[k] = X[2*k+1] */
j = pm64[k];
p = 2 * (128-2*j-1);
q = 2 * (2 * j);
/* Z1[k] = (X1[128-2*k-1] + j * X1[2*k]) * (xcos2[k] + j * xsin2[k]); */
buf1[k].real = data[p] * p_imdct->xcos2[j] - data[q] * p_imdct->xsin2[j];
buf1[k].imag = -1.0f*(data[q] * p_imdct->xcos2[j] + data[p] * p_imdct->xsin2[j]);
/* Z2[k] = (X2[128-2*k-1] + j * X2[2*k]) * (xcos2[k] + j * xsin2[k]); */
buf2[k].real = data[p + 1] * p_imdct->xcos2[j] - data[q + 1] * p_imdct->xsin2[j];
buf2[k].imag = -1.0f*(data[q + 1] * p_imdct->xcos2[j] + data[p + 1] * p_imdct->xsin2[j]);
}
p_imdct->fft_64p(&buf1[0]);
p_imdct->fft_64p(&buf2[0]);
/* Post IFFT complex multiply */
for( i=0; i < 64; i++) {
/* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
tmp_a_r = buf1[i].real;
tmp_a_i = -buf1[i].imag;
buf1[i].real =(tmp_a_r * p_imdct->xcos2[i]) - (tmp_a_i * p_imdct->xsin2[i]);
buf1[i].imag =(tmp_a_r * p_imdct->xsin2[i]) + (tmp_a_i * p_imdct->xcos2[i]);
/* y2[n] = z2[n] * (xcos2[n] + j * xsin2[n]) ; */
tmp_a_r = buf2[i].real;
tmp_a_i = -buf2[i].imag;
buf2[i].real =(tmp_a_r * p_imdct->xcos2[i]) - (tmp_a_i * p_imdct->xsin2[i]);
buf2[i].imag =(tmp_a_r * p_imdct->xsin2[i]) + (tmp_a_i * p_imdct->xcos2[i]);
}
data_ptr = data;
delay_ptr = delay;
window_ptr = window;
/* Window and convert to real valued signal, no overlap */
for(i=0; i< 64; i++) {
*data_ptr++ = -buf1[i].imag * *window_ptr++;
*data_ptr++ = buf1[64-i-1].real * *window_ptr++;
}
for(i=0; i< 64; i++) {
*data_ptr++ = -buf1[i].real * *window_ptr++ + *delay_ptr++;
*data_ptr++ = buf1[64-i-1].imag * *window_ptr++ + *delay_ptr++;
}
delay_ptr = delay;
for(i=0; i< 64; i++) {
*delay_ptr++ = -buf2[i].real * *--window_ptr;
*delay_ptr++ = buf2[64-i-1].imag * *--window_ptr;
}
for(i=0; i< 64; i++) {
*delay_ptr++ = buf2[i].imag * *--window_ptr;
*delay_ptr++ = -buf2[64-i-1].real * *--window_ptr;
}
}
void imdct_do_512_c (imdct_t * p_imdct, float data[], float delay[])
{
int i, j;
float tmp_a_r, tmp_a_i;
float *data_ptr;
float *delay_ptr;
float *window_ptr;
/* 512 IMDCT with source and dest data in 'data'
* Pre IFFT complex multiply plus IFFT complex conjugate */
for( i=0; i < 128; i++) {
j = pm128[i];
/* a = (data[256-2*j-1] - data[2*j]) * (xcos1[j] + xsin1[j]);
* c = data[2*j] * xcos1[j];
* b = data[256-2*j-1] * xsin1[j];
* buf1[i].real = a - b + c;
* buf1[i].imag = b + c; */
p_imdct->buf[i].real = (data[256-2*j-1] * p_imdct->xcos1[j]) - (data[2*j] * p_imdct->xsin1[j]);
p_imdct->buf[i].imag = -1.0 * (data[2*j] * p_imdct->xcos1[j] + data[256-2*j-1] * p_imdct->xsin1[j]);
}
fft_128p_c (&p_imdct->buf[0]);
/* Post IFFT complex multiply plus IFFT complex conjugate */
for (i=0; i < 128; i++) {
tmp_a_r = p_imdct->buf[i].real;
tmp_a_i = p_imdct->buf[i].imag;
/* a = (tmp_a_r - tmp_a_i) * (xcos1[j] + xsin1[j]);
* b = tmp_a_r * xsin1[j];
* c = tmp_a_i * xcos1[j];
* buf[j].real = a - b + c;
* buf[j].imag = b + c; */
p_imdct->buf[i].real =(tmp_a_r * p_imdct->xcos1[i]) + (tmp_a_i * p_imdct->xsin1[i]);
p_imdct->buf[i].imag =(tmp_a_r * p_imdct->xsin1[i]) - (tmp_a_i * p_imdct->xcos1[i]);
}
data_ptr = data;
delay_ptr = delay;
window_ptr = window;
/* Window and convert to real valued signal */
for (i=0; i< 64; i++) {
*data_ptr++ = -p_imdct->buf[64+i].imag * *window_ptr++ + *delay_ptr++;
*data_ptr++ = p_imdct->buf[64-i-1].real * *window_ptr++ + *delay_ptr++;
}
for(i=0; i< 64; i++) {
*data_ptr++ = -p_imdct->buf[i].real * *window_ptr++ + *delay_ptr++;
*data_ptr++ = p_imdct->buf[128-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< 64; i++) {
*delay_ptr++ = -p_imdct->buf[64+i].real * *--window_ptr;
*delay_ptr++ = p_imdct->buf[64-i-1].imag * *--window_ptr;
}
for(i=0; i<64; i++) {
*delay_ptr++ = p_imdct->buf[i].imag * *--window_ptr;
*delay_ptr++ = -p_imdct->buf[128-i-1].real * *--window_ptr;
}
}
void imdct_do_512_nol_c (imdct_t * p_imdct, float data[], float delay[])
{
int i, j;
float tmp_a_i;
float tmp_a_r;
float *data_ptr;
float *delay_ptr;
float *window_ptr;
/* 512 IMDCT with source and dest data in 'data'
* Pre IFFT complex multiply plus IFFT cmplx conjugate */
for( i=0; i < 128; i++) {
/* z[i] = (X[256-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) */
j = pm128[i];
/* a = (data[256-2*j-1] - data[2*j]) * (xcos1[j] + xsin1[j]);
* c = data[2*j] * xcos1[j];
* b = data[256-2*j-1] * xsin1[j];
* buf1[i].real = a - b + c;
* buf1[i].imag = b + c; */
p_imdct->buf[i].real = (data[256-2*j-1] * p_imdct->xcos1[j]) - (data[2*j] * p_imdct->xsin1[j]);
p_imdct->buf[i].imag = -1.0 * (data[2*j] * p_imdct->xcos1[j] + data[256-2*j-1] * p_imdct->xsin1[j]);
}
fft_128p_c (&p_imdct->buf[0]);
/* Post IFFT complex multiply plus IFFT complex conjugate*/
for (i=0; i < 128; i++) {
/* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ;
* int j1 = i; */
tmp_a_r = p_imdct->buf[i].real;
tmp_a_i = p_imdct->buf[i].imag;
/* a = (tmp_a_r - tmp_a_i) * (xcos1[j] + xsin1[j]);
* b = tmp_a_r * xsin1[j];
* c = tmp_a_i * xcos1[j];
* buf[j].real = a - b + c;
* buf[j].imag = b + c; */
p_imdct->buf[i].real =(tmp_a_r * p_imdct->xcos1[i]) + (tmp_a_i * p_imdct->xsin1[i]);
p_imdct->buf[i].imag =(tmp_a_r * p_imdct->xsin1[i]) - (tmp_a_i * p_imdct->xcos1[i]);
}
data_ptr = data;
delay_ptr = delay;
window_ptr = window;
/* Window and convert to real valued signal, no overlap here*/
for (i=0; i< 64; i++) {
*data_ptr++ = -p_imdct->buf[64+i].imag * *window_ptr++;
*data_ptr++ = p_imdct->buf[64-i-1].real * *window_ptr++;
}
for(i=0; i< 64; i++) {
*data_ptr++ = -p_imdct->buf[i].real * *window_ptr++;
*data_ptr++ = p_imdct->buf[128-i-1].imag * *window_ptr++;
}
/* The trailing edge of the window goes into the delay line */
delay_ptr = delay;
for(i=0; i< 64; i++) {
*delay_ptr++ = -p_imdct->buf[64+i].real * *--window_ptr;
*delay_ptr++ = p_imdct->buf[64-i-1].imag * *--window_ptr;
}
for(i=0; i<64; i++) {
*delay_ptr++ = p_imdct->buf[i].imag * *--window_ptr;
*delay_ptr++ = -p_imdct->buf[128-i-1].real * *--window_ptr;
}
}
int imdct_init_c (imdct_t * p_imdct);
void imdct_do_256(imdct_t * p_imdct, float data[], float delay[]);
void imdct_do_256_nol(imdct_t * p_imdct, float data[], float delay[]);
void imdct_do_512_c(imdct_t * p_imdct, float data[], float delay[]);
void imdct_do_512_nol_c(imdct_t * p_imdct, float data[], float delay[]);
......@@ -2,7 +2,7 @@
* ac3_mantissa.c: ac3 mantissa computation
*****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id: ac3_mantissa.c,v 1.24 2001/04/26 00:12:19 reno Exp $
* $Id: ac3_mantissa.c,v 1.25 2001/04/30 21:04:20 reno Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Aaron Holtzman <aholtzma@engr.uvic.ca>
......@@ -411,10 +411,10 @@ static __inline__ void uncouple_channel (ac3dec_t * p_ac3dec, u32 ch)
* so the channels are uncorrelated */
if (p_ac3dec->audblk.dithflag[ch] && !p_ac3dec->audblk.cpl_bap[i])
{
p_ac3dec->coeffs.fbw[ch][i] = cpl_coord * dither_gen(&p_ac3dec->mantissa) *
p_ac3dec->samples[ch][i] = cpl_coord * dither_gen(&p_ac3dec->mantissa) *
scale_factor[p_ac3dec->audblk.cpl_exp[i]];
} else {
p_ac3dec->coeffs.fbw[ch][i] = cpl_coord * p_ac3dec->audblk.cpl_flt[i];
p_ac3dec->samples[ch][i] = cpl_coord * p_ac3dec->audblk.cpl_flt[i];
}
i++;
}
......@@ -432,7 +432,7 @@ void mantissa_unpack (ac3dec_t * p_ac3dec)
for (i=0; i< p_ac3dec->bsi.nfchans; i++) {
for (j=0; j < p_ac3dec->audblk.endmant[i]; j++)
p_ac3dec->coeffs.fbw[i][j] = coeff_get_float(p_ac3dec, p_ac3dec->audblk.fbw_bap[i][j],
p_ac3dec->samples[i][j] = coeff_get_float(p_ac3dec, p_ac3dec->audblk.fbw_bap[i][j],
p_ac3dec->audblk.dithflag[i], p_ac3dec->audblk.fbw_exp[i][j]);
if (p_ac3dec->audblk.cplinu && p_ac3dec->audblk.chincpl[i] && !(done_cpl)) {
......@@ -458,7 +458,7 @@ void mantissa_unpack (ac3dec_t * p_ac3dec)
if (p_ac3dec->bsi.lfeon) {
/* There are always 7 mantissas for lfe, no dither for lfe */
for (j=0; j < 7 ; j++)
p_ac3dec->coeffs.lfe[j] = coeff_get_float(p_ac3dec, p_ac3dec->audblk.lfe_bap[j],
p_ac3dec->samples[5][j] = coeff_get_float(p_ac3dec, p_ac3dec->audblk.lfe_bap[j],
0, p_ac3dec->audblk.lfe_exp[j]);
}
}
......
......@@ -2,7 +2,7 @@
* ac3_rematrix.c: ac3 audio rematrixing
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: ac3_rematrix.c,v 1.14 2001/04/26 11:23:16 sam Exp $
* $Id: ac3_rematrix.c,v 1.15 2001/04/30 21:04:20 reno Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Aaron Holtzman <aholtzma@engr.uvic.ca>
......@@ -71,10 +71,10 @@ void rematrix (ac3dec_t * p_ac3dec)
end = min_value(rematrix_band[i].end ,12 * p_ac3dec->audblk.cplbegf + 36);
for (j=start;j < end; j++) {
left = 0.5f * (p_ac3dec->coeffs.fbw[0][j] + p_ac3dec->coeffs.fbw[1][j]);
right = 0.5f * (p_ac3dec->coeffs.fbw[0][j] - p_ac3dec->coeffs.fbw[1][j]);
p_ac3dec->coeffs.fbw[0][j] = left;
p_ac3dec->coeffs.fbw[1][j] = right;
left = 0.5f * (p_ac3dec->samples[0][j] + p_ac3dec->samples[1][j]);
right = 0.5f * (p_ac3dec->samples[0][j] - p_ac3dec->samples[1][j]);
p_ac3dec->samples[0][j] = left;
p_ac3dec->samples[1][j] = right;
}
}
}
#include "defs.h"
#include <math.h>
#include <stdio.h>
#include "config.h"
#include "common.h"
#include "threads.h"
#include "mtime.h"
#include "stream_control.h"
#include "input_ext-dec.h"
#include "ac3_decoder.h"
#include "ac3_srfft.h"
void fft_8 (complex_t *x);
void fft_4(complex_t *x)
{
/* delta_p = 1 here */
/* x[k] = sum_{i=0..3} x[i] * w^{i*k}, w=e^{-2*pi/4}
*/
register float yt_r, yt_i, yb_r, yb_i, u_r, u_i, vi_r, vi_i;
yt_r = x[0].real;
yb_r = yt_r - x[2].real;
yt_r += x[2].real;
u_r = x[1].real;
vi_i = x[3].real - u_r;
u_r += x[3].real;
u_i = x[1].imag;
vi_r = u_i - x[3].imag;
u_i += x[3].imag;
yt_i = yt_r;
yt_i += u_r;
x[0].real = yt_i;
yt_r -= u_r;
x[2].real = yt_r;
yt_i = yb_r;
yt_i += vi_r;
x[1].real = yt_i;
yb_r -= vi_r;
x[3].real = yb_r;
yt_i = x[0].imag;
yb_i = yt_i - x[2].imag;
yt_i += x[2].imag;
yt_r = yt_i;
yt_r += u_i;
x[0].imag = yt_r;
yt_i -= u_i;
x[2].imag = yt_i;
yt_r = yb_i;
yt_r += vi_i;
x[1].imag = yt_r;
yb_i -= vi_i;
x[3].imag = yb_i;
}
void fft_8 (complex_t *x)
{
/* delta_p = diag{1, sqrt(i)} here */
/* x[k] = sum_{i=0..7} x[i] * w^{i*k}, w=e^{-2*pi/8}
*/
register float wT1_r, wT1_i, wB1_r, wB1_i, wT2_r, wT2_i, wB2_r, wB2_i;
wT1_r = x[1].real;
wT1_i = x[1].imag;
wB1_r = x[3].real;
wB1_i = x[3].imag;
x[1] = x[2];
x[2] = x[4];
x[3] = x[6];
fft_4(&x[0]);
/* x[0] x[4] */
wT2_r = x[5].real;
wT2_r += x[7].real;
wT2_r += wT1_r;
wT2_r += wB1_r;
wT2_i = wT2_r;
wT2_r += x[0].real;
wT2_i = x[0].real - wT2_i;
x[0].real = wT2_r;
x[4].real = wT2_i;
wT2_i = x[5].imag;
wT2_i += x[7].imag;
wT2_i += wT1_i;
wT2_i += wB1_i;
wT2_r = wT2_i;
wT2_r += x[0].imag;
wT2_i = x[0].imag - wT2_i;
x[0].imag = wT2_r;
x[4].imag = wT2_i;
/* x[2] x[6] */
wT2_r = x[5].imag;
wT2_r -= x[7].imag;
wT2_r += wT1_i;
wT2_r -= wB1_i;
wT2_i = wT2_r;
wT2_r += x[2].real;
wT2_i = x[2].real - wT2_i;
x[2].real = wT2_r;
x[6].real = wT2_i;
wT2_i = x[5].real;
wT2_i -= x[7].real;
wT2_i += wT1_r;
wT2_i -= wB1_r;
wT2_r = wT2_i;
wT2_r += x[2].imag;
wT2_i = x[2].imag - wT2_i;
x[2].imag = wT2_i;
x[6].imag = wT2_r;
/* x[1] x[5] */
wT2_r = wT1_r;
wT2_r += wB1_i;
wT2_r -= x[5].real;
wT2_r -= x[7].imag;
wT2_i = wT1_i;
wT2_i -= wB1_r;
wT2_i -= x[5].imag;
wT2_i += x[7].real;
wB2_r = wT2_r;
wB2_r += wT2_i;
wT2_i -= wT2_r;
wB2_r *= HSQRT2;
wT2_i *= HSQRT2;
wT2_r = wB2_r;
wB2_r += x[1].real;
wT2_r = x[1].real - wT2_r;
wB2_i = x[5].real;
x[1].real = wB2_r;
x[5].real = wT2_r;
wT2_r = wT2_i;
wT2_r += x[1].imag;
wT2_i = x[1].imag - wT2_i;
wB2_r = x[5].imag;
x[1].imag = wT2_r;
x[5].imag = wT2_i;
/* x[3] x[7] */
wT1_r -= wB1_i;
wT1_i += wB1_r;
wB1_r = wB2_i - x[7].imag;
wB1_i = wB2_r + x[7].real;
wT1_r -= wB1_r;
wT1_i -= wB1_i;
wB1_r = wT1_r + wT1_i;
wB1_r *= HSQRT2;
wT1_i -= wT1_r;
wT1_i *= HSQRT2;
wB2_r = x[3].real;
wB2_i = wB2_r + wT1_i;
wB2_r -= wT1_i;
x[3].real = wB2_i;
x[7].real = wB2_r;
wB2_i = x[3].imag;
wB2_r = wB2_i + wB1_r;
wB2_i -= wB1_r;
x[3].imag = wB2_i;
x[7].imag = wB2_r;
}
void fft_asmb(int k, complex_t *x, complex_t *wTB,
const complex_t *d, const complex_t *d_3)
{
register complex_t *x2k, *x3k, *x4k, *wB;
register float a_r, a_i, a1_r, a1_i, u_r, u_i, v_r, v_i;
x2k = x + 2 * k;
x3k = x2k + 2 * k;
x4k = x3k + 2 * k;
wB = wTB + 2 * k;
TRANSZERO(x[0],x2k[0],x3k[0],x4k[0]);
TRANS(x[1],x2k[1],x3k[1],x4k[1],wTB[1],wB[1],d[1],d_3[1]);
--k;
for(;;) {
TRANS(x[2],x2k[2],x3k[2],x4k[2],wTB[2],wB[2],d[2],d_3[2]);
TRANS(x[3],x2k[3],x3k[3],x4k[3],wTB[3],wB[3],d[3],d_3[3]);
if (!--k) break;
x += 2;
x2k += 2;
x3k += 2;
x4k += 2;
d += 2;
d_3 += 2;
wTB += 2;
wB += 2;
}
}
void fft_asmb16(complex_t *x, complex_t *wTB)
{
register float a_r, a_i, a1_r, a1_i, u_r, u_i, v_r, v_i;
int k = 2;
/* transform x[0], x[8], x[4], x[12] */
TRANSZERO(x[0],x[4],x[8],x[12]);
/* transform x[1], x[9], x[5], x[13] */
TRANS(x[1],x[5],x[9],x[13],wTB[1],wTB[5],delta16[1],delta16_3[1]);
/* transform x[2], x[10], x[6], x[14] */
TRANSHALF_16(x[2],x[6],x[10],x[14]);
/* transform x[3], x[11], x[7], x[15] */
TRANS(x[3],x[7],x[11],x[15],wTB[3],wTB[7],delta16[3],delta16_3[3]);
}
void fft_64p_c (complex_t *a)
{
fft_8(&a[0]); fft_4(&a[8]); fft_4(&a[12]);
fft_asmb16(&a[0], &a[8]);
fft_8(&a[16]), fft_8(&a[24]);
fft_asmb(4, &a[0], &a[16],&delta32[0], &delta32_3[0]);
fft_8(&a[32]); fft_4(&a[40]); fft_4(&a[44]);
fft_asmb16(&a[32], &a[40]);
fft_8(&a[48]); fft_4(&a[56]); fft_4(&a[60]);
fft_asmb16(&a[48], &a[56]);
fft_asmb(8, &a[0], &a[32],&delta64[0], &delta64_3[0]);
}
void fft_128p_c (complex_t *a)
{
fft_8(&a[0]); fft_4(&a[8]); fft_4(&a[12]);
fft_asmb16(&a[0], &a[8]);
fft_8(&a[16]), fft_8(&a[24]);
fft_asmb(4, &a[0], &a[16],&delta32[0], &delta32_3[0]);
fft_8(&a[32]); fft_4(&a[40]); fft_4(&a[44]);
fft_asmb16(&a[32], &a[40]);
fft_8(&a[48]); fft_4(&a[56]); fft_4(&a[60]);
fft_asmb16(&a[48], &a[56]);
fft_asmb(8, &a[0], &a[32],&delta64[0], &delta64_3[0]);
fft_8(&a[64]); fft_4(&a[72]); fft_4(&a[76]);
/* fft_16(&a[64]); */
fft_asmb16(&a[64], &a[72]);
fft_8(&a[80]); fft_8(&a[88]);
/* fft_32(&a[64]); */
fft_asmb(4, &a[64], &a[80],&delta32[0], &delta32_3[0]);
fft_8(&a[96]); fft_4(&a[104]), fft_4(&a[108]);
/* fft_16(&a[96]); */
fft_asmb16(&a[96], &a[104]);
fft_8(&a[112]), fft_8(&a[120]);
/* fft_32(&a[96]); */
fft_asmb(4, &a[96], &a[112], &delta32[0], &delta32_3[0]);
/* fft_128(&a[0]); */
fft_asmb(16, &a[0], &a[64], &delta128[0], &delta128_3[0]);
}
static complex_t delta16[4] =
{ {1.00000000000000, 0.00000000000000},
{0.92387953251129, -0.38268343236509},
{0.70710678118655, -0.70710678118655},
{0.38268343236509, -0.92387953251129}};
static complex_t delta16_3[4] =
{ {1.00000000000000, 0.00000000000000},
{0.38268343236509, -0.92387953251129},
{-0.70710678118655, -0.70710678118655},
{-0.92387953251129, 0.38268343236509}};
static complex_t delta32[8] =
{ {1.00000000000000, 0.00000000000000},
{0.98078528040323, -0.19509032201613},
{0.92387953251129, -0.38268343236509},
{0.83146961230255, -0.55557023301960},
{0.70710678118655, -0.70710678118655},
{0.55557023301960, -0.83146961230255},
{0.38268343236509, -0.92387953251129},
{0.19509032201613, -0.98078528040323}};
static complex_t delta32_3[8] =
{ {1.00000000000000, 0.00000000000000},
{0.83146961230255, -0.55557023301960},
{0.38268343236509, -0.92387953251129},
{-0.19509032201613, -0.98078528040323},
{-0.70710678118655, -0.70710678118655},
{-0.98078528040323, -0.19509032201613},
{-0.92387953251129, 0.38268343236509},
{-0.55557023301960, 0.83146961230255}};
static complex_t delta64[16] =
{ {1.00000000000000, 0.00000000000000},
{0.99518472667220, -0.09801714032956},
{0.98078528040323, -0.19509032201613},
{0.95694033573221, -0.29028467725446},
{0.92387953251129, -0.38268343236509},
{0.88192126434836, -0.47139673682600},
{0.83146961230255, -0.55557023301960},
{0.77301045336274, -0.63439328416365},
{0.70710678118655, -0.70710678118655},
{0.63439328416365, -0.77301045336274},
{0.55557023301960, -0.83146961230255},
{0.47139673682600, -0.88192126434835},
{0.38268343236509, -0.92387953251129},
{0.29028467725446, -0.95694033573221},
{0.19509032201613, -0.98078528040323},
{0.09801714032956, -0.99518472667220}};
static complex_t delta64_3[16] =
{ {1.00000000000000, 0.00000000000000},
{0.95694033573221, -0.29028467725446},
{0.83146961230255, -0.55557023301960},
{0.63439328416365, -0.77301045336274},
{0.38268343236509, -0.92387953251129},
{0.09801714032956, -0.99518472667220},
{-0.19509032201613, -0.98078528040323},
{-0.47139673682600, -0.88192126434836},
{-0.70710678118655, -0.70710678118655},
{-0.88192126434835, -0.47139673682600},
{-0.98078528040323, -0.19509032201613},
{-0.99518472667220, 0.09801714032956},
{-0.92387953251129, 0.38268343236509},
{-0.77301045336274, 0.63439328416365},
{-0.55557023301960, 0.83146961230255},
{-0.29028467725446, 0.95694033573221}};
static complex_t delta128[32] =
{ {1.00000000000000, 0.00000000000000},
{0.99879545620517, -0.04906767432742},
{0.99518472667220, -0.09801714032956},
{0.98917650996478, -0.14673047445536},
{0.98078528040323, -0.19509032201613},
{0.97003125319454, -0.24298017990326},
{0.95694033573221, -0.29028467725446},
{0.94154406518302, -0.33688985339222},
{0.92387953251129, -0.38268343236509},
{0.90398929312344, -0.42755509343028},
{0.88192126434836, -0.47139673682600},
{0.85772861000027, -0.51410274419322},
{0.83146961230255, -0.55557023301960},
{0.80320753148064, -0.59569930449243},
{0.77301045336274, -0.63439328416365},
{0.74095112535496, -0.67155895484702},
{0.70710678118655, -0.70710678118655},
{0.67155895484702, -0.74095112535496},
{0.63439328416365, -0.77301045336274},
{0.59569930449243, -0.80320753148064},
{0.55557023301960, -0.83146961230255},
{0.51410274419322, -0.85772861000027},
{0.47139673682600, -0.88192126434835},
{0.42755509343028, -0.90398929312344},
{0.38268343236509, -0.92387953251129},
{0.33688985339222, -0.94154406518302},
{0.29028467725446, -0.95694033573221},
{0.24298017990326, -0.97003125319454},
{0.19509032201613, -0.98078528040323},
{0.14673047445536, -0.98917650996478},
{0.09801714032956, -0.99518472667220},
{0.04906767432742, -0.99879545620517}};
static complex_t delta128_3[32] =
{ {1.00000000000000, 0.00000000000000},
{0.98917650996478, -0.14673047445536},
{0.95694033573221, -0.29028467725446},
{0.90398929312344, -0.42755509343028},
{0.83146961230255, -0.55557023301960},
{0.74095112535496, -0.67155895484702},
{0.63439328416365, -0.77301045336274},
{0.51410274419322, -0.85772861000027},
{0.38268343236509, -0.92387953251129},
{0.24298017990326, -0.97003125319454},
{0.09801714032956, -0.99518472667220},
{-0.04906767432742, -0.99879545620517},
{-0.19509032201613, -0.98078528040323},
{-0.33688985339222, -0.94154406518302},
{-0.47139673682600, -0.88192126434836},
{-0.59569930449243, -0.80320753148065},
{-0.70710678118655, -0.70710678118655},
{-0.80320753148065, -0.59569930449243},
{-0.88192126434835, -0.47139673682600},
{-0.94154406518302, -0.33688985339222},
{-0.98078528040323, -0.19509032201613},
{-0.99879545620517, -0.04906767432742},
{-0.99518472667220, 0.09801714032956},
{-0.97003125319454, 0.24298017990326},
{-0.92387953251129, 0.38268343236509},
{-0.85772861000027, 0.51410274419322},
{-0.77301045336274, 0.63439328416365},
{-0.67155895484702, 0.74095112535496},
{-0.55557023301960, 0.83146961230255},
{-0.42755509343028, 0.90398929312344},
{-0.29028467725446, 0.95694033573221},
{-0.14673047445536, 0.98917650996478}};
#define HSQRT2 0.707106781188;
#define TRANSZERO(A0,A4,A8,A12) { \
u_r = wTB[0].real; \
v_i = u_r - wTB[k*2].real; \
u_r += wTB[k*2].real; \
u_i = wTB[0].imag; \
v_r = wTB[k*2].imag - u_i; \
u_i += wTB[k*2].imag; \
a_r = A0.real; \
a_i = A0.imag; \
a1_r = a_r; \
a1_r += u_r; \
A0.real = a1_r; \
a_r -= u_r; \
A8.real = a_r; \
a1_i = a_i; \
a1_i += u_i; \
A0.imag = a1_i; \
a_i -= u_i; \
A8.imag = a_i; \
a1_r = A4.real; \
a1_i = A4.imag; \
a_r = a1_r; \
a_r -= v_r; \
A4.real = a_r; \
a1_r += v_r; \
A12.real = a1_r; \
a_i = a1_i; \
a_i -= v_i; \
A4.imag = a_i; \
a1_i += v_i; \
A12.imag = a1_i; \
}
#define TRANSHALF_16(A2,A6,A10,A14) {\
u_r = wTB[2].real; \
a_r = u_r; \
u_i = wTB[2].imag; \
u_r += u_i; \
u_i -= a_r; \
a_r = wTB[6].real; \
a1_r = a_r; \
a_i = wTB[6].imag; \
a_r = a_i - a_r; \
a_i += a1_r; \
v_i = u_r - a_r; \
u_r += a_r; \
v_r = u_i + a_i; \
u_i -= a_i; \
v_i *= HSQRT2; \
v_r *= HSQRT2; \
u_r *= HSQRT2; \
u_i *= HSQRT2; \
a_r = A2.real; \
a_i = A2.imag; \
a1_r = a_r; \
a1_r += u_r; \
A2.real = a1_r; \
a_r -= u_r; \
A10.real = a_r; \
a1_i = a_i; \
a1_i += u_i; \
A2.imag = a1_i; \
a_i -= u_i; \
A10.imag = a_i; \
a1_r = A6.real; \
a1_i = A6.imag; \
a_r = a1_r; \
a1_r += v_r; \
A6.real = a1_r; \
a_r -= v_r; \
A14.real = a_r; \
a_i = a1_i; \
a1_i -= v_i; \
A6.imag = a1_i; \
a_i += v_i; \
A14.imag = a_i; \
}
#define TRANS(A1,A5,A9,A13,WT,WB,D,D3) { \
u_r = WT.real; \
a_r = u_r; \
a_r *= D.imag; \
u_r *= D.real; \
a_i = WT.imag; \
a1_i = a_i; \
a1_i *= D.real; \
a_i *= D.imag; \
u_r -= a_i; \
u_i = a_r; \
u_i += a1_i; \
a_r = WB.real; \
a1_r = a_r; \
a1_r *= D3.real; \
a_r *= D3.imag; \
a_i = WB.imag; \
a1_i = a_i; \
a_i *= D3.real; \
a1_i *= D3.imag; \
a1_r -= a1_i; \
a_r += a_i; \
v_i = u_r - a1_r; \
u_r += a1_r; \
v_r = a_r - u_i; \
u_i += a_r; \
a_r = A1.real; \
a_i = A1.imag; \
a1_r = a_r; \
a1_r += u_r; \
A1.real = a1_r; \
a_r -= u_r; \
A9.real = a_r; \
a1_i = a_i; \
a1_i += u_i; \
A1.imag = a1_i; \
a_i -= u_i; \
A9.imag = a_i; \
a1_r = A5.real; \
a1_i = A5.imag; \
a_r = a1_r; \
a1_r -= v_r; \
A5.real = a1_r; \
a_r += v_r; \
A13.real = a_r; \
a_i = a1_i; \
a1_i -= v_i; \
A5.imag = a1_i; \
a_i += v_i; \
A13.imag = a_i; \
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment