vdr/xine-lib-vdr/src/libdts Makefile.am Makefile.in bitstream.c bitstream.h downmix.c dts.h dts_internal.h parse.c tables.h tables_adpcm.h tables_fir.h tables_huffman.h tables_quantization.h tables_vq.h xine_decoder.c

Darren Salt pkg-vdr-dvb-changes@lists.alioth.debian.org
Mon, 04 Apr 2005 22:29:50 +0000


Update of /cvsroot/pkg-vdr-dvb/vdr/xine-lib-vdr/src/libdts
In directory haydn:/tmp/cvs-serv2129/src/libdts

Added Files:
	Makefile.am Makefile.in bitstream.c bitstream.h downmix.c 
	dts.h dts_internal.h parse.c tables.h tables_adpcm.h 
	tables_fir.h tables_huffman.h tables_quantization.h 
	tables_vq.h xine_decoder.c 
Log Message:
Import of VDR-patched xine-lib.

--- NEW FILE: dts_internal.h ---
/*
 * dts_internal.h
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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-1307  USA
 */

#define DTS_SUBFRAMES_MAX (16)
#define DTS_PRIM_CHANNELS_MAX (5)
#define DTS_SUBBANDS (32)
#define DTS_ABITS_MAX (32) /* Should be 28 */
#define DTS_SUBSUBFAMES_MAX (4)
#define DTS_LFE_MAX (3)

struct dts_state_s {

    /* Frame header */
    int frame_type;             /* type of the current frame */
    int samples_deficit;        /* deficit sample count */
    int crc_present;            /* crc is present in the bitstream */
    int sample_blocks;          /* number of PCM sample blocks */
    int frame_size;             /* primary frame byte size */
    int amode;                  /* audio channels arrangement */
    int sample_rate;            /* audio sampling rate */
    int bit_rate;               /* transmission bit rate */

    int downmix;                /* embedded downmix enabled */
    int dynrange;               /* embedded dynamic range flag */
    int timestamp;              /* embedded time stamp flag */
    int aux_data;               /* auxiliary data flag */
    int hdcd;                   /* source material is mastered in HDCD */
    int ext_descr;              /* extension audio descriptor flag */
    int ext_coding;             /* extended coding flag */
    int aspf;                   /* audio sync word insertion flag */
    int lfe;                    /* low frequency effects flag */
    int predictor_history;      /* predictor history flag */
    int header_crc;             /* header crc check bytes */
    int multirate_inter;        /* multirate interpolator switch */
    int version;                /* encoder software revision */
    int copy_history;           /* copy history */
    int source_pcm_res;         /* source pcm resolution */
    int front_sum;              /* front sum/difference flag */
    int surround_sum;           /* surround sum/difference flag */
    int dialog_norm;            /* dialog normalisation parameter */

    /* Primary audio coding header */
    int subframes;              /* number of subframes */
    int prim_channels;          /* number of primary audio channels */
    /* subband activity count */
    int subband_activity[DTS_PRIM_CHANNELS_MAX];
    /* high frequency vq start subband */
    int vq_start_subband[DTS_PRIM_CHANNELS_MAX];
    /* joint intensity coding index */
    int joint_intensity[DTS_PRIM_CHANNELS_MAX];
    /* transient mode code book */
    int transient_huffman[DTS_PRIM_CHANNELS_MAX];
    /* scale factor code book */
    int scalefactor_huffman[DTS_PRIM_CHANNELS_MAX];
    /* bit allocation quantizer select */
    int bitalloc_huffman[DTS_PRIM_CHANNELS_MAX];
    /* quantization index codebook select */
    int quant_index_huffman[DTS_PRIM_CHANNELS_MAX][DTS_ABITS_MAX];
    /* scale factor adjustment */
    float scalefactor_adj[DTS_PRIM_CHANNELS_MAX][DTS_ABITS_MAX];

