summaryrefslogtreecommitdiff
path: root/apps/codecs
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2007-07-03 09:25:36 +0000
committerDave Chapman <dave@dchapman.com>2007-07-03 09:25:36 +0000
commitc72824786a0e8c68921ebb9b72f02a2e80aaee17 (patch)
treeadf8dac26d074ee3620df4ab482ff108561ead01 /apps/codecs
parent2ca895bae7a25ea8ef7f295b4e8ab01ff75a4914 (diff)
downloadrockbox-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')
-rw-r--r--apps/codecs/Makefile14
-rw-r--r--apps/codecs/SOURCES1
-rw-r--r--apps/codecs/libwma/Makefile43
-rw-r--r--apps/codecs/libwma/SOURCES2
-rw-r--r--apps/codecs/libwma/asf.h24
-rw-r--r--apps/codecs/libwma/avcodec.h58
-rw-r--r--apps/codecs/libwma/bswap.h127
-rw-r--r--apps/codecs/libwma/common.c107
-rw-r--r--apps/codecs/libwma/common.h387
-rw-r--r--apps/codecs/libwma/dsputil.h106
-rw-r--r--apps/codecs/libwma/ffmpeg_config.h18
-rw-r--r--apps/codecs/libwma/wmadata.h1412
-rw-r--r--apps/codecs/libwma/wmadec.h162
-rw-r--r--apps/codecs/libwma/wmadeci.c2592
-rw-r--r--apps/codecs/wma.c385
15 files changed, 5435 insertions, 3 deletions
diff --git a/apps/codecs/Makefile b/apps/codecs/Makefile
index ba54333104..44caacf780 100644
--- a/apps/codecs/Makefile
+++ b/apps/codecs/Makefile
@@ -17,7 +17,7 @@ ifdef APPEXTRA
17endif 17endif
18 18
19ifdef SOFTWARECODECS 19ifdef SOFTWARECODECS
20 CODECLIBS = -lmad -la52 -lffmpegFLAC -lTremor -lwavpack -lmusepack -lalac -lfaad -lm4a -lspeex -ldemac 20 CODECLIBS = -lmad -la52 -lffmpegFLAC -lTremor -lwavpack -lmusepack -lalac -lfaad -lm4a -lspeex -ldemac -lwma
21endif 21endif
22 22
23# we "borrow" the plugin LDS file 23# we "borrow" the plugin LDS file
@@ -39,7 +39,7 @@ DIRS = .
39 39
40CODECDEPS = $(LINKCODEC) $(BUILDDIR)/libcodec.a 40CODECDEPS = $(LINKCODEC) $(BUILDDIR)/libcodec.a
41 41
42.PHONY: libmad liba52 libffmpegFLAC libTremor libspeex libwavpack libmusepack libalac libfaad libm4a libdemac 42.PHONY: libmad liba52 libffmpegFLAC libTremor libspeex libwavpack libmusepack libalac libfaad libm4a libdemac libwma
43 43
44OUTPUT = $(SOFTWARECODECS) 44OUTPUT = $(SOFTWARECODECS)
45 45
@@ -65,6 +65,7 @@ $(OBJDIR)/alac.elf : $(OBJDIR)/alac.o $(BUILDDIR)/libalac.a $(BUILDDIR)/libm4a.a
65$(OBJDIR)/aac.elf : $(OBJDIR)/aac.o $(BUILDDIR)/libfaad.a $(BUILDDIR)/libm4a.a $(OBJDIR)/codec_crt0.o 65$(OBJDIR)/aac.elf : $(OBJDIR)/aac.o $(BUILDDIR)/libfaad.a $(BUILDDIR)/libm4a.a $(OBJDIR)/codec_crt0.o
66$(OBJDIR)/shorten.elf : $(OBJDIR)/shorten.o $(BUILDDIR)/libffmpegFLAC.a $(OBJDIR)/codec_crt0.o 66$(OBJDIR)/shorten.elf : $(OBJDIR)/shorten.o $(BUILDDIR)/libffmpegFLAC.a $(OBJDIR)/codec_crt0.o
67$(OBJDIR)/ape.elf : $(OBJDIR)/ape.o $(BUILDDIR)/libdemac.a $(OBJDIR)/codec_crt0.o 67$(OBJDIR)/ape.elf : $(OBJDIR)/ape.o $(BUILDDIR)/libdemac.a $(OBJDIR)/codec_crt0.o
68$(OBJDIR)/wma.elf : $(OBJDIR)/wma.o $(BUILDDIR)/libwma.a $(OBJDIR)/codec_crt0.o
68$(OBJDIR)/aiff_enc.elf: $(OBJDIR)/aiff_enc.o $(OBJDIR)/codec_crt0.o 69$(OBJDIR)/aiff_enc.elf: $(OBJDIR)/aiff_enc.o $(OBJDIR)/codec_crt0.o
69$(OBJDIR)/mp3_enc.elf: $(OBJDIR)/mp3_enc.o $(OBJDIR)/codec_crt0.o 70$(OBJDIR)/mp3_enc.elf: $(OBJDIR)/mp3_enc.o $(OBJDIR)/codec_crt0.o
70$(OBJDIR)/wav_enc.elf: $(OBJDIR)/wav_enc.o $(OBJDIR)/codec_crt0.o 71$(OBJDIR)/wav_enc.elf: $(OBJDIR)/wav_enc.o $(OBJDIR)/codec_crt0.o
@@ -151,6 +152,12 @@ liba52:
151 $(SILENT)mkdir -p $(OBJDIR)/liba52 152 $(SILENT)mkdir -p $(OBJDIR)/liba52
152 $(call PRINTS,MAKE in liba52)$(MAKE) -C liba52 OBJDIR=$(OBJDIR)/liba52 OUTPUT=$(BUILDDIR)/liba52.a 153 $(call PRINTS,MAKE in liba52)$(MAKE) -C liba52 OBJDIR=$(OBJDIR)/liba52 OUTPUT=$(BUILDDIR)/liba52.a
153 154
155$(BUILDDIR)/libwma.a: libwma
156
157libwma:
158 $(SILENT)mkdir -p $(OBJDIR)/libwma
159 $(call PRINTS,MAKE in libwma)$(MAKE) -C libwma OBJDIR=$(OBJDIR)/libwma OUTPUT=$(BUILDDIR)/libwma.a
160
154$(BUILDDIR)/libffmpegFLAC.a: libffmpegFLAC 161$(BUILDDIR)/libffmpegFLAC.a: libffmpegFLAC
155 162
156libffmpegFLAC: 163libffmpegFLAC:
@@ -206,7 +213,7 @@ libdemac:
206 $(call PRINTS,MAKE in libdemac)$(MAKE) -C demac/libdemac OBJDIR=$(OBJDIR)/libdemac OUTPUT=$(BUILDDIR)/libdemac.a 213 $(call PRINTS,MAKE in libdemac)$(MAKE) -C demac/libdemac OBJDIR=$(OBJDIR)/libdemac OUTPUT=$(BUILDDIR)/libdemac.a
207 214
208clean: 215clean:
209 $(call PRINTS,cleaning codecs)rm -fr $(OBJDIR)/libmad $(BUILDDIR)/libmad.a $(OBJDIR)/liba52 $(BUILDDIR)/liba52.a $(OBJDIR)/libffmpegFLAC $(BUILDDIR)/libffmpegFLAC.a $(OBJDIR)/Tremor $(BUILDDIR)/libTremor.a $(OBJDIR)/libspeex $(BUILDDIR)/libSpeex.a $(OBJDIR)/libwavpack $(BUILDDIR)/libwavpack.a $(OBJDIR)/libmusepack $(BUILDDIR)/libmusepack.a $(OBJDIR)/libalac $(BUILDDIR)/libalac.a $(OBJDIR)/libfaad $(BUILDDIR)/libfaad.a $(OBJDIR)/libm4a $(BUILDDIR)/libm4a.a $(OBJDIR)/libdemac $(BUILDDIR)/libdemac.a 216 $(call PRINTS,cleaning codecs)rm -fr $(OBJDIR)/libmad $(BUILDDIR)/libmad.a $(OBJDIR)/liba52 $(BUILDDIR)/liba52.a $(OBJDIR)/libffmpegFLAC $(BUILDDIR)/libffmpegFLAC.a $(OBJDIR)/Tremor $(BUILDDIR)/libTremor.a $(OBJDIR)/libspeex $(BUILDDIR)/libSpeex.a $(OBJDIR)/libwavpack $(BUILDDIR)/libwavpack.a $(OBJDIR)/libmusepack $(BUILDDIR)/libmusepack.a $(OBJDIR)/libalac $(BUILDDIR)/libalac.a $(OBJDIR)/libfaad $(BUILDDIR)/libfaad.a $(OBJDIR)/libm4a $(BUILDDIR)/libm4a.a $(OBJDIR)/libdemac $(BUILDDIR)/libdemac.a $(OBJDIR)/libwma $(BUILDDIR)/libwma.a
210 $(SILENT)$(MAKE) -C libmad clean OBJDIR=$(OBJDIR)/libmad 217 $(SILENT)$(MAKE) -C libmad clean OBJDIR=$(OBJDIR)/libmad
211 $(SILENT)$(MAKE) -C liba52 clean OBJDIR=$(OBJDIR)/liba52 218 $(SILENT)$(MAKE) -C liba52 clean OBJDIR=$(OBJDIR)/liba52
212 $(SILENT)$(MAKE) -C libffmpegFLAC clean OBJDIR=$(OBJDIR)/libffmpegFLAC 219 $(SILENT)$(MAKE) -C libffmpegFLAC clean OBJDIR=$(OBJDIR)/libffmpegFLAC
@@ -218,6 +225,7 @@ clean:
218 $(SILENT)$(MAKE) -C libfaad clean OBJDIR=$(OBJDIR)/libfaad 225 $(SILENT)$(MAKE) -C libfaad clean OBJDIR=$(OBJDIR)/libfaad
219 $(SILENT)$(MAKE) -C libm4a clean OBJDIR=$(OBJDIR)/libm4a 226 $(SILENT)$(MAKE) -C libm4a clean OBJDIR=$(OBJDIR)/libm4a
220 $(SILENT)$(MAKE) -C demac/libdemac clean OBJDIR=$(OBJDIR)/libdemac 227 $(SILENT)$(MAKE) -C demac/libdemac clean OBJDIR=$(OBJDIR)/libdemac
228 $(SILENT)$(MAKE) -C libwma clean OBJDIR=$(OBJDIR)/libwma
221 $(SILENT)$(MAKE) -C lib clean OBJDIR=$(OBJDIR)/lib 229 $(SILENT)$(MAKE) -C lib clean OBJDIR=$(OBJDIR)/lib
222 230
223ifneq ($(MAKECMDGOALS),clean) 231ifneq ($(MAKECMDGOALS),clean)
diff --git a/apps/codecs/SOURCES b/apps/codecs/SOURCES
index 7a3d4055cc..a93cb6c0cc 100644
--- a/apps/codecs/SOURCES
+++ b/apps/codecs/SOURCES
@@ -8,6 +8,7 @@ a52.c
8mpc.c 8mpc.c
9wavpack.c 9wavpack.c
10alac.c 10alac.c
11wma.c
11#if MEMORYSIZE > 1 12#if MEMORYSIZE > 1
12aac.c 13aac.c
13#endif 14#endif
diff --git a/apps/codecs/libwma/Makefile b/apps/codecs/libwma/Makefile
new file mode 100644
index 0000000000..fc1cd6f690
--- /dev/null
+++ b/apps/codecs/libwma/Makefile
@@ -0,0 +1,43 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id: Makefile 11401 2006-10-30 18:14:12Z learman $
8#
9
10INCLUDES=-I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
11 -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(BUILDDIR)
12
13ifdef APPEXTRA
14 INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA)))
15endif
16
17WMAOPTS = -O2
18CFLAGS = $(INCLUDES) $(GCCOPTS) $(TARGET_INC) $(WMAOPTS) $(TARGET) \
19$(EXTRA_DEFINES) -DMEM=${MEMORYSIZE} $(PROFILE_OPTS) -DCODEC=1
20
21# This sets up 'SRC' based on the files mentioned in SOURCES
22include $(TOOLSDIR)/makesrc.inc
23
24SOURCES = $(SRC)
25OBJS2 := $(SRC:%.c=$(OBJDIR)/%.o)
26OBJS = $(patsubst %.S, $(OBJDIR)/%.o, $(OBJS2))
27DEPFILE = $(OBJDIR)/dep-libwma
28DIRS =
29
30all: $(OUTPUT)
31
32$(OUTPUT): $(OBJS)
33 $(call PRINTS,AR+RANLIB $(@F))$(AR) ruv $@ $+ >/dev/null 2>&1
34 $(SILENT)$(RANLIB) $@
35
36include $(TOOLSDIR)/make.inc
37
38clean:
39 $(call PRINTS,cleaning libwma)rm -f $(OBJS) $(OUTPUT) $(DEPFILE)
40
41ifneq ($(MAKECMDGOALS),clean)
42-include $(DEPFILE)
43endif
diff --git a/apps/codecs/libwma/SOURCES b/apps/codecs/libwma/SOURCES
new file mode 100644
index 0000000000..3351bb27b8
--- /dev/null
+++ b/apps/codecs/libwma/SOURCES
@@ -0,0 +1,2 @@
1wmadeci.c
2common.c
diff --git a/apps/codecs/libwma/asf.h b/apps/codecs/libwma/asf.h
new file mode 100644
index 0000000000..8cae8fae1d
--- /dev/null
+++ b/apps/codecs/libwma/asf.h
@@ -0,0 +1,24 @@
1#ifndef _ASF_H
2#define _ASF_H
3
4#include <inttypes.h>
5
6/* ASF codec IDs */
7#define ASF_CODEC_ID_WMAV1 0x160
8#define ASF_CODEC_ID_WMAV2 0x161
9
10struct asf_waveformatex_s {
11 uint32_t packet_size;
12 int audiostream;
13 uint16_t codec_id;
14 uint16_t channels;
15 uint32_t rate;
16 uint32_t bitrate;
17 uint16_t blockalign;
18 uint16_t bitspersample;
19 uint16_t datalen;
20 uint8_t data[6];
21};
22typedef struct asf_waveformatex_s asf_waveformatex_t;
23
24#endif
diff --git a/apps/codecs/libwma/avcodec.h b/apps/codecs/libwma/avcodec.h
new file mode 100644
index 0000000000..3ddc2d6770
--- /dev/null
+++ b/apps/codecs/libwma/avcodec.h
@@ -0,0 +1,58 @@
1#ifndef AVCODEC_H
2#define AVCODEC_H
3
4/**
5 * @file avcodec.h
6 * external api header.
7 */
8
9#include "common.h"
10#include <sys/types.h> /* size_t */
11
12/**
13 * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
14 * this is mainly needed because some optimized bitstream readers read
15 * 32 or 64 bit at once and could read over the end<br>
16 * Note, if the first 23 bits of the additional bytes are not 0 then damaged
17 * MPEG bitstreams could cause overread and segfault
18 */
19#define FF_INPUT_BUFFER_PADDING_SIZE 8
20
21/* memory */
22void *av_malloc(unsigned int size);
23void *av_mallocz(unsigned int size);
24void *av_realloc(void *ptr, unsigned int size);
25void av_free(void *ptr);
26char *av_strdup(const char *s);
27void __av_freep(void **ptr);
28#define av_freep(p) __av_freep((void **)(p))
29void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
30/* for static data only */
31/* call av_free_static to release all staticaly allocated tables */
32void av_free_static(void);
33void *__av_mallocz_static(void** location, unsigned int size);
34#define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
35
36/* av_log API */
37
38#include <stdarg.h>
39
40#define AV_LOG_ERROR 0
41#define AV_LOG_INFO 1
42#define AV_LOG_DEBUG 2
43
44extern void av_log(int level, const char *fmt, ...);
45extern void av_vlog(int level, const char *fmt, va_list);
46extern int av_log_get_level(void);
47extern void av_log_set_level(int);
48extern void av_log_set_callback(void (*)(int, const char*, va_list));
49
50#undef AV_LOG_TRAP_PRINTF
51#ifdef AV_LOG_TRAP_PRINTF
52#define printf DO NOT USE
53#define fprintf DO NOT USE
54#undef stderr
55#define stderr DO NOT USE
56#endif
57
58#endif /* AVCODEC_H */
diff --git a/apps/codecs/libwma/bswap.h b/apps/codecs/libwma/bswap.h
new file mode 100644
index 0000000000..cacaac488d
--- /dev/null
+++ b/apps/codecs/libwma/bswap.h
@@ -0,0 +1,127 @@
1/**
2 * @file bswap.h
3 * byte swap.
4 */
5
6#ifndef __BSWAP_H__
7#define __BSWAP_H__
8
9#include <config.h>
10
11#ifdef ARCH_X86
12static inline unsigned short ByteSwap16(unsigned short x)
13{
14 __asm("xchgb %b0,%h0" :
15 "=q" (x) :
16 "0" (x));
17 return x;
18}
19#define bswap_16(x) ByteSwap16(x)
20
21static inline unsigned int ByteSwap32(unsigned int x)
22{
23#if __CPU__ > 386
24 __asm("bswap %0":
25 "=r" (x) :
26#else
27 __asm("xchgb %b0,%h0\n"
28 " rorl $16,%0\n"
29 " xchgb %b0,%h0":
30 "=q" (x) :
31#endif
32 "0" (x));
33 return x;
34}
35#define bswap_32(x) ByteSwap32(x)
36
37static inline unsigned long long int ByteSwap64(unsigned long long int x)
38{
39 register union { __extension__ uint64_t __ll;
40 uint32_t __l[2]; } __x;
41 asm("xchgl %0,%1":
42 "=r"(__x.__l[0]),"=r"(__x.__l[1]):
43 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
44 return __x.__ll;
45}
46#define bswap_64(x) ByteSwap64(x)
47
48#elif defined(ARCH_SH4)
49
50static inline uint16_t ByteSwap16(uint16_t x) {
51 __asm__("swap.b %0,%0":"=r"(x):"0"(x));
52 return x;
53}
54
55static inline uint32_t ByteSwap32(uint32_t x) {
56 __asm__(
57 "swap.b %0,%0\n"
58 "swap.w %0,%0\n"
59 "swap.b %0,%0\n"
60 :"=r"(x):"0"(x));
61 return x;
62}
63
64#define bswap_16(x) ByteSwap16(x)
65#define bswap_32(x) ByteSwap32(x)
66
67static inline uint64_t ByteSwap64(uint64_t x)
68{
69 union {
70 uint64_t ll;
71 struct {
72 uint32_t l,h;
73 } l;
74 } r;
75 r.l.l = bswap_32 (x);
76 r.l.h = bswap_32 (x>>32);
77 return r.ll;
78}
79#define bswap_64(x) ByteSwap64(x)
80
81#else
82
83#define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
84
85
86// code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
87#define bswap_32(x) \
88 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
89 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
90
91static inline uint64_t ByteSwap64(uint64_t x)
92{
93 union {
94 uint64_t ll;
95 uint32_t l[2];
96 } w, r;
97 w.ll = x;
98 r.l[0] = bswap_32 (w.l[1]);
99 r.l[1] = bswap_32 (w.l[0]);
100 return r.ll;
101}
102#define bswap_64(x) ByteSwap64(x)
103
104#endif /* !ARCH_X86 */
105
106#endif /* !HAVE_BYTESWAP_H */
107
108// be2me ... BigEndian to MachineEndian
109// le2me ... LittleEndian to MachineEndian
110
111#ifdef ROCKBOX_BIG_ENDIAN
112#define be2me_16(x) (x)
113#define be2me_32(x) (x)
114#define be2me_64(x) (x)
115#define le2me_16(x) bswap_16(x)
116#define le2me_32(x) bswap_32(x)
117#define le2me_64(x) bswap_64(x)
118#else
119#define be2me_16(x) bswap_16(x)
120#define be2me_32(x) bswap_32(x)
121#define be2me_64(x) bswap_64(x)
122#define le2me_16(x) (x)
123#define le2me_32(x) (x)
124#define le2me_64(x) (x)
125#endif
126
127#endif /* __BSWAP_H__ */
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
30const 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
37const 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 */
54void 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 */
74unsigned 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 */
85unsigned 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
95void align_get_bits(GetBitContext *s)
96{
97 int n= (-get_bits_count(s)) & 7;
98 if(n) skip_bits(s, n);
99}
100
101int check_marker(GetBitContext *s, const char *msg)
102{
103 (void)msg;
104 int bit= get_bits1(s);
105 return bit;
106}
107
diff --git a/apps/codecs/libwma/common.h b/apps/codecs/libwma/common.h
new file mode 100644
index 0000000000..dc55dcaed2
--- /dev/null
+++ b/apps/codecs/libwma/common.h
@@ -0,0 +1,387 @@
1/**
2 * @file common.h
3 * common internal api header.
4 */
5
6#ifndef COMMON_H
7#define COMMON_H
8
9/* only include the following when compiling package */
10#include "ffmpeg_config.h"
11
12#include <stdlib.h>
13#include <stdio.h>
14#include <string.h>
15#include <ctype.h>
16#include <math.h>
17#include <stddef.h>
18#include <inttypes.h>
19
20#ifndef M_PI
21#define M_PI 3.14159265358979323846
22#endif
23
24#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
25# define always_inline __attribute__((always_inline)) inline
26#else
27# define always_inline inline
28#endif
29
30#ifndef INT64_MAX
31#define INT64_MAX 9223372036854775807LL
32#endif
33
34# if defined(__MINGW32__) || defined(__CYGWIN__) || \
35 defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
36# define MANGLE(a) "_" #a
37# else
38# define MANGLE(a) #a
39# endif
40
41/* debug stuff */
42
43# ifndef DEBUG
44# define NDEBUG
45# endif
46# include <assert.h>
47
48/* dprintf macros */
49# if defined(CONFIG_WIN32) && !defined(__MINGW32__)
50
51inline void dprintf(const char* fmt,...) {}
52
53# else
54
55# ifdef DEBUG
56# define dprintf(fmt,...) printf(fmt, __VA_ARGS__)
57# else
58# define dprintf(fmt,...)
59# endif
60
61# endif /* !CONFIG_WIN32 */
62
63# define av_abort() do { av_log(AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
64
65//rounded divison & shift
66#define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b))
67/* assume b>0 */
68#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
69
70extern const uint32_t inverse[256];
71
72#define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
73#define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
74
75/* bit input */
76
77typedef struct GetBitContext {
78 const uint8_t *buffer, *buffer_end;
79 int index;
80 int size_in_bits;
81} GetBitContext;
82
83static inline int get_bits_count(GetBitContext *s);
84
85/* used to avoid missaligned exceptions on some archs (alpha, ...) */
86static inline uint32_t unaligned32(const void *v) {
87 struct Unaligned {
88 uint32_t i;
89 } __attribute__((packed));
90
91 return ((const struct Unaligned *) v)->i;
92}
93
94
95/* Bitstream reader API docs:
96name
97 abritary name which is used as prefix for the internal variables
98
99gb
100 getbitcontext
101
102OPEN_READER(name, gb)
103 loads gb into local variables
104
105CLOSE_READER(name, gb)
106 stores local vars in gb
107
108UPDATE_CACHE(name, gb)
109 refills the internal cache from the bitstream
110 after this call at least MIN_CACHE_BITS will be available,
111
112GET_CACHE(name, gb)
113 will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
114
115SHOW_UBITS(name, gb, num)
116 will return the nest num bits
117
118SHOW_SBITS(name, gb, num)
119 will return the nest num bits and do sign extension
120
121SKIP_BITS(name, gb, num)
122 will skip over the next num bits
123 note, this is equinvalent to SKIP_CACHE; SKIP_COUNTER
124
125SKIP_CACHE(name, gb, num)
126 will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
127
128SKIP_COUNTER(name, gb, num)
129 will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
130
131LAST_SKIP_CACHE(name, gb, num)
132 will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
133
134LAST_SKIP_BITS(name, gb, num)
135 is equinvalent to SKIP_LAST_CACHE; SKIP_COUNTER
136
137for examples see get_bits, show_bits, skip_bits, get_vlc
138*/
139
140static inline int unaligned32_be(const void *v)
141{
142#ifdef CONFIG_ALIGN
143 const uint8_t *p=v;
144 return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]);
145#else
146 return be2me_32( unaligned32(v)); //original
147#endif
148}
149
150#define MIN_CACHE_BITS 25
151
152#define OPEN_READER(name, gb)\
153 int name##_index= (gb)->index;\
154 int name##_cache= 0;\
155
156#define CLOSE_READER(name, gb)\
157 (gb)->index= name##_index;\
158
159#define UPDATE_CACHE(name, gb)\
160 name##_cache= unaligned32_be( ((uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
161
162#define SKIP_CACHE(name, gb, num)\
163 name##_cache <<= (num);\
164
165// FIXME name?
166#define SKIP_COUNTER(name, gb, num)\
167 name##_index += (num);\
168
169#define SKIP_BITS(name, gb, num)\
170 {\
171 SKIP_CACHE(name, gb, num)\
172 SKIP_COUNTER(name, gb, num)\
173 }\
174
175#define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
176#define LAST_SKIP_CACHE(name, gb, num) ;
177
178#define SHOW_UBITS(name, gb, num)\
179 NEG_USR32(name##_cache, num)
180
181#define SHOW_SBITS(name, gb, num)\
182 NEG_SSR32(name##_cache, num)
183
184#define GET_CACHE(name, gb)\
185 ((uint32_t)name##_cache)
186
187static inline int get_bits_count(GetBitContext *s){
188 return s->index;
189}
190
191/**
192 * reads 0-17 bits.
193 * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
194 */
195static inline unsigned int get_bits(GetBitContext *s, int n){
196 register int tmp;
197 OPEN_READER(re, s)
198 UPDATE_CACHE(re, s)
199 tmp= SHOW_UBITS(re, s, n);
200 LAST_SKIP_BITS(re, s, n)
201 CLOSE_READER(re, s)
202 return tmp;
203}
204
205unsigned int get_bits_long(GetBitContext *s, int n);
206
207/**
208 * shows 0-17 bits.
209 * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
210 */
211static inline unsigned int show_bits(GetBitContext *s, int n){
212 register int tmp;
213 OPEN_READER(re, s)
214 UPDATE_CACHE(re, s)
215 tmp= SHOW_UBITS(re, s, n);
216// CLOSE_READER(re, s)
217 return tmp;
218}
219
220unsigned int show_bits_long(GetBitContext *s, int n);
221
222static inline void skip_bits(GetBitContext *s, int n){
223 //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
224 OPEN_READER(re, s)
225 UPDATE_CACHE(re, s)
226 LAST_SKIP_BITS(re, s, n)
227 CLOSE_READER(re, s)
228}
229
230static inline unsigned int get_bits1(GetBitContext *s){
231 int index= s->index;
232 uint8_t result= s->buffer[ index>>3 ];
233 result<<= (index&0x07);
234 result>>= 8 - 1;
235 index++;
236 s->index= index;
237
238 return result;
239}
240
241static inline unsigned int show_bits1(GetBitContext *s){
242 return show_bits(s, 1);
243}
244
245static inline void skip_bits1(GetBitContext *s){
246 skip_bits(s, 1);
247}
248
249void init_get_bits(GetBitContext *s,
250 const uint8_t *buffer, int buffer_size);
251
252int check_marker(GetBitContext *s, const char *msg);
253void align_get_bits(GetBitContext *s);
254
255//#define TRACE
256
257#ifdef TRACE
258
259static inline void print_bin(int bits, int n){
260 int i;
261
262 for(i=n-1; i>=0; i--){
263 printf("%d", (bits>>i)&1);
264 }
265 for(i=n; i<24; i++)
266 printf(" ");
267}
268
269static inline int get_bits_trace(GetBitContext *s, int n, char *file, char *func, int line){
270 int r= get_bits(s, n);
271
272 print_bin(r, n);
273 printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
274 return r;
275}
276static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, char *func, int line){
277 int show= show_bits(s, 24);
278 int pos= get_bits_count(s);
279 int r= get_vlc2(s, table, bits, max_depth);
280 int len= get_bits_count(s) - pos;
281 int bits2= show>>(24-len);
282
283 print_bin(bits2, len);
284
285 printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
286 return r;
287}
288static inline int get_xbits_trace(GetBitContext *s, int n, char *file, char *func, int line){
289 int show= show_bits(s, n);
290 int r= get_xbits(s, n);
291
292 print_bin(show, n);
293 printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
294 return r;
295}
296
297#define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
298#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
299#define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
300#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
301#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
302
303#define tprintf printf
304
305#else //TRACE
306#define tprintf(_arg...) {}
307#endif
308
309/* define it to include statistics code (useful only for optimizing
310 codec efficiency */
311//#define STATS
312
313#ifdef STATS
314
315enum {
316 ST_UNKNOWN,
317 ST_DC,
318 ST_INTRA_AC,
319 ST_INTER_AC,
320 ST_INTRA_MB,
321 ST_INTER_MB,
322 ST_MV,
323 ST_NB,
324};
325
326extern int st_current_index;
327extern unsigned int st_bit_counts[ST_NB];
328extern unsigned int st_out_bit_counts[ST_NB];
329
330void print_stats(void);
331#endif
332
333/* misc math functions */
334extern const uint8_t ff_log2_tab[256];
335
336static inline int av_log2(unsigned int v)
337{
338 int n;
339
340 n = 0;
341 if (v & 0xffff0000) {
342 v >>= 16;
343 n += 16;
344 }
345 if (v & 0xff00) {
346 v >>= 8;
347 n += 8;
348 }
349 n += ff_log2_tab[v];
350
351 return n;
352}
353
354static inline int clip(int a, int amin, int amax)
355{
356 if (a < amin)
357 return amin;
358 else if (a > amax)
359 return amax;
360 else
361 return a;
362}
363
364/* math */
365extern const uint8_t ff_sqrt_tab[128];
366
367int64_t ff_gcd(int64_t a, int64_t b);
368
369static inline int ff_sqrt(int a)
370{
371 int ret=0;
372 int s;
373 int ret_sq=0;
374
375 if(a<128) return ff_sqrt_tab[a];
376
377 for(s=15; s>=0; s--){
378 int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
379 if(b<=a){
380 ret_sq=b;
381 ret+= 1<<s;
382 }
383 }
384 return ret;
385}
386
387#endif /* COMMON_H */
diff --git a/apps/codecs/libwma/dsputil.h b/apps/codecs/libwma/dsputil.h
new file mode 100644
index 0000000000..a5b2af3039
--- /dev/null
+++ b/apps/codecs/libwma/dsputil.h
@@ -0,0 +1,106 @@
1/*
2 * DSP utils
3 * Copyright (c) 2000, 2001, 2002 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
21/**
22 * @file dsputil.h
23 * DSP utils.
24 * note, many functions in here may use MMX which trashes the FPU state, it is
25 * absolutely necessary to call emms_c() between dsp & float/double code
26 */
27
28#ifndef DSPUTIL_H
29#define DSPUTIL_H
30
31#include "common.h"
32
33//#define DEBUG
34
35void dsputil_static_init(void);
36
37/* FFT computation */
38
39/* NOTE: soon integer code will be added, so you must use the
40 FFTSample type */
41typedef float FFTSample;
42
43typedef struct FFTComplex {
44 FFTSample re, im;
45} FFTComplex;
46
47typedef struct FFTContext {
48 int nbits;
49 int inverse;
50 uint16_t *revtab;
51 FFTComplex *exptab;
52 FFTComplex *exptab1; /* only used by SSE code */
53 void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
54} FFTContext;
55
56int fft_inits(FFTContext *s, int nbits, int inverse);
57void fft_permute(FFTContext *s, FFTComplex *z);
58void fft_calc_c(FFTContext *s, FFTComplex *z);
59void fft_calc_sse(FFTContext *s, FFTComplex *z);
60void fft_calc_altivec(FFTContext *s, FFTComplex *z);
61
62static inline void fft_calc(FFTContext *s, FFTComplex *z)
63{
64 s->fft_calc(s, z);
65}
66void fft_end(FFTContext *s);
67
68/* MDCT computation */
69
70typedef struct MDCTContext {
71 int n; /* size of MDCT (i.e. number of input data * 2) */
72 int nbits; /* n = 2^nbits */
73 /* pre/post rotation tables */
74 FFTSample *tcos;
75 FFTSample *tsin;
76 FFTContext fft;
77} MDCTContext;
78
79int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
80void ff_imdct_calc(MDCTContext *s, FFTSample *output,
81 const FFTSample *input, FFTSample *tmp);
82void ff_mdct_calc(MDCTContext *s, FFTSample *out,
83 const FFTSample *input, FFTSample *tmp);
84void ff_mdct_end(MDCTContext *s);
85
86#define WARPER8_16(name8, name16)\
87static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
88 return name8(s, dst , src , stride, h)\
89 +name8(s, dst+8 , src+8 , stride, h);\
90}
91
92#define WARPER8_16_SQ(name8, name16)\
93static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
94 int score=0;\
95 score +=name8(s, dst , src , stride, 8);\
96 score +=name8(s, dst+8 , src+8 , stride, 8);\
97 if(h==16){\
98 dst += 8*stride;\
99 src += 8*stride;\
100 score +=name8(s, dst , src , stride, 8);\
101 score +=name8(s, dst+8 , src+8 , stride, 8);\
102 }\
103 return score;\
104}
105
106#endif
diff --git a/apps/codecs/libwma/ffmpeg_config.h b/apps/codecs/libwma/ffmpeg_config.h
new file mode 100644
index 0000000000..4b5f4f7fa6
--- /dev/null
+++ b/apps/codecs/libwma/ffmpeg_config.h
@@ -0,0 +1,18 @@
1/* Automatically generated by configure - do not modify */
2#ifndef _CONFIG_H
3#define _CONFIG_H
4
5#define CONFIG_ALIGN 1
6
7#define ARCH_X86 1
8#undef HAVE_MMX
9#define __CPU__ 586
10#define HAVE_BUILTIN_VECTOR 1
11#define HAVE_LOCALTIME_R 1
12#define HAVE_LRINTF 1
13#undef HAVE_VHOOK
14#define HAVE_MALLOC_H 1
15#define HAVE_MEMALIGN 1
16#define SIMPLE_IDCT 1
17
18#endif
diff --git a/apps/codecs/libwma/wmadata.h b/apps/codecs/libwma/wmadata.h
new file mode 100644
index 0000000000..ee17207102
--- /dev/null
+++ b/apps/codecs/libwma/wmadata.h
@@ -0,0 +1,1412 @@
1/**
2 * @file wmadata.h
3 * Various WMA tables.
4 */
5
6static const uint16_t wma_critical_freqs[25] = {
7 100, 200, 300, 400, 510, 630, 770, 920,
8 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150,
9 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500,
10 24500,
11};
12
13/* first value is number of bands */
14static const uint8_t exponent_band_22050[3][25] = {
15 { 10, 4, 8, 4, 8, 8, 12, 20, 24, 24, 16, },
16 { 14, 4, 8, 8, 4, 12, 12, 16, 24, 16, 20, 24, 32, 40, 36, },
17 { 23, 4, 4, 4, 8, 4, 4, 8, 8, 8, 8, 8, 12, 12, 16, 16, 24, 24, 32, 44, 48, 60, 84, 72, },
18};
19
20static const uint8_t exponent_band_32000[3][25] = {
21 { 11, 4, 4, 8, 4, 4, 12, 16, 24, 20, 28, 4, },
22 { 15, 4, 8, 4, 4, 8, 8, 16, 20, 12, 20, 20, 28, 40, 56, 8, },
23 { 16, 8, 4, 8, 8, 12, 16, 20, 24, 40, 32, 32, 44, 56, 80, 112, 16, },
24};
25
26static const uint8_t exponent_band_44100[3][25] = {
27 { 12, 4, 4, 4, 4, 4, 8, 8, 8, 12, 16, 20, 36, },
28 { 15, 4, 8, 4, 8, 8, 4, 8, 8, 12, 12, 12, 24, 28, 40, 76, },
29 { 17, 4, 8, 8, 4, 12, 12, 8, 8, 24, 16, 20, 24, 32, 40, 60, 80, 152, },
30};
31
32static const uint16_t hgain_huffcodes[37] = {
33 0x00003, 0x002e7, 0x00001, 0x005cd, 0x0005d, 0x005c9, 0x0005e, 0x00003,
34 0x00016, 0x0000b, 0x00001, 0x00006, 0x00001, 0x00006, 0x00004, 0x00005,
35 0x00004, 0x00007, 0x00003, 0x00007, 0x00004, 0x0000a, 0x0000a, 0x00002,
36 0x00003, 0x00000, 0x00005, 0x00002, 0x0005f, 0x00004, 0x00003, 0x00002,
37 0x005c8, 0x000b8, 0x005ca, 0x005cb, 0x005cc,
38};
39
40static const uint8_t hgain_huffbits[37] = {
41 10, 12, 10, 13, 9, 13, 9, 8,
42 7, 5, 5, 4, 4, 3, 3, 3,
43 4, 3, 4, 4, 5, 5, 6, 8,
44 7, 10, 8, 10, 9, 8, 9, 9,
45 13, 10, 13, 13, 13,
46};
47
48static const float lsp_codebook[NB_LSP_COEFS][16] = {
49 { 1.98732877, 1.97944528, 1.97179088, 1.96260549, 1.95038374, 1.93336114, 1.90719232, 1.86191415, },
50 { 1.97260000, 1.96083160, 1.94982586, 1.93806164, 1.92516608, 1.91010199, 1.89232331, 1.87149812,
51 1.84564818, 1.81358067, 1.77620070, 1.73265264, 1.67907855, 1.60959081, 1.50829650, 1.33120330, },
52 { 1.90109110, 1.86482426, 1.83419671, 1.80168452, 1.76650116, 1.72816320, 1.68502700, 1.63738256,
53 1.58501580, 1.51795181, 1.43679906, 1.33950585, 1.24176208, 1.12260729, 0.96749668, 0.74048265, },
54 { 1.76943864, 1.67822463, 1.59946365, 1.53560582, 1.47470796, 1.41210167, 1.34509536, 1.27339507,
55 1.19303814, 1.09765169, 0.98818722, 0.87239446, 0.74369172, 0.59768184, 0.43168630, 0.17977021, },
56 { 1.43428349, 1.32038354, 1.21074086, 1.10577988, 1.00561746, 0.90335924, 0.80437489, 0.70709671,
57 0.60427395, 0.49814048, 0.38509539, 0.27106800, 0.14407416, 0.00219910, -0.16725141, -0.36936085, },
58 { 0.99895687, 0.84188166, 0.70753739, 0.57906595, 0.47055563, 0.36966965, 0.26826648, 0.17163380,
59 0.07208392, -0.03062936, -1.40037388, -0.25128968, -0.37213937, -0.51075646, -0.64887512, -0.80308031, },
60 { 0.26515280, 0.06313551, -0.08872080, -0.21103548, -0.31069678, -0.39680323, -0.47223474, -0.54167135,
61 -0.61444740, -0.68943343, -0.76580211, -0.85170082, -0.95289061, -1.06514703, -1.20510707, -1.37617746, },
62 { -0.53940301, -0.73770929, -0.88424876, -1.01117930, -1.13389091, -1.26830073, -1.42041987, -1.62033919,
63 -1.10158808, -1.16512566, -1.23337128, -1.30414401, -1.37663312, -1.46853845, -1.57625798, -1.66893638, },
64 { -0.38601997, -0.56009350, -0.66978483, -0.76028471, -0.83846064, -0.90868087, -0.97408881, -1.03694962, },
65 { -1.56144989, -1.65944032, -1.72689685, -1.77857740, -1.82203011, -1.86220079, -1.90283983, -1.94820479, },
66};
67
68static const uint32_t scale_huffcodes[121] = {
69 0x3ffe8, 0x3ffe6, 0x3ffe7, 0x3ffe5, 0x7fff5, 0x7fff1, 0x7ffed, 0x7fff6,
70 0x7ffee, 0x7ffef, 0x7fff0, 0x7fffc, 0x7fffd, 0x7ffff, 0x7fffe, 0x7fff7,
71 0x7fff8, 0x7fffb, 0x7fff9, 0x3ffe4, 0x7fffa, 0x3ffe3, 0x1ffef, 0x1fff0,
72 0x0fff5, 0x1ffee, 0x0fff2, 0x0fff3, 0x0fff4, 0x0fff1, 0x07ff6, 0x07ff7,
73 0x03ff9, 0x03ff5, 0x03ff7, 0x03ff3, 0x03ff6, 0x03ff2, 0x01ff7, 0x01ff5,
74 0x00ff9, 0x00ff7, 0x00ff6, 0x007f9, 0x00ff4, 0x007f8, 0x003f9, 0x003f7,
75 0x003f5, 0x001f8, 0x001f7, 0x000fa, 0x000f8, 0x000f6, 0x00079, 0x0003a,
76 0x00038, 0x0001a, 0x0000b, 0x00004, 0x00000, 0x0000a, 0x0000c, 0x0001b,
77 0x00039, 0x0003b, 0x00078, 0x0007a, 0x000f7, 0x000f9, 0x001f6, 0x001f9,
78 0x003f4, 0x003f6, 0x003f8, 0x007f5, 0x007f4, 0x007f6, 0x007f7, 0x00ff5,
79 0x00ff8, 0x01ff4, 0x01ff6, 0x01ff8, 0x03ff8, 0x03ff4, 0x0fff0, 0x07ff4,
80 0x0fff6, 0x07ff5, 0x3ffe2, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd,
81 0x7ffde, 0x7ffd8, 0x7ffd2, 0x7ffd3, 0x7ffd4, 0x7ffd5, 0x7ffd6, 0x7fff2,
82 0x7ffdf, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffe6, 0x7ffe0,
83 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffd7, 0x7ffec, 0x7fff4,
84 0x7fff3,
85};
86
87static const uint8_t scale_huffbits[121] = {
88 18, 18, 18, 18, 19, 19, 19, 19,
89 19, 19, 19, 19, 19, 19, 19, 19,
90 19, 19, 19, 18, 19, 18, 17, 17,
91 16, 17, 16, 16, 16, 16, 15, 15,
92 14, 14, 14, 14, 14, 14, 13, 13,
93 12, 12, 12, 11, 12, 11, 10, 10,
94 10, 9, 9, 8, 8, 8, 7, 6,
95 6, 5, 4, 3, 1, 4, 4, 5,
96 6, 6, 7, 7, 8, 8, 9, 9,
97 10, 10, 10, 11, 11, 11, 11, 12,
98 12, 13, 13, 13, 14, 14, 16, 15,
99 16, 15, 18, 19, 19, 19, 19, 19,
100 19, 19, 19, 19, 19, 19, 19, 19,
101 19, 19, 19, 19, 19, 19, 19, 19,
102 19, 19, 19, 19, 19, 19, 19, 19,
103 19,
104};
105
106static const uint32_t coef0_huffcodes[666] = {
107 0x00258, 0x0003d, 0x00000, 0x00005, 0x00008, 0x00008, 0x0000c, 0x0001b,
108 0x0001f, 0x00015, 0x00024, 0x00032, 0x0003a, 0x00026, 0x0002c, 0x0002f,
109 0x0004a, 0x0004d, 0x00061, 0x00070, 0x00073, 0x00048, 0x00052, 0x0005a,
110 0x0005d, 0x0006e, 0x00099, 0x0009e, 0x000c1, 0x000ce, 0x000e4, 0x000f0,
111 0x00093, 0x0009e, 0x000a2, 0x000a1, 0x000b8, 0x000d2, 0x000d3, 0x0012e,
112 0x00130, 0x000de, 0x0012d, 0x0019b, 0x001e4, 0x00139, 0x0013a, 0x0013f,
113 0x0014f, 0x0016d, 0x001a2, 0x0027c, 0x0027e, 0x00332, 0x0033c, 0x0033f,
114 0x0038b, 0x00396, 0x003c5, 0x00270, 0x0027c, 0x0025a, 0x00395, 0x00248,
115 0x004bd, 0x004fb, 0x00662, 0x00661, 0x0071b, 0x004e6, 0x004ff, 0x00666,
116 0x0071c, 0x0071a, 0x0071f, 0x00794, 0x00536, 0x004e2, 0x0078e, 0x004ee,
117 0x00518, 0x00535, 0x004fb, 0x0078d, 0x00530, 0x00680, 0x0068f, 0x005cb,
118 0x00965, 0x006a6, 0x00967, 0x0097f, 0x00682, 0x006ae, 0x00cd0, 0x00e28,
119 0x00f13, 0x00f1f, 0x009f5, 0x00cd3, 0x00f11, 0x00926, 0x00964, 0x00f32,
120 0x00f12, 0x00f30, 0x00966, 0x00d0b, 0x00a68, 0x00b91, 0x009c7, 0x00b73,
121 0x012fa, 0x0131d, 0x013f9, 0x01ca0, 0x0199c, 0x01c7a, 0x0198c, 0x01248,
122 0x01c74, 0x01c64, 0x0139e, 0x012fd, 0x00a77, 0x012fc, 0x01c7b, 0x012ca,
123 0x014cc, 0x014d2, 0x014e3, 0x014dc, 0x012dc, 0x03344, 0x02598, 0x0263c,
124 0x0333b, 0x025e6, 0x01a1c, 0x01e3c, 0x014e2, 0x033d4, 0x01a11, 0x03349,
125 0x03cce, 0x014e1, 0x01a34, 0x0273e, 0x02627, 0x0273f, 0x038ee, 0x03971,
126 0x03c67, 0x03c61, 0x0333d, 0x038c2, 0x0263f, 0x038cd, 0x02638, 0x02e41,
127 0x0351f, 0x03348, 0x03c66, 0x03562, 0x02989, 0x027d5, 0x0333c, 0x02e4f,
128 0x0343b, 0x02ddf, 0x04bc8, 0x029c0, 0x02e57, 0x04c72, 0x025b7, 0x03547,
129 0x03540, 0x029d3, 0x04c45, 0x025bb, 0x06600, 0x04c73, 0x04bce, 0x0357b,
130 0x029a6, 0x029d2, 0x0263e, 0x0298a, 0x07183, 0x06602, 0x07958, 0x04b66,
131 0x0537d, 0x05375, 0x04fe9, 0x04b67, 0x0799f, 0x04bc9, 0x051fe, 0x06a3b,
132 0x05bb6, 0x04fa8, 0x0728f, 0x05376, 0x0492c, 0x0537e, 0x0795a, 0x06a3c,
133 0x0e515, 0x07887, 0x0683a, 0x051f9, 0x051fd, 0x0cc6a, 0x06a8a, 0x0cc6d,
134 0x05bb3, 0x0683b, 0x051fc, 0x05378, 0x0728e, 0x07886, 0x05bb7, 0x0f2a4,
135 0x0795b, 0x0683c, 0x09fc1, 0x0683d, 0x0b752, 0x09678, 0x0a3e8, 0x06ac7,
136 0x051f0, 0x0b759, 0x06af3, 0x04b6b, 0x0f2a0, 0x0f2ad, 0x096c3, 0x0e518,
137 0x0b75c, 0x0d458, 0x0cc6b, 0x0537c, 0x067aa, 0x04fea, 0x0343a, 0x0cc71,
138 0x0967f, 0x09fc4, 0x096c2, 0x0e516, 0x0f2a1, 0x0d45c, 0x0d45d, 0x0d45e,
139 0x12fb9, 0x0967e, 0x1982f, 0x09883, 0x096c4, 0x0b753, 0x12fb8, 0x0f2a8,
140 0x1ca21, 0x096c5, 0x0e51a, 0x1ca27, 0x12f3c, 0x0d471, 0x0f2aa, 0x0b75b,
141 0x12fbb, 0x0f2a9, 0x0f2ac, 0x0d45a, 0x0b74f, 0x096c8, 0x16e91, 0x096ca,
142 0x12fbf, 0x0d0a7, 0x13103, 0x0d516, 0x16e99, 0x12cbd, 0x0a3ea, 0x19829,
143 0x0b755, 0x29ba7, 0x1ca28, 0x29ba5, 0x16e93, 0x1982c, 0x19828, 0x25994,
144 0x0a3eb, 0x1ca29, 0x16e90, 0x1ca25, 0x1982d, 0x1ca26, 0x16e9b, 0x0b756,
145 0x0967c, 0x25997, 0x0b75f, 0x198d3, 0x0b757, 0x19a2a, 0x0d45b, 0x0e517,
146 0x1ca24, 0x1ca23, 0x1ca22, 0x0b758, 0x16e97, 0x0cd14, 0x13100, 0x00007,
147 0x0003b, 0x0006b, 0x00097, 0x00138, 0x00125, 0x00173, 0x00258, 0x00335,
148 0x0028e, 0x004c6, 0x00715, 0x00729, 0x004ef, 0x00519, 0x004ed, 0x00532,
149 0x0068c, 0x00686, 0x00978, 0x00e5d, 0x00e31, 0x009f4, 0x00b92, 0x012f8,
150 0x00d06, 0x00a67, 0x00d44, 0x00a76, 0x00d59, 0x012cd, 0x01c78, 0x01c75,
151 0x0199f, 0x0198f, 0x01c67, 0x014c6, 0x01c79, 0x01c76, 0x00b94, 0x00d1b,
152 0x01e32, 0x01e31, 0x01ab0, 0x01a05, 0x01aa1, 0x0333a, 0x025e5, 0x02626,
153 0x03541, 0x03544, 0x03421, 0x03546, 0x02e55, 0x02e56, 0x0492d, 0x02dde,
154 0x0299b, 0x02ddc, 0x0357a, 0x0249c, 0x0668b, 0x1c77f, 0x1ca20, 0x0d45f,
155 0x09886, 0x16e9a, 0x0f2a7, 0x0b751, 0x0a3ee, 0x0cf59, 0x0cf57, 0x0b754,
156 0x0d0a6, 0x16e98, 0x0b760, 0x06ac6, 0x0a3f0, 0x12fbe, 0x13104, 0x0f2a5,
157 0x0a3ef, 0x0d472, 0x12cba, 0x1982e, 0x16e9c, 0x1c77e, 0x198d0, 0x13105,
158 0x16e92, 0x0b75d, 0x0d459, 0x0001a, 0x000c0, 0x0016c, 0x003cd, 0x00350,
159 0x0067b, 0x0051e, 0x006a9, 0x009f4, 0x00b72, 0x00d09, 0x01249, 0x01e3d,
160 0x01ca1, 0x01a1f, 0x01721, 0x01a8a, 0x016e8, 0x03347, 0x01a35, 0x0249d,
161 0x0299a, 0x02596, 0x02e4e, 0x0298b, 0x07182, 0x04c46, 0x025ba, 0x02e40,
162 0x027d6, 0x04fe8, 0x06607, 0x05310, 0x09884, 0x072e1, 0x06a3d, 0x04b6a,
163 0x04c7a, 0x06603, 0x04c7b, 0x03428, 0x06605, 0x09664, 0x09fc0, 0x071de,
164 0x06601, 0x05bb2, 0x09885, 0x0a3e2, 0x1c61f, 0x12cbb, 0x0b750, 0x0cf58,
165 0x0967d, 0x25995, 0x668ad, 0x0b75a, 0x09fc2, 0x0537f, 0x0b75e, 0x13fae,
166 0x12fbc, 0x00031, 0x001c4, 0x004c5, 0x005b8, 0x00cf4, 0x0096f, 0x00d46,
167 0x01e57, 0x01a04, 0x02625, 0x03346, 0x028f9, 0x04c47, 0x072e0, 0x04b69,
168 0x03420, 0x07957, 0x06639, 0x0799e, 0x07959, 0x07881, 0x04b68, 0x09fc3,
169 0x09fd6, 0x0cc70, 0x0a3f1, 0x12cbe, 0x0e30e, 0x0e51b, 0x06af2, 0x12cbc,
170 0x1c77d, 0x0f2ab, 0x12fbd, 0x1aa2f, 0x0a3ec, 0x0d473, 0x05377, 0x0a3e9,
171 0x1982b, 0x0e300, 0x12f3f, 0x0cf5f, 0x096c0, 0x38c3c, 0x16e94, 0x16e95,
172 0x12f3d, 0x29ba4, 0x29ba6, 0x1c77c, 0x6a8ba, 0x3545c, 0x33457, 0x668ac,
173 0x6a8bb, 0x16e9d, 0x0e519, 0x25996, 0x12f3e, 0x00036, 0x0033e, 0x006ad,
174 0x00d03, 0x012c8, 0x0124a, 0x03c42, 0x03ccd, 0x06606, 0x07880, 0x06852,
175 0x06a3a, 0x05bb4, 0x0f2a2, 0x09fc7, 0x12cb9, 0x0cc6c, 0x0a6e8, 0x096c1,
176 0x0004a, 0x00355, 0x012f9, 0x014e8, 0x01abe, 0x025b6, 0x0492e, 0x09fc6,
177 0x051ff, 0x0cc6f, 0x096cb, 0x0d071, 0x198d1, 0x12cb8, 0x38c3d, 0x13faf,
178 0x096c9, 0x0009d, 0x00539, 0x012ce, 0x0341f, 0x029c1, 0x04b33, 0x0a3e3,
179 0x0d070, 0x16e96, 0x0b763, 0x000a0, 0x009ce, 0x038cc, 0x0343d, 0x051fa,
180 0x09888, 0x12fba, 0x000df, 0x00a75, 0x029a7, 0x09fc5, 0x0e301, 0x0967b,
181 0x001e7, 0x012c9, 0x051fb, 0x09889, 0x0f2a6, 0x0016f, 0x01cb9, 0x0cf5a,
182 0x12cbf, 0x09679, 0x00272, 0x01a15, 0x0967a, 0x003cb, 0x025f6, 0x0b762,
183 0x0028d, 0x03c60, 0x0cf5e, 0x00352, 0x03ccc, 0x0072f, 0x07186, 0x004ec,
184 0x05379, 0x0068e, 0x09887, 0x006a7, 0x06af1, 0x00e29, 0x0cf5b, 0x00f31,
185 0x0d470, 0x009c6, 0x013fb, 0x13102, 0x019a5, 0x13101, 0x01983, 0x01c65,
186 0x0124f, 0x014c7, 0x01726, 0x01abf, 0x03304, 0x02624, 0x03c41, 0x027d7,
187 0x02ddd, 0x02e54, 0x0343c, 0x06604, 0x07181, 0x0663a, 0x04fa9, 0x0663b,
188 0x05311, 0x0537a, 0x06839, 0x05bb5, 0x0492f, 0x06af0, 0x096c7, 0x0cc6e,
189 0x0537b, 0x0cf5c, 0x0cf56, 0x198d2, 0x0cf5d, 0x0a3ed, 0x0f2a3, 0x1982a,
190 0x0b761, 0x096c6,
191};
192
193static const uint8_t coef0_huffbits[666] = {
194 11, 6, 2, 3, 4, 5, 5, 5,
195 5, 6, 6, 6, 6, 7, 7, 7,
196 7, 7, 7, 7, 7, 8, 8, 8,
197 8, 8, 8, 8, 8, 8, 8, 8,
198 9, 9, 9, 9, 9, 9, 9, 9,
199 9, 9, 9, 9, 9, 10, 10, 10,
200 10, 10, 10, 10, 10, 10, 10, 10,
201 10, 10, 10, 11, 11, 11, 10, 11,
202 11, 11, 11, 11, 11, 11, 11, 11,
203 11, 11, 11, 11, 12, 12, 11, 12,
204 12, 12, 12, 11, 12, 12, 12, 12,
205 12, 12, 12, 12, 12, 12, 12, 12,
206 12, 12, 12, 12, 12, 13, 13, 12,
207 12, 12, 13, 13, 13, 13, 13, 13,
208 13, 13, 13, 13, 13, 13, 13, 14,
209 13, 13, 13, 13, 13, 13, 13, 14,
210 14, 14, 14, 14, 14, 14, 14, 14,
211 14, 14, 14, 13, 14, 14, 14, 14,
212 14, 14, 14, 14, 14, 14, 14, 14,
213 14, 14, 14, 14, 14, 14, 14, 15,
214 15, 14, 14, 15, 15, 15, 14, 15,
215 15, 15, 15, 15, 15, 15, 15, 15,
216 15, 15, 15, 15, 15, 15, 15, 15,
217 15, 15, 14, 15, 15, 15, 15, 16,
218 16, 16, 15, 16, 15, 15, 16, 16,
219 16, 16, 15, 16, 16, 16, 15, 16,
220 16, 15, 16, 16, 16, 16, 16, 16,
221 16, 16, 16, 16, 15, 15, 16, 16,
222 15, 16, 16, 16, 17, 17, 17, 16,
223 16, 17, 16, 16, 16, 16, 17, 16,
224 17, 17, 16, 16, 15, 15, 15, 16,
225 17, 16, 17, 16, 16, 17, 17, 17,
226 17, 17, 17, 16, 17, 17, 17, 16,
227 17, 17, 16, 17, 17, 17, 16, 17,
228 17, 16, 16, 17, 17, 17, 18, 17,
229 17, 17, 17, 17, 18, 18, 17, 17,
230 17, 19, 17, 19, 18, 17, 17, 18,
231 17, 17, 18, 17, 17, 17, 18, 17,
232 17, 18, 17, 17, 17, 17, 17, 16,
233 17, 17, 17, 17, 18, 16, 17, 4,
234 6, 8, 9, 9, 10, 10, 10, 10,
235 11, 11, 11, 11, 12, 12, 12, 12,
236 12, 12, 12, 12, 12, 13, 13, 13,
237 13, 13, 13, 13, 13, 13, 13, 13,
238 13, 13, 13, 14, 13, 13, 13, 13,
239 13, 13, 14, 14, 14, 14, 14, 14,
240 15, 15, 15, 15, 15, 15, 16, 15,
241 15, 15, 15, 15, 15, 17, 17, 17,
242 16, 18, 16, 17, 17, 16, 16, 17,
243 17, 18, 17, 16, 17, 17, 17, 16,
244 17, 17, 18, 17, 18, 17, 17, 17,
245 18, 17, 17, 5, 8, 10, 10, 11,
246 11, 12, 12, 12, 13, 13, 14, 13,
247 13, 14, 14, 14, 14, 14, 14, 15,
248 15, 15, 15, 15, 15, 15, 15, 15,
249 15, 15, 15, 16, 16, 15, 16, 16,
250 15, 15, 15, 15, 15, 16, 16, 15,
251 15, 16, 16, 17, 17, 18, 17, 16,
252 17, 18, 19, 17, 16, 16, 17, 17,
253 17, 6, 9, 11, 12, 12, 13, 13,
254 13, 14, 14, 14, 15, 15, 15, 16,
255 15, 15, 15, 15, 15, 15, 16, 16,
256 16, 16, 17, 18, 16, 16, 16, 18,
257 17, 16, 17, 18, 17, 17, 16, 17,
258 17, 16, 17, 16, 17, 18, 18, 18,
259 17, 19, 19, 17, 20, 19, 18, 19,
260 20, 18, 16, 18, 17, 7, 10, 12,
261 13, 13, 14, 14, 14, 15, 15, 16,
262 16, 16, 16, 16, 18, 16, 17, 17,
263 8, 11, 13, 14, 14, 15, 16, 16,
264 16, 16, 17, 17, 17, 18, 18, 17,
265 17, 8, 12, 14, 15, 15, 15, 17,
266 17, 18, 17, 9, 12, 14, 15, 16,
267 16, 17, 9, 13, 15, 16, 16, 17,
268 9, 13, 16, 16, 16, 10, 13, 16,
269 18, 17, 10, 14, 17, 10, 14, 17,
270 11, 14, 16, 11, 14, 11, 15, 12,
271 16, 12, 16, 12, 16, 12, 16, 12,
272 17, 13, 13, 17, 13, 17, 13, 13,
273 14, 14, 14, 14, 14, 14, 14, 15,
274 15, 15, 15, 15, 15, 15, 16, 15,
275 16, 16, 16, 16, 16, 16, 17, 16,
276 16, 16, 16, 17, 16, 17, 16, 17,
277 17, 17,
278};
279
280static const uint32_t coef1_huffcodes[555] = {
281 0x00115, 0x00002, 0x00001, 0x00000, 0x0000d, 0x00007, 0x00013, 0x0001d,
282 0x00008, 0x0000c, 0x00023, 0x0002b, 0x0003f, 0x00017, 0x0001b, 0x00043,
283 0x00049, 0x00050, 0x00055, 0x00054, 0x00067, 0x00064, 0x0007b, 0x0002d,
284 0x00028, 0x0002a, 0x00085, 0x00089, 0x0002b, 0x00035, 0x00090, 0x00091,
285 0x00094, 0x00088, 0x000c1, 0x000c6, 0x000f2, 0x000e3, 0x000c5, 0x000e2,
286 0x00036, 0x000f0, 0x000a7, 0x000cd, 0x000fb, 0x00059, 0x00116, 0x00103,
287 0x00108, 0x0012b, 0x0012d, 0x00188, 0x0012e, 0x0014c, 0x001c3, 0x00187,
288 0x001e7, 0x0006f, 0x00094, 0x00069, 0x001e6, 0x001ca, 0x00147, 0x00195,
289 0x000a7, 0x00213, 0x00209, 0x00303, 0x00295, 0x00289, 0x0028c, 0x0028d,
290 0x00312, 0x00330, 0x0029b, 0x00308, 0x00328, 0x0029a, 0x0025e, 0x003c5,
291 0x00384, 0x0039f, 0x00397, 0x00296, 0x0032e, 0x00332, 0x003c6, 0x003e6,
292 0x0012d, 0x000d1, 0x00402, 0x000dd, 0x00161, 0x0012b, 0x00127, 0x0045d,
293 0x00601, 0x004ab, 0x0045f, 0x00410, 0x004bf, 0x00528, 0x0045c, 0x00424,
294 0x00400, 0x00511, 0x00618, 0x0073d, 0x0063a, 0x00614, 0x0073c, 0x007c0,
295 0x007cf, 0x00802, 0x00966, 0x00964, 0x00951, 0x008a0, 0x00346, 0x00803,
296 0x00a52, 0x0024a, 0x007c1, 0x0063f, 0x00126, 0x00406, 0x00789, 0x008a2,
297 0x00960, 0x00967, 0x00c05, 0x00c70, 0x00c79, 0x00a5d, 0x00c26, 0x00c4d,
298 0x00372, 0x008a5, 0x00c08, 0x002c5, 0x00f11, 0x00cc4, 0x00f8e, 0x00e16,
299 0x00496, 0x00e77, 0x00f9c, 0x00c25, 0x00f1e, 0x00c27, 0x00f1f, 0x00e17,
300 0x00ccd, 0x00355, 0x00c09, 0x00c78, 0x00f90, 0x00521, 0x00357, 0x00356,
301 0x0068e, 0x00f9d, 0x00c04, 0x00e58, 0x00a20, 0x00a2c, 0x00c4c, 0x0052f,
302 0x00f8d, 0x01178, 0x01053, 0x01097, 0x0180f, 0x0180d, 0x012fb, 0x012aa,
303 0x0202a, 0x00a40, 0x018ed, 0x01ceb, 0x01455, 0x018e3, 0x012a1, 0x00354,
304 0x00353, 0x00f1c, 0x00c7b, 0x00c37, 0x0101d, 0x012cb, 0x01142, 0x0197d,
305 0x01095, 0x01e3b, 0x0186b, 0x00588, 0x01c2a, 0x014b8, 0x01e3a, 0x018ec,
306 0x01f46, 0x012fa, 0x00a53, 0x01ce8, 0x00a55, 0x01c29, 0x0117b, 0x01052,
307 0x012a0, 0x00589, 0x00950, 0x01c2b, 0x00a50, 0x0208b, 0x0180e, 0x02027,
308 0x02556, 0x01e20, 0x006e7, 0x01c28, 0x0197a, 0x00684, 0x020a2, 0x01f22,
309 0x03018, 0x039cf, 0x03e25, 0x02557, 0x0294c, 0x028a6, 0x00d11, 0x028a9,
310 0x02979, 0x00d46, 0x00a56, 0x039ce, 0x030cc, 0x0329a, 0x0149d, 0x0510f,
311 0x0451c, 0x02028, 0x03299, 0x01ced, 0x014b9, 0x00f85, 0x00c7a, 0x01800,
312 0x00341, 0x012ca, 0x039c8, 0x0329d, 0x00d0d, 0x03e20, 0x05144, 0x00d45,
313 0x030d0, 0x0186d, 0x030d5, 0x00d0f, 0x00d40, 0x04114, 0x020a1, 0x0297f,
314 0x03e24, 0x032f1, 0x04047, 0x030d4, 0x028a8, 0x00d0e, 0x0451d, 0x04044,
315 0x0297e, 0x04042, 0x030d2, 0x030cf, 0x03e21, 0x03e26, 0x028a5, 0x0451a,
316 0x00d48, 0x01a16, 0x00d44, 0x04518, 0x0149b, 0x039ca, 0x01498, 0x0403d,
317 0x0451b, 0x0149c, 0x032f3, 0x030cb, 0x08073, 0x03e22, 0x0529a, 0x020aa,
318 0x039cc, 0x0738a, 0x06530, 0x07389, 0x06193, 0x08071, 0x04043, 0x030ce,
319 0x05147, 0x07388, 0x05145, 0x08072, 0x04521, 0x00d47, 0x0297c, 0x030cd,
320 0x030ca, 0x0000b, 0x0000c, 0x00083, 0x000e4, 0x00048, 0x00102, 0x001cc,
321 0x001f5, 0x00097, 0x0020b, 0x00124, 0x00453, 0x00627, 0x00639, 0x00605,
322 0x00517, 0x001b8, 0x00663, 0x00667, 0x007c3, 0x00823, 0x00961, 0x00963,
323 0x00e5a, 0x00e59, 0x00a2b, 0x00cbf, 0x00292, 0x00a2d, 0x007d0, 0x00953,
324 0x00cc5, 0x00f84, 0x004ab, 0x014a7, 0x0068a, 0x0117a, 0x0052e, 0x01442,
325 0x0052c, 0x00c77, 0x00f8f, 0x004aa, 0x01094, 0x01801, 0x012c4, 0x0297b,
326 0x00952, 0x01f19, 0x006a5, 0x01149, 0x012c5, 0x01803, 0x022f2, 0x0329b,
327 0x04520, 0x0149e, 0x00d13, 0x01f16, 0x01ce9, 0x0101c, 0x006e6, 0x039c9,
328 0x06191, 0x07c8e, 0x06192, 0x0ca63, 0x039cd, 0x06190, 0x06884, 0x06885,
329 0x07382, 0x00d49, 0x00d41, 0x0450c, 0x0149a, 0x030d1, 0x08077, 0x03e23,
330 0x01a15, 0x0e701, 0x0e702, 0x08079, 0x0822a, 0x0a218, 0x07887, 0x0403f,
331 0x0520b, 0x0529b, 0x0e700, 0x04519, 0x00007, 0x000e0, 0x000d0, 0x0039b,
332 0x003e5, 0x00163, 0x0063e, 0x007c9, 0x00806, 0x00954, 0x01044, 0x01f44,
333 0x0197c, 0x01f45, 0x00a51, 0x01f47, 0x00951, 0x0052d, 0x02291, 0x0092f,
334 0x00a54, 0x00d12, 0x0297d, 0x00d0c, 0x01499, 0x0329e, 0x032f0, 0x02025,
335 0x039c6, 0x00a57, 0x03e46, 0x00d42, 0x0738b, 0x05146, 0x04046, 0x08078,
336 0x0510e, 0x07886, 0x02904, 0x04156, 0x04157, 0x06032, 0x030d3, 0x08bce,
337 0x04040, 0x0403e, 0x0a414, 0x10457, 0x08075, 0x06887, 0x07c8f, 0x039c7,
338 0x07387, 0x08070, 0x08bcf, 0x1482a, 0x10456, 0x1482b, 0x01a17, 0x06886,
339 0x0450d, 0x00013, 0x0006b, 0x00615, 0x0080b, 0x0082b, 0x00952, 0x00e5b,
340 0x018e2, 0x0186c, 0x01f18, 0x0329f, 0x00d43, 0x03e29, 0x05140, 0x05141,
341 0x0ca62, 0x06033, 0x03c42, 0x03e28, 0x0450f, 0x0a21a, 0x07384, 0x0a219,
342 0x0e703, 0x0a21b, 0x01a14, 0x07383, 0x045e6, 0x0007a, 0x0012c, 0x00ccc,
343 0x0068f, 0x01802, 0x00a52, 0x00953, 0x04045, 0x01a20, 0x0451f, 0x000a4,
344 0x00735, 0x01cec, 0x02029, 0x020a3, 0x0451e, 0x00069, 0x00c24, 0x02024,
345 0x032f2, 0x05142, 0x00196, 0x00523, 0x000a6, 0x0197b, 0x0030b, 0x0092e,
346 0x003e9, 0x03e27, 0x00160, 0x05143, 0x00652, 0x04041, 0x00734, 0x028a7,
347 0x0080f, 0x01483, 0x0097c, 0x00340, 0x0068b, 0x00522, 0x01054, 0x01096,
348 0x01f17, 0x0202b, 0x01cea, 0x020a0, 0x02978, 0x02026, 0x0297a, 0x039cb,
349 0x03e2b, 0x0149f, 0x0329c, 0x07385, 0x08074, 0x0450e, 0x03e2a, 0x05149,
350 0x08076, 0x07386, 0x05148,
351};
352
353static const uint8_t coef1_huffbits[555] = {
354 9, 5, 2, 4, 4, 5, 5, 5,
355 6, 6, 6, 6, 6, 7, 7, 7,
356 7, 7, 7, 7, 7, 7, 7, 8,
357 8, 8, 8, 8, 8, 8, 8, 8,
358 8, 8, 8, 8, 8, 8, 8, 8,
359 9, 8, 8, 8, 8, 9, 9, 9,
360 9, 9, 9, 9, 9, 9, 9, 9,
361 9, 10, 10, 10, 9, 9, 9, 9,
362 10, 10, 10, 10, 10, 10, 10, 10,
363 10, 10, 10, 10, 10, 10, 10, 10,
364 10, 10, 10, 10, 10, 10, 10, 10,
365 11, 11, 11, 11, 11, 11, 11, 11,
366 11, 11, 11, 11, 11, 11, 11, 11,
367 11, 11, 11, 11, 11, 11, 11, 11,
368 11, 12, 12, 12, 12, 12, 12, 12,
369 12, 12, 11, 11, 11, 11, 11, 12,
370 12, 12, 12, 12, 12, 12, 12, 12,
371 13, 12, 12, 12, 12, 12, 12, 12,
372 13, 12, 12, 12, 12, 12, 12, 12,
373 12, 13, 12, 12, 12, 13, 13, 13,
374 13, 12, 12, 12, 12, 12, 12, 13,
375 12, 13, 13, 13, 13, 13, 13, 13,
376 14, 14, 13, 13, 13, 13, 13, 13,
377 13, 12, 12, 12, 13, 13, 13, 13,
378 13, 13, 13, 13, 13, 13, 13, 13,
379 13, 13, 14, 13, 14, 13, 13, 13,
380 13, 13, 14, 13, 14, 14, 13, 14,
381 14, 13, 14, 13, 13, 14, 14, 13,
382 14, 14, 14, 14, 14, 14, 14, 14,
383 14, 15, 14, 14, 14, 14, 15, 15,
384 15, 14, 14, 13, 13, 12, 12, 13,
385 13, 13, 14, 14, 15, 14, 15, 15,
386 14, 13, 14, 15, 15, 15, 14, 14,
387 14, 14, 15, 14, 14, 15, 15, 15,
388 14, 15, 14, 14, 14, 14, 14, 15,
389 15, 16, 15, 15, 15, 14, 15, 15,
390 15, 15, 14, 14, 16, 14, 15, 14,
391 14, 15, 15, 15, 15, 16, 15, 14,
392 15, 15, 15, 16, 15, 15, 14, 14,
393 14, 4, 7, 8, 8, 9, 9, 9,
394 9, 10, 10, 11, 11, 11, 11, 11,
395 11, 12, 11, 11, 11, 12, 12, 12,
396 12, 12, 12, 12, 12, 12, 11, 12,
397 12, 12, 13, 13, 13, 13, 13, 13,
398 13, 12, 12, 13, 13, 13, 13, 14,
399 14, 13, 14, 13, 13, 13, 14, 14,
400 15, 15, 14, 13, 13, 13, 14, 14,
401 15, 15, 15, 16, 14, 15, 17, 17,
402 15, 15, 15, 15, 15, 14, 16, 14,
403 16, 16, 16, 16, 16, 16, 15, 15,
404 17, 15, 16, 15, 6, 8, 10, 10,
405 10, 11, 11, 11, 12, 12, 13, 13,
406 13, 13, 14, 13, 14, 13, 14, 14,
407 14, 14, 14, 15, 15, 14, 14, 14,
408 14, 14, 14, 15, 15, 15, 15, 16,
409 15, 15, 16, 15, 15, 15, 14, 16,
410 15, 15, 18, 17, 16, 17, 15, 14,
411 15, 16, 16, 19, 17, 19, 16, 17,
412 15, 7, 10, 11, 12, 12, 12, 12,
413 13, 13, 13, 14, 15, 14, 15, 15,
414 16, 15, 14, 14, 15, 16, 15, 16,
415 16, 16, 16, 15, 15, 7, 11, 12,
416 13, 13, 14, 14, 15, 15, 15, 8,
417 11, 13, 14, 14, 15, 9, 12, 14,
418 14, 15, 9, 13, 10, 13, 10, 14,
419 10, 14, 11, 15, 11, 15, 11, 14,
420 12, 15, 12, 13, 13, 13, 13, 13,
421 13, 14, 13, 14, 14, 14, 14, 14,
422 14, 15, 14, 15, 16, 15, 14, 15,
423 16, 15, 15,
424};
425
426static const uint32_t coef2_huffcodes[1336] = {
427 0x003e6, 0x000f6, 0x00000, 0x00002, 0x00006, 0x0000f, 0x0001b, 0x00028,
428 0x00039, 0x0003f, 0x0006b, 0x00076, 0x000b7, 0x000e8, 0x000ef, 0x00169,
429 0x001a7, 0x001d4, 0x001dc, 0x002c4, 0x00349, 0x00355, 0x00391, 0x003dc,
430 0x00581, 0x005b2, 0x00698, 0x0070c, 0x00755, 0x0073a, 0x00774, 0x007cf,
431 0x00b0a, 0x00b66, 0x00d2e, 0x00d5e, 0x00e1b, 0x00eac, 0x00e5a, 0x00f7e,
432 0x00fa1, 0x0163e, 0x01a37, 0x01a52, 0x01c39, 0x01ab3, 0x01d5f, 0x01cb6,
433 0x01f52, 0x01dd9, 0x02c04, 0x02c2e, 0x02c2d, 0x02c23, 0x03467, 0x034a3,
434 0x0351b, 0x03501, 0x03a5d, 0x0351c, 0x03875, 0x03dea, 0x0397b, 0x039db,
435 0x03df1, 0x039d8, 0x03bb4, 0x0580a, 0x0584d, 0x05842, 0x05b13, 0x058ea,
436 0x0697d, 0x06a06, 0x068cc, 0x06ac7, 0x06a96, 0x072f4, 0x07543, 0x072b4,
437 0x07d20, 0x0b003, 0x073b5, 0x07be6, 0x0d180, 0x07bd1, 0x07cb8, 0x07d06,
438 0x07d25, 0x0d2f2, 0x0d19a, 0x0d334, 0x0e1dc, 0x0d529, 0x0d584, 0x0e1d2,
439 0x0e5e3, 0x0eec4, 0x0e564, 0x0fa49, 0x16001, 0x0eedc, 0x0f7fa, 0x1a32c,
440 0x16131, 0x16003, 0x0f9c8, 0x1ef80, 0x1d2a0, 0x1aa4b, 0x0f7ce, 0x1abfe,
441 0x1aa50, 0x1a458, 0x1a816, 0x1cae4, 0x1d2fe, 0x1d52e, 0x1aa4c, 0x2c245,
442 0x1d2a1, 0x1a35d, 0x1ca1b, 0x1d5d8, 0x1f531, 0x1ca1c, 0x1f389, 0x1f4af,
443 0x3a5e7, 0x351fb, 0x2c24b, 0x34bce, 0x2c24d, 0x2c249, 0x2c24a, 0x72dfc,
444 0x357ef, 0x35002, 0x3a5e6, 0x39431, 0x5843b, 0x34a77, 0x58431, 0x3a5f3,
445 0x3a5dd, 0x3e5e5, 0x356bd, 0x3976e, 0x6a3d2, 0x3500d, 0x694c4, 0x580bd,
446 0x3e5e8, 0x74b95, 0x34a6e, 0x3977c, 0x39432, 0x5b0d2, 0x6a3d8, 0x580b8,
447 0x5b0cb, 0x5b0d7, 0x72dee, 0x72ded, 0x72dec, 0x74b9c, 0x3977f, 0x72dea,
448 0x74b9e, 0x7be7d, 0x580bf, 0x5b0d5, 0x7cba8, 0x74b91, 0x3e5dd, 0xb6171,
449 0xd46b3, 0xd46b9, 0x7cba1, 0x74b9f, 0x72de1, 0xe59f5, 0x3e5eb, 0x00004,
450 0x00015, 0x00038, 0x00075, 0x000e8, 0x001d3, 0x00347, 0x0039c, 0x00690,
451 0x0074a, 0x00b60, 0x00e93, 0x00f74, 0x0163d, 0x01a5a, 0x01d24, 0x01cbe,
452 0x01f4b, 0x03468, 0x03562, 0x03947, 0x03e82, 0x05804, 0x05b12, 0x05803,
453 0x0696d, 0x06a9e, 0x0697c, 0x06978, 0x06afb, 0x074b2, 0x072f5, 0x073c0,
454 0x07541, 0x06944, 0x074b7, 0x070d3, 0x07ba9, 0x0b0b1, 0x0d1af, 0x0e1dd,
455 0x0e5e2, 0x0e1a3, 0x0eec3, 0x1612f, 0x0e961, 0x0eeda, 0x0e78e, 0x0fa48,
456 0x1612c, 0x0e511, 0x0e565, 0x0e953, 0x1aa4a, 0x0e59d, 0x1d52c, 0x1a811,
457 0x1cae7, 0x1abfc, 0x1d52d, 0x1cacf, 0x1cf05, 0x2c254, 0x34a72, 0x1f4ac,
458 0x3976b, 0x34a71, 0x2c6d9, 0x2d873, 0x34a6a, 0x357e7, 0x3464c, 0x3e5f5,
459 0x58433, 0x1f53a, 0x3500a, 0x357ea, 0x34a73, 0x3942f, 0x357e5, 0x39775,
460 0x694cd, 0x39772, 0x7cba5, 0x6a3ef, 0x35483, 0x74b98, 0x5b0c1, 0x39770,
461 0x3a5d7, 0x39433, 0x39434, 0x694ce, 0x580be, 0x3e5ff, 0x6a3ec, 0xb616f,
462 0xd46b1, 0x6a3d1, 0x72de5, 0x74b6e, 0x72de9, 0x3e700, 0xd46b6, 0x6a3e9,
463 0x74b69, 0xe5675, 0xd46b8, 0x7cbaa, 0x3a5d1, 0x0000c, 0x0003c, 0x000eb,
464 0x001f1, 0x003a4, 0x006a8, 0x007d5, 0x00d43, 0x00e77, 0x016c5, 0x01cb1,
465 0x02c5d, 0x03a55, 0x03a56, 0x03e51, 0x03bb5, 0x05b0a, 0x06a9f, 0x074b8,
466 0x07d28, 0x0d187, 0x0d40e, 0x0d52e, 0x0d425, 0x0eae3, 0x0e1d3, 0x1612e,
467 0x0e59e, 0x0eec2, 0x0e578, 0x0e51a, 0x0e579, 0x0e515, 0x0e960, 0x0d183,
468 0x0d220, 0x0d2cb, 0x0e512, 0x16c3e, 0x16002, 0x16c42, 0x1cae9, 0x3461a,
469 0x1d2fa, 0x1a308, 0x1a849, 0x1cf07, 0x1f38f, 0x34b65, 0x2c253, 0x1ef9e,
470 0x1cbc3, 0x1cbc1, 0x2c255, 0x1f384, 0x58435, 0x2c5cd, 0x3a5f7, 0x2c252,
471 0x3959c, 0x2c6d8, 0x3a5d3, 0x6ad78, 0x6a3f2, 0x7cba9, 0xb6176, 0x72deb,
472 0x39764, 0x3e5f6, 0x3a5d8, 0x74a8c, 0x6a3e6, 0x694d1, 0x6ad79, 0x1a4592,
473 0xe59fb, 0x7cbb3, 0x5b0cd, 0x00017, 0x000b5, 0x002c3, 0x005b7, 0x00b1c,
474 0x00e5c, 0x0163f, 0x01ab2, 0x01efa, 0x0348a, 0x0396e, 0x058da, 0x06963,
475 0x06a30, 0x072cd, 0x073cf, 0x07ce7, 0x0d2ca, 0x0d2d8, 0x0e764, 0x0e794,
476 0x16008, 0x16167, 0x1617e, 0x1aa49, 0x1a30b, 0x1a813, 0x2c6da, 0x1a580,
477 0x1cbc2, 0x0f9ca, 0x1617f, 0x1d2fe, 0x0f7fc, 0x16c40, 0x0e513, 0x0eec5,
478 0x0f7c3, 0x1d508, 0x1a81e, 0x1d2fd, 0x39430, 0x35486, 0x3e5fd, 0x2c24c,
479 0x2c75a, 0x34a74, 0x3a5f4, 0x3464d, 0x694ca, 0x3a5f1, 0x1d509, 0x1d5c0,
480 0x34648, 0x3464e, 0x6a3d5, 0x6a3e8, 0x6a3e7, 0x5b0c3, 0x2c248, 0x1f38a,
481 0x3a5f2, 0x6a3e5, 0x00029, 0x00168, 0x0058c, 0x00b67, 0x00f9d, 0x01c3d,
482 0x01cbf, 0x02c20, 0x0351d, 0x03df6, 0x06af9, 0x072b5, 0x0b1d7, 0x0b0b2,
483 0x0d40a, 0x0d52b, 0x0e952, 0x0e797, 0x163c3, 0x1c3a0, 0x1f386, 0x1ca21,
484 0x34655, 0x2c247, 0x1f53b, 0x2c250, 0x2c24f, 0x1f385, 0x1ef5d, 0x1cf15,
485 0x1caea, 0x1ab0a, 0x1cf19, 0x1f53d, 0x1d5c2, 0x1d2fb, 0x1ef58, 0x34a78,
486 0x357ec, 0x1f533, 0x3a5e1, 0x694d2, 0x58482, 0x3a5ee, 0x2c6dc, 0x357eb,
487 0x5b0c4, 0x39778, 0x6a3e1, 0x7cbb4, 0x3a5e1, 0x74b68, 0x3a5ef, 0x3a5d2,
488 0x39424, 0x72de2, 0xe59f6, 0xe59f7, 0x3e702, 0x3e5ec, 0x1f38b, 0x0003b,
489 0x001f0, 0x00777, 0x00fa8, 0x01cb2, 0x02d84, 0x03a57, 0x03dd6, 0x06917,
490 0x06a11, 0x07d07, 0x0eae2, 0x0e796, 0x0f9c9, 0x0f7fb, 0x16166, 0x16160,
491 0x1ab1b, 0x1abfa, 0x2d87b, 0x1d2f7, 0x39768, 0x1f38c, 0x34653, 0x34651,
492 0x6a3d9, 0x35001, 0x3abbd, 0x38742, 0x39426, 0x34a76, 0x3a5ec, 0x34a75,
493 0x35000, 0x35488, 0x1cf10, 0x2c6db, 0x357ed, 0x357e8, 0x357e9, 0x3a5f0,
494 0x694c2, 0xb6178, 0x72df5, 0x39425, 0x3942b, 0x74b6d, 0x74b6f, 0xb6177,
495 0xb6179, 0x74b6a, 0xb6172, 0x58487, 0x3e5ee, 0x3e5ed, 0x72df2, 0x72df4,
496 0x7cbae, 0x6a3ca, 0x70e86, 0x34bcf, 0x6a3c8, 0x00059, 0x00384, 0x00d5b,
497 0x01c38, 0x03560, 0x0395b, 0x0584e, 0x06964, 0x073cd, 0x0b1e7, 0x0e798,
498 0x0e78d, 0x0fa43, 0x1a848, 0x1a32f, 0x1aa4e, 0x3464a, 0x1f4ab, 0x1f38d,
499 0x3a5eb, 0x3a5d4, 0x3548a, 0x6a3c7, 0x5b0d0, 0x6a3c5, 0x7cbb0, 0x694cb,
500 0x3a5e5, 0x3e5e2, 0x3942c, 0x2d872, 0x1f4ae, 0x3a5d5, 0x694d3, 0x58481,
501 0x35009, 0x39774, 0x58432, 0xb616c, 0x5b0db, 0x3548b, 0xb6174, 0x1d5d95,
502 0xb004c, 0x7cbb2, 0x3a5e5, 0x74a8f, 0xe59f9, 0x72df6, 0xe59fd, 0x7cbad,
503 0xd427d, 0x72cff, 0x3977a, 0x5b0d9, 0xb616d, 0xb616b, 0x1a4593, 0x7cbaf,
504 0x5b0da, 0x00071, 0x003eb, 0x01603, 0x02c6c, 0x03961, 0x068c8, 0x06a31,
505 0x072bd, 0x0d2c2, 0x0e51b, 0x0e5e6, 0x1abfb, 0x1d2ff, 0x1cae5, 0x1ef5c,
506 0x1ef5e, 0x1cf13, 0x34a6d, 0x3976d, 0xb616a, 0x3e5f2, 0x6a3c4, 0xb6169,
507 0x3e5dc, 0x580b9, 0x74b99, 0x75764, 0x58434, 0x3a5d9, 0x6945a, 0x69459,
508 0x3548c, 0x3a5e9, 0x69457, 0x72df1, 0x6945e, 0x6a35e, 0x3e701, 0xb6168,
509 0x5b0dd, 0x3a5de, 0x6a3c2, 0xd4278, 0x6a3cc, 0x72dfd, 0xb6165, 0x16009a,
510 0x7cbb1, 0xd427c, 0xb6162, 0xe765e, 0x1cecbe, 0x7cbb6, 0x69454, 0xb6160,
511 0xd427a, 0x1d5d96, 0xb1d6d, 0xe59f4, 0x72de8, 0x3a5db, 0x0007a, 0x006ae,
512 0x01c3c, 0x03aba, 0x058e9, 0x072cc, 0x0d2dd, 0x0d22d, 0x0eec1, 0x0eedb,
513 0x1d2a2, 0x1ef5b, 0x357e2, 0x3abbf, 0x1d2f9, 0x35004, 0x3a5dc, 0x351fc,
514 0x3976c, 0x6a3c6, 0x6a3cb, 0x3e5ea, 0xe59f3, 0x6a3ce, 0x69452, 0xe59f0,
515 0x74b90, 0xd4279, 0xd427b, 0x7cbb5, 0x5b0c5, 0x3a5e3, 0x3a5e2, 0x000d0,
516 0x00775, 0x01efe, 0x03dd5, 0x0728c, 0x07cb9, 0x0e1a2, 0x0ea85, 0x0eed8,
517 0x1a30a, 0x1aa4f, 0x3a5df, 0x35008, 0x3a5e0, 0x3e5f4, 0x3e5f7, 0xb1d6c,
518 0x5843e, 0x34a70, 0x72df8, 0x74b6b, 0xd427f, 0x72df0, 0x5b0bf, 0x5b0c0,
519 0xd46b0, 0x72def, 0xe59f8, 0x162e64, 0xb1d6f, 0x3a5e0, 0x39427, 0x69166,
520 0x6a3e2, 0x6a3e3, 0x74a8d, 0xd427e, 0x1d5d97, 0xd46b4, 0x5b0d8, 0x6a3d3,
521 0x000e0, 0x00b63, 0x034cc, 0x06a33, 0x073c9, 0x0e1a0, 0x0f7fd, 0x0f9cc,
522 0x1617d, 0x1caeb, 0x1f4a9, 0x3abb3, 0x69450, 0x39420, 0x39777, 0x3e5e0,
523 0x6a3d4, 0x6a3ed, 0xb6166, 0xe59f1, 0xb1d6e, 0xe5676, 0x6a3ea, 0xe5674,
524 0xb6163, 0xd46b7, 0x7cba6, 0xd46ba, 0x1d5d94, 0xb6164, 0x6a3f1, 0x7cba2,
525 0x69451, 0x72dfa, 0xd46bb, 0x72df7, 0x74b94, 0x1cecbf, 0xe59fa, 0x16009b,
526 0x6a3e4, 0x000e6, 0x00e94, 0x03876, 0x070ef, 0x0d52a, 0x16015, 0x16014,
527 0x1abf9, 0x1cf17, 0x34a79, 0x34650, 0x3e705, 0x6a3d0, 0x58430, 0x74b9d,
528 0x7be7e, 0x5b0be, 0x39773, 0x6a3de, 0x000fb, 0x00f7b, 0x03dd7, 0x07bd0,
529 0x0e59c, 0x0f9cd, 0x1cf18, 0x1d2ff, 0x34a7a, 0x39429, 0x3500c, 0x72de0,
530 0x69456, 0x7be7c, 0xd46b5, 0xd46b2, 0x6a3dd, 0x001a2, 0x0163b, 0x06913,
531 0x0b016, 0x0fa42, 0x1a32d, 0x1cf06, 0x34a7c, 0x34a7d, 0xb6161, 0x35481,
532 0x3e5fa, 0x7cba0, 0x7be7f, 0x7cba3, 0x7cba7, 0x5b0d3, 0x72de6, 0x6a3dc,
533 0x001a9, 0x01ab4, 0x06a34, 0x0d46a, 0x16130, 0x1ef5f, 0x1f532, 0x1f536,
534 0x3942e, 0x58436, 0x6a3db, 0x6945b, 0x001c9, 0x01ca0, 0x0728b, 0x0eed9,
535 0x1f539, 0x1ca1d, 0x39765, 0x39766, 0x58439, 0x6945d, 0x39767, 0x001d3,
536 0x01f2c, 0x07bfc, 0x16161, 0x34652, 0x3a5ed, 0x3548d, 0x58438, 0x6a3da,
537 0x002c1, 0x02c5e, 0x0d335, 0x1ab1a, 0x2d874, 0x35006, 0x35484, 0x5b0cc,
538 0x74b9a, 0x72df3, 0x6a3d6, 0x002da, 0x034b3, 0x0d5ae, 0x1caee, 0x2d871,
539 0x357e3, 0x74b97, 0x72df9, 0x580ba, 0x5b0d4, 0x0034d, 0x0354e, 0x0f750,
540 0x1cbc0, 0x3a5e7, 0x3a5e4, 0x00385, 0x03a58, 0x16c41, 0x2c5cf, 0x3e5e1,
541 0x74b6c, 0xe5677, 0x6a3df, 0x00390, 0x03e50, 0x163c2, 0x2d876, 0x35482,
542 0x5b0d6, 0x5843a, 0x0039f, 0x0585e, 0x1a583, 0x3500f, 0x74b93, 0x39771,
543 0x003e4, 0x06912, 0x16c43, 0x357e1, 0x0058a, 0x0696f, 0x1f538, 0x5b0c9,
544 0x6a3cf, 0x005b6, 0x06af8, 0x1f534, 0x58483, 0x6a3e0, 0x00695, 0x07d02,
545 0x1cae8, 0x58485, 0x006a2, 0x0754a, 0x357ee, 0x3977b, 0x00748, 0x074b2,
546 0x34a7b, 0x00729, 0x0b1e0, 0x34649, 0x3e5e3, 0x0073d, 0x0d2c4, 0x3e5e6,
547 0x007bb, 0x0b099, 0x39762, 0x5b0ce, 0x6945f, 0x007d1, 0x0d5ab, 0x39779,
548 0x007d3, 0x0d52f, 0x39763, 0x6945c, 0x00b1a, 0x0d2c5, 0x35489, 0x00d23,
549 0x0eaed, 0x3e5f8, 0x00d32, 0x16016, 0x3e5fb, 0x00d41, 0x0e768, 0x3a5ed,
550 0x00e1f, 0x16017, 0x58027, 0x00ead, 0x0fa07, 0x69455, 0x00e54, 0x1612b,
551 0x00e55, 0x1a581, 0x00f78, 0x1a32b, 0x580bc, 0x6a3ee, 0x00f79, 0x1abfd,
552 0x00f95, 0x1ab18, 0x6a3f0, 0x01637, 0x1aa4d, 0x0162d, 0x1f53c, 0x6a3f3,
553 0x01a31, 0x1a810, 0x39769, 0x01a50, 0x1caef, 0x01a36, 0x1a32e, 0x01a67,
554 0x1f38e, 0x01a85, 0x1ef59, 0x01aa6, 0x1ef83, 0x01d51, 0x2c012, 0x01d53,
555 0x2d879, 0x01d5e, 0x35005, 0x01cba, 0x1cf04, 0x69453, 0x01d2d, 0x351ff,
556 0x01f2d, 0x2d86f, 0x01f29, 0x35007, 0x02c22, 0x351fa, 0x02c03, 0x3a5ec,
557 0x02c5f, 0x3a5eb, 0x02c58, 0x34a6b, 0x03469, 0x356be, 0x02c59, 0x34a6c,
558 0x0346a, 0x3a5ea, 0x034bd, 0x034bf, 0x356bf, 0x0386a, 0x03ab9, 0x5843f,
559 0x0386b, 0x3a5f5, 0x03a4b, 0x39421, 0x03aa4, 0x3a5e9, 0x03a5a, 0x03960,
560 0x3977e, 0x03de9, 0x03958, 0x03df7, 0x039e1, 0x3e5e4, 0x0395f, 0x69458,
561 0x03e91, 0x03df2, 0x39428, 0x058f2, 0x03e80, 0x6a3c3, 0x03e93, 0x694c0,
562 0x058b8, 0x5b0ca, 0x0584f, 0x694c1, 0x058f1, 0x068d6, 0x06a10, 0x06ac3,
563 0x06a32, 0x070d2, 0x06911, 0x074b1, 0x07494, 0x06ad4, 0x06ad6, 0x072b8,
564 0x06afa, 0x074b3, 0x07540, 0x073ce, 0x0b005, 0x074b3, 0x07495, 0x074b9,
565 0x0d336, 0x07bff, 0x07763, 0x073c8, 0x07d29, 0x0b622, 0x0d221, 0x0d181,
566 0x0b1d1, 0x074b8, 0x0b1d0, 0x0d19b, 0x0d2c3, 0x0b172, 0x0d2dc, 0x0b623,
567 0x0d5aa, 0x0d426, 0x0d182, 0x0e795, 0x0e1d1, 0x0d337, 0x0e96c, 0x0e5e4,
568 0x0e514, 0x0eaee, 0x16000, 0x0e767, 0x0e1a1, 0x0e78f, 0x16004, 0x0f7c2,
569 0x0e799, 0x0e5e7, 0x0e566, 0x0e769, 0x0f751, 0x0eede, 0x0fa06, 0x16005,
570 0x0fa9f, 0x1a5e6, 0x0e766, 0x1636f, 0x0eedd, 0x0eec0, 0x1a309, 0x1ceca,
571 0x163cd, 0x0f9cb, 0x0eedf, 0x1a582, 0x1612d, 0x0e5e5, 0x1abf8, 0x1a30c,
572 0x1ca1f, 0x163cc, 0x1a35c, 0x1ca1e, 0x1aa51, 0x163ac, 0x1a84e, 0x1a53f,
573 0x1cf16, 0x1d2fc, 0x1a5b3, 0x1ab19, 0x1a81f, 0x1d5c3, 0x16c3f, 0x1d5c1,
574 0x1d2fc, 0x1f4aa, 0x1a812, 0x1f535, 0x1cf12, 0x1a817, 0x1617c, 0x1ab0b,
575 0x1d2f8, 0x1ef82, 0x2d87a, 0x1d52f, 0x1f530, 0x1aa48, 0x35487, 0x1d2fd,
576 0x1f4ad, 0x1cf11, 0x3461b, 0x35485, 0x1ca20, 0x1caed, 0x1cae6, 0x1abff,
577 0x3464f, 0x34a6f, 0x1ef81, 0x3464b, 0x39d96, 0x1f383, 0x1f537, 0x1cf14,
578 0x2c5ce, 0x3500e, 0x2c251, 0x1caec, 0x1f387, 0x34654, 0x357e4, 0x2d878,
579 0x3500b, 0x35480, 0x3a5e8, 0x3548e, 0x34b64, 0x1f4a8, 0x35003, 0x3e5df,
580 0x2d870, 0x357e6, 0x3e5f0, 0x1ef5a, 0x3a5ea, 0x1f388, 0x3e703, 0x2c24e,
581 0x3a5e2, 0x351fd, 0x2c6dd, 0x3e704, 0x351fe, 0x2d875, 0x5b0c7, 0x3976a,
582 0x3a5e6, 0x39423, 0x58480, 0x2c246, 0x3a5e3, 0x2d877, 0x3e5f1, 0x3abbe,
583 0x58489, 0x3e5f9, 0x357e0, 0x3abbc, 0x5b0c6, 0x69167, 0x69165, 0x3e5e9,
584 0x39422, 0x3976f, 0x3977d, 0x3e5de, 0x6a3c9, 0x58b98, 0x3a5f6, 0x3a5d0,
585 0x58486, 0x6a3c1, 0x3e5fc, 0x5b0dc, 0x3548f, 0x3942d, 0x694c9, 0x58484,
586 0x3a5e8, 0x74b9b, 0x74b96, 0x694d0, 0x58488, 0x3a5e4, 0x3942a, 0x72ec2,
587 0x39776, 0x5b0d1, 0x5b0cf, 0x3a5d6, 0xe59fc, 0x5b0c8, 0x3e5e7, 0x7cbb7,
588 0x70e87, 0x7cbab, 0x5b0c2, 0x694c3, 0x74a8e, 0x3e5f3, 0x6a3cd, 0x72dfe,
589 0x73b2e, 0x72ec0, 0x694c5, 0x58437, 0x694c8, 0x72dff, 0x39435, 0x5843d,
590 0x6a3d7, 0x72ec1, 0xd22c8, 0x694cf, 0xb6173, 0x3e5fe, 0x580bb, 0xe59f2,
591 0xb616e, 0xb6175, 0x3a5da, 0x5b0bd, 0x694cc, 0x5843c, 0x694c7, 0x74b92,
592 0x72ec3, 0x694c6, 0xb6170, 0x7cbac, 0xb1733, 0x7cba4, 0xb6167, 0x72de7,
593 0x72de4, 0x6a3c0, 0x3e5ef, 0x162e65, 0x72de3, 0x72dfb, 0x6a35f, 0x6a3eb,
594};
595
596static const uint8_t coef2_huffbits[1336] = {
597 11, 9, 2, 3, 4, 4, 5, 6,
598 6, 7, 7, 8, 8, 8, 9, 9,
599 9, 9, 10, 10, 10, 10, 11, 11,
600 11, 11, 11, 11, 11, 12, 12, 12,
601 12, 12, 12, 12, 12, 12, 13, 13,
602 13, 13, 13, 13, 13, 13, 13, 14,
603 14, 14, 14, 14, 14, 14, 14, 14,
604 14, 14, 14, 14, 14, 15, 15, 15,
605 15, 15, 15, 15, 15, 15, 15, 15,
606 15, 15, 15, 15, 15, 16, 15, 16,
607 16, 16, 16, 16, 16, 16, 16, 16,
608 16, 16, 16, 16, 16, 16, 16, 16,
609 17, 17, 17, 17, 17, 17, 17, 17,
610 17, 17, 17, 18, 17, 17, 17, 17,
611 17, 17, 17, 18, 18, 17, 17, 18,
612 17, 17, 18, 17, 18, 18, 18, 18,
613 19, 18, 18, 18, 18, 18, 18, 20,
614 18, 18, 18, 19, 19, 18, 19, 18,
615 19, 19, 18, 19, 19, 18, 19, 19,
616 19, 19, 18, 19, 19, 19, 19, 19,
617 19, 19, 20, 20, 20, 19, 19, 20,
618 19, 20, 19, 19, 20, 19, 19, 20,
619 20, 20, 20, 19, 20, 21, 19, 3,
620 5, 7, 8, 9, 9, 10, 11, 11,
621 12, 12, 12, 13, 13, 13, 13, 14,
622 14, 14, 14, 15, 15, 15, 15, 15,
623 15, 15, 15, 15, 15, 15, 16, 16,
624 15, 15, 15, 15, 16, 16, 16, 16,
625 17, 16, 17, 17, 16, 17, 17, 17,
626 17, 17, 17, 16, 17, 17, 17, 17,
627 18, 17, 17, 18, 18, 18, 18, 18,
628 19, 18, 18, 18, 18, 18, 18, 19,
629 19, 18, 18, 18, 18, 19, 18, 19,
630 19, 19, 20, 19, 18, 19, 19, 19,
631 19, 19, 19, 19, 19, 19, 19, 20,
632 20, 19, 20, 19, 20, 19, 20, 19,
633 19, 21, 20, 20, 19, 4, 7, 8,
634 10, 11, 11, 12, 12, 13, 13, 14,
635 14, 14, 14, 15, 15, 15, 15, 15,
636 16, 16, 16, 16, 16, 16, 16, 17,
637 17, 17, 17, 17, 17, 17, 16, 16,
638 16, 16, 17, 17, 17, 17, 18, 18,
639 18, 17, 17, 18, 18, 18, 18, 18,
640 18, 18, 18, 18, 19, 18, 18, 18,
641 19, 18, 19, 19, 19, 20, 20, 20,
642 19, 19, 19, 19, 19, 19, 19, 21,
643 21, 20, 19, 5, 8, 10, 11, 12,
644 13, 13, 13, 14, 14, 15, 15, 15,
645 15, 16, 16, 16, 16, 16, 17, 17,
646 17, 17, 17, 17, 17, 17, 18, 17,
647 18, 17, 17, 17, 17, 17, 17, 17,
648 17, 17, 17, 17, 19, 18, 19, 18,
649 18, 18, 18, 18, 19, 18, 17, 17,
650 18, 18, 19, 19, 19, 19, 18, 18,
651 18, 19, 6, 9, 11, 12, 13, 13,
652 14, 14, 14, 15, 15, 16, 16, 16,
653 16, 16, 16, 17, 17, 17, 18, 18,
654 18, 18, 18, 18, 18, 18, 18, 18,
655 18, 17, 18, 18, 17, 18, 18, 18,
656 18, 18, 18, 19, 19, 18, 18, 18,
657 19, 19, 19, 20, 19, 19, 18, 19,
658 19, 20, 21, 21, 19, 19, 18, 6,
659 10, 12, 13, 14, 14, 14, 15, 15,
660 15, 16, 16, 17, 17, 17, 17, 17,
661 17, 17, 18, 18, 19, 18, 18, 18,
662 19, 18, 18, 18, 19, 18, 18, 18,
663 18, 18, 18, 18, 18, 18, 18, 18,
664 19, 20, 20, 19, 19, 19, 19, 20,
665 20, 19, 20, 19, 19, 19, 20, 20,
666 20, 19, 19, 18, 19, 7, 10, 12,
667 13, 14, 15, 15, 15, 16, 16, 17,
668 17, 17, 17, 17, 17, 18, 18, 18,
669 18, 19, 18, 19, 19, 19, 20, 19,
670 18, 19, 19, 18, 18, 19, 19, 19,
671 18, 19, 19, 20, 19, 18, 20, 21,
672 20, 20, 19, 19, 21, 20, 21, 20,
673 20, 20, 19, 19, 20, 20, 21, 20,
674 19, 7, 11, 13, 14, 15, 15, 15,
675 16, 16, 17, 17, 17, 17, 18, 18,
676 18, 18, 18, 19, 20, 19, 19, 20,
677 19, 19, 19, 19, 19, 19, 19, 19,
678 18, 18, 19, 20, 19, 19, 19, 20,
679 19, 19, 19, 20, 19, 20, 20, 21,
680 20, 20, 20, 21, 22, 20, 19, 20,
681 20, 21, 20, 21, 20, 19, 8, 11,
682 13, 14, 15, 16, 16, 16, 17, 17,
683 17, 18, 18, 18, 18, 18, 19, 18,
684 19, 19, 19, 19, 21, 19, 19, 21,
685 19, 20, 20, 20, 19, 18, 18, 8,
686 12, 14, 15, 16, 16, 16, 16, 17,
687 17, 17, 19, 18, 18, 19, 19, 20,
688 19, 18, 20, 19, 20, 20, 19, 19,
689 20, 20, 21, 21, 20, 19, 19, 19,
690 19, 19, 19, 20, 21, 20, 19, 19,
691 8, 12, 14, 15, 16, 16, 17, 17,
692 17, 18, 18, 18, 19, 19, 19, 19,
693 19, 19, 20, 21, 20, 21, 19, 21,
694 20, 20, 20, 20, 21, 20, 19, 20,
695 19, 20, 20, 20, 19, 22, 21, 21,
696 19, 9, 12, 14, 15, 16, 17, 17,
697 17, 18, 18, 18, 19, 19, 19, 19,
698 20, 19, 19, 19, 9, 13, 15, 16,
699 17, 17, 18, 18, 18, 19, 18, 20,
700 19, 20, 20, 20, 19, 9, 13, 15,
701 16, 17, 17, 18, 18, 18, 20, 18,
702 19, 20, 20, 20, 20, 19, 20, 19,
703 9, 13, 15, 16, 17, 18, 18, 18,
704 19, 19, 19, 19, 10, 14, 16, 17,
705 18, 18, 19, 19, 19, 19, 19, 10,
706 14, 16, 17, 18, 18, 18, 19, 19,
707 10, 14, 16, 17, 18, 18, 18, 19,
708 19, 20, 19, 10, 14, 16, 18, 18,
709 18, 19, 20, 19, 19, 10, 14, 17,
710 18, 18, 18, 10, 15, 17, 18, 19,
711 19, 21, 19, 11, 15, 17, 18, 18,
712 19, 19, 11, 15, 17, 18, 19, 19,
713 11, 15, 17, 18, 11, 15, 18, 19,
714 19, 11, 15, 18, 19, 19, 11, 16,
715 18, 19, 11, 15, 18, 19, 11, 16,
716 18, 12, 16, 18, 19, 12, 16, 19,
717 12, 16, 19, 19, 19, 12, 16, 19,
718 12, 16, 19, 19, 12, 16, 18, 12,
719 16, 19, 12, 17, 19, 12, 17, 19,
720 12, 17, 19, 12, 17, 19, 13, 17,
721 13, 17, 13, 17, 19, 19, 13, 17,
722 13, 17, 19, 13, 17, 13, 18, 19,
723 13, 17, 19, 13, 18, 13, 17, 13,
724 18, 13, 18, 13, 18, 13, 18, 13,
725 18, 13, 18, 14, 18, 19, 14, 18,
726 14, 18, 14, 18, 14, 18, 14, 19,
727 14, 19, 14, 18, 14, 18, 14, 18,
728 14, 19, 14, 14, 18, 14, 14, 19,
729 14, 18, 14, 19, 14, 19, 14, 15,
730 19, 15, 15, 15, 15, 19, 15, 19,
731 15, 15, 19, 15, 15, 19, 15, 19,
732 15, 19, 15, 19, 15, 15, 15, 15,
733 15, 15, 15, 15, 15, 15, 15, 16,
734 15, 15, 15, 16, 16, 16, 15, 16,
735 16, 16, 16, 16, 16, 16, 16, 16,
736 16, 16, 16, 16, 16, 16, 16, 16,
737 16, 16, 16, 17, 16, 16, 16, 17,
738 17, 16, 17, 17, 16, 17, 17, 17,
739 17, 17, 17, 17, 17, 17, 17, 17,
740 17, 17, 17, 17, 17, 17, 17, 18,
741 17, 17, 17, 17, 17, 17, 17, 17,
742 18, 17, 17, 18, 17, 17, 17, 17,
743 18, 18, 17, 17, 17, 17, 17, 17,
744 17, 18, 17, 18, 18, 17, 17, 17,
745 18, 18, 18, 17, 18, 17, 18, 18,
746 18, 18, 18, 18, 18, 18, 18, 17,
747 18, 18, 18, 18, 19, 18, 18, 18,
748 18, 18, 18, 18, 18, 18, 18, 18,
749 18, 18, 18, 18, 18, 18, 18, 19,
750 18, 18, 19, 18, 18, 18, 19, 18,
751 19, 18, 18, 19, 18, 18, 19, 19,
752 19, 19, 19, 18, 19, 18, 19, 18,
753 19, 19, 18, 18, 19, 19, 19, 19,
754 19, 19, 19, 19, 19, 19, 18, 19,
755 19, 19, 19, 19, 18, 19, 19, 19,
756 19, 19, 19, 19, 19, 19, 19, 20,
757 19, 19, 19, 19, 21, 19, 19, 20,
758 19, 20, 19, 19, 19, 19, 19, 20,
759 20, 20, 19, 19, 19, 20, 19, 19,
760 19, 20, 20, 19, 20, 19, 19, 21,
761 20, 20, 19, 19, 19, 19, 19, 19,
762 20, 19, 20, 20, 20, 20, 20, 20,
763 20, 19, 19, 21, 20, 20, 19, 19,
764};
765
766static const uint32_t coef3_huffcodes[1072] = {
767 0x001b2, 0x00069, 0x00000, 0x00004, 0x00006, 0x0000e, 0x00014, 0x00019,
768 0x00016, 0x0002b, 0x00030, 0x0003d, 0x0003c, 0x0005a, 0x0005f, 0x0006d,
769 0x0007e, 0x0005f, 0x0007f, 0x000b6, 0x000bc, 0x000d8, 0x000f2, 0x000fe,
770 0x000bc, 0x000fc, 0x00161, 0x0016e, 0x00174, 0x00176, 0x001a2, 0x001e3,
771 0x001f3, 0x00174, 0x0017a, 0x001ea, 0x002a8, 0x002c4, 0x002e6, 0x00314,
772 0x00346, 0x00367, 0x003e9, 0x002e5, 0x002ee, 0x003d6, 0x00555, 0x00554,
773 0x00557, 0x005c3, 0x005d6, 0x006e0, 0x0062f, 0x006e2, 0x00799, 0x00789,
774 0x007fa, 0x005ce, 0x007fe, 0x005ec, 0x007cc, 0x007af, 0x00aa7, 0x00b19,
775 0x00b94, 0x00b85, 0x00b9f, 0x00c48, 0x00c45, 0x00dd8, 0x00c4c, 0x00c4b,
776 0x00d99, 0x00d1f, 0x00dc2, 0x00f95, 0x00fa2, 0x00bb5, 0x00b9f, 0x00f5d,
777 0x00bbf, 0x00f47, 0x0154a, 0x00fd5, 0x00f45, 0x00f7f, 0x0160d, 0x01889,
778 0x01757, 0x01722, 0x018b3, 0x0172d, 0x01a39, 0x01a18, 0x01bb3, 0x01b30,
779 0x01e63, 0x0173c, 0x01b35, 0x01723, 0x01e80, 0x01fee, 0x01761, 0x01ffc,
780 0x01f7f, 0x02c7c, 0x01fa1, 0x0177b, 0x01755, 0x0175a, 0x01fa6, 0x02eab,
781 0x0310a, 0x02c69, 0x03669, 0x03127, 0x03103, 0x02e43, 0x03662, 0x03165,
782 0x03124, 0x0313b, 0x03111, 0x03668, 0x0343b, 0x03c52, 0x03efc, 0x02e6c,
783 0x03fda, 0x03ef8, 0x02e7b, 0x03ee2, 0x03cc5, 0x03d72, 0x058c0, 0x03df8,
784 0x02ea9, 0x03e7e, 0x0556d, 0x05c82, 0x03d71, 0x03e7b, 0x03c42, 0x058d7,
785 0x03f4e, 0x06200, 0x03d70, 0x05cb2, 0x05c96, 0x05cb0, 0x03f45, 0x05cb1,
786 0x02e6d, 0x03110, 0x02f68, 0x05c90, 0x07ca6, 0x07c88, 0x06204, 0x062c8,
787 0x078a6, 0x07986, 0x079d5, 0x0b1ad, 0x07989, 0x0b079, 0x05cdd, 0x0aad4,
788 0x05de8, 0x07dcd, 0x07987, 0x05d67, 0x05d99, 0x0b91d, 0x07cf1, 0x05d9b,
789 0x079d7, 0x0b07b, 0x05c85, 0x05d9a, 0x07dcc, 0x07ebf, 0x07dce, 0x07dfb,
790 0x07ec0, 0x07d1a, 0x07a07, 0x05c84, 0x0c471, 0x07cf2, 0x0baef, 0x0b9d2,
791 0x05deb, 0x07bd6, 0x0b845, 0x05d98, 0x0b91a, 0x0bae8, 0x0c4e0, 0x0dc31,
792 0x0f93d, 0x0bbce, 0x0d1d2, 0x0f7a9, 0x0d9b9, 0x0bbcb, 0x0b900, 0x0aad7,
793 0x0babd, 0x0c4e1, 0x0f46f, 0x0c588, 0x0c58b, 0x160e6, 0x0bbcf, 0x0bac3,
794 0x0f945, 0x0f7a3, 0x0d1c1, 0x0fb8e, 0x0f7a4, 0x0fb8c, 0x0f40c, 0x0c473,
795 0x0fd72, 0x0bbcd, 0x0fffa, 0x0f940, 0x0bbc9, 0x0f7a8, 0x1a1ed, 0x0bbc5,
796 0x1f26f, 0x163fd, 0x160c7, 0x1a1f5, 0x0f947, 0x163fc, 0x154b3, 0x0fff6,
797 0x163f6, 0x160e9, 0x1a1f0, 0x0bab9, 0x0baba, 0x17086, 0x0b903, 0x0fd75,
798 0x0f308, 0x176f3, 0x163ff, 0x0fd7d, 0x1bb78, 0x163fb, 0x188db, 0x1a1f7,
799 0x154b2, 0x172fd, 0x163f4, 0x1bb73, 0x172ff, 0x0babc, 0x0f97d, 0x1a1f3,
800 0x1bb6d, 0x1ffd5, 0x1a1f4, 0x1f272, 0x17380, 0x17382, 0x1ffe7, 0x0bac8,
801 0x0bbc4, 0x188d3, 0x160e0, 0x0fd7b, 0x1725f, 0x172f5, 0x1bb79, 0x1fad9,
802 0x1f269, 0x188d0, 0x0bac4, 0x0bac5, 0x31185, 0x188d2, 0x188cc, 0x31187,
803 0x3e7fe, 0x188d1, 0x1bb6c, 0x1f268, 0x1fad2, 0x1ffd9, 0x1a1ea, 0x1bb68,
804 0x1facb, 0x3fdb2, 0x1e81a, 0x188ce, 0x172fb, 0x1a1ef, 0x1face, 0x1bb70,
805 0x0bac1, 0x1bb6b, 0x172f8, 0x1bb66, 0x1ffdf, 0x1bb6a, 0x1ffd7, 0x1f266,
806 0x176f8, 0x37653, 0x1fa7e, 0x31182, 0x1fac8, 0x2c7e3, 0x370ee, 0x176ec,
807 0x176e9, 0x2e4bc, 0x160c5, 0x3765a, 0x3ce9c, 0x17373, 0x176e8, 0x188d4,
808 0x176f1, 0x176ef, 0x37659, 0x1bb7c, 0x1ffde, 0x176f2, 0x3118b, 0x2c7d4,
809 0x37651, 0x5ce9f, 0x37650, 0x31191, 0x3f4f6, 0x3f4f5, 0x7a06c, 0x1fac1,
810 0x5c97b, 0x2c7e0, 0x79d3a, 0x3e7fd, 0x2c7df, 0x3f4f0, 0x7a06d, 0x376c1,
811 0x79d3b, 0x00004, 0x00014, 0x00059, 0x000ab, 0x000b8, 0x00177, 0x001f5,
812 0x001f2, 0x00315, 0x003fc, 0x005bd, 0x0062d, 0x006e8, 0x007dd, 0x00b04,
813 0x007cd, 0x00b1e, 0x00d1e, 0x00f15, 0x00f3b, 0x00f41, 0x01548, 0x018b0,
814 0x0173b, 0x01884, 0x01a1c, 0x01bb4, 0x01f25, 0x017b5, 0x0176d, 0x01ef8,
815 0x02e73, 0x03107, 0x03125, 0x03105, 0x02e49, 0x03ce8, 0x03ef9, 0x03e5e,
816 0x02e72, 0x03471, 0x03fd9, 0x0623f, 0x078a0, 0x06867, 0x05cb3, 0x06272,
817 0x068ec, 0x06e9a, 0x079d4, 0x06e98, 0x0b1aa, 0x06e1a, 0x07985, 0x068ee,
818 0x06e9b, 0x05c88, 0x0b1ac, 0x07dfa, 0x05d65, 0x07cf0, 0x07cbf, 0x0c475,
819 0x160eb, 0x1bb7e, 0x0f7a6, 0x1fedd, 0x160e3, 0x0fffb, 0x0fb8d, 0x0fff9,
820 0x0d1c0, 0x0c58c, 0x1a1e9, 0x0bab8, 0x0f5cf, 0x0fff5, 0x376c5, 0x1a1ec,
821 0x160ed, 0x1fede, 0x1fac9, 0x1a1eb, 0x1f224, 0x176ee, 0x0fd79, 0x17080,
822 0x17387, 0x1bb7a, 0x1ffe9, 0x176f7, 0x17385, 0x17781, 0x2c7d5, 0x17785,
823 0x1ffe3, 0x163f5, 0x1fac2, 0x3e7f9, 0x3118d, 0x3fdb1, 0x1ffe2, 0x1f226,
824 0x3118a, 0x2c7d9, 0x31190, 0x3118c, 0x3f4f3, 0x1bb7f, 0x1bb72, 0x31184,
825 0xb92f4, 0x3e7fb, 0x6e1d9, 0x1faca, 0x62300, 0x3fdb8, 0x3d037, 0x3e7fc,
826 0x62301, 0x3f4f2, 0x1f26a, 0x0000e, 0x00063, 0x000f8, 0x001ee, 0x00377,
827 0x003f7, 0x006e3, 0x005cc, 0x00b05, 0x00dd2, 0x00fd4, 0x0172e, 0x0172a,
828 0x01e23, 0x01f2d, 0x01763, 0x01769, 0x0176c, 0x02e75, 0x03104, 0x02ec1,
829 0x03e58, 0x0583f, 0x03f62, 0x03f44, 0x058c5, 0x0623c, 0x05cf4, 0x07bd7,
830 0x05d9d, 0x0aad2, 0x05d66, 0x0b1a9, 0x0b078, 0x07cfe, 0x0b918, 0x0c46f,
831 0x0b919, 0x0b847, 0x06e1b, 0x0b84b, 0x0aad8, 0x0fd74, 0x172f4, 0x17081,
832 0x0f97c, 0x1f273, 0x0f7a0, 0x0fd7c, 0x172f7, 0x0fd7a, 0x1bb77, 0x172fe,
833 0x1f270, 0x0fd73, 0x1bb7b, 0x1a1bc, 0x1bb7d, 0x0bbc3, 0x172f6, 0x0baeb,
834 0x0fb8f, 0x3f4f4, 0x3fdb4, 0x376c8, 0x3e7fa, 0x1ffd0, 0x62303, 0xb92f5,
835 0x1f261, 0x31189, 0x3fdb5, 0x2c7db, 0x376c9, 0x1fad6, 0x1fad1, 0x00015,
836 0x000f0, 0x002e0, 0x0058e, 0x005d7, 0x00c4d, 0x00fa1, 0x00bdb, 0x01756,
837 0x01f70, 0x02c19, 0x0313c, 0x0370f, 0x03cc0, 0x02ea8, 0x058c6, 0x058c7,
838 0x02eb7, 0x058d0, 0x07d18, 0x0aa58, 0x0b848, 0x05d9e, 0x05d6c, 0x0b84c,
839 0x0c589, 0x0b901, 0x163f8, 0x0bac9, 0x0b9c5, 0x0f93c, 0x188d8, 0x0bbc7,
840 0x160ec, 0x0fd6f, 0x188d9, 0x160ea, 0x0f7a7, 0x0f944, 0x0baab, 0x0dc3a,
841 0x188cf, 0x176fb, 0x2c7d8, 0x2c7d7, 0x1bb75, 0x5ce9e, 0x62302, 0x370ed,
842 0x176f4, 0x1ffd1, 0x370ef, 0x3f4f8, 0x376c7, 0x1ffe1, 0x376c6, 0x176ff,
843 0x6e1d8, 0x176f6, 0x17087, 0x0f5cd, 0x00035, 0x001a0, 0x0058b, 0x00aac,
844 0x00b9a, 0x0175f, 0x01e22, 0x01e8c, 0x01fb2, 0x0310b, 0x058d1, 0x0552e,
845 0x05c27, 0x0686e, 0x07ca7, 0x0c474, 0x0dc33, 0x07bf2, 0x05de9, 0x07a35,
846 0x0baaa, 0x0b9eb, 0x0fb95, 0x0b9b8, 0x17381, 0x1f262, 0x188cd, 0x17088,
847 0x172fa, 0x0f7a2, 0x1fad3, 0x0bac0, 0x3765c, 0x1fedf, 0x1f225, 0x1fad4,
848 0x2c7da, 0x5ce9d, 0x3e7f8, 0x1e203, 0x188d7, 0x00054, 0x002c0, 0x007a1,
849 0x00f78, 0x01b36, 0x01fa3, 0x0313a, 0x03436, 0x0343a, 0x07d1d, 0x07bd8,
850 0x05cdf, 0x0b846, 0x0b189, 0x0d9b8, 0x0fff8, 0x0d9be, 0x0c58a, 0x05dea,
851 0x0d1d3, 0x160e4, 0x1f26b, 0x188da, 0x1e202, 0x2c7d2, 0x163fe, 0x31193,
852 0x17782, 0x376c2, 0x2c7d1, 0x3fdb0, 0x3765d, 0x2c7d0, 0x1fad0, 0x1e201,
853 0x188dd, 0x2c7e2, 0x37657, 0x37655, 0x376c4, 0x376c0, 0x176ea, 0x0006f,
854 0x003cf, 0x00dd5, 0x01f23, 0x02c61, 0x02ed0, 0x05d54, 0x0552d, 0x07883,
855 0x0b1a8, 0x0b91c, 0x0babf, 0x0b902, 0x0f7aa, 0x0f7a5, 0x1a1e8, 0x1ffd6,
856 0x0babe, 0x1a1bf, 0x163f3, 0x1ffd8, 0x1fad7, 0x1f275, 0x1ffdc, 0x0007d,
857 0x005bc, 0x01549, 0x02a99, 0x03def, 0x06273, 0x079d6, 0x07d1b, 0x0aad3,
858 0x0d0fc, 0x2c7dd, 0x188d6, 0x0bac2, 0x2c7e1, 0x1bb76, 0x1a1bd, 0x31186,
859 0x0fd78, 0x1a1be, 0x31183, 0x3fdb6, 0x3f4f1, 0x37652, 0x1fad5, 0x3f4f9,
860 0x3e7ff, 0x5ce9c, 0x3765b, 0x31188, 0x17372, 0x000bd, 0x0078b, 0x01f21,
861 0x03c43, 0x03ded, 0x0aad6, 0x07ec1, 0x0f942, 0x05c86, 0x17089, 0x0babb,
862 0x1ffe8, 0x2c7de, 0x1f26e, 0x1fac4, 0x3f4f7, 0x37656, 0x1fa7d, 0x376c3,
863 0x3fdb3, 0x3118f, 0x1fac6, 0x000f8, 0x007ed, 0x01efd, 0x03e7a, 0x05c91,
864 0x0aad9, 0x0baec, 0x0dc32, 0x0f46e, 0x1e200, 0x176fa, 0x3765e, 0x3fdb7,
865 0x2c7d6, 0x3fdb9, 0x37654, 0x37658, 0x3118e, 0x1ffdb, 0x000f6, 0x00c43,
866 0x03106, 0x068ef, 0x0b84d, 0x0b188, 0x0bbcc, 0x1f264, 0x1bb69, 0x17386,
867 0x1fac0, 0x00171, 0x00f39, 0x03e41, 0x068ed, 0x0d9bc, 0x0f7a1, 0x1bb67,
868 0x1ffdd, 0x176f9, 0x001b9, 0x00f7d, 0x03f63, 0x0d0fd, 0x0b9ea, 0x188dc,
869 0x1fac3, 0x1a1f2, 0x31192, 0x1ffe4, 0x001f6, 0x01754, 0x06865, 0x0f309,
870 0x160e5, 0x176f5, 0x3765f, 0x1facc, 0x001e9, 0x01a1a, 0x06201, 0x0f105,
871 0x176f0, 0x002df, 0x01756, 0x05d6d, 0x163fa, 0x176ed, 0x00342, 0x02e40,
872 0x0d0ff, 0x17082, 0x003cd, 0x02a98, 0x0fffc, 0x2c7dc, 0x1fa7f, 0x003fe,
873 0x03764, 0x0fffd, 0x176fc, 0x1fac5, 0x002f7, 0x02ed1, 0x0fb97, 0x0058a,
874 0x02edc, 0x0bbc8, 0x005d4, 0x0623d, 0x160e8, 0x0062e, 0x05830, 0x163f9,
875 0x006eb, 0x06205, 0x1f274, 0x007de, 0x062c9, 0x1f265, 0x005c9, 0x05cde,
876 0x1ffd3, 0x005d4, 0x07988, 0x007ce, 0x0b849, 0x00b1b, 0x05c89, 0x1fac7,
877 0x00b93, 0x05c83, 0x00b9e, 0x0f14f, 0x00c4a, 0x0b9c7, 0x00dd4, 0x0c470,
878 0x1f271, 0x00f38, 0x0fb96, 0x176eb, 0x00fa0, 0x163f7, 0x00bb2, 0x0b91b,
879 0x00bbe, 0x0f102, 0x00f44, 0x0f946, 0x1facd, 0x00f79, 0x0d9bd, 0x0154d,
880 0x0bbc6, 0x00fd2, 0x160e7, 0x0172b, 0x188cb, 0x0175e, 0x0fd76, 0x0175c,
881 0x1bb71, 0x0189f, 0x1a1ee, 0x01f24, 0x1a1f6, 0x01ba7, 0x0bbca, 0x01f7d,
882 0x0ffff, 0x01f2e, 0x1bb65, 0x01bb5, 0x172f9, 0x01fef, 0x1f26c, 0x01f3e,
883 0x0fd77, 0x01762, 0x1bb6e, 0x01ef9, 0x172fc, 0x01fa0, 0x02ab7, 0x02e4a,
884 0x1f267, 0x01fb3, 0x1ffda, 0x02e42, 0x03101, 0x17780, 0x0313d, 0x03475,
885 0x17784, 0x03126, 0x1facf, 0x03c51, 0x17783, 0x03e40, 0x1ffe5, 0x03663,
886 0x1ffe0, 0x03e8f, 0x1f26d, 0x0343c, 0x03cc1, 0x176fd, 0x03e45, 0x02ec0,
887 0x03f61, 0x03dee, 0x03fd8, 0x0583e, 0x02e45, 0x03e59, 0x03d02, 0x05ce8,
888 0x05568, 0x176fe, 0x02f69, 0x1fad8, 0x058c1, 0x05c83, 0x1ffe6, 0x06271,
889 0x06e1c, 0x062c7, 0x068e1, 0x0552f, 0x06864, 0x06866, 0x06e99, 0x05cbc,
890 0x07ca5, 0x078a1, 0x05c82, 0x07dcf, 0x0623b, 0x0623e, 0x068e8, 0x07a36,
891 0x05d9c, 0x0b077, 0x07cf3, 0x07a34, 0x07ca4, 0x07d19, 0x079d2, 0x07d1c,
892 0x07bd9, 0x0b84a, 0x0fb94, 0x0aad5, 0x0dc30, 0x07bf3, 0x0baee, 0x0b07a,
893 0x0c472, 0x0b91e, 0x0d9ba, 0x05d9f, 0x0d0fe, 0x0b9c6, 0x05c87, 0x0f14e,
894 0x0baed, 0x0b92e, 0x0f103, 0x0b9c4, 0x0fb91, 0x0d9bb, 0x0b1ab, 0x0c58d,
895 0x0fffe, 0x0f93b, 0x0f941, 0x0baea, 0x0b91f, 0x0f5cc, 0x0d9bf, 0x0f943,
896 0x0f104, 0x1f260, 0x0fb92, 0x0f93f, 0x0f3a6, 0x0bac7, 0x0f7ab, 0x0bac6,
897 0x17383, 0x0fd6d, 0x0bae9, 0x0fd6e, 0x1e74f, 0x188ca, 0x1f227, 0x0fb93,
898 0x0fb90, 0x0fff7, 0x17085, 0x17083, 0x160e1, 0x17084, 0x0f93e, 0x160e2,
899 0x160c6, 0x1a1f1, 0x1bb6f, 0x17384, 0x0fd70, 0x1f263, 0x188d5, 0x173a6,
900 0x0f5ce, 0x163f2, 0x0fd71, 0x1ffd2, 0x160c4, 0x1ffd4, 0x2c7d3, 0x1bb74,
901};
902
903static const uint8_t coef3_huffbits[1072] = {
904 9, 7, 2, 3, 4, 4, 5, 5,
905 6, 6, 6, 6, 7, 7, 7, 7,
906 7, 8, 8, 8, 8, 8, 8, 8,
907 9, 9, 9, 9, 9, 9, 9, 9,
908 9, 10, 10, 10, 10, 10, 10, 10,
909 10, 10, 10, 11, 11, 11, 11, 11,
910 11, 11, 11, 11, 11, 11, 11, 11,
911 11, 12, 11, 12, 12, 12, 12, 12,
912 12, 12, 12, 12, 12, 12, 12, 12,
913 12, 12, 12, 12, 12, 13, 13, 13,
914 13, 13, 13, 13, 13, 13, 13, 13,
915 13, 13, 13, 13, 13, 13, 13, 13,
916 13, 14, 13, 14, 14, 13, 14, 13,
917 13, 14, 14, 14, 14, 14, 14, 14,
918 14, 14, 14, 14, 14, 14, 14, 14,
919 14, 14, 14, 14, 14, 14, 14, 15,
920 14, 14, 15, 14, 14, 15, 15, 15,
921 15, 15, 15, 15, 15, 15, 14, 15,
922 15, 15, 15, 15, 15, 15, 15, 15,
923 15, 14, 15, 15, 15, 15, 15, 15,
924 15, 15, 15, 16, 15, 16, 16, 16,
925 16, 15, 15, 16, 16, 16, 16, 16,
926 15, 16, 16, 16, 15, 16, 15, 15,
927 16, 15, 16, 16, 16, 16, 16, 16,
928 16, 16, 16, 16, 16, 16, 16, 16,
929 16, 17, 16, 17, 16, 17, 17, 16,
930 17, 16, 17, 16, 16, 17, 17, 17,
931 16, 17, 16, 16, 17, 16, 17, 16,
932 17, 17, 16, 16, 17, 17, 17, 17,
933 17, 17, 17, 17, 16, 17, 17, 16,
934 17, 17, 17, 17, 17, 17, 17, 17,
935 16, 18, 17, 17, 17, 17, 17, 17,
936 17, 17, 17, 17, 17, 17, 16, 17,
937 17, 17, 17, 17, 17, 17, 17, 17,
938 17, 17, 17, 17, 17, 17, 17, 18,
939 17, 17, 17, 17, 18, 17, 17, 18,
940 19, 17, 17, 17, 18, 17, 17, 17,
941 18, 18, 18, 17, 17, 17, 18, 17,
942 17, 17, 17, 17, 17, 17, 17, 17,
943 18, 18, 18, 18, 18, 18, 18, 18,
944 18, 18, 17, 18, 18, 18, 18, 17,
945 18, 18, 18, 17, 17, 18, 18, 18,
946 18, 19, 18, 18, 19, 19, 20, 18,
947 19, 18, 19, 19, 18, 19, 20, 18,
948 19, 4, 6, 7, 8, 9, 9, 9,
949 10, 10, 10, 11, 11, 11, 11, 12,
950 12, 12, 12, 12, 12, 13, 13, 13,
951 13, 13, 13, 13, 13, 14, 14, 14,
952 14, 14, 14, 14, 14, 14, 14, 14,
953 14, 14, 14, 15, 15, 15, 15, 15,
954 15, 15, 15, 15, 16, 15, 15, 15,
955 15, 16, 16, 15, 16, 16, 15, 16,
956 17, 17, 17, 17, 17, 16, 16, 16,
957 16, 16, 17, 17, 17, 16, 18, 17,
958 17, 17, 18, 17, 17, 18, 17, 17,
959 17, 17, 17, 18, 17, 18, 18, 18,
960 17, 17, 18, 19, 18, 18, 17, 17,
961 18, 18, 18, 18, 19, 17, 17, 18,
962 20, 19, 19, 18, 19, 18, 19, 19,
963 19, 19, 17, 5, 7, 9, 10, 10,
964 11, 11, 12, 12, 12, 13, 13, 13,
965 13, 13, 14, 14, 14, 14, 14, 15,
966 14, 15, 15, 15, 15, 15, 16, 16,
967 16, 16, 16, 16, 16, 16, 16, 16,
968 16, 16, 15, 16, 16, 17, 17, 17,
969 16, 17, 17, 17, 17, 17, 17, 17,
970 17, 17, 17, 17, 17, 17, 17, 16,
971 16, 19, 18, 18, 19, 17, 19, 20,
972 17, 18, 18, 18, 18, 18, 18, 6,
973 8, 10, 11, 12, 12, 12, 13, 13,
974 13, 14, 14, 14, 14, 15, 15, 15,
975 15, 15, 15, 16, 16, 16, 16, 16,
976 16, 17, 17, 17, 16, 16, 17, 17,
977 17, 17, 17, 17, 17, 16, 16, 16,
978 17, 18, 18, 18, 17, 19, 19, 18,
979 18, 17, 18, 19, 18, 17, 18, 18,
980 19, 18, 17, 17, 6, 9, 11, 12,
981 13, 13, 13, 14, 14, 14, 15, 15,
982 15, 15, 15, 16, 16, 16, 16, 16,
983 16, 17, 16, 17, 17, 17, 17, 17,
984 17, 17, 18, 17, 18, 17, 17, 18,
985 18, 19, 19, 17, 17, 7, 10, 12,
986 13, 13, 14, 14, 14, 14, 15, 16,
987 16, 16, 16, 16, 16, 16, 16, 16,
988 16, 17, 17, 17, 17, 18, 17, 18,
989 18, 18, 18, 18, 18, 18, 18, 17,
990 17, 18, 18, 18, 18, 18, 18, 7,
991 10, 12, 13, 14, 15, 15, 15, 15,
992 16, 16, 17, 17, 17, 17, 17, 17,
993 17, 17, 17, 17, 18, 17, 17, 8,
994 11, 13, 14, 15, 15, 15, 15, 16,
995 16, 18, 17, 17, 18, 17, 17, 18,
996 17, 17, 18, 18, 19, 18, 18, 19,
997 19, 19, 18, 18, 18, 8, 11, 13,
998 14, 15, 16, 16, 16, 16, 17, 17,
999 17, 18, 17, 18, 19, 18, 18, 18,
1000 18, 18, 18, 8, 12, 14, 15, 15,
1001 16, 16, 16, 17, 17, 18, 18, 18,
1002 18, 18, 18, 18, 18, 17, 9, 12,
1003 14, 15, 16, 16, 17, 17, 17, 17,
1004 18, 9, 12, 14, 15, 16, 17, 17,
1005 17, 18, 9, 13, 15, 16, 17, 17,
1006 18, 17, 18, 17, 9, 13, 15, 16,
1007 17, 18, 18, 18, 10, 13, 15, 16,
1008 18, 10, 14, 16, 17, 18, 10, 14,
1009 16, 17, 10, 14, 16, 18, 18, 10,
1010 14, 16, 18, 18, 11, 15, 16, 11,
1011 15, 17, 11, 15, 17, 11, 15, 17,
1012 11, 15, 17, 11, 15, 17, 12, 16,
1013 17, 12, 15, 12, 16, 12, 16, 18,
1014 12, 16, 12, 16, 12, 16, 12, 16,
1015 17, 12, 16, 18, 12, 17, 13, 16,
1016 13, 16, 13, 16, 18, 13, 16, 13,
1017 17, 13, 17, 13, 17, 13, 17, 13,
1018 17, 13, 17, 13, 17, 13, 17, 13,
1019 16, 13, 17, 13, 17, 13, 17, 14,
1020 17, 14, 17, 14, 17, 14, 14, 14,
1021 17, 14, 17, 14, 14, 18, 14, 14,
1022 18, 14, 18, 14, 18, 14, 17, 14,
1023 17, 14, 17, 14, 14, 18, 14, 15,
1024 15, 15, 14, 15, 15, 14, 15, 15,
1025 15, 18, 15, 18, 15, 15, 17, 15,
1026 15, 15, 15, 15, 15, 15, 15, 15,
1027 15, 15, 16, 15, 15, 15, 15, 16,
1028 16, 16, 16, 16, 15, 15, 15, 15,
1029 16, 16, 16, 16, 16, 16, 16, 16,
1030 16, 16, 16, 16, 16, 16, 16, 16,
1031 16, 16, 16, 16, 16, 16, 16, 16,
1032 16, 16, 16, 16, 16, 17, 16, 16,
1033 16, 17, 16, 16, 16, 17, 17, 17,
1034 17, 17, 16, 17, 17, 17, 17, 16,
1035 16, 16, 17, 17, 17, 17, 16, 17,
1036 17, 17, 17, 17, 17, 17, 17, 17,
1037 17, 17, 17, 17, 17, 17, 18, 17,
1038};
1039
1040static const uint32_t coef4_huffcodes[476] = {
1041 0x00f01, 0x0001e, 0x00000, 0x00004, 0x00006, 0x0000d, 0x0000a, 0x00017,
1042 0x0001d, 0x00017, 0x0002c, 0x00031, 0x00039, 0x0003e, 0x00039, 0x0005a,
1043 0x00066, 0x00070, 0x0007b, 0x00070, 0x00077, 0x000af, 0x000c9, 0x000f2,
1044 0x000f4, 0x000b2, 0x000e3, 0x0015b, 0x0015d, 0x00181, 0x0019d, 0x001e3,
1045 0x001c5, 0x002b5, 0x002db, 0x00338, 0x003c3, 0x003cc, 0x003f0, 0x002cd,
1046 0x003fa, 0x003a1, 0x005b4, 0x00657, 0x007ab, 0x0074d, 0x0074c, 0x00ac1,
1047 0x00ac5, 0x0076b, 0x00ca8, 0x00f04, 0x00f00, 0x00fe3, 0x00f3c, 0x00f10,
1048 0x00f39, 0x00fe6, 0x00e26, 0x00e90, 0x016c5, 0x01827, 0x01954, 0x015c5,
1049 0x01958, 0x01f8a, 0x01c4a, 0x02b0f, 0x02b41, 0x02b0e, 0x033c6, 0x03050,
1050 0x01c4f, 0x02d88, 0x0305c, 0x03c18, 0x02b4f, 0x02cc2, 0x03a47, 0x05680,
1051 0x0569d, 0x06442, 0x06443, 0x06446, 0x0656e, 0x06444, 0x07120, 0x0748a,
1052 0x0c1ba, 0x07e22, 0x07aa6, 0x07f25, 0x07aa7, 0x07e20, 0x0c11b, 0x0c118,
1053 0x07aa5, 0x0ad0a, 0x0f389, 0x19ebb, 0x0caad, 0x0fe42, 0x0fe40, 0x16c34,
1054 0x2b4e5, 0x33d65, 0x16c30, 0x1e7ae, 0x1e25c, 0x18370, 0x1e703, 0x19eba,
1055 0x16c37, 0x0e234, 0x16c6e, 0x00004, 0x0002a, 0x00061, 0x00075, 0x000cb,
1056 0x000ff, 0x00190, 0x001eb, 0x001d1, 0x002b9, 0x00307, 0x00339, 0x0033f,
1057 0x003fb, 0x003b4, 0x0060c, 0x00679, 0x00645, 0x0067d, 0x0078a, 0x007e3,
1058 0x00749, 0x00ac4, 0x00ad2, 0x00ae3, 0x00c10, 0x00c16, 0x00ad1, 0x00cf4,
1059 0x00fe2, 0x01586, 0x00e9d, 0x019f1, 0x01664, 0x01e26, 0x01d38, 0x02b4d,
1060 0x033c5, 0x01fc2, 0x01fc3, 0x01d28, 0x03c1d, 0x0598e, 0x0f094, 0x07aa4,
1061 0x0ad38, 0x0ac0c, 0x0c11a, 0x079ea, 0x0c881, 0x0fe44, 0x0b635, 0x0ac0d,
1062 0x0b61e, 0x05987, 0x07121, 0x0f382, 0x0f387, 0x0e237, 0x0fe47, 0x0f383,
1063 0x0f091, 0x0f385, 0x0e233, 0x182ee, 0x19eb8, 0x1663e, 0x0f093, 0x00014,
1064 0x00058, 0x00159, 0x00167, 0x00300, 0x003d4, 0x005b5, 0x0079d, 0x0076a,
1065 0x00b67, 0x00b60, 0x00f05, 0x00cf0, 0x00f17, 0x00e95, 0x01822, 0x01913,
1066 0x016c2, 0x0182f, 0x01959, 0x01fcb, 0x01e27, 0x01c40, 0x033c7, 0x01e7b,
1067 0x01c49, 0x02d89, 0x01e23, 0x01660, 0x03f12, 0x02cc6, 0x033e1, 0x05b34,
1068 0x0609a, 0x06569, 0x07488, 0x07e21, 0x0cf5f, 0x0712c, 0x0389d, 0x067cf,
1069 0x07f28, 0x1663f, 0x33d67, 0x1663d, 0x1e25d, 0x3c1ab, 0x15c44, 0x16c36,
1070 0x0001f, 0x000ec, 0x00323, 0x005b2, 0x0079f, 0x00ac2, 0x00f16, 0x00e9e,
1071 0x01956, 0x01e0f, 0x019ea, 0x01666, 0x02b89, 0x02b02, 0x02d8c, 0x03c1b,
1072 0x03c19, 0x032b5, 0x03f9c, 0x02ccf, 0x03897, 0x05b35, 0x0ad02, 0x07f29,
1073 0x06441, 0x03884, 0x07888, 0x0784e, 0x06568, 0x0c1bb, 0x05986, 0x067cc,
1074 0x0fe49, 0x0fe48, 0x0c1bc, 0x0fe41, 0x18371, 0x1663c, 0x0e231, 0x0711e,
1075 0x0ad09, 0x0f092, 0x0002d, 0x001db, 0x00781, 0x00c1a, 0x00f55, 0x01580,
1076 0x01ea8, 0x02d9b, 0x032af, 0x03f16, 0x03c1c, 0x07834, 0x03c45, 0x0389c,
1077 0x067ce, 0x06445, 0x0c1b9, 0x07889, 0x07f3a, 0x0784f, 0x07f2b, 0x0ad0b,
1078 0x0f090, 0x0c11d, 0x0e94e, 0x0711f, 0x0e9f1, 0x0f38e, 0x079e9, 0x0ad03,
1079 0x0f09b, 0x0caae, 0x0fe46, 0x2b4e6, 0x0e9f0, 0x19eb6, 0x67ac1, 0x67ac0,
1080 0x33d66, 0x0f388, 0x00071, 0x003a0, 0x00ca9, 0x01829, 0x01d39, 0x02b43,
1081 0x02cc4, 0x06554, 0x0f09a, 0x0b61f, 0x067cd, 0x0711c, 0x0b636, 0x07f2a,
1082 0x0b634, 0x0c11f, 0x0cf5e, 0x0b61d, 0x0f06b, 0x0caab, 0x0c1be, 0x0e94c,
1083 0x0f099, 0x182ed, 0x0e94f, 0x0c119, 0x0e232, 0x2b4e4, 0x0f38a, 0x19eb4,
1084 0x1e25f, 0x0e94d, 0x000b7, 0x00785, 0x016cc, 0x03051, 0x033c4, 0x0656f,
1085 0x03891, 0x0711d, 0x0caaf, 0x0f097, 0x07489, 0x0f098, 0x0c880, 0x0caaa,
1086 0x0f386, 0x19eb7, 0x16c6f, 0x0f384, 0x182e8, 0x182e9, 0x0e230, 0x1e700,
1087 0x33d62, 0x33d63, 0x33d64, 0x16c33, 0x0e216, 0x000fd, 0x00c15, 0x01665,
1088 0x03c4a, 0x07f3b, 0x07896, 0x0c11c, 0x0e215, 0x16c32, 0x0f38b, 0x0f38d,
1089 0x182ea, 0x1e701, 0x712df, 0x15c46, 0x00194, 0x00fe0, 0x03f13, 0x0748b,
1090 0x0f096, 0x0cf80, 0x1e25e, 0xe25bd, 0x33d61, 0x16c31, 0x001f9, 0x01912,
1091 0x05710, 0x0f3d0, 0x0c1bf, 0x00301, 0x01e24, 0x0ad08, 0x003cd, 0x01c41,
1092 0x0c1bd, 0x00563, 0x03a52, 0x0f3d1, 0x00570, 0x02cce, 0x0e217, 0x0067b,
1093 0x0655d, 0x0074b, 0x06447, 0x00c12, 0x074fb, 0x00f08, 0x0b61c, 0x00e22,
1094 0x0fe43, 0x016c7, 0x01836, 0x019f2, 0x01c43, 0x01d3f, 0x01fcf, 0x02b4c,
1095 0x0304c, 0x032b6, 0x03a46, 0x05607, 0x03f17, 0x02cc5, 0x0609b, 0x0655c,
1096 0x07e23, 0x067c1, 0x07f26, 0x07f27, 0x0f095, 0x0e9f3, 0x0cf81, 0x0c11e,
1097 0x0caac, 0x0f38f, 0x0e9f2, 0x074fa, 0x0e236, 0x0fe45, 0x1c428, 0x0e235,
1098 0x182ef, 0x19eb5, 0x0f3d6, 0x182ec, 0x16c35, 0x0f38c, 0x2b4e7, 0x15c47,
1099 0xe25bc, 0x1e702, 0x1c4b6, 0x0e25a, 0x3c1aa, 0x15c45, 0x1c429, 0x19eb9,
1100 0x1e7af, 0x182eb, 0x1e0d4, 0x3896e,
1101};
1102
1103static const uint8_t coef4_huffbits[476] = {
1104 12, 6, 2, 3, 4, 4, 5, 5,
1105 5, 6, 6, 6, 6, 6, 7, 7,
1106 7, 7, 7, 8, 8, 8, 8, 8,
1107 8, 9, 9, 9, 9, 9, 9, 9,
1108 10, 10, 10, 10, 10, 10, 10, 11,
1109 10, 11, 11, 11, 11, 12, 12, 12,
1110 12, 12, 12, 12, 12, 12, 12, 12,
1111 12, 12, 13, 13, 13, 13, 13, 13,
1112 13, 13, 14, 14, 14, 14, 14, 14,
1113 14, 14, 14, 14, 14, 15, 15, 15,
1114 15, 15, 15, 15, 15, 15, 16, 16,
1115 16, 15, 15, 15, 15, 15, 16, 16,
1116 15, 16, 16, 17, 16, 16, 16, 17,
1117 18, 18, 17, 17, 17, 17, 17, 17,
1118 17, 17, 17, 4, 6, 7, 8, 8,
1119 8, 9, 9, 10, 10, 10, 10, 10,
1120 10, 11, 11, 11, 11, 11, 11, 11,
1121 12, 12, 12, 12, 12, 12, 12, 12,
1122 12, 13, 13, 13, 14, 13, 14, 14,
1123 14, 13, 13, 14, 14, 16, 16, 15,
1124 16, 16, 16, 15, 16, 16, 16, 16,
1125 16, 16, 16, 16, 16, 17, 16, 16,
1126 16, 16, 17, 17, 17, 18, 16, 5,
1127 8, 9, 10, 10, 10, 11, 11, 12,
1128 12, 12, 12, 12, 12, 13, 13, 13,
1129 13, 13, 13, 13, 13, 14, 14, 13,
1130 14, 14, 13, 14, 14, 15, 14, 15,
1131 15, 15, 16, 15, 16, 16, 15, 15,
1132 15, 18, 18, 18, 17, 18, 17, 17,
1133 6, 9, 10, 11, 11, 12, 12, 13,
1134 13, 13, 13, 14, 14, 14, 14, 14,
1135 14, 14, 14, 15, 15, 15, 16, 15,
1136 15, 15, 15, 15, 15, 16, 16, 15,
1137 16, 16, 16, 16, 17, 18, 17, 16,
1138 16, 16, 7, 10, 11, 12, 12, 13,
1139 13, 14, 14, 14, 14, 15, 14, 15,
1140 15, 15, 16, 15, 15, 15, 15, 16,
1141 16, 16, 17, 16, 17, 16, 15, 16,
1142 16, 16, 16, 18, 17, 17, 19, 19,
1143 18, 16, 7, 11, 12, 13, 14, 14,
1144 15, 15, 16, 16, 15, 16, 16, 15,
1145 16, 16, 16, 16, 16, 16, 16, 17,
1146 16, 17, 17, 16, 17, 18, 16, 17,
1147 17, 17, 8, 11, 13, 14, 14, 15,
1148 15, 16, 16, 16, 16, 16, 16, 16,
1149 16, 17, 17, 16, 17, 17, 17, 17,
1150 18, 18, 18, 17, 17, 8, 12, 14,
1151 14, 15, 15, 16, 17, 17, 16, 16,
1152 17, 17, 20, 17, 9, 12, 14, 16,
1153 16, 16, 17, 21, 18, 17, 9, 13,
1154 15, 16, 16, 10, 13, 16, 10, 14,
1155 16, 11, 15, 16, 11, 15, 17, 11,
1156 15, 12, 15, 12, 16, 12, 16, 13,
1157 16, 13, 13, 13, 14, 14, 13, 14,
1158 14, 14, 15, 15, 14, 15, 15, 15,
1159 15, 15, 15, 15, 16, 17, 16, 16,
1160 16, 16, 17, 16, 17, 16, 18, 17,
1161 17, 17, 16, 17, 17, 16, 18, 17,
1162 21, 17, 18, 17, 18, 17, 18, 17,
1163 17, 17, 17, 19,
1164};
1165
1166static const uint32_t coef5_huffcodes[435] = {
1167 0x00347, 0x0000b, 0x00001, 0x00001, 0x0000c, 0x00004, 0x00010, 0x00015,
1168 0x0001f, 0x0000b, 0x00023, 0x00026, 0x00029, 0x00035, 0x00037, 0x00001,
1169 0x00015, 0x0001a, 0x0001d, 0x0001c, 0x0001e, 0x0004e, 0x00049, 0x00051,
1170 0x00078, 0x00004, 0x00000, 0x00008, 0x0000d, 0x0007b, 0x00005, 0x00032,
1171 0x00095, 0x00091, 0x00096, 0x000a1, 0x000d9, 0x00003, 0x00019, 0x00061,
1172 0x00066, 0x00060, 0x00017, 0x0000e, 0x00063, 0x001a0, 0x001b7, 0x001e6,
1173 0x001e7, 0x001b6, 0x00018, 0x001e8, 0x00038, 0x00031, 0x00005, 0x0003d,
1174 0x00027, 0x001ea, 0x0001a, 0x000c5, 0x000f9, 0x000ff, 0x000db, 0x00250,
1175 0x000fc, 0x0025c, 0x00008, 0x00075, 0x003d7, 0x003d3, 0x001b0, 0x0007c,
1176 0x003ca, 0x00036, 0x00189, 0x004a6, 0x004a2, 0x004fb, 0x000c0, 0x0007f,
1177 0x0009a, 0x00311, 0x0006e, 0x0009b, 0x0068c, 0x006c0, 0x00484, 0x00012,
1178 0x000c3, 0x0094f, 0x00979, 0x009f9, 0x00d09, 0x00da6, 0x00da8, 0x00901,
1179 0x000c1, 0x00373, 0x00d08, 0x009fa, 0x00d8b, 0x00d85, 0x00d86, 0x000df,
1180 0x006e2, 0x000ce, 0x00f24, 0x009fe, 0x001f7, 0x007c1, 0x000cf, 0x009fc,
1181 0x009ff, 0x00d89, 0x00da9, 0x009fd, 0x001f8, 0x01a36, 0x0128c, 0x0129d,
1182 0x01a37, 0x00196, 0x003ea, 0x00f8b, 0x00d93, 0x01e45, 0x01e58, 0x01e4b,
1183 0x01e59, 0x013f1, 0x00309, 0x00265, 0x00308, 0x0243a, 0x027e1, 0x00f89,
1184 0x00324, 0x03cbc, 0x03c86, 0x03695, 0x0243c, 0x0243b, 0x0243e, 0x01e4a,
1185 0x003a5, 0x03468, 0x03428, 0x03c84, 0x027e0, 0x025e2, 0x01880, 0x00197,
1186 0x00325, 0x03cb7, 0x0791e, 0x007ec, 0x06c75, 0x004c8, 0x04bc7, 0x004c6,
1187 0x00983, 0x0481e, 0x01b53, 0x0251b, 0x01b58, 0x00984, 0x04fa8, 0x03cbb,
1188 0x00f8a, 0x00322, 0x0346a, 0x0243d, 0x00326, 0x03469, 0x0481f, 0x0481d,
1189 0x00746, 0x09032, 0x01b50, 0x01d13, 0x0d8e4, 0x0481b, 0x06c74, 0x0796b,
1190 0x07969, 0x00985, 0x0d8e3, 0x00986, 0x00fa2, 0x01301, 0x06c7c, 0x00987,
1191 0x03cb8, 0x0f4af, 0x00e88, 0x1b1c0, 0x00fce, 0x033eb, 0x03f6a, 0x03f69,
1192 0x00fcf, 0x0791f, 0x004c9, 0x04871, 0x00fcd, 0x00982, 0x00fcc, 0x00fa3,
1193 0x01d12, 0x0796c, 0x01b47, 0x00321, 0x0796a, 0x0d8e2, 0x04872, 0x04873,
1194 0x0000e, 0x00014, 0x0000a, 0x000a0, 0x00012, 0x0007d, 0x001a2, 0x0003b,
1195 0x0025f, 0x000dd, 0x0027c, 0x00343, 0x00368, 0x0036b, 0x0003e, 0x001fa,
1196 0x00485, 0x001b3, 0x0007f, 0x001b1, 0x0019e, 0x004ba, 0x007ad, 0x00339,
1197 0x00066, 0x007a4, 0x00793, 0x006c6, 0x0007e, 0x000f1, 0x00372, 0x009fb,
1198 0x00d83, 0x00d8a, 0x00947, 0x009f4, 0x001d0, 0x01b09, 0x01b4b, 0x007ec,
1199 0x003e1, 0x000ca, 0x003ec, 0x02539, 0x04fa9, 0x01b57, 0x03429, 0x03d2a,
1200 0x00d97, 0x003a7, 0x00dc0, 0x00d96, 0x00dc1, 0x007eb, 0x03cba, 0x00c43,
1201 0x00c41, 0x01b52, 0x007ef, 0x00323, 0x03cb9, 0x03c83, 0x007d0, 0x007ed,
1202 0x06c7f, 0x09033, 0x03f6c, 0x36383, 0x1e95d, 0x06c78, 0x00747, 0x01b51,
1203 0x00022, 0x00016, 0x00039, 0x00252, 0x00079, 0x00486, 0x00338, 0x00369,
1204 0x00d88, 0x00026, 0x00d87, 0x00f4b, 0x00d82, 0x00027, 0x001e1, 0x01a15,
1205 0x007c7, 0x012f0, 0x001e0, 0x006d0, 0x01a16, 0x01e44, 0x01e5f, 0x03690,
1206 0x00d90, 0x00c42, 0x00daf, 0x00d92, 0x00f80, 0x00cfb, 0x0342f, 0x0487f,
1207 0x01b46, 0x07968, 0x00d95, 0x00d91, 0x01b55, 0x03f68, 0x04bc6, 0x03cbd,
1208 0x00f81, 0x00320, 0x00069, 0x000fe, 0x006d5, 0x0033f, 0x000de, 0x007c6,
1209 0x01e40, 0x00d94, 0x00f88, 0x03c8e, 0x03694, 0x00dae, 0x00dad, 0x00267,
1210 0x003a6, 0x00327, 0x0487e, 0x007ee, 0x00749, 0x004c7, 0x03692, 0x01b56,
1211 0x00fd1, 0x07a56, 0x06c77, 0x09031, 0x00748, 0x06c7a, 0x0796d, 0x033ea,
1212 0x06c76, 0x00fd0, 0x36382, 0x1e417, 0x00745, 0x04faf, 0x0d8e1, 0x03f6b,
1213 0x1e95c, 0x04fad, 0x0009e, 0x004bd, 0x0067c, 0x01b08, 0x003eb, 0x01b45,
1214 0x03691, 0x0d8e5, 0x07904, 0x00981, 0x007ea, 0x019f4, 0x06c7d, 0x04fab,
1215 0x04fac, 0x06c7e, 0x01300, 0x06c7b, 0x0006f, 0x003f7, 0x03c85, 0x004c4,
1216 0x0001e, 0x006e1, 0x03693, 0x01b44, 0x00241, 0x01e46, 0x0019d, 0x00266,
1217 0x004bb, 0x02538, 0x007ac, 0x01b54, 0x00902, 0x04870, 0x00da7, 0x00900,
1218 0x00185, 0x06c79, 0x006e3, 0x003e9, 0x01e94, 0x003ed, 0x003f2, 0x0342e,
1219 0x0346b, 0x0251a, 0x004c5, 0x01881, 0x0481c, 0x01b59, 0x03c87, 0x04fae,
1220 0x007e9, 0x03f6d, 0x0f20a, 0x09030, 0x04faa, 0x0d8e6, 0x03f6f, 0x0481a,
1221 0x03f6e, 0x1e416, 0x0d8e7,
1222};
1223
1224static const uint8_t coef5_huffbits[435] = {
1225 10, 4, 2, 4, 4, 5, 5, 5,
1226 5, 6, 6, 6, 6, 6, 6, 7,
1227 7, 7, 7, 7, 7, 7, 7, 7,
1228 7, 8, 8, 8, 8, 7, 8, 8,
1229 8, 8, 8, 8, 8, 9, 9, 9,
1230 9, 9, 9, 9, 9, 9, 9, 9,
1231 9, 9, 10, 9, 10, 10, 10, 10,
1232 10, 9, 10, 10, 10, 10, 10, 10,
1233 10, 10, 11, 11, 10, 10, 11, 11,
1234 10, 11, 11, 11, 11, 11, 12, 12,
1235 12, 12, 12, 12, 11, 11, 11, 12,
1236 12, 12, 12, 12, 12, 12, 12, 12,
1237 12, 12, 12, 12, 12, 12, 12, 13,
1238 13, 13, 12, 12, 13, 13, 13, 12,
1239 12, 12, 12, 12, 13, 13, 13, 13,
1240 13, 14, 14, 14, 14, 13, 13, 13,
1241 13, 13, 14, 14, 14, 14, 14, 14,
1242 15, 14, 14, 14, 14, 14, 14, 13,
1243 14, 14, 14, 14, 14, 14, 15, 14,
1244 15, 14, 15, 15, 15, 15, 15, 15,
1245 16, 15, 15, 14, 15, 16, 15, 14,
1246 14, 15, 14, 14, 15, 14, 15, 15,
1247 15, 16, 15, 17, 16, 15, 15, 15,
1248 15, 16, 16, 16, 16, 17, 15, 16,
1249 14, 16, 16, 17, 16, 16, 16, 16,
1250 16, 15, 15, 15, 16, 16, 16, 16,
1251 17, 15, 15, 15, 15, 16, 15, 15,
1252 4, 7, 8, 8, 9, 9, 9, 10,
1253 10, 10, 10, 10, 10, 10, 11, 11,
1254 11, 11, 11, 11, 11, 11, 11, 12,
1255 12, 11, 11, 11, 12, 12, 12, 12,
1256 12, 12, 12, 12, 13, 13, 13, 13,
1257 12, 13, 14, 14, 15, 15, 14, 14,
1258 14, 14, 14, 14, 14, 15, 14, 14,
1259 14, 15, 15, 15, 14, 14, 15, 15,
1260 15, 16, 16, 18, 17, 15, 15, 15,
1261 6, 9, 10, 10, 11, 11, 12, 12,
1262 12, 13, 12, 12, 12, 13, 13, 13,
1263 13, 13, 13, 13, 13, 13, 13, 14,
1264 14, 14, 14, 14, 14, 14, 14, 15,
1265 15, 15, 14, 14, 15, 16, 15, 14,
1266 14, 15, 7, 10, 11, 12, 13, 13,
1267 13, 14, 14, 14, 14, 14, 14, 14,
1268 14, 15, 15, 15, 15, 15, 14, 15,
1269 16, 15, 15, 16, 15, 15, 15, 16,
1270 15, 16, 18, 17, 15, 15, 16, 16,
1271 17, 15, 8, 11, 13, 13, 14, 15,
1272 14, 16, 15, 16, 15, 15, 15, 15,
1273 15, 15, 17, 15, 9, 12, 14, 15,
1274 10, 13, 14, 15, 10, 13, 11, 14,
1275 11, 14, 11, 15, 12, 15, 12, 12,
1276 13, 15, 13, 14, 13, 14, 14, 14,
1277 14, 14, 15, 15, 15, 15, 14, 15,
1278 15, 16, 16, 16, 15, 16, 16, 15,
1279 16, 17, 16,
1280};
1281
1282static const uint16_t levels0[60] = {
1283317, 92, 62, 60, 19, 17, 10, 7,
1284 6, 5, 5, 3, 3, 3, 2, 2,
1285 2, 2, 2, 2, 2, 1, 2, 2,
1286 1, 1, 1, 1, 1, 1, 1, 1,
1287 1, 1, 1, 1, 1, 1, 1, 1,
1288 1, 1, 1, 1, 1, 1, 1, 1,
1289 1, 1, 1, 1, 1, 1, 1, 1,
1290 1, 1, 1, 1,
1291};
1292
1293static const uint16_t levels1[40] = {
1294311, 91, 61, 28, 10, 6, 5, 2,
1295 2, 2, 2, 2, 2, 2, 2, 1,
1296 1, 1, 1, 1, 1, 1, 1, 1,
1297 1, 1, 1, 1, 1, 1, 1, 1,
1298 1, 1, 1, 1, 1, 1, 1, 1,
1299};
1300
1301static const uint16_t levels2[340] = {
1302181,110, 78, 63, 61, 62, 60, 61,
1303 33, 41, 41, 19, 17, 19, 12, 11,
1304 9, 11, 10, 6, 8, 7, 6, 4,
1305 5, 5, 4, 4, 3, 4, 3, 5,
1306 3, 4, 3, 3, 3, 3, 3, 3,
1307 2, 2, 4, 2, 3, 2, 3, 3,
1308 2, 2, 2, 2, 2, 2, 2, 2,
1309 3, 2, 2, 2, 2, 2, 2, 2,
1310 2, 2, 2, 1, 2, 1, 2, 2,
1311 2, 2, 1, 2, 1, 1, 1, 2,
1312 2, 1, 2, 1, 2, 2, 2, 2,
1313 1, 1, 1, 1, 1, 1, 1, 1,
1314 1, 1, 1, 1, 1, 1, 1, 1,
1315 1, 1, 1, 1, 1, 1, 1, 1,
1316 1, 1, 1, 1, 1, 1, 1, 1,
1317 1, 1, 1, 1, 1, 1, 1, 1,
1318 1, 1, 1, 1, 1, 1, 1, 1,
1319 1, 1, 1, 1, 1, 1, 1, 1,
1320 1, 1, 1, 1, 1, 1, 1, 1,
1321 1, 1, 1, 1, 1, 1, 1, 1,
1322 1, 1, 1, 1, 1, 1, 1, 1,
1323 1, 1, 1, 1, 1, 1, 1, 1,
1324 1, 1, 1, 1, 1, 1, 1, 1,
1325 1, 1, 1, 1, 1, 1, 1, 1,
1326 1, 1, 1, 1, 1, 1, 1, 1,
1327 1, 1, 1, 1, 1, 1, 1, 1,
1328 1, 1, 1, 1, 1, 1, 1, 1,
1329 1, 1, 1, 1, 1, 1, 1, 1,
1330 1, 1, 1, 1, 1, 1, 1, 1,
1331 1, 1, 1, 1, 1, 1, 1, 1,
1332 1, 1, 1, 1, 1, 1, 1, 1,
1333 1, 1, 1, 1, 1, 1, 1, 1,
1334 1, 1, 1, 1, 1, 1, 1, 1,
1335 1, 1, 1, 1, 1, 1, 1, 1,
1336 1, 1, 1, 1, 1, 1, 1, 1,
1337 1, 1, 1, 1, 1, 1, 1, 1,
1338 1, 1, 1, 1, 1, 1, 1, 1,
1339 1, 1, 1, 1, 1, 1, 1, 1,
1340 1, 1, 1, 1, 1, 1, 1, 1,
1341 1, 1, 1, 1, 1, 1, 1, 1,
1342 1, 1, 1, 1, 1, 1, 1, 1,
1343 1, 1, 1, 1, 1, 1, 1, 1,
1344 1, 1, 1, 1,
1345};
1346
1347static const uint16_t levels3[180] = {
1348351,122, 76, 61, 41, 42, 24, 30,
1349 22, 19, 11, 9, 10, 8, 5, 5,
1350 4, 5, 5, 3, 3, 3, 3, 3,
1351 3, 3, 2, 2, 3, 2, 2, 2,
1352 3, 3, 2, 2, 2, 3, 2, 2,
1353 2, 2, 2, 2, 2, 2, 2, 2,
1354 2, 2, 2, 2, 2, 2, 1, 1,
1355 2, 2, 1, 2, 1, 2, 2, 2,
1356 2, 2, 2, 1, 2, 1, 1, 1,
1357 1, 1, 1, 1, 1, 1, 1, 2,
1358 2, 1, 2, 1, 1, 1, 1, 1,
1359 1, 1, 1, 1, 1, 1, 1, 1,
1360 1, 1, 1, 1, 1, 1, 1, 1,
1361 1, 1, 1, 1, 1, 1, 1, 1,
1362 1, 1, 1, 1, 1, 1, 1, 1,
1363 1, 1, 1, 1, 1, 1, 1, 1,
1364 1, 1, 1, 1, 1, 1, 1, 1,
1365 1, 1, 1, 1, 1, 1, 1, 1,
1366 1, 1, 1, 1, 1, 1, 1, 1,
1367 1, 1, 1, 1, 1, 1, 1, 1,
1368 1, 1, 1, 1, 1, 1, 1, 1,
1369 1, 1, 1, 1, 1, 1, 1, 1,
1370 1, 1, 1, 1,
1371};
1372
1373static const uint16_t levels4[70] = {
1374113, 68, 49, 42, 40, 32, 27, 15,
1375 10, 5, 3, 3, 3, 3, 2, 2,
1376 2, 2, 2, 1, 1, 1, 1, 1,
1377 1, 1, 1, 1, 1, 1, 1, 1,
1378 1, 1, 1, 1, 1, 1, 1, 1,
1379 1, 1, 1, 1, 1, 1, 1, 1,
1380 1, 1, 1, 1, 1, 1, 1, 1,
1381 1, 1, 1, 1, 1, 1, 1, 1,
1382 1, 1, 1, 1, 1, 1,
1383};
1384
1385static const uint16_t levels5[40] = {
1386214, 72, 42, 40, 18, 4, 4, 2,
1387 2, 2, 2, 2, 1, 1, 2, 1,
1388 1, 1, 1, 1, 1, 1, 1, 1,
1389 1, 1, 1, 1, 1, 1, 1, 1,
1390 1, 1, 1, 1, 1, 1, 1, 1,
1391};
1392
1393static const CoefVLCTable coef_vlcs[6] = {
1394 {
1395 sizeof(coef0_huffbits), coef0_huffcodes, coef0_huffbits, levels0,
1396 },
1397 {
1398 sizeof(coef1_huffbits), coef1_huffcodes, coef1_huffbits, levels1,
1399 },
1400 {
1401 sizeof(coef2_huffbits), coef2_huffcodes, coef2_huffbits, levels2,
1402 },
1403 {
1404 sizeof(coef3_huffbits), coef3_huffcodes, coef3_huffbits, levels3,
1405 },
1406 {
1407 sizeof(coef4_huffbits), coef4_huffcodes, coef4_huffbits, levels4,
1408 },
1409 {
1410 sizeof(coef5_huffbits), coef5_huffcodes, coef5_huffbits, levels5,
1411 },
1412};
diff --git a/apps/codecs/libwma/wmadec.h b/apps/codecs/libwma/wmadec.h
new file mode 100644
index 0000000000..89c100daba
--- /dev/null
+++ b/apps/codecs/libwma/wmadec.h
@@ -0,0 +1,162 @@
1#ifndef _WMADEC_H
2#define _WMADEC_H
3
4#include "asf.h"
5#include "common.h" /* For GetBitContext */
6//#include "dsputil.h" /* For MDCTContext */
7
8
9//#define TRACE
10/* size of blocks */
11#define BLOCK_MIN_BITS 7
12#define BLOCK_MAX_BITS 11
13#define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
14
15#define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
16
17/* XXX: find exact max size */
18#define HIGH_BAND_MAX_SIZE 16
19
20#define NB_LSP_COEFS 10
21
22/* XXX: is it a suitable value ? */
23#define MAX_CODED_SUPERFRAME_SIZE 16384
24
25#define M_PI 3.14159265358979323846
26
27#define M_PI_F 0x3243f // in fixed 32 format
28#define TWO_M_PI_F 0x6487f //in fixed 32
29
30#define MAX_CHANNELS 2
31
32#define NOISE_TAB_SIZE 8192
33
34#define LSP_POW_BITS 7
35
36#define VLC_TYPE int16_t
37
38typedef struct VLC
39{
40 int bits;
41 VLC_TYPE (*table)[2]; ///< code, bits
42 int table_size, table_allocated;
43}
44VLC;
45
46#define fixed32 int32_t
47#define fixed64 int64_t
48
49typedef fixed32 FFTSample;
50
51typedef struct FFTComplex
52{
53 fixed32 re, im;
54}
55FFTComplex;
56
57typedef struct FFTContext
58{
59 int nbits;
60 int inverse;
61 uint16_t *revtab;
62 FFTComplex *exptab;
63 FFTComplex *exptab1; /* only used by SSE code */
64 int (*fft_calc)(struct FFTContext *s, FFTComplex *z);
65}
66FFTContext;
67
68typedef struct MDCTContext
69{
70 int n; /* size of MDCT (i.e. number of input data * 2) */
71 int nbits; /* n = 2^nbits */
72 /* pre/post rotation tables */
73 fixed32 *tcos;
74 fixed32 *tsin;
75 FFTContext fft;
76}
77MDCTContext;
78
79typedef struct WMADecodeContext
80{
81 GetBitContext gb;
82
83 int nb_block_sizes; /* number of block sizes */
84
85 int sample_rate;
86 int nb_channels;
87 int bit_rate;
88 int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
89 int block_align;
90 int use_bit_reservoir;
91 int use_variable_block_len;
92 int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */
93 int use_noise_coding; /* true if perceptual noise is added */
94 int byte_offset_bits;
95 VLC exp_vlc;
96 int exponent_sizes[BLOCK_NB_SIZES];
97 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
98 int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
99 int coefs_start; /* first coded coef */
100 int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
101 int exponent_high_sizes[BLOCK_NB_SIZES];
102 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
103 VLC hgain_vlc;
104
105 /* coded values in high bands */
106 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
107 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
108
109 /* there are two possible tables for spectral coefficients */
110 VLC coef_vlc[2];
111 uint16_t *run_table[2];
112 uint16_t *level_table[2];
113 /* frame info */
114 int frame_len; /* frame length in samples */
115 int frame_len_bits; /* frame_len = 1 << frame_len_bits */
116
117 /* block info */
118 int reset_block_lengths;
119 int block_len_bits; /* log2 of current block length */
120 int next_block_len_bits; /* log2 of next block length */
121 int prev_block_len_bits; /* log2 of prev block length */
122 int block_len; /* block length in samples */
123 int block_num; /* block number in current frame */
124 int block_pos; /* current position in frame */
125 uint8_t ms_stereo; /* true if mid/side stereo mode */
126 uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */
127 fixed32 exponents[MAX_CHANNELS][BLOCK_MAX_SIZE];
128 fixed32 max_exponent[MAX_CHANNELS];
129 int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
130 fixed32 coefs[MAX_CHANNELS][BLOCK_MAX_SIZE];
131 MDCTContext mdct_ctx[BLOCK_NB_SIZES];
132 fixed32 *windows[BLOCK_NB_SIZES];
133 FFTComplex mdct_tmp[BLOCK_MAX_SIZE]; /* temporary storage for imdct */
134 /* output buffer for one frame and the last for IMDCT windowing */
135 fixed32 frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
136 /* last frame info */
137 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
138 int last_bitoffset;
139 int last_superframe_len;
140 fixed32 noise_table[NOISE_TAB_SIZE];
141 int noise_index;
142 fixed32 noise_mult; /* XXX: suppress that and integrate it in the noise array */
143 /* lsp_to_curve tables */
144 fixed32 lsp_cos_table[BLOCK_MAX_SIZE];
145 fixed64 lsp_pow_e_table[256];
146 fixed64 lsp_pow_m_table1[(1 << LSP_POW_BITS)];
147 fixed64 lsp_pow_m_table2[(1 << LSP_POW_BITS)];
148
149#ifdef TRACE
150
151 int frame_count;
152#endif
153}
154WMADecodeContext;
155
156int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx);
157int wma_decode_superframe(WMADecodeContext* s,
158 void *data, int *data_size,
159 uint8_t *buf, int buf_size);
160int wma_decode_end(WMADecodeContext *s);
161
162#endif
diff --git a/apps/codecs/libwma/wmadeci.c b/apps/codecs/libwma/wmadeci.c
new file mode 100644
index 0000000000..95e35c0d86
--- /dev/null
+++ b/apps/codecs/libwma/wmadeci.c
@@ -0,0 +1,2592 @@
1/*
2 * WMA compatible decoder
3 * Copyright (c) 2002 The FFmpeg Project.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/**
21 * @file wmadec.c
22 * WMA compatible decoder.
23 */
24
25#include <codecs.h>
26#include <codecs/lib/codeclib.h>
27#include "asf.h"
28#include "wmadec.h"
29
30/* These are for development and debugging and should not be changed unless
31you REALLY know what you are doing ;) */
32//#define IGNORE_OVERFLOW
33#define FAST_FILTERS
34#define PRECISION 16
35#define PRECISION64 16
36
37static fixed64 IntTo64(int x)
38{
39 fixed64 res = 0;
40 unsigned char *p = (unsigned char *)&res;
41
42#ifdef ROCKBOX_BIG_ENDIAN
43 p[5] = x & 0xff;
44 p[4] = (x & 0xff00)>>8;
45 p[3] = (x & 0xff0000)>>16;
46 p[2] = (x & 0xff000000)>>24;
47#else
48 p[2] = x & 0xff;
49 p[3] = (x & 0xff00)>>8;
50 p[4] = (x & 0xff0000)>>16;
51 p[5] = (x & 0xff000000)>>24;
52#endif
53 return res;
54}
55
56static int IntFrom64(fixed64 x)
57{
58 int res = 0;
59 unsigned char *p = (unsigned char *)&x;
60
61#ifdef ROCKBOX_BIG_ENDIAN
62 res = p[5] | (p[4]<<8) | (p[3]<<16) | (p[2]<<24);
63#else
64 res = p[2] | (p[3]<<8) | (p[4]<<16) | (p[5]<<24);
65#endif
66 return res;
67}
68
69static fixed32 Fixed32From64(fixed64 x)
70{
71 return x & 0xFFFFFFFF;
72}
73
74static fixed64 Fixed32To64(fixed32 x)
75{
76 return (fixed64)x;
77}
78#define fixtof64(x) (float)((float)(x) / (float)(1 << PRECISION64)) //does not work on int64_t!
79#define ftofix32(x) ((fixed32)((x) * (float)(1 << PRECISION) + ((x) < 0 ? -0.5 : 0.5)))
80#define itofix64(x) (IntTo64(x))
81#define itofix32(x) ((x) << PRECISION)
82#define fixtoi32(x) ((x) >> PRECISION)
83#define fixtoi64(x) (IntFrom64(x))
84
85#ifdef CPU_ARM
86#define fixmul32(x, y) \
87 ({ int32_t __hi; \
88 uint32_t __lo; \
89 int32_t __result; \
90 asm ("smull %0, %1, %3, %4\n\t" \
91 "movs %0, %0, lsr %5\n\t" \
92 "adc %2, %0, %1, lsl %6" \
93 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
94 : "%r" (x), "r" (y), \
95 "M" (PRECISION), "M" (32 - PRECISION) \
96 : "cc"); \
97 __result; \
98 })
99#else
100fixed32 fixmul32(fixed32 x, fixed32 y)
101{
102 fixed64 temp;
103 float lol;
104 // int filehandle = rb->open("/mul.txt", O_WRONLY|O_CREAT|O_APPEND);
105 lol= fixtof64(x) * fixtof64(y);
106
107 temp = x;
108 temp *= y;
109
110 temp >>= PRECISION;
111
112 //rb->fdprintf(filehandle,"%d\n", (fixed32)temp);
113 //rb->close(filehandle);
114
115 return (fixed32)temp;
116}
117
118#endif
119//thanks MAD!
120
121
122//mgg: special fixmul32 that does a 16.16 x 1.31 multiply that returns a 16.16 value.
123//this is needed because the fft constants are all normalized to be less then 1 and can't fit into a 16 bit number
124#ifdef CPU_ARM
125
126# define fixmul32b(x, y) \
127 ({ int32_t __hi; \
128 uint32_t __lo; \
129 int32_t __result; \
130 asm ("smull %0, %1, %3, %4\n\t" \
131 "movs %0, %0, lsr %5\n\t" \
132 "adc %2, %0, %1, lsl %6" \
133 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
134 : "%r" (x), "r" (y), \
135 "M" (31), "M" (1) \
136 : "cc"); \
137 __result; \
138 })
139#else
140static fixed32 fixmul32b(fixed32 x, fixed32 y)
141{
142 fixed64 temp;
143
144 temp = x;
145 temp *= y;
146
147 temp >>= 31; //16+31-16 = 31 bits
148
149 return (fixed32)temp;
150}
151
152#endif
153
154
155
156
157static fixed64 fixmul64byfixed(fixed64 x, fixed32 y)
158{
159
160 //return x * y;
161 return (x * y);
162 // return (fixed64) fixmul32(Fixed32From64(x),y);
163}
164
165
166fixed32 fixdiv32(fixed32 x, fixed32 y)
167{
168 fixed64 temp;
169
170 if(x == 0)
171 return 0;
172 if(y == 0)
173 return 0x7fffffff;
174 temp = x;
175 temp <<= PRECISION;
176 return (fixed32)(temp / y);
177}
178
179
180static fixed64 fixdiv64(fixed64 x, fixed64 y)
181{
182 fixed64 temp;
183
184 if(x == 0)
185 return 0;
186 if(y == 0)
187 return 0x07ffffffffffffffLL;
188 temp = x;
189 temp <<= PRECISION64;
190 return (fixed64)(temp / y);
191}
192
193static fixed32 fixsqrt32(fixed32 x)
194{
195
196 unsigned long r = 0, s, v = (unsigned long)x;
197
198#define STEP(k) s = r + (1 << k * 2); r >>= 1; \
199 if (s <= v) { v -= s; r |= (1 << k * 2); }
200
201 STEP(15);
202 STEP(14);
203 STEP(13);
204 STEP(12);
205 STEP(11);
206 STEP(10);
207 STEP(9);
208 STEP(8);
209 STEP(7);
210 STEP(6);
211 STEP(5);
212 STEP(4);
213 STEP(3);
214 STEP(2);
215 STEP(1);
216 STEP(0);
217
218 return (fixed32)(r << (PRECISION / 2));
219}
220
221
222__inline fixed32 fixsin32(fixed32 x)
223{
224
225 fixed64 x2, temp;
226 int sign = 1;
227
228 if(x < 0)
229 {
230 sign = -1;
231 x = -x;
232 }
233 while (x > 0x19220)
234 {
235 x -= M_PI_F;
236 sign = -sign;
237 }
238 if (x > 0x19220)
239 {
240 x = M_PI_F - x;
241 }
242 x2 = (fixed64)x * x;
243 x2 >>= PRECISION;
244 if(sign != 1)
245 {
246 x = -x;
247 }
248 /**
249 temp = ftofix32(-.0000000239f) * x2;
250 temp >>= PRECISION;
251 **/
252 temp = 0; // PJJ
253 //temp = (temp + 0x0) * x2; //MGG: this can't possibly do anything?
254 //temp >>= PRECISION;
255 temp = (temp - 0xd) * x2;
256 temp >>= PRECISION;
257 temp = (temp + 0x222) * x2;
258 temp >>= PRECISION;
259 temp = (temp - 0x2aab) * x2;
260 temp >>= PRECISION;
261 temp += 0x10000;
262 temp = temp * x;
263 temp >>= PRECISION;
264
265 return (fixed32)(temp);
266}
267
268__inline fixed32 fixcos32(fixed32 x)
269{
270 return fixsin32(x - (M_PI_F>>1))*-1;
271}
272
273
274/* Inverse gain of circular cordic rotation in s0.31 format. */
275static const long cordic_circular_gain = 0xb2458939; /* 0.607252929 */
276
277/* Table of values of atan(2^-i) in 0.32 format fractions of pi where pi = 0xffffffff / 2 */
278static const unsigned long atan_table[] = {
279 0x1fffffff, /* +0.785398163 (or pi/4) */
280 0x12e4051d, /* +0.463647609 */
281 0x09fb385b, /* +0.244978663 */
282 0x051111d4, /* +0.124354995 */
283 0x028b0d43, /* +0.062418810 */
284 0x0145d7e1, /* +0.031239833 */
285 0x00a2f61e, /* +0.015623729 */
286 0x00517c55, /* +0.007812341 */
287 0x0028be53, /* +0.003906230 */
288 0x00145f2e, /* +0.001953123 */
289 0x000a2f98, /* +0.000976562 */
290 0x000517cc, /* +0.000488281 */
291 0x00028be6, /* +0.000244141 */
292 0x000145f3, /* +0.000122070 */
293 0x0000a2f9, /* +0.000061035 */
294 0x0000517c, /* +0.000030518 */
295 0x000028be, /* +0.000015259 */
296 0x0000145f, /* +0.000007629 */
297 0x00000a2f, /* +0.000003815 */
298 0x00000517, /* +0.000001907 */
299 0x0000028b, /* +0.000000954 */
300 0x00000145, /* +0.000000477 */
301 0x000000a2, /* +0.000000238 */
302 0x00000051, /* +0.000000119 */
303 0x00000028, /* +0.000000060 */
304 0x00000014, /* +0.000000030 */
305 0x0000000a, /* +0.000000015 */
306 0x00000005, /* +0.000000007 */
307 0x00000002, /* +0.000000004 */
308 0x00000001, /* +0.000000002 */
309 0x00000000, /* +0.000000001 */
310 0x00000000, /* +0.000000000 */
311};
312
313/**
314 * Implements sin and cos using CORDIC rotation.
315 *
316 * @param phase has range from 0 to 0xffffffff, representing 0 and
317 * 2*pi respectively.
318 * @param cos return address for cos
319 * @return sin of phase, value is a signed value from LONG_MIN to LONG_MAX,
320 * representing -1 and 1 respectively.
321 *
322 * Gives at least 24 bits precision (last 2-8 bits or so are probably off)
323 */
324static long fsincos(unsigned long phase, fixed32 *cos)
325{
326 int32_t x, x1, y, y1;
327 unsigned long z, z1;
328 int i;
329
330 /* Setup initial vector */
331 x = cordic_circular_gain;
332 y = 0;
333 z = phase;
334
335 /* The phase has to be somewhere between 0..pi for this to work right */
336 if (z < 0xffffffff / 4) {
337 /* z in first quadrant, z += pi/2 to correct */
338 x = -x;
339 z += 0xffffffff / 4;
340 } else if (z < 3 * (0xffffffff / 4)) {
341 /* z in third quadrant, z -= pi/2 to correct */
342 z -= 0xffffffff / 4;
343 } else {
344 /* z in fourth quadrant, z -= 3pi/2 to correct */
345 x = -x;
346 z -= 3 * (0xffffffff / 4);
347 }
348
349 /* Each iteration adds roughly 1-bit of extra precision */
350 for (i = 0; i < 31; i++) {
351 x1 = x >> i;
352 y1 = y >> i;
353 z1 = atan_table[i];
354
355 /* Decided which direction to rotate vector. Pivot point is pi/2 */
356 if (z >= 0xffffffff / 4) {
357 x -= y1;
358 y += x1;
359 z -= z1;
360 } else {
361 x += y1;
362 y -= x1;
363 z += z1;
364 }
365 }
366
367 if (cos)
368 *cos = x;
369
370 return y;
371}
372
373
374
375/*
376__inline fixed32 fixasin32(fixed32 x)
377{
378 fixed64 temp;
379 int sign = 1;
380
381 if(x > 0x10000 || x < 0xffff0000)
382 {
383 return 0;
384 }
385 if(x < 0)
386 {
387 sign = -1;
388 x = -x;
389 }
390 temp = 0xffffffad * (fixed64)x;
391 temp >>= PRECISION;
392 temp = (temp + 0x1b5) * x;
393 temp >>= PRECISION;
394 temp = (temp - 0x460) * x;
395 temp >>= PRECISION;
396 temp = (temp + 0x7e9) * x;
397 temp >>= PRECISION;
398 temp = (temp - 0xcd8) * x;
399 temp >>= PRECISION;
400 temp = (temp + 0x16c7) * x;
401 temp >>= PRECISION;
402 temp = (temp - 0x36f0) * x;
403 temp >>= PRECISION;
404 temp = (temp + 0x19220) * fixsqrt32(0x10000 - x);
405 temp >>= PRECISION;
406
407 return sign * ((M_PI_F>>1) - (fixed32)temp);
408}
409*/
410
411#define ALT_BITSTREAM_READER
412
413#define unaligned32(a) (*(uint32_t*)(a))
414
415uint16_t bswap_16(uint16_t x)
416{
417 uint16_t hi = x & 0xff00;
418 uint16_t lo = x & 0x00ff;
419 return (hi >> 8) | (lo << 8);
420}
421
422uint32_t bswap_32(uint32_t x)
423{
424 uint32_t b1 = x & 0xff000000;
425 uint32_t b2 = x & 0x00ff0000;
426 uint32_t b3 = x & 0x0000ff00;
427 uint32_t b4 = x & 0x000000ff;
428 return (b1 >> 24) | (b2 >> 8) | (b3 << 8) | (b4 << 24);
429}
430
431// PJJ : reinstate macro
432void CMUL(fixed32 *pre,
433 fixed32 *pim,
434 fixed32 are,
435 fixed32 aim,
436 fixed32 bre,
437 fixed32 bim)
438{
439 //int64_t x,y;
440 fixed32 _aref = are;
441 fixed32 _aimf = aim;
442 fixed32 _bref = bre;
443 fixed32 _bimf = bim;
444 fixed32 _r1 = fixmul32b(_bref, _aref);
445 fixed32 _r2 = fixmul32b(_bimf, _aimf);
446 fixed32 _r3 = fixmul32b(_bref, _aimf);
447 fixed32 _r4 = fixmul32b(_bimf, _aref);
448 *pre = _r1 - _r2;
449 *pim = _r3 + _r4;
450
451}
452
453
454typedef struct CoefVLCTable
455{
456 int n; /* total number of codes */
457 const uint32_t *huffcodes; /* VLC bit values */
458 const uint8_t *huffbits; /* VLC bit size */
459 const uint16_t *levels; /* table to build run/level tables */
460}
461CoefVLCTable;
462
463static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len);
464int fft_calc(FFTContext *s, FFTComplex *z);
465
466
467//static variables that replace malloced stuff
468fixed32 stat0[2048], stat1[1024], stat2[512], stat3[256], stat4[128]; //these are the MDCT reconstruction windows
469
470fixed32 *tcosarray[5], *tsinarray[5];
471fixed32 tcos0[1024], tcos1[512], tcos2[256], tcos3[128], tcos4[64]; //these are the sin and cos rotations used by the MDCT
472fixed32 tsin0[1024], tsin1[512], tsin2[256], tsin3[128], tsin4[64];
473
474FFTComplex *exparray[5]; //these are the fft lookup tables
475uint16_t *revarray[5];
476FFTComplex exptab0[512] IBSS_ATTR;//, exptab1[256], exptab2[128], exptab3[64], exptab4[32]; //folded these in!
477uint16_t revtab0[1024], revtab1[512], revtab2[256], revtab3[128], revtab4[64];
478
479uint16_t *runtabarray[2], *levtabarray[2]; //these are VLC lookup tables
480
481uint16_t runtab0[1336], runtab1[1336], levtab0[1336], levtab1[1336]; //these could be made smaller since only one can be 1336
482
483
484//may also be too large by ~ 1KB each?
485static VLC_TYPE vlcbuf1[6144][2];
486static VLC_TYPE vlcbuf2[3584][2];
487static VLC_TYPE vlcbuf3[1536][2] IBSS_ATTR; //small so lets try iram
488
489//fixed32 window[BLOCK_MAX_SIZE * 2];
490
491const fixed64 pow_table[] =
492 {
493 0x10000LL,0x11f3dLL,0x14249LL,0x1699cLL,0x195bcLL,0x1c73dLL,0x1fec9LL,0x23d1dLL,0x2830bLL,0x2d182LL,
494 0x3298bLL,0x38c53LL,0x3fb28LL,0x47783LL,0x5030aLL,0x59f98LL,0x64f40LL,0x71457LL,0x7f17bLL,0x8e99aLL,
495 0xa0000LL,0xb385eLL,0xc96d9LL,0xe2019LL,0xfd954LL,0x11c865LL,0x13f3dfLL,0x166320LL,0x191e6eLL,0x1c2f10LL,
496 0x1f9f6eLL,0x237b39LL,0x27cf8bLL,0x2cab1aLL,0x321e65LL,0x383bf0LL,0x3f1882LL,0x46cb6aLL,0x4f6eceLL,0x592006LL,
497 0x640000LL,0x7033acLL,0x7de47eLL,0x8d40f6LL,0x9e7d44LL,0xb1d3f4LL,0xc786b7LL,0xdfdf43LL,0xfb304bLL,0x119d69aLL,
498 0x13c3a4eLL,0x162d03aLL,0x18e1b70LL,0x1beaf00LL,0x1f52feeLL,0x2325760LL,0x276f514LL,0x2c3f220LL,0x31a5408LL,
499 0x37b403cLL,0x3e80000LL,0x46204b8LL,0x4eaece8LL,0x58489a0LL,0x630e4a8LL,0x6f24788LL,0x7cb4328LL,0x8beb8a0LL,
500 0x9cfe2f0LL,0xb026200LL,0xc5a4710LL,0xddc2240LL,0xf8d1260LL,0x1172d600LL,0x1393df60LL,0x15f769c0LL,0x18a592c0LL,
501 0x1ba77540LL,0x1f074840LL,0x22d08280LL,0x27100000LL,0x2bd42f40LL,0x312d4100LL,0x372d6000LL,0x3de8ee80LL,
502 0x4576cb80LL,0x4df09f80LL,0x57733600LL,0x621edd80LL,0x6e17d480LL,0x7b86c700LL,0x8a995700LL,0x9b82b800LL,
503 0xae7c5c00LL,0xc3c6b900LL,0xdbaa2200LL,0xf677bc00LL,0x1148a9400LL,0x13648d200LL,0x15c251800LL,0x186a00000LL,
504 0x1b649d800LL,0x1ebc48a00LL,0x227c5c000LL,0x26b195000LL,0x2b6a3f000LL,0x30b663c00LL,0x36a801c00LL,0x3d534a400LL,
505 0x44cee4800LL,0x4d343c800LL,0x569fd6000LL,0x6131b2800LL,0x6d0db9800LL,0x7a5c33800LL,0x894a55000LL,0x9a0ad6000LL,
506 0xacd69d000LL,0xc1ed84000LL,0xd9972f000LL,0xf42400000LL,0x111ee28000LL,0x1335ad6000LL,0x158db98000LL,0x182efd4000LL,
507 0x1b22676000LL,0x1e71fe6000LL,0x2229014000LL,0x26540e8000LL,0x2b014f0000LL,0x3040a5c000LL,0x3623e60000LL,0x3cbf0fc000LL,
508 0x4428940000LL,0x4c79a08000LL,0x55ce758000LL,0x6046c58000LL,0x6c06220000LL,0x7934728000LL,0x87fe7d0000LL,0x9896800000LL,
509 0xab34d90000LL,0xc018c60000LL,0xd7893f0000LL,0xf1d5e40000LL,0x10f580a0000LL,0x13073f00000LL,0x1559a0c0000LL,0x17f48900000LL,
510 0x1ae0d160000LL,0x1e286780000LL,0x21d66fc0000LL,0x25f769c0000LL,0x2a995c80000LL,0x2fcc0440000LL,0x35a10940000LL,
511 0x3c2c3b80000LL,0x4383d500000LL,0x4bc0c780000LL,0x54ff0e80000LL,0x5f5e1000000LL,0x6b010780000LL,0x780f7c00000LL,
512 0x86b5c800000LL,0x9725ae00000LL,0xa9970600000LL,0xbe487500000LL,0xd5804700000LL,0xef8d5a00000LL,0x10cc82e00000LL,
513 0x12d940c00000LL,0x152605c00000LL,0x17baa2200000LL,0x1a9fd9c00000LL,0x1ddf82a00000LL,0x2184a5c00000LL,0x259ba5400000LL,
514 0x2a3265400000LL,0x2f587cc00000LL,0x351f69000000LL,0x3b9aca000000LL,0x42e0a4800000LL,0x4b09ad800000LL,
515 0x54319d000000LL,0x5e778d000000LL,0x69fe64000000LL,0x76ed49800000LL,0x85702c000000LL,0x95b858000000LL,
516 0xa7fd1c000000LL,0xbc7c87000000LL,0xd37c3a000000LL,0xed4a55000000LL,0x10a3e82000000LL,0x12abb1a000000LL,
517 0x14f2e7a000000LL,0x1781474000000LL,0x1a5f7f4000000LL,0x1d974de000000LL,0x2133a18000000LL
518 };
519
520const fixed32 pow_10_to_yover16[] ICONST_ATTR=
521{
5220x10000,0x127a0,0x15562,0x18a39,0x1c73d,0x20db4,0x25f12,0x2bd09,0x3298b,0x3a6d9,0x4378b,0x4dea3,
5230x59f98,0x67e6b,0x77fbb,0x8a8de,0xa0000,0xb8c3e,0xd55d1,0xf6636,0x11c865,0x148906,0x17b6b8,0x1b625b,
5240x1f9f6e,0x248475,0x2a2b6e,0x30b25f,0x383bf0,0x40f02c,0x4afd4b,0x5698b0,0x640000,0x737a6b,0x855a26,
5250x99fe1f,0xb1d3f4,0xcd5a3e,0xed232b,0x111d78a,0x13c3a4e,0x16d2c94,0x1a5b24e,0x1e6f7b0,0x2325760,
5260x28961b4,0x2ede4ec,0x361f6dc,0x3e80000,0x482c830,0x5358580,0x603ed30,0x6f24788,0x8058670,0x9435fb0,
5270xab26b70,0xc5a4710,0xe43bdc0,0x1078f700,0x1305ace0,0x15f769c0,0x195dd100,0x1d4af120
528};
529
530const fixed32 pow_a_table[] =
531{
5320x1004,0x1008,0x100c,0x1010,0x1014,0x1018,0x101c,0x1021,0x1025,0x1029,0x102d,0x1031,0x1036,0x103a,
5330x103e,0x1043,0x1047,0x104b,0x1050,0x1054,0x1059,0x105d,0x1062,0x1066,0x106b,0x106f,0x1074,0x1078,
5340x107d,0x1082,0x1086,0x108b,0x1090,0x1095,0x1099,0x109e,0x10a3,0x10a8,0x10ad,0x10b2,0x10b7,0x10bc,
5350x10c1,0x10c6,0x10cb,0x10d0,0x10d5,0x10da,0x10df,0x10e5,0x10ea,0x10ef,0x10f5,0x10fa,0x10ff,0x1105,
5360x110a,0x1110,0x1115,0x111b,0x1120,0x1126,0x112c,0x1131,0x1137,0x113d,0x1143,0x1149,0x114f,0x1155,
5370x115a,0x1161,0x1167,0x116d,0x1173,0x1179,0x117f,0x1186,0x118c,0x1192,0x1199,0x119f,0x11a6,0x11ac,
5380x11b3,0x11b9,0x11c0,0x11c7,0x11ce,0x11d4,0x11db,0x11e2,0x11e9,0x11f0,0x11f8,0x11ff,0x1206,0x120d,
5390x1215,0x121c,0x1223,0x122b,0x1233,0x123a,0x1242,0x124a,0x1251,0x1259,0x1261,0x1269,0x1271,0x127a,
5400x1282,0x128a,0x1293,0x129b,0x12a4,0x12ac,0x12b5,0x12be,0x12c7,0x12d0,0x12d9,0x12e2,0x12eb,0x12f4,
5410x12fe,0x1307
542};
543
544const fixed64 lsp_pow_e_table[] =
545{
546 0xf333f9deLL, 0xf0518db9LL, 0x0LL, 0x7e656b4fLL, 0x7999fcefLL, 0xf828c6dcLL, 0x0LL,
547 0x3f32b5a7LL, 0x3cccfe78LL, 0xfc14636eLL, 0x0LL, 0x9f995ad4LL, 0x9e667f3cLL, 0xfe0a31b7LL,
548 0x0LL, 0x4fccad6aLL, 0x4f333f9eLL, 0x7f0518dcLL, 0x0LL, 0x27e656b5LL, 0x27999fcfLL,
549 0xbf828c6eLL, 0x0LL, 0x13f32b5aLL, 0x13cccfe7LL, 0xdfc14637LL, 0x0LL, 0x89f995adLL,
550 0x9e667f4LL, 0x6fe0a31bLL, 0x0LL, 0x44fccad7LL, 0x4f333faLL, 0x37f0518eLL, 0x0LL,
551 0xa27e656bLL, 0x827999fdLL, 0x1bf828c7LL, 0x0LL, 0xd13f32b6LL, 0x413cccfeLL, 0xdfc1463LL,
552 0x0LL, 0xe89f995bLL, 0xa09e667fLL, 0x6fe0a32LL, 0x0LL, 0x744fccadLL, 0x504f3340LL,
553 0x837f0519LL, 0x0LL, 0xba27e657LL, 0xa82799a0LL, 0xc1bf828cLL, 0x0LL, 0x5d13f32bLL,
554 0xd413ccd0LL, 0x60dfc146LL, 0x0LL, 0xae89f996LL, 0x6a09e668LL, 0x306fe0a3LL, 0x0LL,
555 0xd744fccbLL, 0xb504f334LL, 0x9837f052LL, 0x80000000LL, 0x6ba27e65LL, 0x5a82799aLL,
556 0x4c1bf829LL, 0x40000000LL, 0x35d13f33LL, 0x2d413ccdLL, 0x260dfc14LL, 0x20000000LL,
557 0x1ae89f99LL, 0x16a09e66LL, 0x1306fe0aLL, 0x10000000LL, 0xd744fcdLL, 0xb504f33LL,
558 0x9837f05LL, 0x8000000LL, 0x6ba27e6LL, 0x5a8279aLL, 0x4c1bf83LL, 0x4000000LL,
559 0x35d13f3LL, 0x2d413cdLL, 0x260dfc1LL, 0x2000000LL, 0x1ae89faLL, 0x16a09e6LL,
560 0x1306fe1LL, 0x1000000LL, 0xd744fdLL, 0xb504f3LL, 0x9837f0LL, 0x800000LL,
561 0x6ba27eLL, 0x5a827aLL, 0x4c1bf8LL, 0x400000LL, 0x35d13fLL, 0x2d413dLL,
562 0x260dfcLL, 0x200000LL, 0x1ae8a0LL, 0x16a09eLL, 0x1306feLL, 0x100000LL,
563 0xd7450LL, 0xb504fLL, 0x9837fLL, 0x80000LL, 0x6ba28LL, 0x5a828LL, 0x4c1c0LL,
564 0x40000LL, 0x35d14LL, 0x2d414LL, 0x260e0LL, 0x20000LL, 0x1ae8aLL, 0x16a0aLL,
565 0x13070LL, 0x10000LL, 0xd745LL, 0xb505LL, 0x9838LL, 0x8000LL, 0x6ba2LL,
566 0x5a82LL, 0x4c1cLL, 0x4000LL, 0x35d1LL, 0x2d41LL, 0x260eLL, 0x2000LL,
567 0x1ae9LL, 0x16a1LL, 0x1307LL, 0x1000LL, 0xd74LL, 0xb50LL, 0x983LL, 0x800LL,
568 0x6baLL, 0x5a8LL, 0x4c2LL, 0x400LL, 0x35dLL, 0x2d4LL, 0x261LL, 0x200LL, 0x1afLL,
569 0x16aLL, 0x130LL, 0x100LL, 0xd7LL, 0xb5LL, 0x98LL, 0x80LL, 0x6cLL, 0x5bLL,
570 0x4cLL, 0x40LL, 0x36LL, 0x2dLL, 0x26LL, 0x20LL, 0x1bLL, 0x17LL, 0x13LL,
571 0x10LL, 0xdLL, 0xbLL, 0xaLL, 0x8LL, 0x7LL, 0x6LL, 0x5LL, 0x4LL, 0x3LL,
572 0x3LL, 0x2LL, 0x2LL, 0x2LL, 0x1LL, 0x1LL, 0x1LL, 0x1LL, 0x1LL, 0x1LL,
573 0x1LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL,
574 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL,
575 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL,
576 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL,
577 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL,
578 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL,
579 0x0LL, 0x0LL
580};
581
582#include "wmadata.h" // PJJ
583
584/**
585 * The size of the FFT is 2^nbits. If inverse is TRUE, inverse FFT is
586 * done
587 */
588int fft_inits(FFTContext *s, int nbits, int inverse)
589{
590 int i, j, m, n;
591 fixed32 alpha, c1, s1, ct, st;
592 int s2;
593
594 s->nbits = nbits;
595 n = 1 << nbits;
596
597 //s->exptab = exparray[10-nbits]; //not needed
598
599 //s->exptab = av_malloc((n >> 1) * sizeof(FFTComplex));
600 //if (!s->exptab)
601 // goto fail;
602 s->revtab = revarray[10-nbits];
603 //s->revtab = av_malloc(n * sizeof(uint16_t));
604 //if (!s->revtab)
605 // goto fail;
606 s->inverse = inverse;
607
608 s2 = inverse ? 1 : -1;
609
610 if(nbits == 10){ //we folded all these stupid tables into the nbits==10 table, so don't make it for the others!
611 //should probably just remove exptab building out of this function and do it higher up for neatness
612 for(i=0;i<(n/2);++i)
613 {
614 //we're going to redo this in CORDIC fixed format! Hold onto your butts
615
616 /*
617 input to cordic is from 0 ->2pi with 0->0 and 2^32-1 ->2pi
618 output, which is what we'll store the variables as is
619 -1->-2^31 and 1->2^31-1
620
621 */
622
623 fixed32 ifix = itofix32(i);
624 fixed32 nfix = itofix32(n);
625 fixed32 res = fixdiv32(ifix,nfix); //this is really bad here since nfix can be as large as 1024 !
626 //also, make this a shift, since its a fucking power of two divide
627 alpha = fixmul32(TWO_M_PI_F, res);
628 ct = fixcos32(alpha); //need to correct alpha for 0->2pi scale
629 st = fixsin32(alpha);// * s2;
630
631 s1 = fsincos(res<<16, &c1); //does sin and cos in one pass!
632
633 //I really have my doubts about the correctness of the alpha to cordic mapping here, but it seems to work well enough
634 //double check this later!
635
636 exptab0[i].re = c1;
637 exptab0[i].im = s1*s2;
638 }
639 }
640 // s->fft_calc = fft_calc;
641 s->exptab1 = NULL;
642
643
644 /* compute bit reverse table */
645
646 for(i=0;i<n;i++)
647 {
648 m=0;
649 for(j=0;j<nbits;j++)
650 {
651 m |= ((i >> j) & 1) << (nbits-j-1);
652
653 }
654
655 s->revtab[i]=m;
656 }
657 return 0;
658//fail:
659 // av_freep(&s->revtab);
660 // av_freep(&s->exptab);
661 // av_freep(&s->exptab1);
662 return -1;
663}
664
665/* butter fly op */
666#define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \
667{\
668 fixed32 ax, ay, bx, by;\
669 bx=pre1;\
670 by=pim1;\
671 ax=qre1;\
672 ay=qim1;\
673 pre = (bx + ax);\
674 pim = (by + ay);\
675 qre = (bx - ax);\
676 qim = (by - ay);\
677}
678
679//this goddamn butterfly could overflow and i'd neve rknow it...
680//holy shit it was the fucking butterfly oh god this is the worst thing ever
681
682
683
684int fft_calc_unscaled(FFTContext *s, FFTComplex *z)
685{
686 int ln = s->nbits;
687 int j, np, np2;
688 int nblocks, nloops;
689 register FFTComplex *p, *q;
690 // FFTComplex *exptab = s->exptab;
691 int l;
692 fixed32 tmp_re, tmp_im;
693 int tabshift = 10-ln;
694
695 np = 1 << ln;
696
697
698 /* pass 0 */
699
700 p=&z[0];
701 j=(np >> 1);
702 do
703 {
704 BF(p[0].re, p[0].im, p[1].re, p[1].im,
705 p[0].re, p[0].im, p[1].re, p[1].im);
706 p+=2;
707 }
708 while (--j != 0);
709
710 /* pass 1 */
711
712
713 p=&z[0];
714 j=np >> 2;
715 if (s->inverse)
716 {
717 do
718 {
719 BF(p[0].re, p[0].im, p[2].re, p[2].im,
720 p[0].re, p[0].im, p[2].re, p[2].im);
721 BF(p[1].re, p[1].im, p[3].re, p[3].im,
722 p[1].re, p[1].im, -p[3].im, p[3].re);
723 p+=4;
724 }
725 while (--j != 0);
726 }
727 else
728 {
729 do
730 {
731 BF(p[0].re, p[0].im, p[2].re, p[2].im,
732 p[0].re, p[0].im, p[2].re, p[2].im);
733 BF(p[1].re, p[1].im, p[3].re, p[3].im,
734 p[1].re, p[1].im, p[3].im, -p[3].re);
735 p+=4;
736 }
737 while (--j != 0);
738 }
739 /* pass 2 .. ln-1 */
740
741 nblocks = np >> 3;
742 nloops = 1 << 2;
743 np2 = np >> 1;
744 do
745 {
746 p = z;
747 q = z + nloops;
748 for (j = 0; j < nblocks; ++j)
749 {
750 BF(p->re, p->im, q->re, q->im,
751 p->re, p->im, q->re, q->im);
752
753 p++;
754 q++;
755 for(l = nblocks; l < np2; l += nblocks)
756 {
757 CMUL(&tmp_re, &tmp_im, exptab0[(l<<tabshift)].re, exptab0[(l<<tabshift)].im, q->re, q->im);
758 //CMUL(&tmp_re, &tmp_im, exptab[l].re, exptab[l].im, q->re, q->im);
759 BF(p->re, p->im, q->re, q->im,
760 p->re, p->im, tmp_re, tmp_im);
761 p++;
762 q++;
763 }
764
765 p += nloops;
766 q += nloops;
767 }
768 nblocks = nblocks >> 1;
769 nloops = nloops << 1;
770 }
771 while (nblocks != 0);
772 return 0;
773}
774
775/*
776//needless since we're statically allocated
777void fft_end(FFTContext *s)
778{
779 // av_freep(&s->revtab);
780 // av_freep(&s->exptab);
781 // av_freep(&s->exptab1);
782}
783*/
784/* VLC decoding */
785
786#define GET_VLC(code, name, gb, table, bits, max_depth)\
787{\
788 int n, index, nb_bits;\
789\
790 index= SHOW_UBITS(name, gb, bits);\
791 code = table[index][0];\
792 n = table[index][1];\
793\
794 if(max_depth > 1 && n < 0){\
795 LAST_SKIP_BITS(name, gb, bits)\
796 UPDATE_CACHE(name, gb)\
797\
798 nb_bits = -n;\
799\
800 index= SHOW_UBITS(name, gb, nb_bits) + code;\
801 code = table[index][0];\
802 n = table[index][1];\
803 if(max_depth > 2 && n < 0){\
804 LAST_SKIP_BITS(name, gb, nb_bits)\
805 UPDATE_CACHE(name, gb)\
806\
807 nb_bits = -n;\
808\
809 index= SHOW_UBITS(name, gb, nb_bits) + code;\
810 code = table[index][0];\
811 n = table[index][1];\
812 }\
813 }\
814 SKIP_BITS(name, gb, n)\
815}
816
817
818//#define DEBUG_VLC
819
820#define GET_DATA(v, table, i, wrap, size) \
821{\
822 const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
823 switch(size) {\
824 case 1:\
825 v = *(const uint8_t *)ptr;\
826 break;\
827 case 2:\
828 v = *(const uint16_t *)ptr;\
829 break;\
830 default:\
831 v = *(const uint32_t *)ptr;\
832 break;\
833 }\
834}
835
836// deprecated, dont use get_vlc for new code, use get_vlc2 instead or use GET_VLC directly
837static inline int get_vlc(GetBitContext *s, VLC *vlc)
838{
839 int code;
840 VLC_TYPE (*table)[2]= vlc->table;
841
842 OPEN_READER(re, s)
843 UPDATE_CACHE(re, s)
844
845 GET_VLC(code, re, s, table, vlc->bits, 3)
846
847 CLOSE_READER(re, s)
848 return code;
849}
850
851static int alloc_table(VLC *vlc, int size)
852{
853 int index;
854 index = vlc->table_size;
855 vlc->table_size += size;
856 if (vlc->table_size > vlc->table_allocated)
857 {
858 // rb->splash(HZ*10, "OH CRAP, TRIED TO REALLOC A STATIC VLC TABLE!");
859 vlc->table_allocated += (1 << vlc->bits);
860 // vlc->table = av_realloc(vlc->table,
861 // sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
862 if (!vlc->table)
863 return -1;
864 }
865 return index;
866}
867
868static int build_table(VLC *vlc, int table_nb_bits,
869 int nb_codes,
870 const void *bits, int bits_wrap, int bits_size,
871 const void *codes, int codes_wrap, int codes_size,
872 uint32_t code_prefix, int n_prefix)
873{
874 int i, j, k, n, table_size, table_index, nb, n1, index;
875 uint32_t code;
876 VLC_TYPE (*table)[2];
877
878 table_size = 1 << table_nb_bits;
879 table_index = alloc_table(vlc, table_size);
880 if (table_index < 0)
881 return -1;
882 table = &vlc->table[table_index];
883
884 for(i=0;i<table_size;i++)
885 {
886 table[i][1] = 0; //bits
887 table[i][0] = -1; //codes
888 }
889
890 /* first pass: map codes and compute auxillary table sizes */
891 for(i=0;i<nb_codes;i++)
892 {
893 GET_DATA(n, bits, i, bits_wrap, bits_size);
894 GET_DATA(code, codes, i, codes_wrap, codes_size);
895 /* we accept tables with holes */
896 if (n <= 0)
897 continue;
898 /* if code matches the prefix, it is in the table */
899 n -= n_prefix;
900 if (n > 0 && (code >> n) == code_prefix)
901 {
902 if (n <= table_nb_bits)
903 {
904 /* no need to add another table */
905 j = (code << (table_nb_bits - n)) & (table_size - 1);
906 nb = 1 << (table_nb_bits - n);
907 for(k=0;k<nb;k++)
908 {
909 if (table[j][1] /*bits*/ != 0)
910 {
911 // PJJ exit(-1);
912 }
913 table[j][1] = n; //bits
914 table[j][0] = i; //code
915 j++;
916 }
917 }
918 else
919 {
920 n -= table_nb_bits;
921 j = (code >> n) & ((1 << table_nb_bits) - 1);
922 /* compute table size */
923 n1 = -table[j][1]; //bits
924 if (n > n1)
925 n1 = n;
926 table[j][1] = -n1; //bits
927 }
928 }
929 }
930
931 /* second pass : fill auxillary tables recursively */
932 for(i=0;i<table_size;i++)
933 {
934 n = table[i][1]; //bits
935 if (n < 0)
936 {
937 n = -n;
938 if (n > table_nb_bits)
939 {
940 n = table_nb_bits;
941 table[i][1] = -n; //bits
942 }
943 index = build_table(vlc, n, nb_codes,
944 bits, bits_wrap, bits_size,
945 codes, codes_wrap, codes_size,
946 (code_prefix << table_nb_bits) | i,
947 n_prefix + table_nb_bits);
948 if (index < 0)
949 return -1;
950 /* note: realloc has been done, so reload tables */
951 table = &vlc->table[table_index];
952 table[i][0] = index; //code
953 }
954 }
955 return table_index;
956}
957
958/* Build VLC decoding tables suitable for use with get_vlc().
959
960 'nb_bits' set thee decoding table size (2^nb_bits) entries. The
961 bigger it is, the faster is the decoding. But it should not be too
962 big to save memory and L1 cache. '9' is a good compromise.
963
964 'nb_codes' : number of vlcs codes
965
966 'bits' : table which gives the size (in bits) of each vlc code.
967
968 'codes' : table which gives the bit pattern of of each vlc code.
969
970 'xxx_wrap' : give the number of bytes between each entry of the
971 'bits' or 'codes' tables.
972
973 'xxx_size' : gives the number of bytes of each entry of the 'bits'
974 or 'codes' tables.
975
976 'wrap' and 'size' allows to use any memory configuration and types
977 (byte/word/long) to store the 'bits' and 'codes' tables.
978*/
979int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
980 const void *bits, int bits_wrap, int bits_size,
981 const void *codes, int codes_wrap, int codes_size)
982{
983 vlc->bits = nb_bits;
984 // vlc->table = NULL;
985 // vlc->table_allocated = 0;
986 vlc->table_size = 0;
987
988 if (build_table(vlc, nb_bits, nb_codes,
989 bits, bits_wrap, bits_size,
990 codes, codes_wrap, codes_size,
991 0, 0) < 0)
992 {
993 // av_free(vlc->table);
994 return -1;
995 }
996 //dump_table("Tab 1",vlc->table[0],vlc->table_size);
997 //dump_table("Tab 2",vlc->table[1],vlc->table_size);
998 return 0;
999}
1000
1001/**
1002 * init MDCT or IMDCT computation.
1003 */
1004int ff_mdct_init(MDCTContext *s, int nbits, int inverse)
1005{
1006 int n, n4, i;
1007 // fixed32 alpha;
1008
1009
1010 memset(s, 0, sizeof(*s));
1011 n = 1 << nbits; //nbits ranges from 12 to 8 inclusive
1012 s->nbits = nbits;
1013 s->n = n;
1014 n4 = n >> 2;
1015 s->tcos = tcosarray[12-nbits];
1016 s->tsin = tsinarray[12-nbits];
1017 //s->tcos = av_malloc(n4 * sizeof(fixed32)); //this allocates between 1024 and 64 elements
1018 //if (!s->tcos)
1019 // goto fail;
1020 //s->tsin = av_malloc(n4 * sizeof(fixed32));
1021 //if (!s->tsin)
1022 // goto fail;
1023//
1024 for(i=0;i<n4;i++)
1025 {
1026 //fixed32 pi2 = fixmul32(0x20000, M_PI_F);
1027 fixed32 ip = itofix32(i) + 0x2000;
1028 ip = ip >> nbits;
1029 //ip = fixdiv32(ip,itofix32(n)); // PJJ optimize
1030 //alpha = fixmul32(TWO_M_PI_F, ip);
1031 //s->tcos[i] = -fixcos32(alpha); //alpha between 0 and pi/2
1032 //s->tsin[i] = -fixsin32(alpha);
1033
1034 s->tsin[i] = - fsincos(ip<<16, &(s->tcos[i])); //I can't remember why this works, but it seems to agree for ~24 bits, maybe more!
1035 s->tcos[i] *=-1;
1036 }
1037 if (fft_inits(&s->fft, s->nbits - 2, inverse) < 0)
1038 goto fail;
1039 return 0;
1040fail:
1041// av_freep(&s->tcos);
1042// av_freep(&s->tsin);
1043 return -1;
1044}
1045
1046/**
1047 * Compute inverse MDCT of size N = 2^nbits
1048 * @param output N samples
1049 * @param input N/2 samples
1050 * @param tmp N/2 samples
1051 */
1052void ff_imdct_calc(MDCTContext *s,
1053 fixed32 *output,
1054 const fixed32 *input,
1055 FFTComplex *tmp)
1056{
1057 int k, n8, n4, n2, n, j,scale;
1058 const uint16_t *revtab = s->fft.revtab;
1059 const fixed32 *tcos = s->tcos;
1060 const fixed32 *tsin = s->tsin;
1061 const fixed32 *in1, *in2;
1062 FFTComplex *z = (FFTComplex *)tmp;
1063
1064 n = 1 << s->nbits;
1065
1066 n2 = n >> 1;
1067 n4 = n >> 2;
1068 n8 = n >> 3;
1069
1070
1071 /* pre rotation */
1072 in1 = input;
1073 in2 = input + n2 - 1;
1074
1075 for(k = 0; k < n4; k++)
1076 {
1077 j=revtab[k];
1078 CMUL(&z[j].re, &z[j].im, *in2, *in1, tcos[k], tsin[k]);
1079 in1 += 2;
1080 in2 -= 2;
1081 }
1082
1083 for(k = 0; k < n4; k++){
1084 z[k].re >>=1;
1085 z[k].im >>=1;
1086 }
1087
1088 //rb->splash(HZ, "in MDCT calc");
1089 scale = fft_calc_unscaled(&s->fft, z);
1090 // scale = fft_calc(&s->fft, z);
1091
1092 //rb->splash(HZ, "in MDCT calc2");
1093
1094 /* post rotation + reordering */
1095
1096 for(k = 0; k < n4; k++)
1097 {
1098 CMUL(&z[k].re, &z[k].im, (z[k].re), (z[k].im), tcos[k], tsin[k]);
1099 }
1100
1101 for(k = 0; k < n8; k++)
1102 {
1103 fixed32 r1,r2,r3,r4,r1n,r2n,r3n;
1104
1105 r1 = z[n8 + k].im;
1106 r1n = r1 * -1;
1107 r2 = z[n8-1-k].re;
1108 r2n = r2 * -1;
1109 r3 = z[k+n8].re;
1110 r3n = r3 * -1;
1111 r4 = z[n8-k-1].im;
1112
1113 output[2*k] = r1n;
1114 output[n2-1-2*k] = r1;
1115
1116 output[2*k+1] = r2;
1117 output[n2-1-2*k-1] = r2n;
1118
1119 output[n2 + 2*k]= r3n;
1120 output[n-1- 2*k]= r3n;
1121
1122 output[n2 + 2*k+1]= r4;
1123 output[n-2 - 2 * k] = r4;
1124 }
1125
1126
1127
1128
1129}
1130
1131void ff_mdct_end(MDCTContext *s)
1132{
1133 (void)s;
1134
1135 // av_freep(&s->tcos);
1136 // av_freep(&s->tsin);
1137 // fft_end(&s->fft);
1138}
1139
1140
1141
1142
1143/* XXX: use same run/length optimization as mpeg decoders */
1144static void init_coef_vlc(VLC *vlc,
1145 uint16_t **prun_table, uint16_t **plevel_table,
1146 const CoefVLCTable *vlc_table, int tab)
1147{
1148 int n = vlc_table->n;
1149 const uint8_t *table_bits = vlc_table->huffbits;
1150 const uint32_t *table_codes = vlc_table->huffcodes;
1151 const uint16_t *levels_table = vlc_table->levels;
1152 uint16_t *run_table, *level_table;
1153 const uint16_t *p;
1154 int i, l, j, level;
1155
1156
1157 init_vlc(vlc, 9, n, table_bits, 1, 1, table_codes, 4, 4);
1158
1159 run_table = runtabarray[tab];
1160 //run_table = av_malloc(n * sizeof(uint16_t)); //max n should be 1336
1161
1162 level_table= levtabarray[tab];
1163 //level_table = av_malloc(n * sizeof(uint16_t));
1164 p = levels_table;
1165 i = 2;
1166 level = 1;
1167 while (i < n)
1168 {
1169 l = *p++;
1170 for(j=0;j<l;++j)
1171 {
1172 run_table[i] = j;
1173 level_table[i] = level;
1174 ++i;
1175 }
1176 ++level;
1177 }
1178 *prun_table = run_table;
1179 *plevel_table = level_table;
1180}
1181
1182int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx)
1183{
1184 //WMADecodeContext *s = avctx->priv_data;
1185 int i, flags1, flags2;
1186 fixed32 *window;
1187 uint8_t *extradata;
1188 fixed64 bps1;
1189 fixed32 high_freq;
1190 fixed64 bps;
1191 int sample_rate1;
1192 int coef_vlc_table;
1193 // int filehandle;
1194
1195 s->sample_rate = wfx->rate;
1196 s->nb_channels = wfx->channels;
1197 s->bit_rate = wfx->bitrate;
1198 s->block_align = wfx->blockalign;
1199
1200 if (wfx->codec_id == ASF_CODEC_ID_WMAV1){
1201 s->version = 1;
1202 }else{
1203 s->version = 2;
1204 }
1205
1206 /* extract flag infos */
1207 flags1 = 0;
1208 flags2 = 0;
1209 extradata = wfx->data;
1210 if (s->version == 1 && wfx->datalen >= 4) {
1211 flags1 = extradata[0] | (extradata[1] << 8);
1212 flags2 = extradata[2] | (extradata[3] << 8);
1213 }else if (s->version == 2 && wfx->datalen >= 6){
1214 flags1 = extradata[0] | (extradata[1] << 8) |
1215 (extradata[2] << 16) | (extradata[3] << 24);
1216 flags2 = extradata[4] | (extradata[5] << 8);
1217 }
1218 s->use_exp_vlc = flags2 & 0x0001;
1219 s->use_bit_reservoir = flags2 & 0x0002;
1220 s->use_variable_block_len = flags2 & 0x0004;
1221
1222 /* compute MDCT block size */
1223 if (s->sample_rate <= 16000){
1224 s->frame_len_bits = 9;
1225 }else if (s->sample_rate <= 22050 ||
1226 (s->sample_rate <= 32000 && s->version == 1)){
1227 s->frame_len_bits = 10;
1228 }else{
1229 s->frame_len_bits = 11;
1230 }
1231 s->frame_len = 1 << s->frame_len_bits;
1232 if (s-> use_variable_block_len)
1233 {
1234 int nb_max, nb;
1235 nb = ((flags2 >> 3) & 3) + 1;
1236 if ((s->bit_rate / s->nb_channels) >= 32000)
1237 {
1238 nb += 2;
1239 }
1240 nb_max = s->frame_len_bits - BLOCK_MIN_BITS; //max is 11-7
1241 if (nb > nb_max)
1242 nb = nb_max;
1243 s->nb_block_sizes = nb + 1;
1244 }
1245 else
1246 {
1247 s->nb_block_sizes = 1;
1248 }
1249
1250 /* init rate dependant parameters */
1251 s->use_noise_coding = 1;
1252 high_freq = fixmul64byfixed(itofix64(s->sample_rate), 0x8000);
1253
1254
1255 /* if version 2, then the rates are normalized */
1256 sample_rate1 = s->sample_rate;
1257 if (s->version == 2)
1258 {
1259 if (sample_rate1 >= 44100)
1260 sample_rate1 = 44100;
1261 else if (sample_rate1 >= 22050)
1262 sample_rate1 = 22050;
1263 else if (sample_rate1 >= 16000)
1264 sample_rate1 = 16000;
1265 else if (sample_rate1 >= 11025)
1266 sample_rate1 = 11025;
1267 else if (sample_rate1 >= 8000)
1268 sample_rate1 = 8000;
1269 }
1270
1271 fixed64 tmp = itofix64(s->bit_rate);
1272 fixed64 tmp2 = itofix64(s->nb_channels * s->sample_rate);
1273 bps = fixdiv64(tmp, tmp2);
1274 fixed64 tim = fixmul64byfixed(bps, s->frame_len);
1275 fixed64 tmpi = fixdiv64(tim,itofix64(8));
1276 s->byte_offset_bits = av_log2(fixtoi64(tmpi)) + 2;
1277
1278 /* compute high frequency value and choose if noise coding should
1279 be activated */
1280 bps1 = bps;
1281 if (s->nb_channels == 2)
1282 bps1 = fixmul32(bps,0x1999a);
1283 if (sample_rate1 == 44100)
1284 {
1285 if (bps1 >= 0x9c29)
1286 s->use_noise_coding = 0;
1287 else
1288 high_freq = fixmul64byfixed(high_freq,0x6666);
1289 }
1290 else if (sample_rate1 == 22050)
1291 {
1292 if (bps1 >= 0x128f6)
1293 s->use_noise_coding = 0;
1294 else if (bps1 >= 0xb852)
1295 high_freq = fixmul64byfixed(high_freq,0xb333);
1296 else
1297 high_freq = fixmul64byfixed(high_freq,0x999a);
1298 }
1299 else if (sample_rate1 == 16000)
1300 {
1301 if (bps > 0x8000)
1302 high_freq = fixmul64byfixed(high_freq,0x8000);
1303 else
1304 high_freq = fixmul64byfixed(high_freq,0x4ccd);
1305 }
1306 else if (sample_rate1 == 11025)
1307 {
1308 high_freq = fixmul64byfixed(high_freq,0xb3333);
1309 }
1310 else if (sample_rate1 == 8000)
1311 {
1312 if (bps <= 0xa000)
1313 {
1314 high_freq = fixmul64byfixed(high_freq,0x8000);
1315 }
1316 else if (bps > 0xc000)
1317 {
1318 s->use_noise_coding = 0;
1319 }
1320 else
1321 {
1322 high_freq = fixmul64byfixed(high_freq,0xa666);
1323 }
1324 }
1325 else
1326 {
1327 if (bps >= 0xcccd)
1328 {
1329 high_freq = fixmul64byfixed(high_freq,0xc000);
1330 }
1331 else if (bps >= 0x999a)
1332 {
1333 high_freq = fixmul64byfixed(high_freq,0x999a);
1334 }
1335 else
1336 {
1337 high_freq = fixmul64byfixed(high_freq,0x8000);
1338 }
1339 }
1340
1341 /* compute the scale factor band sizes for each MDCT block size */
1342 {
1343 int a, b, pos, lpos, k, block_len, i, j, n;
1344 const uint8_t *table;
1345
1346 if (s->version == 1)
1347 {
1348 s->coefs_start = 3;
1349 }
1350 else
1351 {
1352 s->coefs_start = 0;
1353 }
1354 for(k = 0; k < s->nb_block_sizes; ++k)
1355 {
1356 block_len = s->frame_len >> k;
1357
1358 if (s->version == 1)
1359 {
1360 lpos = 0;
1361 for(i=0;i<25;++i)
1362 {
1363 a = wma_critical_freqs[i];
1364 b = s->sample_rate;
1365 pos = ((block_len * 2 * a) + (b >> 1)) / b;
1366 if (pos > block_len)
1367 pos = block_len;
1368 s->exponent_bands[0][i] = pos - lpos;
1369 if (pos >= block_len)
1370 {
1371 ++i;
1372 break;
1373 }
1374 lpos = pos;
1375 }
1376 s->exponent_sizes[0] = i;
1377 }
1378 else
1379 {
1380 /* hardcoded tables */
1381 table = NULL;
1382 a = s->frame_len_bits - BLOCK_MIN_BITS - k;
1383 if (a < 3)
1384 {
1385 if (s->sample_rate >= 44100)
1386 table = exponent_band_44100[a];
1387 else if (s->sample_rate >= 32000)
1388 table = exponent_band_32000[a];
1389 else if (s->sample_rate >= 22050)
1390 table = exponent_band_22050[a];
1391 }
1392 if (table)
1393 {
1394 n = *table++;
1395 for(i=0;i<n;++i)
1396 s->exponent_bands[k][i] = table[i];
1397 s->exponent_sizes[k] = n;
1398 }
1399 else
1400 {
1401 j = 0;
1402 lpos = 0;
1403 for(i=0;i<25;++i)
1404 {
1405 a = wma_critical_freqs[i];
1406 b = s->sample_rate;
1407 pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
1408 pos <<= 2;
1409 if (pos > block_len)
1410 pos = block_len;
1411 if (pos > lpos)
1412 s->exponent_bands[k][j++] = pos - lpos;
1413 if (pos >= block_len)
1414 break;
1415 lpos = pos;
1416 }
1417 s->exponent_sizes[k] = j;
1418 }
1419 }
1420
1421 /* max number of coefs */
1422 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
1423 /* high freq computation */
1424 fixed64 tmp = itofix64(block_len<<2);
1425 tmp = fixmul64byfixed(tmp,high_freq);
1426 fixed64 tmp2 = itofix64(s->sample_rate);
1427 tmp2 += 0x8000;
1428 s->high_band_start[k] = fixtoi64(fixdiv64(tmp,tmp2));
1429
1430 /*
1431 s->high_band_start[k] = (int)((block_len * 2 * high_freq) /
1432 s->sample_rate + 0.5);*/
1433
1434 n = s->exponent_sizes[k];
1435 j = 0;
1436 pos = 0;
1437 for(i=0;i<n;++i)
1438 {
1439 int start, end;
1440 start = pos;
1441 pos += s->exponent_bands[k][i];
1442 end = pos;
1443 if (start < s->high_band_start[k])
1444 start = s->high_band_start[k];
1445 if (end > s->coefs_end[k])
1446 end = s->coefs_end[k];
1447 if (end > start)
1448 s->exponent_high_bands[k][j++] = end - start;
1449 }
1450 s->exponent_high_sizes[k] = j;
1451 }
1452 }
1453
1454 /* init MDCT */
1455 tcosarray[0] = tcos0; tcosarray[1] = tcos1; tcosarray[2] = tcos2; tcosarray[3] = tcos3;tcosarray[4] = tcos4;
1456 tsinarray[0] = tsin0; tsinarray[1] = tsin1; tsinarray[2] = tsin2; tsinarray[3] = tsin3;tsinarray[4] = tsin4;
1457
1458 exparray[0] = exptab0; //exparray[1] = exptab1; exparray[2] = exptab2; exparray[3] = exptab3; exparray[4] = exptab4;
1459 revarray[0]=revtab0; revarray[1]=revtab1; revarray[2]=revtab2; revarray[3]=revtab3; revarray[4]=revtab4;
1460
1461 for(i = 0; i < s->nb_block_sizes; ++i)
1462 {
1463 ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1);
1464 }
1465
1466 /*ffmpeg uses malloc to only allocate as many window sizes as needed. However, we're really only interested in the worst case memory usage.
1467 * In the worst case you can have 5 window sizes, 128 doubling up 2048
1468 * Smaller windows are handled differently.
1469 * Since we don't have malloc, just statically allocate this
1470 */
1471 fixed32 *temp[5];
1472 temp[0] = stat0;
1473 temp[1] = stat1;
1474 temp[2] = stat2;
1475 temp[3] = stat3;
1476 temp[4] = stat4;
1477
1478 /* init MDCT windows : simple sinus window */
1479 for(i = 0; i < s->nb_block_sizes; i++)
1480 {
1481 int n, j;
1482 fixed32 alpha;
1483 n = 1 << (s->frame_len_bits - i);
1484 //window = av_malloc(sizeof(fixed32) * n);
1485 window = temp[i];
1486
1487 //fixed32 n2 = itofix32(n<<1); //2x the window length
1488 //alpha = fixdiv32(M_PI_F, n2); //PI / (2x Window length) == PI<<(s->frame_len_bits - i+1)
1489 //printf("two values of alpha %16.10lf %16.10lf\n", fixtof64(alpha), fixtof64(M_PI_F>>(s->frame_len_bits - i+1)));
1490 alpha = M_PI_F>>(s->frame_len_bits - i+1);
1491 for(j=0;j<n;++j)
1492 {
1493 fixed32 j2 = itofix32(j) + 0x8000;
1494 window[n - j - 1] = fixsin32(fixmul32(j2,alpha)); //alpha between 0 and pi/2
1495
1496 }
1497 //printf("created window\n");
1498 s->windows[i] = window;
1499 //printf("assigned window\n");
1500 }
1501
1502 s->reset_block_lengths = 1;
1503
1504 if (s->use_noise_coding)
1505 {
1506 /* init the noise generator */
1507 if (s->use_exp_vlc)
1508 {
1509 s->noise_mult = 0x51f;
1510 }
1511 else
1512 {
1513 s->noise_mult = 0xa3d;
1514 }
1515
1516
1517 {
1518 unsigned int seed;
1519 fixed32 norm;
1520 seed = 1;
1521 norm = 0; // PJJ: near as makes any diff to 0!
1522 for (i=0;i<NOISE_TAB_SIZE;++i)
1523 {
1524 seed = seed * 314159 + 1;
1525 s->noise_table[i] = itofix32((int)seed) * norm;
1526 }
1527 }
1528
1529 init_vlc(&s->hgain_vlc, 9, sizeof(hgain_huffbits),
1530 hgain_huffbits, 1, 1,
1531 hgain_huffcodes, 2, 2);
1532 }
1533
1534 if (s->use_exp_vlc)
1535 {
1536 s->exp_vlc.table = vlcbuf3;
1537 s->exp_vlc.table_allocated = 1536;
1538 init_vlc(&s->exp_vlc, 9, sizeof(scale_huffbits),
1539 scale_huffbits, 1, 1,
1540 scale_huffcodes, 4, 4);
1541 }
1542 else
1543 {
1544 wma_lsp_to_curve_init(s, s->frame_len);
1545 }
1546
1547 /* choose the VLC tables for the coefficients */
1548 coef_vlc_table = 2;
1549 if (s->sample_rate >= 32000)
1550 {
1551 if (bps1 < 0xb852)
1552 coef_vlc_table = 0;
1553 else if (bps1 < 0x128f6)
1554 coef_vlc_table = 1;
1555 }
1556
1557 runtabarray[0] = runtab0; runtabarray[1] = runtab1;
1558 levtabarray[0] = levtab0; levtabarray[1] = levtab1;
1559
1560 s->coef_vlc[0].table = vlcbuf1;
1561 s->coef_vlc[0].table_allocated = 24576/4;
1562 s->coef_vlc[1].table = vlcbuf2;
1563 s->coef_vlc[1].table_allocated = 14336/4;
1564
1565 init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0],
1566 &coef_vlcs[coef_vlc_table * 2], 0);
1567 init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1],
1568 &coef_vlcs[coef_vlc_table * 2 + 1], 1);
1569
1570 //filehandle = rb->open("/log.txt", O_WRONLY|O_CREAT|O_APPEND);
1571
1572
1573
1574 //rb->fdprintf(filehandle,"In init:\n\nsample rate %d\nbit_rate %d\n version %d\n", s->sample_rate, s->bit_rate, s->version );
1575 //rb->fdprintf(filehandle,"use_noise_coding %d \nframe_len %d\nframe_len_bits %d\n", s->use_noise_coding, s->frame_len, s->frame_len_bits);
1576 //rb->fdprintf(filehandle,"use_bit_reservoir %d\n use_variable_block_len %d\n use_exp_vlc %d\n",s->use_bit_reservoir, s->use_variable_block_len, s->use_exp_vlc);
1577 //rb->fdprintf(filehandle,"use_noise_coding %d\n byte_offset_bits %d\n use_exp_vlc %d\n",s->use_noise_coding, s->byte_offset_bits, s->use_exp_vlc);
1578 //rb->close(filehandle);
1579
1580
1581
1582 return 0;
1583}
1584
1585/* interpolate values for a bigger or smaller block. The block must
1586 have multiple sizes */
1587static void interpolate_array(fixed32 *scale, int old_size, int new_size)
1588{
1589 int i, j, jincr, k;
1590 fixed32 v;
1591
1592
1593
1594 if (new_size > old_size)
1595 {
1596 jincr = new_size / old_size;
1597 j = new_size;
1598 for(i = old_size - 1; i >=0; --i)
1599 {
1600 v = scale[i];
1601 k = jincr;
1602 do
1603 {
1604 scale[--j] = v;
1605 }
1606 while (--k);
1607 }
1608 }
1609 else if (new_size < old_size)
1610 {
1611 j = 0;
1612 jincr = old_size / new_size;
1613 for(i = 0; i < new_size; ++i)
1614 {
1615 scale[i] = scale[j];
1616 j += jincr;
1617 }
1618 }
1619}
1620
1621/* compute x^-0.25 with an exponent and mantissa table. We use linear
1622 interpolation to reduce the mantissa table size at a small speed
1623 expense (linear interpolation approximately doubles the number of
1624 bits of precision). */
1625static inline fixed32 pow_m1_4(WMADecodeContext *s, fixed32 x)
1626{
1627 union {
1628 fixed64 f;
1629 unsigned int v;
1630 } u, t;
1631 unsigned int e, m;
1632 fixed64 a, b;
1633
1634 u.f = x;
1635 e = u.v >> 23;
1636 m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1);
1637 /* build interpolation scale: 1 <= t < 2. */
1638 t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
1639 a = s->lsp_pow_m_table1[m];
1640 b = s->lsp_pow_m_table2[m];
1641 return lsp_pow_e_table[e] * (a + b * t.f);
1642}
1643
1644static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len)
1645{
1646 fixed32 wdel, a, b;
1647 int i, m;
1648
1649 wdel = fixdiv32(M_PI_F, itofix32(frame_len));
1650 for (i=0; i<frame_len; ++i)
1651 {
1652 s->lsp_cos_table[i] = 0x20000 * fixcos32(wdel * i); //wdel*i between 0 and pi
1653
1654 }
1655
1656
1657 /* NOTE: these two tables are needed to avoid two operations in
1658 pow_m1_4 */
1659 b = itofix32(1);
1660 int ix = 0;
1661 for(i=(1 << LSP_POW_BITS) - 1;i>=0;i--)
1662 {
1663 m = (1 << LSP_POW_BITS) + i;
1664 a = m * (0x8000 / (1 << LSP_POW_BITS)); //PJJ
1665 a = pow_a_table[ix++]; // PJJ : further refinement
1666 s->lsp_pow_m_table1[i] = 2 * a - b;
1667 s->lsp_pow_m_table2[i] = b - a;
1668 b = a;
1669 }
1670}
1671
1672/* NOTE: We use the same code as Vorbis here */
1673/* XXX: optimize it further with SSE/3Dnow */
1674static void wma_lsp_to_curve(WMADecodeContext *s,
1675 fixed32 *out,
1676 fixed32 *val_max_ptr,
1677 int n,
1678 fixed32 *lsp)
1679{
1680 int i, j;
1681 fixed32 p, q, w, v, val_max;
1682
1683 val_max = 0;
1684 for(i=0;i<n;++i)
1685 {
1686 p = 0x8000;
1687 q = 0x8000;
1688 w = s->lsp_cos_table[i];
1689 for (j=1;j<NB_LSP_COEFS;j+=2)
1690 {
1691 q *= w - lsp[j - 1];
1692 p *= w - lsp[j];
1693 }
1694 p *= p * (0x20000 - w);
1695 q *= q * (0x20000 + w);
1696 v = p + q;
1697 v = pow_m1_4(s, v); // PJJ
1698 if (v > val_max)
1699 val_max = v;
1700 out[i] = v;
1701 }
1702 *val_max_ptr = val_max;
1703}
1704
1705/* decode exponents coded with LSP coefficients (same idea as Vorbis) */
1706static void decode_exp_lsp(WMADecodeContext *s, int ch)
1707{
1708 fixed32 lsp_coefs[NB_LSP_COEFS];
1709 int val, i;
1710
1711 for (i = 0; i < NB_LSP_COEFS; ++i)
1712 {
1713 if (i == 0 || i >= 8)
1714 val = get_bits(&s->gb, 3);
1715 else
1716 val = get_bits(&s->gb, 4);
1717 lsp_coefs[i] = lsp_codebook[i][val];
1718 }
1719
1720 wma_lsp_to_curve(s,
1721 s->exponents[ch],
1722 &s->max_exponent[ch],
1723 s->block_len,
1724 lsp_coefs);
1725}
1726
1727/* decode exponents coded with VLC codes */
1728static int decode_exp_vlc(WMADecodeContext *s, int ch)
1729{
1730 int last_exp, n, code;
1731 const uint16_t *ptr, *band_ptr;
1732 fixed32 v, max_scale;
1733 fixed32 *q,*q_end;
1734
1735 band_ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
1736 ptr = band_ptr;
1737 q = s->exponents[ch];
1738 q_end = q + s->block_len;
1739 max_scale = 0;
1740
1741
1742 if (s->version == 1) //wmav1 only
1743 {
1744 last_exp = get_bits(&s->gb, 5) + 10;
1745 /* XXX: use a table */
1746 v = pow_10_to_yover16[last_exp];
1747 max_scale = v;
1748 n = *ptr++;
1749 do
1750 {
1751 *q++ = v;
1752 }
1753 while (--n);
1754 }
1755 last_exp = 36;
1756
1757 while (q < q_end)
1758 {
1759 code = get_vlc(&s->gb, &s->exp_vlc);
1760 if (code < 0)
1761 {
1762 return -1;
1763 }
1764 /* NOTE: this offset is the same as MPEG4 AAC ! */
1765 last_exp += code - 60;
1766 /* XXX: use a table */
1767 v = pow_10_to_yover16[last_exp];
1768 if (v > max_scale)
1769 {
1770 max_scale = v;
1771 }
1772 n = *ptr++;
1773 do
1774 {
1775 *q++ = v;
1776
1777 }
1778 while (--n);
1779 }
1780
1781 s->max_exponent[ch] = max_scale;
1782 return 0;
1783}
1784
1785/* return 0 if OK. return 1 if last block of frame. return -1 if
1786 unrecorrable error. */
1787static int wma_decode_block(WMADecodeContext *s)
1788{
1789 int n, v, a, ch, code, bsize;
1790 int coef_nb_bits, total_gain, parse_exponents;
1791 static fixed32 window[BLOCK_MAX_SIZE * 2]; //crap can't do this locally on the device! its big as the whole stack
1792 int nb_coefs[MAX_CHANNELS];
1793 fixed32 mdct_norm;
1794//int filehandle = rb->open("/mul.txt", O_WRONLY|O_CREAT|O_APPEND);
1795// rb->fdprintf(filehandle,"\nIn wma_decode_block:\n use_variable_block_len %d\n nb_block_sizes %d\n reset_block_lengths %d\n", s->use_variable_block_len, s->nb_block_sizes, s->reset_block_lengths );
1796
1797// printf("***decode_block: %d:%d (%d)\n", s->frame_count - 1, s->block_num, s->block_len);
1798 /* compute current block length */
1799 if (s->use_variable_block_len)
1800 {
1801 n = av_log2(s->nb_block_sizes - 1) + 1;
1802
1803 if (s->reset_block_lengths)
1804 {
1805 s->reset_block_lengths = 0;
1806 v = get_bits(&s->gb, n);
1807 if (v >= s->nb_block_sizes)
1808 {
1809 return -2;
1810 }
1811 s->prev_block_len_bits = s->frame_len_bits - v;
1812 v = get_bits(&s->gb, n);
1813 if (v >= s->nb_block_sizes)
1814 {
1815 return -3;
1816 }
1817 s->block_len_bits = s->frame_len_bits - v;
1818 }
1819 else
1820 {
1821 /* update block lengths */
1822 s->prev_block_len_bits = s->block_len_bits;
1823 s->block_len_bits = s->next_block_len_bits;
1824 }
1825 v = get_bits(&s->gb, n);
1826
1827 //rb->fdprintf(filehandle,"v %d \n prev_block_len_bits %d\n block_len_bits %d\n", v, s->prev_block_len_bits, s->block_len_bits);
1828 //rb->close(filehandle);
1829
1830 LOGF("v was %d", v);
1831 if (v >= s->nb_block_sizes)
1832 {
1833 // rb->splash(HZ*4, "v was %d", v); //5, 7
1834 return -4; //this is it
1835 }
1836 else{
1837 //rb->splash(HZ, "passed v block (%d)!", v);
1838 }
1839 s->next_block_len_bits = s->frame_len_bits - v;
1840 }
1841 else
1842 {
1843 /* fixed block len */
1844 s->next_block_len_bits = s->frame_len_bits;
1845 s->prev_block_len_bits = s->frame_len_bits;
1846 s->block_len_bits = s->frame_len_bits;
1847 }
1848 /* now check if the block length is coherent with the frame length */
1849 s->block_len = 1 << s->block_len_bits;
1850
1851 if ((s->block_pos + s->block_len) > s->frame_len)
1852 {
1853 return -5;
1854 }
1855
1856 if (s->nb_channels == 2)
1857 {
1858 s->ms_stereo = get_bits(&s->gb, 1);
1859 }
1860 v = 0;
1861 for (ch = 0; ch < s->nb_channels; ++ch)
1862 {
1863 a = get_bits(&s->gb, 1);
1864 s->channel_coded[ch] = a;
1865 v |= a;
1866 }
1867 /* if no channel coded, no need to go further */
1868 /* XXX: fix potential framing problems */
1869 if (!v)
1870 {
1871 goto next;
1872 }
1873
1874 bsize = s->frame_len_bits - s->block_len_bits;
1875
1876 /* read total gain and extract corresponding number of bits for
1877 coef escape coding */
1878 total_gain = 1;
1879 for(;;)
1880 {
1881 a = get_bits(&s->gb, 7);
1882 total_gain += a;
1883 if (a != 127)
1884 {
1885 break;
1886 }
1887 }
1888
1889 if (total_gain < 15)
1890 coef_nb_bits = 13;
1891 else if (total_gain < 32)
1892 coef_nb_bits = 12;
1893 else if (total_gain < 40)
1894 coef_nb_bits = 11;
1895 else if (total_gain < 45)
1896 coef_nb_bits = 10;
1897 else
1898 coef_nb_bits = 9;
1899 /* compute number of coefficients */
1900 n = s->coefs_end[bsize] - s->coefs_start;
1901
1902 for(ch = 0; ch < s->nb_channels; ++ch)
1903 {
1904 nb_coefs[ch] = n;
1905 }
1906 /* complex coding */
1907
1908 if (s->use_noise_coding)
1909 {
1910
1911 for(ch = 0; ch < s->nb_channels; ++ch)
1912 {
1913 if (s->channel_coded[ch])
1914 {
1915 int i, n, a;
1916 n = s->exponent_high_sizes[bsize];
1917 for(i=0;i<n;++i)
1918 {
1919 a = get_bits(&s->gb, 1);
1920 s->high_band_coded[ch][i] = a;
1921 /* if noise coding, the coefficients are not transmitted */
1922 if (a)
1923 nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
1924 }
1925 }
1926 }
1927 for(ch = 0; ch < s->nb_channels; ++ch)
1928 {
1929 if (s->channel_coded[ch])
1930 {
1931 int i, n, val, code;
1932
1933 n = s->exponent_high_sizes[bsize];
1934 val = (int)0x80000000;
1935 for(i=0;i<n;++i)
1936 {
1937 if (s->high_band_coded[ch][i])
1938 {
1939 if (val == (int)0x80000000)
1940 {
1941 val = get_bits(&s->gb, 7) - 19;
1942 }
1943 else
1944 {
1945 code = get_vlc(&s->gb, &s->hgain_vlc);
1946 if (code < 0)
1947 {
1948 return -6;
1949 }
1950 val += code - 18;
1951 }
1952 s->high_band_values[ch][i] = val;
1953 }
1954 }
1955 }
1956 }
1957 }
1958
1959 /* exposant can be interpolated in short blocks. */
1960 parse_exponents = 1;
1961 if (s->block_len_bits != s->frame_len_bits)
1962 {
1963 parse_exponents = get_bits(&s->gb, 1);
1964 }
1965
1966 if (parse_exponents)
1967 {
1968
1969 for(ch = 0; ch < s->nb_channels; ++ch)
1970 {
1971 if (s->channel_coded[ch])
1972 {
1973 if (s->use_exp_vlc)
1974 {
1975 if (decode_exp_vlc(s, ch) < 0)
1976 {
1977 return -7;
1978 }
1979 }
1980 else
1981 {
1982 decode_exp_lsp(s, ch);
1983 }
1984 }
1985 }
1986 }
1987 else
1988 {
1989 for(ch = 0; ch < s->nb_channels; ++ch)
1990 {
1991 if (s->channel_coded[ch])
1992 {
1993 interpolate_array(s->exponents[ch],
1994 1 << s->prev_block_len_bits,
1995 s->block_len);
1996 }
1997 }
1998 }
1999//ok up to here!
2000//printf("got here!\n");
2001//rb->splash(HZ, "in wma_decode_block 2");
2002 /* parse spectral coefficients : just RLE encoding */
2003 for(ch = 0; ch < s->nb_channels; ++ch)
2004 {
2005 if (s->channel_coded[ch])
2006 {
2007 VLC *coef_vlc;
2008 int level, run, sign, tindex;
2009 int16_t *ptr, *eptr;
2010 const int16_t *level_table, *run_table;
2011
2012 /* special VLC tables are used for ms stereo because
2013 there is potentially less energy there */
2014 tindex = (ch == 1 && s->ms_stereo);
2015 coef_vlc = &s->coef_vlc[tindex];
2016 run_table = s->run_table[tindex];
2017 level_table = s->level_table[tindex];
2018 /* XXX: optimize */
2019 ptr = &s->coefs1[ch][0];
2020 eptr = ptr + nb_coefs[ch];
2021 memset(ptr, 0, s->block_len * sizeof(int16_t));
2022
2023
2024
2025 for(;;)
2026 {
2027 code = get_vlc(&s->gb, coef_vlc);
2028 if (code < 0)
2029 {
2030 return -8;
2031 }
2032 if (code == 1)
2033 {
2034 /* EOB */
2035 break;
2036 }
2037 else if (code == 0)
2038 {
2039 /* escape */
2040 level = get_bits(&s->gb, coef_nb_bits);
2041 /* NOTE: this is rather suboptimal. reading
2042 block_len_bits would be better */
2043 run = get_bits(&s->gb, s->frame_len_bits);
2044 }
2045 else
2046 {
2047 /* normal code */
2048 run = run_table[code];
2049 level = level_table[code];
2050 }
2051 sign = get_bits(&s->gb, 1);
2052 if (!sign)
2053 level = -level;
2054 ptr += run;
2055 if (ptr >= eptr)
2056 {
2057 return -9;
2058 }
2059 *ptr++ = level;
2060
2061
2062 /* NOTE: EOB can be omitted */
2063 if (ptr >= eptr)
2064 break;
2065 }
2066 }
2067 if (s->version == 1 && s->nb_channels >= 2)
2068 {
2069 align_get_bits(&s->gb);
2070 }
2071 }
2072
2073 {
2074 int n4 = s->block_len >> 1;
2075 //mdct_norm = 0x10000;
2076 //mdct_norm = fixdiv32(mdct_norm,itofix32(n4));
2077
2078 mdct_norm = 0x10000>>(s->block_len_bits-1); //theres no reason to do a divide by two in fixed precision ...
2079
2080 if (s->version == 1)
2081 {
2082 fixed32 tmp = fixsqrt32(itofix32(n4));
2083 mdct_norm *= tmp; // PJJ : exercise this path
2084 }
2085 }
2086
2087
2088
2089//rb->splash(HZ, "in wma_decode_block 3");
2090 /* finally compute the MDCT coefficients */
2091 for(ch = 0; ch < s->nb_channels; ++ch)
2092 {
2093 if (s->channel_coded[ch])
2094 {
2095 int16_t *coefs1;
2096 fixed32 *exponents, *exp_ptr;
2097 fixed32 *coefs, atemp;
2098 fixed64 mult;
2099 fixed64 mult1;
2100 fixed32 noise;
2101 int i, j, n, n1, last_high_band;
2102 fixed32 exp_power[HIGH_BAND_MAX_SIZE];
2103
2104 //double test, mul;
2105
2106 //total_gain, coefs1, mdctnorm are lossless
2107
2108 coefs1 = s->coefs1[ch];
2109 exponents = s->exponents[ch];
2110 mult = fixdiv64(pow_table[total_gain],Fixed32To64(s->max_exponent[ch]));
2111 // mul = fixtof64(pow_table[total_gain])/(s->block_len/2)/fixtof64(s->max_exponent[ch]);
2112
2113 mult = fixmul64byfixed(mult, mdct_norm); //what the hell? This is actually fixed64*2^16!
2114 coefs = s->coefs[ch]; //VLC exponenents are used to get MDCT coef here!
2115
2116 n=0;
2117
2118 if (s->use_noise_coding)
2119 {
2120 mult1 = mult;
2121
2122 /* very low freqs : noise */
2123 for(i = 0;i < s->coefs_start; ++i)
2124 {
2125 *coefs++ = fixmul32(fixmul32(s->noise_table[s->noise_index],(*exponents++)),Fixed32From64(mult1));
2126 s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
2127 }
2128
2129 n1 = s->exponent_high_sizes[bsize];
2130
2131 /* compute power of high bands */
2132 exp_ptr = exponents +
2133 s->high_band_start[bsize] -
2134 s->coefs_start;
2135 last_high_band = 0; /* avoid warning */
2136 for (j=0;j<n1;++j)
2137 {
2138 n = s->exponent_high_bands[s->frame_len_bits -
2139 s->block_len_bits][j];
2140 if (s->high_band_coded[ch][j])
2141 {
2142 fixed32 e2, v;
2143 e2 = 0;
2144 for(i = 0;i < n; ++i)
2145 {
2146 v = exp_ptr[i];
2147 e2 += v * v;
2148 }
2149 exp_power[j] = fixdiv32(e2,n);
2150 last_high_band = j;
2151 }
2152 exp_ptr += n;
2153 }
2154
2155 /* main freqs and high freqs */
2156 for(j=-1;j<n1;++j)
2157 {
2158 if (j < 0)
2159 {
2160 n = s->high_band_start[bsize] -
2161 s->coefs_start;
2162 }
2163 else
2164 {
2165 n = s->exponent_high_bands[s->frame_len_bits -
2166 s->block_len_bits][j];
2167 }
2168 if (j >= 0 && s->high_band_coded[ch][j])
2169 {
2170 /* use noise with specified power */
2171 fixed32 tmp = fixdiv32(exp_power[j],exp_power[last_high_band]);
2172 mult1 = (fixed64)fixsqrt32(tmp);
2173 /* XXX: use a table */
2174 mult1 = mult1 * pow_table[s->high_band_values[ch][j]];
2175 mult1 = fixdiv64(mult1,fixmul32(s->max_exponent[ch],s->noise_mult));
2176 mult1 = fixmul64byfixed(mult1,mdct_norm);
2177 for(i = 0;i < n; ++i)
2178 {
2179 noise = s->noise_table[s->noise_index];
2180 s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
2181 *coefs++ = fixmul32(fixmul32(*exponents,noise),Fixed32From64(mult1));
2182 ++exponents;
2183 }
2184 }
2185 else
2186 {
2187 /* coded values + small noise */
2188 for(i = 0;i < n; ++i)
2189 {
2190 // PJJ: check code path
2191 noise = s->noise_table[s->noise_index];
2192 s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
2193 *coefs++ = fixmul32(fixmul32(((*coefs1++) + noise),*exponents),mult);
2194 ++exponents;
2195 }
2196 }
2197 }
2198
2199 /* very high freqs : noise */
2200 n = s->block_len - s->coefs_end[bsize];
2201 mult1 = fixmul32(mult,exponents[-1]);
2202 for (i = 0; i < n; ++i)
2203 {
2204 *coefs++ = fixmul32(s->noise_table[s->noise_index],Fixed32From64(mult1));
2205 s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
2206 }
2207 }
2208 else
2209 {
2210
2211 /* XXX: optimize more */
2212 for(i = 0;i < s->coefs_start; ++i)
2213 *coefs++ = 0; //why do we do this step?!
2214 n = nb_coefs[ch];
2215
2216
2217
2218
2219 for(i = 0;i < n; ++i)
2220 {
2221
2222 atemp = (fixed32)(coefs1[i]*mult>>16);
2223 //atemp= ftofix32(coefs1[i] * fixtof64(exponents[i]) * fixtof64(mult>>16)); //this "works" in the sense that the mdcts converge
2224 *coefs++=fixmul32(atemp,exponents[i]); //this does not work
2225
2226
2227 //atemp = ftofix32( coefs1[i]*mul* fixtof64(exponents[i]) ); //this doesn't seem to help any at all.
2228// *coefs++=atemp;
2229
2230 } //coefs1 could underflow?
2231 n = s->block_len - s->coefs_end[bsize];
2232 for(i = 0;i < n; ++i)
2233 *coefs++ = 0;
2234 }
2235 }
2236 }
2237
2238
2239//rb->splash(HZ, "in wma_decode_block 3b");
2240 if (s->ms_stereo && s->channel_coded[1])
2241 {
2242 fixed32 a, b;
2243 int i;
2244
2245 /* nominal case for ms stereo: we do it before mdct */
2246 /* no need to optimize this case because it should almost
2247 never happen */
2248 if (!s->channel_coded[0])
2249 {
2250 memset(s->coefs[0], 0, sizeof(fixed32) * s->block_len);
2251 s->channel_coded[0] = 1;
2252 }
2253
2254 for(i = 0; i < s->block_len; ++i)
2255 {
2256 a = s->coefs[0][i];
2257 b = s->coefs[1][i];
2258 s->coefs[0][i] = a + b;
2259 s->coefs[1][i] = a - b;
2260 }
2261 }
2262//rb->splash(HZ, "in wma_decode_block 3c");
2263 /* build the window : we ensure that when the windows overlap
2264 their squared sum is always 1 (MDCT reconstruction rule) */
2265 /* XXX: merge with output */
2266 {
2267 int i, next_block_len, block_len, prev_block_len, n;
2268 fixed32 *wptr;
2269
2270 block_len = s->block_len;
2271 prev_block_len = 1 << s->prev_block_len_bits;
2272 next_block_len = 1 << s->next_block_len_bits;
2273 //rb->splash(HZ, "in wma_decode_block 3d"); //got here
2274 /* right part */
2275 wptr = window + block_len;
2276 if (block_len <= next_block_len)
2277 {
2278 for(i=0;i<block_len;++i)
2279 *wptr++ = s->windows[bsize][i];
2280 }
2281 else
2282 {
2283 /* overlap */
2284 n = (block_len / 2) - (next_block_len / 2);
2285 for(i=0;i<n;++i)
2286 *wptr++ = itofix32(1);
2287 for(i=0;i<next_block_len;++i)
2288 *wptr++ = s->windows[s->frame_len_bits - s->next_block_len_bits][i];
2289 for(i=0;i<n;++i)
2290 *wptr++ = 0;
2291 }
2292//rb->splash(HZ, "in wma_decode_block 3e");
2293 /* left part */
2294 wptr = window + block_len;
2295 if (block_len <= prev_block_len)
2296 {
2297 for(i=0;i<block_len;++i)
2298 *--wptr = s->windows[bsize][i];
2299 }
2300 else
2301 {
2302 /* overlap */
2303 n = (block_len / 2) - (prev_block_len / 2);
2304 for(i=0;i<n;++i)
2305 *--wptr = itofix32(1);
2306 for(i=0;i<prev_block_len;++i)
2307 *--wptr = s->windows[s->frame_len_bits - s->prev_block_len_bits][i];
2308 for(i=0;i<n;++i)
2309 *--wptr = 0;
2310 }
2311 }
2312
2313
2314 for(ch = 0; ch < s->nb_channels; ++ch)
2315 {
2316 if (s->channel_coded[ch])
2317 {
2318 static fixed32 output[BLOCK_MAX_SIZE * 2];
2319 fixed32 *ptr;
2320 int i, n4, index, n;
2321
2322 n = s->block_len;
2323 n4 = s->block_len >>1;
2324 //rb->splash(HZ, "in wma_decode_block 4");
2325 ff_imdct_calc(&s->mdct_ctx[bsize],
2326 output,
2327 s->coefs[ch],
2328 s->mdct_tmp);
2329
2330 /* XXX: optimize all that by build the window and
2331 multipying/adding at the same time */
2332 /* multiply by the window */
2333//already broken here!
2334
2335
2336
2337
2338
2339 for(i=0;i<n * 2;++i)
2340 {
2341
2342 output[i] = fixmul32(output[i], window[i]);
2343 //output[i] *= window[i];
2344
2345 }
2346
2347
2348 /* add in the frame */
2349 index = (s->frame_len / 2) + s->block_pos - n4;
2350 ptr = &s->frame_out[ch][index];
2351
2352 for(i=0;i<n * 2;++i)
2353 {
2354 *ptr += output[i];
2355 ++ptr;
2356
2357
2358 }
2359
2360
2361 /* specific fast case for ms-stereo : add to second
2362 channel if it is not coded */
2363 if (s->ms_stereo && !s->channel_coded[1])
2364 {
2365 ptr = &s->frame_out[1][index];
2366 for(i=0;i<n * 2;++i)
2367 {
2368 *ptr += output[i];
2369 ++ptr;
2370 }
2371 }
2372 }
2373 }
2374next:
2375 /* update block number */
2376 ++s->block_num;
2377 s->block_pos += s->block_len;
2378 if (s->block_pos >= s->frame_len)
2379 {
2380 return 1;
2381 }
2382 else
2383 {
2384 return 0;
2385 }
2386}
2387
2388/* decode a frame of frame_len samples */
2389static int wma_decode_frame(WMADecodeContext *s, int16_t *samples)
2390{
2391 int ret, i, n, a, ch, incr;
2392 int16_t *ptr;
2393 fixed32 *iptr;
2394 // rb->splash(HZ, "in wma_decode_frame");
2395
2396 /* read each block */
2397 s->block_num = 0;
2398 s->block_pos = 0;
2399
2400
2401 for(;;)
2402 {
2403 ret = wma_decode_block(s);
2404 if (ret < 0)
2405 {
2406 LOGF("wma_decode_block: %d",ret);
2407 //rb->splash(HZ*4, "wma_decode_block failed with ret %d", ret);
2408 return -1;
2409 }
2410 if (ret)
2411 {
2412 break;
2413 }
2414 }
2415
2416 /* convert frame to integer */
2417 n = s->frame_len;
2418 incr = s->nb_channels;
2419 for(ch = 0; ch < s->nb_channels; ++ch)
2420 {
2421 ptr = samples + ch;
2422 iptr = s->frame_out[ch];
2423
2424 for (i=0;i<n;++i)
2425 {
2426 a = fixtoi32(*iptr++)<<1; //ugly but good enough for now
2427
2428
2429
2430
2431
2432 if (a > 32767)
2433 {
2434 a = 32767;
2435 }
2436 else if (a < -32768)
2437 {
2438 a = -32768;
2439 }
2440 *ptr = a;
2441 ptr += incr;
2442 }
2443 /* prepare for next block */
2444 memmove(&s->frame_out[ch][0], &s->frame_out[ch][s->frame_len],
2445 s->frame_len * sizeof(fixed32));
2446 /* XXX: suppress this */
2447 memset(&s->frame_out[ch][s->frame_len], 0,
2448 s->frame_len * sizeof(fixed32));
2449 }
2450
2451 return 0;
2452}
2453
2454int wma_decode_superframe(WMADecodeContext* s,
2455 void *data,
2456 int *data_size,
2457 uint8_t *buf,
2458 int buf_size)
2459{
2460 //WMADecodeContext *s = avctx->priv_data;
2461 int nb_frames, bit_offset, i, pos, len;
2462 uint8_t *q;
2463 int16_t *samples;
2464
2465 if (buf_size==0)
2466 {
2467 s->last_superframe_len = 0;
2468 return 0;
2469 }
2470
2471 samples = data;
2472 init_get_bits(&s->gb, buf, buf_size*8);
2473 if (s->use_bit_reservoir)
2474 {
2475 /* read super frame header */
2476 get_bits(&s->gb, 4); /* super frame index */
2477 nb_frames = get_bits(&s->gb, 4) - 1;
2478
2479 bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);
2480 if (s->last_superframe_len > 0)
2481 {
2482 /* add bit_offset bits to last frame */
2483 if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) >
2484 MAX_CODED_SUPERFRAME_SIZE)
2485 {
2486 goto fail;
2487 }
2488 q = s->last_superframe + s->last_superframe_len;
2489 len = bit_offset;
2490 while (len > 0)
2491 {
2492 *q++ = (get_bits)(&s->gb, 8);
2493 len -= 8;
2494 }
2495 if (len > 0)
2496 {
2497 *q++ = (get_bits)(&s->gb, len) << (8 - len);
2498 }
2499
2500 /* XXX: bit_offset bits into last frame */
2501 init_get_bits(&s->gb, s->last_superframe, MAX_CODED_SUPERFRAME_SIZE*8);
2502 /* skip unused bits */
2503 if (s->last_bitoffset > 0)
2504 skip_bits(&s->gb, s->last_bitoffset);
2505 /* this frame is stored in the last superframe and in the
2506 current one */
2507 if (wma_decode_frame(s, samples) < 0)
2508 {
2509 goto fail;
2510 }
2511 samples += s->nb_channels * s->frame_len;
2512 }
2513
2514 /* read each frame starting from bit_offset */
2515 pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
2516 init_get_bits(&s->gb, buf + (pos >> 3), (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3))*8);
2517 len = pos & 7;
2518 if (len > 0)
2519 skip_bits(&s->gb, len);
2520
2521 s->reset_block_lengths = 1;
2522 for(i=0;i<nb_frames;++i)
2523 {
2524 if (wma_decode_frame(s, samples) < 0)
2525 {
2526 goto fail;
2527 }
2528 samples += s->nb_channels * s->frame_len;
2529 }
2530
2531 /* we copy the end of the frame in the last frame buffer */
2532 pos = get_bits_count(&s->gb) + ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7);
2533 s->last_bitoffset = pos & 7;
2534 pos >>= 3;
2535 len = buf_size - pos;
2536 if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0)
2537 {
2538 goto fail;
2539 }
2540 s->last_superframe_len = len;
2541 memcpy(s->last_superframe, buf + pos, len);
2542 }
2543 else
2544 {
2545 /* single frame decode */
2546 if (wma_decode_frame(s, samples) < 0)
2547 {
2548 goto fail;
2549 }
2550 samples += s->nb_channels * s->frame_len;
2551 }
2552 *data_size = (int8_t *)samples - (int8_t *)data;
2553 return s->block_align;
2554fail:
2555 /* when error, we reset the bit reservoir */
2556 s->last_superframe_len = 0;
2557 return -1;
2558}
2559
2560/*void free_vlc(VLC *vlc)
2561{
2562 //av_free(vlc->table);
2563}
2564*/
2565int wma_decode_end(WMADecodeContext *s)
2566{
2567 (void)s;
2568/* WMADecodeContext *s = avctx->priv_data;
2569 int i;
2570
2571 for(i = 0; i < s->nb_block_sizes; ++i)
2572 ff_mdct_end(&s->mdct_ctx[i]);
2573 // for(i = 0; i < s->nb_block_sizes; ++i) //now statically allocated
2574 // av_free(s->windows[i]);
2575
2576 if (s->use_exp_vlc)
2577 {
2578 free_vlc(&s->exp_vlc);
2579 }
2580 if (s->use_noise_coding)
2581 {
2582 free_vlc(&s->hgain_vlc);
2583 }
2584 for(i = 0;i < 2; ++i)
2585 {
2586 // free_vlc(&s->coef_vlc[i]);
2587 // av_free(s->run_table[i]);
2588 // av_free(s->level_table[i]);
2589 }
2590*/
2591 return 0;
2592}
diff --git a/apps/codecs/wma.c b/apps/codecs/wma.c
new file mode 100644
index 0000000000..5303eb4287
--- /dev/null
+++ b/apps/codecs/wma.c
@@ -0,0 +1,385 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: flac.c 12830 2007-03-18 09:50:53Z learman $
9 *
10 * Copyright (C) 2005 Dave Chapman
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "codeclib.h"
21#include "libwma/asf.h"
22#include "libwma/wmadec.h"
23
24CODEC_HEADER
25
26#define MAX_BLOCKSIZE 2048
27
28/* The output buffers containing the decoded samples (channels 0 and 1) */
29
30/* NOTE: WMADecodeContext is 142688 bytes (on x86) */
31static WMADecodeContext wmadec;
32
33/* TODO: Check the size of this */
34#define OUTBUF_SIZE 256*1024
35
36enum asf_error_e {
37 ASF_ERROR_INTERNAL = -1, /* incorrect input to API calls */
38 ASF_ERROR_OUTOFMEM = -2, /* some malloc inside program failed */
39 ASF_ERROR_EOF = -3, /* unexpected end of file */
40 ASF_ERROR_IO = -4, /* error reading or writing to file */
41 ASF_ERROR_INVALID_LENGTH = -5, /* length value conflict in input data */
42 ASF_ERROR_INVALID_VALUE = -6, /* other value conflict in input data */
43 ASF_ERROR_INVALID_OBJECT = -7, /* ASF object missing or in wrong place */
44 ASF_ERROR_OBJECT_SIZE = -8, /* invalid ASF object size (too small) */
45 ASF_ERROR_SEEKABLE = -9, /* file not seekable */
46 ASF_ERROR_SEEK = -10 /* file is seekable but seeking failed */
47};
48
49/* Read an unaligned 32-bit little endian long from buffer. */
50static unsigned long get_long_le(void* buf)
51{
52 unsigned char* p = (unsigned char*) buf;
53
54 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
55}
56
57/* Read an unaligned 16-bit little endian short from buffer. */
58static unsigned short get_short_le(void* buf)
59{
60 unsigned char* p = (unsigned char*) buf;
61
62 return p[0] | (p[1] << 8);
63}
64
65#define GETLEN2b(bits) (((bits) == 0x03) ? 4 : bits)
66
67#define GETVALUE2b(bits, data) \
68 (((bits) != 0x03) ? ((bits) != 0x02) ? ((bits) != 0x01) ? \
69 0 : *(data) : get_short_le(data) : get_long_le(data))
70
71static int asf_read_packet(int* padding, asf_waveformatex_t* wfx)
72{
73 uint8_t tmp8, packet_flags, packet_property;
74 int ec_length, opaque_data, ec_length_type;
75 int datalen;
76 uint8_t data[18];
77 uint8_t* datap;
78 uint32_t length;
79 uint32_t padding_length;
80 uint32_t send_time;
81 uint16_t duration;
82 uint16_t payload_count;
83 int payload_length_type;
84 uint32_t payload_hdrlen;
85 int payload_datalen;
86 int multiple;
87 uint32_t replicated_length;
88 uint32_t media_object_number;
89 uint32_t media_object_offset;
90 uint32_t bytesread = 0;
91
92 if (ci->read_filebuf(&tmp8, 1) == 0) {
93 return ASF_ERROR_EOF;
94 }
95 bytesread++;
96
97 /* TODO: We need a better way to detect endofstream */
98 if (tmp8 != 0x82) { return -1; }
99
100 //DEBUGF("tmp8=0x%02x\n",tmp8);
101
102 if (tmp8 & 0x80) {
103 ec_length = tmp8 & 0x0f;
104 opaque_data = (tmp8 >> 4) & 0x01;
105 ec_length_type = (tmp8 >> 5) & 0x03;
106
107 if (ec_length_type != 0x00 || opaque_data != 0 || ec_length != 0x02) {
108 DEBUGF("incorrect error correction flags\n");
109 return ASF_ERROR_INVALID_VALUE;
110 }
111
112 /* Skip ec_data */
113 ci->advance_buffer(ec_length);
114 bytesread += ec_length;
115 } else {
116 ec_length = 0;
117 }
118
119 if (ci->read_filebuf(&packet_flags, 1) == 0) { return ASF_ERROR_EOF; }
120 if (ci->read_filebuf(&packet_property, 1) == 0) { return ASF_ERROR_EOF; }
121 bytesread += 2;
122
123 datalen = GETLEN2b((packet_flags >> 1) & 0x03) +
124 GETLEN2b((packet_flags >> 3) & 0x03) +
125 GETLEN2b((packet_flags >> 5) & 0x03) + 6;
126
127#if 0
128 if (datalen > sizeof(data)) {
129 DEBUGF("Unexpectedly long datalen in data - %d\n",datalen);
130 return ASF_ERROR_OUTOFMEM;
131 }
132#endif
133
134 if (ci->read_filebuf(data, datalen) == 0) {
135 return ASF_ERROR_EOF;
136 }
137
138 bytesread += datalen;
139
140 datap = data;
141 length = GETVALUE2b((packet_flags >> 5) & 0x03, datap);
142 datap += GETLEN2b((packet_flags >> 5) & 0x03);
143 /* sequence value is not used */
144 GETVALUE2b((packet_flags >> 1) & 0x03, datap);
145 datap += GETLEN2b((packet_flags >> 1) & 0x03);
146 padding_length = GETVALUE2b((packet_flags >> 3) & 0x03, datap);
147 datap += GETLEN2b((packet_flags >> 3) & 0x03);
148 send_time = get_long_le(datap);
149 datap += 4;
150 duration = get_short_le(datap);
151 datap += 2;
152
153 /* this is really idiotic, packet length can (and often will) be
154 * undefined and we just have to use the header packet size as the size
155 * value */
156 if (!((packet_flags >> 5) & 0x03)) {
157 length = wfx->packet_size;
158 }
159
160 /* this is also really idiotic, if packet length is smaller than packet
161 * size, we need to manually add the additional bytes into padding length
162 */
163 if (length < wfx->packet_size) {
164 padding_length += wfx->packet_size - length;
165 length = wfx->packet_size;
166 }
167
168 if (length > wfx->packet_size) {
169 DEBUGF("packet with too big length value\n");
170 return ASF_ERROR_INVALID_LENGTH;
171 }
172
173 /* check if we have multiple payloads */
174 if (packet_flags & 0x01) {
175 if (ci->read_filebuf(&tmp8, 1) == 0) {
176 return ASF_ERROR_EOF;
177 }
178 payload_count = tmp8 & 0x3f;
179 payload_length_type = (tmp8 >> 6) & 0x03;
180 bytesread++;
181 } else {
182 payload_count = 1;
183 payload_length_type = 0x02; /* not used */
184 }
185
186 if (length < bytesread) {
187 DEBUGF("header exceeded packet size, invalid file - length=%d, bytesread=%d\n",(int)length,(int)bytesread);
188 /* FIXME: should this be checked earlier? */
189 return ASF_ERROR_INVALID_LENGTH;
190 }
191
192 if (ci->read_filebuf(&tmp8, 1) == 0) {
193 return ASF_ERROR_EOF;
194 }
195 //DEBUGF("stream = %u\n",tmp8&0x7f);
196 bytesread++;
197
198 if ((tmp8 & 0x7f) != wfx->audiostream) {
199 /* Not interested in this packet, just skip it */
200 ci->advance_buffer(length - bytesread);
201 return 0;
202 } else {
203 /* We are now at the data */
204 //DEBUGF("Read packet - length=%u, padding_length=%u, send_time=%u, duration=%u, payload_count=%d, bytesread=%d\n",length,padding_length,(int)send_time,duration,payload_count,bytesread);
205
206 /* TODO: Loop through all payloads in this packet - or do we
207 assume that audio streams only have one payload per packet? */
208
209 payload_hdrlen = GETLEN2b(packet_property & 0x03) +
210 GETLEN2b((packet_property >> 2) & 0x03) +
211 GETLEN2b((packet_property >> 4) & 0x03);
212
213 //DEBUGF("payload_hdrlen = %d\n",payload_hdrlen);
214#if 0
215 /* TODO */
216 if (payload_hdrlen > size) {
217 return ASF_ERROR_INVALID_LENGTH;
218 }
219#endif
220 if (payload_hdrlen > sizeof(data)) {
221 DEBUGF("Unexpectedly long datalen in data - %d\n",datalen);
222 return ASF_ERROR_OUTOFMEM;
223 }
224
225 if (ci->read_filebuf(data, payload_hdrlen) == 0) {
226 return ASF_ERROR_EOF;
227 }
228 bytesread += payload_hdrlen;
229
230 datap = data;
231 media_object_number = GETVALUE2b((packet_property >> 4) & 0x03, datap);
232 datap += GETLEN2b((packet_property >> 4) & 0x03);
233 media_object_offset = GETVALUE2b((packet_property >> 2) & 0x03, datap);
234 datap += GETLEN2b((packet_property >> 2) & 0x03);
235 replicated_length = GETVALUE2b(packet_property & 0x03, datap);
236 datap += GETLEN2b(packet_property & 0x03);
237
238 /* TODO: Validate replicated_length */
239 /* TODO: Is the content of this important for us? */
240 ci->advance_buffer(replicated_length);
241 bytesread += replicated_length;
242
243
244 multiple = packet_flags & 0x01;
245
246 if (multiple) {
247 int x;
248
249 x = GETLEN2b(payload_length_type);
250
251 if (x != 2) {
252 /* in multiple payloads datalen should be a word */
253 return ASF_ERROR_INVALID_VALUE;
254 }
255
256#if 0
257 if (skip + tmp > datalen) {
258 /* not enough data */
259 return ASF_ERROR_INVALID_LENGTH;
260 }
261#endif
262 if (ci->read_filebuf(&data, x) == 0) {
263 return ASF_ERROR_EOF;
264 }
265 bytesread += x;
266 payload_datalen = GETVALUE2b(payload_length_type, data);
267 } else {
268 payload_datalen = length - bytesread;
269 }
270
271 //DEBUGF("WE HAVE DATA - %d bytes\n", payload_datalen);
272// lseek(fd, payload_datalen, SEEK_CUR);
273 *padding = padding_length;
274 return payload_datalen;
275 }
276}
277
278/* this is the codec entry point */
279enum codec_status codec_main(void)
280{
281 uint32_t samplesdone;
282 uint32_t elapsedtime;
283 int retval;
284 asf_waveformatex_t wfx;
285 uint32_t currentframe;
286 unsigned char* inbuffer;
287 size_t resume_offset;
288 size_t n;
289 int wmares, res, padding, outbufsize;
290 uint8_t* outbuf;
291
292 /* Generic codec initialisation */
293 ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512);
294 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, 1024*128);
295
296 ci->configure(DSP_SET_SAMPLE_DEPTH, 15);
297
298 next_track:
299
300 /* Wait for the metadata to be read */
301 while (!*ci->taginfo_ready && !ci->stop_codec)
302 ci->sleep(1);
303
304 retval = CODEC_OK;
305
306 /* Remember the resume position - when the codec is opened, the
307 playback engine will reset it. */
308 resume_offset = ci->id3->offset;
309
310 if (codec_init()) {
311 LOGF("WMA: Error initialising codec\n");
312 retval = CODEC_ERROR;
313 goto exit;
314 }
315
316 outbuf = codec_malloc(OUTBUF_SIZE);
317
318 /* Copy the format metadata we've stored in the id3 TOC field. This
319 saves us from parsing it again here. */
320 memcpy(&wfx, ci->id3->toc, sizeof(wfx));
321
322 wma_decode_init(&wmadec,&wfx);
323
324 /* Now advance the file position to the first frame */
325 ci->seek_buffer(ci->id3->first_frame_offset);
326
327 ci->configure(DSP_SWITCH_FREQUENCY, wfx.rate);
328 ci->configure(DSP_SET_STEREO_MODE, wfx.channels == 1 ?
329 STEREO_MONO : STEREO_INTERLEAVED);
330 codec_set_replaygain(ci->id3);
331
332 /* The main decoding loop */
333
334 currentframe = 0;
335 samplesdone = 0;
336
337 DEBUGF("**************** IN WMA.C ******************\n");
338 wma_decode_init(&wmadec,&wfx);
339
340 res = 1;
341 while (res >= 0)
342 {
343 ci->yield();
344 if (ci->stop_codec || ci->new_track) {
345 goto done;
346 }
347
348 /* Deal with any pending seek requests - ignore them */
349 if (ci->seek_time)
350 {
351 ci->seek_complete();
352 }
353
354 res = asf_read_packet(&padding, &wfx);
355 if (res > 0) {
356 inbuffer = ci->request_buffer(&n, res - padding);
357
358 wmares = wma_decode_superframe(&wmadec,
359 outbuf,&outbufsize,
360 inbuffer,res - padding);
361
362 ci->advance_buffer(res);
363
364 if (wmares > 0) {
365 ci->pcmbuf_insert(outbuf, NULL, outbufsize / (wfx.channels * 2));
366 samplesdone += (outbufsize / (wfx.channels * 2));
367 DEBUGF("Decoded %d samples\n",(outbufsize / (wfx.channels * 2)));
368 elapsedtime = (samplesdone*10)/(wfx.rate/100);
369 ci->set_elapsed(elapsedtime);
370 }
371
372 ci->yield ();
373 }
374 }
375 retval = CODEC_OK;
376
377done:
378 LOGF("WMA: Decoded %ld samples\n",samplesdone);
379
380 if (ci->request_next_track())
381 goto next_track;
382
383exit:
384 return retval;
385}