summaryrefslogtreecommitdiff
path: root/apps/codecs/libcook
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libcook')
-rw-r--r--apps/codecs/libcook/Makefile.test4
-rw-r--r--apps/codecs/libcook/SOURCES3
-rw-r--r--apps/codecs/libcook/bitstream.c85
-rw-r--r--apps/codecs/libcook/bitstream.h21
-rw-r--r--apps/codecs/libcook/bswap.h173
-rw-r--r--apps/codecs/libcook/cook.c15
-rw-r--r--apps/codecs/libcook/cook.h4
-rw-r--r--apps/codecs/libcook/cook_fixpoint.h53
-rw-r--r--apps/codecs/libcook/cookdata_fixpoint.h6
-rw-r--r--apps/codecs/libcook/libcook.make18
-rw-r--r--apps/codecs/libcook/main.c25
11 files changed, 212 insertions, 195 deletions
diff --git a/apps/codecs/libcook/Makefile.test b/apps/codecs/libcook/Makefile.test
index 493ab8f623..c8a3236935 100644
--- a/apps/codecs/libcook/Makefile.test
+++ b/apps/codecs/libcook/Makefile.test
@@ -1,4 +1,4 @@
1CFLAGS = -Wall -O3 1CFLAGS = -Wall -O3 -DTEST -D"DEBUGF=printf"
2OBJS = main.o bitstream.o cook.o ../librm/rm.o 2OBJS = main.o bitstream.o cook.o ../librm/rm.o
3cooktest: $(OBJS) 3cooktest: $(OBJS)
4 gcc -o cooktest $(OBJS) 4 gcc -o cooktest $(OBJS)
@@ -7,4 +7,4 @@ cooktest: $(OBJS)
7 $(CC) $(CFLAGS) -c -o $@ $< 7 $(CC) $(CFLAGS) -c -o $@ $<
8 8
9clean: 9clean:
10 rm -f cooktest $(OBJS) *~ 10 rm -f cooktest $(OBJS) *~ output.wav
diff --git a/apps/codecs/libcook/SOURCES b/apps/codecs/libcook/SOURCES
new file mode 100644
index 0000000000..7b2cd967ea
--- /dev/null
+++ b/apps/codecs/libcook/SOURCES
@@ -0,0 +1,3 @@
1cook.c
2bitstream.c
3../librm/rm.c
diff --git a/apps/codecs/libcook/bitstream.c b/apps/codecs/libcook/bitstream.c
index 4bc706ffb7..1375134b21 100644
--- a/apps/codecs/libcook/bitstream.c
+++ b/apps/codecs/libcook/bitstream.c
@@ -22,13 +22,13 @@
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */ 23 */
24 24
25/**
26 * @file libavcodec/bitstream.c
27 * bitstream api.
28 */
29
30#include "bitstream.h" 25#include "bitstream.h"
31 26
27#ifdef ROCKBOX
28#undef DEBUGF
29#define DEBUGF(...)
30#endif
31
32const uint8_t ff_log2_run[32]={ 32const uint8_t ff_log2_run[32]={
33 0, 0, 0, 0, 1, 1, 1, 1, 33 0, 0, 0, 0, 1, 1, 1, 1,
34 2, 2, 2, 2, 3, 3, 3, 3, 34 2, 2, 2, 2, 3, 3, 3, 3,
@@ -46,24 +46,6 @@ const uint8_t ff_log2_run[32]={
46 * and should correctly use static arrays 46 * and should correctly use static arrays
47 */ 47 */
48 48
49#if 0
50attribute_deprecated av_alloc_size(2)
51static void *ff_realloc_static(void *ptr, unsigned int size);
52
53static void *ff_realloc_static(void *ptr, unsigned int size)
54{
55 return av_realloc(ptr, size);
56}
57
58void align_put_bits(PutBitContext *s)
59{
60#ifdef ALT_BITSTREAM_WRITER
61 put_bits(s,( - s->index) & 7,0);
62#else
63 put_bits(s,s->bit_left & 7,0);
64#endif
65}
66#endif
67 49
68void ff_put_string(PutBitContext * pbc, const char *s, int put_zero) 50void ff_put_string(PutBitContext * pbc, const char *s, int put_zero)
69{ 51{
@@ -75,30 +57,6 @@ void ff_put_string(PutBitContext * pbc, const char *s, int put_zero)
75 put_bits(pbc, 8, 0); 57 put_bits(pbc, 8, 0);
76} 58}
77 59
78#if 0
79void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
80{
81 const uint16_t *srcw= (const uint16_t*)src;
82 int words= length>>4;
83 int bits= length&15;
84 int i;
85
86 if(length==0) return;
87
88 if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){
89 for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(&srcw[i]));
90 }else{
91 for(i=0; put_bits_count(pb)&31; i++)
92 put_bits(pb, 8, src[i]);
93 flush_put_bits(pb);
94 memcpy(pbBufPtr(pb), src+i, 2*words-i);
95 skip_put_bytes(pb, 2*words-i);
96 }
97
98 put_bits(pb, bits, AV_RB16(&srcw[words])>>(16-bits));
99}
100#endif
101
102/* VLC decoding */ 60/* VLC decoding */
103 61
104//#define DEBUG_VLC 62//#define DEBUG_VLC
@@ -127,8 +85,7 @@ static int alloc_table(VLC *vlc, int size, int use_static)
127 vlc->table_size += size; 85 vlc->table_size += size;
128 if (vlc->table_size > vlc->table_allocated) { 86 if (vlc->table_size > vlc->table_allocated) {
129 if(use_static>1){ 87 if(use_static>1){
130 printf("init_vlc() used with too little memory : table_size > allocated_memory\n"); 88 DEBUGF("init_vlc() used with too little memory : table_size > allocated_memory\n");
131 abort(); //cant do anything, init_vlc() is used with too little memory
132 } 89 }
133 90
134 if (!vlc->table) 91 if (!vlc->table)
@@ -151,7 +108,7 @@ static int build_table(VLC *vlc, int table_nb_bits,
151 table_size = 1 << table_nb_bits; 108 table_size = 1 << table_nb_bits;
152 table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC)); 109 table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC));
153#ifdef DEBUG_VLC 110#ifdef DEBUG_VLC
154 printf("new table index=%d size=%d code_prefix=%x n=%d\n", 111 DEBUGF("new table index=%d size=%d code_prefix=%x n=%d\n",
155 table_index, table_size, code_prefix, n_prefix); 112 table_index, table_size, code_prefix, n_prefix);
156#endif 113#endif
157 if (table_index < 0) 114 if (table_index < 0)
@@ -175,15 +132,15 @@ static int build_table(VLC *vlc, int table_nb_bits,
175 else 132 else
176 GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size); 133 GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size);
177#if defined(DEBUG_VLC) && 0 134#if defined(DEBUG_VLC) && 0
178 printf("i=%d n=%d code=0x%x\n", i, n, code); 135 DEBUGF("i=%d n=%d code=0x%x\n", i, n, code);
179#endif 136#endif
180 /* if code matches the prefix, it is in the table */ 137 /* if code matches the prefix, it is in the table */
181 n -= n_prefix; 138 n -= n_prefix;
182 if(flags & INIT_VLC_LE) 139 if(flags & INIT_VLC_LE)
183 code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix)-1); 140 code_prefix2= code & (n_prefix>=32 ? (int)0xffffffff : (1 << n_prefix)-1);
184 else 141 else
185 code_prefix2= code >> n; 142 code_prefix2= code >> n;
186 if (n > 0 && code_prefix2 == code_prefix) { 143 if (n > 0 && code_prefix2 == (int)code_prefix) {
187 if (n <= table_nb_bits) { 144 if (n <= table_nb_bits) {
188 /* no need to add another table */ 145 /* no need to add another table */
189 j = (code << (table_nb_bits - n)) & (table_size - 1); 146 j = (code << (table_nb_bits - n)) & (table_size - 1);
@@ -192,11 +149,11 @@ static int build_table(VLC *vlc, int table_nb_bits,
192 if(flags & INIT_VLC_LE) 149 if(flags & INIT_VLC_LE)
193 j = (code >> n_prefix) + (k<<n); 150 j = (code >> n_prefix) + (k<<n);
194#ifdef DEBUG_VLC 151#ifdef DEBUG_VLC
195 printf("%4x: code=%d n=%d\n", 152 DEBUGF("%4x: code=%d n=%d\n",
196 j, i, n); 153 j, i, n);
197#endif 154#endif
198 if (table[j][1] /*bits*/ != 0) { 155 if (table[j][1] /*bits*/ != 0) {
199 printf("incorrect codes\n"); 156 DEBUGF("incorrect codes\n");
200 return -1; 157 return -1;
201 } 158 }
202 table[j][1] = n; //bits 159 table[j][1] = n; //bits
@@ -207,7 +164,7 @@ static int build_table(VLC *vlc, int table_nb_bits,
207 n -= table_nb_bits; 164 n -= table_nb_bits;
208 j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); 165 j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1);
209#ifdef DEBUG_VLC 166#ifdef DEBUG_VLC
210 printf("%4x: n=%d (subtable)\n", 167 DEBUGF("%4x: n=%d (subtable)\n",
211 j, n); 168 j, n);
212#endif 169#endif
213 /* compute table size */ 170 /* compute table size */
@@ -282,7 +239,7 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
282 if(vlc->table_size && vlc->table_size == vlc->table_allocated){ 239 if(vlc->table_size && vlc->table_size == vlc->table_allocated){
283 return 0; 240 return 0;
284 }else if(vlc->table_size){ 241 }else if(vlc->table_size){
285 abort(); // fatal error, we are called on a partially initialized table 242 return -1; // fatal error, we are called on a partially initialized table
286 } 243 }
287 }else if(!(flags & INIT_VLC_USE_STATIC)) { 244 }else if(!(flags & INIT_VLC_USE_STATIC)) {
288 vlc->table = NULL; 245 vlc->table = NULL;
@@ -296,7 +253,7 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
296 } 253 }
297 254
298#ifdef DEBUG_VLC 255#ifdef DEBUG_VLC
299 printf("build table nb_codes=%d\n", nb_codes); 256 DEBUGF("build table nb_codes=%d\n", nb_codes);
300#endif 257#endif
301 258
302 if (build_table(vlc, nb_bits, nb_codes, 259 if (build_table(vlc, nb_bits, nb_codes,
@@ -304,20 +261,16 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
304 codes, codes_wrap, codes_size, 261 codes, codes_wrap, codes_size,
305 symbols, symbols_wrap, symbols_size, 262 symbols, symbols_wrap, symbols_size,
306 0, 0, flags) < 0) { 263 0, 0, flags) < 0) {
307 free(&vlc->table); 264 //free(&vlc->table);
308 return -1; 265 return -1;
309 } 266 }
310 /* Changed the following condition to be true if table_size > table_allocated. * 267 /* Changed the following condition to be true if table_size > table_allocated. *
311 * This would be more sensible for static tables since we want warnings for * 268 * This would be more sensible for static tables since we want warnings for *
312 * memory shortages only. */ 269 * memory shortages only. */
270#ifdef TEST
313 if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size > vlc->table_allocated) 271 if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size > vlc->table_allocated)
314 printf("needed %d had %d\n", vlc->table_size, vlc->table_allocated); 272 DEBUGF("needed %d had %d\n", vlc->table_size, vlc->table_allocated);
273#endif
315 return 0; 274 return 0;
316} 275}
317 276
318
319void free_vlc(VLC *vlc)
320{
321 free(&vlc->table);
322}
323
diff --git a/apps/codecs/libcook/bitstream.h b/apps/codecs/libcook/bitstream.h
index 085d0a1566..9be8e65690 100644
--- a/apps/codecs/libcook/bitstream.h
+++ b/apps/codecs/libcook/bitstream.h
@@ -18,15 +18,10 @@
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 19 */
20 20
21/** 21#ifndef BITSTREAM_H
22 * @file libavcodec/bitstream.h 22#define BITSTREAM_H
23 * bitstream api header.
24 */
25 23
26#ifndef AVCODEC_BITSTREAM_H 24#include <inttypes.h>
27#define AVCODEC_BITSTREAM_H
28
29#include <stdint.h>
30#include <stdlib.h> 25#include <stdlib.h>
31#include <assert.h> 26#include <assert.h>
32#include <string.h> 27#include <string.h>
@@ -51,7 +46,7 @@
51//#define ALT_BITSTREAM_WRITER 46//#define ALT_BITSTREAM_WRITER
52//#define ALIGNED_BITSTREAM_WRITER 47//#define ALIGNED_BITSTREAM_WRITER
53#if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) 48#if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
54# if ARCH_ARM 49# if defined(ARCH_ARM)
55# define A32_BITSTREAM_READER 50# define A32_BITSTREAM_READER
56# else 51# else
57# define ALT_BITSTREAM_READER 52# define ALT_BITSTREAM_READER
@@ -62,7 +57,7 @@
62 57
63extern const uint8_t ff_reverse[256]; 58extern const uint8_t ff_reverse[256];
64 59
65#if ARCH_X86 60#if defined(ARCH_X86)
66// avoid +32 for shift optimization (gcc should do that ...) 61// avoid +32 for shift optimization (gcc should do that ...)
67static inline int32_t NEG_SSR32( int32_t a, int8_t s){ 62static inline int32_t NEG_SSR32( int32_t a, int8_t s){
68 __asm__ ("sarl %1, %0\n\t" 63 __asm__ ("sarl %1, %0\n\t"
@@ -226,7 +221,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value)
226 } else { 221 } else {
227 bit_buf<<=bit_left; 222 bit_buf<<=bit_left;
228 bit_buf |= value >> (n - bit_left); 223 bit_buf |= value >> (n - bit_left);
229#if !HAVE_FAST_UNALIGNED 224#if !defined(HAVE_FAST_UNALIGNED)
230 if (3 & (intptr_t) s->buf_ptr) { 225 if (3 & (intptr_t) s->buf_ptr) {
231 AV_WB32(s->buf_ptr, bit_buf); 226 AV_WB32(s->buf_ptr, bit_buf);
232 } else 227 } else
@@ -736,6 +731,7 @@ static inline unsigned int show_bits_long(GetBitContext *s, int n){
736 } 731 }
737} 732}
738 733
734#if 0
739static inline int check_marker(GetBitContext *s, const char *msg) 735static inline int check_marker(GetBitContext *s, const char *msg)
740{ 736{
741 int bit= get_bits1(s); 737 int bit= get_bits1(s);
@@ -744,6 +740,7 @@ static inline int check_marker(GetBitContext *s, const char *msg)
744 740
745 return bit; 741 return bit;
746} 742}
743#endif
747 744
748/** 745/**
749 * init GetBitContext. 746 * init GetBitContext.
@@ -963,4 +960,4 @@ static inline int decode210(GetBitContext *gb){
963 return 2 - get_bits1(gb); 960 return 2 - get_bits1(gb);
964} 961}
965 962
966#endif /* AVCODEC_BITSTREAM_H */ 963#endif /* BITSTREAM_H */
diff --git a/apps/codecs/libcook/bswap.h b/apps/codecs/libcook/bswap.h
index 443cd1c3f9..b083d10ed0 100644
--- a/apps/codecs/libcook/bswap.h
+++ b/apps/codecs/libcook/bswap.h
@@ -1,86 +1,137 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg 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.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg 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 FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/** 1/**
22 * @file libavutil/bswap.h 2 * @file bswap.h
23 * byte swapping routines 3 * byte swap.
24 */ 4 */
25 5
26#ifndef AVUTIL_BSWAP_H 6#ifndef __BSWAP_H__
27#define AVUTIL_BSWAP_H 7#define __BSWAP_H__
28 8
29#include <stdint.h> 9#ifdef HAVE_BYTESWAP_H
30//#include "ffmpeg_config.h" 10#include <byteswap.h>
31//#include "common.h" 11#else
32
33#if ARCH_ARM
34# include "arm/bswap.h"
35#elif ARCH_BFIN
36# include "bfin/bswap.h"
37#elif ARCH_SH4
38# include "sh4/bswap.h"
39#elif ARCH_X86
40# include "x86/bswap.h"
41#endif
42 12
43#ifndef bswap_16 13#ifdef ROCKBOX
44static inline uint16_t bswap_16(uint16_t x) 14#include "codecs.h"
15
16/* rockbox' optimised inline functions */
17#define bswap_16(x) swap16(x)
18#define bswap_32(x) swap32(x)
19
20static inline uint64_t ByteSwap64(uint64_t x)
45{ 21{
46 x= (x>>8) | (x<<8); 22 union {
47 return x; 23 uint64_t ll;
24 struct {
25 uint32_t l,h;
26 } l;
27 } r;
28 r.l.l = bswap_32 (x);
29 r.l.h = bswap_32 (x>>32);
30 return r.ll;
48} 31}
49#endif 32#define bswap_64(x) ByteSwap64(x)
50 33
51#ifndef bswap_32 34#elif defined(ARCH_X86)
52static inline uint32_t bswap_32(uint32_t x) 35static inline unsigned short ByteSwap16(unsigned short x)
53{ 36{
54 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); 37 __asm("xchgb %b0,%h0" :
55 x= (x>>16) | (x<<16); 38 "=q" (x) :
39 "0" (x));
56 return x; 40 return x;
57} 41}
42#define bswap_16(x) ByteSwap16(x)
43
44static inline unsigned int ByteSwap32(unsigned int x)
45{
46#if __CPU__ > 386
47 __asm("bswap %0":
48 "=r" (x) :
49#else
50 __asm("xchgb %b0,%h0\n"
51 " rorl $16,%0\n"
52 " xchgb %b0,%h0":
53 "=q" (x) :
58#endif 54#endif
55 "0" (x));
56 return x;
57}
58#define bswap_32(x) ByteSwap32(x)
59 59
60#ifndef bswap_64 60static inline unsigned long long int ByteSwap64(unsigned long long int x)
61static inline uint64_t bswap_64(uint64_t x)
62{ 61{
63#if 0 62 register union { __extension__ uint64_t __ll;
64 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); 63 uint32_t __l[2]; } __x;
65 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); 64 asm("xchgl %0,%1":
66 return (x>>32) | (x<<32); 65 "=r"(__x.__l[0]),"=r"(__x.__l[1]):
66 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
67 return __x.__ll;
68}
69#define bswap_64(x) ByteSwap64(x)
70
71#elif defined(ARCH_SH4)
72
73static inline uint16_t ByteSwap16(uint16_t x) {
74 __asm__("swap.b %0,%0":"=r"(x):"0"(x));
75 return x;
76}
77
78static inline uint32_t ByteSwap32(uint32_t x) {
79 __asm__(
80 "swap.b %0,%0\n"
81 "swap.w %0,%0\n"
82 "swap.b %0,%0\n"
83 :"=r"(x):"0"(x));
84 return x;
85}
86
87#define bswap_16(x) ByteSwap16(x)
88#define bswap_32(x) ByteSwap32(x)
89
90static inline uint64_t ByteSwap64(uint64_t x)
91{
92 union {
93 uint64_t ll;
94 struct {
95 uint32_t l,h;
96 } l;
97 } r;
98 r.l.l = bswap_32 (x);
99 r.l.h = bswap_32 (x>>32);
100 return r.ll;
101}
102#define bswap_64(x) ByteSwap64(x)
103
67#else 104#else
68 union { 105
106#define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
107
108
109// code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
110#define bswap_32(x) \
111 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
112 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
113
114static inline uint64_t ByteSwap64(uint64_t x)
115{
116 union {
69 uint64_t ll; 117 uint64_t ll;
70 uint32_t l[2]; 118 uint32_t l[2];
71 } w, r; 119 } w, r;
72 w.ll = x; 120 w.ll = x;
73 r.l[0] = bswap_32 (w.l[1]); 121 r.l[0] = bswap_32 (w.l[1]);
74 r.l[1] = bswap_32 (w.l[0]); 122 r.l[1] = bswap_32 (w.l[0]);
75 return r.ll; 123 return r.ll;
76#endif
77} 124}
78#endif 125#define bswap_64(x) ByteSwap64(x)
126
127#endif /* !ARCH_X86 */
128
129#endif /* !HAVE_BYTESWAP_H */
79 130
80// be2me ... big-endian to machine-endian 131// be2me ... BigEndian to MachineEndian
81// le2me ... little-endian to machine-endian 132// le2me ... LittleEndian to MachineEndian
82 133
83#ifdef WORDS_BIGENDIAN 134#ifdef ROCKBOX_BIG_ENDIAN
84#define be2me_16(x) (x) 135#define be2me_16(x) (x)
85#define be2me_32(x) (x) 136#define be2me_32(x) (x)
86#define be2me_64(x) (x) 137#define be2me_64(x) (x)
@@ -96,4 +147,4 @@ static inline uint64_t bswap_64(uint64_t x)
96#define le2me_64(x) (x) 147#define le2me_64(x) (x)
97#endif 148#endif
98 149
99#endif /* AVUTIL_BSWAP_H */ 150#endif /* __BSWAP_H__ */
diff --git a/apps/codecs/libcook/cook.c b/apps/codecs/libcook/cook.c
index 8caa3992bd..ba5fbab6a1 100644
--- a/apps/codecs/libcook/cook.c
+++ b/apps/codecs/libcook/cook.c
@@ -21,7 +21,7 @@
21 */ 21 */
22 22
23/** 23/**
24 * @file libavcodec/cook.c 24 * @file cook.c
25 * Cook compatible decoder. Bastardization of the G.722.1 standard. 25 * Cook compatible decoder. Bastardization of the G.722.1 standard.
26 * This decoder handles RealNetworks, RealAudio G2 data. 26 * This decoder handles RealNetworks, RealAudio G2 data.
27 * Cook is identified by the codec name cook in RM files. 27 * Cook is identified by the codec name cook in RM files.
@@ -60,16 +60,15 @@
60#define SUBBAND_SIZE 20 60#define SUBBAND_SIZE 20
61#define MAX_SUBPACKETS 5 61#define MAX_SUBPACKETS 5
62//#define COOKDEBUG 62//#define COOKDEBUG
63#if 0 63#ifndef COOKDEBUG
64#define DEBUGF(message,args ...) printf 64#undef DEBUGF
65#else
66#define DEBUGF(...) 65#define DEBUGF(...)
67#endif 66#endif
68 67
69/** 68/**
70 * Random bit stream generator. 69 * Random bit stream generator.
71 */ 70 */
72static int inline cook_random(COOKContext *q) 71static inline int cook_random(COOKContext *q)
73{ 72{
74 q->random_state = 73 q->random_state =
75 q->random_state * 214013 + 2531011; /* typical RNG numbers */ 74 q->random_state * 214013 + 2531011; /* typical RNG numbers */
@@ -200,7 +199,7 @@ static void decode_gain_info(GetBitContext *gb, int *gaininfo)
200 i = 0; 199 i = 0;
201 while (n--) { 200 while (n--) {
202 int index = get_bits(gb, 3); 201 int index = get_bits(gb, 3);
203 int gain = get_bits1(gb) ? get_bits(gb, 4) - 7 : -1; 202 int gain = get_bits1(gb) ? (int)get_bits(gb, 4) - 7 : -1;
204 203
205 while (i <= index) gaininfo[i++] = gain; 204 while (i <= index) gaininfo[i++] = gain;
206 } 205 }
@@ -789,7 +788,7 @@ int cook_decode_init(RMContext *rmctx, COOKContext *q)
789 return -1; 788 return -1;
790 789
791 790
792 if(q->block_align >= UINT_MAX/2) 791 if(rmctx->block_align >= UINT16_MAX/2)
793 return -1; 792 return -1;
794 793
795 q->gains1.now = q->gain_1; 794 q->gains1.now = q->gain_1;
diff --git a/apps/codecs/libcook/cook.h b/apps/codecs/libcook/cook.h
index ca982076ec..03d6d3254c 100644
--- a/apps/codecs/libcook/cook.h
+++ b/apps/codecs/libcook/cook.h
@@ -22,7 +22,7 @@
22#ifndef _COOK_H 22#ifndef _COOK_H
23#define _COOK_H 23#define _COOK_H
24 24
25#include <stdint.h> 25#include <inttypes.h>
26#include "bitstream.h" 26#include "bitstream.h"
27#include "../librm/rm.h" 27#include "../librm/rm.h"
28#include "cookdata_fixpoint.h" 28#include "cookdata_fixpoint.h"
@@ -99,4 +99,4 @@ int cook_decode_init(RMContext *rmctx, COOKContext *q);
99int cook_decode_frame(RMContext *rmctx,COOKContext *q, 99int cook_decode_frame(RMContext *rmctx,COOKContext *q,
100 int16_t *outbuffer, int *data_size, 100 int16_t *outbuffer, int *data_size,
101 const uint8_t *inbuffer, int buf_size); 101 const uint8_t *inbuffer, int buf_size);
102#endif 102#endif /*_COOK_H */
diff --git a/apps/codecs/libcook/cook_fixpoint.h b/apps/codecs/libcook/cook_fixpoint.h
index 0f12b1340a..e416bc4ef5 100644
--- a/apps/codecs/libcook/cook_fixpoint.h
+++ b/apps/codecs/libcook/cook_fixpoint.h
@@ -54,29 +54,6 @@ static const FIXPU* cplscales[5] = {
54}; 54};
55 55
56/** 56/**
57 * Initialise fixed point implementation.
58 * Nothing to do for fixed point.
59 *
60 * @param q pointer to the COOKContext
61 */
62static inline int init_cook_math(COOKContext *q)
63{
64 return 0;
65}
66
67/**
68 * Free resources used by floating point implementation.
69 * Nothing to do for fixed point.
70 *
71 * @param q pointer to the COOKContext
72 */
73static inline void free_cook_math(COOKContext *q)
74{
75 return;
76}
77
78
79/**
80 * Fixed point multiply by power of two. 57 * Fixed point multiply by power of two.
81 * 58 *
82 * @param x fix point value 59 * @param x fix point value
@@ -167,7 +144,7 @@ static void scalar_dequant_math(COOKContext *q, int index,
167 } 144 }
168} 145}
169 146
170 147#ifdef TEST
171/** 148/**
172 * The modulated lapped transform, this takes transform coefficients 149 * The modulated lapped transform, this takes transform coefficients
173 * and transforms them into timedomain samples. 150 * and transforms them into timedomain samples.
@@ -205,7 +182,35 @@ static inline void imlt_math(COOKContext *q, FIXP *in)
205 q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j]); 182 q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j]);
206 } while (++i < n); 183 } while (++i < n);
207} 184}
185#else
186#include <codecs/lib/codeclib.h>
187
188static inline void imlt_math(COOKContext *q, FIXP *in)
189{
190 const int n = q->samples_per_channel;
191 const int step = 4 << (10 - av_log2(n));
192 int i = 0, j = step>>1;
193
194 mdct_backward(2 * n, in, q->mono_mdct_output);
208 195
196 do {
197 FIXP tmp = q->mono_mdct_output[i];
198
199 q->mono_mdct_output[i] =
200 fixp_mult_su(-q->mono_mdct_output[n + i], sincos_lookup[j]);
201 q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j+1]);
202 j += step;
203 } while (++i < n/2);
204 do {
205 FIXP tmp = q->mono_mdct_output[i];
206
207 j -= step;
208 q->mono_mdct_output[i] =
209 fixp_mult_su(-q->mono_mdct_output[n + i], sincos_lookup[j+1]);
210 q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j]);
211 } while (++i < n);
212}
213#endif
209 214
210/** 215/**
211 * Perform buffer overlapping. 216 * Perform buffer overlapping.
diff --git a/apps/codecs/libcook/cookdata_fixpoint.h b/apps/codecs/libcook/cookdata_fixpoint.h
index b394c46a27..7a9440c664 100644
--- a/apps/codecs/libcook/cookdata_fixpoint.h
+++ b/apps/codecs/libcook/cookdata_fixpoint.h
@@ -26,7 +26,7 @@
26 * fixed point data types and constants 26 * fixed point data types and constants
27 */ 27 */
28 28
29#include <stdint.h> 29#include <inttypes.h>
30typedef int32_t FIXP; /* Fixed point variable type */ 30typedef int32_t FIXP; /* Fixed point variable type */
31typedef uint16_t FIXPU; /* Fixed point fraction 0<=x<1 */ 31typedef uint16_t FIXPU; /* Fixed point fraction 0<=x<1 */
32 32
@@ -39,11 +39,11 @@ typedef FIXP REAL_T;
39typedef struct { 39typedef struct {
40} realvars_t; 40} realvars_t;
41 41
42 42#ifdef TEST
43#define cPI1_8 0xec83 /* 1pi/8 2^16 */ 43#define cPI1_8 0xec83 /* 1pi/8 2^16 */
44#define cPI2_8 0xb505 /* 2pi/8 2^16 */ 44#define cPI2_8 0xb505 /* 2pi/8 2^16 */
45#define cPI3_8 0x61f8 /* 3pi/8 2^16 */ 45#define cPI3_8 0x61f8 /* 3pi/8 2^16 */
46 46#endif
47static const FIXPU sincos_lookup[2050] = { 47static const FIXPU sincos_lookup[2050] = {
48 /* x_i = 2^16 sin(i 2pi/8192), 2^16 cos(i 2pi/8192); i=0..1024 */ 48 /* x_i = 2^16 sin(i 2pi/8192), 2^16 cos(i 2pi/8192); i=0..1024 */
49 0x0000, 0xffff, 0x0032, 0xffff, 0x0065, 0xffff, 0x0097, 0xffff, 49 0x0000, 0xffff, 0x0032, 0xffff, 0x0065, 0xffff, 0x0097, 0xffff,
diff --git a/apps/codecs/libcook/libcook.make b/apps/codecs/libcook/libcook.make
new file mode 100644
index 0000000000..07836913d7
--- /dev/null
+++ b/apps/codecs/libcook/libcook.make
@@ -0,0 +1,18 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id:$
8#
9
10# libcook
11COOKLIB := $(CODECDIR)/libcook.a
12COOKLIB_SRC := $(call preprocess, $(APPSDIR)/codecs/libcook/SOURCES)
13COOKLIB_OBJ := $(call c2obj, $(COOKLIB_SRC))
14OTHER_SRC += $(COOKLIB_SRC)
15
16$(COOKLIB): $(COOKLIB_OBJ)
17 $(SILENT)$(shell rm -f $@)
18 $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null \ No newline at end of file
diff --git a/apps/codecs/libcook/main.c b/apps/codecs/libcook/main.c
index 87f65845e8..fd20f98871 100644
--- a/apps/codecs/libcook/main.c
+++ b/apps/codecs/libcook/main.c
@@ -29,13 +29,6 @@
29#include "cook.h" 29#include "cook.h"
30 30
31//#define DUMP_RAW_FRAMES 31//#define DUMP_RAW_FRAMES
32#ifndef DEBUGF
33# if 0
34# define DEBUGF(message,args ...) printf
35# else
36# define DEBUGF(...)
37# endif
38#endif
39 32
40#define DATA_HEADER_SIZE 18 /* size of DATA chunk header in a rm file */ 33#define DATA_HEADER_SIZE 18 /* size of DATA chunk header in a rm file */
41static unsigned char wav_header[44]={ 34static unsigned char wav_header[44]={
@@ -151,8 +144,8 @@ int main(int argc, char *argv[])
151 144
152 /* copy the input rm file to a memory buffer */ 145 /* copy the input rm file to a memory buffer */
153 uint8_t * filebuf = (uint8_t *)calloc((int)filesize(fd),sizeof(uint8_t)); 146 uint8_t * filebuf = (uint8_t *)calloc((int)filesize(fd),sizeof(uint8_t));
154 read(fd,filebuf,filesize(fd)); 147 res = read(fd,filebuf,filesize(fd));
155 148
156 fd_dec = open_wav("output.wav"); 149 fd_dec = open_wav("output.wav");
157 if (fd_dec < 0) { 150 if (fd_dec < 0) {
158 DEBUGF("Error creating output file\n"); 151 DEBUGF("Error creating output file\n");
@@ -166,27 +159,25 @@ int main(int argc, char *argv[])
166 sps= rmctx.block_align; 159 sps= rmctx.block_align;
167 h = rmctx.sub_packet_h; 160 h = rmctx.sub_packet_h;
168 cook_decode_init(&rmctx,&q); 161 cook_decode_init(&rmctx,&q);
169 DEBUGF("nb_frames = %d\n",nb_frames); 162
170
171 /* change the buffer pointer to point at the first audio frame */ 163 /* change the buffer pointer to point at the first audio frame */
172 advance_buffer(&filebuf, rmctx.data_offset+ DATA_HEADER_SIZE); 164 advance_buffer(&filebuf, rmctx.data_offset+ DATA_HEADER_SIZE);
173 while(packet_count) 165 while(packet_count)
174 { 166 {
175 rm_get_packet_membuf(&filebuf, &rmctx, &pkt); 167 rm_get_packet(&filebuf, &rmctx, &pkt);
176 DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx.audio_pkt_cnt*(fs/sps), packet_count,rmctx.audio_pkt_cnt); 168 //DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx.audio_pkt_cnt*(fs/sps), packet_count,rmctx.audio_pkt_cnt);
177 for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) 169 for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++)
178 { 170 {
179 /* output raw audio frames that are sent to the decoder into separate files */ 171 /* output raw audio frames that are sent to the decoder into separate files */
180 #ifdef DUMP_RAW_FRAMES 172#ifdef DUMP_RAW_FRAMES
181 snprintf(filename,sizeof(filename),"dump%d.raw",++x); 173 snprintf(filename,sizeof(filename),"dump%d.raw",++x);
182 fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND); 174 fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND);
183 write(fd_out,pkt.frames[i],sps); 175 write(fd_out,pkt.frames[i],sps);
184 close(fd_out); 176 close(fd_out);
185 #endif 177#endif
186
187 nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i] , rmctx.block_align); 178 nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i] , rmctx.block_align);
188 rmctx.frame_number++; 179 rmctx.frame_number++;
189 write(fd_dec,outbuf,datasize); 180 res = write(fd_dec,outbuf,datasize);
190 } 181 }
191 packet_count -= rmctx.audio_pkt_cnt; 182 packet_count -= rmctx.audio_pkt_cnt;
192 rmctx.audio_pkt_cnt = 0; 183 rmctx.audio_pkt_cnt = 0;