    /* Primary audio coding side information */
    int subsubframes;           /* number of subsubframes */
    int partial_samples;        /* partial subsubframe samples count */
    /* prediction mode (ADPCM used or not) */
    int prediction_mode[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
    /* prediction VQ coefs */
    int prediction_vq[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
    /* bit allocation index */
    int bitalloc[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
    /* transition mode (transients) */
    int transition_mode[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
    /* scale factors (2 if transient)*/
    int scale_factor[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS][2];
    /* joint subband scale factors codebook */
    int joint_huff[DTS_PRIM_CHANNELS_MAX];
    /* joint subband scale factors */
    int joint_scale_factor[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
    /* stereo downmix coefficients */
    int downmix_coef[DTS_PRIM_CHANNELS_MAX][2];
    /* dynamic range coefficient */
    int dynrange_coef;

    /* VQ encoded high frequency subbands */
    int high_freq_vq[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];

    /* Low frequency effect data */
    double lfe_data[2*DTS_SUBSUBFAMES_MAX*DTS_LFE_MAX * 2 /*history*/];
    int lfe_scale_factor;

    /* Subband samples history (for ADPCM) */
    double subband_samples_hist[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS][4];
    double subband_fir_hist[DTS_PRIM_CHANNELS_MAX][512];
    double subband_fir_noidea[DTS_PRIM_CHANNELS_MAX][64];

    /* Audio output */
    level_t clev;            /* centre channel mix level */
    level_t slev;            /* surround channels mix level */

    int output;              /* type of output */
    level_t level;           /* output level */
    sample_t bias;           /* output bias */

    sample_t * samples;      /* pointer to the internal audio samples buffer */
    int downmixed;

    int dynrnge;             /* apply dynamic range */
    level_t dynrng;          /* dynamic range */
    void * dynrngdata;       /* dynamic range callback funtion and data */
    level_t (* dynrngcall) (level_t range, void * dynrngdata);

    /* Bitstream handling */
    uint32_t * buffer_start;
    uint32_t bits_left;
    uint32_t current_word;
    int      word_mode;         /* 16/14 bits word format (1 -> 16, 0 -> 14) */
    int      bigendian_mode;    /* endianness (1 -> be, 0 -> le) */

    /* Current position in DTS frame */
    int current_subframe;
    int current_subsubframe;

    /* Pre-calculated cosine modulation coefs for the QMF */
    double cos_mod[544];

    /* Debug flag */
    int debug_flag;
};

#define LEVEL_PLUS6DB 2.0
#define LEVEL_PLUS3DB 1.4142135623730951
#define LEVEL_3DB 0.7071067811865476
#define LEVEL_45DB 0.5946035575013605
#define LEVEL_6DB 0.5

int dts_downmix_init (int input, int flags, level_t * level,
                      level_t clev, level_t slev);
int dts_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
                       level_t clev, level_t slev);
void dts_downmix (sample_t * samples, int acmod, int output, sample_t bias,
                  level_t clev, level_t slev);
void dts_upmix (sample_t * samples, int acmod, int output);

#define ROUND(x) ((int)((x) + ((x) > 0 ? 0.5 : -0.5)))

#ifndef LIBDTS_FIXED

typedef sample_t quantizer_t;
#define SAMPLE(x) (x)
#define LEVEL(x) (x)
#define MUL(a,b) ((a) * (b))
#define MUL_L(a,b) ((a) * (b))
#define MUL_C(a,b) ((a) * (b))
#define DIV(a,b) ((a) / (b))
#define BIAS(x) ((x) + bias)

#else /* LIBDTS_FIXED */

typedef int16_t quantizer_t;
#define SAMPLE(x) (sample_t)((x) * (1 << 30))
#define LEVEL(x) (level_t)((x) * (1 << 26))

#if 0
#define MUL(a,b) ((int)(((int64_t)(a) * (b) + (1 << 29)) >> 30))
#define MUL_L(a,b) ((int)(((int64_t)(a) * (b) + (1 << 25)) >> 26))
#elif 1
#define MUL(a,b) \
({ int32_t _ta=(a), _tb=(b), _tc; \
   _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)(((_tc >> 14))+ (((_ta >> 16)*(_tb >> 16)) << 2 )); })
#define MUL_L(a,b) \
({ int32_t _ta=(a), _tb=(b), _tc; \
   _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)((_tc >> 10) + (((_ta >> 16)*(_tb >> 16)) << 6)); })
#else
#define MUL(a,b) (((a) >> 15) * ((b) >> 15))
#define MUL_L(a,b) (((a) >> 13) * ((b) >> 13))
#endif

#define MUL_C(a,b) MUL_L (a, LEVEL (b))
#define DIV(a,b) ((((int64_t)LEVEL (a)) << 26) / (b))
#define BIAS(x) (x)

#endif

--- NEW FILE: tables_vq.h ---
/*
 * tables_vq.h
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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
[...2036 lines suppressed...]
    6, -5, 6, -4, -7, 7, -21, 8, 1, 8, -9, -4, -3, 11, 25, -13 },
  { 4, 4, -1, -6, 4, 9, -8, 1, -3, -10, -2, 0, 15, -9, -16, 11, 
    1, 1, 6, 3, -9, -5, 16, 26, 1, -14, 1, -3, -14, 7, 15, -9 },
  { -12, -2, -9, -13, 2, 6, 14, 0, 1, 0, -1, -13, 0, 10, -1, 6, 
    9, -7, 8, 8, 19, 6, -1, 9, 10, -4, 1, -7, -22, -2, 29, -7 },
  { 2, 4, 13, -12, -8, -4, -5, 13, 12, -5, -3, -3, -4, 1, -1, 10, 
    15, -6, -1, -11, -30, 4, 15, -1, 9, -7, 0, -2, -7, 10, 25, -16 },
  { 7, -15, -7, -7, -1, -5, -5, -11, -20, 10, 3, -10, -3, 5, 20, -4, 
    0, -2, -2, 17, 2, 0, -3, 3, 6, 5, -1, -12, -3, 15, 22, -16 },
  { 4, -1, 3, 4, -5, 0, -1, -5, -24, -29, 4, -9, 1, -3, 0, 0, 
    0, -4, 7, -4, -4, -4, 3, 1, -6, 5, -3, -5, -10, 3, 25, -10 },
  { -2, -1, -1, 4, 4, -1, 2, 0, -4, -4, 2, -1, -3, -1, -2, -2, 
    1, -3, -5, -1, 2, -3, -4, -4, -3, 5, -9, 1, -11, 7, 46, -46 },
  { 0, -9, 3, 4, 4, 3, -5, -6, 5, -4, 4, -2, 1, 7, -4, -10, 
    13, 1, 3, -6, 4, -4, 7, 2, -19, -25, -3, -16, -12, 16, 20, -1 },
  { 18, 6, 4, -12, 0, -14, 9, -6, -1, -4, -5, 2, 1, 12, 4, 2, 
    7, 0, 2, 5, -11, -5, -2, 2, -4, 10, 0, -9, -7, 9, 25, -8 },
  { 5, 0, -6, 5, 6, 3, 3, -10, -5, 1, -1, 4, 3, -11, -8, 5, 
    4, -5, 5, -5, -7, -5, 11, 5, 20, -8, -16, 21, -4, 27, 23, -5 }
};

--- NEW FILE: tables_adpcm.h ---
/*
 * tables_adpcm.h
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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
[...4083 lines suppressed...]
  { 13441, -11509, 6676, -2434 },
  { 7912, -9398, 6663, -4048 },
  { 11723, -13745, 8131, -4148 },
  { 6065, -10257, 5005, -6327 },
  { 11618, -12417, 5336, -1894 },
  { 8891, -13924, 8407, -6131 },
  { 9622, -12563, 7908, -5109 },
  { 11479, -10315, 8349, -3991 },
  { 11676, -14103, 6611, -2330 },
  { 11951, -8953, 3829, -1550 },
  { 10486, -8044, 10493, -5920 },
  { 11801, -10769, 9763, -5305 },
  { 6109, -8676, 5827, -1346 },
  { 7030, -9611, 5624, -5761 },
  { 12808, -12886, 8683, -4148 },
  { 13213, -10464, 6381, -3189 },
  { 11796, -13681, 10703, -6075 },
  { 9639, -7949, 9625, -3944 },
  { 8538, -6997, 5309, 453 }
};

--- NEW FILE: parse.c ---
/*
 * parse.c
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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
[...1251 lines suppressed...]
        }
    }
}

void dts_dynrng (dts_state_t * state,
                 level_t (* call) (level_t, void *), void * data)
{
    state->dynrange = 0;
    if (call) {
        state->dynrange = 1;
        state->dynrngcall = call;
        state->dynrngdata = data;
    }
}

void dts_free (dts_state_t * state)
{
    free (state->samples);
    free (state);
}

--- NEW FILE: tables_quantization.h ---
/*
 * tables_quantization.h
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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-1307  USA
 */

int scale_factor_quant6[] =
{
        1,       2,       2,       3,       3,       4,       6,       7, 
       10,      12,      16,      20,      26,      34,      44,      56, 
       72,      93,     120,     155,     200,     257,     331,     427, 
      550,     708,     912,    1175,    1514,    1950,    2512,    3236, 
     4169,    5370,    6918,    8913,   11482,   14791,   19055,   24547, 
    31623,   40738,   52481,   67608,   87096,  112202,  144544,  186209, 
   239883,  309030,  398107,  512861,  660693,  851138, 1096478, 1412538, 
  1819701, 2344229, 3019952, 3890451, 5011872, 6456542, 8317638,       0
};

int scale_factor_quant7[] =
{
        1,       1,       2,       2,       2,       2,       3,       3, 
        3,       4,       4,       5,       6,       7,       7,       8, 
       10,      11,      12,      14,      16,      18,      20,      23, 
       26,      30,      34,      38,      44,      50,      56,      64, 
       72,      82,      93,     106,     120,     136,     155,     176, 
      200,     226,     257,     292,     331,     376,     427,     484, 
      550,     624,     708,     804,     912,    1035,    1175,    1334, 
     1514,    1718,    1950,    2213,    2512,    2851,    3236,    3673, 
     4169,    4732,    5370,    6095,    6918,    7852,    8913,   10116, 
    11482,   13032,   14791,   16788,   19055,   21627,   24547,   27861, 
    31623,   35892,   40738,   46238,   52481,   59566,   67608,   76736, 
    87096,   98855,  112202,  127350,  144544,  164059,  186209,  211349, 
   239883,  272270,  309030,  350752,  398107,  451856,  512861,  582103, 
   660693,  749894,  851138,  966051, 1096478, 1244515, 1412538, 1603245, 
  1819701, 2065380, 2344229, 2660725, 3019952, 3427678, 3890451, 4415704, 
  5011872, 5688529, 6456542, 7328245, 8317638,       0,       0,       0
};

/* 20bits unsigned fractional binary codes */
int lossy_quant[] =
{
        0, 6710886, 4194304, 3355443, 2474639, 2097152, 1761608, 1426063, 
   796918,  461373,  251658,  146801,   79692,   46137,   27263,   16777, 
    10486,    5872,    3355,    1887,    1258,     713,     336,     168, 
       84,      42,      21,       0,       0,       0,       0,       0
};

double lossy_quant_d[] =
{
          0,     1.6,      1.0,     0.8,    0.59,    0.50,    0.42,    0.34, 
       0.19,    0.11,     0.06,   0.035,   0.019,   0.011,  0.0065,  0.0040, 
     0.0025,  0.0014,   0.0008, 0.00045, 0.00030, 0.00017, 0.00008, 0.00004, 
    0.00002, 0.00001, 0.000005,       0,       0,       0,       0,       0
};

/* 20bits unsigned fractional binary codes */
int lossless_quant[] =
{
        0, 4194304, 2097152, 1384120, 1048576,  696254,  524288,  348127, 
   262144,  131072,   65431,   33026,   16450,    8208,    4100,    2049, 
     1024,     512,     256,     128,      64,      32,      16,       8, 
        4,       2,       1,       0,       0,       0,       0,       0
};

double lossless_quant_d[] =
{
    0,             1.0,      0.5,     0.33,     0.25,    0.166,    0.125,
    0.083,      0.0625,  0.03125,   0.0156, 7.874E-3, 3.922E-3, 1.957E-3,
    9.775E-4, 4.885E-4, 2.442E-4, 1.221E-4, 6.104E-5, 3.052E-5, 1.526E-5,
    7.629E-6, 3.815E-6, 1.907E-6, 9.537E-7, 4.768E-7, 2.384E-7,        0,
           0,        0,        0,        0
};

--- NEW FILE: bitstream.h ---
/*
 * bitstream.h
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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-1307  USA
 */

#ifdef WORDS_BIGENDIAN

#   define swab32(x) (x)

#else

#   define swab32(x)\
((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) |  \
 (((uint8_t*)&x)[2] << 8)  | (((uint8_t*)&x)[3]))

#endif

#ifdef WORDS_BIGENDIAN

#   define swable32(x)\
((((uint8_t*)&x)[0] << 16) | (((uint8_t*)&x)[1] << 24) |  \
 (((uint8_t*)&x)[2])  | (((uint8_t*)&x)[3] << 8))

#else

#   define swable32(x)\
((((uint16_t*)&x)[0] << 16) | (((uint16_t*)&x)[1]))

#endif

void dts_bitstream_init (dts_state_t * state, uint8_t * buf, int word_mode,
                         int endian_mode);
uint32_t dts_bitstream_get_bh (dts_state_t * state, uint32_t num_bits);

static inline uint32_t bitstream_get (dts_state_t * state, uint32_t num_bits)
{
    uint32_t result;

    if (num_bits < state->bits_left) {
        result = (state->current_word << (32 - state->bits_left))
				      >> (32 - num_bits);

        state->bits_left -= num_bits;
        return result;
    }

    return dts_bitstream_get_bh (state, num_bits);
}

--- NEW FILE: tables_fir.h ---
/*
 * fir.h
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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
[...2046 lines suppressed...]
0.00105048984,
0.00096255314,
0.00088037323,
0.00080365466,
0.00073179678,
0.00066567765,
0.00060277141,
0.00054522208,
0.00049204525,
0.00044236859,
0.00039634691,
0.00035398375,
0.00031519096,
0.00027949660,
0.00024667382,
0.00021643363,
0.00018878609,
0.00016358691,
0.00053168571
};

--- NEW FILE: tables.h ---
/*
 * tables.h
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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-1307  USA
 */

static const int dts_sample_rates[] =
{
    0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
    12000, 24000, 48000, 96000, 192000
};

static const int dts_bit_rates[] =
{
    32000, 56000, 64000, 96000, 112000, 128000,
    192000, 224000, 256000, 320000, 384000,
    448000, 512000, 576000, 640000, 768000,
    896000, 1024000, 1152000, 1280000, 1344000,
    1408000, 1411200, 1472000, 1536000, 1920000,
    2048000, 3072000, 3840000, 1/*open*/, 2/*variable*/, 3/*lossless*/
};

static const uint8_t dts_channels[] =
{
    1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8
};

static const uint8_t dts_bits_per_sample[] =
{
    16, 16, 20, 20, 0, 24, 24
};

--- NEW FILE: dts.h ---
/*
 * dts.h
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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-1307  USA
 */

#ifndef DTS_H
#define DTS_H

/* x86 accelerations */
#define MM_ACCEL_X86_MMX	0x80000000
#define MM_ACCEL_X86_3DNOW	0x40000000
#define MM_ACCEL_X86_MMXEXT	0x20000000

uint32_t mm_accel (void);

#if defined(LIBDTS_FIXED)
typedef int32_t sample_t;
typedef int32_t level_t;
#elif defined(LIBDTS_DOUBLE)
typedef double sample_t;
typedef double level_t;
#else
typedef float sample_t;
typedef float level_t;
#endif

typedef struct dts_state_s dts_state_t;

#define DTS_MONO 0
#define DTS_CHANNEL 1
#define DTS_STEREO 2
#define DTS_STEREO_SUMDIFF 3
#define DTS_STEREO_TOTAL 4
#define DTS_3F 5
#define DTS_2F1R 6
#define DTS_3F1R 7
#define DTS_2F2R 8
#define DTS_3F2R 9
#define DTS_4F2R 10

#define DTS_DOLBY 101 /* FIXME */

#define DTS_CHANNEL_MAX  DTS_3F2R /* We don't handle anything above that */
#define DTS_CHANNEL_BITS 6
#define DTS_CHANNEL_MASK 0x3F

#define DTS_LFE 0x80
#define DTS_ADJUST_LEVEL 0x100

dts_state_t * dts_init (uint32_t mm_accel);

int dts_syncinfo (dts_state_t *state, uint8_t * buf, int * flags,
                  int * sample_rate, int * bit_rate, int *frame_length);

int dts_frame (dts_state_t * state, uint8_t * buf, int * flags,
               level_t * level, sample_t bias);

void dts_dynrng (dts_state_t * state,
                 level_t (* call) (level_t, void *), void * data);

int dts_blocks_num (dts_state_t * state);
int dts_block (dts_state_t * state);

sample_t * dts_samples (dts_state_t * state);

void dts_free (dts_state_t * state);

#endif /* DTS_H */

--- NEW FILE: bitstream.c ---
/*
 * bitstream.c
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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-1307  USA
 */

#include "config.h"

#include <inttypes.h>

#include "dts.h"
#include "dts_internal.h"
#include "bitstream.h"

#define BUFFER_SIZE 4096

void dts_bitstream_init (dts_state_t * state, uint8_t * buf, int word_mode,
                         int bigendian_mode)
{
    intptr_t align;

    align = (uintptr_t)buf & 3;
    state->buffer_start = (uint32_t *) (buf - align);
    state->bits_left = 0;
    state->current_word = 0;
    state->word_mode = word_mode;
    state->bigendian_mode = bigendian_mode;
    bitstream_get (state, align * 8);
}
#include<stdio.h>
static inline void bitstream_fill_current (dts_state_t * state)
{
    uint32_t tmp;

    tmp = *(state->buffer_start++);

    if (state->bigendian_mode)
        state->current_word = swab32 (tmp);
    else
        state->current_word = swable32 (tmp);

    if (!state->word_mode)
    {
        state->current_word = (state->current_word & 0x00003FFF) |
            ((state->current_word & 0x3FFF0000 ) >> 2);
    }
}

/*
 * The fast paths for _get is in the
 * bitstream.h header file so it can be inlined.
 *
 * The "bottom half" of this routine is suffixed _bh
 *
 * -ah
 */

uint32_t dts_bitstream_get_bh (dts_state_t * state, uint32_t num_bits)
{
    uint32_t result;

    num_bits -= state->bits_left;

    result = ((state->current_word << (32 - state->bits_left)) >>
	      (32 - state->bits_left));

    if ( !state->word_mode && num_bits > 28 ) {
        bitstream_fill_current (state);
	result = (result << 28) | state->current_word;
	num_bits -= 28;
    }

    bitstream_fill_current (state);

    if ( state->word_mode )
    {
        if (num_bits != 0)
	    result = (result << num_bits) |
	             (state->current_word >> (32 - num_bits));

	state->bits_left = 32 - num_bits;
    }
    else
    {
        if (num_bits != 0)
	    result = (result << num_bits) |
	             (state->current_word >> (28 - num_bits));

	state->bits_left = 28 - num_bits;
    }

    return result;
}

--- NEW FILE: downmix.c ---
/*
 * downmix.c
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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-1307  USA
 */

#include "config.h"

#include <string.h>
#include <inttypes.h>

#include "dts.h"
#include "dts_internal.h"

#define CONVERT(acmod,output) (((output) << DTS_CHANNEL_BITS) + (acmod))

int dts_downmix_init (int input, int flags, level_t * level,
		      level_t clev, level_t slev)
{
    static uint8_t table[11][10] = {
        /* DTS_MONO */
        {DTS_MONO,      DTS_MONO,       DTS_MONO,       DTS_MONO,
         DTS_MONO,      DTS_MONO,       DTS_MONO,       DTS_MONO,
         DTS_MONO,      DTS_MONO},
        /* DTS_CHANNEL */
        {DTS_MONO,      DTS_CHANNEL,    DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_STEREO,     DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_STEREO},
        /* DTS_STEREO */
        {DTS_MONO,      DTS_CHANNEL,    DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_STEREO,     DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_STEREO},
        /* DTS_STEREO_SUMDIFF */
        {DTS_MONO,      DTS_CHANNEL,    DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_STEREO,     DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_STEREO},
        /* DTS_STEREO_TOTAL */
        {DTS_MONO,      DTS_CHANNEL,    DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_STEREO,     DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_STEREO},
        /* DTS_3F */
        {DTS_MONO,      DTS_CHANNEL,    DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_3F,         DTS_3F,         DTS_3F,
         DTS_3F,        DTS_3F},
        /* DTS_2F1R */
        {DTS_MONO,      DTS_CHANNEL,    DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_2F1R,       DTS_2F1R,       DTS_2F1R,
         DTS_2F1R,      DTS_2F1R},
        /* DTS_3F1R */
        {DTS_MONO,      DTS_CHANNEL,    DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_3F,         DTS_3F1R,       DTS_3F1R,
         DTS_3F1R,      DTS_3F1R},
        /* DTS_2F2R */
        {DTS_MONO,      DTS_CHANNEL,    DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_STEREO,     DTS_2F2R,       DTS_2F2R,
         DTS_2F2R,      DTS_2F2R},
        /* DTS_3F2R */
        {DTS_MONO,      DTS_CHANNEL,    DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_3F,         DTS_3F2R,       DTS_3F2R,
         DTS_3F2R,      DTS_3F2R},
        /* DTS_4F2R */
        {DTS_MONO,      DTS_CHANNEL,    DTS_STEREO,     DTS_STEREO,
         DTS_STEREO,    DTS_4F2R,       DTS_4F2R,       DTS_4F2R,
         DTS_4F2R,      DTS_4F2R},
    };
    int output;

    output = flags & DTS_CHANNEL_MASK;

    if (output > DTS_CHANNEL_MAX)
	return -1;

    output = table[output][input];

    if (output == DTS_STEREO &&
	(input == DTS_DOLBY || (input == DTS_3F && clev == LEVEL (LEVEL_3DB))))
	output = DTS_DOLBY;

    if (flags & DTS_ADJUST_LEVEL) {
	level_t adjust;

	switch (CONVERT (input & 7, output)) {

	case CONVERT (DTS_3F, DTS_MONO):
	    adjust = DIV (LEVEL_3DB, LEVEL (1) + clev);
	    break;

	case CONVERT (DTS_STEREO, DTS_MONO):
	case CONVERT (DTS_2F2R, DTS_2F1R):
	case CONVERT (DTS_3F2R, DTS_3F1R):
	level_3db:
	    adjust = LEVEL (LEVEL_3DB);
	    break;

	case CONVERT (DTS_3F2R, DTS_2F1R):
	    if (clev < LEVEL (LEVEL_PLUS3DB - 1))
		goto level_3db;
	    /* break thru */
	case CONVERT (DTS_3F, DTS_STEREO):
	case CONVERT (DTS_3F1R, DTS_2F1R):
	case CONVERT (DTS_3F1R, DTS_2F2R):
	case CONVERT (DTS_3F2R, DTS_2F2R):
	    adjust = DIV (1, LEVEL (1) + clev);
	    break;

	case CONVERT (DTS_2F1R, DTS_MONO):
	    adjust = DIV (LEVEL_PLUS3DB, LEVEL (2) + slev);
	    break;

	case CONVERT (DTS_2F1R, DTS_STEREO):
	case CONVERT (DTS_3F1R, DTS_3F):
	    adjust = DIV (1, LEVEL (1) + MUL_C (slev, LEVEL_3DB));
	    break;

	case CONVERT (DTS_3F1R, DTS_MONO):
	    adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + MUL_C (slev, 0.5));
	    break;

	case CONVERT (DTS_3F1R, DTS_STEREO):
	    adjust = DIV (1, LEVEL (1) + clev + MUL_C (slev, LEVEL_3DB));
	    break;

	case CONVERT (DTS_2F2R, DTS_MONO):
	    adjust = DIV (LEVEL_3DB, LEVEL (1) + slev);
	    break;

	case CONVERT (DTS_2F2R, DTS_STEREO):
	case CONVERT (DTS_3F2R, DTS_3F):
	    adjust = DIV (1, LEVEL (1) + slev);
	    break;

	case CONVERT (DTS_3F2R, DTS_MONO):
	    adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + slev);
	    break;

	case CONVERT (DTS_3F2R, DTS_STEREO):
	    adjust = DIV (1, LEVEL (1) + clev + slev);
	    break;

	case CONVERT (DTS_MONO, DTS_DOLBY):
	    adjust = LEVEL (LEVEL_PLUS3DB);
	    break;

	case CONVERT (DTS_3F, DTS_DOLBY):
	case CONVERT (DTS_2F1R, DTS_DOLBY):
	    adjust = LEVEL (1 / (1 + LEVEL_3DB));
	    break;

	case CONVERT (DTS_3F1R, DTS_DOLBY):
	case CONVERT (DTS_2F2R, DTS_DOLBY):
	    adjust = LEVEL (1 / (1 + 2 * LEVEL_3DB));
	    break;

	case CONVERT (DTS_3F2R, DTS_DOLBY):
	    adjust = LEVEL (1 / (1 + 3 * LEVEL_3DB));
	    break;

	default:
	    return output;
	}

	*level = MUL_L (*level, adjust);
    }

