Mercurial > libavcodec.hg
comparison libac3/bitstream.c @ 0:986e461dc072 libavcodec
Initial revision
| author | glantau |
|---|---|
| date | Sun, 22 Jul 2001 14:18:56 +0000 |
| parents | |
| children | 5aa6292a1660 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:986e461dc072 |
|---|---|
| 1 /* | |
| 2 * bitstream.c | |
| 3 * | |
| 4 * Copyright (C) Aaron Holtzman - Dec 1999 | |
| 5 * | |
| 6 * This file is part of ac3dec, a free AC-3 audio decoder | |
| 7 * | |
| 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) | |
| 11 * any later version. | |
| 12 * | |
| 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. | |
| 17 * | |
| 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. | |
| 21 * | |
| 22 */ | |
| 23 | |
| 24 #include <inttypes.h> | |
| 25 #include <stdlib.h> | |
| 26 #include <stdio.h> | |
| 27 | |
| 28 #include "ac3.h" | |
| 29 #include "ac3_internal.h" | |
| 30 #include "bitstream.h" | |
| 31 | |
| 32 #define BUFFER_SIZE 4096 | |
| 33 | |
| 34 static uint8_t *buffer_start; | |
| 35 | |
| 36 uint32_t bits_left; | |
| 37 uint32_t current_word; | |
| 38 | |
| 39 void bitstream_set_ptr (uint8_t * buf) | |
| 40 { | |
| 41 buffer_start = buf; | |
| 42 bits_left = 0; | |
| 43 } | |
| 44 | |
| 45 static inline void | |
| 46 bitstream_fill_current() | |
| 47 { | |
| 48 current_word = *((uint32_t*)buffer_start)++; | |
| 49 current_word = swab32(current_word); | |
| 50 } | |
| 51 | |
| 52 // | |
| 53 // The fast paths for _get is in the | |
| 54 // bitstream.h header file so it can be inlined. | |
| 55 // | |
| 56 // The "bottom half" of this routine is suffixed _bh | |
| 57 // | |
| 58 // -ah | |
| 59 // | |
| 60 | |
| 61 uint32_t | |
| 62 bitstream_get_bh(uint32_t num_bits) | |
| 63 { | |
| 64 uint32_t result; | |
| 65 | |
| 66 num_bits -= bits_left; | |
| 67 result = (current_word << (32 - bits_left)) >> (32 - bits_left); | |
| 68 | |
| 69 bitstream_fill_current(); | |
| 70 | |
| 71 if(num_bits != 0) | |
| 72 result = (result << num_bits) | (current_word >> (32 - num_bits)); | |
| 73 | |
| 74 bits_left = 32 - num_bits; | |
| 75 | |
| 76 return result; | |
| 77 } |
