diff options
Diffstat (limited to 'apps/codecs/Tremor/vorbisfile.c')
-rw-r--r-- | apps/codecs/Tremor/vorbisfile.c | 286 |
1 files changed, 0 insertions, 286 deletions
diff --git a/apps/codecs/Tremor/vorbisfile.c b/apps/codecs/Tremor/vorbisfile.c index a32d9f2a48..ca18ecb3f7 100644 --- a/apps/codecs/Tremor/vorbisfile.c +++ b/apps/codecs/Tremor/vorbisfile.c | |||
@@ -657,15 +657,6 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, | |||
657 | return ret; | 657 | return ret; |
658 | } | 658 | } |
659 | 659 | ||
660 | /* if, eg, 64 bit stdio is configured by default, this will build with | ||
661 | fseek64 */ | ||
662 | #if 0 | ||
663 | static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){ | ||
664 | if(f==NULL)return(-1); | ||
665 | return fseek(f,off,whence); | ||
666 | } | ||
667 | #endif | ||
668 | |||
669 | static int _ov_open1(void *f,OggVorbis_File *vf,char *initial, | 660 | static int _ov_open1(void *f,OggVorbis_File *vf,char *initial, |
670 | long ibytes, ov_callbacks callbacks){ | 661 | long ibytes, ov_callbacks callbacks){ |
671 | int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1); | 662 | int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1); |
@@ -774,148 +765,6 @@ int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes, | |||
774 | return _ov_open2(vf); | 765 | return _ov_open2(vf); |
775 | } | 766 | } |
776 | 767 | ||
777 | #if 0 | ||
778 | int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){ | ||
779 | ov_callbacks callbacks = { | ||
780 | (size_t (*)(void *, size_t, size_t, void *)) fread, | ||
781 | (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap, | ||
782 | (int (*)(void *)) fclose, | ||
783 | (long (*)(void *)) ftell | ||
784 | }; | ||
785 | |||
786 | return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks); | ||
787 | } | ||
788 | #endif | ||
789 | |||
790 | /* Only partially open the vorbis file; test for Vorbisness, and load | ||
791 | the headers for the first chain. Do not seek (although test for | ||
792 | seekability). Use ov_test_open to finish opening the file, else | ||
793 | ov_clear to close/free it. Same return codes as open. */ | ||
794 | |||
795 | int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes, | ||
796 | ov_callbacks callbacks) | ||
797 | { | ||
798 | return _ov_open1(f,vf,initial,ibytes,callbacks); | ||
799 | } | ||
800 | |||
801 | #if 0 | ||
802 | int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){ | ||
803 | ov_callbacks callbacks = { | ||
804 | (size_t (*)(void *, size_t, size_t, void *)) fread, | ||
805 | (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap, | ||
806 | (int (*)(void *)) fclose, | ||
807 | (long (*)(void *)) ftell | ||
808 | }; | ||
809 | |||
810 | return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks); | ||
811 | } | ||
812 | #endif | ||
813 | |||
814 | int ov_test_open(OggVorbis_File *vf){ | ||
815 | if(vf->ready_state!=PARTOPEN)return(OV_EINVAL); | ||
816 | return _ov_open2(vf); | ||
817 | } | ||
818 | |||
819 | /* How many logical bitstreams in this physical bitstream? */ | ||
820 | long ov_streams(OggVorbis_File *vf){ | ||
821 | return vf->links; | ||
822 | } | ||
823 | |||
824 | /* Is the FILE * associated with vf seekable? */ | ||
825 | long ov_seekable(OggVorbis_File *vf){ | ||
826 | return vf->seekable; | ||
827 | } | ||
828 | |||
829 | /* returns the bitrate for a given logical bitstream or the entire | ||
830 | physical bitstream. If the file is open for random access, it will | ||
831 | find the *actual* average bitrate. If the file is streaming, it | ||
832 | returns the nominal bitrate (if set) else the average of the | ||
833 | upper/lower bounds (if set) else -1 (unset). | ||
834 | |||
835 | If you want the actual bitrate field settings, get them from the | ||
836 | vorbis_info structs */ | ||
837 | |||
838 | long ov_bitrate(OggVorbis_File *vf,int i){ | ||
839 | if(vf->ready_state<OPENED)return(OV_EINVAL); | ||
840 | if(i>=vf->links)return(OV_EINVAL); | ||
841 | if(!vf->seekable && i!=0)return(ov_bitrate(vf,0)); | ||
842 | if(i<0){ | ||
843 | ogg_int64_t bits=0; | ||
844 | int i; | ||
845 | for(i=0;i<vf->links;i++) | ||
846 | bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8; | ||
847 | /* This once read: return(rint(bits/ov_time_total(vf,-1))); | ||
848 | * gcc 3.x on x86 miscompiled this at optimisation level 2 and above, | ||
849 | * so this is slightly transformed to make it work. | ||
850 | */ | ||
851 | return(bits*1000/ov_time_total(vf,-1)); | ||
852 | }else{ | ||
853 | if(vf->seekable){ | ||
854 | /* return the actual bitrate */ | ||
855 | return((vf->offsets[i+1]-vf->dataoffsets[i])*8000/ov_time_total(vf,i)); | ||
856 | }else{ | ||
857 | /* return nominal if set */ | ||
858 | if(vf->vi[i].bitrate_nominal>0){ | ||
859 | return vf->vi[i].bitrate_nominal; | ||
860 | }else{ | ||
861 | if(vf->vi[i].bitrate_upper>0){ | ||
862 | if(vf->vi[i].bitrate_lower>0){ | ||
863 | return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2; | ||
864 | }else{ | ||
865 | return vf->vi[i].bitrate_upper; | ||
866 | } | ||
867 | } | ||
868 | return(OV_FALSE); | ||
869 | } | ||
870 | } | ||
871 | } | ||
872 | } | ||
873 | |||
874 | /* returns the actual bitrate since last call. returns -1 if no | ||
875 | additional data to offer since last call (or at beginning of stream), | ||
876 | EINVAL if stream is only partially open | ||
877 | */ | ||
878 | long ov_bitrate_instant(OggVorbis_File *vf){ | ||
879 | int link=(vf->seekable?vf->current_link:0); | ||
880 | long ret; | ||
881 | if(vf->ready_state<OPENED)return(OV_EINVAL); | ||
882 | if(vf->samptrack==0)return(OV_FALSE); | ||
883 | ret=vf->bittrack/vf->samptrack*vf->vi[link].rate; | ||
884 | vf->bittrack=0; | ||
885 | vf->samptrack=0; | ||
886 | return(ret); | ||
887 | } | ||
888 | |||
889 | /* Guess */ | ||
890 | long ov_serialnumber(OggVorbis_File *vf,int i){ | ||
891 | if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1)); | ||
892 | if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1)); | ||
893 | if(i<0){ | ||
894 | return(vf->current_serialno); | ||
895 | }else{ | ||
896 | return(vf->serialnos[i]); | ||
897 | } | ||
898 | } | ||
899 | |||
900 | /* returns: total raw (compressed) length of content if i==-1 | ||
901 | raw (compressed) length of that logical bitstream for i==0 to n | ||
902 | OV_EINVAL if the stream is not seekable (we can't know the length) | ||
903 | or if stream is only partially open | ||
904 | */ | ||
905 | ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){ | ||
906 | if(vf->ready_state<OPENED)return(OV_EINVAL); | ||
907 | if(!vf->seekable || i>=vf->links)return(OV_EINVAL); | ||
908 | if(i<0){ | ||
909 | ogg_int64_t acc=0; | ||
910 | int i; | ||
911 | for(i=0;i<vf->links;i++) | ||
912 | acc+=ov_raw_total(vf,i); | ||
913 | return(acc); | ||
914 | }else{ | ||
915 | return(vf->offsets[i+1]-vf->offsets[i]); | ||
916 | } | ||
917 | } | ||
918 | |||
919 | /* returns: total PCM length (samples) of content if i==-1 PCM length | 768 | /* returns: total PCM length (samples) of content if i==-1 PCM length |
920 | (samples) of that logical bitstream for i==0 to n | 769 | (samples) of that logical bitstream for i==0 to n |
921 | OV_EINVAL if the stream is not seekable (we can't know the | 770 | OV_EINVAL if the stream is not seekable (we can't know the |
@@ -1417,33 +1266,6 @@ int ov_time_seek(OggVorbis_File *vf,ogg_int64_t milliseconds){ | |||
1417 | } | 1266 | } |
1418 | } | 1267 | } |
1419 | 1268 | ||
1420 | /* page-granularity version of ov_time_seek | ||
1421 | returns zero on success, nonzero on failure */ | ||
1422 | int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t milliseconds){ | ||
1423 | /* translate time to PCM position and call ov_pcm_seek */ | ||
1424 | |||
1425 | int link=-1; | ||
1426 | ogg_int64_t pcm_total=ov_pcm_total(vf,-1); | ||
1427 | ogg_int64_t time_total=ov_time_total(vf,-1); | ||
1428 | |||
1429 | if(vf->ready_state<OPENED)return(OV_EINVAL); | ||
1430 | if(!vf->seekable)return(OV_ENOSEEK); | ||
1431 | if(milliseconds<0 || milliseconds>time_total)return(OV_EINVAL); | ||
1432 | |||
1433 | /* which bitstream section does this time offset occur in? */ | ||
1434 | for(link=vf->links-1;link>=0;link--){ | ||
1435 | pcm_total-=vf->pcmlengths[link*2+1]; | ||
1436 | time_total-=ov_time_total(vf,link); | ||
1437 | if(milliseconds>=time_total)break; | ||
1438 | } | ||
1439 | |||
1440 | /* enough information to convert time offset to pcm offset */ | ||
1441 | { | ||
1442 | ogg_int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000; | ||
1443 | return(ov_pcm_seek_page(vf,target)); | ||
1444 | } | ||
1445 | } | ||
1446 | |||
1447 | /* tell the current stream offset cursor. Note that seek followed by | 1269 | /* tell the current stream offset cursor. Note that seek followed by |
1448 | tell will likely not give the set offset due to caching */ | 1270 | tell will likely not give the set offset due to caching */ |
1449 | ogg_int64_t ov_raw_tell(OggVorbis_File *vf){ | 1271 | ogg_int64_t ov_raw_tell(OggVorbis_File *vf){ |
@@ -1451,12 +1273,6 @@ ogg_int64_t ov_raw_tell(OggVorbis_File *vf){ | |||
1451 | return(vf->offset); | 1273 | return(vf->offset); |
1452 | } | 1274 | } |
1453 | 1275 | ||
1454 | /* return PCM offset (sample) of next PCM sample to be read */ | ||
1455 | ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){ | ||
1456 | if(vf->ready_state<OPENED)return(OV_EINVAL); | ||
1457 | return(vf->pcm_offset); | ||
1458 | } | ||
1459 | |||
1460 | /* return time offset (milliseconds) of next PCM sample to be read */ | 1276 | /* return time offset (milliseconds) of next PCM sample to be read */ |
1461 | ogg_int64_t ov_time_tell(OggVorbis_File *vf) ICODE_ATTR_TREMOR_NOT_MDCT; | 1277 | ogg_int64_t ov_time_tell(OggVorbis_File *vf) ICODE_ATTR_TREMOR_NOT_MDCT; |
1462 | ogg_int64_t ov_time_tell(OggVorbis_File *vf){ | 1278 | ogg_int64_t ov_time_tell(OggVorbis_File *vf){ |
@@ -1505,108 +1321,6 @@ vorbis_info *ov_info(OggVorbis_File *vf,int link){ | |||
1505 | } | 1321 | } |
1506 | } | 1322 | } |
1507 | 1323 | ||
1508 | /* grr, strong typing, grr, no templates/inheritence, grr */ | ||
1509 | vorbis_comment *ov_comment(OggVorbis_File *vf,int link){ | ||
1510 | if(vf->seekable){ | ||
1511 | if(link<0) | ||
1512 | if(vf->ready_state>=STREAMSET) | ||
1513 | return vf->vc+vf->current_link; | ||
1514 | else | ||
1515 | return vf->vc; | ||
1516 | else | ||
1517 | if(link>=vf->links) | ||
1518 | return NULL; | ||
1519 | else | ||
1520 | return vf->vc+link; | ||
1521 | }else{ | ||
1522 | return vf->vc; | ||
1523 | } | ||
1524 | } | ||
1525 | |||
1526 | /* up to this point, everything could more or less hide the multiple | ||
1527 | logical bitstream nature of chaining from the toplevel application | ||
1528 | if the toplevel application didn't particularly care. However, at | ||
1529 | the point that we actually read audio back, the multiple-section | ||
1530 | nature must surface: Multiple bitstream sections do not necessarily | ||
1531 | have to have the same number of channels or sampling rate. | ||
1532 | |||
1533 | ov_read returns the sequential logical bitstream number currently | ||
1534 | being decoded along with the PCM data in order that the toplevel | ||
1535 | application can take action on channel/sample rate changes. This | ||
1536 | number will be incremented even for streamed (non-seekable) streams | ||
1537 | (for seekable streams, it represents the actual logical bitstream | ||
1538 | index within the physical bitstream. Note that the accessor | ||
1539 | functions above are aware of this dichotomy). | ||
1540 | |||
1541 | input values: buffer) a buffer to hold packed PCM data for return | ||
1542 | length) the byte length requested to be placed into buffer | ||
1543 | |||
1544 | return values: <0) error/hole in data (OV_HOLE), partial open (OV_EINVAL) | ||
1545 | 0) EOF | ||
1546 | n) number of bytes of PCM actually returned. The | ||
1547 | below works on a packet-by-packet basis, so the | ||
1548 | return length is not related to the 'length' passed | ||
1549 | in, just guaranteed to fit. | ||
1550 | |||
1551 | *section) set to the logical bitstream number */ | ||
1552 | |||
1553 | long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){ | ||
1554 | int i,j; | ||
1555 | |||
1556 | ogg_int32_t **pcm; | ||
1557 | long samples; | ||
1558 | |||
1559 | if(vf->ready_state<OPENED)return(OV_EINVAL); | ||
1560 | |||
1561 | while(1){ | ||
1562 | if(vf->ready_state==INITSET){ | ||
1563 | samples=vorbis_synthesis_pcmout(&vf->vd,&pcm); | ||
1564 | if(samples)break; | ||
1565 | } | ||
1566 | |||
1567 | /* suck in another packet */ | ||
1568 | { | ||
1569 | int ret=_fetch_and_process_packet(vf,1,1); | ||
1570 | if(ret==OV_EOF) | ||
1571 | return(0); | ||
1572 | if(ret<=0) | ||
1573 | return(ret); | ||
1574 | } | ||
1575 | |||
1576 | } | ||
1577 | |||
1578 | if(samples>0){ | ||
1579 | |||
1580 | /* yay! proceed to pack data into the byte buffer */ | ||
1581 | |||
1582 | long channels=ov_info(vf,-1)->channels; | ||
1583 | |||
1584 | if(channels==1){ | ||
1585 | if(samples>(bytes_req/2)) | ||
1586 | samples=bytes_req/2; | ||
1587 | }else{ | ||
1588 | if(samples>(bytes_req/4)) | ||
1589 | samples=bytes_req/4; | ||
1590 | } | ||
1591 | |||
1592 | for(i=0;i<channels;i++) { /* It's faster in this order */ | ||
1593 | ogg_int32_t *src=pcm[i]; | ||
1594 | short *dest=((short *)buffer)+i; | ||
1595 | for(j=0;j<samples;j++) { | ||
1596 | *dest=CLIP_TO_15(src[j]>>9); | ||
1597 | dest+=channels; | ||
1598 | } | ||
1599 | } | ||
1600 | |||
1601 | vorbis_synthesis_read(&vf->vd,samples); | ||
1602 | vf->pcm_offset+=samples; | ||
1603 | if(bitstream)*bitstream=vf->current_link; | ||
1604 | return(samples*2*channels); | ||
1605 | }else{ | ||
1606 | return(samples); | ||
1607 | } | ||
1608 | } | ||
1609 | |||
1610 | /* input values: pcm_channels) a float vector per channel of output | 1324 | /* input values: pcm_channels) a float vector per channel of output |
1611 | length) the sample length being read by the app | 1325 | length) the sample length being read by the app |
1612 | 1326 | ||