    return output;
}

int dts_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
		       level_t clev, level_t slev)
{
    level_t level_3db;

    level_3db = MUL_C (level, LEVEL_3DB);

    switch (CONVERT (acmod, output & DTS_CHANNEL_MASK)) {

    case CONVERT (DTS_CHANNEL, DTS_CHANNEL):
    case CONVERT (DTS_MONO, DTS_MONO):
    case CONVERT (DTS_STEREO, DTS_STEREO):
    case CONVERT (DTS_3F, DTS_3F):
    case CONVERT (DTS_2F1R, DTS_2F1R):
    case CONVERT (DTS_3F1R, DTS_3F1R):
    case CONVERT (DTS_2F2R, DTS_2F2R):
    case CONVERT (DTS_3F2R, DTS_3F2R):
    case CONVERT (DTS_STEREO, DTS_DOLBY):
	coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level;
	return 0;

    case CONVERT (DTS_CHANNEL, DTS_MONO):
	coeff[0] = coeff[1] = MUL_C (level, LEVEL_6DB);
	return 3;

    case CONVERT (DTS_STEREO, DTS_MONO):
	coeff[0] = coeff[1] = level_3db;
	return 3;

    case CONVERT (DTS_3F, DTS_MONO):
	coeff[0] = coeff[2] = level_3db;
	coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
	return 7;

    case CONVERT (DTS_2F1R, DTS_MONO):
	coeff[0] = coeff[1] = level_3db;
	coeff[2] = MUL_L (level_3db, slev);
	return 7;

    case CONVERT (DTS_2F2R, DTS_MONO):
	coeff[0] = coeff[1] = level_3db;
	coeff[2] = coeff[3] = MUL_L (level_3db, slev);
	return 15;

    case CONVERT (DTS_3F1R, DTS_MONO):
	coeff[0] = coeff[2] = level_3db;
	coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
	coeff[3] = MUL_L (level_3db, slev);
	return 15;

    case CONVERT (DTS_3F2R, DTS_MONO):
	coeff[0] = coeff[2] = level_3db;
	coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
	coeff[3] = coeff[4] = MUL_L (level_3db, slev);
	return 31;

    case CONVERT (DTS_MONO, DTS_DOLBY):
	coeff[0] = level_3db;
	return 0;

    case CONVERT (DTS_3F, DTS_DOLBY):
	coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
	coeff[1] = level_3db;
	return 7;

    case CONVERT (DTS_3F, DTS_STEREO):
    case CONVERT (DTS_3F1R, DTS_2F1R):
    case CONVERT (DTS_3F2R, DTS_2F2R):
	coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
	coeff[1] = MUL_L (level, clev);
	return 7;

    case CONVERT (DTS_2F1R, DTS_DOLBY):
	coeff[0] = coeff[1] = level;
	coeff[2] = level_3db;
	return 7;

    case CONVERT (DTS_2F1R, DTS_STEREO):
	coeff[0] = coeff[1] = level;
	coeff[2] = MUL_L (level_3db, slev);
	return 7;

    case CONVERT (DTS_3F1R, DTS_DOLBY):
	coeff[0] = coeff[2] = level;
	coeff[1] = coeff[3] = level_3db;
	return 15;

    case CONVERT (DTS_3F1R, DTS_STEREO):
	coeff[0] = coeff[2] = level;
	coeff[1] = MUL_L (level, clev);
	coeff[3] = MUL_L (level_3db, slev);
	return 15;

    case CONVERT (DTS_2F2R, DTS_DOLBY):
	coeff[0] = coeff[1] = level;
	coeff[2] = coeff[3] = level_3db;
	return 15;

    case CONVERT (DTS_2F2R, DTS_STEREO):
	coeff[0] = coeff[1] = level;
	coeff[2] = coeff[3] = MUL_L (level, slev);
	return 15;

    case CONVERT (DTS_3F2R, DTS_DOLBY):
	coeff[0] = coeff[2] = level;
	coeff[1] = coeff[3] = coeff[4] = level_3db;
	return 31;

    case CONVERT (DTS_3F2R, DTS_2F1R):
	coeff[0] = coeff[2] = level;
	coeff[1] = MUL_L (level, clev);
	coeff[3] = coeff[4] = level_3db;
	return 31;

    case CONVERT (DTS_3F2R, DTS_STEREO):
	coeff[0] = coeff[2] = level;
	coeff[1] = MUL_L (level, clev);
	coeff[3] = coeff[4] = MUL_L (level, slev);
	return 31;

    case CONVERT (DTS_3F1R, DTS_3F):
	coeff[0] = coeff[1] = coeff[2] = level;
	coeff[3] = MUL_L (level_3db, slev);
	return 13;

    case CONVERT (DTS_3F2R, DTS_3F):
	coeff[0] = coeff[1] = coeff[2] = level;
	coeff[3] = coeff[4] = MUL_L (level, slev);
	return 29;

    case CONVERT (DTS_2F2R, DTS_2F1R):
	coeff[0] = coeff[1] = level;
	coeff[2] = coeff[3] = level_3db;
	return 12;

    case CONVERT (DTS_3F2R, DTS_3F1R):
	coeff[0] = coeff[1] = coeff[2] = level;
	coeff[3] = coeff[4] = level_3db;
	return 24;

    case CONVERT (DTS_2F1R, DTS_2F2R):
	coeff[0] = coeff[1] = level;
	coeff[2] = level_3db;
	return 0;

    case CONVERT (DTS_3F1R, DTS_2F2R):
	coeff[0] = coeff[2] = level;
	coeff[1] = MUL_L (level, clev);
	coeff[3] = level_3db;
	return 7;

    case CONVERT (DTS_3F1R, DTS_3F2R):
	coeff[0] = coeff[1] = coeff[2] = level;
	coeff[3] = level_3db;
	return 0;
    }

    return -1;	/* NOTREACHED */
}

static void mix2to1 (sample_t * dest, sample_t * src, sample_t bias)
{
    int i;

    for (i = 0; i < 256; i++)
	dest[i] += BIAS (src[i]);
}

static void mix3to1 (sample_t * samples, sample_t bias)
{
    int i;

    for (i = 0; i < 256; i++)
	samples[i] += BIAS (samples[i + 256] + samples[i + 512]);
}

static void mix4to1 (sample_t * samples, sample_t bias)
{
    int i;

    for (i = 0; i < 256; i++)
	samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
			    samples[i + 768]);
}

static void mix5to1 (sample_t * samples, sample_t bias)
{
    int i;

    for (i = 0; i < 256; i++)
	samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
			    samples[i + 768] + samples[i + 1024]);
}

static void mix3to2 (sample_t * samples, sample_t bias)
{
    int i;
    sample_t common;

    for (i = 0; i < 256; i++) {
	common = BIAS (samples[i]);
	samples[i] = samples[i + 256] + common;
	samples[i + 256] = samples[i + 512] + common;
    }
}

static void mix21to2 (sample_t * left, sample_t * right, sample_t bias)
{
    int i;
    sample_t common;

    for (i = 0; i < 256; i++) {
	common = BIAS (right[i + 256]);
	left[i] += common;
	right[i] += common;
    }
}

static void mix21toS (sample_t * samples, sample_t bias)
{
    int i;
    sample_t surround;

    for (i = 0; i < 256; i++) {
	surround = samples[i + 512];
	samples[i] += BIAS (-surround);
	samples[i + 256] += BIAS (surround);
    }
}

static void mix31to2 (sample_t * samples, sample_t bias)
{
    int i;
    sample_t common;

    for (i = 0; i < 256; i++) {
	common = BIAS (samples[i] + samples[i + 768]);
	samples[i] = samples[i + 256] + common;
	samples[i + 256] = samples[i + 512] + common;
    }
}

static void mix31toS (sample_t * samples, sample_t bias)
{
    int i;
    sample_t common, surround;

    for (i = 0; i < 256; i++) {
	common = BIAS (samples[i]);
	surround = samples[i + 768];
	samples[i] = samples[i + 256] + common - surround;
	samples[i + 256] = samples[i + 512] + common + surround;
    }
}

static void mix22toS (sample_t * samples, sample_t bias)
{
    int i;
    sample_t surround;

    for (i = 0; i < 256; i++) {
	surround = samples[i + 512] + samples[i + 768];
	samples[i] += BIAS (-surround);
	samples[i + 256] += BIAS (surround);
    }
}

static void mix32to2 (sample_t * samples, sample_t bias)
{
    int i;
    sample_t common;

    for (i = 0; i < 256; i++) {
	common = BIAS (samples[i]);
	samples[i] = common + samples[i + 256] + samples[i + 768];
	samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
    }
}

static void mix32toS (sample_t * samples, sample_t bias)
{
    int i;
    sample_t common, surround;

    for (i = 0; i < 256; i++) {
	common = BIAS (samples[i]);
	surround = samples[i + 768] + samples[i + 1024];
	samples[i] = samples[i + 256] + common - surround;
	samples[i + 256] = samples[i + 512] + common + surround;
    }
}

static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
{
    int i;

    for (i = 0; i < 256; i++)
	dest[i] = BIAS (src[i] + src[i + 256]);
}

