00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "config.h"
00026
00027 #include <inttypes.h>
00028
00029 #include "dts.h"
00030 #include "dts_internal.h"
00031 #include "bitstream.h"
00032
00033 #define BUFFER_SIZE 4096
00034
00035 void dts_bitstream_init (dts_state_t * state, uint8_t * buf, int word_mode,
00036 int bigendian_mode)
00037 {
00038 intptr_t align;
00039
00040 align = (uintptr_t)buf & 3;
00041 state->buffer_start = (uint32_t *) (buf - align);
00042 state->bits_left = 0;
00043 state->current_word = 0;
00044 state->word_mode = word_mode;
00045 state->bigendian_mode = bigendian_mode;
00046 bitstream_get (state, align * 8);
00047 }
00048 #include<stdio.h>
00049 static inline void bitstream_fill_current (dts_state_t * state)
00050 {
00051 uint32_t tmp;
00052
00053 tmp = *(state->buffer_start++);
00054
00055 if (state->bigendian_mode)
00056 state->current_word = swab32 (tmp);
00057 else
00058 state->current_word = swable32 (tmp);
00059
00060 if (!state->word_mode)
00061 {
00062 state->current_word = (state->current_word & 0x00003FFF) |
00063 ((state->current_word & 0x3FFF0000 ) >> 2);
00064 }
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 uint32_t dts_bitstream_get_bh (dts_state_t * state, uint32_t num_bits)
00077 {
00078 uint32_t result;
00079
00080 num_bits -= state->bits_left;
00081
00082 result = ((state->current_word << (32 - state->bits_left)) >>
00083 (32 - state->bits_left));
00084
00085 if ( !state->word_mode && num_bits > 28 ) {
00086 bitstream_fill_current (state);
00087 result = (result << 28) | state->current_word;
00088 num_bits -= 28;
00089 }
00090
00091 bitstream_fill_current (state);
00092
00093 if ( state->word_mode )
00094 {
00095 if (num_bits != 0)
00096 result = (result << num_bits) |
00097 (state->current_word >> (32 - num_bits));
00098
00099 state->bits_left = 32 - num_bits;
00100 }
00101 else
00102 {
00103 if (num_bits != 0)
00104 result = (result << num_bits) |
00105 (state->current_word >> (28 - num_bits));
00106
00107 state->bits_left = 28 - num_bits;
00108 }
00109
00110 return result;
00111 }