4
* Copyright (C) Aaron Holtzman - Dec 1999
6
* This file is part of ac3dec, a free AC-3 audio decoder
8
* ac3dec is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2, or (at your option)
13
* ac3dec is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with GNU Make; see the file COPYING. If not, write to
20
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
#include "../common.h"
26
#include "ac3_internal.h"
27
#include "bitstream.h"
29
#define BUFFER_SIZE 4096
31
static uint8_t *buffer_start;
34
uint32_t current_word;
36
void bitstream_set_ptr (uint8_t * buf)
43
bitstream_fill_current()
45
current_word = *((uint32_t*)buffer_start)++;
46
current_word = swab32(current_word);
50
// The fast paths for _get is in the
51
// bitstream.h header file so it can be inlined.
53
// The "bottom half" of this routine is suffixed _bh
59
bitstream_get_bh(uint32_t num_bits)
63
num_bits -= bits_left;
64
result = (current_word << (32 - bits_left)) >> (32 - bits_left);
66
bitstream_fill_current();
69
result = (result << num_bits) | (current_word >> (32 - num_bits));
71
bits_left = 32 - num_bits;