static void zero (sample_t * samples)
{
    int i;

    for (i = 0; i < 256; i++)
	samples[i] = 0;
}

void dts_downmix (sample_t * samples, int acmod, int output, sample_t bias,
		  level_t clev, level_t slev)
{
    switch (CONVERT (acmod, output & DTS_CHANNEL_MASK)) {

    case CONVERT (DTS_CHANNEL, DTS_MONO):
    case CONVERT (DTS_STEREO, DTS_MONO):
    mix_2to1:
	mix2to1 (samples, samples + 256, bias);
	break;

    case CONVERT (DTS_2F1R, DTS_MONO):
	if (slev == 0)
	    goto mix_2to1;
    case CONVERT (DTS_3F, DTS_MONO):
    mix_3to1:
	mix3to1 (samples, bias);
	break;

    case CONVERT (DTS_3F1R, DTS_MONO):
	if (slev == 0)
	    goto mix_3to1;
    case CONVERT (DTS_2F2R, DTS_MONO):
	if (slev == 0)
	    goto mix_2to1;
	mix4to1 (samples, bias);
	break;

    case CONVERT (DTS_3F2R, DTS_MONO):
	if (slev == 0)
	    goto mix_3to1;
	mix5to1 (samples, bias);
	break;

    case CONVERT (DTS_MONO, DTS_DOLBY):
	memcpy (samples + 256, samples, 256 * sizeof (sample_t));
	break;

    case CONVERT (DTS_3F, DTS_STEREO):
    case CONVERT (DTS_3F, DTS_DOLBY):
    mix_3to2:
	mix3to2 (samples, bias);
	break;

    case CONVERT (DTS_2F1R, DTS_STEREO):
	if (slev == 0)
	    break;
	mix21to2 (samples, samples + 256, bias);
	break;

    case CONVERT (DTS_2F1R, DTS_DOLBY):
	mix21toS (samples, bias);
	break;

    case CONVERT (DTS_3F1R, DTS_STEREO):
	if (slev == 0)
	    goto mix_3to2;
	mix31to2 (samples, bias);
	break;

    case CONVERT (DTS_3F1R, DTS_DOLBY):
	mix31toS (samples, bias);
	break;

    case CONVERT (DTS_2F2R, DTS_STEREO):
	if (slev == 0)
	    break;
	mix2to1 (samples, samples + 512, bias);
	mix2to1 (samples + 256, samples + 768, bias);
	break;

    case CONVERT (DTS_2F2R, DTS_DOLBY):
	mix22toS (samples, bias);
	break;

    case CONVERT (DTS_3F2R, DTS_STEREO):
	if (slev == 0)
	    goto mix_3to2;
	mix32to2 (samples, bias);
	break;

    case CONVERT (DTS_3F2R, DTS_DOLBY):
	mix32toS (samples, bias);
	break;

    case CONVERT (DTS_3F1R, DTS_3F):
	if (slev == 0)
	    break;
	mix21to2 (samples, samples + 512, bias);
	break;

    case CONVERT (DTS_3F2R, DTS_3F):
	if (slev == 0)
	    break;
	mix2to1 (samples, samples + 768, bias);
	mix2to1 (samples + 512, samples + 1024, bias);
	break;

    case CONVERT (DTS_3F1R, DTS_2F1R):
	mix3to2 (samples, bias);
	memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
	break;

    case CONVERT (DTS_2F2R, DTS_2F1R):
	mix2to1 (samples + 512, samples + 768, bias);
	break;

    case CONVERT (DTS_3F2R, DTS_2F1R):
	mix3to2 (samples, bias);
	move2to1 (samples + 768, samples + 512, bias);
	break;

    case CONVERT (DTS_3F2R, DTS_3F1R):
	mix2to1 (samples + 768, samples + 1024, bias);
	break;

    case CONVERT (DTS_2F1R, DTS_2F2R):
	memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
	break;

    case CONVERT (DTS_3F1R, DTS_2F2R):
	mix3to2 (samples, bias);
	memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
	break;

    case CONVERT (DTS_3F2R, DTS_2F2R):
	mix3to2 (samples, bias);
	memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
	memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
	break;

    case CONVERT (DTS_3F1R, DTS_3F2R):
	memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
	break;
    }
}

void dts_upmix (sample_t * samples, int acmod, int output)
{
    switch (CONVERT (acmod, output & DTS_CHANNEL_MASK)) {

    case CONVERT (DTS_3F2R, DTS_MONO):
	zero (samples + 1024);
    case CONVERT (DTS_3F1R, DTS_MONO):
    case CONVERT (DTS_2F2R, DTS_MONO):
	zero (samples + 768);
    case CONVERT (DTS_3F, DTS_MONO):
    case CONVERT (DTS_2F1R, DTS_MONO):
	zero (samples + 512);
    case CONVERT (DTS_CHANNEL, DTS_MONO):
    case CONVERT (DTS_STEREO, DTS_MONO):
	zero (samples + 256);
	break;

    case CONVERT (DTS_3F2R, DTS_STEREO):
    case CONVERT (DTS_3F2R, DTS_DOLBY):
	zero (samples + 1024);
    case CONVERT (DTS_3F1R, DTS_STEREO):
    case CONVERT (DTS_3F1R, DTS_DOLBY):
	zero (samples + 768);
    case CONVERT (DTS_3F, DTS_STEREO):
    case CONVERT (DTS_3F, DTS_DOLBY):
    mix_3to2:
	memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
	zero (samples + 256);
	break;

    case CONVERT (DTS_2F2R, DTS_STEREO):
    case CONVERT (DTS_2F2R, DTS_DOLBY):
	zero (samples + 768);
    case CONVERT (DTS_2F1R, DTS_STEREO):
    case CONVERT (DTS_2F1R, DTS_DOLBY):
	zero (samples + 512);
	break;

    case CONVERT (DTS_3F2R, DTS_3F):
	zero (samples + 1024);
    case CONVERT (DTS_3F1R, DTS_3F):
    case CONVERT (DTS_2F2R, DTS_2F1R):
	zero (samples + 768);
	break;

    case CONVERT (DTS_3F2R, DTS_3F1R):
	zero (samples + 1024);
	break;

    case CONVERT (DTS_3F2R, DTS_2F1R):
	zero (samples + 1024);
    case CONVERT (DTS_3F1R, DTS_2F1R):
    mix_31to21:
	memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
	goto mix_3to2;

    case CONVERT (DTS_3F2R, DTS_2F2R):
	memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
	goto mix_31to21;
    }
}

--- NEW FILE: Makefile.am ---
include $(top_srcdir)/misc/Makefile.common

libdir = $(XINE_PLUGINDIR)

lib_LTLIBRARIES = xineplug_decode_dts.la

xineplug_decode_dts_la_SOURCES = bitstream.c downmix.c parse.c xine_decoder.c
xineplug_decode_dts_la_LIBADD = $(XINE_LIB)
xineplug_decode_dts_la_LDFLAGS = -avoid-version -module $(XINE_PLUGIN_MIN_SYMS)

noinst_HEADERS = bitstream.h dts.h dts_internal.h tables.h tables_adpcm.h \
	tables_fir.h tables_huffman.h tables_quantization.h tables_vq.h

--- NEW FILE: Makefile.in ---
# Makefile.in generated by automake 1.9.3 from Makefile.am.
# @configure_input@

# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004  Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@


SOURCES = $(xineplug_decode_dts_la_SOURCES)

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
	$(srcdir)/Makefile.in $(top_srcdir)/misc/Makefile.common
subdir = src/libdts
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/_xine.m4 $(top_srcdir)/m4/aa.m4 \
	$(top_srcdir)/m4/alsa.m4 $(top_srcdir)/m4/arts.m4 \
	$(top_srcdir)/m4/as.m4 $(top_srcdir)/m4/caca.m4 \
	$(top_srcdir)/m4/codeset.m4 $(top_srcdir)/m4/directx.m4 \
	$(top_srcdir)/m4/dl.m4 $(top_srcdir)/m4/dvdnav.m4 \
	$(top_srcdir)/m4/esd.m4 $(top_srcdir)/m4/ffmpeg.m4 \
	$(top_srcdir)/m4/freetype2.m4 $(top_srcdir)/m4/gettext.m4 \
	$(top_srcdir)/m4/glibc21.m4 $(top_srcdir)/m4/iconv.m4 \
	$(top_srcdir)/m4/irixal.m4 $(top_srcdir)/m4/lcmessage.m4 \
	$(top_srcdir)/m4/libFLAC.m4 $(top_srcdir)/m4/libfame.m4 \
	$(top_srcdir)/m4/ogg.m4 $(top_srcdir)/m4/opengl.m4 \
	$(top_srcdir)/m4/pkg.m4 $(top_srcdir)/m4/progtest.m4 \
	$(top_srcdir)/m4/sdl.m4 $(top_srcdir)/m4/speex.m4 \
	$(top_srcdir)/m4/theora.m4 $(top_srcdir)/m4/vorbis.m4 \
	$(top_srcdir)/m4/xv.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
    *) f=$$p;; \
  esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libdir)"
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 = $(top_builddir)/src/xine-engine/libxine.la
xineplug_decode_dts_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am_xineplug_decode_dts_la_OBJECTS = bitstream.lo downmix.lo parse.lo \
	xine_decoder.lo
