00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00054
00055
00056
00057
00058
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 }