X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Fvorbisfile.c;h=6c2f8207b856c00c82f2bc39045c3d3ac1103f92;hb=5aa00ab1ca4d2dbb49a8c7ed85325275bd47a092;hp=b7fef317834cf444eb81ef9fcd5614a8eaeac690;hpb=cb367abf983c0523ac8f229795d54c808eb355ab;p=platform%2Fupstream%2Flibvorbis.git diff --git a/lib/vorbisfile.c b/lib/vorbisfile.c index b7fef31..6c2f820 100644 --- a/lib/vorbisfile.c +++ b/lib/vorbisfile.c @@ -12,7 +12,7 @@ ******************************************************************** function: stdio-based convenience library for opening/seeking/decoding - last mod: $Id: vorbisfile.c,v 1.21 2000/04/23 15:34:12 msmith Exp $ + last mod: $Id: vorbisfile.c,v 1.22 2000/05/01 05:48:26 jon Exp $ ********************************************************************/ @@ -20,6 +20,8 @@ #include #include #include +#include + #include "vorbis/codec.h" #include "vorbis/vorbisfile.h" @@ -368,8 +370,8 @@ static int _open_seekable(OggVorbis_File *vf){ static int _open_nonseekable(OggVorbis_File *vf){ /* we cannot seek. Set up a 'single' (current) logical bitstream entry */ vf->links=1; - vf->vi=malloc(sizeof(vorbis_info)); - vf->vc=malloc(sizeof(vorbis_info)); + vf->vi=calloc(vf->links,sizeof(vorbis_info)); + vf->vc=calloc(vf->links,sizeof(vorbis_info)); /* Try to fetch the headers, maintaining all the storage */ if(_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno)==-1)return(-1); @@ -966,6 +968,15 @@ vorbis_comment *ov_comment(OggVorbis_File *vf,int link){ } } +int host_is_big_endian() { + short pattern = 0xbabe; + unsigned char *bytewise = (unsigned char *)&pattern; + if (bytewise[0] == 0xba) return 1; + + assert(bytewise[0] == 0xbe); + return 0; +} + /* up to this point, everything could more or less hide the multiple logical bitstream nature of chaining from the toplevel application if the toplevel application didn't particularly care. However, at @@ -1000,6 +1011,7 @@ vorbis_comment *ov_comment(OggVorbis_File *vf,int link){ long ov_read(OggVorbis_File *vf,char *buffer,int length, int bigendianp,int word,int sgned,int *bitstream){ int i,j; + int host_endian = host_is_big_endian(); while(1){ if(vf->decode_ready){ @@ -1027,7 +1039,37 @@ long ov_read(OggVorbis_File *vf,char *buffer,int length, }else{ int off=(sgned?0:32768); - if(bigendianp){ + if(host_endian==bigendianp){ + if(sgned){ + short *dest; + for(i=0;i32767)val=32767; + else if(val<-32768)val=-32768; + *dest=val; + dest+=channels; + } + } + buffer=(char *)dest; + }else{ + short *dest; + for(i=0;i32767)val=32767; + else if(val<-32768)val=-32768; + *dest=val+off; + dest+=channels; + } + } + buffer=(char *)dest; + } + }else if(bigendianp){ for(j=0;j