xineplug_decode_dts_la_OBJECTS = $(am_xineplug_decode_dts_la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
	$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
	$(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
	$(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(xineplug_decode_dts_la_SOURCES)
DIST_SOURCES = $(xineplug_decode_dts_la_SOURCES)
HEADERS = $(noinst_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
AAINFO = @AAINFO@
AALIB_CFLAGS = @AALIB_CFLAGS@
AALIB_CONFIG = @AALIB_CONFIG@
AALIB_LIBS = @AALIB_LIBS@
ACLOCAL = @ACLOCAL@
ACLOCAL_DIR = @ACLOCAL_DIR@
ALLOCA = @ALLOCA@
ALSA_CFLAGS = @ALSA_CFLAGS@
ALSA_LIBS = @ALSA_LIBS@
ALSA_STATIC_LIB = @ALSA_STATIC_LIB@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
ARTS_CFLAGS = @ARTS_CFLAGS@
ARTS_CONFIG = @ARTS_CONFIG@
ARTS_LIBS = @ARTS_LIBS@
AS = @AS@
ASFLAGS = @ASFLAGS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BUILD_ASF_FALSE = @BUILD_ASF_FALSE@
BUILD_ASF_TRUE = @BUILD_ASF_TRUE@
BUILD_DHA_KMOD_FALSE = @BUILD_DHA_KMOD_FALSE@
BUILD_DHA_KMOD_TRUE = @BUILD_DHA_KMOD_TRUE@
BUILD_FAAD_FALSE = @BUILD_FAAD_FALSE@
BUILD_FAAD_TRUE = @BUILD_FAAD_TRUE@
BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@
CACA_CFLAGS = @CACA_CFLAGS@
CACA_CONFIG = @CACA_CONFIG@
CACA_LIBS = @CACA_LIBS@
CATALOGS = @CATALOGS@
CATOBJEXT = @CATOBJEXT@
CC = @CC@
CCAS = @CCAS@
CCASCOMPILE = @CCASCOMPILE@
CCASFLAGS = @CCASFLAGS@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DATADIRNAME = @DATADIRNAME@
DEBUG_CFLAGS = @DEBUG_CFLAGS@
DEFS = @DEFS@
DEPCOMP = @DEPCOMP@
DEPDIR = @DEPDIR@
DEPMOD = @DEPMOD@
DIRECTFB_CFLAGS = @DIRECTFB_CFLAGS@
DIRECTFB_LIBS = @DIRECTFB_LIBS@
DIRECTX_AUDIO_LIBS = @DIRECTX_AUDIO_LIBS@
DIRECTX_CPPFLAGS = @DIRECTX_CPPFLAGS@
DIRECTX_VIDEO_LIBS = @DIRECTX_VIDEO_LIBS@
DLLTOOL = @DLLTOOL@
DVDNAV_CFLAGS = @DVDNAV_CFLAGS@
DVDNAV_CONFIG = @DVDNAV_CONFIG@
DVDNAV_LIBS = @DVDNAV_LIBS@
DYNAMIC_LD_LIBS = @DYNAMIC_LD_LIBS@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
ENABLE_VCD_FALSE = @ENABLE_VCD_FALSE@
ENABLE_VCD_TRUE = @ENABLE_VCD_TRUE@
ESD_CFLAGS = @ESD_CFLAGS@
ESD_CONFIG = @ESD_CONFIG@
ESD_LIBS = @ESD_LIBS@
EXEEXT = @EXEEXT@
EXTRA_X_CFLAGS = @EXTRA_X_CFLAGS@
EXTRA_X_LIBS = @EXTRA_X_LIBS@
F77 = @F77@
FFLAGS = @FFLAGS@
FFMPEG_CPPFLAGS = @FFMPEG_CPPFLAGS@
FFMPEG_LIBS = @FFMPEG_LIBS@
FIG2DEV = @FIG2DEV@
FREETYPE_CONFIG = @FREETYPE_CONFIG@
FT2_CFLAGS = @FT2_CFLAGS@
FT2_LIBS = @FT2_LIBS@
GENCAT = @GENCAT@
GLIBC21 = @GLIBC21@
GLUT_LIBS = @GLUT_LIBS@
GLU_LIBS = @GLU_LIBS@
GMOFILES = @GMOFILES@
GMSGFMT = @GMSGFMT@
GNOME_VFS_CFLAGS = @GNOME_VFS_CFLAGS@
GNOME_VFS_LIBS = @GNOME_VFS_LIBS@
GOOM_LIBS = @GOOM_LIBS@
HAVE_AA_FALSE = @HAVE_AA_FALSE@
HAVE_AA_TRUE = @HAVE_AA_TRUE@
HAVE_ALSA09_FALSE = @HAVE_ALSA09_FALSE@
HAVE_ALSA09_TRUE = @HAVE_ALSA09_TRUE@
HAVE_ALSA_FALSE = @HAVE_ALSA_FALSE@
HAVE_ALSA_TRUE = @HAVE_ALSA_TRUE@
HAVE_ARMV4L_FALSE = @HAVE_ARMV4L_FALSE@
HAVE_ARMV4L_TRUE = @HAVE_ARMV4L_TRUE@
HAVE_ARTS_FALSE = @HAVE_ARTS_FALSE@
HAVE_ARTS_TRUE = @HAVE_ARTS_TRUE@
HAVE_BSDI_CDROM = @HAVE_BSDI_CDROM@
HAVE_CACA_FALSE = @HAVE_CACA_FALSE@
HAVE_CACA_TRUE = @HAVE_CACA_TRUE@
HAVE_CDROM_IOCTLS_FALSE = @HAVE_CDROM_IOCTLS_FALSE@
HAVE_CDROM_IOCTLS_TRUE = @HAVE_CDROM_IOCTLS_TRUE@
HAVE_COREAUDIO_FALSE = @HAVE_COREAUDIO_FALSE@
HAVE_COREAUDIO_TRUE = @HAVE_COREAUDIO_TRUE@
HAVE_DARWIN_CDROM = @HAVE_DARWIN_CDROM@
HAVE_DIRECTFB_FALSE = @HAVE_DIRECTFB_FALSE@
HAVE_DIRECTFB_TRUE = @HAVE_DIRECTFB_TRUE@
HAVE_DIRECTX_FALSE = @HAVE_DIRECTX_FALSE@
HAVE_DIRECTX_TRUE = @HAVE_DIRECTX_TRUE@
HAVE_DVDNAV_FALSE = @HAVE_DVDNAV_FALSE@
HAVE_DVDNAV_TRUE = @HAVE_DVDNAV_TRUE@
HAVE_DXR3_FALSE = @HAVE_DXR3_FALSE@
HAVE_DXR3_TRUE = @HAVE_DXR3_TRUE@
HAVE_ESD_FALSE = @HAVE_ESD_FALSE@
HAVE_ESD_TRUE = @HAVE_ESD_TRUE@
HAVE_FB_FALSE = @HAVE_FB_FALSE@
HAVE_FB_TRUE = @HAVE_FB_TRUE@
HAVE_FFMMX_FALSE = @HAVE_FFMMX_FALSE@
HAVE_FFMMX_TRUE = @HAVE_FFMMX_TRUE@
HAVE_FFMPEG_FALSE = @HAVE_FFMPEG_FALSE@
HAVE_FFMPEG_TRUE = @HAVE_FFMPEG_TRUE@
HAVE_FIG2DEV_FALSE = @HAVE_FIG2DEV_FALSE@
HAVE_FIG2DEV_TRUE = @HAVE_FIG2DEV_TRUE@
HAVE_FLAC_FALSE = @HAVE_FLAC_FALSE@
HAVE_FLAC_TRUE = @HAVE_FLAC_TRUE@
HAVE_FREEBSD_CDROM = @HAVE_FREEBSD_CDROM@
HAVE_GNOME_VFS_FALSE = @HAVE_GNOME_VFS_FALSE@
HAVE_GNOME_VFS_TRUE = @HAVE_GNOME_VFS_TRUE@
HAVE_IRIXAL_FALSE = @HAVE_IRIXAL_FALSE@
HAVE_IRIXAL_TRUE = @HAVE_IRIXAL_TRUE@
HAVE_LIBFAME_FALSE = @HAVE_LIBFAME_FALSE@
HAVE_LIBFAME_TRUE = @HAVE_LIBFAME_TRUE@
HAVE_LIBMNG_FALSE = @HAVE_LIBMNG_FALSE@
HAVE_LIBMNG_TRUE = @HAVE_LIBMNG_TRUE@
HAVE_LIBPNG_FALSE = @HAVE_LIBPNG_FALSE@
HAVE_LIBPNG_TRUE = @HAVE_LIBPNG_TRUE@
HAVE_LIBRTE_FALSE = @HAVE_LIBRTE_FALSE@
HAVE_LIBRTE_TRUE = @HAVE_LIBRTE_TRUE@
HAVE_LIBSMBCLIENT_FALSE = @HAVE_LIBSMBCLIENT_FALSE@
HAVE_LIBSMBCLIENT_TRUE = @HAVE_LIBSMBCLIENT_TRUE@
HAVE_LINUX_CDROM = @HAVE_LINUX_CDROM@
HAVE_LINUX_FALSE = @HAVE_LINUX_FALSE@
HAVE_LINUX_TRUE = @HAVE_LINUX_TRUE@
HAVE_MACOSX_VIDEO_FALSE = @HAVE_MACOSX_VIDEO_FALSE@
HAVE_MACOSX_VIDEO_TRUE = @HAVE_MACOSX_VIDEO_TRUE@
HAVE_MLIB_FALSE = @HAVE_MLIB_FALSE@
HAVE_MLIB_TRUE = @HAVE_MLIB_TRUE@
HAVE_OPENGL_FALSE = @HAVE_OPENGL_FALSE@
HAVE_OPENGL_TRUE = @HAVE_OPENGL_TRUE@
HAVE_OSS_FALSE = @HAVE_OSS_FALSE@
HAVE_OSS_TRUE = @HAVE_OSS_TRUE@
HAVE_POLYPAUDIO_FALSE = @HAVE_POLYPAUDIO_FALSE@
HAVE_POLYPAUDIO_TRUE = @HAVE_POLYPAUDIO_TRUE@
HAVE_SDL_FALSE = @HAVE_SDL_FALSE@
HAVE_SDL_TRUE = @HAVE_SDL_TRUE@
HAVE_SGMLTOOLS_FALSE = @HAVE_SGMLTOOLS_FALSE@
HAVE_SGMLTOOLS_TRUE = @HAVE_SGMLTOOLS_TRUE@
HAVE_SOLARIS_CDROM = @HAVE_SOLARIS_CDROM@
HAVE_SPEEX_FALSE = @HAVE_SPEEX_FALSE@
HAVE_SPEEX_TRUE = @HAVE_SPEEX_TRUE@
HAVE_STK_FALSE = @HAVE_STK_FALSE@
HAVE_STK_TRUE = @HAVE_STK_TRUE@
HAVE_SUNAUDIO_FALSE = @HAVE_SUNAUDIO_FALSE@
HAVE_SUNAUDIO_TRUE = @HAVE_SUNAUDIO_TRUE@
HAVE_SUNDGA_FALSE = @HAVE_SUNDGA_FALSE@
HAVE_SUNDGA_TRUE = @HAVE_SUNDGA_TRUE@
HAVE_SUNFB_FALSE = @HAVE_SUNFB_FALSE@
HAVE_SUNFB_TRUE = @HAVE_SUNFB_TRUE@
HAVE_SYNCFB_FALSE = @HAVE_SYNCFB_FALSE@
HAVE_SYNCFB_TRUE = @HAVE_SYNCFB_TRUE@
HAVE_THEORA_FALSE = @HAVE_THEORA_FALSE@
HAVE_THEORA_TRUE = @HAVE_THEORA_TRUE@
HAVE_V4L_FALSE = @HAVE_V4L_FALSE@
HAVE_V4L_TRUE = @HAVE_V4L_TRUE@
HAVE_VCDNAV_FALSE = @HAVE_VCDNAV_FALSE@
HAVE_VCDNAV_TRUE = @HAVE_VCDNAV_TRUE@
HAVE_VIDIX_FALSE = @HAVE_VIDIX_FALSE@
HAVE_VIDIX_TRUE = @HAVE_VIDIX_TRUE@
HAVE_VLDXVMC_FALSE = @HAVE_VLDXVMC_FALSE@
HAVE_VLDXVMC_TRUE = @HAVE_VLDXVMC_TRUE@
HAVE_VORBIS_FALSE = @HAVE_VORBIS_FALSE@
HAVE_VORBIS_TRUE = @HAVE_VORBIS_TRUE@
HAVE_W32DLL_FALSE = @HAVE_W32DLL_FALSE@
HAVE_W32DLL_TRUE = @HAVE_W32DLL_TRUE@
HAVE_WIN32_CDROM = @HAVE_WIN32_CDROM@
HAVE_X11_FALSE = @HAVE_X11_FALSE@
HAVE_X11_TRUE = @HAVE_X11_TRUE@
HAVE_XVMC_FALSE = @HAVE_XVMC_FALSE@
HAVE_XVMC_TRUE = @HAVE_XVMC_TRUE@
HAVE_XV_FALSE = @HAVE_XV_FALSE@
HAVE_XV_TRUE = @HAVE_XV_TRUE@
HAVE_XXMC_FALSE = @HAVE_XXMC_FALSE@
HAVE_XXMC_TRUE = @HAVE_XXMC_TRUE@
HAVE_ZLIB_FALSE = @HAVE_ZLIB_FALSE@
HAVE_ZLIB_TRUE = @HAVE_ZLIB_TRUE@
HOST_OS_DARWIN_FALSE = @HOST_OS_DARWIN_FALSE@
HOST_OS_DARWIN_TRUE = @HOST_OS_DARWIN_TRUE@
INCLUDED_INTL_FALSE = @INCLUDED_INTL_FALSE@
INCLUDED_INTL_TRUE = @INCLUDED_INTL_TRUE@
INCLUDES = @INCLUDES@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_M4_FALSE = @INSTALL_M4_FALSE@
INSTALL_M4_TRUE = @INSTALL_M4_TRUE@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
INSTOBJEXT = @INSTOBJEXT@
INTLBISON = @INTLBISON@
INTLDIR = @INTLDIR@
INTLLIBS = @INTLLIBS@
INTLOBJS = @INTLOBJS@
INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@
IRIXAL_CFLAGS = @IRIXAL_CFLAGS@
IRIXAL_LIBS = @IRIXAL_LIBS@
IRIXAL_STATIC_LIB = @IRIXAL_STATIC_LIB@
KSTAT_LIBS = @KSTAT_LIBS@
LDFLAGS = @LDFLAGS@
LIBCDIO_CFLAGS = @LIBCDIO_CFLAGS@
LIBCDIO_LIBS = @LIBCDIO_LIBS@
LIBFAME_CFLAGS = @LIBFAME_CFLAGS@
LIBFAME_CONFIG = @LIBFAME_CONFIG@
LIBFAME_LIBS = @LIBFAME_LIBS@
LIBFFMPEG_CFLAGS = @LIBFFMPEG_CFLAGS@
LIBFLAC_CFLAGS = @LIBFLAC_CFLAGS@
LIBFLAC_LIBS = @LIBFLAC_LIBS@
LIBICONV = @LIBICONV@
LIBISO9660_LIBS = @LIBISO9660_LIBS@
LIBMODPLUG_CFLAGS = @LIBMODPLUG_CFLAGS@
LIBMODPLUG_LIBS = @LIBMODPLUG_LIBS@
LIBMPEG2_CFLAGS = @LIBMPEG2_CFLAGS@
LIBNAME = @LIBNAME@
LIBOBJS = @LIBOBJS@
LIBPNG_CONFIG = @LIBPNG_CONFIG@
LIBS = @LIBS@
LIBSMBCLIENT_LIBS = @LIBSMBCLIENT_LIBS@
LIBSTK_CFLAGS = @LIBSTK_CFLAGS@
LIBSTK_LIBS = @LIBSTK_LIBS@
LIBTOOL = $(SHELL) $(top_builddir)/libtool-nofpic
LIBTOOL_DEPS = @LIBTOOL_DEPS@
LIBVCDINFO_LIBS = @LIBVCDINFO_LIBS@
LIBVCD_CFLAGS = @LIBVCD_CFLAGS@
LIBVCD_LIBS = @LIBVCD_LIBS@
LIBVCD_SYSDEP = @LIBVCD_SYSDEP@
LINUX_CDROM_TIMEOUT = @LINUX_CDROM_TIMEOUT@
LINUX_INCLUDE = @LINUX_INCLUDE@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
LT_AGE = @LT_AGE@
LT_CURRENT = @LT_CURRENT@
LT_REVISION = @LT_REVISION@
MAKEINFO = @MAKEINFO@
MKINSTALLDIRS = @MKINSTALLDIRS@
MKNOD = @MKNOD@
MLIB_CFLAGS = @MLIB_CFLAGS@
MLIB_LIBS = @MLIB_LIBS@
MNG_LIBS = @MNG_LIBS@
MSGFMT = @MSGFMT@
NET_LIBS = @NET_LIBS@
OBJC = @OBJC@
OBJCDEPMODE = @OBJCDEPMODE@
OBJCFLAGS = @OBJCFLAGS@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OGG_CFLAGS = @OGG_CFLAGS@
OGG_LIBS = @OGG_LIBS@
OPENGL_CFLAGS = @OPENGL_CFLAGS@
OPENGL_LIBS = @OPENGL_LIBS@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PASS1_CFLAGS = @PASS1_CFLAGS@
PASS2_CFLAGS = @PASS2_CFLAGS@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
PNG_CFLAGS = @PNG_CFLAGS@
PNG_LIBS = @PNG_LIBS@
POFILES = @POFILES@
POLYPAUDIO_CFLAGS = @POLYPAUDIO_CFLAGS@
POLYPAUDIO_LIBS = @POLYPAUDIO_LIBS@
POSUB = @POSUB@
PPC_ARCH_FALSE = @PPC_ARCH_FALSE@
PPC_ARCH_TRUE = @PPC_ARCH_TRUE@
RANLIB = @RANLIB@
RT_LIBS = @RT_LIBS@
SDL_CFLAGS = @SDL_CFLAGS@
SDL_CONFIG = @SDL_CONFIG@
SDL_LIBS = @SDL_LIBS@
SET_MAKE = @SET_MAKE@
SGMLTOOLS = @SGMLTOOLS@
SHELL = @SHELL@
SPEC_VERSION = @SPEC_VERSION@
SPEEX_CFLAGS = @SPEEX_CFLAGS@
SPEEX_LIBS = @SPEEX_LIBS@
STATIC = @STATIC@
STRIP = @STRIP@
SUNDGA_CFLAGS = @SUNDGA_CFLAGS@
SUNDGA_LIBS = @SUNDGA_LIBS@
TAR_NAME = @TAR_NAME@
THEORAENC_LIBS = @THEORAENC_LIBS@
THEORAFILE_LIBS = @THEORAFILE_LIBS@
THEORA_CFLAGS = @THEORA_CFLAGS@
THEORA_LIBS = @THEORA_LIBS@
THREAD_CFLAGS = @THREAD_CFLAGS@
THREAD_CFLAGS_CONFIG = @THREAD_CFLAGS_CONFIG@
THREAD_INCLUDES = @THREAD_INCLUDES@
THREAD_LIBS = @THREAD_LIBS@
THREAD_LIBS_CONFIG = @THREAD_LIBS_CONFIG@
USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@
USE_NLS = @USE_NLS@
VERSION = @VERSION@
VORBISENC_LIBS = @VORBISENC_LIBS@
VORBISFILE_LIBS = @VORBISFILE_LIBS@
VORBIS_CFLAGS = @VORBIS_CFLAGS@
VORBIS_LIBS = @VORBIS_LIBS@
W32DLL_DEP = @W32DLL_DEP@
W32_NO_OPTIMIZE = @W32_NO_OPTIMIZE@
WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
WIN32_FALSE = @WIN32_FALSE@
WIN32_TRUE = @WIN32_TRUE@
XGETTEXT = @XGETTEXT@
XINE_ACFLAGS = @XINE_ACFLAGS@
XINE_BIN_AGE = @XINE_BIN_AGE@
XINE_BUILD_CC = @XINE_BUILD_CC@
XINE_BUILD_DATE = @XINE_BUILD_DATE@
XINE_BUILD_OS = @XINE_BUILD_OS@
XINE_CONFIG_PREFIX = @XINE_CONFIG_PREFIX@
XINE_DATADIR = @XINE_DATADIR@
XINE_FONTDIR = @XINE_FONTDIR@
XINE_FONTPATH = @XINE_FONTPATH@
XINE_IFACE_AGE = @XINE_IFACE_AGE@
XINE_LOCALEDIR = @XINE_LOCALEDIR@
XINE_LOCALEPATH = @XINE_LOCALEPATH@
XINE_MAJOR = @XINE_MAJOR@
XINE_MINOR = @XINE_MINOR@
XINE_PLUGINDIR = @XINE_PLUGINDIR@
XINE_PLUGINPATH = @XINE_PLUGINPATH@
XINE_PLUGIN_MIN_SYMS = @XINE_PLUGIN_MIN_SYMS@
XINE_SCRIPTPATH = @XINE_SCRIPTPATH@
XINE_SUB = @XINE_SUB@
XVMC_LIB = @XVMC_LIB@
XV_LIB = @XV_LIB@
XXMC_LIB = @XXMC_LIB@
X_CFLAGS = @X_CFLAGS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_LIBS = @X_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
ZLIB_INCLUDES = @ZLIB_INCLUDES@
ZLIB_LIBS = @ZLIB_LIBS@
ZLIB_LIBS_CONFIG = @ZLIB_LIBS_CONFIG@
ac_ct_AR = @ac_ct_AR@
ac_ct_AS = @ac_ct_AS@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_DLLTOOL = @ac_ct_DLLTOOL@
ac_ct_F77 = @ac_ct_F77@
ac_ct_OBJDUMP = @ac_ct_OBJDUMP@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__fastdepOBJC_FALSE = @am__fastdepOBJC_FALSE@
am__fastdepOBJC_TRUE = @am__fastdepOBJC_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = $(XINE_PLUGINDIR)
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
w32_path = @w32_path@
XINE_LIB = $(top_builddir)/src/xine-engine/libxine.la
lib_LTLIBRARIES = xineplug_decode_dts.la
xineplug_decode_dts_la_SOURCES = bitstream.c downmix.c parse.c xine_decoder.c
xineplug_decode_dts_la_LIBADD = $(XINE_LIB)
xineplug_decode_dts_la_LDFLAGS = -avoid-version -module $(XINE_PLUGIN_MIN_SYMS)
noinst_HEADERS = bitstream.h dts.h dts_internal.h tables.h tables_adpcm.h \
	tables_fir.h tables_huffman.h tables_quantization.h tables_vq.h

all: all-am

.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(top_srcdir)/misc/Makefile.common $(am__configure_deps)
	@for dep in $?; do \
	  case '$(am__configure_deps)' in \
	    *$$dep*) \
	      cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
		&& exit 0; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  src/libdts/Makefile'; \
	cd $(top_srcdir) && \
	  $(AUTOMAKE) --gnu  src/libdts/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
	esac;

$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh

$(top_srcdir)/configure:  $(am__configure_deps)
	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
	@$(NORMAL_INSTALL)
	test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
	@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	  if test -f $$p; then \
	    f=$(am__strip_dir) \
	    echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
	    $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
	  else :; fi; \
	done

uninstall-libLTLIBRARIES:
	@$(NORMAL_UNINSTALL)
	@set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	  p=$(am__strip_dir) \
	  echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
	  $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
	done

clean-libLTLIBRARIES:
	-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
	@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	  dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
	  test "$$dir" != "$$p" || dir=.; \
	  echo "rm -f \"$${dir}/so_locations\""; \
	  rm -f "$${dir}/so_locations"; \
	done
xineplug_decode_dts.la: $(xineplug_decode_dts_la_OBJECTS) $(xineplug_decode_dts_la_DEPENDENCIES) 
	$(LINK) -rpath $(libdir) $(xineplug_decode_dts_la_LDFLAGS) $(xineplug_decode_dts_la_OBJECTS) $(xineplug_decode_dts_la_LIBADD) $(LIBS)

mostlyclean-compile:
	-rm -f *.$(OBJEXT)

distclean-compile:
	-rm -f *.tab.c

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bitstream.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/downmix.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xine_decoder.Plo@am__quote@

.c.o:
@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@	$(COMPILE) -c $<

.c.obj:
@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`

.c.lo:
@am__fastdepCC_TRUE@	if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<

mostlyclean-libtool:
	-rm -f *.lo

clean-libtool:
	-rm -rf .libs _libs

distclean-libtool:
	-rm -f libtool
uninstall-info-am:

ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	mkid -fID $$unique
tags: TAGS

TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
		$(TAGS_FILES) $(LISP)
	tags=; \
	here=`pwd`; \
	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
	  test -n "$$unique" || unique=$$empty_fix; \
	  $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
	    $$tags $$unique; \
	fi
ctags: CTAGS
CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
		$(TAGS_FILES) $(LISP)
	tags=; \
	here=`pwd`; \
	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	test -z "$(CTAGS_ARGS)$$tags$$unique" \
	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
	     $$tags $$unique

GTAGS:
	here=`$(am__cd) $(top_builddir) && pwd` \
	  && cd $(top_srcdir) \
	  && gtags -i $(GTAGS_ARGS) $$here

distclean-tags:
	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags

distdir: $(DISTFILES)
	$(mkdir_p) $(distdir)/../../misc
	@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
	list='$(DISTFILES)'; for file in $$list; do \
	  case $$file in \
	    $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
	    $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
	  esac; \
	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
	    dir="/$$dir"; \
	    $(mkdir_p) "$(distdir)$$dir"; \
	  else \
	    dir=''; \
	  fi; \
	  if test -d $$d/$$file; then \
	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
	    fi; \
	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
	  else \
	    test -f $(distdir)/$$file \
	    || cp -p $$d/$$file $(distdir)/$$file \
	    || exit 1; \
	  fi; \
	done
check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES) $(HEADERS)
installdirs:
	for dir in "$(DESTDIR)$(libdir)"; do \
	  test -z "$$dir" || $(mkdir_p) "$$dir"; \
	done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am

install-am: all-am
	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am

installcheck: installcheck-am
install-strip:
	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
	  `test -z '$(STRIP)' || \
	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install

clean-generic:

distclean-generic:
	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
clean: clean-am

clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
	mostlyclean-am

distclean: distclean-am
	-rm -rf ./$(DEPDIR)
	-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
	distclean-libtool distclean-tags

dvi: dvi-am

dvi-am:

html: html-am

info: info-am

info-am:

install-data-am:
	@$(NORMAL_INSTALL)
	$(MAKE) $(AM_MAKEFLAGS) install-data-hook

install-exec-am: install-libLTLIBRARIES

install-info: install-info-am

install-man:

installcheck-am:

maintainer-clean: maintainer-clean-am
	-rm -rf ./$(DEPDIR)
	-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic

mostlyclean: mostlyclean-am

mostlyclean-am: mostlyclean-compile mostlyclean-generic \
	mostlyclean-libtool

pdf: pdf-am

pdf-am:

ps: ps-am

ps-am:

uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES
	@$(NORMAL_INSTALL)
	$(MAKE) $(AM_MAKEFLAGS) uninstall-hook

.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
	clean-libLTLIBRARIES clean-libtool ctags distclean \
	distclean-compile distclean-generic distclean-libtool \
	distclean-tags distdir dvi dvi-am html html-am info info-am \
	install install-am install-data install-data-am \
	install-data-hook install-exec install-exec-am install-info \
	install-info-am install-libLTLIBRARIES install-man \
	install-strip installcheck installcheck-am installdirs \
	maintainer-clean maintainer-clean-generic mostlyclean \
	mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
	pdf pdf-am ps ps-am tags uninstall uninstall-am uninstall-hook \
	uninstall-info-am uninstall-libLTLIBRARIES


$(XINE_LIB):
	@cd $(top_srcdir)/src/xine-engine && $(MAKE)

install-data-hook:
	@if test $$MAKELEVEL -le 4 ; then \
	  if test -x "$(top_srcdir)/post-install.sh" ; then \
	    $(top_srcdir)/post-install.sh ; \
	  fi \
	fi

pass1:
	@$(MAKE) MULTIPASS_CFLAGS="$(PASS1_CFLAGS)"

pass2:
	@$(MAKE) MULTIPASS_CFLAGS="$(PASS2_CFLAGS)"

debug:
	@$(MAKE) CFLAGS="$(DEBUG_CFLAGS)"

install-debug: debug
	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
	@list='$(SUBDIRS)'; for subdir in $$list; do \
	  (cd $$subdir && $(MAKE) $@) || exit; \
	done;
	$(MAKE) $(AM_MAKEFLAGS) install-data-hook

install-includeHEADERS: $(include_HEADERS)
	@$(NORMAL_INSTALL)
	$(install_sh) -d $(DESTDIR)$(includedir)/xine
	@list='$(include_HEADERS)'; for p in $$list; do \
	  if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \
	  echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/xine/$$p"; \
	  $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/xine/$$p; \
	done

uninstall-includeHEADERS:
	@$(NORMAL_UNINSTALL)
	list='$(include_HEADERS)'; for p in $$list; do \
	  rm -f $(DESTDIR)$(includedir)/xine/$$p; \
	done

uninstall-hook:
	@if echo '$(libdir)' | egrep ^'$(XINE_PLUGINDIR)' >/dev/null; then \
	  list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	    p="`echo $$p | sed -e 's/\.la$$/\.so/g;s|^.*/||'`"; \
	    echo " rm -f $(DESTDIR)$(libdir)/$$p"; \
	    rm -f $(DESTDIR)$(libdir)/$$p; \
	  done; \
	fi

mostlyclean-generic:
	-rm -f *~ \#* .*~ .\#*

maintainer-clean-generic:
	-@echo "This command is intended for maintainers to use;"
	-@echo "it deletes files that may require special tools to rebuild."
	-rm -f Makefile.in
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

--- NEW FILE: xine_decoder.c ---
/* 
 * Copyright (C) 2000-2004 the xine project
 * 
 * This file is part of xine, a unix video player.
 * 
 * xine 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.
 * 
 * xine 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-1307, USA
 *
 * $Id: xine_decoder.c,v 1.1 2005/04/04 22:29:47 dsalt-guest Exp $
 *
 * 04-09-2001 DTS passtrough  (C) Joachim Koenig 
 * 09-12-2001 DTS passthrough inprovements (C) James Courtier-Dutton
 *
 */

#ifndef __sun
/* required for swab() */
#define _XOPEN_SOURCE 500
#endif
/* avoid compiler warnings */
#define _BSD_SOURCE 1

#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>

#define LOG_MODULE "libdts"
#define LOG_VERBOSE
/*
#define LOG
*/

#include "xine_internal.h"
#include "xineutils.h"
#include "audio_out.h"
#include "buffer.h"
#include "dts.h"

#define MAX_AC5_FRAME 4096

typedef struct {
  audio_decoder_class_t   decoder_class;
} dts_class_t;

typedef struct {
  audio_decoder_t  audio_decoder;

  xine_stream_t    *stream;
  audio_decoder_class_t *class;

  dts_state_t     *dts_state;
  int64_t          pts;

  int              audio_caps;  
  uint32_t         rate;
  uint32_t         bits_per_sample;
  uint32_t         number_of_channels;
  int              sync_state;
  int              ac5_length, ac5_pcm_length, frame_todo;
  uint32_t         syncdword;
  uint8_t          frame_buffer[MAX_AC5_FRAME];
  uint8_t         *frame_ptr;

  int              output_open;
  
  int              bypass_mode;
  int              dts_flags;
  int              dts_sample_rate;
  int              dts_bit_rate;
  int              dts_flags_map[11]; /* Convert from stream dts_flags to the dts_flags we want from the dts downmixer */
  int              ao_flags_map[11];  /* Convert from the xine AO_CAP's to dts_flags. */
  int              have_lfe;
  
  
} dts_decoder_t;

static void dts_reset (audio_decoder_t *this_gen);
static void dts_discontinuity (audio_decoder_t *this_gen);

static void dts_reset (audio_decoder_t *this_gen) {

  /* dts_decoder_t *this = (dts_decoder_t *) this_gen; */

}

static void dts_discontinuity (audio_decoder_t *this_gen) {
}

#if 0
static inline int16_t blah (int32_t i) {

  if (i > 0x43c07fff)
    return 32767;
  else if (i < 0x43bf8000)
    return -32768;
  else
    return i - 0x43c00000;
}
static inline void float_to_int (float * _f, int16_t * s16, int num_channels) {
  int i;
  int32_t * f = (int32_t *) _f;       /* XXX assumes IEEE float format */

  for (i = 0; i < 256; i++) {
    s16[num_channels*i] = blah (f[i]);
  }
}
#endif

static inline void float_to_int (float * _f, int16_t * s16, int num_channels) {
  int i;
  float f;
  for (i = 0; i < 256; i++) {
    f = _f[i] * 32767;
    if (f > INT16_MAX) f = INT16_MAX;
    if (f < INT16_MIN) f = INT16_MIN;
    s16[num_channels*i] = f;
    /* printf("samples[%d] = %f, %d\n", i, _f[i], s16[num_channels*i]); */
  }
}

static inline void mute_channel (int16_t * s16, int num_channels) {
  int i;
                                                                                                                           
  for (i = 0; i < 256; i++) {
    s16[num_channels*i] = 0;
  }
}

static void dts_decode_frame (dts_decoder_t *this, int64_t pts, int preview_mode) {

  audio_buffer_t *audio_buffer;
  uint32_t  ac5_spdif_type=0;
  int output_mode = AO_CAP_MODE_STEREO;
  uint8_t        *data_out;
  uint8_t        *data_in = this->frame_buffer;
  
  lprintf("decode_frame\n");
  audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out);
  audio_buffer->vpts       = pts;

    if(this->bypass_mode) {
      /* SPDIF digital output */
      if (!this->output_open) {
        this->output_open = (this->stream->audio_out->open (this->stream->audio_out, this->stream,
                                                            this->bits_per_sample, 
                                                            this->rate,
                                                            AO_CAP_MODE_AC5));
      }
      
      if (!this->output_open) 
        return;
      
      data_out=(uint8_t *) audio_buffer->mem;
      if (this->ac5_length > 8191) {
        xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: ac5_length too long\n");
        this->ac5_pcm_length = 0;
      }

      switch (this->ac5_pcm_length) {
      case 512:
        ac5_spdif_type = 0x0b; /* DTS-1 (512-sample bursts) */
        break;
      case 1024:
        ac5_spdif_type = 0x0c; /* DTS-1 (1024-sample bursts) */
        break;
      case 2048:
        ac5_spdif_type = 0x0d; /* DTS-1 (2048-sample bursts) */
        break;
      default:
        xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, 
		"libdts: DTS %i-sample bursts not supported\n", this->ac5_pcm_length);
        return;
      }

#ifdef LOG_DEBUG
      {
        int i;
        printf("libdts: DTS frame type=%d\n",data_in[4] >> 7);
        printf("libdts: DTS deficit frame count=%d\n",(data_in[4] & 0x7f) >> 2);
        printf("libdts: DTS AC5 PCM samples=%d\n",ac5_pcm_samples);
        printf("libdts: DTS AC5 length=%d\n",this->ac5_length);
        printf("libdts: DTS AC5 bitrate=%d\n",((data_in[8] & 0x03) << 4) | (data_in[8] >> 4));
        printf("libdts: DTS AC5 spdif type=%d\n", ac5_spdif_type);

        printf("libdts: ");
        for(i=2000;i<2048;i++) {
          printf("%02x ",data_in[i]);
        }
        printf("\n");
      }
#endif

      lprintf("length=%d pts=%lld\n",this->ac5_pcm_length,audio_buffer->vpts);

      audio_buffer->num_frames = this->ac5_pcm_length;

      data_out[0] = 0x72; data_out[1] = 0xf8;	/* spdif syncword    */
      data_out[2] = 0x1f; data_out[3] = 0x4e;	/* ..............    */
      data_out[4] = ac5_spdif_type;		/* DTS data          */
      data_out[5] = 0;		                /* Unknown */
      data_out[6] = (this->ac5_length << 3) & 0xff;   /* ac5_length * 8   */
      data_out[7] = ((this->ac5_length ) >> 5) & 0xff;

      if( this->ac5_pcm_length ) {
        if( this->ac5_pcm_length % 2) {
          swab(data_in, &data_out[8], this->ac5_length );
        } else {
          swab(data_in, &data_out[8], this->ac5_length + 1);
        }
      }
    } else {
      /* Software decode */
      int       i, dts_flags;
      int16_t  *int_samples = audio_buffer->mem;
      int       number_of_dts_blocks;

      level_t   level = 1.0;
      sample_t *samples;

      this->have_lfe = this->dts_flags & DTS_LFE;
      dts_flags = this->dts_flags_map[this->dts_flags & DTS_CHANNEL_MASK];
      if (this->have_lfe)
        if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) {
          output_mode = AO_CAP_MODE_5_1CHANNEL;
          dts_flags |= DTS_LFE;
        } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) {
          output_mode = AO_CAP_MODE_4_1CHANNEL;
          dts_flags |= DTS_LFE;
        } else {
          xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: WHAT DO I DO!!!\n");
          output_mode = this->ao_flags_map[dts_flags & DTS_CHANNEL_MASK];
        }
      else
        output_mode = this->ao_flags_map[dts_flags & DTS_CHANNEL_MASK];

      if(dts_frame(this->dts_state, data_in, &dts_flags, &level, 0)) {
        xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: dts_frame error\n");
        return;
      }
      if (!this->output_open) {
        this->output_open = (this->stream->audio_out->open (this->stream->audio_out, this->stream,
                                                this->bits_per_sample, 
                                                this->rate,
                                                output_mode));
      }
      
      if (!this->output_open) 
        return;
      number_of_dts_blocks = dts_blocks_num (this->dts_state); 
      audio_buffer->num_frames = 256*number_of_dts_blocks;
      for(i = 0; i < number_of_dts_blocks; i++) {
        if(dts_block(this->dts_state)) {
          xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, 
                  "libdts: dts_block error on audio channel %d\n", i);
          audio_buffer->num_frames = 0;
          break;
        }

        samples = dts_samples(this->dts_state);
        switch (output_mode) {
        case AO_CAP_MODE_MONO:
          float_to_int (&samples[0], int_samples+(i*256), 1);
          break;
        case AO_CAP_MODE_STEREO:
          /* Tested, working. */
          float_to_int (&samples[0*256], int_samples+(i*256*2), 2);   /*  L */
          float_to_int (&samples[1*256], int_samples+(i*256*2)+1, 2); /*  R */
          break;
        case AO_CAP_MODE_4CHANNEL:
          /* Tested, working */
          float_to_int (&samples[0*256], int_samples+(i*256*4),   4); /*  L */
          float_to_int (&samples[1*256], int_samples+(i*256*4)+1, 4); /*  R */
          float_to_int (&samples[2*256], int_samples+(i*256*4)+2, 4); /* RL */
          float_to_int (&samples[3*256], int_samples+(i*256*4)+3, 4); /* RR */
          break;
        case AO_CAP_MODE_4_1CHANNEL:
          /* Tested, working */
          float_to_int (&samples[0*256], int_samples+(i*256*6)+0, 6); /*   L */
          float_to_int (&samples[1*256], int_samples+(i*256*6)+1, 6); /*   R */
          float_to_int (&samples[2*256], int_samples+(i*256*6)+2, 6); /*  RL */
          float_to_int (&samples[3*256], int_samples+(i*256*6)+3, 6); /*  RR */
          float_to_int (&samples[4*256], int_samples+(i*256*6)+5, 6); /* LFE */
          mute_channel ( int_samples+(i*256*6)+4, 6); /* C */
          break;
        case AO_CAP_MODE_5CHANNEL:
          /* Tested, working */
          float_to_int (&samples[0*256], int_samples+(i*256*6)+4, 6); /*   C */
          float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /*   L */
          float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /*   R */
          float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /*  RL */
          float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /*  RR */
          mute_channel ( int_samples+(i*256*6)+5, 6); /* LFE */
          break;
        case AO_CAP_MODE_5_1CHANNEL:
          float_to_int (&samples[0*256], int_samples+(i*256*6)+4, 6); /*   C */
          float_to_int (&samples[1*256], int_samples+(i*256*6)+0, 6); /*   L */
          float_to_int (&samples[2*256], int_samples+(i*256*6)+1, 6); /*   R */
          float_to_int (&samples[3*256], int_samples+(i*256*6)+2, 6); /*  RL */
          float_to_int (&samples[4*256], int_samples+(i*256*6)+3, 6); /*  RR */
          float_to_int (&samples[5*256], int_samples+(i*256*6)+5, 6); /* LFE */ /* Not working yet */
          break;
        default:
          xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "libdts: help - unsupported mode %08x\n", output_mode);
        }
      }
    }
    
    this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
   
  
}

