From cfe250957daaf5077823885b243a0841ae9d8c97 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Mon, 30 May 2022 01:36:53 +0200 Subject: [PATCH] Update tremor/remove some unneeded switches --- Makefile | 16 +- Makefile.common | 18 - jni/Android.mk | 1 - mednafen/tremor/!!!VERSION | 8 - mednafen/tremor/Makefile.am.inc | 13 - mednafen/tremor/README | 46 ++ mednafen/tremor/asm_arm.h | 44 +- mednafen/tremor/backends.h | 4 +- mednafen/tremor/bitwise.c | 602 +-------------- mednafen/tremor/bitwise.d | 3 + mednafen/tremor/block.c | 76 +- mednafen/tremor/block.d | 7 + mednafen/tremor/codebook.c | 50 +- mednafen/tremor/codebook.d | 5 + mednafen/tremor/codebook.h | 14 +- mednafen/tremor/codec_internal.h | 2 +- mednafen/tremor/floor0.c | 64 +- mednafen/tremor/floor0.d | 8 + mednafen/tremor/floor1.c | 14 +- mednafen/tremor/floor1.d | 8 + mednafen/tremor/framing.c | 1179 +----------------------------- mednafen/tremor/framing.d | 3 + mednafen/tremor/info.c | 43 +- mednafen/tremor/info.d | 7 + mednafen/tremor/ivorbiscodec.h | 16 +- mednafen/tremor/ivorbisfile.h | 53 +- mednafen/tremor/lsp_lookup.h | 8 +- mednafen/tremor/mapping0.c | 40 +- mednafen/tremor/mapping0.d | 8 + mednafen/tremor/mdct.c | 16 +- mednafen/tremor/mdct.d | 6 + mednafen/tremor/mdct.h | 4 +- mednafen/tremor/mdct_lookup.h | 4 +- mednafen/tremor/misc.h | 86 +-- mednafen/tremor/ogg.h | 16 +- mednafen/tremor/os.h | 22 +- mednafen/tremor/os_types.h | 54 -- mednafen/tremor/registry.d | 7 + mednafen/tremor/res012.c | 35 +- mednafen/tremor/res012.d | 8 + mednafen/tremor/sharedbook.c | 281 +++---- mednafen/tremor/sharedbook.d | 6 + mednafen/tremor/synthesis.c | 8 +- mednafen/tremor/synthesis.d | 8 + mednafen/tremor/vorbisfile.c | 542 ++++++-------- mednafen/tremor/vorbisfile.d | 6 + mednafen/tremor/window.c | 2 +- mednafen/tremor/window.d | 6 + mednafen/tremor/window.h | 2 +- mednafen/tremor/window_lookup.h | 19 +- 50 files changed, 863 insertions(+), 2635 deletions(-) delete mode 100644 mednafen/tremor/!!!VERSION delete mode 100644 mednafen/tremor/Makefile.am.inc create mode 100644 mednafen/tremor/README create mode 100644 mednafen/tremor/bitwise.d create mode 100644 mednafen/tremor/block.d create mode 100644 mednafen/tremor/codebook.d create mode 100644 mednafen/tremor/floor0.d create mode 100644 mednafen/tremor/floor1.d create mode 100644 mednafen/tremor/framing.d create mode 100644 mednafen/tremor/info.d create mode 100644 mednafen/tremor/mapping0.d create mode 100644 mednafen/tremor/mdct.d delete mode 100644 mednafen/tremor/os_types.h create mode 100644 mednafen/tremor/registry.d create mode 100644 mednafen/tremor/res012.d create mode 100644 mednafen/tremor/sharedbook.d create mode 100644 mednafen/tremor/synthesis.d create mode 100644 mednafen/tremor/vorbisfile.d create mode 100644 mednafen/tremor/window.d diff --git a/Makefile b/Makefile index 9f8dd7b..2e0b624 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,5 @@ DEBUG = 0 -FRONTEND_SUPPORTS_RGB565 = 1 -HAVE_RUST = 0 HAVE_OPENGL = 0 -HAVE_JIT = 0 HAVE_CHD = 1 HAVE_CDROM = 0 @@ -48,7 +45,7 @@ NEED_TREMOR = 1 NEED_BPP = 32 NEED_DEINTERLACER = 1 NEED_THREADING = 1 -CORE_DEFINE := -DWANT_SS_EMU +CORE_DEFINE := TARGET_NAME := mednafen_saturn ifeq ($(HAVE_OPENGL),1) @@ -451,16 +448,7 @@ LDFLAGS += $(fpic) $(SHARED) FLAGS += $(fpic) $(NEW_GCC_FLAGS) FLAGS += $(INCFLAGS) -FLAGS += $(ENDIANNESS_DEFINES) $(WARNINGS) -DPACKAGE=\"mednafen\" -DMPC_FIXED_POINT $(CORE_DEFINE) -DSTDC_HEADERS -D__STDC_LIMIT_MACROS -D__LIBRETRO__ -D_LOW_ACCURACY_ $(EXTRA_INCLUDES) $(SOUND_DEFINE) -D__STDC_CONSTANT_MACROS - -ifeq ($(HAVE_RUST),1) - FLAGS += -DHAVE_RUST - LDFLAGS += -ldl -L. -lrsx -endif - -ifeq ($(HAVE_JIT),1) - LDFLAGS += -ljit -endif +FLAGS += $(ENDIANNESS_DEFINES) $(WARNINGS) -DPACKAGE=\"mednafen\" $(CORE_DEFINE) -DSTDC_HEADERS -D__STDC_LIMIT_MACROS -D__LIBRETRO__ -D_LOW_ACCURACY_ $(EXTRA_INCLUDES) $(SOUND_DEFINE) -D__STDC_CONSTANT_MACROS CXXFLAGS += $(FLAGS) CFLAGS += $(FLAGS) diff --git a/Makefile.common b/Makefile.common index fa2e6d3..2e5f3e2 100644 --- a/Makefile.common +++ b/Makefile.common @@ -10,7 +10,6 @@ CDROM_DIR := $(MEDNAFEN_DIR)/cdrom ZLIB_INCFLAGS := -I$(DEPS_DIR)/zlib INCFLAGS := -I$(CORE_DIR) -I$(MEDNAFEN_DIR) -I$(MEDNAFEN_DIR)/include -I$(MEDNAFEN_DIR)/intl -I$(MEDNAFEN_DIR)/hw_sound -I$(MEDNAFEN_DIR)/hw_cpu -I$(MEDNAFEN_DIR)/hw_misc -I$(LIBRETRO_COMM_DIR)/include - ZLIB_SOURCES_C := $(DEPS_DIR)/zlib/adler32.c \ $(DEPS_DIR)/zlib/crc32.c \ $(DEPS_DIR)/zlib/inffast.c \ @@ -25,30 +24,14 @@ ifeq ($(NEED_DEINTERLACER), 1) FLAGS += -DNEED_DEINTERLACER endif -ifeq ($(NEED_BPP), 8) -FLAGS += -DWANT_8BPP -endif - -ifeq ($(NEED_BPP), 16) -FLAGS += -DWANT_16BPP -endif - ifeq ($(NEED_BPP), 32) FLAGS += -DWANT_32BPP endif -ifeq ($(WANT_NEW_API), 1) -FLAGS += -DWANT_NEW_API -endif - ifeq ($(NO_COMPUTED_GOTO), 1) FLAGS += -DNO_COMPUTED_GOTO endif -ifeq ($(FRONTEND_SUPPORTS_RGB565), 1) -FLAGS += -DFRONTEND_SUPPORTS_RGB565 -endif - ifeq ($(NEED_CD), 1) FLAGS += -DNEED_CD endif @@ -124,7 +107,6 @@ SOURCES_CXX += $(CDROM_DIR)/CDAccess.cpp \ $(CDROM_DIR)/recover-raw.cpp \ $(CDROM_DIR)/l-ec.cpp \ $(CDROM_DIR)/edc_crc32.cpp -FLAGS += -DNEED_CD ifeq ($(HAVE_CHD), 1) ifneq ($(SYSTEM_LIBCHDR), 1) diff --git a/jni/Android.mk b/jni/Android.mk index 74e7dab..a050551 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -3,7 +3,6 @@ LOCAL_PATH := $(call my-dir) CORE_DIR := $(LOCAL_PATH)/.. DEBUG := 0 -FRONTEND_SUPPORTS_RGB565 := 1 NEED_CD := 1 NEED_BPP := 32 NEED_DEINTERLACER := 1 diff --git a/mednafen/tremor/!!!VERSION b/mednafen/tremor/!!!VERSION deleted file mode 100644 index f911ec0..0000000 --- a/mednafen/tremor/!!!VERSION +++ /dev/null @@ -1,8 +0,0 @@ -tremor git 7c30a66346199f3f09017a09567c6c8a3a0eedc8 -libogg 1.3.2 - -With modifications like: -perl -p -i -e "s//\"ogg.h\"/g" ./* && perl -p -i -e "s//\"os_types.h\"/g" ./* - -Jan 20, 2013: -Mednafen-specific modifications to os_types.h, os.h, and misc.h - config_types.h was removed. diff --git a/mednafen/tremor/Makefile.am.inc b/mednafen/tremor/Makefile.am.inc deleted file mode 100644 index 3c88c15..0000000 --- a/mednafen/tremor/Makefile.am.inc +++ /dev/null @@ -1,13 +0,0 @@ -noinst_LIBRARIES += libvorbisidec.a -libvorbisidec_a_CFLAGS = @AM_CFLAGS@ @CFLAG_VISIBILITY@ -Wno-shadow -Wno-unused -libvorbisidec_a_CPPFLAGS= -I$(srcdir)/tremor - -libvorbisidec_a_SOURCES = tremor/mdct.c tremor/block.c tremor/window.c \ - tremor/synthesis.c tremor/info.c \ - tremor/floor1.c tremor/floor0.c tremor/vorbisfile.c \ - tremor/res012.c tremor/mapping0.c tremor/registry.c tremor/codebook.c \ - tremor/sharedbook.c tremor/framing.c tremor/bitwise.c - -mednafen_LDADD += libvorbisidec.a -mednafen_DEPENDENCIES += libvorbisidec.a - diff --git a/mednafen/tremor/README b/mednafen/tremor/README new file mode 100644 index 0000000..1321175 --- /dev/null +++ b/mednafen/tremor/README @@ -0,0 +1,46 @@ +This README covers the Ogg Vorbis 'Tremor' integer playback codec +source as of date 2002 09 02, version 1.0.0. + + ****** + +The C source in this package will build on any ANSI C compiler and +function completely and properly on any platform. The included build +system assumes GNU build system and make tools (m4, automake, +autoconf, libtool and gmake). GCC is not required, although GCC is +the most tested compiler. To build using GNU tools, type in the +source directory: + +./autogen.sh +make + +Currently, the source implements playback in pure C on all platforms +except ARM, where a [currently] small amount of assembly (see +asm_arm.h) is used to implement 64 bit math operations and fast LSP +computation. If building on ARM without the benefit of GNU build +system tools, be sure that '_ARM_ASSEM_' is #defined by the build +system if this assembly is desired, else the resulting library will +use whatever 64 bit math builtins the compiler implements. + +No math library is required by this source. No floating point +operations are used at any point in either setup or decode. This +decoder library will properly decode any past, current or future +Vorbis I file or stream. + + ******** + +The build system produces a static and [when supported by the OS] +dynamic library named 'libvorbisidec'. This library exposes an API +nearly identical to the BSD reference library's 'libvorbisfile', +including all the features familiar to users of vorbisfile. This API +is similar enough that the proper header file to include is named +'ivorbisfile.h' [included in the source build directory]. Lower level +libvorbis-style headers and structures are in 'ivorbiscodec.h' +[included in the source build directory]. A simple example program, +ivorbisfile_example.c, can be built with 'make example'. + + ******** + +Detailed Tremor API Documentation begins at doc/index.html + +Monty +xiph.org diff --git a/mednafen/tremor/asm_arm.h b/mednafen/tremor/asm_arm.h index c3bda00..83b94b2 100644 --- a/mednafen/tremor/asm_arm.h +++ b/mednafen/tremor/asm_arm.h @@ -20,7 +20,7 @@ #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) { +static inline int32_t MULT32(int32_t x, int32_t y) { int lo,hi; asm volatile("smull\t%0, %1, %2, %3" : "=&r"(lo),"=&r"(hi) @@ -29,11 +29,11 @@ static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { return(hi); } -static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { +static inline int32_t MULT31(int32_t x, int32_t y) { return MULT32(x,y)<<1; } -static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { +static inline int32_t MULT31_SHIFT15(int32_t x, int32_t y) { int lo,hi; asm volatile("smull %0, %1, %2, %3\n\t" "movs %0, %0, lsr #15\n\t" @@ -46,9 +46,9 @@ static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { #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) +static inline void XPROD32(int32_t a, int32_t b, + int32_t t, int32_t v, + int32_t *x, int32_t *y) { int x1, y1, l; asm( "smull %0, %1, %4, %6\n\t" @@ -64,9 +64,9 @@ static inline void XPROD32(ogg_int32_t a, ogg_int32_t b, *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) +static inline void XPROD31(int32_t a, int32_t b, + int32_t t, int32_t v, + int32_t *x, int32_t *y) { int x1, y1, l; asm( "smull %0, %1, %4, %6\n\t" @@ -82,9 +82,9 @@ static inline void XPROD31(ogg_int32_t a, ogg_int32_t b, *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) +static inline void XNPROD31(int32_t a, int32_t b, + int32_t t, int32_t v, + int32_t *x, int32_t *y) { int x1, y1, l; asm( "rsb %2, %4, #0\n\t" @@ -105,7 +105,7 @@ static inline void XNPROD31(ogg_int32_t a, ogg_int32_t b, #ifndef _V_CLIP_MATH #define _V_CLIP_MATH -static inline ogg_int32_t CLIP_TO_15(ogg_int32_t x) { +static inline int32_t CLIP_TO_15(int32_t x) { int tmp; asm volatile("subs %1, %0, #32768\n\t" "movpl %0, #0x7f00\n\t" @@ -123,13 +123,13 @@ static inline ogg_int32_t CLIP_TO_15(ogg_int32_t x) { #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){ +static inline void lsp_loop_asm(uint32_t *qip,uint32_t *pip, + int32_t *qexpp, + int32_t *ilsp,int32_t wi, + int32_t m){ - ogg_uint32_t qi=*qip,pi=*pip; - ogg_int32_t qexp=*qexpp; + uint32_t qi=*qip,pi=*pip; + int32_t qexp=*qexpp; asm("mov r0,%3;" "movs r1,%5,asr#1;" @@ -216,10 +216,10 @@ static inline void lsp_loop_asm(ogg_uint32_t *qip,ogg_uint32_t *pip, *qexpp=qexp; } -static inline void lsp_norm_asm(ogg_uint32_t *qip,ogg_int32_t *qexpp){ +static inline void lsp_norm_asm(uint32_t *qip,int32_t *qexpp){ - ogg_uint32_t qi=*qip; - ogg_int32_t qexp=*qexpp; + uint32_t qi=*qip; + int32_t qexp=*qexpp; asm("tst %0,#0x0000ff00;" "moveq %0,%0,lsl #8;" diff --git a/mednafen/tremor/backends.h b/mednafen/tremor/backends.h index 5202421..8b7793e 100644 --- a/mednafen/tremor/backends.h +++ b/mednafen/tremor/backends.h @@ -39,7 +39,7 @@ typedef struct{ 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 *); + void *buffer,int32_t *); } vorbis_func_floor; typedef struct{ @@ -81,7 +81,7 @@ typedef struct{ 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); + int32_t **,int *,int); } vorbis_func_residue; typedef struct vorbis_info_residue0{ diff --git a/mednafen/tremor/bitwise.c b/mednafen/tremor/bitwise.c index 945335f..50c85df 100644 --- a/mednafen/tremor/bitwise.c +++ b/mednafen/tremor/bitwise.c @@ -5,13 +5,13 @@ * 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-2014 * + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2010 * * by the Xiph.Org Foundation http://www.xiph.org/ * * * ******************************************************************** function: packing variable sized words into an octet stream - last mod: $Id: bitwise.c 19149 2014-05-27 16:26:23Z giles $ + last mod: $Id: bitwise.c 18051 2011-08-04 17:56:39Z giles $ ********************************************************************/ @@ -39,7 +39,7 @@ static const unsigned int mask8B[]= void oggpack_writeinit(oggpack_buffer *b){ memset(b,0,sizeof(*b)); - b->ptr=b->buffer=_ogg_malloc(BUFFER_INCREMENT); + b->ptr=b->buffer=malloc(BUFFER_INCREMENT); b->buffer[0]='\0'; b->storage=BUFFER_INCREMENT; } @@ -86,7 +86,7 @@ void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){ void *ret; if(!b->ptr)return; if(b->storage>LONG_MAX-BUFFER_INCREMENT) goto err; - ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT); + ret=realloc(b->buffer,b->storage+BUFFER_INCREMENT); if(!ret) goto err; b->buffer=ret; b->storage+=BUFFER_INCREMENT; @@ -129,7 +129,7 @@ void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){ void *ret; if(!b->ptr)return; if(b->storage>LONG_MAX-BUFFER_INCREMENT) goto err; - ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT); + ret=realloc(b->buffer,b->storage+BUFFER_INCREMENT); if(!ret) goto err; b->buffer=ret; b->storage+=BUFFER_INCREMENT; @@ -187,22 +187,8 @@ static void oggpack_writecopy_helper(oggpack_buffer *b, unsigned char *ptr=(unsigned char *)source; long bytes=bits/8; - long pbytes=(b->endbit+bits)/8; bits-=bytes*8; - /* expand storage up-front */ - if(b->endbyte+pbytes>=b->storage){ - void *ret; - if(!b->ptr) goto err; - if(b->storage>b->endbyte+pbytes+BUFFER_INCREMENT) goto err; - b->storage=b->endbyte+pbytes+BUFFER_INCREMENT; - ret=_ogg_realloc(b->buffer,b->storage); - if(!ret) goto err; - b->buffer=ret; - b->ptr=b->buffer+b->endbyte; - } - - /* copy whole octets */ if(b->endbit){ int i; /* unaligned copy. Do it the hard way. */ @@ -210,13 +196,23 @@ static void oggpack_writecopy_helper(oggpack_buffer *b, w(b,(unsigned long)(ptr[i]),8); }else{ /* aligned block copy */ + if(b->endbyte+bytes+1>=b->storage){ + void *ret; + if(!b->ptr) goto err; + if(b->endbyte+bytes+BUFFER_INCREMENT>b->storage) goto err; + b->storage=b->endbyte+bytes+BUFFER_INCREMENT; + ret=realloc(b->buffer,b->storage); + if(!ret) goto err; + b->buffer=ret; + b->ptr=b->buffer+b->endbyte; + } + memmove(b->ptr,source,bytes); b->ptr+=bytes; b->endbyte+=bytes; *b->ptr=0; - } - /* copy trailing bits */ + } if(bits){ if(msb) w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits); @@ -248,7 +244,8 @@ void oggpackB_reset(oggpack_buffer *b){ } void oggpack_writeclear(oggpack_buffer *b){ - if(b->buffer)_ogg_free(b->buffer); + if(b->buffer) + free(b->buffer); memset(b,0,sizeof(*b)); } @@ -524,565 +521,4 @@ unsigned char *oggpackB_get_buffer(oggpack_buffer *b){ return oggpack_get_buffer(b); } -/* Self test of the bitwise routines; everything else is based on - them, so they damned well better be solid. */ - -#ifdef _V_SELFTEST -#include - -static int ilog(unsigned int v){ - int ret=0; - while(v){ - ret++; - v>>=1; - } - return(ret); -} - -oggpack_buffer o; -oggpack_buffer r; - -void report(char *in){ - fprintf(stderr,"%s",in); - exit(1); -} - -void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){ - long bytes,i; - unsigned char *buffer; - - oggpack_reset(&o); - for(i=0;i #include #include #include "ogg.h" @@ -92,9 +91,9 @@ int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){ 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 */ + /* can't just realloc... there are outstanding pointers */ if(vb->localstore){ - struct alloc_chain *link=(struct alloc_chain *)_ogg_malloc(sizeof(*link)); + struct alloc_chain *link=(struct alloc_chain *)malloc(sizeof(*link)); vb->totaluse+=vb->localtop; link->next=vb->reap; link->ptr=vb->localstore; @@ -102,7 +101,7 @@ void *_vorbis_block_alloc(vorbis_block *vb,long bytes){ } /* highly conservative */ vb->localalloc=bytes; - vb->localstore=_ogg_malloc(vb->localalloc); + vb->localstore=malloc(vb->localalloc); vb->localtop=0; } { @@ -118,14 +117,14 @@ void _vorbis_block_ripcord(vorbis_block *vb){ struct alloc_chain *reap=vb->reap; while(reap){ struct alloc_chain *next=reap->next; - _ogg_free(reap->ptr); + free(reap->ptr); memset(reap,0,sizeof(*reap)); - _ogg_free(reap); + free(reap); reap=next; } /* consolidate storage */ if(vb->totaluse){ - vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc); + vb->localstore=realloc(vb->localstore,vb->totaluse+vb->localalloc); vb->localalloc+=vb->totaluse; vb->totaluse=0; } @@ -137,7 +136,8 @@ void _vorbis_block_ripcord(vorbis_block *vb){ int vorbis_block_clear(vorbis_block *vb){ _vorbis_block_ripcord(vb); - if(vb->localstore)_ogg_free(vb->localstore); + if(vb->localstore) + free(vb->localstore); memset(vb,0,sizeof(*vb)); return(0); @@ -151,7 +151,7 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ if(ci==NULL) return 1; memset(v,0,sizeof(*v)); - b=(private_state *)(v->backend_state=_ogg_calloc(1,sizeof(*b))); + b=(private_state *)(v->backend_state=calloc(1,sizeof(*b))); v->vi=vi; b->modebits=ilog(ci->modes); @@ -162,7 +162,7 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ /* finish the codebooks */ if(!ci->fullbooks){ - ci->fullbooks=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->fullbooks)); + ci->fullbooks=(codebook *)calloc(ci->books,sizeof(*ci->fullbooks)); for(i=0;ibooks;i++){ if(ci->book_param[i]==NULL) goto abort_books; @@ -175,10 +175,10 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ } v->pcm_storage=ci->blocksizes[1]; - v->pcm=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcm)); - v->pcmret=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcmret)); + v->pcm=(int32_t **)malloc(vi->channels*sizeof(*v->pcm)); + v->pcmret=(int32_t **)malloc(vi->channels*sizeof(*v->pcmret)); for(i=0;ichannels;i++) - v->pcm[i]=(ogg_int32_t *)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i])); + v->pcm[i]=(int32_t *)calloc(v->pcm_storage,sizeof(*v->pcm[i])); /* all 1 (large block) or 0 (small block) */ /* explicitly set for the sake of clarity */ @@ -186,7 +186,7 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ v->W=0; /* current window size */ /* initialize all the mapping/backend lookups */ - b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode)); + b->mode=(vorbis_look_mapping **)calloc(ci->modes,sizeof(*b->mode)); for(i=0;imodes;i++){ int mapnum=ci->mode_param[i]->mapping; int maptype=ci->map_type[mapnum]; @@ -239,11 +239,15 @@ void vorbis_dsp_clear(vorbis_dsp_state *v){ codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL); private_state *b=(private_state *)v->backend_state; - if(v->pcm){ - for(i=0;ichannels;i++) - if(v->pcm[i])_ogg_free(v->pcm[i]); - _ogg_free(v->pcm); - if(v->pcmret)_ogg_free(v->pcmret); + if(v->pcm) + { + if(vi) + for(i=0;ichannels;i++) + if(v->pcm[i]) + free(v->pcm[i]); + free(v->pcm); + if(v->pcmret) + free(v->pcmret); } /* free mode lookups; these are actually vorbis_look_mapping structs */ @@ -255,9 +259,11 @@ void vorbis_dsp_clear(vorbis_dsp_state *v){ } } - if(b){ - if(b->mode)_ogg_free(b->mode); - _ogg_free(b); + if(b) + { + if(b->mode) + free(b->mode); + free(b); } memset(v,0,sizeof(*v)); @@ -316,30 +322,30 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){ if(v->lW){ if(v->W){ /* large/large */ - ogg_int32_t *pcm=v->pcm[j]+prevCenter; - ogg_int32_t *p=vb->pcm[j]; + int32_t *pcm=v->pcm[j]+prevCenter; + int32_t *p=vb->pcm[j]; for(i=0;ipcm[j]+prevCenter+n1/2-n0/2; - ogg_int32_t *p=vb->pcm[j]; + int32_t *pcm=v->pcm[j]+prevCenter+n1/2-n0/2; + int32_t *p=vb->pcm[j]; for(i=0;iW){ /* small/large */ - ogg_int32_t *pcm=v->pcm[j]+prevCenter; - ogg_int32_t *p=vb->pcm[j]+n1/2-n0/2; + int32_t *pcm=v->pcm[j]+prevCenter; + int32_t *p=vb->pcm[j]+n1/2-n0/2; for(i=0;ipcm[j]+prevCenter; - ogg_int32_t *p=vb->pcm[j]; + int32_t *pcm=v->pcm[j]+prevCenter; + int32_t *p=vb->pcm[j]; for(i=0;ipcm[j]+thisCenter; - ogg_int32_t *p=vb->pcm[j]+n; + int32_t *pcm=v->pcm[j]+thisCenter; + int32_t *p=vb->pcm[j]+n; for(i=0;isample_count-vb->granulepos; - /* we use ogg_int64_t for granule positions because a + /* we use int64_t for granule positions because a uint64 isn't universally available. Unfortunately, that means granposes can be 'negative' and result in extra being negative */ @@ -451,7 +457,7 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){ if(extra > v->pcm_current - v->pcm_returned) extra = v->pcm_current - v->pcm_returned; - /* we use ogg_int64_t for granule positions because a + /* we use int64_t for granule positions because a uint64 isn't universally available. Unfortunately, that means granposes can be 'negative' and result in extra being negative */ @@ -475,7 +481,7 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){ } /* pcm==NULL indicates we just want the pending samples, no more */ -int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm){ +int vorbis_synthesis_pcmout(vorbis_dsp_state *v,int32_t ***pcm){ vorbis_info *vi=v->vi; if(v->pcm_returned>-1 && v->pcm_returnedpcm_current){ if(pcm){ diff --git a/mednafen/tremor/block.d b/mednafen/tremor/block.d new file mode 100644 index 0000000..2835f85 --- /dev/null +++ b/mednafen/tremor/block.d @@ -0,0 +1,7 @@ +mednafen/tremor/block.o: mednafen/tremor/block.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ogg.h mednafen/tremor/ivorbiscodec.h \ + mednafen/tremor/codec_internal.h mednafen/tremor/codebook.h \ + mednafen/tremor/window.h mednafen/tremor/registry.h \ + mednafen/tremor/backends.h mednafen/tremor/misc.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h diff --git a/mednafen/tremor/codebook.c b/mednafen/tremor/codebook.c index 3fbd89c..8f00ce4 100644 --- a/mednafen/tremor/codebook.c +++ b/mednafen/tremor/codebook.c @@ -27,7 +27,7 @@ readies the codebook auxiliary structures for decode *************/ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){ long i,j; - static_codebook *s=_ogg_calloc(1,sizeof(*s)); + static_codebook *s=calloc(1,sizeof(*s)); /* make sure alignment is correct */ if(oggpack_read(opb,24)!=0x564342)goto _eofout; @@ -48,7 +48,7 @@ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){ if((s->entries*(unused?1:5)+7)>>3>opb->storage-oggpack_bytes(opb)) goto _eofout; /* unordered */ - s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries); + s->lengthlist=(long *)malloc(sizeof(*s->lengthlist)*s->entries); /* allocated but unused entries? */ if(unused){ @@ -78,7 +78,7 @@ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){ { long length=oggpack_read(opb,5)+1; if(length==0)goto _eofout; - s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries); + s->lengthlist=(long *)malloc(sizeof(*s->lengthlist)*s->entries); for(i=0;ientries;){ long num=oggpack_read(opb,_ilog(s->entries-i)); @@ -127,7 +127,7 @@ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){ /* quantized values */ if((quantvals*s->q_quant+7)>>3>opb->storage-oggpack_bytes(opb)) goto _eofout; - s->quantlist=(long *)_ogg_malloc(sizeof(*s->quantlist)*quantvals); + s->quantlist=(long *)malloc(sizeof(*s->quantlist)*quantvals); for(i=0;iquantlist[i]=oggpack_read(opb,s->q_quant); @@ -155,7 +155,7 @@ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){ be. The first-stage decode table catches most words so that bitreverse is not in the main execution path. */ -static ogg_uint32_t bitreverse(ogg_uint32_t x){ +static uint32_t bitreverse(uint32_t x){ x= ((x>>16)&0x0000ffff) | ((x<<16)&0xffff0000); x= ((x>> 8)&0x00ff00ff) | ((x<< 8)&0xff00ff00); x= ((x>> 4)&0x0f0f0f0f) | ((x<< 4)&0xf0f0f0f0); @@ -163,7 +163,7 @@ static ogg_uint32_t bitreverse(ogg_uint32_t x){ return((x>> 1)&0x55555555) | ((x<< 1)&0xaaaaaaaa); } -STIN long decode_packed_entry_number(codebook *book, +static INLINE long decode_packed_entry_number(codebook *book, oggpack_buffer *b){ int read=book->dec_maxlength; long lo,hi; @@ -195,7 +195,7 @@ STIN long decode_packed_entry_number(codebook *book, /* bisect search for the codeword in the ordered list */ { - ogg_uint32_t testword=bitreverse((ogg_uint32_t)lok); + uint32_t testword=bitreverse((uint32_t)lok); while(hi-lo>1){ long p=(hi-lo)>>1; @@ -242,12 +242,12 @@ long vorbis_book_decode(codebook *book, oggpack_buffer *b){ /* returns 0 on OK or -1 on eof *************************************/ /* decode vector / dim granularity gaurding is done in the upper layer */ -long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a, +long vorbis_book_decodevs_add(codebook *book,int32_t *a, oggpack_buffer *b,int n,int point){ if(book->used_entries>0){ int step=n/book->dim; long *entry = (long *)alloca(sizeof(*entry)*step); - ogg_int32_t **t = (ogg_int32_t **)alloca(sizeof(*t)*step); + int32_t **t = (int32_t **)alloca(sizeof(*t)*step); int i,j,o; int shift=point-book->binarypoint; @@ -258,7 +258,7 @@ long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a, t[i] = book->valuelist+entry[i]*book->dim; } for(i=0,o=0;idim;i++,o+=step) - for (j=0;o+j>shift; }else{ for (i = 0; i < step; i++) { @@ -267,7 +267,7 @@ long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a, t[i] = book->valuelist+entry[i]*book->dim; } for(i=0,o=0;idim;i++,o+=step) - for (j=0;o+jused_entries>0){ int i,j,entry; - ogg_int32_t *t; + int32_t *t; int shift=point-book->binarypoint; if(shift>=0){ @@ -287,7 +287,7 @@ long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a, entry = decode_packed_entry_number(book,b); if(entry==-1)return(-1); t = book->valuelist+entry*book->dim; - for (j=0;idim;) + for (j=0;jdim;) a[i++]+=t[j++]>>shift; } }else{ @@ -295,7 +295,7 @@ long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a, entry = decode_packed_entry_number(book,b); if(entry==-1)return(-1); t = book->valuelist+entry*book->dim; - for (j=0;idim;) + for (j=0;jdim;) a[i++]+=t[j++]<<-shift; } } @@ -306,11 +306,11 @@ long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a, /* unlike the others, we guard against n not being an integer number of internally rather than in the upper layer (called only by floor0) */ -long vorbis_book_decodev_set(codebook *book,ogg_int32_t *a, +long vorbis_book_decodev_set(codebook *book,int32_t *a, oggpack_buffer *b,int n,int point){ if(book->used_entries>0){ int i,j,entry; - ogg_int32_t *t; + int32_t *t; int shift=point-book->binarypoint; if(shift>=0){ @@ -345,22 +345,22 @@ long vorbis_book_decodev_set(codebook *book,ogg_int32_t *a, } /* decode vector / dim granularity gaurding is done in the upper layer */ -long vorbis_book_decodevv_add(codebook *book,ogg_int32_t **a,\ +long vorbis_book_decodevv_add(codebook *book,int32_t **a,\ long offset,int ch, oggpack_buffer *b,int n,int point){ if(book->used_entries>0){ long i,j,entry; int chptr=0; int shift=point-book->binarypoint; - int m=offset+n; + if(shift>=0){ - for(i=offset;ivaluelist+entry*book->dim; - for (j=0;idim;j++){ + const int32_t *t = book->valuelist+entry*book->dim; + for (j=0;jdim;j++){ a[chptr++][i]+=t[j]>>shift; if(chptr==ch){ chptr=0; @@ -371,12 +371,12 @@ long vorbis_book_decodevv_add(codebook *book,ogg_int32_t **a,\ } }else{ - for(i=offset;ivaluelist+entry*book->dim; - for (j=0;idim;j++){ + const int32_t *t = book->valuelist+entry*book->dim; + for (j=0;jdim;j++){ a[chptr++][i]+=t[j]<<-shift; if(chptr==ch){ chptr=0; diff --git a/mednafen/tremor/codebook.d b/mednafen/tremor/codebook.d new file mode 100644 index 0000000..f50d2ba --- /dev/null +++ b/mednafen/tremor/codebook.d @@ -0,0 +1,5 @@ +mednafen/tremor/codebook.o: mednafen/tremor/codebook.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ogg.h mednafen/tremor/ivorbiscodec.h \ + mednafen/tremor/codebook.h mednafen/tremor/misc.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h diff --git a/mednafen/tremor/codebook.h b/mednafen/tremor/codebook.h index c6f46cd..c346494 100644 --- a/mednafen/tremor/codebook.h +++ b/mednafen/tremor/codebook.h @@ -62,12 +62,12 @@ typedef struct codebook{ /* the below are ordered by bitreversed codeword and only used entries are populated */ int binarypoint; - ogg_int32_t *valuelist; /* list of dim*entries actual entry values */ - ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */ + int32_t *valuelist; /* list of dim*entries actual entry values */ + uint32_t *codelist; /* list of bitstream codewords for each entry */ int *dec_index; char *dec_codelengths; - ogg_uint32_t *dec_firsttable; + uint32_t *dec_firsttable; int dec_firsttablen; int dec_maxlength; @@ -85,13 +85,13 @@ extern long _book_maptype1_quantvals(const static_codebook *b); extern static_codebook *vorbis_staticbook_unpack(oggpack_buffer *b); extern long vorbis_book_decode(codebook *book, oggpack_buffer *b); -extern long vorbis_book_decodevs_add(codebook *book, ogg_int32_t *a, +extern long vorbis_book_decodevs_add(codebook *book, int32_t *a, oggpack_buffer *b,int n,int point); -extern long vorbis_book_decodev_set(codebook *book, ogg_int32_t *a, +extern long vorbis_book_decodev_set(codebook *book, int32_t *a, oggpack_buffer *b,int n,int point); -extern long vorbis_book_decodev_add(codebook *book, ogg_int32_t *a, +extern long vorbis_book_decodev_add(codebook *book, int32_t *a, oggpack_buffer *b,int n,int point); -extern long vorbis_book_decodevv_add(codebook *book, ogg_int32_t **a, +extern long vorbis_book_decodevv_add(codebook *book, int32_t **a, long off,int ch, oggpack_buffer *b,int n,int point); diff --git a/mednafen/tremor/codec_internal.h b/mednafen/tremor/codec_internal.h index 3ca7f54..8a2548b 100644 --- a/mednafen/tremor/codec_internal.h +++ b/mednafen/tremor/codec_internal.h @@ -45,7 +45,7 @@ typedef struct private_state { int modebits; vorbis_look_mapping **mode; - ogg_int64_t sample_count; + int64_t sample_count; } private_state; diff --git a/mednafen/tremor/floor0.c b/mednafen/tremor/floor0.c index 1ece59d..9721f6f 100644 --- a/mednafen/tremor/floor0.c +++ b/mednafen/tremor/floor0.c @@ -35,7 +35,7 @@ typedef struct { int *linearmap; vorbis_info_floor0 *vi; - ogg_int32_t *lsp_look; + int32_t *lsp_look; } vorbis_look_floor0; @@ -48,7 +48,7 @@ typedef struct { returns in m.8 format */ static long ADJUST_SQRT2[2]={8192,5792}; -STIN ogg_int32_t vorbis_invsqlook_i(long a,long e){ +static INLINE int32_t vorbis_invsqlook_i(long a,long e){ long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1); long d=a&INVSQ_LOOKUP_I_MASK; /* 0.10 */ long val=INVSQ_LOOKUP_I[i]- /* 1.16 */ @@ -60,7 +60,7 @@ STIN ogg_int32_t vorbis_invsqlook_i(long a,long e){ /* interpolated lookup based fromdB function, domain -140dB to 0dB only */ /* a is in n.12 format */ -STIN ogg_int32_t vorbis_fromdBlook_i(long a){ +static INLINE int32_t vorbis_fromdBlook_i(long a){ int i=(-a)>>(12-FROMdB2_SHIFT); if(i<0) return 0x7fffffff; if(i>=(FROMdB_LOOKUP_SZ<>COS_LOOKUP_I_SHIFT; int d=a&COS_LOOKUP_I_MASK; return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>> @@ -79,7 +79,7 @@ STIN ogg_int32_t vorbis_coslook_i(long a){ /* interpolated lookup based cos function */ /* a is in 0.16 format, where 0==0, 2^^16==PI, return .LSP_FRACBITS */ -STIN ogg_int32_t vorbis_coslook2_i(long a){ +static INLINE int32_t vorbis_coslook2_i(long a){ a=a&0x1ffff; if(a>0x10000)a=0x20000-a; @@ -102,7 +102,7 @@ static const int barklook[28]={ }; /* used in init only; interpolate the long way */ -STIN ogg_int32_t toBARK(int n){ +static INLINE int32_t toBARK(int n){ int i; for(i=0;i<27;i++) if(n>=barklook[i] && n>10)*0x517d)>>14; + int32_t val=((lsp[i]>>10)*0x517d)>>14; #endif /* safeguard against a malicious stream */ @@ -166,10 +166,10 @@ void vorbis_lsp_to_curve(ogg_int32_t *curve,int *map,int n,int ln, i=0; while(ilinearmap)_ogg_free(look->linearmap); - if(look->lsp_look)_ogg_free(look->lsp_look); + if(look->linearmap) + free(look->linearmap); + if(look->lsp_look) + free(look->lsp_look); memset(look,0,sizeof(*look)); - _ogg_free(look); + free(look); } } @@ -311,7 +313,7 @@ static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; int j; - vorbis_info_floor0 *info=(vorbis_info_floor0 *)_ogg_malloc(sizeof(*info)); + vorbis_info_floor0 *info=(vorbis_info_floor0 *)malloc(sizeof(*info)); info->order=oggpack_read(opb,8); info->rate=oggpack_read(opb,16); info->barkmap=oggpack_read(opb,16); @@ -351,7 +353,7 @@ static vorbis_look_floor *floor0_look (vorbis_dsp_state *vd,vorbis_info_mode *mi vorbis_info *vi=vd->vi; codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; vorbis_info_floor0 *info=(vorbis_info_floor0 *)i; - vorbis_look_floor0 *look=(vorbis_look_floor0 *)_ogg_calloc(1,sizeof(*look)); + vorbis_look_floor0 *look=(vorbis_look_floor0 *)calloc(1,sizeof(*look)); look->m=info->order; look->n=ci->blocksizes[mi->blockflag]/2; look->ln=info->barkmap; @@ -363,7 +365,7 @@ static vorbis_look_floor *floor0_look (vorbis_dsp_state *vd,vorbis_info_mode *mi the encoder may do what it wishes in filling them. They're necessary in some mapping combinations to keep the scale spacing accurate */ - look->linearmap=(int *)_ogg_malloc((look->n+1)*sizeof(*look->linearmap)); + look->linearmap=(int *)malloc((look->n+1)*sizeof(*look->linearmap)); for(j=0;jn;j++){ int val=(look->ln* @@ -374,7 +376,7 @@ static vorbis_look_floor *floor0_look (vorbis_dsp_state *vd,vorbis_info_mode *mi } look->linearmap[j]=-1; - look->lsp_look=(ogg_int32_t *)_ogg_malloc(look->ln*sizeof(*look->lsp_look)); + look->lsp_look=(int32_t *)malloc(look->ln*sizeof(*look->lsp_look)); for(j=0;jln;j++) look->lsp_look[j]=vorbis_coslook2_i(0x10000*j/look->ln); @@ -395,8 +397,8 @@ static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){ if(booknum!=-1 && booknumnumbooks){ /* be paranoid */ codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup; codebook *b=ci->fullbooks+info->books[booknum]; - ogg_int32_t last=0; - ogg_int32_t *lsp=(ogg_int32_t *)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+1)); + int32_t last=0; + int32_t *lsp=(int32_t *)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+1)); if(vorbis_book_decodev_set(b,lsp,&vb->opb,look->m,-24)==-1)goto eop; for(j=0;jm;){ @@ -413,13 +415,13 @@ static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){ } static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i, - void *memo,ogg_int32_t *out){ + void *memo,int32_t *out){ vorbis_look_floor0 *look=(vorbis_look_floor0 *)i; vorbis_info_floor0 *info=look->vi; if(memo){ - ogg_int32_t *lsp=(ogg_int32_t *)memo; - ogg_int32_t amp=lsp[look->m]; + int32_t *lsp=(int32_t *)memo; + int32_t amp=lsp[look->m]; /* take the coefficients back to a spectral envelope curve */ vorbis_lsp_to_curve(out,look->linearmap,look->n,look->ln, diff --git a/mednafen/tremor/floor0.d b/mednafen/tremor/floor0.d new file mode 100644 index 0000000..6821641 --- /dev/null +++ b/mednafen/tremor/floor0.d @@ -0,0 +1,8 @@ +mednafen/tremor/floor0.o: mednafen/tremor/floor0.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ogg.h mednafen/tremor/ivorbiscodec.h \ + mednafen/tremor/codec_internal.h mednafen/tremor/codebook.h \ + mednafen/tremor/registry.h mednafen/tremor/backends.h \ + mednafen/tremor/misc.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h \ + mednafen/tremor/block.h mednafen/tremor/lsp_lookup.h diff --git a/mednafen/tremor/floor1.c b/mednafen/tremor/floor1.c index ab4c899..9817ad1 100644 --- a/mednafen/tremor/floor1.c +++ b/mednafen/tremor/floor1.c @@ -47,7 +47,7 @@ static void floor1_free_info(vorbis_info_floor *i){ vorbis_info_floor1 *info=(vorbis_info_floor1 *)i; if(info){ memset(info,0,sizeof(*info)); - _ogg_free(info); + free(info); } } @@ -55,7 +55,7 @@ static void floor1_free_look(vorbis_look_floor *i){ vorbis_look_floor1 *look=(vorbis_look_floor1 *)i; if(look){ memset(look,0,sizeof(*look)); - _ogg_free(look); + free(look); } } @@ -76,7 +76,7 @@ static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; int j,k,count=0,maxclass=-1,rangebits; - vorbis_info_floor1 *info=(vorbis_info_floor1 *)_ogg_calloc(1,sizeof(*info)); + vorbis_info_floor1 *info=(vorbis_info_floor1 *)calloc(1,sizeof(*info)); /* read partitions */ info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */ for(j=0;jpartitions;j++){ @@ -141,7 +141,7 @@ static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,vorbis_info_mode *mi, int *sortpointer[VIF_POSIT+2]; vorbis_info_floor1 *info=(vorbis_info_floor1 *)in; - vorbis_look_floor1 *look=(vorbis_look_floor1 *)_ogg_calloc(1,sizeof(*look)); + vorbis_look_floor1 *look=(vorbis_look_floor1 *)calloc(1,sizeof(*look)); int i,j,n=0; look->vi=info; @@ -229,7 +229,7 @@ static int render_point(int x0,int x1,int y0,int y1,int x){ # define XdB(n) (n) #endif -static const ogg_int32_t FLOOR_fromdB_LOOKUP[256]={ +static const int32_t FLOOR_fromdB_LOOKUP[256]={ XdB(0x000000e5), XdB(0x000000f4), XdB(0x00000103), XdB(0x00000114), XdB(0x00000126), XdB(0x00000139), XdB(0x0000014e), XdB(0x00000163), XdB(0x0000017a), XdB(0x00000193), XdB(0x000001ad), XdB(0x000001c9), @@ -296,7 +296,7 @@ static const ogg_int32_t FLOOR_fromdB_LOOKUP[256]={ XdB(0x69f80e9a), XdB(0x70dafda8), XdB(0x78307d76), XdB(0x7fffffff), }; -static void render_line(int n, int x0,int x1,int y0,int y1,ogg_int32_t *d){ +static void render_line(int n, int x0,int x1,int y0,int y1,int32_t *d){ int dy=y1-y0; int adx=x1-x0; int ady=abs(dy); @@ -412,7 +412,7 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){ } static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo, - ogg_int32_t *out){ + int32_t *out){ vorbis_look_floor1 *look=(vorbis_look_floor1 *)in; vorbis_info_floor1 *info=look->vi; diff --git a/mednafen/tremor/floor1.d b/mednafen/tremor/floor1.d new file mode 100644 index 0000000..9219559 --- /dev/null +++ b/mednafen/tremor/floor1.d @@ -0,0 +1,8 @@ +mednafen/tremor/floor1.o: mednafen/tremor/floor1.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ogg.h mednafen/tremor/ivorbiscodec.h \ + mednafen/tremor/codec_internal.h mednafen/tremor/codebook.h \ + mednafen/tremor/registry.h mednafen/tremor/backends.h \ + mednafen/tremor/misc.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h \ + mednafen/tremor/block.h diff --git a/mednafen/tremor/framing.c b/mednafen/tremor/framing.c index 56d5eee..4ac6823 100644 --- a/mednafen/tremor/framing.c +++ b/mednafen/tremor/framing.c @@ -12,7 +12,7 @@ function: code raw packets into framed OggSquish stream and decode Ogg streams back into raw packets - last mod: $Id: framing.c 18758 2013-01-08 16:29:56Z tterribe $ + last mod: $Id: framing.c 18052 2011-08-04 17:57:02Z giles $ note: The CRC code is directly derived from public domain code by Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html @@ -21,7 +21,6 @@ ********************************************************************/ #include -#include #include #include "ogg.h" @@ -43,9 +42,9 @@ int ogg_page_eos(const ogg_page *og){ return((int)(og->header[5]&0x04)); } -ogg_int64_t ogg_page_granulepos(const ogg_page *og){ +int64_t ogg_page_granulepos(const ogg_page *og){ unsigned char *page=og->header; - ogg_int64_t granulepos=page[13]&(0xff); + int64_t granulepos=page[13]&(0xff); granulepos= (granulepos<<8)|(page[12]&0xff); granulepos= (granulepos<<8)|(page[11]&0xff); granulepos= (granulepos<<8)|(page[10]&0xff); @@ -97,28 +96,7 @@ int ogg_page_packets(const ogg_page *og){ } -#if 0 -/* helper to initialize lookup for direct-table CRC (illustrative; we - use the static init below) */ - -static ogg_uint32_t _ogg_crc_entry(unsigned long index){ - int i; - unsigned long r; - - r = index << 24; - for (i=0; i<8; i++) - if (r & 0x80000000UL) - r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator - polynomial, although we use an - unreflected alg and an init/final - of 0, not 0xffffffff */ - else - r<<=1; - return (r & 0xffffffffUL); -} -#endif - -static const ogg_uint32_t crc_lookup[256]={ +static const uint32_t crc_lookup[256]={ 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9, 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005, 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61, @@ -192,9 +170,9 @@ int ogg_stream_init(ogg_stream_state *os,int serialno){ os->body_storage=16*1024; os->lacing_storage=1024; - os->body_data=_ogg_malloc(os->body_storage*sizeof(*os->body_data)); - os->lacing_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals)); - os->granule_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals)); + os->body_data=malloc(os->body_storage*sizeof(*os->body_data)); + os->lacing_vals=malloc(os->lacing_storage*sizeof(*os->lacing_vals)); + os->granule_vals=malloc(os->lacing_storage*sizeof(*os->granule_vals)); if(!os->body_data || !os->lacing_vals || !os->granule_vals){ ogg_stream_clear(os); @@ -217,9 +195,12 @@ int ogg_stream_check(ogg_stream_state *os){ /* _clear does not free os, only the non-flat storage within */ int ogg_stream_clear(ogg_stream_state *os){ if(os){ - if(os->body_data)_ogg_free(os->body_data); - if(os->lacing_vals)_ogg_free(os->lacing_vals); - if(os->granule_vals)_ogg_free(os->granule_vals); + if(os->body_data) + free(os->body_data); + if(os->lacing_vals) + free(os->lacing_vals); + if(os->granule_vals) + free(os->granule_vals); memset(os,0,sizeof(*os)); } @@ -229,7 +210,7 @@ int ogg_stream_clear(ogg_stream_state *os){ int ogg_stream_destroy(ogg_stream_state *os){ if(os){ ogg_stream_clear(os); - _ogg_free(os); + free(os); } return(0); } @@ -237,51 +218,37 @@ int ogg_stream_destroy(ogg_stream_state *os){ /* Helpers for ogg_stream_encode; this keeps the structure and what's happening fairly clear */ -static int _os_body_expand(ogg_stream_state *os,long needed){ - if(os->body_storage-needed<=os->body_fill){ - long body_storage; - void *ret; - if(os->body_storage>LONG_MAX-needed){ - ogg_stream_clear(os); - return -1; - } - body_storage=os->body_storage+needed; - if(body_storagebody_data,body_storage*sizeof(*os->body_data)); +static int _os_body_expand(ogg_stream_state *os,int needed){ + if(os->body_storage<=os->body_fill+needed){ + void *ret=realloc(os->body_data,(os->body_storage+needed+1024)* + sizeof(*os->body_data)); if(!ret){ ogg_stream_clear(os); return -1; } - os->body_storage=body_storage; + os->body_storage+=(needed+1024); os->body_data=ret; } return 0; } -static int _os_lacing_expand(ogg_stream_state *os,long needed){ - if(os->lacing_storage-needed<=os->lacing_fill){ - long lacing_storage; - void *ret; - if(os->lacing_storage>LONG_MAX-needed){ - ogg_stream_clear(os); - return -1; - } - lacing_storage=os->lacing_storage+needed; - if(lacing_storagelacing_vals,lacing_storage*sizeof(*os->lacing_vals)); +static int _os_lacing_expand(ogg_stream_state *os,int needed){ + if(os->lacing_storage<=os->lacing_fill+needed){ + void *ret=realloc(os->lacing_vals,(os->lacing_storage+needed+32)* + sizeof(*os->lacing_vals)); if(!ret){ ogg_stream_clear(os); return -1; } os->lacing_vals=ret; - ret=_ogg_realloc(os->granule_vals,lacing_storage* + ret=realloc(os->granule_vals,(os->lacing_storage+needed+32)* sizeof(*os->granule_vals)); if(!ret){ ogg_stream_clear(os); return -1; } os->granule_vals=ret; - os->lacing_storage=lacing_storage; + os->lacing_storage+=(needed+32); } return 0; } @@ -292,7 +259,7 @@ static int _os_lacing_expand(ogg_stream_state *os,long needed){ void ogg_page_checksum_set(ogg_page *og){ if(og){ - ogg_uint32_t crc_reg=0; + uint32_t crc_reg=0; int i; /* safety; needed for API behavior, but not framing code */ @@ -315,19 +282,14 @@ void ogg_page_checksum_set(ogg_page *og){ /* submit data to the internal buffer of the framing engine */ int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, int count, - long e_o_s, ogg_int64_t granulepos){ + long e_o_s, int64_t granulepos){ - long bytes = 0, lacing_vals; - int i; + int bytes = 0, lacing_vals, i; if(ogg_stream_check(os)) return -1; if(!iov) return 0; - for (i = 0; i < count; ++i){ - if(iov[i].iov_len>LONG_MAX) return -1; - if(bytes>LONG_MAX-(long)iov[i].iov_len) return -1; - bytes += (long)iov[i].iov_len; - } + for (i = 0; i < count; ++i) bytes += (int)iov[i].iov_len; lacing_vals=bytes/255+1; if(os->body_returned){ @@ -393,7 +355,7 @@ static int ogg_stream_flush_i(ogg_stream_state *os,ogg_page *og, int force, int int maxvals=(os->lacing_fill>255?255:os->lacing_fill); int bytes=0; long acc=0; - ogg_int64_t granule_pos=-1; + int64_t granule_pos=-1; if(ogg_stream_check(os)) return(0); if(maxvals==0) return(0); @@ -606,7 +568,8 @@ int ogg_sync_init(ogg_sync_state *oy){ /* clear non-flat storage within */ int ogg_sync_clear(ogg_sync_state *oy){ if(oy){ - if(oy->data)_ogg_free(oy->data); + if(oy->data) + free(oy->data); memset(oy,0,sizeof(*oy)); } return(0); @@ -615,7 +578,7 @@ int ogg_sync_clear(ogg_sync_state *oy){ int ogg_sync_destroy(ogg_sync_state *oy){ if(oy){ ogg_sync_clear(oy); - _ogg_free(oy); + free(oy); } return(0); } @@ -642,9 +605,9 @@ char *ogg_sync_buffer(ogg_sync_state *oy, long size){ void *ret; if(oy->data) - ret=_ogg_realloc(oy->data,newsize); + ret=realloc(oy->data,newsize); else - ret=_ogg_malloc(newsize); + ret=malloc(newsize); if(!ret){ ogg_sync_clear(oy); return NULL; @@ -815,7 +778,7 @@ int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){ int continued=ogg_page_continued(og); int bos=ogg_page_bos(og); int eos=ogg_page_eos(og); - ogg_int64_t granulepos=ogg_page_granulepos(og); + int64_t granulepos=ogg_page_granulepos(og); int serialno=ogg_page_serialno(og); long pageno=ogg_page_pageno(og); int segments=header[26]; @@ -1038,1074 +1001,6 @@ int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){ } void ogg_packet_clear(ogg_packet *op) { - _ogg_free(op->packet); + free(op->packet); memset(op, 0, sizeof(*op)); } - -#ifdef _V_SELFTEST -#include - -ogg_stream_state os_en, os_de; -ogg_sync_state oy; - -void checkpacket(ogg_packet *op,long len, int no, long pos){ - long j; - static int sequence=0; - static int lastno=0; - - if(op->bytes!=len){ - fprintf(stderr,"incorrect packet length (%ld != %ld)!\n",op->bytes,len); - exit(1); - } - if(op->granulepos!=pos){ - fprintf(stderr,"incorrect packet granpos (%ld != %ld)!\n",(long)op->granulepos,pos); - exit(1); - } - - /* packet number just follows sequence/gap; adjust the input number - for that */ - if(no==0){ - sequence=0; - }else{ - sequence++; - if(no>lastno+1) - sequence++; - } - lastno=no; - if(op->packetno!=sequence){ - fprintf(stderr,"incorrect packet sequence %ld != %d\n", - (long)(op->packetno),sequence); - exit(1); - } - - /* Test data */ - for(j=0;jbytes;j++) - if(op->packet[j]!=((j+no)&0xff)){ - fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n", - j,op->packet[j],(j+no)&0xff); - exit(1); - } -} - -void check_page(unsigned char *data,const int *header,ogg_page *og){ - long j; - /* Test data */ - for(j=0;jbody_len;j++) - if(og->body[j]!=data[j]){ - fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n", - j,data[j],og->body[j]); - exit(1); - } - - /* Test header */ - for(j=0;jheader_len;j++){ - if(og->header[j]!=header[j]){ - fprintf(stderr,"header content mismatch at pos %ld:\n",j); - for(j=0;jheader[j]); - fprintf(stderr,"\n"); - exit(1); - } - } - if(og->header_len!=header[26]+27){ - fprintf(stderr,"header length incorrect! (%ld!=%d)\n", - og->header_len,header[26]+27); - exit(1); - } -} - -void print_header(ogg_page *og){ - int j; - fprintf(stderr,"\nHEADER:\n"); - fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n", - og->header[0],og->header[1],og->header[2],og->header[3], - (int)og->header[4],(int)og->header[5]); - - fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n", - (og->header[9]<<24)|(og->header[8]<<16)| - (og->header[7]<<8)|og->header[6], - (og->header[17]<<24)|(og->header[16]<<16)| - (og->header[15]<<8)|og->header[14], - ((long)(og->header[21])<<24)|(og->header[20]<<16)| - (og->header[19]<<8)|og->header[18]); - - fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (", - (int)og->header[22],(int)og->header[23], - (int)og->header[24],(int)og->header[25], - (int)og->header[26]); - - for(j=27;jheader_len;j++) - fprintf(stderr,"%d ",(int)og->header[j]); - fprintf(stderr,")\n\n"); -} - -void copy_page(ogg_page *og){ - unsigned char *temp=_ogg_malloc(og->header_len); - memcpy(temp,og->header,og->header_len); - og->header=temp; - - temp=_ogg_malloc(og->body_len); - memcpy(temp,og->body,og->body_len); - og->body=temp; -} - -void free_page(ogg_page *og){ - _ogg_free (og->header); - _ogg_free (og->body); -} - -void error(void){ - fprintf(stderr,"error!\n"); - exit(1); -} - -/* 17 only */ -const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0x15,0xed,0xec,0x91, - 1, - 17}; - -/* 17, 254, 255, 256, 500, 510, 600 byte, pad */ -const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0x59,0x10,0x6c,0x2c, - 1, - 17}; -const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04, - 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0x89,0x33,0x85,0xce, - 13, - 254,255,0,255,1,255,245,255,255,0, - 255,255,90}; - -/* nil packets; beginning,middle,end */ -const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; -const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04, - 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0x5c,0x3f,0x66,0xcb, - 17, - 17,254,255,0,0,255,1,0,255,245,255,255,0, - 255,255,90,0}; - -/* large initial packet */ -const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0x01,0x27,0x31,0xaa, - 18, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,10}; - -const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04, - 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0x7f,0x4e,0x8a,0xd2, - 4, - 255,4,255,0}; - - -/* continuing packet test */ -const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; - -const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00, - 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0xf8,0x3c,0x19,0x79, - 255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255}; - -const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05, - 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,2,0,0,0, - 0x38,0xe6,0xb6,0x28, - 6, - 255,220,255,4,255,0}; - - -/* spill expansion test */ -const int head1_4b[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; - -const int head2_4b[] = {0x4f,0x67,0x67,0x53,0,0x00, - 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0xce,0x8f,0x17,0x1a, - 23, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,10,255,4,255,0,0}; - - -const int head3_4b[] = {0x4f,0x67,0x67,0x53,0,0x04, - 0x07,0x14,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,2,0,0,0, - 0x9b,0xb2,0x50,0xa1, - 1, - 0}; - -/* page with the 255 segment limit */ -const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; - -const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00, - 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0xed,0x2a,0x2e,0xa7, - 255, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10}; - -const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04, - 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,2,0,0,0, - 0x6c,0x3b,0x82,0x3d, - 1, - 50}; - - -/* packet that overspans over an entire page */ -const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; - -const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00, - 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0x68,0x22,0x7c,0x3d, - 255, - 100, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255}; - -const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01, - 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, - 0x01,0x02,0x03,0x04,2,0,0,0, - 0xf4,0x87,0xba,0xf3, - 255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255}; - -const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05, - 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,3,0,0,0, - 0xf7,0x2f,0x6c,0x60, - 5, - 254,255,4,255,0}; - -/* packet that overspans over an entire page */ -const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; - -const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00, - 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0x68,0x22,0x7c,0x3d, - 255, - 100, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255}; - -const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05, - 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,2,0,0,0, - 0xd4,0xe0,0x60,0xe5, - 1, - 0}; - -void test_pack(const int *pl, const int **headers, int byteskip, - int pageskip, int packetskip){ - unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */ - long inptr=0; - long outptr=0; - long deptr=0; - long depacket=0; - long granule_pos=7,pageno=0; - int i,j,packets,pageout=pageskip; - int eosflag=0; - int bosflag=0; - - int byteskipcount=0; - - ogg_stream_reset(&os_en); - ogg_stream_reset(&os_de); - ogg_sync_reset(&oy); - - for(packets=0;packetsbyteskip){ - memcpy(next,og.header,byteskipcount-byteskip); - next+=byteskipcount-byteskip; - byteskipcount=byteskip; - } - - byteskipcount+=og.body_len; - if(byteskipcount>byteskip){ - memcpy(next,og.body,byteskipcount-byteskip); - next+=byteskipcount-byteskip; - byteskipcount=byteskip; - } - - ogg_sync_wrote(&oy,next-buf); - - while(1){ - int ret=ogg_sync_pageout(&oy,&og_de); - if(ret==0)break; - if(ret<0)continue; - /* got a page. Happy happy. Verify that it's good. */ - - fprintf(stderr,"(%d), ",pageout); - - check_page(data+deptr,headers[pageout],&og_de); - deptr+=og_de.body_len; - pageout++; - - /* submit it to deconstitution */ - ogg_stream_pagein(&os_de,&og_de); - - /* packets out? */ - while(ogg_stream_packetpeek(&os_de,&op_de2)>0){ - ogg_stream_packetpeek(&os_de,NULL); - ogg_stream_packetout(&os_de,&op_de); /* just catching them all */ - - /* verify peek and out match */ - if(memcmp(&op_de,&op_de2,sizeof(op_de))){ - fprintf(stderr,"packetout != packetpeek! pos=%ld\n", - depacket); - exit(1); - } - - /* verify the packet! */ - /* check data */ - if(memcmp(data+depacket,op_de.packet,op_de.bytes)){ - fprintf(stderr,"packet data mismatch in decode! pos=%ld\n", - depacket); - exit(1); - } - /* check bos flag */ - if(bosflag==0 && op_de.b_o_s==0){ - fprintf(stderr,"b_o_s flag not set on packet!\n"); - exit(1); - } - if(bosflag && op_de.b_o_s){ - fprintf(stderr,"b_o_s flag incorrectly set on packet!\n"); - exit(1); - } - bosflag=1; - depacket+=op_de.bytes; - - /* check eos flag */ - if(eosflag){ - fprintf(stderr,"Multiple decoded packets with eos flag!\n"); - exit(1); - } - - if(op_de.e_o_s)eosflag=1; - - /* check granulepos flag */ - if(op_de.granulepos!=-1){ - fprintf(stderr," granule:%ld ",(long)op_de.granulepos); - } - } - } - } - } - } - } - _ogg_free(data); - if(headers[pageno]!=NULL){ - fprintf(stderr,"did not write last page!\n"); - exit(1); - } - if(headers[pageout]!=NULL){ - fprintf(stderr,"did not decode last page!\n"); - exit(1); - } - if(inptr!=outptr){ - fprintf(stderr,"encoded page data incomplete!\n"); - exit(1); - } - if(inptr!=deptr){ - fprintf(stderr,"decoded page data incomplete!\n"); - exit(1); - } - if(inptr!=depacket){ - fprintf(stderr,"decoded packet data incomplete!\n"); - exit(1); - } - if(!eosflag){ - fprintf(stderr,"Never got a packet with EOS set!\n"); - exit(1); - } - fprintf(stderr,"ok.\n"); -} - -int main(void){ - - ogg_stream_init(&os_en,0x04030201); - ogg_stream_init(&os_de,0x04030201); - ogg_sync_init(&oy); - - /* Exercise each code path in the framing code. Also verify that - the checksums are working. */ - - { - /* 17 only */ - const int packets[]={17, -1}; - const int *headret[]={head1_0,NULL}; - - fprintf(stderr,"testing single page encoding... "); - test_pack(packets,headret,0,0,0); - } - - { - /* 17, 254, 255, 256, 500, 510, 600 byte, pad */ - const int packets[]={17, 254, 255, 256, 500, 510, 600, -1}; - const int *headret[]={head1_1,head2_1,NULL}; - - fprintf(stderr,"testing basic page encoding... "); - test_pack(packets,headret,0,0,0); - } - - { - /* nil packets; beginning,middle,end */ - const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1}; - const int *headret[]={head1_2,head2_2,NULL}; - - fprintf(stderr,"testing basic nil packets... "); - test_pack(packets,headret,0,0,0); - } - - { - /* large initial packet */ - const int packets[]={4345,259,255,-1}; - const int *headret[]={head1_3,head2_3,NULL}; - - fprintf(stderr,"testing initial-packet lacing > 4k... "); - test_pack(packets,headret,0,0,0); - } - - { - /* continuing packet test; with page spill expansion, we have to - overflow the lacing table. */ - const int packets[]={0,65500,259,255,-1}; - const int *headret[]={head1_4,head2_4,head3_4,NULL}; - - fprintf(stderr,"testing single packet page span... "); - test_pack(packets,headret,0,0,0); - } - - { - /* spill expand packet test */ - const int packets[]={0,4345,259,255,0,0,-1}; - const int *headret[]={head1_4b,head2_4b,head3_4b,NULL}; - - fprintf(stderr,"testing page spill expansion... "); - test_pack(packets,headret,0,0,0); - } - - /* page with the 255 segment limit */ - { - - const int packets[]={0,10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,50,-1}; - const int *headret[]={head1_5,head2_5,head3_5,NULL}; - - fprintf(stderr,"testing max packet segments... "); - test_pack(packets,headret,0,0,0); - } - - { - /* packet that overspans over an entire page */ - const int packets[]={0,100,130049,259,255,-1}; - const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL}; - - fprintf(stderr,"testing very large packets... "); - test_pack(packets,headret,0,0,0); - } - - { - /* test for the libogg 1.1.1 resync in large continuation bug - found by Josh Coalson) */ - const int packets[]={0,100,130049,259,255,-1}; - const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL}; - - fprintf(stderr,"testing continuation resync in very large packets... "); - test_pack(packets,headret,100,2,3); - } - - { - /* term only page. why not? */ - const int packets[]={0,100,64770,-1}; - const int *headret[]={head1_7,head2_7,head3_7,NULL}; - - fprintf(stderr,"testing zero data page (1 nil packet)... "); - test_pack(packets,headret,0,0,0); - } - - - - { - /* build a bunch of pages for testing */ - unsigned char *data=_ogg_malloc(1024*1024); - int pl[]={0, 1,1,98,4079, 1,1,2954,2057, 76,34,912,0,234,1000,1000, 1000,300,-1}; - int inptr=0,i,j; - ogg_page og[5]; - - ogg_stream_reset(&os_en); - - for(i=0;pl[i]!=-1;i++){ - ogg_packet op; - int len=pl[i]; - - op.packet=data+inptr; - op.bytes=len; - op.e_o_s=(pl[i+1]<0?1:0); - op.granulepos=(i+1)*1000; - - for(j=0;j0)error(); - - /* Test fractional page inputs: incomplete fixed header */ - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3, - 20); - ogg_sync_wrote(&oy,20); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - /* Test fractional page inputs: incomplete header */ - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23, - 5); - ogg_sync_wrote(&oy,5); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - /* Test fractional page inputs: incomplete body */ - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28, - og[1].header_len-28); - ogg_sync_wrote(&oy,og[1].header_len-28); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000); - ogg_sync_wrote(&oy,1000); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000, - og[1].body_len-1000); - ogg_sync_wrote(&oy,og[1].body_len-1000); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - - fprintf(stderr,"ok.\n"); - } - - /* Test fractional page inputs: page + incomplete capture */ - { - ogg_page og_de; - fprintf(stderr,"Testing sync on 1+partial inputs... "); - ogg_sync_reset(&oy); - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, - og[1].header_len); - ogg_sync_wrote(&oy,og[1].header_len); - - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy,og[1].body_len); - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, - 20); - ogg_sync_wrote(&oy,20); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20, - og[1].header_len-20); - ogg_sync_wrote(&oy,og[1].header_len-20); - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy,og[1].body_len); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - - fprintf(stderr,"ok.\n"); - } - - /* Test recapture: garbage + page */ - { - ogg_page og_de; - fprintf(stderr,"Testing search for capture... "); - ogg_sync_reset(&oy); - - /* 'garbage' */ - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy,og[1].body_len); - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, - og[1].header_len); - ogg_sync_wrote(&oy,og[1].header_len); - - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy,og[1].body_len); - - memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header, - 20); - ogg_sync_wrote(&oy,20); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20, - og[2].header_len-20); - ogg_sync_wrote(&oy,og[2].header_len-20); - memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body, - og[2].body_len); - ogg_sync_wrote(&oy,og[2].body_len); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - - fprintf(stderr,"ok.\n"); - } - - /* Test recapture: page + garbage + page */ - { - ogg_page og_de; - fprintf(stderr,"Testing recapture... "); - ogg_sync_reset(&oy); - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, - og[1].header_len); - ogg_sync_wrote(&oy,og[1].header_len); - - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy,og[1].body_len); - - memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header, - og[2].header_len); - ogg_sync_wrote(&oy,og[2].header_len); - - memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header, - og[2].header_len); - ogg_sync_wrote(&oy,og[2].header_len); - - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - - memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body, - og[2].body_len-5); - ogg_sync_wrote(&oy,og[2].body_len-5); - - memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header, - og[3].header_len); - ogg_sync_wrote(&oy,og[3].header_len); - - memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body, - og[3].body_len); - ogg_sync_wrote(&oy,og[3].body_len); - - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - - fprintf(stderr,"ok.\n"); - } - - /* Free page data that was previously copied */ - { - for(i=0;i<5;i++){ - free_page(&og[i]); - } - } - } - - return(0); -} - -#endif diff --git a/mednafen/tremor/framing.d b/mednafen/tremor/framing.d new file mode 100644 index 0000000..9529bb4 --- /dev/null +++ b/mednafen/tremor/framing.d @@ -0,0 +1,3 @@ +mednafen/tremor/framing.o: mednafen/tremor/framing.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ogg.h diff --git a/mednafen/tremor/info.c b/mednafen/tremor/info.c index 6ec5146..4dc39f9 100644 --- a/mednafen/tremor/info.c +++ b/mednafen/tremor/info.c @@ -94,11 +94,14 @@ void vorbis_comment_clear(vorbis_comment *vc){ long i; if(vc->user_comments){ for(i=0;icomments;i++) - if(vc->user_comments[i])_ogg_free(vc->user_comments[i]); - _ogg_free(vc->user_comments); + if(vc->user_comments[i]) + free(vc->user_comments[i]); + free(vc->user_comments); } - if(vc->comment_lengths)_ogg_free(vc->comment_lengths); - if(vc->vendor)_ogg_free(vc->vendor); + if(vc->comment_lengths) + free(vc->comment_lengths); + if(vc->vendor) + free(vc->vendor); memset(vc,0,sizeof(*vc)); } } @@ -113,7 +116,7 @@ int vorbis_info_blocksize(vorbis_info *vi,int zo){ /* used by synthesis, which has a full, alloced vi */ void vorbis_info_init(vorbis_info *vi){ memset(vi,0,sizeof(*vi)); - vi->codec_setup=(codec_setup_info *)_ogg_calloc(1,sizeof(codec_setup_info)); + vi->codec_setup=(codec_setup_info *)calloc(1,sizeof(codec_setup_info)); } void vorbis_info_clear(vorbis_info *vi){ @@ -123,7 +126,8 @@ void vorbis_info_clear(vorbis_info *vi){ if(ci){ for(i=0;imodes;i++) - if(ci->mode_param[i])_ogg_free(ci->mode_param[i]); + if(ci->mode_param[i]) + free(ci->mode_param[i]); for(i=0;imaps;i++) /* unpack does the range checking */ if(ci->map_param[i]) @@ -146,9 +150,9 @@ void vorbis_info_clear(vorbis_info *vi){ vorbis_book_clear(ci->fullbooks+i); } if(ci->fullbooks) - _ogg_free(ci->fullbooks); + free(ci->fullbooks); - _ogg_free(ci); + free(ci); } memset(vi,0,sizeof(*vi)); @@ -193,13 +197,13 @@ static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){ vendorlen=oggpack_read(opb,32); if(vendorlen<0)goto err_out; if(vendorlen>opb->storage-oggpack_bytes(opb))goto err_out; - vc->vendor=(char *)_ogg_calloc(vendorlen+1,1); + vc->vendor=(char *)calloc(vendorlen+1,1); if(vc->vendor==NULL)goto err_out; _v_readstring(opb,vc->vendor,vendorlen); i=oggpack_read(opb,32); if(i<0||i>=INT_MAX||i>(opb->storage-oggpack_bytes(opb))>>2)goto err_out; - vc->user_comments=(char **)_ogg_calloc(i+1,sizeof(*vc->user_comments)); - vc->comment_lengths=(int *)_ogg_calloc(i+1, sizeof(*vc->comment_lengths)); + vc->user_comments=(char **)calloc(i+1,sizeof(*vc->user_comments)); + vc->comment_lengths=(int *)calloc(i+1, sizeof(*vc->comment_lengths)); if(vc->user_comments==NULL||vc->comment_lengths==NULL)goto err_out; vc->comments=i; @@ -207,7 +211,7 @@ static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){ int len=oggpack_read(opb,32); if(len<0||len>opb->storage-oggpack_bytes(opb))goto err_out; vc->comment_lengths[i]=len; - vc->user_comments[i]=(char *)_ogg_calloc(len+1,1); + vc->user_comments[i]=(char *)calloc(len+1,1); if(vc->user_comments[i]==NULL){ vc->comments=i; goto err_out; @@ -227,6 +231,7 @@ static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){ static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; int i; + if(!ci)return(OV_EFAULT); /* codebooks */ ci->books=oggpack_read(opb,8)+1; @@ -281,7 +286,7 @@ static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){ ci->modes=oggpack_read(opb,6)+1; if(ci->modes<=0)goto err_out; for(i=0;imodes;i++){ - ci->mode_param[i]=(vorbis_info_mode *)_ogg_calloc(1,sizeof(*ci->mode_param[i])); + ci->mode_param[i]=(vorbis_info_mode *)calloc(1,sizeof(*ci->mode_param[i])); ci->mode_param[i]->blockflag=oggpack_read(opb,1); ci->mode_param[i]->windowtype=oggpack_read(opb,16); ci->mode_param[i]->transformtype=oggpack_read(opb,16); @@ -366,10 +371,6 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op) /* um... we didn't get the initial header */ return(OV_EBADHEADER); } - if(vc->vendor!=NULL){ - /* previously initialized comment header */ - return(OV_EBADHEADER); - } return(_vorbis_unpack_comment(vc,&opb)); @@ -378,14 +379,6 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op) /* um... we didn;t get the initial header or comments yet */ return(OV_EBADHEADER); } - if(vi->codec_setup==NULL){ - /* improperly initialized vorbis_info */ - return(OV_EFAULT); - } - if(((codec_setup_info *)vi->codec_setup)->books>0){ - /* previously initialized setup header */ - return(OV_EBADHEADER); - } return(_vorbis_unpack_books(vi,&opb)); diff --git a/mednafen/tremor/info.d b/mednafen/tremor/info.d new file mode 100644 index 0000000..fe68b29 --- /dev/null +++ b/mednafen/tremor/info.d @@ -0,0 +1,7 @@ +mednafen/tremor/info.o: mednafen/tremor/info.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ogg.h mednafen/tremor/ivorbiscodec.h \ + mednafen/tremor/codec_internal.h mednafen/tremor/codebook.h \ + mednafen/tremor/registry.h mednafen/tremor/backends.h \ + mednafen/tremor/window.h mednafen/tremor/misc.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h diff --git a/mednafen/tremor/ivorbiscodec.h b/mednafen/tremor/ivorbiscodec.h index 25e6509..2c2e72a 100644 --- a/mednafen/tremor/ivorbiscodec.h +++ b/mednafen/tremor/ivorbiscodec.h @@ -60,8 +60,8 @@ typedef struct vorbis_dsp_state{ int analysisp; vorbis_info *vi; - ogg_int32_t **pcm; - ogg_int32_t **pcmret; + int32_t **pcm; + int32_t **pcmret; int pcm_storage; int pcm_current; int pcm_returned; @@ -74,15 +74,15 @@ typedef struct vorbis_dsp_state{ long nW; long centerW; - ogg_int64_t granulepos; - ogg_int64_t sequence; + int64_t granulepos; + int64_t sequence; void *backend_state; } vorbis_dsp_state; typedef struct vorbis_block{ /* necessary stream state for linking to the framing abstraction */ - ogg_int32_t **pcm; /* this is a pointer into local storage */ + int32_t **pcm; /* this is a pointer into local storage */ oggpack_buffer opb; long lW; @@ -92,8 +92,8 @@ typedef struct vorbis_block{ int mode; int eofflag; - ogg_int64_t granulepos; - ogg_int64_t sequence; + int64_t granulepos; + int64_t sequence; vorbis_dsp_state *vd; /* For read-only access of configuration */ /* local storage to avoid remallocing; it's up to the mapping to @@ -174,7 +174,7 @@ extern int vorbis_synthesis_restart(vorbis_dsp_state *v); extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op); extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op); extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb); -extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm); +extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,int32_t ***pcm); extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples); extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op); diff --git a/mednafen/tremor/ivorbisfile.h b/mednafen/tremor/ivorbisfile.h index f6ecb0e..1a0bf2d 100644 --- a/mednafen/tremor/ivorbisfile.h +++ b/mednafen/tremor/ivorbisfile.h @@ -26,8 +26,7 @@ extern "C" #include #include "ivorbiscodec.h" -#define CHUNKSIZE 65535 -#define READSIZE 1024 +#define CHUNKSIZE 1024 /* The function prototypes for the callbacks are basically the same as for * the stdio functions fread, fseek, fclose, ftell. * The one difference is that the FILE * arguments have been replaced with @@ -40,7 +39,7 @@ extern "C" */ typedef struct { size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource); - int (*seek_func) (void *datasource, ogg_int64_t offset, int whence); + int (*seek_func) (void *datasource, int64_t offset, int whence); int (*close_func) (void *datasource); long (*tell_func) (void *datasource); } ov_callbacks; @@ -54,28 +53,28 @@ typedef struct { typedef struct OggVorbis_File { void *datasource; /* Pointer to a FILE *, etc. */ int seekable; - ogg_int64_t offset; - ogg_int64_t end; + int64_t offset; + int64_t end; ogg_sync_state oy; /* If the FILE handle isn't seekable (eg, a pipe), only the current stream appears */ int links; - ogg_int64_t *offsets; - ogg_int64_t *dataoffsets; - ogg_uint32_t *serialnos; - ogg_int64_t *pcmlengths; + int64_t *offsets; + int64_t *dataoffsets; + uint32_t *serialnos; + int64_t *pcmlengths; vorbis_info *vi; vorbis_comment *vc; /* Decoding working state local storage */ - ogg_int64_t pcm_offset; + int64_t pcm_offset; int ready_state; - ogg_uint32_t current_serialno; + uint32_t current_serialno; int current_link; - ogg_int64_t bittrack; - ogg_int64_t samptrack; + int64_t bittrack; + int64_t samptrack; ogg_stream_state os; /* take physical pages, weld into a logical stream of packets */ @@ -87,34 +86,28 @@ typedef struct OggVorbis_File { } OggVorbis_File; extern int ov_clear(OggVorbis_File *vf); -extern int ov_open(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes); extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf, const char *initial, long ibytes, ov_callbacks callbacks); -extern int ov_test(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes); -extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf, - const char *initial, long ibytes, ov_callbacks callbacks); -extern int ov_test_open(OggVorbis_File *vf); - extern long ov_bitrate(OggVorbis_File *vf,int i); extern long ov_bitrate_instant(OggVorbis_File *vf); extern long ov_streams(OggVorbis_File *vf); extern long ov_seekable(OggVorbis_File *vf); extern long ov_serialnumber(OggVorbis_File *vf,int i); -extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i); -extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i); -extern ogg_int64_t ov_time_total(OggVorbis_File *vf,int i); +extern int64_t ov_raw_total(OggVorbis_File *vf,int i); +extern int64_t ov_pcm_total(OggVorbis_File *vf,int i); +extern int64_t ov_time_total(OggVorbis_File *vf,int i); -extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos); -extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos); -extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos); -extern int ov_time_seek(OggVorbis_File *vf,ogg_int64_t pos); -extern int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t pos); +extern int ov_raw_seek(OggVorbis_File *vf,int64_t pos); +extern int ov_pcm_seek(OggVorbis_File *vf,int64_t pos); +extern int ov_pcm_seek_page(OggVorbis_File *vf,int64_t pos); +extern int ov_time_seek(OggVorbis_File *vf,int64_t pos); +extern int ov_time_seek_page(OggVorbis_File *vf,int64_t pos); -extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf); -extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf); -extern ogg_int64_t ov_time_tell(OggVorbis_File *vf); +extern int64_t ov_raw_tell(OggVorbis_File *vf); +extern int64_t ov_pcm_tell(OggVorbis_File *vf); +extern int64_t ov_time_tell(OggVorbis_File *vf); extern vorbis_info *ov_info(OggVorbis_File *vf,int link); extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link); diff --git a/mednafen/tremor/lsp_lookup.h b/mednafen/tremor/lsp_lookup.h index fa84851..4b9903f 100644 --- a/mednafen/tremor/lsp_lookup.h +++ b/mednafen/tremor/lsp_lookup.h @@ -18,7 +18,7 @@ #ifndef _V_LOOKUP_DATA_H_ #define _V_LOOKUP_DATA_H_ -#include "os_types.h" +#include #define FROMdB_LOOKUP_SZ 35 #define FROMdB2_LOOKUP_SZ 32 @@ -26,7 +26,7 @@ #define FROMdB2_SHIFT 3 #define FROMdB2_MASK 31 -static const ogg_int32_t FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={ +static const int32_t FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={ 0x003fffff, 0x0028619b, 0x00197a96, 0x0010137a, 0x000a24b0, 0x00066666, 0x000409c3, 0x00028c42, 0x00019b8c, 0x000103ab, 0x0000a3d7, 0x00006760, @@ -37,7 +37,7 @@ static const ogg_int32_t FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={ 0x0000000b, 0x00000007, 0x00000004, 0x00000003, 0x00000002, 0x00000001, 0x00000001}; -static const ogg_int32_t FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={ +static const int32_t FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={ 0x000001fc, 0x000001f5, 0x000001ee, 0x000001e7, 0x000001e0, 0x000001d9, 0x000001d2, 0x000001cc, 0x000001c5, 0x000001bf, 0x000001b8, 0x000001b2, @@ -92,7 +92,7 @@ static const long INVSQ_LOOKUP_IDel[64]={ #define COS_LOOKUP_I_SHIFT 9 #define COS_LOOKUP_I_MASK 511 #define COS_LOOKUP_I_SZ 128 -static const ogg_int32_t COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={ +static const int32_t COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={ 16384, 16379, 16364, 16340, 16305, 16261, 16207, 16143, 16069, 15986, 15893, 15791, diff --git a/mednafen/tremor/mapping0.c b/mednafen/tremor/mapping0.c index de050ef..4da4865 100644 --- a/mednafen/tremor/mapping0.c +++ b/mednafen/tremor/mapping0.c @@ -57,7 +57,7 @@ static void mapping0_free_info(vorbis_info_mapping *i){ vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i; if(info){ memset(info,0,sizeof(*info)); - _ogg_free(info); + free(info); } } @@ -71,12 +71,12 @@ static void mapping0_free_look(vorbis_look_mapping *look){ l->residue_func[i]->free_look(l->residue_look[i]); } - _ogg_free(l->floor_func); - _ogg_free(l->residue_func); - _ogg_free(l->floor_look); - _ogg_free(l->residue_look); + free(l->floor_func); + free(l->residue_func); + free(l->floor_look); + free(l->residue_look); memset(l,0,sizeof(*l)); - _ogg_free(l); + free(l); } } @@ -85,16 +85,16 @@ static vorbis_look_mapping *mapping0_look(vorbis_dsp_state *vd,vorbis_info_mode int i; vorbis_info *vi=vd->vi; codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)_ogg_calloc(1,sizeof(*look)); + vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)calloc(1,sizeof(*look)); vorbis_info_mapping0 *info=look->map=(vorbis_info_mapping0 *)m; look->mode=vm; - look->floor_look=(vorbis_look_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_look)); + look->floor_look=(vorbis_look_floor **)calloc(info->submaps,sizeof(*look->floor_look)); - look->residue_look=(vorbis_look_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_look)); + look->residue_look=(vorbis_look_residue **)calloc(info->submaps,sizeof(*look->residue_look)); - look->floor_func=(vorbis_func_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_func)); - look->residue_func=(vorbis_func_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_func)); + look->floor_func=(vorbis_func_floor **)calloc(info->submaps,sizeof(*look->floor_func)); + look->residue_func=(vorbis_func_residue **)calloc(info->submaps,sizeof(*look->residue_func)); for(i=0;isubmaps;i++){ int floornum=info->floorsubmap[i]; @@ -127,7 +127,7 @@ static int ilog(unsigned int v){ /* also responsible for range checking */ static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){ int i,b; - vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)_ogg_calloc(1,sizeof(*info)); + vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)calloc(1,sizeof(*info)); codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; memset(info,0,sizeof(*info)); @@ -194,7 +194,7 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ int i,j; long n=vb->pcmend=ci->blocksizes[vb->W]; - ogg_int32_t **pcmbundle=(ogg_int32_t **)alloca(sizeof(*pcmbundle)*vi->channels); + int32_t **pcmbundle=(int32_t **)alloca(sizeof(*pcmbundle)*vi->channels); int *zerobundle=(int *)alloca(sizeof(*zerobundle)*vi->channels); int *nonzero =(int *)alloca(sizeof(*nonzero)*vi->channels); @@ -249,12 +249,12 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ /* channel coupling */ for(i=info->coupling_steps-1;i>=0;i--){ - ogg_int32_t *pcmM=vb->pcm[info->coupling_mag[i]]; - ogg_int32_t *pcmA=vb->pcm[info->coupling_ang[i]]; + int32_t *pcmM=vb->pcm[info->coupling_mag[i]]; + int32_t *pcmA=vb->pcm[info->coupling_ang[i]]; for(j=0;j0) if(ang>0){ @@ -280,7 +280,7 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ /* compute and apply spectral envelope */ for(i=0;ichannels;i++){ - ogg_int32_t *pcm=vb->pcm[i]; + int32_t *pcm=vb->pcm[i]; int submap=info->chmuxlist[i]; look->floor_func[submap]-> inverse2(vb,look->floor_look[submap],floormemo[i],pcm); @@ -292,7 +292,7 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ /* transform the PCM data; takes PCM vector, vb; modifies PCM vector */ /* only MDCT right now.... */ for(i=0;ichannels;i++){ - ogg_int32_t *pcm=vb->pcm[i]; + int32_t *pcm=vb->pcm[i]; mdct_backward(n,pcm,pcm); } @@ -301,7 +301,7 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ /* window the data */ for(i=0;ichannels;i++){ - ogg_int32_t *pcm=vb->pcm[i]; + int32_t *pcm=vb->pcm[i]; if(nonzero[i]) _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW); else diff --git a/mednafen/tremor/mapping0.d b/mednafen/tremor/mapping0.d new file mode 100644 index 0000000..3b701f0 --- /dev/null +++ b/mednafen/tremor/mapping0.d @@ -0,0 +1,8 @@ +mednafen/tremor/mapping0.o: mednafen/tremor/mapping0.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ogg.h mednafen/tremor/ivorbiscodec.h \ + mednafen/tremor/mdct.h mednafen/tremor/misc.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h \ + mednafen/tremor/codec_internal.h mednafen/tremor/codebook.h \ + mednafen/tremor/window.h mednafen/tremor/registry.h \ + mednafen/tremor/backends.h diff --git a/mednafen/tremor/mdct.c b/mednafen/tremor/mdct.c index d5d278e..2f1ef20 100644 --- a/mednafen/tremor/mdct.c +++ b/mednafen/tremor/mdct.c @@ -13,7 +13,7 @@ function: normalized modified discrete cosine transform power of two length transform only [64 <= n ] - last mod: $Id: mdct.c 19172 2014-06-24 14:44:34Z xiphmont $ + last mod: $Id: mdct.c,v 1.9 2002/10/16 09:17:39 xiphmont Exp $ Original algorithm adapted long ago from _The use of multirate filter banks for coding of high quality digital audio_, by T. Sporer, @@ -40,7 +40,7 @@ /* 8 point butterfly (in place) */ -STIN void mdct_butterfly_8(DATA_TYPE *x){ +static INLINE void mdct_butterfly_8(DATA_TYPE *x){ REG_TYPE r0 = x[4] + x[0]; REG_TYPE r1 = x[4] - x[0]; @@ -63,7 +63,7 @@ STIN void mdct_butterfly_8(DATA_TYPE *x){ } /* 16 point butterfly (in place, 4 register) */ -STIN void mdct_butterfly_16(DATA_TYPE *x){ +static INLINE void mdct_butterfly_16(DATA_TYPE *x){ REG_TYPE r0, r1; @@ -94,7 +94,7 @@ STIN void mdct_butterfly_16(DATA_TYPE *x){ } /* 32 point butterfly (in place, 4 register) */ -STIN void mdct_butterfly_32(DATA_TYPE *x){ +static INLINE void mdct_butterfly_32(DATA_TYPE *x){ REG_TYPE r0, r1; @@ -145,7 +145,7 @@ STIN void mdct_butterfly_32(DATA_TYPE *x){ } /* N/stage point generic N stage butterfly (in place, 2 register) */ -STIN void mdct_butterfly_generic(DATA_TYPE *x,int points,int step){ +static INLINE void mdct_butterfly_generic(DATA_TYPE *x,int points,int step){ LOOKUP_T *T = sincos_lookup0; DATA_TYPE *x1 = x + points - 8; @@ -231,7 +231,7 @@ STIN void mdct_butterfly_generic(DATA_TYPE *x,int points,int step){ }while(T>sincos_lookup0); } -STIN void mdct_butterflies(DATA_TYPE *x,int points,int shift){ +static INLINE void mdct_butterflies(DATA_TYPE *x,int points,int shift){ int stages=8-shift; int i,j; @@ -248,11 +248,11 @@ STIN void mdct_butterflies(DATA_TYPE *x,int points,int shift){ static unsigned char bitrev[16]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15}; -STIN int bitrev12(int x){ +static INLINE int bitrev12(int x){ return bitrev[x>>8]|(bitrev[(x&0x0f0)>>4]<<4)|(((int)bitrev[x&0x00f])<<8); } -STIN void mdct_bitreverse(DATA_TYPE *x,int n,int step,int shift){ +static INLINE void mdct_bitreverse(DATA_TYPE *x,int n,int step,int shift){ int bit = 0; DATA_TYPE *w0 = x; diff --git a/mednafen/tremor/mdct.d b/mednafen/tremor/mdct.d new file mode 100644 index 0000000..9b8c4b0 --- /dev/null +++ b/mednafen/tremor/mdct.d @@ -0,0 +1,6 @@ +mednafen/tremor/mdct.o: mednafen/tremor/mdct.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ivorbiscodec.h mednafen/tremor/ogg.h \ + mednafen/tremor/codebook.h mednafen/tremor/misc.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h \ + mednafen/tremor/mdct.h mednafen/tremor/mdct_lookup.h diff --git a/mednafen/tremor/mdct.h b/mednafen/tremor/mdct.h index 6d88907..b274163 100644 --- a/mednafen/tremor/mdct.h +++ b/mednafen/tremor/mdct.h @@ -21,8 +21,8 @@ #include "ivorbiscodec.h" #include "misc.h" -#define DATA_TYPE ogg_int32_t -#define REG_TYPE register ogg_int32_t +#define DATA_TYPE int32_t +#define REG_TYPE register int32_t #ifdef _LOW_ACCURACY_ #define cPI3_8 (0x0062) diff --git a/mednafen/tremor/mdct_lookup.h b/mednafen/tremor/mdct_lookup.h index ee4f101..627aee1 100644 --- a/mednafen/tremor/mdct_lookup.h +++ b/mednafen/tremor/mdct_lookup.h @@ -18,7 +18,7 @@ #include "misc.h" /* {sin(2*i*PI/4096), cos(2*i*PI/4096)}, with i = 0 to 512 */ -static const LOOKUP_T sincos_lookup0[1026] = { +static LOOKUP_T sincos_lookup0[1026] = { X(0x00000000), X(0x7fffffff), X(0x003243f5), X(0x7ffff621), X(0x006487e3), X(0x7fffd886), X(0x0096cbc1), X(0x7fffa72c), X(0x00c90f88), X(0x7fff6216), X(0x00fb5330), X(0x7fff0943), @@ -279,7 +279,7 @@ static const LOOKUP_T sincos_lookup0[1026] = { }; /* {sin((2*i+1)*PI/4096), cos((2*i+1)*PI/4096)}, with i = 0 to 511 */ -static const LOOKUP_T sincos_lookup1[1024] = { +static LOOKUP_T sincos_lookup1[1024] = { X(0x001921fb), X(0x7ffffd88), X(0x004b65ee), X(0x7fffe9cb), X(0x007da9d4), X(0x7fffc251), X(0x00afeda8), X(0x7fff8719), X(0x00e23160), X(0x7fff3824), X(0x011474f6), X(0x7ffed572), diff --git a/mednafen/tremor/misc.h b/mednafen/tremor/misc.h index 4fb9bfc..fbc1570 100644 --- a/mednafen/tremor/misc.h +++ b/mednafen/tremor/misc.h @@ -19,13 +19,14 @@ #define _V_RANDOM_H_ #include "ivorbiscodec.h" #include "os.h" +#include #ifdef _LOW_ACCURACY_ # define X(n) (((((n)>>22)+1)>>1) - ((((n)>>22)+1)>>9)) -# define LOOKUP_T const unsigned char +# define LOOKUP_T const uint8_t #else # define X(n) (n) -# define LOOKUP_T const ogg_int32_t +# define LOOKUP_T const int32_t #endif #include "asm_arm.h" @@ -41,40 +42,38 @@ #include #endif -#if OGG_BYTE_ORDER==OGG_LITTLE_ENDIAN +#ifdef MSB_FIRST union magic { struct { - ogg_int32_t lo; - ogg_int32_t hi; + int32_t hi; + int32_t lo; } halves; - ogg_int64_t whole; + int64_t whole; }; -#endif - -#if OGG_BYTE_ORDER==OGG_BIG_ENDIAN +#else union magic { struct { - ogg_int32_t hi; - ogg_int32_t lo; + int32_t lo; + int32_t hi; } halves; - ogg_int64_t whole; + int64_t whole; }; #endif -STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { +static INLINE int32_t MULT32(int32_t x, int32_t y) { union magic magic; - magic.whole = (ogg_int64_t)x * y; + magic.whole = (int64_t)x * y; return magic.halves.hi; } -STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { +static INLINE int32_t MULT31(int32_t x, int32_t y) { return MULT32(x,y)<<1; } -STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { +static INLINE int32_t MULT31_SHIFT15(int32_t x, int32_t y) { union magic magic; - magic.whole = (ogg_int64_t)x * y; - return ((ogg_uint32_t)(magic.halves.lo)>>15) | ((magic.halves.hi)<<17); + magic.whole = (int64_t)x * y; + return ((uint32_t)(magic.halves.lo)>>15) | ((magic.halves.hi)<<17); } #else @@ -93,15 +92,15 @@ STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { * tables in this case. */ -STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { +static INLINE int32_t MULT32(int32_t x, int32_t y) { return (x >> 9) * y; /* y preshifted >>23 */ } -STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { +static INLINE int32_t MULT31(int32_t x, int32_t y) { return (x >> 8) * y; /* y preshifted >>23 */ } -STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { +static INLINE int32_t MULT31_SHIFT15(int32_t x, int32_t y) { return (x >> 6) * y; /* y preshifted >>9 */ } @@ -138,25 +137,25 @@ STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { #else -STIN 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) +static INLINE void XPROD32(int32_t a, int32_t b, + int32_t t, int32_t v, + int32_t *x, int32_t *y) { *x = MULT32(a, t) + MULT32(b, v); *y = MULT32(b, t) - MULT32(a, v); } -STIN 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) +static INLINE void XPROD31(int32_t a, int32_t b, + int32_t t, int32_t v, + int32_t *x, int32_t *y) { *x = MULT31(a, t) + MULT31(b, v); *y = MULT31(b, t) - MULT31(a, v); } -STIN 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) +static INLINE void XNPROD31(int32_t a, int32_t b, + int32_t t, int32_t v, + int32_t *x, int32_t *y) { *x = MULT31(a, t) - MULT31(b, v); *y = MULT31(b, t) + MULT31(a, v); @@ -169,7 +168,7 @@ STIN void XNPROD31(ogg_int32_t a, ogg_int32_t b, #ifndef _V_CLIP_MATH #define _V_CLIP_MATH -STIN ogg_int32_t CLIP_TO_15(ogg_int32_t x) { +static INLINE int32_t CLIP_TO_15(int32_t x) { int ret=x; ret-= ((x<=32767)-1)&(x-32767); ret-= ((x>=-32768)-1)&(x+32768); @@ -178,10 +177,11 @@ STIN ogg_int32_t CLIP_TO_15(ogg_int32_t x) { #endif -STIN ogg_int32_t VFLOAT_MULT(ogg_int32_t a,ogg_int32_t ap, - ogg_int32_t b,ogg_int32_t bp, - ogg_int32_t *p){ - if(a && b){ +static INLINE int32_t VFLOAT_MULT(int32_t a,int32_t ap, + int32_t b,int32_t bp, + int32_t *p){ + if(a && b) + { #ifndef _LOW_ACCURACY_ *p=ap+bp+32; return MULT32(a,b); @@ -189,23 +189,23 @@ STIN ogg_int32_t VFLOAT_MULT(ogg_int32_t a,ogg_int32_t ap, *p=ap+bp+31; return (a>>15)*(b>>16); #endif - }else - return 0; + } + return 0; } int _ilog(unsigned int); -STIN ogg_int32_t VFLOAT_MULTI(ogg_int32_t a,ogg_int32_t ap, - ogg_int32_t i, - ogg_int32_t *p){ +static INLINE int32_t VFLOAT_MULTI(int32_t a,int32_t ap, + int32_t i, + int32_t *p){ int ip=_ilog(abs(i))-31; return VFLOAT_MULT(a,ap,i<<-ip,ip,p); } -STIN ogg_int32_t VFLOAT_ADD(ogg_int32_t a,ogg_int32_t ap, - ogg_int32_t b,ogg_int32_t bp, - ogg_int32_t *p){ +static INLINE int32_t VFLOAT_ADD(int32_t a,int32_t ap, + int32_t b,int32_t bp, + int32_t *p){ if(!a){ *p=bp; diff --git a/mednafen/tremor/ogg.h b/mednafen/tremor/ogg.h index 00975ca..cab8b6f 100644 --- a/mednafen/tremor/ogg.h +++ b/mednafen/tremor/ogg.h @@ -21,8 +21,8 @@ extern "C" { #endif +#include #include -#include "os_types.h" typedef struct { void *iov_base; @@ -58,7 +58,7 @@ typedef struct { int *lacing_vals; /* The values that will go to the segment table */ - ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact + int64_t *granule_vals; /* granulepos values for headers. Not compact this way, but it is simple coupled to the lacing fifo */ long lacing_storage; @@ -75,12 +75,12 @@ typedef struct { of a logical bitstream */ long serialno; long pageno; - ogg_int64_t packetno; /* sequence number for decode; the framing + int64_t packetno; /* sequence number for decode; the framing knows where there's a hole in the data, but we need coupling so that the codec (which is in a separate abstraction layer) also knows about the gap */ - ogg_int64_t granulepos; + int64_t granulepos; } ogg_stream_state; @@ -93,9 +93,9 @@ typedef struct { long b_o_s; long e_o_s; - ogg_int64_t granulepos; + int64_t granulepos; - ogg_int64_t packetno; /* sequence number for decode; the framing + int64_t packetno; /* sequence number for decode; the framing knows where there's a hole in the data, but we need coupling so that the codec (which is in a separate abstraction @@ -157,7 +157,7 @@ extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b); extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op); extern int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, - int count, long e_o_s, ogg_int64_t granulepos); + int count, long e_o_s, int64_t granulepos); extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og); extern int ogg_stream_pageout_fill(ogg_stream_state *os, ogg_page *og, int nfill); extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og); @@ -195,7 +195,7 @@ extern int ogg_page_version(const ogg_page *og); extern int ogg_page_continued(const ogg_page *og); extern int ogg_page_bos(const ogg_page *og); extern int ogg_page_eos(const ogg_page *og); -extern ogg_int64_t ogg_page_granulepos(const ogg_page *og); +extern int64_t ogg_page_granulepos(const ogg_page *og); extern int ogg_page_serialno(const ogg_page *og); extern long ogg_page_pageno(const ogg_page *og); extern int ogg_page_packets(const ogg_page *og); diff --git a/mednafen/tremor/os.h b/mednafen/tremor/os.h index 65a4992..81dcbee 100644 --- a/mednafen/tremor/os.h +++ b/mednafen/tremor/os.h @@ -17,20 +17,10 @@ ********************************************************************/ +#include #include -#include "os_types.h" -#ifndef _V_IFDEFJAIL_H_ -# define _V_IFDEFJAIL_H_ - -# ifdef __GNUC__ -# define STIN static __inline__ -# elif _WIN32 -# define STIN static __inline -# endif -#else -# define STIN static -#endif +#include #ifndef M_PI # define M_PI (3.1415926536f) @@ -51,12 +41,4 @@ # include #endif -#ifndef min -# define min(x,y) ((x)>(y)?(y):(x)) -#endif - -#ifndef max -# define max(x,y) ((x)<(y)?(y):(x)) -#endif - #endif /* _OS_H */ diff --git a/mednafen/tremor/os_types.h b/mednafen/tremor/os_types.h deleted file mode 100644 index 8d98348..0000000 --- a/mednafen/tremor/os_types.h +++ /dev/null @@ -1,54 +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: #ifdef jail to whip a few platforms into the UNIX ideal. - last mod: $Id: os_types.h 17712 2010-12-03 17:10:02Z xiphmont $ - - ********************************************************************/ - -/* - Modified for usage in Mednafen -*/ - -#ifndef _OS_TYPES_H -#define _OS_TYPES_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -#define OGG_BIG_ENDIAN 4321 -#define OGG_LITTLE_ENDIAN 1234 - -#ifdef MSB_FIRST - #define OGG_BYTE_ORDER OGG_BIG_ENDIAN -#else - #define OGG_BYTE_ORDER OGG_LITTLE_ENDIAN -#endif - -/* make it easy on the folks that want to compile the libs with a - different malloc than stdlib */ -#define _ogg_malloc malloc -#define _ogg_calloc calloc -#define _ogg_realloc realloc -#define _ogg_free free - -#include - -typedef int16_t ogg_int16_t; -typedef uint16_t ogg_uint16_t; -typedef int32_t ogg_int32_t; -typedef uint32_t ogg_uint32_t; -typedef int64_t ogg_int64_t; -typedef uint64_t ogg_uint64_t; - -#endif /* _OS_TYPES_H */ diff --git a/mednafen/tremor/registry.d b/mednafen/tremor/registry.d new file mode 100644 index 0000000..d1993e6 --- /dev/null +++ b/mednafen/tremor/registry.d @@ -0,0 +1,7 @@ +mednafen/tremor/registry.o: mednafen/tremor/registry.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ivorbiscodec.h mednafen/tremor/ogg.h \ + mednafen/tremor/codec_internal.h mednafen/tremor/codebook.h \ + mednafen/tremor/registry.h mednafen/tremor/backends.h \ + mednafen/tremor/misc.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h diff --git a/mednafen/tremor/res012.c b/mednafen/tremor/res012.c index e2438c5..96f5520 100644 --- a/mednafen/tremor/res012.c +++ b/mednafen/tremor/res012.c @@ -46,7 +46,7 @@ void res0_free_info(vorbis_info_residue *i){ vorbis_info_residue0 *info=(vorbis_info_residue0 *)i; if(info){ memset(info,0,sizeof(*info)); - _ogg_free(info); + free(info); } } @@ -57,14 +57,15 @@ void res0_free_look(vorbis_look_residue *i){ vorbis_look_residue0 *look=(vorbis_look_residue0 *)i; for(j=0;jparts;j++) - if(look->partbooks[j])_ogg_free(look->partbooks[j]); - _ogg_free(look->partbooks); + if(look->partbooks[j]) + free(look->partbooks[j]); + free(look->partbooks); for(j=0;jpartvals;j++) - _ogg_free(look->decodemap[j]); - _ogg_free(look->decodemap); + free(look->decodemap[j]); + free(look->decodemap); memset(look,0,sizeof(*look)); - _ogg_free(look); + free(look); } } @@ -89,7 +90,7 @@ static int icount(unsigned int v){ /* vorbis_info is for range checking */ vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){ int j,acc=0; - vorbis_info_residue0 *info=(vorbis_info_residue0 *)_ogg_calloc(1,sizeof(*info)); + vorbis_info_residue0 *info=(vorbis_info_residue0 *)calloc(1,sizeof(*info)); codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; info->begin=oggpack_read(opb,24); @@ -154,7 +155,7 @@ vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){ vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, vorbis_info_residue *vr){ vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr; - vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look)); + vorbis_look_residue0 *look=(vorbis_look_residue0 *)calloc(1,sizeof(*look)); codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup; int j,k,acc=0; @@ -168,13 +169,13 @@ vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, look->phrasebook=ci->fullbooks+info->groupbook; dim=look->phrasebook->dim; - look->partbooks=(codebook ***)_ogg_calloc(look->parts,sizeof(*look->partbooks)); + look->partbooks=(codebook ***)calloc(look->parts,sizeof(*look->partbooks)); for(j=0;jparts;j++){ int stages=ilog(info->secondstages[j]); if(stages){ if(stages>maxstage)maxstage=stages; - look->partbooks[j]=(codebook **)_ogg_calloc(stages,sizeof(*look->partbooks[j])); + look->partbooks[j]=(codebook **)calloc(stages,sizeof(*look->partbooks[j])); for(k=0;ksecondstages[j]&(1<partbooks[j][k]=ci->fullbooks+info->booklist[acc++]; @@ -189,11 +190,11 @@ vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, look->partvals=look->parts; for(j=1;jpartvals*=look->parts; look->stages=maxstage; - look->decodemap=(int **)_ogg_malloc(look->partvals*sizeof(*look->decodemap)); + look->decodemap=(int **)malloc(look->partvals*sizeof(*look->decodemap)); for(j=0;jpartvals;j++){ long val=j; long mult=look->partvals/look->parts; - look->decodemap[j]=(int *)_ogg_malloc(dim*sizeof(*look->decodemap[j])); + look->decodemap[j]=(int *)malloc(dim*sizeof(*look->decodemap[j])); for(k=0;kinfo; diff --git a/mednafen/tremor/res012.d b/mednafen/tremor/res012.d new file mode 100644 index 0000000..8c7ec29 --- /dev/null +++ b/mednafen/tremor/res012.d @@ -0,0 +1,8 @@ +mednafen/tremor/res012.o: mednafen/tremor/res012.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ogg.h mednafen/tremor/ivorbiscodec.h \ + mednafen/tremor/codec_internal.h mednafen/tremor/codebook.h \ + mednafen/tremor/registry.h mednafen/tremor/backends.h \ + mednafen/tremor/misc.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h \ + mednafen/tremor/block.h diff --git a/mednafen/tremor/sharedbook.c b/mednafen/tremor/sharedbook.c index 2e80918..d18792c 100644 --- a/mednafen/tremor/sharedbook.c +++ b/mednafen/tremor/sharedbook.c @@ -41,7 +41,7 @@ int _ilog(unsigned int v){ #define VQ_FMAN 21 #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */ -static ogg_int32_t _float32_unpack(long val,int *point){ +static int32_t _float32_unpack(long val,int *point){ long mant=val&0x1fffff; int sign=val&0x80000000; long exp =(val&0x7fe00000L)>>VQ_FMAN; @@ -67,16 +67,16 @@ static ogg_int32_t _float32_unpack(long val,int *point){ /* given a list of word lengths, generate a list of codewords. Works for length ordered or unordered, always assigns the lowest valued codewords first. Extended to handle unused entries (length 0) */ -ogg_uint32_t *_make_words(long *l,long n,long sparsecount){ +uint32_t *_make_words(long *l,long n,long sparsecount){ long i,j,count=0; - ogg_uint32_t marker[33]; - ogg_uint32_t *r=(ogg_uint32_t *)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r)); + uint32_t marker[33]; + uint32_t *r=(uint32_t *)malloc((sparsecount?sparsecount:n)*sizeof(*r)); memset(marker,0,sizeof(marker)); for(i=0;i0){ - ogg_uint32_t entry=marker[length]; + uint32_t entry=marker[length]; /* when we claim a node for an entry, we also claim the nodes below it (pruning off the imagined tree that may have dangled @@ -84,10 +84,11 @@ ogg_uint32_t *_make_words(long *l,long n,long sparsecount){ above for leaves */ /* update ourself */ - if(length<32 && (entry>>length)){ - /* error condition; the lengths must specify an overpopulated tree */ - _ogg_free(r); - return(NULL); + if(length<32 && (entry>>length)) + { + /* error condition; the lengths must specify an overpopulated tree */ + free(r); + return(NULL); } r[count++]=entry; @@ -127,18 +128,20 @@ ogg_uint32_t *_make_words(long *l,long n,long sparsecount){ which appears to be underpopulated because the tree doesn't really exist; there's only one possible 'codeword' or zero bits, but the above tree-gen code doesn't mark that. */ - if(sparsecount != 1){ - for(i=1;i<33;i++) - if(marker[i] & (0xffffffffUL>>(32-i))){ - _ogg_free(r); - return(NULL); - } + if(sparsecount != 1) + { + for(i=1;i<33;i++) + if(marker[i] & (0xffffffffUL>>(32-i))) + { + free(r); + return(NULL); + } } /* bitreverse the words because our bitwise packer/unpacker is LSb endian */ for(i=0,count=0;i>j)&1; @@ -191,130 +194,140 @@ long _book_maptype1_quantvals(const static_codebook *b){ the values in the quant vector). in map type 2, all the values came in in an explicit list. Both value lists must be unpacked */ -ogg_int32_t *_book_unquantize(const static_codebook *b,int n,int *sparsemap, - int *maxpoint){ - long j,k,count=0; - if(b->maptype==1 || b->maptype==2){ - int quantvals; - int minpoint,delpoint; - ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint); - ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint); - ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r)); - int *rp=(int *)_ogg_calloc(n*b->dim,sizeof(*rp)); +int32_t *_book_unquantize(const static_codebook *b,int n,int *sparsemap, + int *maxpoint) +{ + long j,k,count=0; + if(b->maptype==1 || b->maptype==2) + { + int quantvals; + int minpoint,delpoint; + int32_t mindel=_float32_unpack(b->q_min,&minpoint); + int32_t delta=_float32_unpack(b->q_delta,&delpoint); + int32_t *r=(int32_t *)calloc(n*b->dim,sizeof(*r)); + int *rp=(int *)calloc(n*b->dim,sizeof(*rp)); - *maxpoint=minpoint; + *maxpoint=minpoint; - /* maptype 1 and 2 both use a quantized value vector, but - different sizes */ - switch(b->maptype){ - case 1: - /* most of the time, entries%dimensions == 0, but we need to be - well defined. We define that the possible vales at each - scalar is values == entries/dim. If entries%dim != 0, we'll - have 'too few' values (values*dimentries;j++){ - if((sparsemap && b->lengthlist[j]) || !sparsemap){ - ogg_int32_t last=0; - int lastpoint=0; - int indexdiv=1; - for(k=0;kdim;k++){ - int index= (j/indexdiv)%quantvals; - int point=0; - int val=VFLOAT_MULTI(delta,delpoint, - abs(b->quantlist[index]),&point); + /* maptype 1 and 2 both use a quantized value vector, but + different sizes */ + switch(b->maptype){ + case 1: + /* most of the time, entries%dimensions == 0, but we need to be + well defined. We define that the possible vales at each + scalar is values == entries/dim. If entries%dim != 0, we'll + have 'too few' values (values*dimentries;j++){ + if((sparsemap && b->lengthlist[j]) || !sparsemap){ + int32_t last=0; + int lastpoint=0; + int indexdiv=1; + for(k=0;kdim;k++){ + int index= (j/indexdiv)%quantvals; + int point=0; + int val=VFLOAT_MULTI(delta,delpoint, + abs(b->quantlist[index]),&point); - val=VFLOAT_ADD(mindel,minpoint,val,point,&point); - val=VFLOAT_ADD(last,lastpoint,val,point,&point); - - if(b->q_sequencep){ - last=val; - lastpoint=point; - } - - if(sparsemap){ - r[sparsemap[count]*b->dim+k]=val; - rp[sparsemap[count]*b->dim+k]=point; - }else{ - r[count*b->dim+k]=val; - rp[count*b->dim+k]=point; - } - if(*maxpointq_sequencep){ + last=val; + lastpoint=point; + } + + if(sparsemap){ + r[sparsemap[count]*b->dim+k]=val; + rp[sparsemap[count]*b->dim+k]=point; + }else{ + r[count*b->dim+k]=val; + rp[count*b->dim+k]=point; + } + if(*maxpointentries;j++){ + if((sparsemap && b->lengthlist[j]) || !sparsemap){ + int32_t last=0; + int lastpoint=0; + + for(k=0;kdim;k++){ + int point=0; + int val=VFLOAT_MULTI(delta,delpoint, + abs(b->quantlist[j*b->dim+k]),&point); + + val=VFLOAT_ADD(mindel,minpoint,val,point,&point); + val=VFLOAT_ADD(last,lastpoint,val,point,&point); + + if(b->q_sequencep){ + last=val; + lastpoint=point; + } + + if(sparsemap){ + r[sparsemap[count]*b->dim+k]=val; + rp[sparsemap[count]*b->dim+k]=point; + }else{ + r[count*b->dim+k]=val; + rp[count*b->dim+k]=point; + } + if(*maxpointentries;j++){ - if((sparsemap && b->lengthlist[j]) || !sparsemap){ - ogg_int32_t last=0; - int lastpoint=0; - for(k=0;kdim;k++){ - int point=0; - int val=VFLOAT_MULTI(delta,delpoint, - abs(b->quantlist[j*b->dim+k]),&point); + for(j=0;jdim;j++) + if(rp[j]<*maxpoint) + r[j]>>=*maxpoint-rp[j]; - val=VFLOAT_ADD(mindel,minpoint,val,point,&point); - val=VFLOAT_ADD(last,lastpoint,val,point,&point); - - if(b->q_sequencep){ - last=val; - lastpoint=point; - } - - if(sparsemap){ - r[sparsemap[count]*b->dim+k]=val; - rp[sparsemap[count]*b->dim+k]=point; - }else{ - r[count*b->dim+k]=val; - rp[count*b->dim+k]=point; - } - if(*maxpointdim;j++) - if(rp[j]<*maxpoint) - r[j]>>=*maxpoint-rp[j]; - - _ogg_free(rp); - return(r); - } - return(NULL); + free(rp); + return(r); + } + return(NULL); } -void vorbis_staticbook_destroy(static_codebook *b){ - if(b->quantlist)_ogg_free(b->quantlist); - if(b->lengthlist)_ogg_free(b->lengthlist); - memset(b,0,sizeof(*b)); - _ogg_free(b); +void vorbis_staticbook_destroy(static_codebook *b) +{ + if(b->quantlist) + free(b->quantlist); + if(b->lengthlist) + free(b->lengthlist); + memset(b,0,sizeof(*b)); + free(b); } void vorbis_book_clear(codebook *b){ /* static book is not cleared; we're likely called on the lookup and the static codebook belongs to the info struct */ - if(b->valuelist)_ogg_free(b->valuelist); - if(b->codelist)_ogg_free(b->codelist); + if(b->valuelist) + free(b->valuelist); + if(b->codelist) + free(b->codelist); - if(b->dec_index)_ogg_free(b->dec_index); - if(b->dec_codelengths)_ogg_free(b->dec_codelengths); - if(b->dec_firsttable)_ogg_free(b->dec_firsttable); + if(b->dec_index) + free(b->dec_index); + if(b->dec_codelengths) + free(b->dec_codelengths); + if(b->dec_firsttable) + free(b->dec_firsttable); memset(b,0,sizeof(*b)); } -static ogg_uint32_t bitreverse(ogg_uint32_t x){ +static uint32_t bitreverse(uint32_t x){ x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL); x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL); x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL); @@ -323,8 +336,8 @@ static ogg_uint32_t bitreverse(ogg_uint32_t x){ } static int sort32a(const void *a,const void *b){ - return (**(ogg_uint32_t **)a>**(ogg_uint32_t **)b)- - (**(ogg_uint32_t **)a<**(ogg_uint32_t **)b); + return (**(uint32_t **)a>**(uint32_t **)b)- + (**(uint32_t **)a<**(uint32_t **)b); } /* decode codebook arrangement is more heavily optimized than encode */ @@ -354,8 +367,8 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ by sorted bitreversed codeword to allow treeless decode. */ /* perform sort */ - ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries); - ogg_uint32_t **codep=(ogg_uint32_t **)alloca(sizeof(*codep)*n); + uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries); + uint32_t **codep=(uint32_t **)alloca(sizeof(*codep)*n); if(codes==NULL)goto err_out; @@ -367,7 +380,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ qsort(codep,n,sizeof(*codep),sort32a); sortindex=(int *)alloca(n*sizeof(*sortindex)); - c->codelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist)); + c->codelist=(uint32_t *)malloc(n*sizeof(*c->codelist)); /* the index is a reverse index */ for(i=0;icodelist[sortindex[i]]=codes[i]; - _ogg_free(codes); - - + free(codes); c->valuelist=_book_unquantize(s,n,sortindex,&c->binarypoint); - c->dec_index=(int *)_ogg_malloc(n*sizeof(*c->dec_index)); + c->dec_index=(int *)malloc(n*sizeof(*c->dec_index)); for(n=0,i=0;ientries;i++) if(s->lengthlist[i]>0) c->dec_index[sortindex[n++]]=i; - c->dec_codelengths=(char *)_ogg_malloc(n*sizeof(*c->dec_codelengths)); + c->dec_codelengths=(char *)malloc(n*sizeof(*c->dec_codelengths)); for(n=0,i=0;ientries;i++) if(s->lengthlist[i]>0) c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; @@ -397,14 +408,14 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ if(c->dec_firsttablen>8)c->dec_firsttablen=8; tabn=1<dec_firsttablen; - c->dec_firsttable=(ogg_uint32_t *)_ogg_calloc(tabn,sizeof(*c->dec_firsttable)); + c->dec_firsttable=(uint32_t *)calloc(tabn,sizeof(*c->dec_firsttable)); c->dec_maxlength=0; for(i=0;idec_maxlengthdec_codelengths[i]) c->dec_maxlength=c->dec_codelengths[i]; if(c->dec_codelengths[i]<=c->dec_firsttablen){ - ogg_uint32_t orig=bitreverse(c->codelist[i]); + uint32_t orig=bitreverse(c->codelist[i]); for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++) c->dec_firsttable[orig|(j<dec_codelengths[i])]=i+1; } @@ -413,11 +424,11 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ /* now fill in 'unused' entries in the firsttable with hi/lo search hints for the non-direct-hits */ { - ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen); + uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen); long lo=0,hi=0; for(i=0;idec_firsttablen); + uint32_t word=i<<(32-c->dec_firsttablen); if(c->dec_firsttable[bitreverse(word)]==0){ while((lo+1)codelist[lo+1]<=word)lo++; while( hi=(c->codelist[hi]&mask))hi++; diff --git a/mednafen/tremor/sharedbook.d b/mednafen/tremor/sharedbook.d new file mode 100644 index 0000000..22c53a1 --- /dev/null +++ b/mednafen/tremor/sharedbook.d @@ -0,0 +1,6 @@ +mednafen/tremor/sharedbook.o: mednafen/tremor/sharedbook.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ogg.h mednafen/tremor/misc.h \ + mednafen/tremor/ivorbiscodec.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h \ + mednafen/tremor/codebook.h diff --git a/mednafen/tremor/synthesis.c b/mednafen/tremor/synthesis.c index 5e4d3d6..bb50b4f 100644 --- a/mednafen/tremor/synthesis.c +++ b/mednafen/tremor/synthesis.c @@ -67,15 +67,15 @@ static int _vorbis_synthesis1(vorbis_block *vb,ogg_packet *op,int decodep){ /* more setup */ vb->granulepos=op->granulepos; - vb->sequence=op->packetno; /* first block is third packet */ + vb->sequence=op->packetno-3; /* first block is third packet */ vb->eofflag=op->e_o_s; if(decodep){ /* alloc pcm passback storage */ vb->pcmend=ci->blocksizes[vb->W]; - vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); + vb->pcm=(int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); for(i=0;ichannels;i++) - vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); + vb->pcm[i]=(int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); /* unpack_header enforces range checking */ type=ci->map_type[ci->mode_param[mode]->mapping]; @@ -124,7 +124,7 @@ long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){ /* read our mode and pre/post windowsize */ mode=oggpack_read(&opb,modebits); } - if(mode==-1 || !ci->mode_param[mode])return(OV_EBADPACKET); + if(mode==-1)return(OV_EBADPACKET); return(ci->blocksizes[ci->mode_param[mode]->blockflag]); } diff --git a/mednafen/tremor/synthesis.d b/mednafen/tremor/synthesis.d new file mode 100644 index 0000000..ef9d686 --- /dev/null +++ b/mednafen/tremor/synthesis.d @@ -0,0 +1,8 @@ +mednafen/tremor/synthesis.o: mednafen/tremor/synthesis.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ogg.h mednafen/tremor/ivorbiscodec.h \ + mednafen/tremor/codec_internal.h mednafen/tremor/codebook.h \ + mednafen/tremor/registry.h mednafen/tremor/backends.h \ + mednafen/tremor/misc.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h \ + mednafen/tremor/block.h diff --git a/mednafen/tremor/vorbisfile.c b/mednafen/tremor/vorbisfile.c index b842a58..b75b580 100644 --- a/mednafen/tremor/vorbisfile.c +++ b/mednafen/tremor/vorbisfile.c @@ -6,18 +6,17 @@ * 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-2014 * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2009 * * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * * * ******************************************************************** function: stdio-based convenience library for opening/seeking/decoding - last mod: $Id: vorbisfile.c 19172 2014-06-24 14:44:34Z xiphmont $ + last mod: $Id: vorbisfile.c,v 1.6 2003/03/30 23:40:56 xiphmont Exp $ ********************************************************************/ #include -#include #include #include #include @@ -63,26 +62,33 @@ static long _get_data(OggVorbis_File *vf){ errno=0; if(!(vf->callbacks.read_func))return(-1); if(vf->datasource){ - char *buffer=ogg_sync_buffer(&vf->oy,READSIZE); - long bytes=(vf->callbacks.read_func)(buffer,1,READSIZE,vf->datasource); + char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE); + long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource); if(bytes>0)ogg_sync_wrote(&vf->oy,bytes); - if(bytes==0 && errno)return(-1); +#ifdef GEKKO + // It seems that EOVERFLOW is set whenever + // we read to the end of the file on WII... + // Fix copied from WiiMednafen code. + if(bytes==0 && errno && errno != EOVERFLOW) +#else + if(bytes==0 && errno) +#endif + { + return(-1); + } return(bytes); }else return(0); } /* save a tiny smidge of verbosity to make the code more readable */ -static int _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){ +static int _seek_helper(OggVorbis_File *vf,int64_t offset){ if(vf->datasource){ - /* only seek if the file position isn't already there */ - if(vf->offset != offset){ - if(!(vf->callbacks.seek_func)|| - (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET) == -1) - return OV_EREAD; - vf->offset=offset; - ogg_sync_reset(&vf->oy); - } + if(!(vf->callbacks.seek_func)|| + (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET) == -1) + return OV_EREAD; + vf->offset=offset; + ogg_sync_reset(&vf->oy); }else{ /* shouldn't happen unless someone writes a broken callback */ return OV_EFAULT; @@ -103,8 +109,8 @@ static int _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){ return: <0) did not find a page (OV_FALSE, OV_EOF, OV_EREAD) n) found a page at absolute offset n */ -static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og, - ogg_int64_t boundary){ +static int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og, + int64_t boundary){ if(boundary>0)boundary+=vf->offset; while(1){ long more; @@ -127,7 +133,7 @@ static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og, }else{ /* got a page. Return the offset at the page beginning, advance the internal offset past the page end */ - ogg_int64_t ret=vf->offset; + int64_t ret=vf->offset; vf->offset+=more; return(ret); @@ -136,14 +142,16 @@ static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og, } } -/* find the latest page beginning before the passed in position. Much - dirtier than the above as Ogg doesn't have any backward search - linkage. no 'readp' as it will certainly have to read. */ +/* find the latest page beginning before the current stream cursor + position. Much dirtier than the above as Ogg doesn't have any + backward search linkage. no 'readp' as it will certainly have to + read. */ /* returns offset or OV_EREAD, OV_FAULT */ -static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_int64_t begin,ogg_page *og){ - ogg_int64_t end = begin; - ogg_int64_t ret; - ogg_int64_t offset=-1; +static int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){ + int64_t begin=vf->offset; + int64_t end=begin; + int64_t ret; + int64_t offset=-1; while(offset==-1){ begin-=CHUNKSIZE; @@ -181,21 +189,21 @@ static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_int64_t begin,ogg_page return(offset); } -static void _add_serialno(ogg_page *og,ogg_uint32_t **serialno_list, int *n){ - ogg_uint32_t s = ogg_page_serialno(og); +static void _add_serialno(ogg_page *og,uint32_t **serialno_list, int *n){ + uint32_t s = ogg_page_serialno(og); (*n)++; if(*serialno_list){ - *serialno_list = _ogg_realloc(*serialno_list, sizeof(**serialno_list)*(*n)); + *serialno_list = realloc(*serialno_list, sizeof(**serialno_list)*(*n)); }else{ - *serialno_list = _ogg_malloc(sizeof(**serialno_list)); + *serialno_list = malloc(sizeof(**serialno_list)); } (*serialno_list)[(*n)-1] = s; } /* returns nonzero if found */ -static int _lookup_serialno(ogg_uint32_t s, ogg_uint32_t *serialno_list, int n){ +static int _lookup_serialno(uint32_t s, uint32_t *serialno_list, int n){ if(serialno_list){ while(n--){ if(*serialno_list == s) return 1; @@ -205,8 +213,8 @@ static int _lookup_serialno(ogg_uint32_t s, ogg_uint32_t *serialno_list, int n){ return 0; } -static int _lookup_page_serialno(ogg_page *og, ogg_uint32_t *serialno_list, int n){ - ogg_uint32_t s = ogg_page_serialno(og); +static int _lookup_page_serialno(ogg_page *og, uint32_t *serialno_list, int n){ + uint32_t s = ogg_page_serialno(og); return _lookup_serialno(s,serialno_list,n); } @@ -216,17 +224,18 @@ static int _lookup_page_serialno(ogg_page *og, ogg_uint32_t *serialno_list, int info of last page of the matching serial number instead of the very last page. If no page of the specified serialno is seen, it will return the info of last page and alter *serialno. */ -static ogg_int64_t _get_prev_page_serial(OggVorbis_File *vf, ogg_int64_t begin, - ogg_uint32_t *serial_list, int serial_n, - int *serialno, ogg_int64_t *granpos){ +static int64_t _get_prev_page_serial(OggVorbis_File *vf, + uint32_t *serial_list, int serial_n, + int *serialno, int64_t *granpos){ ogg_page og; - ogg_int64_t end=begin; - ogg_int64_t ret; + int64_t begin=vf->offset; + int64_t end=begin; + int64_t ret; - ogg_int64_t prefoffset=-1; - ogg_int64_t offset=-1; - ogg_int64_t ret_serialno=-1; - ogg_int64_t ret_gran=-1; + int64_t prefoffset=-1; + int64_t offset=-1; + int64_t ret_serialno=-1; + int64_t ret_gran=-1; while(offset==-1){ begin-=CHUNKSIZE; @@ -246,12 +255,12 @@ static ogg_int64_t _get_prev_page_serial(OggVorbis_File *vf, ogg_int64_t begin, ret_gran=ogg_page_granulepos(&og); offset=ret; - if((ogg_uint32_t)ret_serialno == *serialno){ + if((uint32_t)ret_serialno == *serialno){ prefoffset=ret; *granpos=ret_gran; } - if(!_lookup_serialno((ogg_uint32_t)ret_serialno,serial_list,serial_n)){ + if(!_lookup_serialno((uint32_t)ret_serialno,serial_list,serial_n)){ /* we fell off the end of the link, which means we seeked back too far and shouldn't have been looking in that link to begin with. If we found the preferred serial number, @@ -274,7 +283,7 @@ static ogg_int64_t _get_prev_page_serial(OggVorbis_File *vf, ogg_int64_t begin, /* uses the local ogg_stream storage in vf; this is important for non-streaming input sources */ static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc, - ogg_uint32_t **serialno_list, int *serialno_n, + uint32_t **serialno_list, int *serialno_n, ogg_page *og_ptr){ ogg_page og; ogg_packet op; @@ -282,7 +291,7 @@ static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc, int allbos=0; if(!og_ptr){ - ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE); + int64_t llret=_get_next_page(vf,&og,CHUNKSIZE); if(llret==OV_EREAD)return(OV_EREAD); if(llret<0)return(OV_ENOTVORBIS); og_ptr=&og; @@ -299,7 +308,8 @@ static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc, if(serialno_list){ if(_lookup_page_serialno(og_ptr,*serialno_list,*serialno_n)){ /* a dupe serialnumber in an initial header packet set == invalid stream */ - if(*serialno_list)_ogg_free(*serialno_list); + if(*serialno_list) + free(*serialno_list); *serialno_list=0; *serialno_n=0; ret=OV_EBADHEADER; @@ -328,7 +338,7 @@ static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc, /* get next page */ { - ogg_int64_t llret=_get_next_page(vf,og_ptr,CHUNKSIZE); + int64_t llret=_get_next_page(vf,og_ptr,CHUNKSIZE); if(llret==OV_EREAD){ ret=OV_EREAD; goto bail_header; @@ -413,9 +423,9 @@ static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc, next page. Consumes the page in the process without decoding audio, however this is only called during stream parsing upon seekable open. */ -static ogg_int64_t _initial_pcmoffset(OggVorbis_File *vf, vorbis_info *vi){ +static int64_t _initial_pcmoffset(OggVorbis_File *vf, vorbis_info *vi){ ogg_page og; - ogg_int64_t accumulated=0; + int64_t accumulated=0; long lastblock=-1; int result; int serialno = vf->os.serialno; @@ -458,21 +468,21 @@ static ogg_int64_t _initial_pcmoffset(OggVorbis_File *vf, vorbis_info *vi){ Recurses for each link so it can alloc the link storage after finding them all, then unroll and fill the cache at the same time */ static int _bisect_forward_serialno(OggVorbis_File *vf, - ogg_int64_t begin, - ogg_int64_t searched, - ogg_int64_t end, - ogg_int64_t endgran, + int64_t begin, + int64_t searched, + int64_t end, + int64_t endgran, int endserial, - ogg_uint32_t *currentno_list, + uint32_t *currentno_list, int currentnos, long m){ - ogg_int64_t pcmoffset; - ogg_int64_t dataoffset=searched; - ogg_int64_t endsearched=end; - ogg_int64_t next=end; - ogg_int64_t searchgran=-1; + int64_t pcmoffset; + int64_t dataoffset=searched; + int64_t endsearched=end; + int64_t next=end; + int64_t searchgran=-1; ogg_page og; - ogg_int64_t ret,last; + int64_t ret,last; int serialno = vf->os.serialno; /* invariants: @@ -488,44 +498,42 @@ static int _bisect_forward_serialno(OggVorbis_File *vf, down to (or just started with) a single link. Now we need to find the last vorbis page belonging to the first vorbis stream for this link. */ - searched = end; + while(endserial != serialno){ endserial = serialno; - searched=_get_prev_page_serial(vf,searched,currentno_list,currentnos,&endserial,&endgran); + vf->offset=_get_prev_page_serial(vf,currentno_list,currentnos,&endserial,&endgran); } vf->links=m+1; - if(vf->offsets)_ogg_free(vf->offsets); - if(vf->serialnos)_ogg_free(vf->serialnos); - if(vf->dataoffsets)_ogg_free(vf->dataoffsets); + if(vf->offsets) + free(vf->offsets); + if(vf->serialnos) + free(vf->serialnos); + if(vf->dataoffsets) + free(vf->dataoffsets); - vf->offsets=_ogg_malloc((vf->links+1)*sizeof(*vf->offsets)); - vf->vi=_ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi)); - vf->vc=_ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc)); - vf->serialnos=_ogg_malloc(vf->links*sizeof(*vf->serialnos)); - vf->dataoffsets=_ogg_malloc(vf->links*sizeof(*vf->dataoffsets)); - vf->pcmlengths=_ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths)); + vf->offsets=malloc((vf->links+1)*sizeof(*vf->offsets)); + vf->vi=realloc(vf->vi,vf->links*sizeof(*vf->vi)); + vf->vc=realloc(vf->vc,vf->links*sizeof(*vf->vc)); + vf->serialnos=malloc(vf->links*sizeof(*vf->serialnos)); + vf->dataoffsets=malloc(vf->links*sizeof(*vf->dataoffsets)); + vf->pcmlengths=malloc(vf->links*2*sizeof(*vf->pcmlengths)); vf->offsets[m+1]=end; vf->offsets[m]=begin; - vf->pcmlengths[m*2+1]=(endgran<0?0:endgran); + vf->pcmlengths[m*2+1]=endgran; }else{ - /* last page is not in the starting stream's serial number list, - so we have multiple links. Find where the stream that begins - our bisection ends. */ - - ogg_uint32_t *next_serialno_list=NULL; + uint32_t *next_serialno_list=NULL; int next_serialnos=0; vorbis_info vi; vorbis_comment vc; - int testserial = serialno+1; /* the below guards against garbage seperating the last and first pages of two links. */ while(searchedoffset){ + ret=_seek_helper(vf,bisect); + if(ret)return(ret); + } last=_get_next_page(vf,&og,-1); if(last==OV_EREAD)return(OV_EREAD); @@ -547,22 +557,28 @@ static int _bisect_forward_serialno(OggVorbis_File *vf, } /* Bisection point found */ + /* for the time being, fetch end PCM offset the simple way */ - searched = next; - while(testserial != serialno){ - testserial = serialno; - searched = _get_prev_page_serial(vf,searched,currentno_list,currentnos,&testserial,&searchgran); + { + int testserial = serialno+1; + vf->offset = next; + while(testserial != serialno){ + testserial = serialno; + vf->offset=_get_prev_page_serial(vf,currentno_list,currentnos,&testserial,&searchgran); + } } - ret=_seek_helper(vf,next); - if(ret)return(ret); + if(vf->offset!=next){ + ret=_seek_helper(vf,next); + if(ret)return(ret); + } ret=_fetch_headers(vf,&vi,&vc,&next_serialno_list,&next_serialnos,NULL); if(ret)return(ret); serialno = vf->os.serialno; dataoffset = vf->offset; - /* this will consume a page, however the next bisection always + /* this will consume a page, however the next bistection always starts with a raw seek */ pcmoffset = _initial_pcmoffset(vf,&vi); @@ -570,7 +586,8 @@ static int _bisect_forward_serialno(OggVorbis_File *vf, next_serialno_list,next_serialnos,m+1); if(ret)return(ret); - if(next_serialno_list)_ogg_free(next_serialno_list); + if(next_serialno_list) + free(next_serialno_list); vf->offsets[m+1]=next; vf->serialnos[m+1]=serialno; @@ -582,7 +599,6 @@ static int _bisect_forward_serialno(OggVorbis_File *vf, vf->pcmlengths[m*2+1]=searchgran; vf->pcmlengths[m*2+2]=pcmoffset; vf->pcmlengths[m*2+3]-=pcmoffset; - if(vf->pcmlengths[m*2+3]<0)vf->pcmlengths[m*2+3]=0; } return(0); @@ -606,7 +622,7 @@ static int _make_decode_ready(OggVorbis_File *vf){ } static int _open_seekable2(OggVorbis_File *vf){ - ogg_int64_t dataoffset=vf->dataoffsets[0],end,endgran=-1; + int64_t dataoffset=vf->dataoffsets[0],end,endgran=-1; int endserial=vf->os.serialno; int serialno=vf->os.serialno; @@ -614,7 +630,7 @@ static int _open_seekable2(OggVorbis_File *vf){ storage in vf */ /* fetch initial PCM offset */ - ogg_int64_t pcmoffset = _initial_pcmoffset(vf,vf->vi); + int64_t pcmoffset = _initial_pcmoffset(vf,vf->vi); /* we can seek, so set out learning all about this file */ if(vf->callbacks.seek_func && vf->callbacks.tell_func){ @@ -630,11 +646,11 @@ static int _open_seekable2(OggVorbis_File *vf){ /* Get the offset of the last page of the physical bitstream, or, if we're lucky the last vorbis page of this link as most OggVorbis files will contain a single logical bitstream */ - end=_get_prev_page_serial(vf,vf->end,vf->serialnos+2,vf->serialnos[1],&endserial,&endgran); + end=_get_prev_page_serial(vf,vf->serialnos+2,vf->serialnos[1],&endserial,&endgran); if(end<0)return(end); /* now determine bitstream structure recursively */ - if(_bisect_forward_serialno(vf,0,dataoffset,end,endgran,endserial, + if(_bisect_forward_serialno(vf,0,dataoffset,vf->offset,endgran,endserial, vf->serialnos+2,vf->serialnos[1],0)<0)return(OV_EREAD); vf->offsets[0]=0; @@ -642,7 +658,6 @@ static int _open_seekable2(OggVorbis_File *vf){ vf->dataoffsets[0]=dataoffset; vf->pcmlengths[0]=pcmoffset; vf->pcmlengths[1]-=pcmoffset; - if(vf->pcmlengths[1]<0)vf->pcmlengths[1]=0; return(ov_raw_seek(vf,dataoffset)); } @@ -687,7 +702,7 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, ogg_packet op; ogg_packet *op_ptr=(op_in?op_in:&op); int result=ogg_stream_packetout(&vf->os,op_ptr); - ogg_int64_t granulepos; + int64_t granulepos; op_in=NULL; if(result==-1)return(OV_HOLE); /* hole in the data. */ @@ -710,7 +725,7 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, if(oldsamples)return(OV_EFAULT); vorbis_synthesis_blockin(&vf->vd,&vf->vb); - vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL); + vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples; vf->bittrack+=op_ptr->bytes*8; } @@ -755,7 +770,7 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, } if(vf->ready_state>=OPENED){ - ogg_int64_t ret; + int64_t ret; while(1){ /* the loop is not strictly necessary, but there's no sense in @@ -819,7 +834,7 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, if(vf->ready_stateseekable){ - ogg_uint32_t serialno = ogg_page_serialno(&og); + uint32_t serialno = ogg_page_serialno(&og); /* match the serialno to bitstream section. We use this rather than offset positions to avoid problems near logical bitstream @@ -858,17 +873,10 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, } } -/* if, eg, 64 bit stdio is configured by default, this will build with - fseek64 */ -static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){ - if(f==NULL)return(-1); - return fseek(f,off,whence); -} - static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial, long ibytes, ov_callbacks callbacks){ int offsettest=((f && callbacks.seek_func)?callbacks.seek_func(f,0,SEEK_CUR):-1); - ogg_uint32_t *serialno_list=NULL; + uint32_t *serialno_list=NULL; int serialno_list_size=0; int ret; @@ -895,8 +903,8 @@ static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial, /* No seeking yet; Set up a 'single' (current) logical bitstream entry for partial open */ vf->links=1; - vf->vi=_ogg_calloc(vf->links,sizeof(*vf->vi)); - vf->vc=_ogg_calloc(vf->links,sizeof(*vf->vc)); + vf->vi=calloc(vf->links,sizeof(*vf->vi)); + vf->vc=calloc(vf->links,sizeof(*vf->vc)); ogg_stream_init(&vf->os,-1); /* fill in the serialno later */ /* Fetch all BOS pages, store the vorbis header and all seen serial @@ -908,19 +916,20 @@ static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial, /* serial number list for first link needs to be held somewhere for second stage of seekable stream open; this saves having to seek/reread first link's serialnumber data then. */ - vf->serialnos=_ogg_calloc(serialno_list_size+2,sizeof(*vf->serialnos)); + vf->serialnos=calloc(serialno_list_size+2,sizeof(*vf->serialnos)); vf->serialnos[0]=vf->current_serialno=vf->os.serialno; vf->serialnos[1]=serialno_list_size; memcpy(vf->serialnos+2,serialno_list,serialno_list_size*sizeof(*vf->serialnos)); - vf->offsets=_ogg_calloc(1,sizeof(*vf->offsets)); - vf->dataoffsets=_ogg_calloc(1,sizeof(*vf->dataoffsets)); + vf->offsets=calloc(1,sizeof(*vf->offsets)); + vf->dataoffsets=calloc(1,sizeof(*vf->dataoffsets)); vf->offsets[0]=0; vf->dataoffsets[0]=vf->offset; vf->ready_state=PARTOPEN; } - if(serialno_list)_ogg_free(serialno_list); + if(serialno_list) + free(serialno_list); return(ret); } @@ -954,21 +963,22 @@ int ov_clear(OggVorbis_File *vf){ vorbis_info_clear(vf->vi+i); vorbis_comment_clear(vf->vc+i); } - _ogg_free(vf->vi); - _ogg_free(vf->vc); + free(vf->vi); + free(vf->vc); } - if(vf->dataoffsets)_ogg_free(vf->dataoffsets); - if(vf->pcmlengths)_ogg_free(vf->pcmlengths); - if(vf->serialnos)_ogg_free(vf->serialnos); - if(vf->offsets)_ogg_free(vf->offsets); + if(vf->dataoffsets) + free(vf->dataoffsets); + if(vf->pcmlengths) + free(vf->pcmlengths); + if(vf->serialnos) + free(vf->serialnos); + if(vf->offsets) + free(vf->offsets); ogg_sync_clear(&vf->oy); if(vf->datasource && vf->callbacks.close_func) (vf->callbacks.close_func)(vf->datasource); memset(vf,0,sizeof(*vf)); } -#ifdef DEBUG_LEAKS - _VDBG_dump(); -#endif return(0); } @@ -987,55 +997,6 @@ int ov_open_callbacks(void *f,OggVorbis_File *vf, return _ov_open2(vf); } -int ov_open(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes){ - ov_callbacks callbacks = { - (size_t (*)(void *, size_t, size_t, void *)) fread, - (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap, - (int (*)(void *)) fclose, - (long (*)(void *)) ftell - }; - - return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks); -} - -int ov_fopen(const char *path,OggVorbis_File *vf){ - int ret; - FILE *f = fopen(path,"rb"); - if(!f) return -1; - - ret = ov_open(f,vf,NULL,0); - if(ret) fclose(f); - return ret; -} - - -/* Only partially open the vorbis file; test for Vorbisness, and load - the headers for the first chain. Do not seek (although test for - seekability). Use ov_test_open to finish opening the file, else - ov_clear to close/free it. Same return codes as open. */ - -int ov_test_callbacks(void *f,OggVorbis_File *vf, - const char *initial,long ibytes,ov_callbacks callbacks) -{ - return _ov_open1(f,vf,initial,ibytes,callbacks); -} - -int ov_test(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes){ - ov_callbacks callbacks = { - (size_t (*)(void *, size_t, size_t, void *)) fread, - (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap, - (int (*)(void *)) fclose, - (long (*)(void *)) ftell - }; - - return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks); -} - -int ov_test_open(OggVorbis_File *vf){ - if(vf->ready_state!=PARTOPEN)return(OV_EINVAL); - return _ov_open2(vf); -} - /* How many logical bitstreams in this physical bitstream? */ long ov_streams(OggVorbis_File *vf){ return vf->links; @@ -1060,7 +1021,7 @@ long ov_bitrate(OggVorbis_File *vf,int i){ if(i>=vf->links)return(OV_EINVAL); if(!vf->seekable && i!=0)return(ov_bitrate(vf,0)); if(i<0){ - ogg_int64_t bits=0; + int64_t bits=0; int i; for(i=0;ilinks;i++) bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8; @@ -1122,11 +1083,11 @@ long ov_serialnumber(OggVorbis_File *vf,int i){ OV_EINVAL if the stream is not seekable (we can't know the length) or if stream is only partially open */ -ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){ +int64_t ov_raw_total(OggVorbis_File *vf,int i){ if(vf->ready_stateseekable || i>=vf->links)return(OV_EINVAL); if(i<0){ - ogg_int64_t acc=0; + int64_t acc=0; int i; for(i=0;ilinks;i++) acc+=ov_raw_total(vf,i); @@ -1141,11 +1102,11 @@ ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){ OV_EINVAL if the stream is not seekable (we can't know the length) or only partially open */ -ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){ +int64_t ov_pcm_total(OggVorbis_File *vf,int i){ if(vf->ready_stateseekable || i>=vf->links)return(OV_EINVAL); if(i<0){ - ogg_int64_t acc=0; + int64_t acc=0; int i; for(i=0;ilinks;i++) acc+=ov_pcm_total(vf,i); @@ -1160,17 +1121,17 @@ ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){ OV_EINVAL if the stream is not seekable (we can't know the length) or only partially open */ -ogg_int64_t ov_time_total(OggVorbis_File *vf,int i){ +int64_t ov_time_total(OggVorbis_File *vf,int i){ if(vf->ready_stateseekable || i>=vf->links)return(OV_EINVAL); if(i<0){ - ogg_int64_t acc=0; + int64_t acc=0; int i; for(i=0;ilinks;i++) acc+=ov_time_total(vf,i); return(acc); }else{ - return(((ogg_int64_t)vf->pcmlengths[i*2+1])*1000/vf->vi[i].rate); + return(((int64_t)vf->pcmlengths[i*2+1])*1000/vf->vi[i].rate); } } @@ -1181,7 +1142,7 @@ ogg_int64_t ov_time_total(OggVorbis_File *vf,int i){ returns zero on success, nonzero on failure */ -int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){ +int ov_raw_seek(OggVorbis_File *vf,int64_t pos){ ogg_stream_state work_os; int ret; @@ -1232,7 +1193,7 @@ int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){ int thisblock=0; int lastflag=0; int firstflag=0; - ogg_int64_t pagepos=-1; + int64_t pagepos=-1; ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */ ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE @@ -1268,7 +1229,7 @@ int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){ if(op.granulepos!=-1){ int i,link=vf->current_link; - ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2]; + int64_t granulepos=op.granulepos-vf->pcmlengths[link*2]; if(granulepos<0)granulepos=0; for(i=0;iready_statelinks;link++) if(vf->serialnos[link]==serialno)break; @@ -1353,9 +1314,9 @@ int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){ /* rescales the number x from the range of [0,from] to [0,to] x is in the range [0,from] from, to are in the range [1, 1<<62-1] */ -ogg_int64_t rescale64(ogg_int64_t x, ogg_int64_t from, ogg_int64_t to){ - ogg_int64_t frac=0; - ogg_int64_t ret=0; +int64_t rescale64(int64_t x, int64_t from, int64_t to){ + int64_t frac=0; + int64_t ret=0; int i; if(x >= from) return to; if(x <= 0) return 0; @@ -1386,10 +1347,10 @@ ogg_int64_t rescale64(ogg_int64_t x, ogg_int64_t from, ogg_int64_t to){ Seek to the last [granule marked] page preceding the specified pos location, such that decoding past the returned point will quickly arrive at the requested position. */ -int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ +int ov_pcm_seek_page(OggVorbis_File *vf,int64_t pos){ int link=-1; - ogg_int64_t result=0; - ogg_int64_t total=ov_pcm_total(vf,-1); + int64_t result=0; + int64_t total=ov_pcm_total(vf,-1); if(vf->ready_stateseekable)return(OV_ENOSEEK); @@ -1402,43 +1363,24 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ if(pos>=total)break; } - /* Search within the logical bitstream for the page with the highest - pcm_pos preceding pos. If we're looking for a position on the - first page, bisection will halt without finding our position as - it's before the first explicit granulepos fencepost. That case is - handled separately below. - - There is a danger here; missing pages or incorrect frame number - information in the bitstream could make our task impossible. - Account for that (it would be an error condition) */ - - /* new search algorithm originally by HB (Nicholas Vinen) */ + /* search within the logical bitstream for the page with the highest + pcm_pos preceding (or equal to) pos. There is a danger here; + missing pages or incorrect frame number information in the + bitstream could make our task impossible. Account for that (it + would be an error condition) */ + /* new search algorithm by HB (Nicholas Vinen) */ { - ogg_int64_t end=vf->offsets[link+1]; - ogg_int64_t begin=vf->dataoffsets[link]; - ogg_int64_t begintime = vf->pcmlengths[link*2]; - ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime; - ogg_int64_t target=pos-total+begintime; - ogg_int64_t best=-1; - int got_page=0; + int64_t end=vf->offsets[link+1]; + int64_t begin=vf->offsets[link]; + int64_t begintime = vf->pcmlengths[link*2]; + int64_t endtime = vf->pcmlengths[link*2+1]+begintime; + int64_t target=pos-total+begintime; + int64_t best=begin; ogg_page og; - - /* if we have only one page, there will be no bisection. Grab the page here */ - if(begin==end){ - result=_seek_helper(vf,begin); - if(result) goto seek_error; - - result=_get_next_page(vf,&og,1); - if(result<0) goto seek_error; - - got_page=1; - } - - /* bisection loop */ while(beginoffset){ + result=_seek_helper(vf,bisect); + if(result) goto seek_error; + } - /* read loop within the bisection loop */ while(beginoffset); if(result==OV_EREAD) goto seek_error; if(result<0){ - /* there is no next page! */ if(bisect<=begin+1) - /* No bisection left to perform. We've either found the - best candidate already or failed. Exit loop. */ - end=begin; + end=begin; /* found it */ else{ - /* We tried to load a fraction of the last page; back up a - bit and try to get the whole last page */ if(bisect==0) goto seek_error; bisect-=CHUNKSIZE; - - /* don't repeat/loop on a read we've already performed */ if(bisect<=begin)bisect=begin+1; - - /* seek and continue bisection */ result=_seek_helper(vf,bisect); if(result) goto seek_error; } }else{ - ogg_int64_t granulepos; - got_page=1; + int64_t granulepos; - /* got a page. analyze it */ - /* only consider pages from primary vorbis stream */ if(ogg_page_serialno(&og)!=vf->serialnos[link]) continue; - /* only consider pages with the granulepos set */ granulepos=ogg_page_granulepos(&og); if(granulepos==-1)continue; if(granuleposoffset; /* raw offset of next page */ begintime=granulepos; - /* if we're before our target but within a short distance, - don't bisect; read forward */ if(target-begintime>44100)break; - - bisect=begin; /* *not* begin + 1 as above */ + bisect=begin; /* *not* begin + 1 */ }else{ - - /* This is one of our pages, but the granpos is - post-target; it is not a bisection return - candidate. (The only way we'd use it is if it's the - first page in the stream; we handle that case later - outside the bisection) */ - if(bisect<=begin+1){ - /* No bisection left to perform. We've either found the - best candidate already or failed. Exit loop. */ - end=begin; - }else{ - if(end==vf->offset){ - /* bisection read to the end; use the known page - boundary (result) to update bisection, back up a - little bit, and try again */ + if(bisect<=begin+1) + end=begin; /* found it */ + else{ + if(end==vf->offset){ /* we're pretty close - we'd be stuck in */ end=result; - bisect-=CHUNKSIZE; + bisect-=CHUNKSIZE; /* an endless loop otherwise. */ if(bisect<=begin)bisect=begin+1; result=_seek_helper(vf,bisect); if(result) goto seek_error; }else{ - /* Normal bisection */ end=bisect; endtime=granulepos; break; @@ -1535,46 +1448,9 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ } } - /* Out of bisection: did it 'fail?' */ - if(best == -1){ - - /* Check the 'looking for data in first page' special case; - bisection would 'fail' because our search target was before the - first PCM granule position fencepost. */ - - if(got_page && - begin == vf->dataoffsets[link] && - ogg_page_serialno(&og)==vf->serialnos[link]){ - - /* Yes, this is the beginning-of-stream case. We already have - our page, right at the beginning of PCM data. Set state - and return. */ - - vf->pcm_offset=total; - - if(link!=vf->current_link){ - /* Different link; dump entire decode machine */ - _decode_clear(vf); - - vf->current_link=link; - vf->current_serialno=vf->serialnos[link]; - vf->ready_state=STREAMSET; - - }else{ - vorbis_synthesis_restart(&vf->vd); - } - - ogg_stream_reset_serialno(&vf->os,vf->current_serialno); - ogg_stream_pagein(&vf->os,&og); - - }else - goto seek_error; - - }else{ - - /* Bisection found our page. seek to it, update pcm offset. Easier case than - raw_seek, don't keep packets preceding granulepos. */ - + /* found our page. seek to it, update pcm offset. Easier case than + raw_seek, don't keep packets preceding granulepos. */ + { ogg_page og; ogg_packet op; @@ -1604,23 +1480,23 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ while(1){ result=ogg_stream_packetpeek(&vf->os,&op); if(result==0){ - /* No packet returned; we exited the bisection with 'best' - pointing to a page with a granule position, so the packet - finishing this page ('best') originated on a preceding - page. Keep fetching previous pages until we get one with - a granulepos or without the 'continued' flag set. Then - just use raw_seek for simplicity. */ - /* Do not rewind past the beginning of link data; if we do, - it's either a bug or a broken stream */ - result=best; - while(result>vf->dataoffsets[link]){ - result=_get_prev_page(vf,result,&og); + /* !!! the packet finishing this page originated on a + preceding page. Keep fetching previous pages until we + get one with a granulepos or without the 'continued' flag + set. Then just use raw_seek for simplicity. */ + + result=_seek_helper(vf,best); + if(result<0) goto seek_error; + + while(1){ + result=_get_prev_page(vf,&og); if(result<0) goto seek_error; if(ogg_page_serialno(&og)==vf->current_serialno && (ogg_page_granulepos(&og)>-1 || !ogg_page_continued(&og))){ return ov_raw_seek(vf,result); } + vf->offset=result; } } if(result<0){ @@ -1657,7 +1533,7 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ /* seek to a sample offset relative to the decompressed pcm stream returns zero on success, nonzero on failure */ -int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ +int ov_pcm_seek(OggVorbis_File *vf,int64_t pos){ int thisblock,lastblock=0; int ret=ov_pcm_seek_page(vf,pos); if(ret<0)return(ret); @@ -1711,7 +1587,7 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ if(ogg_page_bos(&og))_decode_clear(vf); if(vf->ready_statelinks;link++) @@ -1736,7 +1612,7 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ /* discard samples until we reach the desired position. Crossing a logical bitstream boundary with abandon is OK. */ while(vf->pcm_offsetpcm_offset; + int64_t target=pos-vf->pcm_offset; long samples=vorbis_synthesis_pcmout(&vf->vd,NULL); if(samples>target)samples=target; @@ -1752,12 +1628,12 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ /* seek to a playback time relative to the decompressed pcm stream returns zero on success, nonzero on failure */ -int ov_time_seek(OggVorbis_File *vf,ogg_int64_t milliseconds){ +int ov_time_seek(OggVorbis_File *vf,int64_t milliseconds){ /* translate time to PCM position and call ov_pcm_seek */ int link=-1; - ogg_int64_t pcm_total=0; - ogg_int64_t time_total=0; + int64_t pcm_total=0; + int64_t time_total=0; if(vf->ready_stateseekable)return(OV_ENOSEEK); @@ -1765,7 +1641,7 @@ int ov_time_seek(OggVorbis_File *vf,ogg_int64_t milliseconds){ /* which bitstream section does this time offset occur in? */ for(link=0;linklinks;link++){ - ogg_int64_t addsec = ov_time_total(vf,link); + int64_t addsec = ov_time_total(vf,link); if(millisecondspcmlengths[link*2+1]; @@ -1775,19 +1651,19 @@ int ov_time_seek(OggVorbis_File *vf,ogg_int64_t milliseconds){ /* enough information to convert time offset to pcm offset */ { - ogg_int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000; + int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000; return(ov_pcm_seek(vf,target)); } } /* page-granularity version of ov_time_seek returns zero on success, nonzero on failure */ -int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t milliseconds){ +int ov_time_seek_page(OggVorbis_File *vf,int64_t milliseconds){ /* translate time to PCM position and call ov_pcm_seek */ int link=-1; - ogg_int64_t pcm_total=0; - ogg_int64_t time_total=0; + int64_t pcm_total=0; + int64_t time_total=0; if(vf->ready_stateseekable)return(OV_ENOSEEK); @@ -1795,7 +1671,7 @@ int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t milliseconds){ /* which bitstream section does this time offset occur in? */ for(link=0;linklinks;link++){ - ogg_int64_t addsec = ov_time_total(vf,link); + int64_t addsec = ov_time_total(vf,link); if(millisecondspcmlengths[link*2+1]; @@ -1805,29 +1681,29 @@ int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t milliseconds){ /* enough information to convert time offset to pcm offset */ { - ogg_int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000; + int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000; return(ov_pcm_seek_page(vf,target)); } } /* tell the current stream offset cursor. Note that seek followed by tell will likely not give the set offset due to caching */ -ogg_int64_t ov_raw_tell(OggVorbis_File *vf){ +int64_t ov_raw_tell(OggVorbis_File *vf){ if(vf->ready_stateoffset); } /* return PCM offset (sample) of next PCM sample to be read */ -ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){ +int64_t ov_pcm_tell(OggVorbis_File *vf){ if(vf->ready_statepcm_offset); } /* return time offset (milliseconds) of next PCM sample to be read */ -ogg_int64_t ov_time_tell(OggVorbis_File *vf){ +int64_t ov_time_tell(OggVorbis_File *vf){ int link=0; - ogg_int64_t pcm_total=0; - ogg_int64_t time_total=0; + int64_t pcm_total=0; + int64_t time_total=0; if(vf->ready_stateseekable){ @@ -1918,7 +1794,7 @@ vorbis_comment *ov_comment(OggVorbis_File *vf,int link){ long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){ int i,j; - ogg_int32_t **pcm; + int32_t **pcm; long samples; if(vf->ready_state>9); diff --git a/mednafen/tremor/vorbisfile.d b/mednafen/tremor/vorbisfile.d new file mode 100644 index 0000000..39172ef --- /dev/null +++ b/mednafen/tremor/vorbisfile.d @@ -0,0 +1,6 @@ +mednafen/tremor/vorbisfile.o: mednafen/tremor/vorbisfile.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/ivorbiscodec.h mednafen/tremor/ogg.h \ + mednafen/tremor/ivorbisfile.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/misc.h \ + mednafen/tremor/asm_arm.h diff --git a/mednafen/tremor/window.c b/mednafen/tremor/window.c index 006a1ee..f392c53 100644 --- a/mednafen/tremor/window.c +++ b/mednafen/tremor/window.c @@ -52,7 +52,7 @@ const void *_vorbis_window(int type, int left){ } } -void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2], +void _vorbis_apply_window(int32_t *d,const void *window_p[2], long *blocksizes, int lW,int W,int nW){ diff --git a/mednafen/tremor/window.d b/mednafen/tremor/window.d new file mode 100644 index 0000000..34cafca --- /dev/null +++ b/mednafen/tremor/window.d @@ -0,0 +1,6 @@ +mednafen/tremor/window.o: mednafen/tremor/window.c \ + lightning-lightrec-include/debug.h libretro-common/include/libretro.h \ + mednafen/tremor/misc.h mednafen/tremor/ivorbiscodec.h \ + mednafen/tremor/ogg.h mednafen/tremor/os.h \ + libretro-common/include/retro_inline.h mednafen/tremor/asm_arm.h \ + mednafen/tremor/window.h mednafen/tremor/window_lookup.h diff --git a/mednafen/tremor/window.h b/mednafen/tremor/window.h index 27647fe..02acd93 100644 --- a/mednafen/tremor/window.h +++ b/mednafen/tremor/window.h @@ -19,7 +19,7 @@ #define _V_WINDOW_ extern const void *_vorbis_window(int type,int left); -extern void _vorbis_apply_window(ogg_int32_t *d,const void *window[2], +extern void _vorbis_apply_window(int32_t *d,const void *window[2], long *blocksizes, int lW,int W,int nW); diff --git a/mednafen/tremor/window_lookup.h b/mednafen/tremor/window_lookup.h index 84dc590..e154d00 100644 --- a/mednafen/tremor/window_lookup.h +++ b/mednafen/tremor/window_lookup.h @@ -15,10 +15,7 @@ ********************************************************************/ - -#include "os_types.h" - -static const LOOKUP_T vwin64[32] = { +static LOOKUP_T vwin64[32] = { X(0x001f0003), X(0x01168c98), X(0x030333c8), X(0x05dfe3a4), X(0x09a49562), X(0x0e45df18), X(0x13b47ef2), X(0x19dcf676), X(0x20a74d83), X(0x27f7137c), X(0x2fabb05a), X(0x37a1105a), @@ -29,7 +26,7 @@ static const LOOKUP_T vwin64[32] = { X(0x7fdd78a5), X(0x7ff6ec6d), X(0x7ffed0e9), X(0x7ffffc3f), }; -static const LOOKUP_T vwin128[64] = { +static LOOKUP_T vwin128[64] = { X(0x0007c04d), X(0x0045bb89), X(0x00c18b87), X(0x017ae294), X(0x02714a4e), X(0x03a4217a), X(0x05129952), X(0x06bbb24f), X(0x089e38a1), X(0x0ab8c073), X(0x0d09a228), X(0x0f8ef6bd), @@ -48,7 +45,7 @@ static const LOOKUP_T vwin128[64] = { X(0x7ffdcf39), X(0x7fff6dac), X(0x7fffed01), X(0x7fffffc4), }; -static const LOOKUP_T vwin256[128] = { +static LOOKUP_T vwin256[128] = { X(0x0001f018), X(0x00117066), X(0x00306e9e), X(0x005ee5f1), X(0x009ccf26), X(0x00ea208b), X(0x0146cdea), X(0x01b2c87f), X(0x022dfedf), X(0x02b85ced), X(0x0351cbbd), X(0x03fa317f), @@ -83,7 +80,7 @@ static const LOOKUP_T vwin256[128] = { X(0x7fffdcd2), X(0x7ffff6d6), X(0x7ffffed0), X(0x7ffffffc), }; -static const LOOKUP_T vwin512[256] = { +static LOOKUP_T vwin512[256] = { X(0x00007c06), X(0x00045c32), X(0x000c1c62), X(0x0017bc4c), X(0x00273b7a), X(0x003a9955), X(0x0051d51c), X(0x006cede7), X(0x008be2a9), X(0x00aeb22a), X(0x00d55b0d), X(0x00ffdbcc), @@ -150,7 +147,7 @@ static const LOOKUP_T vwin512[256] = { X(0x7ffffdcd), X(0x7fffff6d), X(0x7fffffed), X(0x7fffffff), }; -static const LOOKUP_T vwin1024[512] = { +static LOOKUP_T vwin1024[512] = { X(0x00001f02), X(0x0001170e), X(0x00030724), X(0x0005ef40), X(0x0009cf59), X(0x000ea767), X(0x0014775e), X(0x001b3f2e), X(0x0022fec8), X(0x002bb618), X(0x00356508), X(0x00400b81), @@ -281,7 +278,7 @@ static const LOOKUP_T vwin1024[512] = { X(0x7fffffdd), X(0x7ffffff7), X(0x7fffffff), X(0x7fffffff), }; -static const LOOKUP_T vwin2048[1024] = { +static LOOKUP_T vwin2048[1024] = { X(0x000007c0), X(0x000045c4), X(0x0000c1ca), X(0x00017bd3), X(0x000273de), X(0x0003a9eb), X(0x00051df9), X(0x0006d007), X(0x0008c014), X(0x000aee1e), X(0x000d5a25), X(0x00100428), @@ -540,7 +537,7 @@ static const LOOKUP_T vwin2048[1024] = { X(0x7ffffffe), X(0x7fffffff), X(0x7fffffff), X(0x7fffffff), }; -static const LOOKUP_T vwin4096[2048] = { +static LOOKUP_T vwin4096[2048] = { X(0x000001f0), X(0x00001171), X(0x00003072), X(0x00005ef5), X(0x00009cf8), X(0x0000ea7c), X(0x00014780), X(0x0001b405), X(0x0002300b), X(0x0002bb91), X(0x00035698), X(0x0004011e), @@ -1055,7 +1052,7 @@ static const LOOKUP_T vwin4096[2048] = { X(0x7fffffff), X(0x7fffffff), X(0x7fffffff), X(0x7fffffff), }; -static const LOOKUP_T vwin8192[4096] = { +static LOOKUP_T vwin8192[4096] = { X(0x0000007c), X(0x0000045c), X(0x00000c1d), X(0x000017bd), X(0x0000273e), X(0x00003a9f), X(0x000051e0), X(0x00006d02), X(0x00008c03), X(0x0000aee5), X(0x0000d5a7), X(0x00010049),