summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rwxr-xr-xconfigure39
-rw-r--r--tremor/COPYING28
-rw-r--r--tremor/Makefile42
-rw-r--r--tremor/asm_arm.h243
-rw-r--r--tremor/backends.h127
-rw-r--r--tremor/bitwise.c144
-rw-r--r--tremor/block.c409
-rw-r--r--tremor/codebook.c347
-rw-r--r--tremor/codebook.h99
-rw-r--r--tremor/codec_internal.h87
-rw-r--r--tremor/config_types.h22
-rw-r--r--tremor/floor0.c436
-rw-r--r--tremor/floor1.c438
-rw-r--r--tremor/framing.c672
-rw-r--r--tremor/info.c351
-rw-r--r--tremor/ivorbiscodec.h198
-rw-r--r--tremor/lsp_lookup.h133
-rw-r--r--tremor/mapping0.c319
-rw-r--r--tremor/mdct.c510
-rw-r--r--tremor/mdct.h52
-rw-r--r--tremor/mdct_lookup.h540
-rw-r--r--tremor/misc.h238
-rw-r--r--tremor/ogg.h167
-rw-r--r--tremor/os.h59
-rw-r--r--tremor/os_types.h88
-rw-r--r--tremor/registry.c47
-rw-r--r--tremor/registry.h37
-rw-r--r--tremor/res012.c331
-rw-r--r--tremor/sharedbook.c439
-rw-r--r--tremor/synthesis.c102
-rw-r--r--tremor/window.c84
-rw-r--r--tremor/window.h27
-rw-r--r--tremor/window_lookup.h2084
34 files changed, 8942 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index d3f52f13ca..795a885068 100644
--- a/Makefile
+++ b/Makefile
@@ -77,6 +77,9 @@ endif
ifeq ($(LIBMENU),yes)
PARTS += libmenu
endif
+ifeq ($(TREMOR),yes)
+PARTS += tremor
+endif
ALL_PRG = $(PRG)
ifeq ($(MENCODER),yes)
@@ -100,6 +103,10 @@ endif
ifeq ($(INTERNAL_FAAD),yes)
COMMON_DEPS += libfaad2/libfaad2.a
endif
+ifeq ($(TREMOR),yes)
+COMMON_DEPS += tremor/libvorbisidec.a
+COMMON_LIBS += tremor/libvorbisidec.a
+endif
ifeq ($(VIDIX),yes)
COMMON_DEPS += libdha/libdha.so vidix/libvidix.a
endif
@@ -184,6 +191,9 @@ libfaad2/libfaad2.a:
mp3lib/libMP3.a:
$(MAKE) -C mp3lib
+tremor/libvorbisidec.a:
+ $(MAKE) -C tremor
+
libdha/libdha.so:
$(MAKE) -C libdha
diff --git a/configure b/configure
index 0d8dda6dd0..a6c20ad171 100755
--- a/configure
+++ b/configure
@@ -205,8 +205,10 @@ Codecs:
--disable-libavcodec disable libavcodec [autodetect]
--disable-libavformat disable libavformat [autodetect]
--enable-libfame enable libfame realtime encoder [autodetect]
- --enable-vorbis build with OggVorbis support [autodetect]
- --enable-tremor build with integer-only OggVorbis support [disabled]
+ --disable-internal-tremor do not build internal OggVorbis support [enabled]
+ --enable-tremor-low build with lower accuracy internal tremor [disabled]
+ --enable-external-tremor build with external tremor [disabled]
+ --disable-vorbis disable OggVorbis support entirely [autodetect]
--enable-theora build with OggTheora support [autodetect]
--disable-internal-matroska disable internal Matroska support [enabled]
--enable-external-faad build with external FAAD2 (AAC) support [autodetect]
@@ -1314,6 +1316,8 @@ _jack=auto
_liblzo=auto
_mad=auto
_toolame=auto
+_tremor_internal=yes
+_tremor_low=no
_vorbis=auto
_theora=auto
_mp3lib=yes
@@ -1499,8 +1503,12 @@ for ac_option do
--disable-liblzo) _liblzo=no ;;
--enable-vorbis) _vorbis=yes ;;
--disable-vorbis) _vorbis=no ;;
- --enable-tremor) _tremor=yes ;;
- --disable-tremor) _tremor=no ;;
+ --enable-internal-tremor) _tremor_internal=yes ;;
+ --disable-internal-tremor) _tremor_internal=no ;;
+ --enable-tremor-low) _tremor_low=yes ;;
+ --disable-tremor-low) _tremor_low=no ;;
+ --enable-external-tremor) _tremor=yes ;;
+ --disable-external-tremor) _tremor=no ;;
--enable-theora) _theora=yes ;;
--disable-theora) _theora=no ;;
--enable-mp3lib) _mp3lib=yes ;;
@@ -5102,7 +5110,9 @@ else
fi
echocheck "OggVorbis support"
-if test "$_vorbis" = auto ; then
+if test "$_tremor_internal" = yes; then
+ _vorbis=yes
+elif test "$_vorbis" = auto; then
_vorbis=no
cat > $TMPC << EOF
#include <vorbis/codec.h>
@@ -5112,7 +5122,16 @@ EOF
fi
if test "$_vorbis" = yes ; then
_def_vorbis='#define HAVE_OGGVORBIS 1'
- if test "$_tremor" = yes ; then
+ if test "$_tremor_internal" = yes ; then
+ # do not set _ld_vorbis as it is resolved separately
+ # mp3lame support for vorbis is deprecated so don't care
+ _def_tremor='#define TREMOR 1'
+ if test "$_tremor_low" = yes ; then
+ _tremor_flags='-D_LOW_ACCURACY_'
+ else
+ _tremor_flags=''
+ fi
+ elif test "$_tremor" = yes ; then
_def_tremor='#define TREMOR 1'
_ld_vorbis='-lvorbisidec'
else
@@ -5125,7 +5144,11 @@ else
_def_tremor='#undef TREMOR'
_nocodecmodules="libvorbis $_nocodecmodules"
fi
-if test "$_vorbis" = yes -a "$_tremor" = yes ; then
+if test "$_vorbis" = yes -a "$_tremor_internal" = yes -a "$_tremor_low" = yes ; then
+ echores "$_vorbis (internal low accuracy Tremor)"
+elif test "$_vorbis" = yes -a "$_tremor_internal" = yes ; then
+ echores "$_vorbis (internal Tremor)"
+elif test "$_vorbis" = yes -a "$_tremor" = yes ; then
echores "$_vorbis (Tremor)"
else
echores "$_vorbis"
@@ -6650,6 +6673,8 @@ OPENDIVX = $_opendivx
MP3LIB = $_mp3lib
LIBA52 = $_liba52
LIBMPEG2 = $_libmpeg2
+TREMOR = $_tremor_internal
+TREMOR_FLAGS = $_tremor_flags
UNRARLIB = $_unrarlib
HAVE_FFPOSTPROCESS = $_def_haveffpostprocess
diff --git a/tremor/COPYING b/tremor/COPYING
new file mode 100644
index 0000000000..6111c6c5a6
--- /dev/null
+++ b/tremor/COPYING
@@ -0,0 +1,28 @@
+Copyright (c) 2002, Xiph.org Foundation
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+- Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+- Neither the name of the Xiph.org Foundation nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/tremor/Makefile b/tremor/Makefile
new file mode 100644
index 0000000000..68f27e653b
--- /dev/null
+++ b/tremor/Makefile
@@ -0,0 +1,42 @@
+
+LIBNAME = libvorbisidec.a
+
+include ../config.mak
+
+SRCS = bitwise.c block.c codebook.c floor0.c floor1.c framing.c info.c \
+mapping0.c mdct.c registry.c res012.c sharedbook.c synthesis.c window.c
+
+OBJS = $(SRCS:.c=.o)
+INCLUDE = -I. -I.. $(EXTRA_INC)
+CFLAGS = $(OPTFLAGS) $(INCLUDE) $(TREMOR_FLAGS)
+
+.SUFFIXES: .c .o
+
+# .PHONY: all clean
+
+.c.o:
+ $(CC) -c $(CFLAGS) -o $@ $<
+
+$(LIBNAME): $(OBJS)
+ $(AR) r $(LIBNAME) $(OBJS)
+ $(RANLIB) $(LIBNAME)
+
+all: $(LIBNAME)
+
+clean:
+ rm -f *.o *.a *~
+
+distclean:
+ rm -f Makefile.bak *.o *.a *~ .depend
+
+dep: depend
+
+depend:
+ $(CC) -MM $(CFLAGS) $(SRCS) 1>.depend
+
+#
+# include dependency files if they exist
+#
+ifneq ($(wildcard .depend),)
+include .depend
+endif
diff --git a/tremor/asm_arm.h b/tremor/asm_arm.h
new file mode 100644
index 0000000000..3a3716df1f
--- /dev/null
+++ b/tremor/asm_arm.h
@@ -0,0 +1,243 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: arm7 and later wide math functions
+
+ ********************************************************************/
+
+#ifdef _ARM_ASSEM_
+
+#if !defined(_V_WIDE_MATH) && !defined(_LOW_ACCURACY_)
+#define _V_WIDE_MATH
+
+static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) {
+ int lo,hi;
+ asm volatile("smull\t%0, %1, %2, %3"
+ : "=&r"(lo),"=&r"(hi)
+ : "%r"(x),"r"(y)
+ : "cc");
+ return(hi);
+}
+
+static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) {
+ return MULT32(x,y)<<1;
+}
+
+static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) {
+ int lo,hi;
+ asm volatile("smull %0, %1, %2, %3\n\t"
+ "movs %0, %0, lsr #15\n\t"
+ "adc %1, %0, %1, lsl #17\n\t"
+ : "=&r"(lo),"=&r"(hi)
+ : "%r"(x),"r"(y)
+ : "cc");
+ return(hi);
+}
+
+#define MB() asm volatile ("" : : : "memory")
+
+static inline void XPROD32(ogg_int32_t a, ogg_int32_t b,
+ ogg_int32_t t, ogg_int32_t v,
+ ogg_int32_t *x, ogg_int32_t *y)
+{
+ int x1, y1, l;
+ asm( "smull %0, %1, %4, %6\n\t"
+ "smlal %0, %1, %5, %7\n\t"
+ "rsb %3, %4, #0\n\t"
+ "smull %0, %2, %5, %6\n\t"
+ "smlal %0, %2, %3, %7"
+ : "=&r" (l), "=&r" (x1), "=&r" (y1), "=r" (a)
+ : "3" (a), "r" (b), "r" (t), "r" (v)
+ : "cc" );
+ *x = x1;
+ MB();
+ *y = y1;
+}
+
+static inline void XPROD31(ogg_int32_t a, ogg_int32_t b,
+ ogg_int32_t t, ogg_int32_t v,
+ ogg_int32_t *x, ogg_int32_t *y)
+{
+ int x1, y1, l;
+ asm( "smull %0, %1, %4, %6\n\t"
+ "smlal %0, %1, %5, %7\n\t"
+ "rsb %3, %4, #0\n\t"
+ "smull %0, %2, %5, %6\n\t"
+ "smlal %0, %2, %3, %7"
+ : "=&r" (l), "=&r" (x1), "=&r" (y1), "=r" (a)
+ : "3" (a), "r" (b), "r" (t), "r" (v)
+ : "cc" );
+ *x = x1 << 1;
+ MB();
+ *y = y1 << 1;
+}
+
+static inline void XNPROD31(ogg_int32_t a, ogg_int32_t b,
+ ogg_int32_t t, ogg_int32_t v,
+ ogg_int32_t *x, ogg_int32_t *y)
+{
+ int x1, y1, l;
+ asm( "rsb %2, %4, #0\n\t"
+ "smull %0, %1, %3, %5\n\t"
+ "smlal %0, %1, %2, %6\n\t"
+ "smull %0, %2, %4, %5\n\t"
+ "smlal %0, %2, %3, %6"
+ : "=&r" (l), "=&r" (x1), "=&r" (y1)
+ : "r" (a), "r" (b), "r" (t), "r" (v)
+ : "cc" );
+ *x = x1 << 1;
+ MB();
+ *y = y1 << 1;
+}
+
+#endif
+
+#ifndef _V_CLIP_MATH
+#define _V_CLIP_MATH
+
+static inline ogg_int32_t CLIP_TO_15(ogg_int32_t x) {
+ int tmp;
+ asm volatile("subs %1, %0, #32768\n\t"
+ "movpl %0, #0x7f00\n\t"
+ "orrpl %0, %0, #0xff\n"
+ "adds %1, %0, #32768\n\t"
+ "movmi %0, #0x8000"
+ : "+r"(x),"=r"(tmp)
+ :
+ : "cc");
+ return(x);
+}
+
+#endif
+
+#ifndef _V_LSP_MATH_ASM
+#define _V_LSP_MATH_ASM
+
+static inline void lsp_loop_asm(ogg_uint32_t *qip,ogg_uint32_t *pip,
+ ogg_int32_t *qexpp,
+ ogg_int32_t *ilsp,ogg_int32_t wi,
+ ogg_int32_t m){
+
+ ogg_uint32_t qi=*qip,pi=*pip;
+ ogg_int32_t qexp=*qexpp;
+
+ asm("mov r0,%3;"
+ "mov r1,%5,asr#1;"
+ "add r0,r0,r1,lsl#3;"
+ "1:"
+
+ "ldmdb r0!,{r1,r3};"
+ "subs r1,r1,%4;" //ilsp[j]-wi
+ "rsbmi r1,r1,#0;" //labs(ilsp[j]-wi)
+ "umull %0,r2,r1,%0;" //qi*=labs(ilsp[j]-wi)
+
+ "subs r1,r3,%4;" //ilsp[j+1]-wi
+ "rsbmi r1,r1,#0;" //labs(ilsp[j+1]-wi)
+ "umull %1,r3,r1,%1;" //pi*=labs(ilsp[j+1]-wi)
+
+ "cmn r2,r3;" // shift down 16?
+ "beq 0f;"
+ "add %2,%2,#16;"
+ "mov %0,%0,lsr #16;"
+ "orr %0,%0,r2,lsl #16;"
+ "mov %1,%1,lsr #16;"
+ "orr %1,%1,r3,lsl #16;"
+ "0:"
+ "cmp r0,%3;\n"
+ "bhi 1b;\n"
+
+ // odd filter assymetry
+ "ands r0,%5,#1;\n"
+ "beq 2f;\n"
+ "add r0,%3,%5,lsl#2;\n"
+
+ "ldr r1,[r0,#-4];\n"
+ "mov r0,#0x4000;\n"
+
+ "subs r1,r1,%4;\n" //ilsp[j]-wi
+ "rsbmi r1,r1,#0;\n" //labs(ilsp[j]-wi)
+ "umull %0,r2,r1,%0;\n" //qi*=labs(ilsp[j]-wi)
+ "umull %1,r3,r0,%1;\n" //pi*=labs(ilsp[j+1]-wi)
+
+ "cmn r2,r3;\n" // shift down 16?
+ "beq 2f;\n"
+ "add %2,%2,#16;\n"
+ "mov %0,%0,lsr #16;\n"
+ "orr %0,%0,r2,lsl #16;\n"
+ "mov %1,%1,lsr #16;\n"
+ "orr %1,%1,r3,lsl #16;\n"
+
+ //qi=(pi>>shift)*labs(ilsp[j]-wi);
+ //pi=(qi>>shift)*labs(ilsp[j+1]-wi);
+ //qexp+=shift;
+
+ //}
+
+ /* normalize to max 16 sig figs */
+ "2:"
+ "mov r2,#0;"
+ "orr r1,%0,%1;"
+ "tst r1,#0xff000000;"
+ "addne r2,r2,#8;"
+ "movne r1,r1,lsr #8;"
+ "tst r1,#0x00f00000;"
+ "addne r2,r2,#4;"
+ "movne r1,r1,lsr #4;"
+ "tst r1,#0x000c0000;"
+ "addne r2,r2,#2;"
+ "movne r1,r1,lsr #2;"
+ "tst r1,#0x00020000;"
+ "addne r2,r2,#1;"
+ "movne r1,r1,lsr #1;"
+ "tst r1,#0x00010000;"
+ "addne r2,r2,#1;"
+ "mov %0,%0,lsr r2;"
+ "mov %1,%1,lsr r2;"
+ "add %2,%2,r2;"
+
+ : "+r"(qi),"+r"(pi),"+r"(qexp)
+ : "r"(ilsp),"r"(wi),"r"(m)
+ : "r0","r1","r2","r3","cc");
+
+ *qip=qi;
+ *pip=pi;
+ *qexpp=qexp;
+}
+
+static inline void lsp_norm_asm(ogg_uint32_t *qip,ogg_int32_t *qexpp){
+
+ ogg_uint32_t qi=*qip;
+ ogg_int32_t qexp=*qexpp;
+
+ asm("tst %0,#0x0000ff00;"
+ "moveq %0,%0,lsl #8;"
+ "subeq %1,%1,#8;"
+ "tst %0,#0x0000f000;"
+ "moveq %0,%0,lsl #4;"
+ "subeq %1,%1,#4;"
+ "tst %0,#0x0000c000;"
+ "moveq %0,%0,lsl #2;"
+ "subeq %1,%1,#2;"
+ "tst %0,#0x00008000;"
+ "moveq %0,%0,lsl #1;"
+ "subeq %1,%1,#1;"
+ : "+r"(qi),"+r"(qexp)
+ :
+ : "cc");
+ *qip=qi;
+ *qexpp=qexp;
+}
+
+#endif
+#endif
+
diff --git a/tremor/backends.h b/tremor/backends.h
new file mode 100644
index 0000000000..046e680fc9
--- /dev/null
+++ b/tremor/backends.h
@@ -0,0 +1,127 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * ALL REDISTRIBUTION RIGHTS RESERVED. *
+ * *
+ ********************************************************************
+
+ function: backend and mapping structures
+
+ ********************************************************************/
+
+/* this is exposed up here because we need it for static modes.
+ Lookups for each backend aren't exposed because there's no reason
+ to do so */
+
+#ifndef _vorbis_backend_h_
+#define _vorbis_backend_h_
+
+#include "codec_internal.h"
+
+/* this would all be simpler/shorter with templates, but.... */
+/* Transform backend generic *************************************/
+
+/* only mdct right now. Flesh it out more if we ever transcend mdct
+ in the transform domain */
+
+/* Floor backend generic *****************************************/
+typedef struct{
+ vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
+ vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_mode *,
+ vorbis_info_floor *);
+ void (*free_info) (vorbis_info_floor *);
+ void (*free_look) (vorbis_look_floor *);
+ void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
+ int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
+ void *buffer,ogg_int32_t *);
+} vorbis_func_floor;
+
+typedef struct{
+ int order;
+ long rate;
+ long barkmap;
+
+ int ampbits;
+ int ampdB;
+
+ int numbooks; /* <= 16 */
+ int books[16];
+
+} vorbis_info_floor0;
+
+#define VIF_POSIT 63
+#define VIF_CLASS 16
+#define VIF_PARTS 31
+typedef struct{
+ int partitions; /* 0 to 31 */
+ int partitionclass[VIF_PARTS]; /* 0 to 15 */
+
+ int class_dim[VIF_CLASS]; /* 1 to 8 */
+ int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
+ int class_book[VIF_CLASS]; /* subs ^ dim entries */
+ int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
+
+
+ int mult; /* 1 2 3 or 4 */
+ int postlist[VIF_POSIT+2]; /* first two implicit */
+
+} vorbis_info_floor1;
+
+/* Residue backend generic *****************************************/
+typedef struct{
+ vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
+ vorbis_look_residue *(*look) (vorbis_dsp_state *,vorbis_info_mode *,
+ vorbis_info_residue *);
+ void (*free_info) (vorbis_info_residue *);
+ void (*free_look) (vorbis_look_residue *);
+ int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
+ ogg_int32_t **,int *,int);
+} vorbis_func_residue;
+
+typedef struct vorbis_info_residue0{
+/* block-partitioned VQ coded straight residue */
+ long begin;
+ long end;
+
+ /* first stage (lossless partitioning) */
+ int grouping; /* group n vectors per partition */
+ int partitions; /* possible codebooks for a partition */
+ int groupbook; /* huffbook for partitioning */
+ int secondstages[64]; /* expanded out to pointers in lookup */
+ int booklist[256]; /* list of second stage books */
+} vorbis_info_residue0;
+
+/* Mapping backend generic *****************************************/
+typedef struct{
+ vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
+ vorbis_look_mapping *(*look) (vorbis_dsp_state *,vorbis_info_mode *,
+ vorbis_info_mapping *);
+ void (*free_info) (vorbis_info_mapping *);
+ void (*free_look) (vorbis_look_mapping *);
+ int (*inverse) (struct vorbis_block *vb,vorbis_look_mapping *);
+} vorbis_func_mapping;
+
+typedef struct vorbis_info_mapping0{
+ int submaps; /* <= 16 */
+ int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
+
+ int floorsubmap[16]; /* [mux] submap to floors */
+ int residuesubmap[16]; /* [mux] submap to residue */
+
+ int psy[2]; /* by blocktype; impulse/padding for short,
+ transition/normal for long */
+
+ int coupling_steps;
+ int coupling_mag[256];
+ int coupling_ang[256];
+} vorbis_info_mapping0;
+
+#endif
+
+
+
+
+
diff --git a/tremor/bitwise.c b/tremor/bitwise.c
new file mode 100644
index 0000000000..4782ee053b
--- /dev/null
+++ b/tremor/bitwise.c
@@ -0,0 +1,144 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * ALL REDISTRIBUTION RIGHTS RESERVED. *
+ * *
+ ********************************************************************
+
+ function: packing variable sized words into an octet stream
+
+ ********************************************************************/
+
+/* We're 'LSb' endian; if we write a word but read individual bits,
+ then we'll read the lsb first */
+
+#include <string.h>
+#include <stdlib.h>
+#include "ogg.h"
+
+#define BUFFER_INCREMENT 256
+
+static unsigned long mask[]=
+{0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
+ 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
+ 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
+ 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
+ 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
+ 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
+ 0x3fffffff,0x7fffffff,0xffffffff };
+
+void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
+ memset(b,0,sizeof(*b));
+ b->buffer=b->ptr=buf;
+ b->storage=bytes;
+}
+
+/* Read in bits without advancing the bitptr; bits <= 32 */
+long oggpack_look(oggpack_buffer *b,int bits){
+ unsigned long ret;
+ unsigned long m=mask[bits];
+
+ bits+=b->endbit;
+
+ if(b->endbyte+4>=b->storage){
+ /* not the main path */
+ if(b->endbyte*8+bits>b->storage*8)return(-1);
+ }
+
+ ret=b->ptr[0]>>b->endbit;
+ if(bits>8){
+ ret|=b->ptr[1]<<(8-b->endbit);
+ if(bits>16){
+ ret|=b->ptr[2]<<(16-b->endbit);
+ if(bits>24){
+ ret|=b->ptr[3]<<(24-b->endbit);
+ if(bits>32 && b->endbit)
+ ret|=b->ptr[4]<<(32-b->endbit);
+ }
+ }
+ }
+ return(m&ret);
+}
+
+long oggpack_look1(oggpack_buffer *b){
+ if(b->endbyte>=b->storage)return(-1);
+ return((b->ptr[0]>>b->endbit)&1);
+}
+
+void oggpack_adv(oggpack_buffer *b,int bits){
+ bits+=b->endbit;
+ b->ptr+=bits/8;
+ b->endbyte+=bits/8;
+ b->endbit=bits&7;
+}
+
+void oggpack_adv1(oggpack_buffer *b){
+ if(++(b->endbit)>7){
+ b->endbit=0;
+ b->ptr++;
+ b->endbyte++;
+ }
+}
+
+/* bits <= 32 */
+long oggpack_read(oggpack_buffer *b,int bits){
+ unsigned long ret;
+ unsigned long m=mask[bits];
+
+ bits+=b->endbit;
+
+ if(b->endbyte+4>=b->storage){
+ /* not the main path */
+ ret=-1UL;
+ if(b->endbyte*8+bits>b->storage*8)goto overflow;
+ }
+
+ ret=b->ptr[0]>>b->endbit;
+ if(bits>8){
+ ret|=b->ptr[1]<<(8-b->endbit);
+ if(bits>16){
+ ret|=b->ptr[2]<<(16-b->endbit);
+ if(bits>24){
+ ret|=b->ptr[3]<<(24-b->endbit);
+ if(bits>32 && b->endbit){
+ ret|=b->ptr[4]<<(32-b->endbit);
+ }
+ }
+ }
+ }
+ ret&=m;
+
+ overflow:
+
+ b->ptr+=bits/8;
+ b->endbyte+=bits/8;
+ b->endbit=bits&7;
+ return(ret);
+}
+
+long oggpack_read1(oggpack_buffer *b){
+ unsigned long ret;
+
+ if(b->endbyte>=b->storage){
+ /* not the main path */
+ ret=-1UL;
+ goto overflow;
+ }
+
+ ret=(b->ptr[0]>>b->endbit)&1;
+
+ overflow:
+
+ b->endbit++;
+ if(b->endbit>7){
+ b->endbit=0;
+ b->ptr++;
+ b->endbyte++;
+ }
+ return(ret);
+}
+
+#undef BUFFER_INCREMENT
diff --git a/tremor/block.c b/tremor/block.c
new file mode 100644
index 0000000000..546b756704
--- /dev/null
+++ b/tremor/block.c
@@ -0,0 +1,409 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * ALL REDISTRIBUTION RIGHTS RESERVED. *
+ * *
+ ********************************************************************
+
+ function: PCM data vector blocking, windowing and dis/reassembly
+
+ ********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ogg.h"
+#include "ivorbiscodec.h"
+#include "codec_internal.h"
+
+#include "window.h"
+#include "registry.h"
+#include "misc.h"
+
+static int ilog(unsigned int v){
+ int ret=0;
+ if(v)--v;
+ while(v){
+ ret++;
+ v>>=1;
+ }
+ return(ret);
+}
+
+/* pcm accumulator examples (not exhaustive):
+
+ <-------------- lW ---------------->
+ <--------------- W ---------------->
+: .....|..... _______________ |
+: .''' | '''_--- | |\ |
+:.....''' |_____--- '''......| | \_______|
+:.................|__________________|_______|__|______|
+ |<------ Sl ------>| > Sr < |endW
+ |beginSl |endSl | |endSr
+ |beginW |endlW |beginSr
+
+
+ |< lW >|
+ <--------------- W ---------------->
+ | | .. ______________ |
+ | | ' `/ | ---_ |
+ |___.'___/`. | ---_____|
+ |_______|__|_______|_________________|
+ | >|Sl|< |<------ Sr ----->|endW
+ | | |endSl |beginSr |endSr
+ |beginW | |endlW
+ mult[0] |beginSl mult[n]
+
+ <-------------- lW ----------------->
+ |<--W-->|
+: .............. ___ | |
+: .''' |`/ \ | |
+:.....''' |/`....\|...|
+:.........................|___|___|___|
+ |Sl |Sr |endW
+ | | |endSr
+ | |beginSr
+ | |endSl
+ |beginSl
+ |beginW
+*/
+
+/* block abstraction setup *********************************************/
+
+#ifndef WORD_ALIGN
+#define WORD_ALIGN 8
+#endif
+
+int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
+ memset(vb,0,sizeof(*vb));
+ vb->vd=v;
+ vb->localalloc=0;
+ vb->localstore=NULL;
+
+ return(0);
+}
+
+void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
+ bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
+ if(bytes+vb->localtop>vb->localalloc){
+ /* can't just _ogg_realloc... there are outstanding pointers */
+ if(vb->localstore){
+ struct alloc_chain *link=(struct alloc_chain *)_ogg_malloc(sizeof(*link));
+ vb->totaluse+=vb->localtop;
+ link->next=vb->reap;
+ link->ptr=vb->localstore;
+ vb->reap=link;
+ }
+ /* highly conservative */
+ vb->localalloc=bytes;
+ vb->localstore=_ogg_malloc(vb->localalloc);
+ vb->localtop=0;
+ }
+ {
+ void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
+ vb->localtop+=bytes;
+ return ret;
+ }
+}
+
+/* reap the chain, pull the ripcord */
+void _vorbis_block_ripcord(vorbis_block *vb){
+ /* reap the chain */
+ struct alloc_chain *reap=vb->reap;
+ while(reap){
+ struct alloc_chain *next=reap->next;
+ _ogg_free(reap->ptr);
+ memset(reap,0,sizeof(*reap));
+ _ogg_free(reap);
+ reap=next;
+ }
+ /* consolidate storage */
+ if(vb->totaluse){
+ vb->localstore=_ogg_realloc