|
|
cf42fb7 |
Index: doc/Vorbis_I_spec.pdf
|
|
|
cf42fb7 |
===================================================================
|
|
|
cf42fb7 |
Cannot display: file marked as a binary type.
|
|
|
cf42fb7 |
svn:mime-type = application/pdf
|
|
|
cf42fb7 |
Index: lib/sharedbook.c
|
|
|
cf42fb7 |
===================================================================
|
|
|
cf42fb7 |
--- lib/sharedbook.c (revision 14810)
|
|
|
cf42fb7 |
+++ lib/sharedbook.c (revision 14811)
|
|
|
cf42fb7 |
@@ -124,7 +124,14 @@
|
|
|
cf42fb7 |
}else
|
|
|
cf42fb7 |
if(sparsecount==0)count++;
|
|
|
cf42fb7 |
}
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
+ /* sanity check the huffman tree; an underpopulated tree must be rejected. */
|
|
|
cf42fb7 |
+ for(i=1;i<33;i++)
|
|
|
cf42fb7 |
+ if(marker[i] & (0xffffffffUL>>(32-i))){
|
|
|
cf42fb7 |
+ _ogg_free(r);
|
|
|
cf42fb7 |
+ return(NULL);
|
|
|
cf42fb7 |
+ }
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
/* bitreverse the words because our bitwise packer/unpacker is LSb
|
|
|
cf42fb7 |
endian */
|
|
|
cf42fb7 |
for(i=0,count=0;i
|
|
|
cf42fb7 |
Index: lib/block.c
|
|
|
cf42fb7 |
===================================================================
|
|
|
cf42fb7 |
--- lib/block.c (revision 14810)
|
|
|
cf42fb7 |
+++ lib/block.c (revision 14811)
|
|
|
cf42fb7 |
@@ -235,7 +235,8 @@
|
|
|
cf42fb7 |
if(!ci->fullbooks){
|
|
|
cf42fb7 |
ci->fullbooks=_ogg_calloc(ci->books,sizeof(*ci->fullbooks));
|
|
|
cf42fb7 |
for(i=0;i<ci->books;i++){
|
|
|
cf42fb7 |
- vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
|
|
|
cf42fb7 |
+ if(vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]))
|
|
|
cf42fb7 |
+ return -1;
|
|
|
cf42fb7 |
/* decode codebooks are now standalone after init */
|
|
|
cf42fb7 |
vorbis_staticbook_destroy(ci->book_param[i]);
|
|
|
cf42fb7 |
ci->book_param[i]=NULL;
|
|
|
cf42fb7 |
@@ -694,9 +695,11 @@
|
|
|
cf42fb7 |
}
|
|
|
cf42fb7 |
|
|
|
cf42fb7 |
int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
|
|
|
cf42fb7 |
- if(_vds_shared_init(v,vi,0)) return 1;
|
|
|
cf42fb7 |
+ if(_vds_shared_init(v,vi,0)){
|
|
|
cf42fb7 |
+ vorbis_dsp_clear(v);
|
|
|
cf42fb7 |
+ return 1;
|
|
|
cf42fb7 |
+ }
|
|
|
cf42fb7 |
vorbis_synthesis_restart(v);
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
return 0;
|
|
|
cf42fb7 |
}
|
|
|
cf42fb7 |
|
|
|
cf42fb7 |
Index: examples/decoder_example.c
|
|
|
cf42fb7 |
===================================================================
|
|
|
cf42fb7 |
--- examples/decoder_example.c (revision 14810)
|
|
|
cf42fb7 |
+++ examples/decoder_example.c (revision 14811)
|
|
|
cf42fb7 |
@@ -198,108 +198,111 @@
|
|
|
cf42fb7 |
|
|
|
cf42fb7 |
/* OK, got and parsed all three headers. Initialize the Vorbis
|
|
|
cf42fb7 |
packet->PCM decoder. */
|
|
|
cf42fb7 |
- vorbis_synthesis_init(&vd,&vi;; /* central decode state */
|
|
|
cf42fb7 |
- vorbis_block_init(&vd,&vb;; /* local state for most of the decode
|
|
|
cf42fb7 |
- so multiple block decodes can
|
|
|
cf42fb7 |
- proceed in parallel. We could init
|
|
|
cf42fb7 |
- multiple vorbis_block structures
|
|
|
cf42fb7 |
- for vd here */
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
- /* The rest is just a straight decode loop until end of stream */
|
|
|
cf42fb7 |
- while(!eos){
|
|
|
cf42fb7 |
+ if(vorbis_synthesis_init(&vd,&vi)==0){ /* central decode state */
|
|
|
cf42fb7 |
+ vorbis_block_init(&vd,&vb;; /* local state for most of the decode
|
|
|
cf42fb7 |
+ so multiple block decodes can
|
|
|
cf42fb7 |
+ proceed in parallel. We could init
|
|
|
cf42fb7 |
+ multiple vorbis_block structures
|
|
|
cf42fb7 |
+ for vd here */
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
+ /* The rest is just a straight decode loop until end of stream */
|
|
|
cf42fb7 |
while(!eos){
|
|
|
cf42fb7 |
- int result=ogg_sync_pageout(&oy,&og);
|
|
|
cf42fb7 |
- if(result==0)break; /* need more data */
|
|
|
cf42fb7 |
- if(result<0){ /* missing or corrupt data at this page position */
|
|
|
cf42fb7 |
- fprintf(stderr,"Corrupt or missing data in bitstream; "
|
|
|
cf42fb7 |
- "continuing...\n");
|
|
|
cf42fb7 |
- }else{
|
|
|
cf42fb7 |
- ogg_stream_pagein(&os,&og); /* can safely ignore errors at
|
|
|
cf42fb7 |
- this point */
|
|
|
cf42fb7 |
- while(1){
|
|
|
cf42fb7 |
- result=ogg_stream_packetout(&os,&op);
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
- if(result==0)break; /* need more data */
|
|
|
cf42fb7 |
- if(result<0){ /* missing or corrupt data at this page position */
|
|
|
cf42fb7 |
- /* no reason to complain; already complained above */
|
|
|
cf42fb7 |
- }else{
|
|
|
cf42fb7 |
- /* we have a packet. Decode it */
|
|
|
cf42fb7 |
- float **pcm;
|
|
|
cf42fb7 |
- int samples;
|
|
|
cf42fb7 |
+ while(!eos){
|
|
|
cf42fb7 |
+ int result=ogg_sync_pageout(&oy,&og);
|
|
|
cf42fb7 |
+ if(result==0)break; /* need more data */
|
|
|
cf42fb7 |
+ if(result<0){ /* missing or corrupt data at this page position */
|
|
|
cf42fb7 |
+ fprintf(stderr,"Corrupt or missing data in bitstream; "
|
|
|
cf42fb7 |
+ "continuing...\n");
|
|
|
cf42fb7 |
+ }else{
|
|
|
cf42fb7 |
+ ogg_stream_pagein(&os,&og); /* can safely ignore errors at
|
|
|
cf42fb7 |
+ this point */
|
|
|
cf42fb7 |
+ while(1){
|
|
|
cf42fb7 |
+ result=ogg_stream_packetout(&os,&op);
|
|
|
cf42fb7 |
|
|
|
cf42fb7 |
- if(vorbis_synthesis(&vb,&op)==0) /* test for success! */
|
|
|
cf42fb7 |
- vorbis_synthesis_blockin(&vd,&vb;;
|
|
|
cf42fb7 |
- /*
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
- **pcm is a multichannel float vector. In stereo, for
|
|
|
cf42fb7 |
- example, pcm[0] is left, and pcm[1] is right. samples is
|
|
|
cf42fb7 |
- the size of each channel. Convert the float values
|
|
|
cf42fb7 |
- (-1.<=range<=1.) to whatever PCM format and write it out */
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
- while((samples=vorbis_synthesis_pcmout(&vd,&pcm))>0){
|
|
|
cf42fb7 |
- int j;
|
|
|
cf42fb7 |
- int clipflag=0;
|
|
|
cf42fb7 |
- int bout=(samples
|
|
|
cf42fb7 |
+ if(result==0)break; /* need more data */
|
|
|
cf42fb7 |
+ if(result<0){ /* missing or corrupt data at this page position */
|
|
|
cf42fb7 |
+ /* no reason to complain; already complained above */
|
|
|
cf42fb7 |
+ }else{
|
|
|
cf42fb7 |
+ /* we have a packet. Decode it */
|
|
|
cf42fb7 |
+ float **pcm;
|
|
|
cf42fb7 |
+ int samples;
|
|
|
cf42fb7 |
|
|
|
cf42fb7 |
- /* convert floats to 16 bit signed ints (host order) and
|
|
|
cf42fb7 |
- interleave */
|
|
|
cf42fb7 |
- for(i=0;i
|
|
|
cf42fb7 |
- ogg_int16_t *ptr=convbuffer+i;
|
|
|
cf42fb7 |
- float *mono=pcm[i];
|
|
|
cf42fb7 |
- for(j=0;j
|
|
|
cf42fb7 |
+ if(vorbis_synthesis(&vb,&op)==0) /* test for success! */
|
|
|
cf42fb7 |
+ vorbis_synthesis_blockin(&vd,&vb;;
|
|
|
cf42fb7 |
+ /*
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
+ **pcm is a multichannel float vector. In stereo, for
|
|
|
cf42fb7 |
+ example, pcm[0] is left, and pcm[1] is right. samples is
|
|
|
cf42fb7 |
+ the size of each channel. Convert the float values
|
|
|
cf42fb7 |
+ (-1.<=range<=1.) to whatever PCM format and write it out */
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
+ while((samples=vorbis_synthesis_pcmout(&vd,&pcm))>0){
|
|
|
cf42fb7 |
+ int j;
|
|
|
cf42fb7 |
+ int clipflag=0;
|
|
|
cf42fb7 |
+ int bout=(samples
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
+ /* convert floats to 16 bit signed ints (host order) and
|
|
|
cf42fb7 |
+ interleave */
|
|
|
cf42fb7 |
+ for(i=0;i
|
|
|
cf42fb7 |
+ ogg_int16_t *ptr=convbuffer+i;
|
|
|
cf42fb7 |
+ float *mono=pcm[i];
|
|
|
cf42fb7 |
+ for(j=0;j
|
|
|
cf42fb7 |
#if 1
|
|
|
cf42fb7 |
- int val=mono[j]*32767.f;
|
|
|
cf42fb7 |
+ int val=mono[j]*32767.f;
|
|
|
cf42fb7 |
#else /* optional dither */
|
|
|
cf42fb7 |
- int val=mono[j]*32767.f+drand48()-0.5f;
|
|
|
cf42fb7 |
+ int val=mono[j]*32767.f+drand48()-0.5f;
|
|
|
cf42fb7 |
#endif
|
|
|
cf42fb7 |
- /* might as well guard against clipping */
|
|
|
cf42fb7 |
- if(val>32767){
|
|
|
cf42fb7 |
- val=32767;
|
|
|
cf42fb7 |
- clipflag=1;
|
|
|
cf42fb7 |
+ /* might as well guard against clipping */
|
|
|
cf42fb7 |
+ if(val>32767){
|
|
|
cf42fb7 |
+ val=32767;
|
|
|
cf42fb7 |
+ clipflag=1;
|
|
|
cf42fb7 |
+ }
|
|
|
cf42fb7 |
+ if(val<-32768){
|
|
|
cf42fb7 |
+ val=-32768;
|
|
|
cf42fb7 |
+ clipflag=1;
|
|
|
cf42fb7 |
+ }
|
|
|
cf42fb7 |
+ *ptr=val;
|
|
|
cf42fb7 |
+ ptr+=vi.channels;
|
|
|
cf42fb7 |
}
|
|
|
cf42fb7 |
- if(val<-32768){
|
|
|
cf42fb7 |
- val=-32768;
|
|
|
cf42fb7 |
- clipflag=1;
|
|
|
cf42fb7 |
- }
|
|
|
cf42fb7 |
- *ptr=val;
|
|
|
cf42fb7 |
- ptr+=vi.channels;
|
|
|
cf42fb7 |
}
|
|
|
cf42fb7 |
- }
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
- if(clipflag)
|
|
|
cf42fb7 |
- fprintf(stderr,"Clipping in frame %ld\n",(long)(vd.sequence));
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
- fwrite(convbuffer,2*vi.channels,bout,stdout);
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
- vorbis_synthesis_read(&vd,bout); /* tell libvorbis how
|
|
|
cf42fb7 |
- many samples we
|
|
|
cf42fb7 |
- actually consumed */
|
|
|
cf42fb7 |
- }
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
+ if(clipflag)
|
|
|
cf42fb7 |
+ fprintf(stderr,"Clipping in frame %ld\n",(long)(vd.sequence));
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
+ fwrite(convbuffer,2*vi.channels,bout,stdout);
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
+ vorbis_synthesis_read(&vd,bout); /* tell libvorbis how
|
|
|
cf42fb7 |
+ many samples we
|
|
|
cf42fb7 |
+ actually consumed */
|
|
|
cf42fb7 |
+ }
|
|
|
cf42fb7 |
+ }
|
|
|
cf42fb7 |
}
|
|
|
cf42fb7 |
+ if(ogg_page_eos(&og))eos=1;
|
|
|
cf42fb7 |
}
|
|
|
cf42fb7 |
- if(ogg_page_eos(&og))eos=1;
|
|
|
cf42fb7 |
}
|
|
|
cf42fb7 |
+ if(!eos){
|
|
|
cf42fb7 |
+ buffer=ogg_sync_buffer(&oy,4096);
|
|
|
cf42fb7 |
+ bytes=fread(buffer,1,4096,stdin);
|
|
|
cf42fb7 |
+ ogg_sync_wrote(&oy,bytes);
|
|
|
cf42fb7 |
+ if(bytes==0)eos=1;
|
|
|
cf42fb7 |
+ }
|
|
|
cf42fb7 |
}
|
|
|
cf42fb7 |
- if(!eos){
|
|
|
cf42fb7 |
- buffer=ogg_sync_buffer(&oy,4096);
|
|
|
cf42fb7 |
- bytes=fread(buffer,1,4096,stdin);
|
|
|
cf42fb7 |
- ogg_sync_wrote(&oy,bytes);
|
|
|
cf42fb7 |
- if(bytes==0)eos=1;
|
|
|
cf42fb7 |
- }
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
+ /* ogg_page and ogg_packet structs always point to storage in
|
|
|
cf42fb7 |
+ libvorbis. They're never freed or manipulated directly */
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
+ vorbis_block_clear(&vb;;
|
|
|
cf42fb7 |
+ vorbis_dsp_clear(&vd);
|
|
|
cf42fb7 |
+ }else{
|
|
|
cf42fb7 |
+ fprintf(stderr,"Error: Corrupt header during playback initialization.\n");
|
|
|
cf42fb7 |
}
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
/* clean up this logical bitstream; before exit we see if we're
|
|
|
cf42fb7 |
followed by another [chained] */
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
+
|
|
|
cf42fb7 |
ogg_stream_clear(&os);
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
- /* ogg_page and ogg_packet structs always point to storage in
|
|
|
cf42fb7 |
- libvorbis. They're never freed or manipulated directly */
|
|
|
cf42fb7 |
-
|
|
|
cf42fb7 |
- vorbis_block_clear(&vb;;
|
|
|
cf42fb7 |
- vorbis_dsp_clear(&vd);
|
|
|
cf42fb7 |
- vorbis_comment_clear(&vc);
|
|
|
cf42fb7 |
+ vorbis_comment_clear(&vc);
|
|
|
cf42fb7 |
vorbis_info_clear(&vi;; /* must be called last */
|
|
|
cf42fb7 |
}
|
|
|
cf42fb7 |
|