diff options
Diffstat (limited to 'apps/codecs')
-rw-r--r-- | apps/codecs/Tremor/asm_mcf5249.h | 33 | ||||
-rw-r--r-- | apps/codecs/Tremor/bitwise.c | 15 | ||||
-rw-r--r-- | apps/codecs/Tremor/framing.c | 69 | ||||
-rw-r--r-- | apps/codecs/Tremor/info.c | 48 | ||||
-rw-r--r-- | apps/codecs/Tremor/ivorbiscodec.h | 5 | ||||
-rw-r--r-- | apps/codecs/Tremor/ivorbisfile_example.c | 86 | ||||
-rw-r--r-- | apps/codecs/Tremor/ogg.h | 5 | ||||
-rw-r--r-- | apps/codecs/Tremor/vorbisfile.c | 286 |
8 files changed, 0 insertions, 547 deletions
diff --git a/apps/codecs/Tremor/asm_mcf5249.h b/apps/codecs/Tremor/asm_mcf5249.h index 7d366fa9ca..fd816a2e9b 100644 --- a/apps/codecs/Tremor/asm_mcf5249.h +++ b/apps/codecs/Tremor/asm_mcf5249.h | |||
@@ -306,39 +306,6 @@ void vect_mult_bw(ogg_int32_t *data, LOOKUP_T *window, int n) | |||
306 | "cc", "memory"); | 306 | "cc", "memory"); |
307 | } | 307 | } |
308 | 308 | ||
309 | #if 0 | ||
310 | /* this routine is subsumed by Jens' asm optimised memset which appears | ||
311 | to be more efficient anyway; will eventually be deleted */ | ||
312 | static inline | ||
313 | void mcf5249_vect_zero(ogg_int32_t *ptr, int n) | ||
314 | { | ||
315 | /* ensure ptr is aligned to 16-bytes */ | ||
316 | while(n>0 && (int)ptr%16) { | ||
317 | *ptr++ = 0; | ||
318 | n--; | ||
319 | } | ||
320 | asm volatile ("clr.l %%d0;" | ||
321 | "clr.l %%d1;" | ||
322 | "clr.l %%d2;" | ||
323 | "clr.l %%d3;" | ||
324 | /* loop start */ | ||
325 | "tst.l %[n];" | ||
326 | "bra 1f;" | ||
327 | "0: movem.l %%d0-%%d3, (%[ptr]);" | ||
328 | "lea (4*4, %[ptr]), %[ptr];" | ||
329 | "subq.l #4, %[n];" /* done 4 elements */ | ||
330 | "1: bgt 0b;" | ||
331 | : [n] "+d" (n), [ptr] "+a" (ptr) | ||
332 | : | ||
333 | : "%d0","%d1","%d2","%d3","cc","memory"); | ||
334 | /* clear remaining elements */ | ||
335 | while(n>0) { | ||
336 | *ptr++ = 0; | ||
337 | n--; | ||
338 | } | ||
339 | } | ||
340 | #endif | ||
341 | |||
342 | #endif | 309 | #endif |
343 | 310 | ||
344 | #endif | 311 | #endif |
diff --git a/apps/codecs/Tremor/bitwise.c b/apps/codecs/Tremor/bitwise.c index 55d3712708..caa42f4277 100644 --- a/apps/codecs/Tremor/bitwise.c +++ b/apps/codecs/Tremor/bitwise.c | |||
@@ -130,11 +130,6 @@ static int _halt_one(oggpack_buffer *b){ | |||
130 | return 0; | 130 | return 0; |
131 | } | 131 | } |
132 | 132 | ||
133 | int oggpack_eop(oggpack_buffer *b){ | ||
134 | if(b->headend<0)return -1; | ||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | /* bits <= 32 */ | 133 | /* bits <= 32 */ |
139 | long oggpack_read(oggpack_buffer *b,int bits) ICODE_ATTR_TREMOR_NOT_MDCT; | 134 | long oggpack_read(oggpack_buffer *b,int bits) ICODE_ATTR_TREMOR_NOT_MDCT; |
140 | long oggpack_read(oggpack_buffer *b,int bits){ | 135 | long oggpack_read(oggpack_buffer *b,int bits){ |
@@ -217,13 +212,3 @@ long oggpack_read(oggpack_buffer *b,int bits){ | |||
217 | return ret; | 212 | return ret; |
218 | } | 213 | } |
219 | 214 | ||
220 | long oggpack_bytes(oggpack_buffer *b){ | ||
221 | return(b->count+b->headptr-b->head->buffer->data-b->head->begin+ | ||
222 | (b->headbit+7)/8); | ||
223 | } | ||
224 | |||
225 | long oggpack_bits(oggpack_buffer *b){ | ||
226 | return((b->count+b->headptr-b->head->buffer->data-b->head->begin)*8+ | ||
227 | b->headbit); | ||
228 | } | ||
229 | |||
diff --git a/apps/codecs/Tremor/framing.c b/apps/codecs/Tremor/framing.c index 1cd5c1eb50..4fc4a69d4c 100644 --- a/apps/codecs/Tremor/framing.c +++ b/apps/codecs/Tremor/framing.c | |||
@@ -469,36 +469,6 @@ ogg_uint32_t ogg_page_pageno(ogg_page *og){ | |||
469 | return oggbyte_read4(&ob,18); | 469 | return oggbyte_read4(&ob,18); |
470 | } | 470 | } |
471 | 471 | ||
472 | /* returns the number of packets that are completed on this page (if | ||
473 | the leading packet is begun on a previous page, but ends on this | ||
474 | page, it's counted */ | ||
475 | |||
476 | /* NOTE: | ||
477 | If a page consists of a packet begun on a previous page, and a new | ||
478 | packet begun (but not completed) on this page, the return will be: | ||
479 | ogg_page_packets(page) ==1, | ||
480 | ogg_page_continued(page) !=0 | ||
481 | |||
482 | If a page happens to be a single packet that was begun on a | ||
483 | previous page, and spans to the next page (in the case of a three or | ||
484 | more page packet), the return will be: | ||
485 | ogg_page_packets(page) ==0, | ||
486 | ogg_page_continued(page) !=0 | ||
487 | */ | ||
488 | |||
489 | int ogg_page_packets(ogg_page *og){ | ||
490 | int i; | ||
491 | int n; | ||
492 | int count=0; | ||
493 | oggbyte_buffer ob; | ||
494 | oggbyte_init(&ob,og->header); | ||
495 | |||
496 | n=oggbyte_read1(&ob,26); | ||
497 | for(i=0;i<n;i++) | ||
498 | if(oggbyte_read1(&ob,27+i)<255)count++; | ||
499 | return(count); | ||
500 | } | ||
501 | |||
502 | /* Static CRC calculation table. See older code in CVS for dead | 472 | /* Static CRC calculation table. See older code in CVS for dead |
503 | run-time initialization code. */ | 473 | run-time initialization code. */ |
504 | 474 | ||
@@ -770,45 +740,6 @@ long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){ | |||
770 | return ret; | 740 | return ret; |
771 | } | 741 | } |
772 | 742 | ||
773 | /* sync the stream and get a page. Keep trying until we find a page. | ||
774 | Supress 'sync errors' after reporting the first. | ||
775 | |||
776 | return values: | ||
777 | OGG_HOLE) recapture (hole in data) | ||
778 | 0) need more data | ||
779 | 1) page returned | ||
780 | |||
781 | Returns pointers into buffered data; invalidated by next call to | ||
782 | _stream, _clear, _init, or _buffer */ | ||
783 | |||
784 | int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){ | ||
785 | |||
786 | /* all we need to do is verify a page at the head of the stream | ||
787 | buffer. If it doesn't verify, we look for the next potential | ||
788 | frame */ | ||
789 | |||
790 | while(1){ | ||
791 | long ret=ogg_sync_pageseek(oy,og); | ||
792 | if(ret>0){ | ||
793 | /* have a page */ | ||
794 | return 1; | ||
795 | } | ||
796 | if(ret==0){ | ||
797 | /* need more data */ | ||
798 | return 0; | ||
799 | } | ||
800 | |||
801 | /* head did not start a synced page... skipped some bytes */ | ||
802 | if(!oy->unsynced){ | ||
803 | oy->unsynced=1; | ||
804 | return OGG_HOLE; | ||
805 | } | ||
806 | |||
807 | /* loop. keep looking */ | ||
808 | |||
809 | } | ||
810 | } | ||
811 | |||
812 | /* clear things to an initial state. Good to call, eg, before seeking */ | 743 | /* clear things to an initial state. Good to call, eg, before seeking */ |
813 | int ogg_sync_reset(ogg_sync_state *oy){ | 744 | int ogg_sync_reset(ogg_sync_state *oy){ |
814 | 745 | ||
diff --git a/apps/codecs/Tremor/info.c b/apps/codecs/Tremor/info.c index c8d9651bd4..c0bd0ae990 100644 --- a/apps/codecs/Tremor/info.c +++ b/apps/codecs/Tremor/info.c | |||
@@ -41,54 +41,6 @@ void vorbis_comment_init(vorbis_comment *vc){ | |||
41 | memset(vc,0,sizeof(*vc)); | 41 | memset(vc,0,sizeof(*vc)); |
42 | } | 42 | } |
43 | 43 | ||
44 | /* This is more or less the same as strncasecmp - but that doesn't exist | ||
45 | * everywhere, and this is a fairly trivial function, so we include it */ | ||
46 | static int tagcompare(const char *s1, const char *s2, int n){ | ||
47 | int c=0; | ||
48 | while(c < n){ | ||
49 | if(toupper(s1[c]) != toupper(s2[c])) | ||
50 | return !0; | ||
51 | c++; | ||
52 | } | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){ | ||
57 | long i; | ||
58 | int found = 0; | ||
59 | int taglen = strlen(tag)+1; /* +1 for the = we append */ | ||
60 | char *fulltag = (char *)alloca(taglen+ 1); | ||
61 | |||
62 | strcpy(fulltag, tag); | ||
63 | strcat(fulltag, "="); | ||
64 | |||
65 | for(i=0;i<vc->comments;i++){ | ||
66 | if(!tagcompare(vc->user_comments[i], fulltag, taglen)){ | ||
67 | if(count == found) | ||
68 | /* We return a pointer to the data, not a copy */ | ||
69 | return vc->user_comments[i] + taglen; | ||
70 | else | ||
71 | found++; | ||
72 | } | ||
73 | } | ||
74 | return NULL; /* didn't find anything */ | ||
75 | } | ||
76 | |||
77 | int vorbis_comment_query_count(vorbis_comment *vc, char *tag){ | ||
78 | int i,count=0; | ||
79 | int taglen = strlen(tag)+1; /* +1 for the = we append */ | ||
80 | char *fulltag = (char *)alloca(taglen+1); | ||
81 | strcpy(fulltag,tag); | ||
82 | strcat(fulltag, "="); | ||
83 | |||
84 | for(i=0;i<vc->comments;i++){ | ||
85 | if(!tagcompare(vc->user_comments[i], fulltag, taglen)) | ||
86 | count++; | ||
87 | } | ||
88 | |||
89 | return count; | ||
90 | } | ||
91 | |||
92 | void vorbis_comment_clear(vorbis_comment *vc){ | 44 | void vorbis_comment_clear(vorbis_comment *vc){ |
93 | if(vc){ | 45 | if(vc){ |
94 | long i; | 46 | long i; |
diff --git a/apps/codecs/Tremor/ivorbiscodec.h b/apps/codecs/Tremor/ivorbiscodec.h index d4de1fd344..b3e63226ee 100644 --- a/apps/codecs/Tremor/ivorbiscodec.h +++ b/apps/codecs/Tremor/ivorbiscodec.h | |||
@@ -48,7 +48,6 @@ typedef struct vorbis_info{ | |||
48 | long bitrate_upper; | 48 | long bitrate_upper; |
49 | long bitrate_nominal; | 49 | long bitrate_nominal; |
50 | long bitrate_lower; | 50 | long bitrate_lower; |
51 | long bitrate_window; | ||
52 | 51 | ||
53 | void *codec_setup; | 52 | void *codec_setup; |
54 | } vorbis_info; | 53 | } vorbis_info; |
@@ -57,7 +56,6 @@ typedef struct vorbis_info{ | |||
57 | analysis/synthesis state. The DSP state belongs to a specific | 56 | analysis/synthesis state. The DSP state belongs to a specific |
58 | logical bitstream ****************************************************/ | 57 | logical bitstream ****************************************************/ |
59 | typedef struct vorbis_dsp_state{ | 58 | typedef struct vorbis_dsp_state{ |
60 | int analysisp; | ||
61 | vorbis_info *vi; | 59 | vorbis_info *vi; |
62 | 60 | ||
63 | ogg_int32_t **pcm; | 61 | ogg_int32_t **pcm; |
@@ -66,7 +64,6 @@ typedef struct vorbis_dsp_state{ | |||
66 | int pcm_current; | 64 | int pcm_current; |
67 | int pcm_returned; | 65 | int pcm_returned; |
68 | 66 | ||
69 | int preextrapolate; | ||
70 | int eofflag; | 67 | int eofflag; |
71 | 68 | ||
72 | long lW; | 69 | long lW; |
@@ -156,8 +153,6 @@ extern void vorbis_comment_init(vorbis_comment *vc); | |||
156 | extern void vorbis_comment_add(vorbis_comment *vc, char *comment); | 153 | extern void vorbis_comment_add(vorbis_comment *vc, char *comment); |
157 | extern void vorbis_comment_add_tag(vorbis_comment *vc, | 154 | extern void vorbis_comment_add_tag(vorbis_comment *vc, |
158 | char *tag, char *contents); | 155 | char *tag, char *contents); |
159 | extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count); | ||
160 | extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag); | ||
161 | extern void vorbis_comment_clear(vorbis_comment *vc); | 156 | extern void vorbis_comment_clear(vorbis_comment *vc); |
162 | 157 | ||
163 | extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb); | 158 | extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb); |
diff --git a/apps/codecs/Tremor/ivorbisfile_example.c b/apps/codecs/Tremor/ivorbisfile_example.c deleted file mode 100644 index 3c34b25f79..0000000000 --- a/apps/codecs/Tremor/ivorbisfile_example.c +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | /******************************************************************** | ||
2 | * * | ||
3 | * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * | ||
4 | * * | ||
5 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * | ||
6 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * | ||
7 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * | ||
8 | * * | ||
9 | * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * | ||
10 | * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * | ||
11 | * * | ||
12 | ******************************************************************** | ||
13 | |||
14 | function: simple example decoder using vorbisidec | ||
15 | |||
16 | ********************************************************************/ | ||
17 | |||
18 | /* Takes a vorbis bitstream from stdin and writes raw stereo PCM to | ||
19 | stdout using vorbisfile. Using vorbisfile is much simpler than | ||
20 | dealing with libvorbis. */ | ||
21 | |||
22 | #include "config-tremor.h" | ||
23 | #include <stdio.h> | ||
24 | #include <vorbis/ivorbiscodec.h> | ||
25 | #include <vorbis/ivorbisfile.h> | ||
26 | |||
27 | #ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */ | ||
28 | #include <io.h> | ||
29 | #include <fcntl.h> | ||
30 | #endif | ||
31 | |||
32 | char pcmout[4096]; /* take 4k out of the data segment, not the stack */ | ||
33 | |||
34 | int main(){ | ||
35 | OggVorbis_File vf; | ||
36 | int eof=0; | ||
37 | int current_section; | ||
38 | |||
39 | #ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */ | ||
40 | /* Beware the evil ifdef. We avoid these where we can, but this one we | ||
41 | cannot. Don't add any more, you'll probably go to hell if you do. */ | ||
42 | _setmode( _fileno( stdin ), _O_BINARY ); | ||
43 | _setmode( _fileno( stdout ), _O_BINARY ); | ||
44 | #endif | ||
45 | |||
46 | if(ov_open(stdin, &vf, NULL, 0) < 0) { | ||
47 | fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n"); | ||
48 | exit(1); | ||
49 | } | ||
50 | |||
51 | /* Throw the comments plus a few lines about the bitstream we're | ||
52 | decoding */ | ||
53 | { | ||
54 | char **ptr=ov_comment(&vf,-1)->user_comments; | ||
55 | vorbis_info *vi=ov_info(&vf,-1); | ||
56 | while(*ptr){ | ||
57 | fprintf(stderr,"%s\n",*ptr); | ||
58 | ++ptr; | ||
59 | } | ||
60 | fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate); | ||
61 | fprintf(stderr,"\nDecoded length: %ld samples\n", | ||
62 | (long)ov_pcm_total(&vf,-1)); | ||
63 | fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor); | ||
64 | } | ||
65 | |||
66 | while(!eof){ | ||
67 | long ret=ov_read(&vf,pcmout,sizeof(pcmout),¤t_section); | ||
68 | if (ret == 0) { | ||
69 | /* EOF */ | ||
70 | eof=1; | ||
71 | } else if (ret < 0) { | ||
72 | /* error in the stream. Not a problem, just reporting it in | ||
73 | case we (the app) cares. In this case, we don't. */ | ||
74 | } else { | ||
75 | /* we don't bother dealing with sample rate changes, etc, but | ||
76 | you'll have to*/ | ||
77 | fwrite(pcmout,1,ret,stdout); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | /* cleanup */ | ||
82 | ov_clear(&vf); | ||
83 | |||
84 | fprintf(stderr,"Done.\n"); | ||
85 | return(0); | ||
86 | } | ||
diff --git a/apps/codecs/Tremor/ogg.h b/apps/codecs/Tremor/ogg.h index 5f85eb420f..7e2785f117 100644 --- a/apps/codecs/Tremor/ogg.h +++ b/apps/codecs/Tremor/ogg.h | |||
@@ -143,9 +143,6 @@ typedef struct { | |||
143 | extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r); | 143 | extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r); |
144 | extern long oggpack_look_full(oggpack_buffer *b,int bits); | 144 | extern long oggpack_look_full(oggpack_buffer *b,int bits); |
145 | extern long oggpack_read(oggpack_buffer *b,int bits); | 145 | extern long oggpack_read(oggpack_buffer *b,int bits); |
146 | extern long oggpack_bytes(oggpack_buffer *b); | ||
147 | extern long oggpack_bits(oggpack_buffer *b); | ||
148 | extern int oggpack_eop(oggpack_buffer *b); | ||
149 | 146 | ||
150 | /* Inline a few, often called functions */ | 147 | /* Inline a few, often called functions */ |
151 | 148 | ||
@@ -221,7 +218,6 @@ extern int ogg_sync_reset(ogg_sync_state *oy); | |||
221 | extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size); | 218 | extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size); |
222 | extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes); | 219 | extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes); |
223 | extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og); | 220 | extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og); |
224 | extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og); | ||
225 | extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og); | 221 | extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og); |
226 | extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op); | 222 | extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op); |
227 | extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op); | 223 | extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op); |
@@ -243,7 +239,6 @@ extern int ogg_page_eos(ogg_page *og); | |||
243 | extern ogg_int64_t ogg_page_granulepos(ogg_page *og); | 239 | extern ogg_int64_t ogg_page_granulepos(ogg_page *og); |
244 | extern ogg_uint32_t ogg_page_serialno(ogg_page *og); | 240 | extern ogg_uint32_t ogg_page_serialno(ogg_page *og); |
245 | extern ogg_uint32_t ogg_page_pageno(ogg_page *og); | 241 | extern ogg_uint32_t ogg_page_pageno(ogg_page *og); |
246 | extern int ogg_page_packets(ogg_page *og); | ||
247 | extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer); | 242 | extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer); |
248 | 243 | ||
249 | extern int ogg_packet_release(ogg_packet *op); | 244 | extern int ogg_packet_release(ogg_packet *op); |
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 | ||