24 #include "../vorbis/codec.h"
25 #include "../vorbis/vorbisfile.h"
61 #define CHUNKSIZE 8500
69 if(bytes==0 && errno)
return(-1);
102 if(boundary>0)boundary+=vf->
offset;
117 long ret=_get_data(vf);
148 _seek_helper(vf,begin);
150 ret=_get_next_page(vf,og,end-vf->
offset);
161 _seek_helper(vf,offset);
187 while(searched<endsearched){
193 bisect=(searched+endsearched)/2;
196 _seek_helper(vf,bisect);
197 ret=_get_next_page(vf,&og,-1);
207 _seek_helper(vf,next);
208 ret=_get_next_page(vf,&og,-1);
211 if(searched>=end || ret<0){
217 ret=_bisect_forward_serialno(vf,next,vf->
offset,
268 if(_get_next_page(vf,og_ptr,
CHUNKSIZE)<0){
302 for(i=0;i<vf->
links;i++){
306 _seek_helper(vf,dataoffset);
312 _seek_helper(vf,vf->
offsets[i]);
332 ret=_get_next_page(vf,&og,-1);
347 accumulated+=(lastblock+thisblock)>>2;
361 if(accumulated<0)accumulated=0;
370 _seek_helper(vf,end);
373 ret=_get_prev_page(vf,&og);
420 end=_get_prev_page(vf,&og);
421 if(end<0)
return(end);
428 if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)
return(
OV_EREAD);
433 if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))
return(
OV_EREAD);
438 _prefetch_all_headers(vf,dataoffset);
505 if(granulepos!=-1 && !op_ptr->
e_o_s){
524 if(granulepos<0)granulepos=0;
547 if((ret=_get_next_page(vf,&og,-1))<0){
594 for(link=0;link<vf->
links;link++)
618 int ret=_make_decode_ready(vf);
628 static int _fseek64_wrap(FILE *
f,
ogg_int64_t off,
int whence){
629 if(f==
NULL)
return(-1);
630 return fseek(f,off,whence);
638 memset(vf,0,
sizeof(*vf));
651 memcpy(buffer,initial,ibytes);
678 int ret=_open_seekable2(vf);
700 for(i=0;i<vf->
links;i++){
713 memset(vf,0,
sizeof(*vf));
731 int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
733 return _ov_open2(vf);
738 (size_t (*)(
void *, size_t, size_t,
void *))
fread,
740 (
int (*)(
void *)) fclose,
741 (long (*)(
void *)) ftell
761 for(i=0;i<vf->
links;i++){
783 return _ov_open1(f,vf,initial,ibytes,callbacks);
788 (size_t (*)(
void *, size_t, size_t,
void *))
fread,
790 (
int (*)(
void *)) fclose,
791 (long (*)(
void *)) ftell
799 return _ov_open2(vf);
829 for(i=0;i<vf->
links;i++)
896 for(i=0;i<vf->
links;i++)
915 for(i=0;i<vf->
links;i++)
934 for(i=0;i<vf->
links;i++)
967 _seek_helper(vf,pos);
1014 if(lastblock)accblock+=(lastblock+thisblock)>>2;
1020 if(granulepos<0)granulepos=0;
1027 lastblock=thisblock;
1035 if(_get_next_page(vf,&og,-1)<0){
1056 for(link=0;link<vf->
links;link++)
1058 if(link==vf->
links)
goto seek_error;
1102 if(pos<0 || pos>total)
return(
OV_EINVAL);
1105 for(link=vf->
links-1;link>=0;link--){
1107 if(pos>=total)
break;
1134 (target-begintime)*(end-begin)/(endtime-begintime) -
CHUNKSIZE;
1139 _seek_helper(vf,bisect);
1142 result=_get_next_page(vf,&og,end-vf->
offset);
1143 if(result==
OV_EREAD)
goto seek_error;
1148 if(bisect==0)
goto seek_error;
1150 if(bisect<=begin)bisect=begin+1;
1151 _seek_helper(vf,bisect);
1155 if(granulepos==-1)
continue;
1156 if(granulepos<target){
1159 begintime=granulepos;
1161 if(target-begintime>44100)
break;
1170 if(bisect<=begin)bisect=begin+1;
1171 _seek_helper(vf,bisect);
1190 _seek_helper(vf,best);
1193 if(_get_next_page(vf,&og,-1)<0)
return(
OV_EOF);
1219 _seek_helper(vf,best);
1222 result=_get_prev_page(vf,&og);
1223 if(result<0)
goto seek_error;
1266 int thisblock,lastblock=0;
1268 if(ret<0)
return(ret);
1269 if((ret=_make_decode_ready(vf)))
return ret;
1285 if(lastblock)vf->
pcm_offset+=(lastblock+thisblock)>>2;
1309 lastblock=thisblock;
1312 if(ret<0 && ret!=
OV_HOLE)
break;
1315 if(_get_next_page(vf,&og,-1)<0)
break;
1322 for(link=0;link<vf->
links;link++)
1329 ret=_make_decode_ready(vf);
1346 if(samples>target)samples=target;
1351 if(_fetch_and_process_packet(vf,
NULL,1,1)<=0)
1368 if(seconds<0 || seconds>TIME_Total)
return(
OV_EINVAL);
1371 for(link=vf->
links-1;link>=0;link--){
1374 if(seconds>=TIME_Total)
break;
1395 if(seconds<0 || seconds>TIME_Total)
return(
OV_EINVAL);
1398 for(link=vf->
links-1;link>=0;link--){
1401 if(seconds>=TIME_Total)
break;
1428 double TIME_Total=0.f;
1436 for(link=vf->
links-1;link>=0;link--){
1443 return((
double)TIME_Total+(
double)(vf->
pcm_offset-pcm_total)/vf->
vi[link].
rate);
1489 static int host_is_big_endian() {
1491 unsigned char *bytewise = (
unsigned char *)&pattern;
1492 if (bytewise[0] == 0xfe)
return 1;
1528 int bigendianp,
int word,
int sgned,
int *bitstream){
1530 int host_endian = host_is_big_endian();
1545 int ret=_fetch_and_process_packet(vf,
NULL,1,1);
1559 long bytespersample=word * channels;
1561 if(samples>length/bytespersample)samples=length/bytespersample;
1570 int off=(sgned?0:128);
1572 for(j=0;j<samples;j++)
1573 for(i=0;i<channels;i++){
1574 val=vorbis_ftoi(pcm[i][j]*128.f);
1576 else if(val<-128)val=-128;
1581 int off=(sgned?0:32768);
1583 if(host_endian==bigendianp){
1587 for(i=0;i<channels;i++) {
1589 short *dest=((
short *)buffer)+
i;
1590 for(j=0;j<samples;j++) {
1591 val=vorbis_ftoi(src[j]*32768.f);
1592 if(val>32767)val=32767;
1593 else if(val<-32768)val=-32768;
1603 for(i=0;i<channels;i++) {
1605 short *dest=((
short *)buffer)+
i;
1606 for(j=0;j<samples;j++) {
1607 val=vorbis_ftoi(src[j]*32768.f);
1608 if(val>32767)val=32767;
1609 else if(val<-32768)val=-32768;
1617 }
else if(bigendianp){
1620 for(j=0;j<samples;j++)
1621 for(i=0;i<channels;i++){
1622 val=vorbis_ftoi(pcm[i][j]*32768.f);
1623 if(val>32767)val=32767;
1624 else if(val<-32768)val=-32768;
1627 *buffer++=(val&0xff);
1634 for(j=0;j<samples;j++)
1635 for(i=0;i<channels;i++){
1636 val=vorbis_ftoi(pcm[i][j]*32768.f);
1637 if(val>32767)val=32767;
1638 else if(val<-32768)val=-32768;
1640 *buffer++=(val&0xff);
1652 return(samples*bytespersample);
1682 if(pcm_channels)*pcm_channels=pcm;
1683 if(samples>length)samples=
length;
1694 int ret=_fetch_and_process_packet(vf,
NULL,1,1);
1695 if(ret==
OV_EOF)
return(0);
1696 if(ret<=0)
return(ret);
1706 static void _ov_splice(
float **pcm,
float **lappcm,
1709 float *
w1,
float *
w2){
1720 for(j=0;j<ch1 && j<ch2;j++){
1727 d[
i]=d[
i]*wd + s[
i]*ws;
1747 int ret=_fetch_and_process_packet(vf,
NULL,1,0);
1748 if(ret<0 && ret!=
OV_HOLE)
return(ret);
1765 int ret=_fetch_and_process_packet(vf,
NULL,1,0);
1766 if(ret<0 && ret!=
OV_HOLE)
return(ret);
1776 float **lappcm,
int lapsize){
1781 while(lapcount<lapsize){
1784 if(samples>lapsize-lapcount)samples=lapsize-lapcount;
1786 memcpy(lappcm[i]+lapcount,pcm[i],
sizeof(**pcm)*samples);
1791 int ret=_fetch_and_process_packet(vf,
NULL,1,0);
1795 if(lapcount<lapsize){
1802 memset(lappcm[i]+lapcount,0,
sizeof(**pcm)*lapsize-lapcount);
1805 if(samples>lapsize-lapcount)samples=lapsize-lapcount;
1807 memcpy(lappcm[i]+lapcount,pcm[i],
sizeof(**pcm)*samples);
1820 int n1,n2,
i,ret,hs1,hs2;
1822 if(vf1==vf2)
return(0);
1830 ret=_ov_initset(vf1);
1832 ret=_ov_initprime(vf2);
1840 lappcm=alloca(
sizeof(*lappcm)*vi1->
channels);
1847 lappcm[i]=alloca(
sizeof(**lappcm)*n1);
1849 _ov_getlap(vf1,vi1,&vf1->
vd,lappcm,n1);
1871 int n1,n2,ch1,ch2,hs;
1875 ret=_ov_initset(vf);
1887 lappcm=alloca(
sizeof(*lappcm)*ch1);
1889 lappcm[i]=alloca(
sizeof(**lappcm)*n1);
1890 _ov_getlap(vf,vi,&vf->
vd,lappcm,n1);
1893 ret=localseek(vf,pos);
1895 ret=_ov_initprime(vf);
1908 _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
1932 int n1,n2,ch1,ch2,hs;
1936 ret=_ov_initset(vf);
1948 lappcm=alloca(
sizeof(*lappcm)*ch1);
1950 lappcm[i]=alloca(
sizeof(**lappcm)*n1);
1951 _ov_getlap(vf,vi,&vf->
vd,lappcm,n1);
1954 ret=localseek(vf,pos);
1956 ret=_ov_initprime(vf);
1969 _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
double ov_TIME_Tell(OggVorbis_File *vf)
int(* close_func)(void *datasource)
int vorbis_synthesis_halfrate(vorbis_info *v, int flag)
int vorbis_synthesis(vorbis_block *vb, ogg_packet *op)
int ov_time_seek_lap(OggVorbis_File *vf, double pos)
long ov_bitrate(OggVorbis_File *vf, int i)
void vorbis_comment_clear(vorbis_comment *vc)
void _analysis_output_always(char *base, int i, float *v, int n, int bark, int dB, ogg_int64_t off)
int vorbis_synthesis_trackonly(vorbis_block *vb, ogg_packet *op)
int vorbis_synthesis_read(vorbis_dsp_state *v, int samples)
ogg_int64_t ogg_page_granulepos(ogg_page *og)
int vorbis_synthesis_halfrate_p(vorbis_info *v)
int ov_clear(OggVorbis_File *vf)
long ov_bitrate_instant(OggVorbis_File *vf)
int ogg_page_serialno(ogg_page *og)
int ov_time_seek_page_lap(OggVorbis_File *vf, double pos)
vorbis_info * ov_info(OggVorbis_File *vf, int link)
int ogg_sync_wrote(ogg_sync_state *oy, long bytes)
size_t(* read_func)(void *ptr, size_t size, size_t nmemb, void *datasource)
#define vorbis_fpu_setround(vorbis_fpu_control)
ogg_int64_t ov_pcm_total(OggVorbis_File *vf, int i)
int ov_test_open(OggVorbis_File *vf)
ogg_int64_t ov_raw_tell(OggVorbis_File *vf)
double ov_TIME_Total(OggVorbis_File *vf, int i)
vorbis_comment * ov_comment(OggVorbis_File *vf, int link)
int ov_raw_seek(OggVorbis_File *vf, ogg_int64_t pos)
void vorbis_comment_init(vorbis_comment *vc)
int vorbis_synthesis_headerin(vorbis_info *vi, vorbis_comment *vc, ogg_packet *op)
char * ogg_sync_buffer(ogg_sync_state *oy, long size)
int ov_open_callbacks(void *f, OggVorbis_File *vf, char *initial, long ibytes, ov_callbacks callbacks)
int ogg_sync_reset(ogg_sync_state *oy)
int ov_time_seek(OggVorbis_File *vf, double seconds)
int ov_time_seek_page(OggVorbis_File *vf, double seconds)
GLubyte GLubyte GLubyte GLubyte w
int vorbis_synthesis_restart(vorbis_dsp_state *v)
int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2)
int ogg_stream_packetpeek(ogg_stream_state *os, ogg_packet *op)
void vorbis_info_init(vorbis_info *vi)
int vorbis_synthesis_pcmout(vorbis_dsp_state *v, float ***pcm)
int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og)
int ov_pcm_seek_lap(OggVorbis_File *vf, ogg_int64_t pos)
float * vorbis_window(vorbis_dsp_state *v, int W)
int ov_pcm_seek_page(OggVorbis_File *vf, ogg_int64_t pos)
int ov_test_callbacks(void *f, OggVorbis_File *vf, char *initial, long ibytes, ov_callbacks callbacks)
int ogg_sync_clear(ogg_sync_state *oy)
void vorbis_info_clear(vorbis_info *vi)
int ov_pcm_seek_page_lap(OggVorbis_File *vf, ogg_int64_t pos)
int ov_test(FILE *f, OggVorbis_File *vf, char *initial, long ibytes)
ogg_int64_t ov_raw_total(OggVorbis_File *vf, int i)
ogg_int64_t ov_pcm_tell(OggVorbis_File *vf)
int vorbis_synthesis_init(vorbis_dsp_state *v, vorbis_info *vi)
long ov_seekable(OggVorbis_File *vf)
int vorbis_block_clear(vorbis_block *vb)
long(* tell_func)(void *datasource)
long ov_read(OggVorbis_File *vf, char *buffer, int length, int bigendianp, int word, int sgned, int *bitstream)
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
int(* seek_func)(void *datasource, ogg_int64_t offset, int whence)
int ogg_stream_clear(ogg_stream_state *os)
int ov_open(FILE *f, OggVorbis_File *vf, char *initial, long ibytes)
long ov_streams(OggVorbis_File *vf)
#define vorbis_fpu_restore(vorbis_fpu_control)
void vorbis_dsp_clear(vorbis_dsp_state *v)
ogg_int64_t * dataoffsets
long ov_read_float(OggVorbis_File *vf, float ***pcm_channels, int length, int *bitstream)
long ogg_sync_pageseek(ogg_sync_state *oy, ogg_page *og)
long vorbis_packet_blocksize(vorbis_info *vi, ogg_packet *op)
int ogg_page_continued(ogg_page *og)
int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb)
int ogg_stream_packetout(ogg_stream_state *os, ogg_packet *op)
GLsizei const GLcharARB const GLint * length
int ov_pcm_seek(OggVorbis_File *vf, ogg_int64_t pos)
long ov_serialnumber(OggVorbis_File *vf, int i)
int ov_raw_seek_lap(OggVorbis_File *vf, ogg_int64_t pos)
int ov_halfrate(OggVorbis_File *vf, int flag)
int ogg_page_eos(ogg_page *og)
int vorbis_info_blocksize(vorbis_info *vi, int zo)
int ogg_stream_reset(ogg_stream_state *os)
int ogg_sync_init(ogg_sync_state *oy)
int ogg_stream_reset_serialno(ogg_stream_state *os, int serialno)
int ov_halfrate_p(OggVorbis_File *vf)
int ogg_stream_init(ogg_stream_state *os, int serialno)
int vorbis_synthesis_blockin(vorbis_dsp_state *v, vorbis_block *vb)
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
int vorbis_synthesis_lapout(vorbis_dsp_state *v, float ***pcm)