diff options
37 files changed, 3 insertions, 9779 deletions
@@ -38,14 +38,6 @@ Copyright: 1995-1999 by Michael Hipp License: GNU General Public License -Name: Tremor -Version: 1.0 + parts CVS from December 2004 + patches -URL: http://xiph.org/ -Directory: tremor -Copyright: 1994-2002, Xiph.org Foundation http://www.xiph.org/ -License: BSD-like, see tremor/COPYING - - Name: avifile DLL loader Version: 0.47 + patches + CVS updates URL: http://avifile.sourceforge.net/ @@ -186,21 +186,6 @@ SRCS_COMMON-$(REAL_CODECS) += libmpcodecs/ad_realaud.c \ SRCS_COMMON-$(SPEEX) += libmpcodecs/ad_speex.c SRCS_COMMON-$(STREAM_CACHE) += stream/cache2.c -SRCS_COMMON-$(TREMOR_INTERNAL) += tremor/bitwise.c \ - tremor/block.c \ - tremor/codebook.c \ - tremor/floor0.c \ - tremor/floor1.c \ - tremor/framing.c \ - tremor/info.c \ - tremor/mapping0.c \ - tremor/mdct.c \ - tremor/registry.c \ - tremor/res012.c \ - tremor/sharedbook.c \ - tremor/synthesis.c \ - tremor/window.c \ - SRCS_COMMON-$(TV) += stream/stream_tv.c stream/tv.c \ stream/frequencies.c stream/tvi_dummy.c SRCS_COMMON-$(TV_BSDBT848) += stream/tvi_bsdbt848.c @@ -601,7 +586,6 @@ DIRS = . \ stream/librtsp \ stream/realrtsp \ sub \ - tremor \ TOOLS \ MOFILES := $(MSG_LANGS:%=locale/%/LC_MESSAGES/mplayer.mo) @@ -693,8 +677,6 @@ mp3lib/decode_i586%: CFLAGS += -fomit-frame-pointer stream/stream_dvdnav%: CFLAGS := $(CFLAGS_LIBDVDNAV) $(CFLAGS) -tremor/%: CFLAGS += $(CFLAGS_TREMOR_LOW) - ###### installation / clean / generic rules ####### @@ -366,9 +366,7 @@ Codecs: --disable-xvid disable Xvid [autodetect] --disable-libnut disable libnut [autodetect] --disable-ffmpeg disable FFmpeg [autodetect] - --disable-tremor-internal disable internal Tremor [enabled] - --enable-tremor-low enable lower accuracy internal Tremor [disabled] - --enable-tremor enable external Tremor [autodetect] + --disable-tremor disable Tremor [autodetect] --disable-libvorbis disable libvorbis support [autodetect] --disable-speex disable Speex support [autodetect] --enable-theora enable OggTheora libraries [autodetect] @@ -611,8 +609,6 @@ _libcdio=auto _liblzo=auto _mad=auto _tremor=auto -_tremor_internal=yes -_tremor_low=no _libvorbis=auto _speex=auto _theora=auto @@ -971,10 +967,6 @@ for ac_option do --disable-speex) _speex=no ;; --enable-tremor) _tremor=yes ;; --disable-tremor) _tremor=no ;; - --enable-tremor-internal) _tremor_internal=yes ;; - --disable-tremor-internal) _tremor_internal=no ;; - --enable-tremor-low) _tremor_low=yes ;; - --disable-tremor-low) _tremor_low=no ;; --enable-theora) _theora=yes ;; --disable-theora) _theora=no ;; --enable-mpg123) _mpg123=yes ;; @@ -5669,9 +5661,7 @@ fi echores "$_mad" echocheck "OggVorbis support" -if test "$_tremor_internal" = yes; then - _libvorbis=no -elif test "$_tremor" = auto; then +if test "$_tremor" = auto; then _tremor=no statement_check tremor/ivorbiscodec.h 'vorbis_packet_blocksize(0, 0)' -logg -lvorbisidec $_ld_lm && _tremor=yes && _libvorbis=no fi @@ -5679,17 +5669,7 @@ if test "$_libvorbis" = auto; then _libvorbis=no statement_check vorbis/codec.h 'vorbis_packet_blocksize(0, 0)' -lvorbis -logg $_ld_lm && _libvorbis=yes fi -if test "$_tremor_internal" = yes ; then - _vorbis=yes - def_vorbis='#define CONFIG_OGGVORBIS 1' - def_tremor='#define CONFIG_TREMOR 1' - codecmodules="tremor(internal) $codecmodules" - res_comment="internal Tremor" - if test "$_tremor_low" = yes ; then - cflags_tremor_low="-D_LOW_ACCURACY_" - res_comment="internal low accuracy Tremor" - fi -elif test "$_tremor" = yes ; then +if test "$_tremor" = yes ; then _vorbis=yes def_vorbis='#define CONFIG_OGGVORBIS 1' def_tremor='#define CONFIG_TREMOR 1' @@ -5771,18 +5751,6 @@ EOF _ld_theora="-ltheora -logg" cc_check $_ld_theora && extra_ldflags="$extra_ldflags $_ld_theora" && _theora=yes fi - if test "$_theora" = no && test "$_tremor_internal" = yes; then - _ld_theora=$($_pkg_config --silence-errors --libs theora) - _inc_theora=$($_pkg_config --silence-errors --cflags theora) - cc_check tremor/bitwise.c $_inc_theora $_ld_theora && - extra_ldflags="$extra_ldflags $_ld_theora" && - extra_cflags="$extra_cflags $_inc_theora" && _theora=yes - if test _theora = no; then - _ld_theora="-ltheora -logg" - cc_check tremor/bitwise.c $_ld_theora && - extra_ldflags="$extra_ldflags $_ld_theora" && _theora=yes - fi - fi fi if test "$_theora" = yes ; then def_theora='#define CONFIG_OGGTHEORA 1' @@ -6808,7 +6776,6 @@ CFLAGS_LIBDVDCSS_DVDREAD = $cflags_libdvdcss_dvdread CFLAGS_LIBDVDNAV = $cflags_libdvdnav CFLAGS_NO_OMIT_LEAF_FRAME_POINTER = $cflags_no_omit_leaf_frame_pointer CFLAGS_STACKREALIGN = $cflags_stackrealign -CFLAGS_TREMOR_LOW = $cflags_tremor_low EXTRALIBS = $extra_ldflags $_ld_static $_ld_lm $extra_libs EXTRALIBS_MPLAYER = $libs_mplayer @@ -6937,7 +6904,6 @@ SVGA = $_svga TDFXFB = $_tdfxfb TDFXVID = $_tdfxvid TGA = $_tga -TREMOR_INTERNAL = $_tremor_internal TV = $_tv TV_BSDBT848 = $_tv_bsdbt848 TV_DSHOW = $_tv_dshow diff --git a/rpm/mplayer.spec b/rpm/mplayer.spec index 9a4b524106..2acc2a6ed7 100644 --- a/rpm/mplayer.spec +++ b/rpm/mplayer.spec @@ -134,7 +134,6 @@ mv DOCS/man/zh DOCS/man/zh_CN --disable-libdvdcss-internal \ --enable-menu \ \ - --disable-tremor-internal \ %{!?_with_amr:--disable-libamr_nb --disable-libamr_wb} \ %{!?_with_libmad:--disable-mad} \ %{?_with_xmms:--enable-xmms} \ @@ -178,7 +177,6 @@ mv -f mplayer gmplayer --disable-libdvdcss-internal \ --enable-menu \ \ - --disable-tremor-internal \ %{!?_with_amr:--disable-libamr_nb --disable-libamr_wb} \ %{!?_with_libmad:--disable-mad} \ %{?_with_xmms:--enable-xmms} \ diff --git a/tremor/COPYING b/tremor/COPYING deleted file mode 100644 index 6111c6c5a6..0000000000 --- a/tremor/COPYING +++ /dev/null @@ -1,28 +0,0 @@ -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/FILES b/tremor/FILES deleted file mode 100644 index 9733e7a5a2..0000000000 --- a/tremor/FILES +++ /dev/null @@ -1,49 +0,0 @@ -On the origin of the files: -========================== - -The code is a mixture of Tremor SVN Trunk r3989 (API, parser, part of math -code) and December 2004 Trunk fetched from xiph.org's Subversion -(mostly math). - -SVN Trunk r3989: ------------ -backends.h -block.c -codebook.c -codebook.h -codec_internal.h -config_types.h -info.c -ivorbiscodec.h -lsp_lookup.h -mapping0.c -os.h -registry.c -registry.h -res012.c -sharedbook.c -synthesis.c - -Dec 2004 SVN Trunk: ------------------- -asm_arm.h -COPYING -floor0.c -floor1.c -mdct.c -mdct.h -mdct_lookup.h -misc.h -os_types.h -window.c -window.h -window_lookup.h - -libogg 1.1.2: ------------- -bitwise.c -framing.c -ogg.h - -Additional MPlayer-specific changes are contained in tremor.diff. -This file should be updated with each modification of the Tremor code. diff --git a/tremor/asm_arm.h b/tremor/asm_arm.h deleted file mode 100644 index f4b1f4f8cf..0000000000 --- a/tremor/asm_arm.h +++ /dev/null @@ -1,243 +0,0 @@ -/******************************************************************** - * * - * 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 deleted file mode 100644 index 269d9b812e..0000000000 --- a/tremor/backends.h +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************** - * * - * 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: 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 deleted file mode 100644 index 6bd082b6dc..0000000000 --- a/tremor/bitwise.c +++ /dev/null @@ -1,450 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis SOFTWARE 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 SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * by the Xiph.Org Foundation http://www.xiph.org/ * - * * - ******************************************************************** - - function: packing variable sized words into an octet stream - last mod: $Id$ - - ********************************************************************/ - -/* 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 const 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 }; - -static const unsigned int mask8B[]= -{0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}; - -void oggpack_writeinit(oggpack_buffer *b){ - memset(b,0,sizeof(*b)); - b->ptr=b->buffer=_ogg_malloc(BUFFER_INCREMENT); - b->buffer[0]='\0'; - b->storage=BUFFER_INCREMENT; -} - -void oggpackB_writeinit(oggpack_buffer *b){ - oggpack_writeinit(b); -} - -void oggpack_writetrunc(oggpack_buffer *b,long bits){ - long bytes=bits>>3; - bits-=bytes*8; - b->ptr=b->buffer+bytes; - b->endbit=bits; - b->endbyte=bytes; - *b->ptr&=mask[bits]; -} - -void oggpackB_writetrunc(oggpack_buffer *b,long bits){ - long bytes=bits>>3; - bits-=bytes*8; - b->ptr=b->buffer+bytes; - b->endbit=bits; - b->endbyte=bytes; - *b->ptr&=mask8B[bits]; -} - -/* Takes only up to 32 bits. */ -void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){ - if(b->endbyte+4>=b->storage){ - b->buffer=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT); - b->storage+=BUFFER_INCREMENT; - b->ptr=b->buffer+b->endbyte; - } - - value&=mask[bits]; - bits+=b->endbit; - - b->ptr[0]|=value<<b->endbit; - - if(bits>=8){ - b->ptr[1]=(unsigned char)(value>>(8-b->endbit)); - if(bits>=16){ - b->ptr[2]=(unsigned char)(value>>(16-b->endbit)); - if(bits>=24){ - b->ptr[3]=(unsigned char)(value>>(24-b->endbit)); - if(bits>=32){ - if(b->endbit) - b->ptr[4]=(unsigned char)(value>>(32-b->endbit)); - else - b->ptr[4]=0; - } - } - } - } - - b->endbyte+=bits/8; - b->ptr+=bits/8; - b->endbit=bits&7; -} - -/* Takes only up to 32 bits. */ -void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){ - if(b->endbyte+4>=b->storage){ - b->buffer=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT); - b->storage+=BUFFER_INCREMENT; - b->ptr=b->buffer+b->endbyte; - } - - value=(value&mask[bits])<<(32-bits); - bits+=b->endbit; - - b->ptr[0]|=value>>(24+b->endbit); - - if(bits>=8){ - b->ptr[1]=(unsigned char)(value>>(16+b->endbit)); - if(bits>=16){ - b->ptr[2]=(unsigned char)(value>>(8+b->endbit)); - if(bits>=24){ - b->ptr[3]=(unsigned char)(value>>(b->endbit)); - if(bits>=32){ - if(b->endbit) - b->ptr[4]=(unsigned char)(value<<(8-b->endbit)); - else - b->ptr[4]=0; - } - } |