- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# bitstream.h

    00001 /*
    00002  * bitstream.h
    00003  * Copyright (C) 2004 Gildas Bazin <gbazin@videolan.org>
    00004  * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
    00005  * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
    00006  *
    00007  * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
    00008  * See http://www.videolan.org/dtsdec.html for updates.
    00009  *
    00010  * dtsdec is free software; you can redistribute it and/or modify
    00011  * it under the terms of the GNU General Public License as published by
    00012  * the Free Software Foundation; either version 2 of the License, or
    00013  * (at your option) any later version.
    00014  *
    00015  * dtsdec is distributed in the hope that it will be useful,
    00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00018  * GNU General Public License for more details.
    00019  *
    00020  * You should have received a copy of the GNU General Public License
    00021  * along with this program; if not, write to the Free Software
    00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00023  */
    00024
    00025 #ifdef WORDS_BIGENDIAN
    00026
    00027 #   define swab32(x) (x)
    00028
    00029 #else
    00030
    00031 #   define swab32(x)\
    00032 ((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) |  \
    00033  (((uint8_t*)&x)[2] << 8)  | (((uint8_t*)&x)[3]))
    00034
    00035 #endif
    00036
    00037 #ifdef WORDS_BIGENDIAN
    00038
    00039 #   define swable32(x)\
    00040 ((((uint8_t*)&x)[0] << 16) | (((uint8_t*)&x)[1] << 24) |  \
    00041  (((uint8_t*)&x)[2])  | (((uint8_t*)&x)[3] << 8))
    00042
    00043 #else
    00044
    00045 #   define swable32(x)\
    00046 ((((uint16_t*)&x)[0] << 16) | (((uint16_t*)&x)[1]))
    00047
    00048 #endif
    00049
    00050 void dts_bitstream_init (dts_state_t * state, uint8_t * buf, int word_mode,
    00051                          int endian_mode);
    00052 uint32_t dts_bitstream_get_bh (dts_state_t * state, uint32_t num_bits);
    00053
    00054 static inline uint32_t bitstream_get (dts_state_t * state, uint32_t num_bits)
    00055 {
    00056     uint32_t result;
    00057
    00058     if (num_bits < state->bits_left) {
    00059         result = (state->current_word << (32 - state->bits_left))
    00060                                       >> (32 - num_bits);
    00061
    00062         state->bits_left -= num_bits;
    00063         return result;
    00064     }
    00065
    00066     return dts_bitstream_get_bh (state, num_bits);
    00067 }