bitstream.c

00001 /*
00002  * bitstream.c
00003  * Copyright (C) 2000-2002 Michel Lespinasse <[email protected]>
00004  * Copyright (C) 1999-2000 Aaron Holtzman <[email protected]>
00005  *
00006  * This file is part of a52dec, a free ATSC A-52 stream decoder.
00007  * See http://liba52.sourceforge.net/ for updates.
00008  *
00009  * a52dec is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * a52dec is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  */
00023 
00024 #include "config.h"
00025 
00026 #include <inttypes.h>
00027 
00028 #include "a52.h"
00029 #include "a52_internal.h"
00030 #include "bitstream.h"
00031 
00032 #define BUFFER_SIZE 4096
00033 
00034 void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf)
00035 {
00036     int align;
00037 
00038     align = (long)buf & 3;
00039     state->buffer_start = (uint32_t *) (buf - align);
00040     state->bits_left = 0;
00041     bitstream_get (state, align * 8);
00042 }
00043 
00044 static inline void bitstream_fill_current (a52_state_t * state)
00045 {
00046     uint32_t tmp;
00047 
00048     tmp = *(state->buffer_start++);
00049     state->current_word = swab32 (tmp);
00050 }
00051 
00052 /*
00053  * The fast paths for _get is in the
00054  * bitstream.h header file so it can be inlined.
00055  *
00056  * The "bottom half" of this routine is suffixed _bh
00057  *
00058  * -ah
00059  */
00060 
00061 uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits)
00062 {
00063     uint32_t result;
00064 
00065     num_bits -= state->bits_left;
00066     result = ((state->current_word << (32 - state->bits_left)) >>
00067               (32 - state->bits_left));
00068 
00069     bitstream_fill_current (state);
00070 
00071     if (num_bits != 0)
00072         result = (result << num_bits) | (state->current_word >> (32 - num_bits));
00073 
00074     state->bits_left = 32 - num_bits;
00075 
00076     return result;
00077 }
00078 
00079 int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits)
00080 {
00081     int32_t result;
00082 
00083     num_bits -= state->bits_left;
00084     result = ((((int32_t)state->current_word) << (32 - state->bits_left)) >>
00085               (32 - state->bits_left));
00086 
00087     bitstream_fill_current(state);
00088 
00089     if (num_bits != 0)
00090         result = (result << num_bits) | (state->current_word >> (32 - num_bits));
00091         
00092     state->bits_left = 32 - num_bits;
00093 
00094     return result;
00095 }

Generated on Tue Dec 13 14:47:27 2005 for guliverkli by  doxygen 1.4.5