diff options
author | Dave Chapman <dave@dchapman.com> | 2007-07-03 09:25:36 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2007-07-03 09:25:36 +0000 |
commit | c72824786a0e8c68921ebb9b72f02a2e80aaee17 (patch) | |
tree | adf8dac26d074ee3620df4ab482ff108561ead01 /apps/codecs/libwma/common.c | |
parent | 2ca895bae7a25ea8ef7f295b4e8ab01ff75a4914 (diff) | |
download | rockbox-c72824786a0e8c68921ebb9b72f02a2e80aaee17.tar.gz rockbox-c72824786a0e8c68921ebb9b72f02a2e80aaee17.zip |
Initial, work-in-progress, version of a WMA codec using Michael Giacomelli's fixed-point and malloc-less WMA decoder (based on the ffmpeg WMA decoder from early 2006, and also building on the work started by Paul Jones). The codec itself and the ASF parsing code were written by me, inspired by the ASF parser in libasf. Current performance is around 400% realtime on gigabeat, 100% realtime on PP and 20% realtime on Coldfire.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13769 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libwma/common.c')
-rw-r--r-- | apps/codecs/libwma/common.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/apps/codecs/libwma/common.c b/apps/codecs/libwma/common.c new file mode 100644 index 0000000000..4d165ed0a8 --- /dev/null +++ b/apps/codecs/libwma/common.c | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * Common bit i/o utils | ||
3 | * Copyright (c) 2000, 2001 Fabrice Bellard. | ||
4 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
5 | * | ||
6 | * This library is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This library is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with this library; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at> | ||
21 | */ | ||
22 | |||
23 | /** | ||
24 | * @file common.c | ||
25 | * common internal api. | ||
26 | */ | ||
27 | |||
28 | #include "avcodec.h" | ||
29 | |||
30 | const uint8_t ff_sqrt_tab[128]={ | ||
31 | 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, | ||
32 | 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, | ||
33 | 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, | ||
34 | 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11 | ||
35 | }; | ||
36 | |||
37 | const uint8_t ff_log2_tab[256]={ | ||
38 | 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, | ||
39 | 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | ||
40 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
41 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
42 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
43 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
44 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
45 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 | ||
46 | }; | ||
47 | |||
48 | /** | ||
49 | * init GetBitContext. | ||
50 | * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits | ||
51 | * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end | ||
52 | * @param bit_size the size of the buffer in bits | ||
53 | */ | ||
54 | void init_get_bits(GetBitContext *s, | ||
55 | const uint8_t *buffer, int bit_size) | ||
56 | { | ||
57 | const int buffer_size= (bit_size+7)>>3; | ||
58 | |||
59 | s->buffer= buffer; | ||
60 | s->size_in_bits= bit_size; | ||
61 | s->buffer_end= buffer + buffer_size; | ||
62 | s->index=0; | ||
63 | { | ||
64 | OPEN_READER(re, s) | ||
65 | UPDATE_CACHE(re, s) | ||
66 | UPDATE_CACHE(re, s) | ||
67 | CLOSE_READER(re, s) | ||
68 | } | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * reads 0-32 bits. | ||
73 | */ | ||
74 | unsigned int get_bits_long(GetBitContext *s, int n){ | ||
75 | if(n<=17) return get_bits(s, n); | ||
76 | else{ | ||
77 | int ret= get_bits(s, 16) << (n-16); | ||
78 | return ret | get_bits(s, n-16); | ||
79 | } | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * shows 0-32 bits. | ||
84 | */ | ||
85 | unsigned int show_bits_long(GetBitContext *s, int n){ | ||
86 | if(n<=17) return show_bits(s, n); | ||
87 | else{ | ||
88 | GetBitContext gb= *s; | ||
89 | int ret= get_bits_long(s, n); | ||
90 | *s= gb; | ||
91 | return ret; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | void align_get_bits(GetBitContext *s) | ||
96 | { | ||
97 | int n= (-get_bits_count(s)) & 7; | ||
98 | if(n) skip_bits(s, n); | ||
99 | } | ||
100 | |||
101 | int check_marker(GetBitContext *s, const char *msg) | ||
102 | { | ||
103 | (void)msg; | ||
104 | int bit= get_bits1(s); | ||
105 | return bit; | ||
106 | } | ||
107 | |||