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 \ ...@@ -70,6 +70,8 @@ AC3_DECODER = src/ac3_decoder/ac3_decoder_thread.o \
src/ac3_decoder/ac3_mantissa.o \ src/ac3_decoder/ac3_mantissa.o \
src/ac3_decoder/ac3_rematrix.o \ src/ac3_decoder/ac3_rematrix.o \
src/ac3_decoder/ac3_imdct.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.o \
src/ac3_decoder/ac3_downmix_c.o src/ac3_decoder/ac3_downmix_c.o
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ac3_decoder.c: core ac3 decoder * ac3_decoder.c: core ac3 decoder
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN * 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> * Authors: Michel Kaempf <maxx@via.ecp.fr>
* Michel Lespinasse <walken@zoy.org> * Michel Lespinasse <walken@zoy.org>
...@@ -45,6 +45,10 @@ ...@@ -45,6 +45,10 @@
#include <stdio.h> #include <stdio.h>
void imdct_init (imdct_t * p_imdct); 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) int ac3_init (ac3dec_t * p_ac3dec)
{ {
...@@ -52,6 +56,7 @@ 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->bit_stream.i_available = 0;
p_ac3dec->mantissa.lfsr_state = 1; /* dither_gen initialization */ p_ac3dec->mantissa.lfsr_state = 1; /* dither_gen initialization */
imdct_init(&p_ac3dec->imdct); imdct_init(&p_ac3dec->imdct);
downmix_init(&p_ac3dec->downmix);
return 0; return 0;
} }
...@@ -68,7 +73,27 @@ int ac3_decode_frame (ac3dec_t * p_ac3dec, s16 * buffer) ...@@ -68,7 +73,27 @@ int ac3_decode_frame (ac3dec_t * p_ac3dec, s16 * buffer)
return 1; 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++) { 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)) if ((p_ac3dec_t->p_fifo->b_die) && (p_ac3dec_t->p_fifo->b_error))
{ {
return 1; return 1;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ac3_decoder.h : ac3 decoder interface * ac3_decoder.h : ac3 decoder interface
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN * 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> * Authors: Michel Kaempf <maxx@via.ecp.fr>
* Renaud Dartus <reno@videolan.org> * Renaud Dartus <reno@videolan.org>
...@@ -308,6 +308,7 @@ typedef struct audblk_s { ...@@ -308,6 +308,7 @@ typedef struct audblk_s {
} audblk_t; } audblk_t;
/* Everything you wanted to know about band structure */ /* Everything you wanted to know about band structure */
/* /*
* The entire frequency domain is represented by 256 real * The entire frequency domain is represented by 256 real
* floating point fourier coefficients. Only the lower 253 * floating point fourier coefficients. Only the lower 253
...@@ -326,17 +327,6 @@ typedef struct audblk_s { ...@@ -326,17 +327,6 @@ typedef struct audblk_s {
* approximate a 1/6 octave scale. * 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 typedef struct bit_allocate_s
{ {
s16 psd[256]; s16 psd[256];
...@@ -375,6 +365,7 @@ typedef struct imdct_s ...@@ -375,6 +365,7 @@ typedef struct imdct_s
/* Delay buffer for time domain interleaving */ /* Delay buffer for time domain interleaving */
float delay[6][256]; float delay[6][256];
float delay1[6][256];
/* Twiddle factors for IMDCT */ /* Twiddle factors for IMDCT */
float xcos1[N/4]; float xcos1[N/4];
...@@ -392,8 +383,32 @@ typedef struct imdct_s ...@@ -392,8 +383,32 @@ typedef struct imdct_s
complex_t w_32[32]; complex_t w_32[32];
complex_t w_64[64]; 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; } 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 struct ac3dec_s
{ {
/* /*
...@@ -412,10 +427,12 @@ struct ac3dec_s ...@@ -412,10 +427,12 @@ struct ac3dec_s
bsi_t bsi; bsi_t bsi;
audblk_t audblk; audblk_t audblk;
stream_coeffs_t coeffs; float samples[6][256];
stream_samples_t samples; dm_par_t dm_par;
bit_allocate_t bit_allocate; bit_allocate_t bit_allocate;
mantissa_t mantissa; mantissa_t mantissa;
imdct_t imdct; imdct_t imdct;
downmix_t downmix;
}; };
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ac3_decoder_thread.c: ac3 decoder thread * ac3_decoder_thread.c: ac3 decoder thread
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN * 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> * Authors: Michel Lespinasse <walken@zoy.org>
* *
...@@ -170,6 +170,7 @@ static void RunThread (ac3dec_thread_t * p_ac3dec_t) ...@@ -170,6 +170,7 @@ static void RunThread (ac3dec_thread_t * p_ac3dec_t)
{ {
s16 * buffer; s16 * buffer;
ac3_sync_info_t sync_info; ac3_sync_info_t sync_info;
int ptr;
if (!sync) { if (!sync) {
do { do {
...@@ -177,6 +178,14 @@ static void RunThread (ac3dec_thread_t * p_ac3dec_t) ...@@ -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) } while ((!p_ac3dec_t->sync_ptr) && (!p_ac3dec_t->p_fifo->b_die)
&& (!p_ac3dec_t->p_fifo->b_error)); && (!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 */ /* we are in sync now */
sync = 1; sync = 1;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ac3_downmix.c: ac3 downmix functions * ac3_downmix.c: ac3 downmix functions
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN * 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> * Authors: Michel Kaempf <maxx@via.ecp.fr>
* Aaron Holtzman <aholtzma@engr.uvic.ca> * Aaron Holtzman <aholtzma@engr.uvic.ca>
...@@ -29,72 +29,36 @@ ...@@ -29,72 +29,36 @@
#include "threads.h" #include "threads.h"
#include "mtime.h" #include "mtime.h"
#include "tests.h"
#include "stream_control.h" #include "stream_control.h"
#include "input_ext-dec.h" #include "input_ext-dec.h"
#include "ac3_decoder.h" #include "ac3_decoder.h"
#include "ac3_internal.h" #include "ac3_internal.h"
#include "ac3_downmix.h" #include "ac3_downmix.h"
/* Pre-scaled downmix coefficients */ void downmix_init (downmix_t * p_downmix)
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)
{ {
#if 0
dm_par_t dm_par; if ( TestCPU (CPU_CAPABILITY_MMX) )
{
dm_par.clev = 0.0; fprintf(stderr,"Using MMX for downmix\n");
dm_par.slev = 0.0; p_downmix->downmix_3f_2r_to_2ch = downmix_3f_2r_to_2ch_kni;
dm_par.unit = 1.0; 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;
if (p_ac3dec->bsi.acmod & 0x1) /* have center */ p_downmix->downmix_2f_1r_to_2ch = downmix_2f_1r_to_2ch_kni;
dm_par.clev = cmixlev_lut[p_ac3dec->bsi.cmixlev]; 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;
if (p_ac3dec->bsi.acmod & 0x4) /* have surround channels */ p_downmix->stream_sample_1ch_to_s16 = stream_sample_1ch_to_s16_kni;
dm_par.slev = smixlev_lut[p_ac3dec->bsi.surmixlev]; } else
#endif
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)
{ {
case 7: // 3/2 p_downmix->downmix_3f_2r_to_2ch = downmix_3f_2r_to_2ch_c;
downmix_3f_2r_to_2ch_c (channel, &dm_par); p_downmix->downmix_2f_2r_to_2ch = downmix_2f_2r_to_2ch_c;
break; p_downmix->downmix_3f_1r_to_2ch = downmix_3f_1r_to_2ch_c;
case 6: // 2/2 p_downmix->downmix_2f_1r_to_2ch = downmix_2f_1r_to_2ch_c;
downmix_2f_2r_to_2ch_c (channel, &dm_par); p_downmix->downmix_3f_0r_to_2ch = downmix_3f_0r_to_2ch_c;
break; p_downmix->stream_sample_2ch_to_s16 = stream_sample_2ch_to_s16_c;
case 5: // 3/1 p_downmix->stream_sample_1ch_to_s16 = stream_sample_1ch_to_s16_c;
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;
} }
return 0;
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ac3_downmix.h: ac3 downmix functions * ac3_downmix.h: ac3 downmix functions
***************************************************************************** *****************************************************************************
* Copyright (C) 2000, 2001 VideoLAN * 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> * Authors: Renaud Dartus <reno@videolan.org>
* *
...@@ -21,14 +21,7 @@ ...@@ -21,14 +21,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#define NORM 16384 /* C functions */
typedef struct dm_par_s {
float unit;
float clev;
float slev;
} dm_par_t;
void downmix_3f_2r_to_2ch_c(float *samples, dm_par_t * dm_par); 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_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); 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); ...@@ -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 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_2ch_to_s16_c(s16 *s16_samples, float *left, float *right);
void stream_sample_1ch_to_s16_c(s16 *s16_samples, float *center); 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 @@ ...@@ -2,7 +2,7 @@
* ac3_downmix_c.c: ac3 downmix functions * ac3_downmix_c.c: ac3 downmix functions
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN * 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> * Authors: Renaud Dartus <reno@videolan.org>
* Aaron Holtzman <aholtzma@engr.uvic.ca> * Aaron Holtzman <aholtzma@engr.uvic.ca>
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "ac3_internal.h" #include "ac3_internal.h"
#include "ac3_downmix.h" #include "ac3_downmix.h"
void __inline__ downmix_3f_2r_to_2ch_c (float *samples, dm_par_t *dm_par) void __inline__ downmix_3f_2r_to_2ch_c (float *samples, dm_par_t *dm_par)
{ {
int i; int i;
...@@ -137,8 +138,8 @@ void __inline__ stream_sample_2ch_to_s16_c (s16 *out_buf, float *left, float *ri ...@@ -137,8 +138,8 @@ void __inline__ stream_sample_2ch_to_s16_c (s16 *out_buf, float *left, float *ri
{ {
int i; int i;
for (i=0; i < 256; i++) { for (i=0; i < 256; i++) {
*out_buf++ = (s16) (*left++ * NORM); *out_buf++ = (s16) (*left++);
*out_buf++ = (s16) (*right++ * NORM); *out_buf++ = (s16) (*right++);
} }
} }
...@@ -149,7 +150,7 @@ void __inline__ stream_sample_1ch_to_s16_c (s16 *out_buf, float *center) ...@@ -149,7 +150,7 @@ void __inline__ stream_sample_1ch_to_s16_c (s16 *out_buf, float *center)
float tmp; float tmp;
for (i=0; i < 256; i++) { for (i=0; i < 256; i++) {
*out_buf++ = tmp = (s16) (0.7071f * *center++ * NORM); *out_buf++ = tmp = (s16) (0.7071f * *center++);
*out_buf++ = tmp; *out_buf++ = tmp;
} }
} }
This diff is collapsed.
This diff is collapsed.
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 @@ ...@@ -2,7 +2,7 @@
* ac3_mantissa.c: ac3 mantissa computation * ac3_mantissa.c: ac3 mantissa computation
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN * 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> * Authors: Michel Kaempf <maxx@via.ecp.fr>
* Aaron Holtzman <aholtzma@engr.uvic.ca> * Aaron Holtzman <aholtzma@engr.uvic.ca>
...@@ -411,10 +411,10 @@ static __inline__ void uncouple_channel (ac3dec_t * p_ac3dec, u32 ch) ...@@ -411,10 +411,10 @@ static __inline__ void uncouple_channel (ac3dec_t * p_ac3dec, u32 ch)
* so the channels are uncorrelated */ * so the channels are uncorrelated */
if (p_ac3dec->audblk.dithflag[ch] && !p_ac3dec->audblk.cpl_bap[i]) 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]]; scale_factor[p_ac3dec->audblk.cpl_exp[i]];
} else { } 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++; i++;
} }
...@@ -432,7 +432,7 @@ void mantissa_unpack (ac3dec_t * p_ac3dec) ...@@ -432,7 +432,7 @@ void mantissa_unpack (ac3dec_t * p_ac3dec)
for (i=0; i< p_ac3dec->bsi.nfchans; i++) { for (i=0; i< p_ac3dec->bsi.nfchans; i++) {
for (j=0; j < p_ac3dec->audblk.endmant[i]; j++) 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]); p_ac3dec->audblk.dithflag[i], p_ac3dec->audblk.fbw_exp[i][j]);
if (p_ac3dec->audblk.cplinu && p_ac3dec->audblk.chincpl[i] && !(done_cpl)) { if (p_ac3dec->audblk.cplinu && p_ac3dec->audblk.chincpl[i] && !(done_cpl)) {
...@@ -458,7 +458,7 @@ void mantissa_unpack (ac3dec_t * p_ac3dec) ...@@ -458,7 +458,7 @@ void mantissa_unpack (ac3dec_t * p_ac3dec)
if (p_ac3dec->bsi.lfeon) { if (p_ac3dec->bsi.lfeon) {
/* There are always 7 mantissas for lfe, no dither for lfe */ /* There are always 7 mantissas for lfe, no dither for lfe */
for (j=0; j < 7 ; j++) 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]); 0, p_ac3dec->audblk.lfe_exp[j]);
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ac3_rematrix.c: ac3 audio rematrixing * ac3_rematrix.c: ac3 audio rematrixing
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN * 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> * Authors: Michel Kaempf <maxx@via.ecp.fr>
* Aaron Holtzman <aholtzma@engr.uvic.ca> * Aaron Holtzman <aholtzma@engr.uvic.ca>
...@@ -71,10 +71,10 @@ void rematrix (ac3dec_t * p_ac3dec) ...@@ -71,10 +71,10 @@ void rematrix (ac3dec_t * p_ac3dec)
end = min_value(rematrix_band[i].end ,12 * p_ac3dec->audblk.cplbegf + 36); end = min_value(rematrix_band[i].end ,12 * p_ac3dec->audblk.cplbegf + 36);
for (j=start;j < end; j++) { for (j=start;j < end; j++) {
left = 0.5f * (p_ac3dec->coeffs.fbw[0][j] + p_ac3dec->coeffs.fbw[1][j]); left = 0.5f * (p_ac3dec->samples[0][j] + p_ac3dec->samples[1][j]);
right = 0.5f * (p_ac3dec->coeffs.fbw[0][j] - p_ac3dec->coeffs.fbw[1][j]); right = 0.5f * (p_ac3dec->samples[0][j] - p_ac3dec->samples[1][j]);
p_ac3dec->coeffs.fbw[0][j] = left; p_ac3dec->samples[0][j] = left;
p_ac3dec->coeffs.fbw[1][j] = right; 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