static void dts_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {

  dts_decoder_t  *this = (dts_decoder_t *) this_gen;
  uint8_t        *current = (uint8_t *)buf->content;
  uint8_t        *sync_start=current + 1;
  uint8_t        *end = buf->content + buf->size;
  
  lprintf("decode_data\n");

  if (buf->decoder_flags & BUF_FLAG_PREVIEW)
    return;
  if (buf->decoder_flags & BUF_FLAG_STDHEADER)
    return;

  lprintf ("processing...state %d\n", this->sync_state);

  while (current < end) {
    switch (this->sync_state) {
    case 0:  /* Looking for sync header */
	  this->syncdword = (this->syncdword << 8) | *current++;
/*
          if ((this->syncdword == 0xff1f00e8) ||
              (this->syncdword == 0x1fffe800) ||
              (this->syncdword == 0xfe7f0180) ||
              (this->syncdword == 0x7ffe8001) ) {
*/
          if ((this->syncdword == 0x7ffe8001)) {

            lprintf ("sync found: syncdword=0x%x\n", this->syncdword);
	    this->frame_buffer[0] = 0x7f;
	    this->frame_buffer[1] = 0xfe;
	    this->frame_buffer[2] = 0x80;
	    this->frame_buffer[3] = 0x01;

	    this->sync_state = 1;
	    this->frame_ptr = this->frame_buffer+4;
            this->pts = buf->pts;
            break;
	  }
          if ((this->syncdword == 0xff1f00e8)) {

            lprintf ("sync found: syncdword=0x%x\n", this->syncdword);
	    this->frame_buffer[0] = 0xff;
	    this->frame_buffer[1] = 0x1f;
	    this->frame_buffer[2] = 0x00;
	    this->frame_buffer[3] = 0xe8;

	    this->sync_state = 1;
	    this->frame_ptr = this->frame_buffer+4;
            this->pts = buf->pts;
            break;
	  }
          break;

    case 1:  /* Looking for enough bytes for sync_info. */
          sync_start = current - 1;
	  *this->frame_ptr++ = *current++;
          if ((this->frame_ptr - this->frame_buffer) > 19) {
	    int old_dts_flags       = this->dts_flags;
	    int old_dts_sample_rate = this->dts_sample_rate;
	    int old_dts_bit_rate    = this->dts_bit_rate;

	    this->ac5_length = dts_syncinfo (this->dts_state, this->frame_buffer,
					       &this->dts_flags,
					       &this->dts_sample_rate,
					       &this->dts_bit_rate, &(this->ac5_pcm_length));
	    lprintf("ac5_length=%d\n",this->ac5_length);
	    lprintf("dts_sample_rate=%d\n",this->dts_sample_rate);

            if ( (this->ac5_length < 80) || (this->ac5_length > MAX_AC5_FRAME) ) { /* Invalid dts ac5_pcm_length */
	      this->syncdword = 0;
	      current = sync_start;
	      this->sync_state = 0;
	      break;
	    }

            lprintf("Frame length = %d\n",this->ac5_pcm_length);

	    this->frame_todo = this->ac5_length - 20;
	    this->sync_state = 2;
	    if (!_x_meta_info_get(this->stream, XINE_META_INFO_AUDIOCODEC) ||
	        old_dts_flags       != this->dts_flags ||
                old_dts_sample_rate != this->dts_sample_rate ||
		old_dts_bit_rate    != this->dts_bit_rate) {

              this->rate = this->dts_sample_rate;
              if (((this->dts_flags & DTS_CHANNEL_MASK) == DTS_3F2R) && (this->dts_flags & DTS_LFE))
                _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 5.1");
              else if ((((this->dts_flags & DTS_CHANNEL_MASK) == DTS_2F2R) && (this->dts_flags & DTS_LFE)) ||
                       (((this->dts_flags & DTS_CHANNEL_MASK) == DTS_3F1R) && (this->dts_flags & DTS_LFE)))
                _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 4.1");
              else if ((this->dts_flags & DTS_CHANNEL_MASK) == DTS_3F2R) 
                _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 5.0");
              else if (((this->dts_flags & DTS_CHANNEL_MASK) == DTS_2F2R) ||
                       ((this->dts_flags & DTS_CHANNEL_MASK) == DTS_3F1R))
                _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 4.0");
              else if (((this->dts_flags & DTS_CHANNEL_MASK) == DTS_2F1R) ||
                       ((this->dts_flags & DTS_CHANNEL_MASK) == DTS_3F))
                _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 3.0");
              else if ((this->dts_flags & DTS_CHANNEL_MASK) == DTS_STEREO)
                _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 2.0 (stereo)");
              else if ((this->dts_flags & DTS_CHANNEL_MASK) == DTS_MONO)
                _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS 1.0");
              else
                _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DTS");

              _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, this->dts_bit_rate);
              _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, this->dts_sample_rate);
            }
          }
          break;
            
    case 2:  /* Filling frame_buffer with sync_info bytes */
	  *this->frame_ptr++ = *current++;
	  this->frame_todo--;
	  if (this->frame_todo < 1) {
	    this->sync_state = 3;
          } else break;
      
    case 3:  /* Ready for decode */
#if 0
          dtsdec_decode_frame (this, this->pts_list[0], buf->decoder_flags & BUF_FLAG_PREVIEW);
#else
          dts_decode_frame (this, this->pts, buf->decoder_flags & BUF_FLAG_PREVIEW);
#endif
    case 4:  /* Clear up ready for next frame */
          this->pts = 0;
	  this->syncdword = 0;
	  this->sync_state = 0;
          break;
    default: /* No come here */ 
          break;
    }
  }
}

