Slim down tremor

This commit is contained in:
libretroadmin 2022-07-18 23:29:23 +02:00
parent 9b08a696cc
commit 4232a75be0
7 changed files with 61 additions and 225 deletions

View File

@ -241,9 +241,10 @@ void vorbis_dsp_clear(vorbis_dsp_state *v){
if(v->pcm)
{
for(i=0;i<vi->channels;i++)
if(v->pcm[i])
free(v->pcm[i]);
if(vi)
for(i=0;i<vi->channels;i++)
if(v->pcm[i])
free(v->pcm[i]);
free(v->pcm);
if(v->pcmret)
free(v->pcmret);

View File

@ -437,5 +437,3 @@ vorbis_func_floor floor0_exportbundle={
&floor0_unpack,&floor0_look,&floor0_free_info,
&floor0_free_look,&floor0_inverse1,&floor0_inverse2
};

View File

@ -41,18 +41,6 @@ void vorbis_comment_init(vorbis_comment *vc){
memset(vc,0,sizeof(*vc));
}
/* This is more or less the same as strncasecmp - but that doesn't exist
* everywhere, and this is a fairly trivial function, so we include it */
static int tagcompare(const char *s1, const char *s2, int n){
int c=0;
while(c < n){
if(toupper(s1[c]) != toupper(s2[c]))
return !0;
c++;
}
return 0;
}
void vorbis_comment_clear(vorbis_comment *vc){
if(vc){
long i;

View File

@ -88,21 +88,12 @@ extern int ov_clear(OggVorbis_File *vf);
extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
const char *initial, long ibytes, ov_callbacks callbacks);
extern long ov_bitrate(OggVorbis_File *vf,int i);
extern long ov_serialnumber(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,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 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);

View File

@ -180,7 +180,8 @@ static INLINE int32_t CLIP_TO_15(int32_t x) {
static INLINE int32_t VFLOAT_MULT(int32_t a,int32_t ap,
int32_t b,int32_t bp,
int32_t *p){
if(a && b){
if(a && b)
{
#ifndef _LOW_ACCURACY_
*p=ap+bp+32;
return MULT32(a,b);
@ -188,8 +189,8 @@ static INLINE int32_t VFLOAT_MULT(int32_t a,int32_t ap,
*p=ap+bp+31;
return (a>>15)*(b>>16);
#endif
}else
return 0;
}
return 0;
}
int _ilog(unsigned int);

View File

@ -165,7 +165,8 @@ long _book_maptype1_quantvals(const static_codebook *b){
int bits=_ilog(b->entries);
int vals=b->entries>>((bits-1)*(b->dim-1)/b->dim);
while(1){
for(;;)
{
long acc=1;
long acc1=1;
int i;
@ -173,14 +174,14 @@ long _book_maptype1_quantvals(const static_codebook *b){
acc*=vals;
acc1*=vals+1;
}
if(acc<=b->entries && acc1>b->entries){
if(acc<=b->entries && acc1>b->entries)
return(vals);
}else{
if(acc>b->entries){
else
{
if(acc>b->entries)
vals--;
}else{
else
vals++;
}
}
}
}

View File

@ -27,10 +27,6 @@
#include "os.h"
#include "misc.h"
#define VSEEK_END 2
#define VSEEK_CUR 1
#define VSEEK_SET 0
/* A 'chained bitstream' is a Vorbis bitstream that contains more than
one logical bitstream arranged end to end (the only form of Ogg
multiplexing allowed in a Vorbis bitstream; grouping [parallel
@ -89,7 +85,7 @@ static long _get_data(OggVorbis_File *vf){
static int _seek_helper(OggVorbis_File *vf,int64_t offset){
if(vf->datasource){
if(!(vf->callbacks.seek_func)||
(vf->callbacks.seek_func)(vf->datasource, offset, VSEEK_SET) == -1)
(vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET) == -1)
return OV_EREAD;
vf->offset=offset;
ogg_sync_reset(&vf->oy);
@ -116,7 +112,8 @@ static int _seek_helper(OggVorbis_File *vf,int64_t offset){
static int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
int64_t boundary){
if(boundary>0)boundary+=vf->offset;
while(1){
for(;;)
{
long more;
if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
@ -366,8 +363,8 @@ static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
goto bail_header;
}
while(1){
for(;;)
{
i=0;
while(i<2){ /* get a page loop */
@ -434,7 +431,8 @@ static int64_t _initial_pcmoffset(OggVorbis_File *vf, vorbis_info *vi){
int result;
int serialno = vf->os.serialno;
while(1){
for(;;)
{
ogg_packet op;
if(_get_next_page(vf,&og,-1)<0)
break; /* should not be possible unless the file is truncated/mangled */
@ -638,7 +636,7 @@ static int _open_seekable2(OggVorbis_File *vf){
/* we can seek, so set out learning all about this file */
if(vf->callbacks.seek_func && vf->callbacks.tell_func){
(vf->callbacks.seek_func)(vf->datasource,0,VSEEK_END);
(vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
}else{
vf->offset=vf->end=-1;
@ -692,8 +690,8 @@ static int _fetch_and_process_packet(OggVorbis_File *vf,
/* handle one packet. Try to fetch it from current stream state */
/* extract packets from page */
while(1){
for(;;)
{
if(vf->ready_state==STREAMSET){
int ret=_make_decode_ready(vf);
if(ret<0)return ret;
@ -702,9 +700,10 @@ static int _fetch_and_process_packet(OggVorbis_File *vf,
/* process a packet if we can. If the machine isn't loaded,
neither is a page */
if(vf->ready_state==INITSET){
while(1) {
ogg_packet op;
ogg_packet *op_ptr=(op_in?op_in:&op);
for(;;)
{
ogg_packet op;
ogg_packet *op_ptr=(op_in?op_in:&op);
int result=ogg_stream_packetout(&vf->os,op_ptr);
int64_t granulepos;
@ -776,7 +775,7 @@ static int _fetch_and_process_packet(OggVorbis_File *vf,
if(vf->ready_state>=OPENED){
int64_t ret;
while(1){
for(;;){
/* the loop is not strictly necessary, but there's no sense in
doing the extra checks of the larger loop for the common
case in a multiplexed bistream where the page is simply
@ -879,7 +878,7 @@ static int _fetch_and_process_packet(OggVorbis_File *vf,
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,VSEEK_CUR):-1);
int offsettest=((f && callbacks.seek_func)?callbacks.seek_func(f,0,SEEK_CUR):-1);
uint32_t *serialno_list=NULL;
int serialno_list_size=0;
int ret;
@ -937,23 +936,6 @@ static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial,
return(ret);
}
static int _ov_open2(OggVorbis_File *vf){
if(vf->ready_state != PARTOPEN) return OV_EINVAL;
vf->ready_state=OPENED;
if(vf->seekable){
int ret=_open_seekable2(vf);
if(ret){
vf->datasource=NULL;
ov_clear(vf);
}
return(ret);
}else
vf->ready_state=STREAMSET;
return 0;
}
/* clear out the OggVorbis_File struct */
int ov_clear(OggVorbis_File *vf){
if(vf){
@ -998,82 +980,23 @@ int ov_open_callbacks(void *f,OggVorbis_File *vf,
const char *initial,long ibytes,ov_callbacks callbacks){
int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
if(ret)return ret;
return _ov_open2(vf);
}
/* returns the bitrate for a given logical bitstream or the entire
physical bitstream. If the file is open for random access, it will
find the *actual* average bitrate. If the file is streaming, it
returns the nominal bitrate (if set) else the average of the
upper/lower bounds (if set) else -1 (unset).
If you want the actual bitrate field settings, get them from the
vorbis_info structs */
long ov_bitrate(OggVorbis_File *vf,int i){
if(vf->ready_state<OPENED)return(OV_EINVAL);
if(i>=vf->links)return(OV_EINVAL);
if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
if(i<0){
int64_t bits=0;
int i;
for(i=0;i<vf->links;i++)
bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
/* This once read: return(rint(bits/ov_time_total(vf,-1)));
* gcc 3.x on x86 miscompiled this at optimisation level 2 and above,
* so this is slightly transformed to make it work.
*/
return(bits*1000/ov_time_total(vf,-1));
}else{
if(vf->seekable){
/* return the actual bitrate */
return((vf->offsets[i+1]-vf->dataoffsets[i])*8000/ov_time_total(vf,i));
}else{
/* return nominal if set */
if(vf->vi[i].bitrate_nominal>0){
return vf->vi[i].bitrate_nominal;
}else{
if(vf->vi[i].bitrate_upper>0){
if(vf->vi[i].bitrate_lower>0){
return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
}else{
return vf->vi[i].bitrate_upper;
}
}
return(OV_FALSE);
}
if(vf->ready_state != PARTOPEN)
return OV_EINVAL;
vf->ready_state=OPENED;
if(vf->seekable)
{
int ret=_open_seekable2(vf);
if(ret)
{
vf->datasource=NULL;
ov_clear(vf);
}
return(ret);
}
}
else
vf->ready_state=STREAMSET;
/* Guess */
long ov_serialnumber(OggVorbis_File *vf,int i){
if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
if(i<0){
return(vf->current_serialno);
}else{
return(vf->serialnos[i]);
}
}
/* returns: total raw (compressed) length of content if i==-1
raw (compressed) length of that logical bitstream for i==0 to n
OV_EINVAL if the stream is not seekable (we can't know the length)
or if stream is only partially open
*/
int64_t ov_raw_total(OggVorbis_File *vf,int i){
if(vf->ready_state<OPENED)return(OV_EINVAL);
if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
if(i<0){
int64_t acc=0;
int i;
for(i=0;i<vf->links;i++)
acc+=ov_raw_total(vf,i);
return(acc);
}else{
return(vf->offsets[i+1]-vf->offsets[i]);
}
return 0;
}
/* returns: total PCM length (samples) of content if i==-1 PCM length
@ -1109,9 +1032,8 @@ int64_t ov_time_total(OggVorbis_File *vf,int i){
for(i=0;i<vf->links;i++)
acc+=ov_time_total(vf,i);
return(acc);
}else{
return(((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);
}
/* seek to an offset relative to the *compressed* data. This also
@ -1158,7 +1080,7 @@ int ov_raw_seek(OggVorbis_File *vf,int64_t pos){
the shared vf->os stream state. We use the local state to
scan, and the shared state as a buffer for later decode.
Unfortuantely, on the last page we still advance to last packet
Unfortunately, on the last page we still advance to last packet
because the granulepos on the last page is not necessarily on a
packet boundary, and we need to make sure the granpos is
correct.
@ -1179,7 +1101,7 @@ int ov_raw_seek(OggVorbis_File *vf,int64_t pos){
return from not necessarily
starting from the beginning */
while(1){
for(;;){
if(vf->ready_state>=STREAMSET){
/* snarf/scan a packet if we can */
int result=ogg_stream_packetout(&work_os,&op);
@ -1293,7 +1215,7 @@ int ov_raw_seek(OggVorbis_File *vf,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] */
static int64_t rescale64(int64_t x, int64_t from, int64_t to){
int64_t rescale64(int64_t x, int64_t from, int64_t to){
int64_t frac=0;
int64_t ret=0;
int i;
@ -1456,7 +1378,7 @@ int ov_pcm_seek_page(OggVorbis_File *vf,int64_t pos){
ogg_stream_pagein(&vf->os,&og);
/* pull out all but last packet; the one with granulepos */
while(1){
for(;;){
result=ogg_stream_packetpeek(&vf->os,&op);
if(result==0){
/* !!! the packet finishing this page originated on a
@ -1467,14 +1389,13 @@ int ov_pcm_seek_page(OggVorbis_File *vf,int64_t pos){
result=_seek_helper(vf,best);
if(result<0) goto seek_error;
while(1){
for(;;){
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))){
!ogg_page_continued(&og)))
return ov_raw_seek(vf,result);
}
vf->offset=result;
}
}
@ -1521,7 +1442,7 @@ int ov_pcm_seek(OggVorbis_File *vf,int64_t pos){
/* discard leading packets we don't need for the lapping of the
position we want; don't decode them */
while(1){
for(;;){
ogg_packet op;
ogg_page og;
@ -1605,71 +1526,6 @@ int ov_pcm_seek(OggVorbis_File *vf,int64_t pos){
return 0;
}
/* 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,int64_t milliseconds){
/* translate time to PCM position and call ov_pcm_seek */
int link=-1;
int64_t pcm_total=0;
int64_t time_total=0;
if(vf->ready_state<OPENED)return(OV_EINVAL);
if(!vf->seekable)return(OV_ENOSEEK);
if(milliseconds<0)return(OV_EINVAL);
/* which bitstream section does this time offset occur in? */
for(link=0;link<vf->links;link++){
int64_t addsec = ov_time_total(vf,link);
if(milliseconds<time_total+addsec)break;
time_total+=addsec;
pcm_total+=vf->pcmlengths[link*2+1];
}
if(link==vf->links)return(OV_EINVAL);
/* enough information to convert time offset to pcm offset */
{
int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000;
return(ov_pcm_seek(vf,target));
}
}
/* tell the current stream offset cursor. Note that seek followed by
tell will likely not give the set offset due to caching */
int64_t ov_raw_tell(OggVorbis_File *vf){
if(vf->ready_state<OPENED)return(OV_EINVAL);
return(vf->offset);
}
/* return PCM offset (sample) of next PCM sample to be read */
int64_t ov_pcm_tell(OggVorbis_File *vf){
if(vf->ready_state<OPENED)return(OV_EINVAL);
return(vf->pcm_offset);
}
/* return time offset (milliseconds) of next PCM sample to be read */
int64_t ov_time_tell(OggVorbis_File *vf){
int link=0;
int64_t pcm_total=0;
int64_t time_total=0;
if(vf->ready_state<OPENED)return(OV_EINVAL);
if(vf->seekable){
pcm_total=ov_pcm_total(vf,-1);
time_total=ov_time_total(vf,-1);
/* which bitstream section does this time offset occur in? */
for(link=vf->links-1;link>=0;link--){
pcm_total-=vf->pcmlengths[link*2+1];
time_total-=ov_time_total(vf,link);
if(vf->pcm_offset>=pcm_total)break;
}
}
return(time_total+(1000*vf->pcm_offset-pcm_total)/vf->vi[link].rate);
}
/* link: -1) return the vorbis_info struct for the bitstream section
currently being decoded
0-n) to request information for a specific bitstream section
@ -1722,7 +1578,8 @@ vorbis_info *ov_info(OggVorbis_File *vf,int link){
*section) set to the logical bitstream number */
long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){
long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream)
{
int i,j;
int32_t **pcm;
@ -1730,7 +1587,8 @@ long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){
if(vf->ready_state<OPENED)return(OV_EINVAL);
while(1){
for(;;)
{
if(vf->ready_state==INITSET){
samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
if(samples)break;
@ -1744,11 +1602,10 @@ long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){
if(ret<=0)
return(ret);
}
}
if(samples>0){
if(samples>0)
{
/* yay! proceed to pack data into the byte buffer */
long channels=ov_info(vf,-1)->channels;
@ -1767,9 +1624,8 @@ long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){
vorbis_synthesis_read(&vf->vd,samples);
vf->pcm_offset+=samples;
if(bitstream)*bitstream=vf->current_link;
if(bitstream) *bitstream=vf->current_link;
return(samples*2*channels);
}else{
return(samples);
}
return(samples);
}