static void dts_dispose (audio_decoder_t *this_gen) {
  dts_decoder_t *this = (dts_decoder_t *) this_gen; 
  
  if (this->output_open) 
    this->stream->audio_out->close (this->stream->audio_out, this->stream);
  this->output_open = 0;
  
  free (this);
}

static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {
  dts_decoder_t *this ;

  lprintf("open_plugin\n");

  this = (dts_decoder_t *) xine_xmalloc (sizeof (dts_decoder_t));

  this->audio_decoder.decode_data         = dts_decode_data;
  this->audio_decoder.reset               = dts_reset;
  this->audio_decoder.discontinuity       = dts_discontinuity;
  this->audio_decoder.dispose             = dts_dispose;

  this->dts_state = dts_init(0);
  this->audio_caps        = stream->audio_out->get_capabilities(stream->audio_out);
  if(this->audio_caps & AO_CAP_MODE_AC5)
    this->bypass_mode = 1;
  else {
    this->bypass_mode = 0;
    /* FIXME: Leave "DOLBY pro logic" downmix out for now. */

    this->dts_flags_map[DTS_MONO]   = DTS_MONO;
    this->dts_flags_map[DTS_STEREO] = DTS_STEREO;
    this->dts_flags_map[DTS_3F]     = DTS_STEREO;
    this->dts_flags_map[DTS_2F1R]   = DTS_STEREO;
    this->dts_flags_map[DTS_3F1R]   = DTS_STEREO;
    this->dts_flags_map[DTS_2F2R]   = DTS_STEREO;
    this->dts_flags_map[DTS_3F2R]   = DTS_STEREO;

    this->ao_flags_map[DTS_MONO]    = AO_CAP_MODE_MONO;
    this->ao_flags_map[DTS_STEREO]  = AO_CAP_MODE_STEREO;
    this->ao_flags_map[DTS_3F]      = AO_CAP_MODE_STEREO;
    this->ao_flags_map[DTS_2F1R]    = AO_CAP_MODE_STEREO;
    this->ao_flags_map[DTS_3F1R]    = AO_CAP_MODE_STEREO;
    this->ao_flags_map[DTS_2F2R]    = AO_CAP_MODE_STEREO;
    this->ao_flags_map[DTS_3F2R]    = AO_CAP_MODE_STEREO;

    /* find best mode */
    if (this->audio_caps & AO_CAP_MODE_5_1CHANNEL) {

      this->dts_flags_map[DTS_2F2R]   = DTS_2F2R;
      this->dts_flags_map[DTS_3F2R]   = DTS_3F2R | DTS_LFE;
      this->ao_flags_map[DTS_2F2R]    = AO_CAP_MODE_4CHANNEL;
      this->ao_flags_map[DTS_3F2R]    = AO_CAP_MODE_5CHANNEL;
                                                                                                                           
    } else if (this->audio_caps & AO_CAP_MODE_5CHANNEL) {

      this->dts_flags_map[DTS_2F2R]   = DTS_2F2R;
      this->dts_flags_map[DTS_3F2R]   = DTS_3F2R;
      this->ao_flags_map[DTS_2F2R]    = AO_CAP_MODE_4CHANNEL;
      this->ao_flags_map[DTS_3F2R]    = AO_CAP_MODE_5CHANNEL;

    } else if (this->audio_caps & AO_CAP_MODE_4_1CHANNEL) {

      this->dts_flags_map[DTS_2F2R]   = DTS_2F2R;
      this->dts_flags_map[DTS_3F2R]   = DTS_2F2R | DTS_LFE;
      this->ao_flags_map[DTS_2F2R]    = AO_CAP_MODE_4CHANNEL;
      this->ao_flags_map[DTS_3F2R]    = AO_CAP_MODE_4CHANNEL;

    } else if (this->audio_caps & AO_CAP_MODE_4CHANNEL) {

      this->dts_flags_map[DTS_2F2R]   = DTS_2F2R;
      this->dts_flags_map[DTS_3F2R]   = DTS_2F2R;

      this->ao_flags_map[DTS_2F2R]    = AO_CAP_MODE_4CHANNEL;
      this->ao_flags_map[DTS_3F2R]    = AO_CAP_MODE_4CHANNEL;

      /* else if (this->audio_caps & AO_CAP_MODE_STEREO)
         defaults are ok */
    } else if (!(this->audio_caps & AO_CAP_MODE_STEREO)) {
      xprintf (this->stream->xine, XINE_VERBOSITY_LOG, _("HELP! a mono-only audio driver?!\n"));

      this->dts_flags_map[DTS_MONO]   = DTS_MONO;
      this->dts_flags_map[DTS_STEREO] = DTS_MONO;
      this->dts_flags_map[DTS_3F]     = DTS_MONO;
      this->dts_flags_map[DTS_2F1R]   = DTS_MONO;
      this->dts_flags_map[DTS_3F1R]   = DTS_MONO;
      this->dts_flags_map[DTS_2F2R]   = DTS_MONO;
      this->dts_flags_map[DTS_3F2R]   = DTS_MONO;

      this->ao_flags_map[DTS_MONO]    = AO_CAP_MODE_MONO;
      this->ao_flags_map[DTS_STEREO]  = AO_CAP_MODE_MONO;
      this->ao_flags_map[DTS_3F]      = AO_CAP_MODE_MONO;
      this->ao_flags_map[DTS_2F1R]    = AO_CAP_MODE_MONO;
      this->ao_flags_map[DTS_3F1R]    = AO_CAP_MODE_MONO;
      this->ao_flags_map[DTS_2F2R]    = AO_CAP_MODE_MONO;
      this->ao_flags_map[DTS_3F2R]    = AO_CAP_MODE_MONO;
    }
  }
  this->stream        = stream;
  this->class         = class_gen;
  this->output_open   = 0;
  this->rate          = 48000;
  this->bits_per_sample=16;
  this->number_of_channels=2;
  return &this->audio_decoder;
}

static char *get_identifier (audio_decoder_class_t *this) {
  return "DTS";
}

static char *get_description (audio_decoder_class_t *this) {
  return "DTS passthru audio format decoder plugin";
}

static void dispose_class (audio_decoder_class_t *this) {
  lprintf("dispose_class\n");

  free (this);
}

static void *init_plugin (xine_t *xine, void *data) {
  dts_class_t *this ;

  lprintf("init_plugin\n");

  this = (dts_class_t *) xine_xmalloc (sizeof (dts_class_t));

  this->decoder_class.open_plugin     = open_plugin;
  this->decoder_class.get_identifier  = get_identifier;
  this->decoder_class.get_description = get_description;
  this->decoder_class.dispose         = dispose_class;

  return this;
}

static uint32_t audio_types[] = { 
  BUF_AUDIO_DTS, 0
 };

static decoder_info_t dec_info_audio = {
  audio_types,         /* supported types */
  1                    /* priority        */
};

plugin_info_t xine_plugin_info[] = {
  /* type, API, "name", version, special_info, init_function */  
  { PLUGIN_AUDIO_DECODER, 15, "dts", XINE_VERSION_CODE, &dec_info_audio, init_plugin },
  { PLUGIN_NONE, 0, "", 0, NULL, NULL }
};

--- NEW FILE: tables_huffman.h ---
/*
 * huffman_tables.h
 * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
 *
 * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/dtsdec.html for updates.
 *
 * dtsdec 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.
 *
 * dtsdec 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
[...1031 lines suppressed...]
    int length = 0, j;

    while( 1 )
    {
        length++;
        value <<= 1;
        value |= bitstream_get (state, 1);

	for( j = 0; huff[j].length != 0 && huff[j].length < length; j++ );

	if( huff[j].length == 0 ) break;

	for( ; huff[j].length == length; j++ )
	{
	    if( huff[j].code == value ) return huff[j].value;
	}
    }

    return 0;
}