Browse Source

update libvorbis 135

Johxz 8 years ago
parent
commit
d474b891df

+ 15 - 0
Engine/lib/libvorbis/CHANGES

@@ -1,3 +1,18 @@
+libvorbis 1.3.5 (unreleased) -- "Xiph.Org libVorbis I 20150105 (⛄⛄⛄⛄)"
+
+* Tolerate single-entry codebooks.
+* Fix decoder crash with invalid input.
+* Fix encoder crash with non-positive sample rates.
+# Fix issues in vorbisfile's seek bisection code.
+* Spec errata.
+* Reject multiple headers of the same type.
+* Various build fixes and code cleanup.
+
+libvorbis 1.3.4 (2014-01-22) -- "Xiph.Org libVorbis I 20140122 (Turpakäräjiin)"
+
+* Reduce codebook footprint in library code.
+* Various build and documentation fixes.
+
 libvorbis 1.3.3 (2012-02-03) -- "Xiph.Org libVorbis I 20120203 (Omnipresent)"
 
 * vorbis: additional proofing against invalid/malicious 

+ 64 - 0
Engine/lib/libvorbis/lib/barkmel.c

@@ -0,0 +1,64 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
+ *                                                                  *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
+ *                                                                  *
+ ********************************************************************
+
+ function: bark scale utility
+ last mod: $Id: barkmel.c 19454 2015-03-02 22:39:28Z xiphmont $
+
+ ********************************************************************/
+
+#include <stdio.h>
+#include "scales.h"
+int main(){
+  int i;
+  double rate;
+  for(i=64;i<32000;i*=2){
+    rate=48000.f;
+    fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n",
+            rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2));
+
+    rate=44100.f;
+    fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n",
+            rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2));
+
+    rate=32000.f;
+    fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n",
+            rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2));
+
+    rate=22050.f;
+    fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n",
+            rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2));
+
+    rate=16000.f;
+    fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n",
+            rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2));
+
+    rate=11025.f;
+    fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n",
+            rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2));
+
+    rate=8000.f;
+    fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n\n",
+            rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2));
+
+
+  }
+  {
+    float i;
+    int j;
+    for(i=0.,j=0;i<28;i+=1,j++){
+      fprintf(stderr,"(%d) bark=%f %gHz (%d of 128)\n",
+              j,i,fromBARK(i),(int)(fromBARK(i)/22050.*128.));
+    }
+  }
+  return(0);
+}
+

+ 22 - 21
Engine/lib/libvorbis/lib/block.c

@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c 17561 2010-10-23 10:34:24Z xiphmont $
+ last mod: $Id: block.c 19457 2015-03-03 00:15:29Z giles $
 
  Handle windowing, overlap-add, etc of the PCM vectors.  This is made
  more amusing by Vorbis' current two allowed block sizes.
@@ -31,16 +31,6 @@
 #include "registry.h"
 #include "misc.h"
 
-static int ilog2(unsigned int v){
-  int ret=0;
-  if(v)--v;
-  while(v){
-    ret++;
-    v>>=1;
-  }
-  return(ret);
-}
-
 /* pcm accumulator examples (not exhaustive):
 
  <-------------- lW ---------------->
@@ -184,14 +174,19 @@ static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
   private_state *b=NULL;
   int hs;
 
-  if(ci==NULL) return 1;
+  if(ci==NULL||
+     ci->modes<=0||
+     ci->blocksizes[0]<64||
+     ci->blocksizes[1]<ci->blocksizes[0]){
+    return 1;
+  }
   hs=ci->halfrate_flag;
 
   memset(v,0,sizeof(*v));
   b=v->backend_state=_ogg_calloc(1,sizeof(*b));
 
   v->vi=vi;
-  b->modebits=ilog2(ci->modes);
+  b->modebits=ov_ilog(ci->modes-1);
 
   b->transform[0]=_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
   b->transform[1]=_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
@@ -204,8 +199,14 @@ static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
   mdct_init(b->transform[1][0],ci->blocksizes[1]>>hs);
 
   /* Vorbis I uses only window type 0 */
-  b->window[0]=ilog2(ci->blocksizes[0])-6;
-  b->window[1]=ilog2(ci->blocksizes[1])-6;
+  /* note that the correct computation below is technically:
+       b->window[0]=ov_ilog(ci->blocksizes[0]-1)-6;
+       b->window[1]=ov_ilog(ci->blocksizes[1]-1)-6;
+    but since blocksizes are always powers of two,
+    the below is equivalent.
+   */
+  b->window[0]=ov_ilog(ci->blocksizes[0])-7;
+  b->window[1]=ov_ilog(ci->blocksizes[1])-7;
 
   if(encp){ /* encode/decode differ here */
 
@@ -771,14 +772,14 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
       if(v->lW){
         if(v->W){
           /* large/large */
-          float *w=_vorbis_window_get(b->window[1]-hs);
+          const float *w=_vorbis_window_get(b->window[1]-hs);
           float *pcm=v->pcm[j]+prevCenter;
           float *p=vb->pcm[j];
           for(i=0;i<n1;i++)
             pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
         }else{
           /* large/small */
-          float *w=_vorbis_window_get(b->window[0]-hs);
+          const float *w=_vorbis_window_get(b->window[0]-hs);
           float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
           float *p=vb->pcm[j];
           for(i=0;i<n0;i++)
@@ -787,7 +788,7 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
       }else{
         if(v->W){
           /* small/large */
-          float *w=_vorbis_window_get(b->window[0]-hs);
+          const float *w=_vorbis_window_get(b->window[0]-hs);
           float *pcm=v->pcm[j]+prevCenter;
           float *p=vb->pcm[j]+n1/2-n0/2;
           for(i=0;i<n0;i++)
@@ -796,7 +797,7 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
             pcm[i]=p[i];
         }else{
           /* small/small */
-          float *w=_vorbis_window_get(b->window[0]-hs);
+          const float *w=_vorbis_window_get(b->window[0]-hs);
           float *pcm=v->pcm[j]+prevCenter;
           float *p=vb->pcm[j];
           for(i=0;i<n0;i++)
@@ -1035,7 +1036,7 @@ int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
 
 }
 
-float *vorbis_window(vorbis_dsp_state *v,int W){
+const float *vorbis_window(vorbis_dsp_state *v,int W){
   vorbis_info *vi=v->vi;
   codec_setup_info *ci=vi->codec_setup;
   int hs=ci->halfrate_flag;

File diff suppressed because it is too large
+ 131 - 114
Engine/lib/libvorbis/lib/books/coupled/res_books_51.h


File diff suppressed because it is too large
+ 114 - 114
Engine/lib/libvorbis/lib/books/coupled/res_books_stereo.h


File diff suppressed because it is too large
+ 132 - 132
Engine/lib/libvorbis/lib/books/floor/floor_books.h


File diff suppressed because it is too large
+ 113 - 113
Engine/lib/libvorbis/lib/books/uncoupled/res_books_uncoupled.h


+ 14 - 8
Engine/lib/libvorbis/lib/codebook.c

@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c 18183 2012-02-03 20:51:27Z xiphmont $
+ last mod: $Id: codebook.c 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
@@ -53,16 +53,16 @@ int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
     oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
 
     for(i=1;i<c->entries;i++){
-      long this=c->lengthlist[i];
-      long last=c->lengthlist[i-1];
+      char this=c->lengthlist[i];
+      char last=c->lengthlist[i-1];
       if(this>last){
         for(j=last;j<this;j++){
-          oggpack_write(opb,i-count,_ilog(c->entries-count));
+          oggpack_write(opb,i-count,ov_ilog(c->entries-count));
           count=i;
         }
       }
     }
-    oggpack_write(opb,i-count,_ilog(c->entries-count));
+    oggpack_write(opb,i-count,ov_ilog(c->entries-count));
 
   }else{
     /* length random.  Again, we don't code the codeword itself, just
@@ -159,7 +159,7 @@ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){
   s->entries=oggpack_read(opb,24);
   if(s->entries==-1)goto _eofout;
 
-  if(_ilog(s->dim)+_ilog(s->entries)>24)goto _eofout;
+  if(ov_ilog(s->dim)+ov_ilog(s->entries)>24)goto _eofout;
 
   /* codeword ordering.... length ordered or unordered? */
   switch((int)oggpack_read(opb,1)){
@@ -203,7 +203,7 @@ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){
       s->lengthlist=_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
 
       for(i=0;i<s->entries;){
-        long num=oggpack_read(opb,_ilog(s->entries-i));
+        long num=oggpack_read(opb,ov_ilog(s->entries-i));
         if(num==-1)goto _eofout;
         if(length>32 || num>s->entries-i ||
            (num>0 && (num-1)>>(length-1)>1)){
@@ -312,6 +312,12 @@ STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
     hi=book->used_entries;
   }
 
+  /* Single entry codebooks use a firsttablen of 1 and a
+     dec_maxlength of 1.  If a single-entry codebook gets here (due to
+     failure to read one bit above), the next look attempt will also
+     fail and we'll correctly kick out instead of trying to walk the
+     underformed tree */
+
   lok = oggpack_look(b, read);
 
   while(lok<0 && read>1)

+ 8 - 9
Engine/lib/libvorbis/lib/codebook.h

@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: basic shared codebook operations
- last mod: $Id: codebook.h 17030 2010-03-25 06:52:55Z xiphmont $
+ last mod: $Id: codebook.h 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
@@ -34,14 +34,14 @@
 */
 
 typedef struct static_codebook{
-  long   dim;            /* codebook dimensions (elements per vector) */
-  long   entries;        /* codebook entries */
-  long  *lengthlist;     /* codeword lengths in bits */
+  long   dim;           /* codebook dimensions (elements per vector) */
+  long   entries;       /* codebook entries */
+  char  *lengthlist;    /* codeword lengths in bits */
 
   /* mapping ***************************************************************/
-  int    maptype;        /* 0=none
-                            1=implicitly populated values from map column
-                            2=listed arbitrary values */
+  int    maptype;       /* 0=none
+                           1=implicitly populated values from map column
+                           2=listed arbitrary values */
 
   /* The below does a linear, single monotonic sequence mapping. */
   long     q_min;       /* packed 32 bit float; quant value 0 maps to minval */
@@ -89,7 +89,6 @@ extern float *_book_logdist(const static_codebook *b,float *vals);
 extern float _float32_unpack(long val);
 extern long   _float32_pack(float val);
 extern int  _best(codebook *book, float *a, int step);
-extern int _ilog(unsigned int v);
 extern long _book_maptype1_quantvals(const static_codebook *b);
 
 extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);

+ 6 - 3
Engine/lib/libvorbis/lib/floor0.c

@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: floor backend 0 implementation
- last mod: $Id: floor0.c 18184 2012-02-03 20:55:12Z xiphmont $
+ last mod: $Id: floor0.c 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
@@ -147,6 +147,9 @@ static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
                                       vorbis_info_floor *i){
   vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
   vorbis_look_floor0 *look=_ogg_calloc(1,sizeof(*look));
+
+  (void)vd;
+
   look->m=info->order;
   look->ln=info->barkmap;
   look->vi=info;
@@ -165,7 +168,7 @@ static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
   if(ampraw>0){ /* also handles the -1 out of data case */
     long maxval=(1<<info->ampbits)-1;
     float amp=(float)ampraw/maxval*info->ampdB;
-    int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
+    int booknum=oggpack_read(&vb->opb,ov_ilog(info->numbooks));
 
     if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
       codec_setup_info  *ci=vb->vd->vi->codec_setup;

+ 16 - 29
Engine/lib/libvorbis/lib/floor1.c

@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: floor backend 1 implementation
- last mod: $Id: floor1.c 18151 2012-01-20 07:35:26Z xiphmont $
+ last mod: $Id: floor1.c 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
@@ -72,25 +72,6 @@ static void floor1_free_look(vorbis_look_floor *i){
   }
 }
 
-static int ilog(unsigned int v){
-  int ret=0;
-  while(v){
-    ret++;
-    v>>=1;
-  }
-  return(ret);
-}
-
-static int ilog2(unsigned int v){
-  int ret=0;
-  if(v)--v;
-  while(v){
-    ret++;
-    v>>=1;
-  }
-  return(ret);
-}
-
 static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
   vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
   int j,k;
@@ -117,8 +98,10 @@ static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
 
   /* save out the post list */
   oggpack_write(opb,info->mult-1,2);     /* only 1,2,3,4 legal now */
-  oggpack_write(opb,ilog2(maxposit),4);
-  rangebits=ilog2(maxposit);
+  /* maxposit cannot legally be less than 1; this is encode-side, we
+     can assume our setup is OK */
+  oggpack_write(opb,ov_ilog(maxposit-1),4);
+  rangebits=ov_ilog(maxposit-1);
 
   for(j=0,k=0;j<info->partitions;j++){
     count+=info->class_dim[info->partitionclass[j]];
@@ -203,6 +186,8 @@ static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
   vorbis_look_floor1 *look=_ogg_calloc(1,sizeof(*look));
   int i,j,n=0;
 
+  (void)vd;
+
   look->vi=info;
   look->n=info->postlist[1];
 
@@ -852,9 +837,9 @@ int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
 
     /* beginning/end post */
     look->frames++;
-    look->postbits+=ilog(look->quant_q-1)*2;
-    oggpack_write(opb,out[0],ilog(look->quant_q-1));
-    oggpack_write(opb,out[1],ilog(look->quant_q-1));
+    look->postbits+=ov_ilog(look->quant_q-1)*2;
+    oggpack_write(opb,out[0],ov_ilog(look->quant_q-1));
+    oggpack_write(opb,out[1],ov_ilog(look->quant_q-1));
 
 
     /* partition by partition */
@@ -870,7 +855,9 @@ int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
 
       /* generate the partition's first stage cascade value */
       if(csubbits){
-        int maxval[8];
+        int maxval[8]={0,0,0,0,0,0,0,0}; /* gcc's static analysis
+                                            issues a warning without
+                                            initialization */
         for(k=0;k<csub;k++){
           int booknum=info->class_subbook[class][k];
           if(booknum<0){
@@ -978,8 +965,8 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
   if(oggpack_read(&vb->opb,1)==1){
     int *fit_value=_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
 
-    fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
-    fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
+    fit_value[0]=oggpack_read(&vb->opb,ov_ilog(look->quant_q-1));
+    fit_value[1]=oggpack_read(&vb->opb,ov_ilog(look->quant_q-1));
 
     /* partition by partition */
     for(i=0,j=2;i<info->partitions;i++){

+ 24 - 19
Engine/lib/libvorbis/lib/info.c

@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2010             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: maintain the info structure, info <-> header packets
- last mod: $Id: info.c 18186 2012-02-03 22:08:44Z xiphmont $
+ last mod: $Id: info.c 19441 2015-01-21 01:17:41Z xiphmont $
 
  ********************************************************************/
 
@@ -31,20 +31,10 @@
 #include "misc.h"
 #include "os.h"
 
-#define GENERAL_VENDOR_STRING "Xiph.Org libVorbis 1.3.3"
-#define ENCODE_VENDOR_STRING "Xiph.Org libVorbis I 20120203 (Omnipresent)"
+#define GENERAL_VENDOR_STRING "Xiph.Org libVorbis 1.3.5"
+#define ENCODE_VENDOR_STRING "Xiph.Org libVorbis I 20150105 (⛄⛄⛄⛄)"
 
 /* helpers */
-static int ilog2(unsigned int v){
-  int ret=0;
-  if(v)--v;
-  while(v){
-    ret++;
-    v>>=1;
-  }
-  return(ret);
-}
-
 static void _v_writestring(oggpack_buffer *o,const char *s, int bytes){
 
   while(bytes--){
@@ -272,7 +262,6 @@ static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
 static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
   codec_setup_info     *ci=vi->codec_setup;
   int i;
-  if(!ci)return(OV_EFAULT);
 
   /* codebooks */
   ci->books=oggpack_read(opb,8)+1;
@@ -411,6 +400,10 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op)
           /* um... we didn't get the initial header */
           return(OV_EBADHEADER);
         }
+        if(vc->vendor!=NULL){
+          /* previously initialized comment header */
+          return(OV_EBADHEADER);
+        }
 
         return(_vorbis_unpack_comment(vc,&opb));
 
@@ -419,6 +412,14 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op)
           /* um... we didn;t get the initial header or comments yet */
           return(OV_EBADHEADER);
         }
+        if(vi->codec_setup==NULL){
+          /* improperly initialized vorbis_info */
+          return(OV_EFAULT);
+        }
+        if(((codec_setup_info *)vi->codec_setup)->books>0){
+          /* previously initialized setup header */
+          return(OV_EBADHEADER);
+        }
 
         return(_vorbis_unpack_books(vi,&opb));
 
@@ -436,7 +437,11 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op)
 
 static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
   codec_setup_info     *ci=vi->codec_setup;
-  if(!ci)return(OV_EFAULT);
+  if(!ci||
+     ci->blocksizes[0]<64||
+     ci->blocksizes[1]<ci->blocksizes[0]){
+    return(OV_EFAULT);
+  }
 
   /* preamble */
   oggpack_write(opb,0x01,8);
@@ -451,8 +456,8 @@ static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
   oggpack_write(opb,vi->bitrate_nominal,32);
   oggpack_write(opb,vi->bitrate_lower,32);
 
-  oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
-  oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
+  oggpack_write(opb,ov_ilog(ci->blocksizes[0]-1),4);
+  oggpack_write(opb,ov_ilog(ci->blocksizes[1]-1),4);
   oggpack_write(opb,1,1);
 
   return(0);
@@ -578,7 +583,7 @@ int vorbis_analysis_headerout(vorbis_dsp_state *v,
   oggpack_buffer opb;
   private_state *b=v->backend_state;
 
-  if(!b){
+  if(!b||vi->channels<=0){
     ret=OV_EFAULT;
     goto err_out;
   }

+ 142 - 0
Engine/lib/libvorbis/lib/lookups.pl

@@ -0,0 +1,142 @@
+#!/usr/bin/perl
+print <<'EOD';
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
+ *                                                                  *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
+ *                                                                  *
+ ********************************************************************
+
+  function: lookup data; generated by lookups.pl; edit there
+  last mod: $Id: lookups.pl 13293 2007-07-24 00:09:47Z xiphmont $
+
+ ********************************************************************/
+
+#ifndef _V_LOOKUP_DATA_H_
+
+#ifdef FLOAT_LOOKUP
+EOD
+
+$cos_sz=128;
+$invsq_sz=32;
+$invsq2exp_min=-32;
+$invsq2exp_max=32;
+
+$fromdB_sz=35;
+$fromdB_shift=5;
+$fromdB2_shift=3;
+
+$invsq_i_shift=10;
+$cos_i_shift=9;
+$delta_shift=6;
+
+print "#define COS_LOOKUP_SZ $cos_sz\n";
+print "static float COS_LOOKUP[COS_LOOKUP_SZ+1]={\n";
+
+for($i=0;$i<=$cos_sz;){
+    print "\t";
+    for($j=0;$j<4 && $i<=$cos_sz;$j++){
+	printf "%+.13f,", cos(3.14159265358979323846*($i++)/$cos_sz) ;
+    }
+    print "\n";
+}
+print "};\n\n";
+
+print "#define INVSQ_LOOKUP_SZ $invsq_sz\n";
+print "static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={\n";
+
+for($i=0;$i<=$invsq_sz;){
+    print "\t";
+    for($j=0;$j<4 && $i<=$invsq_sz;$j++){
+	my$indexmap=$i++/$invsq_sz*.5+.5;
+	printf "%.12f,", 1./sqrt($indexmap);
+    }
+    print "\n";
+}
+print "};\n\n";
+
+print "#define INVSQ2EXP_LOOKUP_MIN $invsq2exp_min\n";
+print "#define INVSQ2EXP_LOOKUP_MAX $invsq2exp_max\n";
+print "static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\\\n".
+      "                              INVSQ2EXP_LOOKUP_MIN+1]={\n";
+
+for($i=$invsq2exp_min;$i<=$invsq2exp_max;){
+    print "\t";
+    for($j=0;$j<4 && $i<=$invsq2exp_max;$j++){
+	printf "%15.10g,", 2**($i++*-.5);
+    }
+    print "\n";
+}
+print "};\n\n#endif\n\n";
+
+
+# 0 to -140 dB
+$fromdB2_sz=1<<$fromdB_shift;
+$fromdB_gran=1<<($fromdB_shift-$fromdB2_shift);
+print "#define FROMdB_LOOKUP_SZ $fromdB_sz\n";
+print "#define FROMdB2_LOOKUP_SZ $fromdB2_sz\n";
+print "#define FROMdB_SHIFT $fromdB_shift\n";
+print "#define FROMdB2_SHIFT $fromdB2_shift\n";
+print "#define FROMdB2_MASK ".((1<<$fromdB_shift)-1)."\n";
+
+print "static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={\n";
+
+for($i=0;$i<$fromdB_sz;){
+    print "\t";
+    for($j=0;$j<4 && $i<$fromdB_sz;$j++){
+	printf "%15.10g,", 10**(.05*(-$fromdB_gran*$i++));
+    }
+    print "\n";
+}
+print "};\n\n";
+
+print "static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={\n";
+
+for($i=0;$i<$fromdB2_sz;){
+    print "\t";
+    for($j=0;$j<4 && $i<$fromdB_sz;$j++){
+	printf "%15.10g,", 10**(.05*(-$fromdB_gran/$fromdB2_sz*(.5+$i++)));
+    }
+    print "\n";
+}
+print "};\n\n#ifdef INT_LOOKUP\n\n";
+
+
+$iisz=0x10000>>$invsq_i_shift;
+print "#define INVSQ_LOOKUP_I_SHIFT $invsq_i_shift\n";
+print "#define INVSQ_LOOKUP_I_MASK ".(0x0ffff>>(16-$invsq_i_shift))."\n";
+print "static long INVSQ_LOOKUP_I[$iisz+1]={\n";
+for($i=0;$i<=$iisz;){
+    print "\t";
+    for($j=0;$j<4 && $i<=$iisz;$j++){
+	my$indexmap=$i++/$iisz*.5+.5;
+	printf "%8d,", int(1./sqrt($indexmap)*65536.+.5);
+    }
+    print "\n";
+}
+print "};\n\n";
+
+$cisz=0x10000>>$cos_i_shift;
+print "#define COS_LOOKUP_I_SHIFT $cos_i_shift\n";
+print "#define COS_LOOKUP_I_MASK ".(0x0ffff>>(16-$cos_i_shift))."\n";
+print "#define COS_LOOKUP_I_SZ $cisz\n";
+print "static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={\n";
+
+for($i=0;$i<=$cisz;){
+    print "\t";
+    for($j=0;$j<4 && $i<=$cisz;$j++){
+	printf "%8d,", int(cos(3.14159265358979323846*($i++)/$cos_sz)*16384.+.5) ;
+    }
+    print "\n";
+}
+print "};\n\n";
+
+
+print "#endif\n\n#endif\n";
+
+

+ 1 - 3
Engine/lib/libvorbis/lib/lsp.c

@@ -11,7 +11,7 @@
  ********************************************************************
 
   function: LSP (also called LSF) conversion routines
-  last mod: $Id: lsp.c 17538 2010-10-15 02:52:29Z tterribe $
+  last mod: $Id: lsp.c 19453 2015-03-02 22:35:34Z xiphmont $
 
   The LSP generation code is taken (with minimal modification and a
   few bugfixes) from "On the Computation of the LSP Frequencies" by
@@ -309,7 +309,6 @@ static int comp(const void *a,const void *b){
 #define EPSILON 10e-7
 static int Laguerre_With_Deflation(float *a,int ord,float *r){
   int i,m;
-  double lastdelta=0.f;
   double *defl=alloca(sizeof(*defl)*(ord+1));
   for(i=0;i<=ord;i++)defl[i]=a[i];
 
@@ -346,7 +345,6 @@ static int Laguerre_With_Deflation(float *a,int ord,float *r){
       if(delta<0.f)delta*=-1;
 
       if(fabs(delta/new)<10e-12)break;
-      lastdelta=delta;
     }
 
     r[m-1]=new;

+ 9 - 15
Engine/lib/libvorbis/lib/mapping0.c

@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: channel mapping 0 implementation
- last mod: $Id: mapping0.c 17022 2010-03-25 03:45:42Z xiphmont $
+ last mod: $Id: mapping0.c 19441 2015-01-21 01:17:41Z xiphmont $
 
  ********************************************************************/
 
@@ -45,16 +45,6 @@ static void mapping0_free_info(vorbis_info_mapping *i){
   }
 }
 
-static int ilog(unsigned int v){
-  int ret=0;
-  if(v)--v;
-  while(v){
-    ret++;
-    v>>=1;
-  }
-  return(ret);
-}
-
 static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
                           oggpack_buffer *opb){
   int i;
@@ -78,8 +68,8 @@ static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
     oggpack_write(opb,info->coupling_steps-1,8);
 
     for(i=0;i<info->coupling_steps;i++){
-      oggpack_write(opb,info->coupling_mag[i],ilog(vi->channels));
-      oggpack_write(opb,info->coupling_ang[i],ilog(vi->channels));
+      oggpack_write(opb,info->coupling_mag[i],ov_ilog(vi->channels-1));
+      oggpack_write(opb,info->coupling_ang[i],ov_ilog(vi->channels-1));
     }
   }else
     oggpack_write(opb,0,1);
@@ -104,6 +94,7 @@ static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb)
   vorbis_info_mapping0 *info=_ogg_calloc(1,sizeof(*info));
   codec_setup_info     *ci=vi->codec_setup;
   memset(info,0,sizeof(*info));
+  if(vi->channels<=0)goto err_out;
 
   b=oggpack_read(opb,1);
   if(b<0)goto err_out;
@@ -119,8 +110,11 @@ static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb)
     info->coupling_steps=oggpack_read(opb,8)+1;
     if(info->coupling_steps<=0)goto err_out;
     for(i=0;i<info->coupling_steps;i++){
-      int testM=info->coupling_mag[i]=oggpack_read(opb,ilog(vi->channels));
-      int testA=info->coupling_ang[i]=oggpack_read(opb,ilog(vi->channels));
+      /* vi->channels > 0 is enforced in the caller */
+      int testM=info->coupling_mag[i]=
+        oggpack_read(opb,ov_ilog(vi->channels-1));
+      int testA=info->coupling_ang[i]=
+        oggpack_read(opb,ov_ilog(vi->channels-1));
 
       if(testM<0 ||
          testA<0 ||

+ 3 - 2
Engine/lib/libvorbis/lib/misc.h

@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: miscellaneous prototypes
- last mod: $Id: misc.h 16227 2009-07-08 06:58:46Z xiphmont $
+ last mod: $Id: misc.h 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
@@ -21,6 +21,7 @@
 
 extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
 extern void _vorbis_block_ripcord(vorbis_block *vb);
+extern int ov_ilog(ogg_uint32_t v);
 
 #ifdef ANALYSIS
 extern int analysis_noisy;

+ 1 - 1
Engine/lib/libvorbis/lib/modes/residue_44p51.h

@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: toplevel residue templates for 32/44.1/48kHz uncoupled
- last mod: $Id$
+ last mod: $Id: residue_44p51.h 19013 2013-11-12 04:04:50Z giles $
 
  ********************************************************************/
 

+ 1 - 1
Engine/lib/libvorbis/lib/modes/setup_44p51.h

@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: toplevel settings for 44.1/48kHz 5.1 surround modes
- last mod: $Id$
+ last mod: $Id: setup_44p51.h 19013 2013-11-12 04:04:50Z giles $
 
  ********************************************************************/
 

+ 9 - 4
Engine/lib/libvorbis/lib/os.h

@@ -7,13 +7,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: #ifdef jail to whip a few platforms into the UNIX ideal.
- last mod: $Id: os.h 16227 2009-07-08 06:58:46Z xiphmont $
+ last mod: $Id: os.h 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
@@ -119,8 +119,9 @@ static inline int vorbis_ftoi(double f){  /* yes, double!  Otherwise,
 
 
 /* MSVC inline assembly. 32 bit only; inline ASM isn't implemented in the
- * 64 bit compiler */
-#if defined(_MSC_VER) && !defined(_WIN64) && !defined(_WIN32_WCE)
+ * 64 bit compiler and doesn't work on arm. */
+#if defined(_MSC_VER) && !defined(_WIN64) && \
+      !defined(_WIN32_WCE) && !defined(_M_ARM)
 #  define VORBIS_FPU_CONTROL
 
 typedef ogg_int16_t vorbis_fpu_control;
@@ -135,9 +136,11 @@ static __inline int vorbis_ftoi(double f){
 }
 
 static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
+  (void)fpu;
 }
 
 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
+  (void)fpu;
 }
 
 #endif /* Special MSVC 32 bit implementation */
@@ -156,9 +159,11 @@ static __inline int vorbis_ftoi(double f){
 }
 
 static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
+  (void)fpu;
 }
 
 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
+  (void)fpu;
 }
 
 #endif /* Special MSVC x64 implementation */

+ 524 - 0
Engine/lib/libvorbis/lib/psytune.c

@@ -0,0 +1,524 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
+ *                                                                  *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
+ *                                                                  *
+ ********************************************************************
+
+ function: simple utility that runs audio through the psychoacoustics
+           without encoding
+ last mod: $Id: psytune.c 16037 2009-05-26 21:10:58Z xiphmont $
+
+ ********************************************************************/
+
+/* NB: this is dead code, retained purely for doc and reference value
+       don't try to compile it */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "vorbis/codec.h"
+#include "codec_internal.h"
+#include "os.h"
+#include "misc.h"
+#include "psy.h"
+#include "mdct.h"
+#include "smallft.h"
+#include "window.h"
+#include "scales.h"
+#include "lpc.h"
+#include "lsp.h"
+#include "masking.h"
+#include "registry.h"
+
+static vorbis_info_psy_global _psy_set0G={
+  0,   /* decaydBpms */
+  8,   /* lines per eighth octave */
+  
+  /* thresh sample period, preecho clamp trigger threshhold, range, minenergy */
+  256, {26.f,26.f,26.f,30.f}, {-90.f,-90.f,-90.f,-90.f}, -90.f,
+  -6.f, 
+  
+  0,
+
+  0.,
+  0.,
+};
+
+static vp_part _vp_part0[]={
+  {    1,9e10f, 9e10f,       1.f,9999.f},
+  { 9999,  .75f, 9e10f,       .5f,9999.f},
+/*{ 9999, 1.5f, 9e10f,       .5f,9999.f},*/
+  {   18,9e10f, 9e10f,       .5f,  30.f},
+  { 9999,9e10f, 9e10f,       .5f,  30.f}
+};
+
+static vp_couple _vp_couple0[]={
+  {    1,  {9e10f,9e10f,0}, {   0.f,   0.f,0}, {   0.f, 0.f,0}, {0.f,0.f,0}},
+  {   18,  {9e10f,9e10f,0}, {   0.f,   0.f,0}, {   0.f, 0.f,0}, {0.f,0.f,0}},
+  { 9999,  {9e10f,9e10f,0}, {   0.f, 9e10f,0}, {   0.f,22.f,1}, {0.f,0.f,0}}
+};
+
+static vorbis_info_psy _psy_set0={
+  ATH_Bark_dB_lineaggressive,
+  
+  -100.f,
+  -140.f,
+  6.f, /* floor master att */
+
+  /*     0  1  2   3   4   5   6   7   8   9  10  11  12  13  14  15   16   */
+  /* x: 63 88 125 175 250 350 500 700 1k 1.4k 2k 2.8k 4k 5.6k 8k 11.5k 16k Hz */
+  /* y: 0 10 20 30 40 50 60 70 80 90 100 dB */
+   1,  /* tonemaskp */
+  0.f, /* tone master att */
+  /*  0   10   20   30   40   50   60   70   80   90   100 */
+  {
+   {-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f}, /*63*/
+   {-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f}, /*88*/
+   {-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f,-999.f}, /*125*/
+
+   {-30.f,-30.f,-35.f,-40.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*175*/
+   {-30.f,-30.f,-35.f,-40.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*250*/
+   {-30.f,-30.f,-35.f,-40.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*350*/
+   {-30.f,-30.f,-35.f,-40.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*500*/
+   {-30.f,-30.f,-35.f,-40.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*700*/
+   {-30.f,-30.f,-35.f,-40.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*1000*/
+   {-30.f,-30.f,-35.f,-40.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*1400*/
+   {-40.f,-40.f,-40.f,-40.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*2000*/
+   {-40.f,-40.f,-40.f,-40.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*2800*/
+   {-40.f,-40.f,-40.f,-40.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*4000*/
+
+   {-30.f,-35.f,-35.f,-40.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*5600*/
+
+   {-30.f,-30.f,-33.f,-35.f,-40.f,-50.f,-60.f,-70.f,-80.f,-90.f,-100.f}, /*8000*/
+   {-30.f,-30.f,-33.f,-35.f,-40.f,-45.f,-50.f,-60.f,-70.f,-85.f,-100.f}, /*11500*/
+   {-24.f,-24.f,-26.f,-32.f,-32.f,-42.f,-50.f,-60.f,-70.f,-85.f,-100.f}, /*16000*/
+
+  },
+
+  1,/* peakattp */
+  {{-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*63*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*88*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*125*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*175*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*250*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*350*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*500*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*700*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*1000*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*1400*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*2000*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*2800*/
+   {-14.f,-20.f,-20.f,-20.f,-26.f,-32.f,-40.f,-40.f,-40.f,-40.f,-40.f},/*4000*/
+   {-10.f,-12.f,-14.f,-16.f,-16.f,-20.f,-24.f,-30.f,-32.f,-40.f,-40.f},/*5600*/
+   {-10.f,-12.f,-14.f,-16.f,-16.f,-20.f,-24.f,-30.f,-32.f,-40.f,-40.f},/*8000*/
+   {-10.f,-10.f,-10.f,-12.f,-14.f,-18.f,-22.f,-28.f,-32.f,-40.f,-40.f},/*11500*/
+   {-10.f,-10.f,-10.f,-12.f,-14.f,-18.f,-22.f,-28.f,-32.f,-40.f,-40.f},/*16000*/
+  },
+
+  1,/*noisemaskp */
+  -10.f,  /* suppress any noise curve over maxspec+n */
+  .5f,   /* low window */
+  .5f,   /* high window */
+  10,
+  10,
+  25,
+  {.000f, 0.f, /*63*/
+   .000f, 0.f, /*88*/
+   .000f, 0.f, /*125*/
+   .000f, 0.f, /*175*/
+   .000f, 0.f, /*250*/
+   .000f, 0.f, /*350*/
+   .000f, 0.f, /*500*/
+   .000f, 0.f, /*700*/
+   .000f, 0.f, /*1000*/
+   .300f, 0.f, /*1400*/
+   .300f, 0.f, /*2000*/
+   .300f, 0.f, /*2800*/
+   .500f, 0.f, /*4000*/
+   .700f, 0.f, /*5600*/
+   .850f, 0.f, /*8000*/
+   .900f, 0.f, /*11500*/
+   .900f, 1.f, /*16000*/
+  },
+ 
+  95.f,  /* even decade + 5 is important; saves an rint() later in a
+            tight loop) */
+  -44.,
+
+  32,
+  _vp_part0,_vp_couple0
+};
+
+static vorbis_info_floor1 _floor_set0={1,
+                                        {0},
+                                        
+                                        {32},
+                                        {0},
+                                        {0},
+                                        {{-1}},
+
+                                        2,
+                                        {0,1024,
+
+                                         88,31,243,
+
+                                         14,54,143,460,
+                                         
+                                         6,3,10, 22,18,26, 41,36,47, 
+                                         69,61,78, 112,99,126, 185,162,211,  
+                                         329,282,387, 672,553,825
+                                         },
+                                        
+                                        60,30,400,
+                                        20,8,1,18.,
+                                        20,600,
+                                        960};
+
+
+static vorbis_info_mapping0 mapping_info={1,{0,1},{0},{0},{0},0, 1, {0},{1}};
+static codec_setup_info codec_setup0={ {0,0}, 
+                                       1,1,1,1,1,0,1,        
+                                       {NULL},
+                                       {0},{&mapping_info},
+                                       {0},{NULL},
+                                       {1},{&_floor_set0},
+                                       {2},{NULL},
+                                       {NULL},
+                                       {&_psy_set0},
+                                       &_psy_set0G};
+                                       
+static int noisy=0;
+void analysis(char *base,int i,float *v,int n,int bark,int dB){
+  if(noisy){
+    int j;
+    FILE *of;
+    char buffer[80];
+    sprintf(buffer,"%s_%d.m",base,i);
+    of=fopen(buffer,"w");
+
+    for(j=0;j<n;j++){
+      if(dB && v[j]==0)
+          fprintf(of,"\n\n");
+      else{
+        if(bark)
+          fprintf(of,"%g ",toBARK(22050.f*j/n));
+        else
+          fprintf(of,"%g ",(float)j);
+      
+        if(dB){
+          fprintf(of,"%g\n",todB(v+j));
+        }else{
+          fprintf(of,"%g\n",v[j]);
+        }
+      }
+    }
+    fclose(of);
+  }
+}
+
+long frameno=0;
+
+/****************************************************************/
+
+int main(int argc,char *argv[]){
+  int eos=0;
+  float nonz=0.f;
+  float acc=0.f;
+  float tot=0.f;
+  float ampmax=-9999,newmax;
+  float local_ampmax[2];
+
+  int framesize=2048;
+  float ampmax_att_per_sec=-6.;
+
+  float *pcm[2],*out[2],*window,*flr[2],*mask[2],*work[2];
+  signed char *buffer,*buffer2;
+  mdct_lookup m_look;
+  drft_lookup f_look;
+  vorbis_look_psy p_look;
+  vorbis_look_psy_global *pg_look;
+  vorbis_look_floor *floor_look;
+  vorbis_info vi;
+  long i,j,k;
+
+  int ath=0;
+  int decayp=0;
+
+  argv++;
+  while(*argv){
+    if(*argv[0]=='-'){
+      /* option */
+      if(argv[0][1]=='v'){
+        noisy=0;
+      }
+    }else
+      if(*argv[0]=='+'){
+        /* option */
+        if(argv[0][1]=='v'){
+          noisy=1;
+        }
+      }else
+        framesize=atoi(argv[0]);
+    argv++;
+  }
+  
+  vi.channels=2;
+  vi.codec_setup=&codec_setup0;
+
+  pcm[0]=_ogg_malloc(framesize*sizeof(float));
+  pcm[1]=_ogg_malloc(framesize*sizeof(float));
+  out[0]=_ogg_calloc(framesize/2,sizeof(float));
+  out[1]=_ogg_calloc(framesize/2,sizeof(float));
+  work[0]=_ogg_calloc(framesize,sizeof(float));
+  work[1]=_ogg_calloc(framesize,sizeof(float));
+  flr[0]=_ogg_calloc(framesize/2,sizeof(float));
+  flr[1]=_ogg_calloc(framesize/2,sizeof(float));
+  buffer=_ogg_malloc(framesize*4);
+  buffer2=buffer+framesize*2;
+  window=_vorbis_window_create(0,framesize,framesize/2,framesize/2);
+  mdct_init(&m_look,framesize);
+  drft_init(&f_look,framesize);
+  _vp_psy_init(&p_look,&_psy_set0,&_psy_set0G,framesize/2,44100);
+  pg_look=_vp_global_look(&vi);
+  floor_look=_floor_P[1]->look(NULL,NULL,&_floor_set0);
+
+  /* we cheat on the WAV header; we just bypass 44 bytes and never
+     verify that it matches 16bit/stereo/44.1kHz. */
+  
+  fread(buffer,1,44,stdin);
+  fwrite(buffer,1,44,stdout);
+  memset(buffer,0,framesize*2);
+
+  analysis("window",0,window,framesize,0,0);
+
+  fprintf(stderr,"Processing for frame size %d...\n",framesize);
+
+  while(!eos){
+    long bytes=fread(buffer2,1,framesize*2,stdin); 
+    if(bytes<framesize*2)
+      memset(buffer2+bytes,0,framesize*2-bytes);
+    
+    if(bytes!=0){
+      int nonzero[2];
+
+      /* uninterleave samples */
+      for(i=0;i<framesize;i++){
+        pcm[0][i]=((buffer[i*4+1]<<8)|
+                      (0x00ff&(int)buffer[i*4]))/32768.f;
+        pcm[1][i]=((buffer[i*4+3]<<8)|
+                   (0x00ff&(int)buffer[i*4+2]))/32768.f;
+      }
+      
+      {
+        float secs=framesize/44100.;
+        
+        ampmax+=secs*ampmax_att_per_sec;
+        if(ampmax<-9999)ampmax=-9999;
+      }
+
+      for(i=0;i<2;i++){
+        float scale=4.f/framesize;
+        float *fft=work[i];
+        float *mdct=pcm[i];
+        float *logmdct=mdct+framesize/2;
+
+        analysis("pre",frameno+i,pcm[i],framesize,0,0);
+        
+        /* fft and mdct transforms  */
+        for(j=0;j<framesize;j++)
+          fft[j]=pcm[i][j]*=window[j];
+        
+        drft_forward(&f_look,fft);
+
+        local_ampmax[i]=-9999.f;
+        fft[0]*=scale;
+        fft[0]=todB(fft);
+        for(j=1;j<framesize-1;j+=2){
+          float temp=scale*FAST_HYPOT(fft[j],fft[j+1]);
+          temp=fft[(j+1)>>1]=todB(&temp);
+          if(temp>local_ampmax[i])local_ampmax[i]=temp;
+        }
+        if(local_ampmax[i]>ampmax)ampmax=local_ampmax[i];
+        
+        mdct_forward(&m_look,pcm[i],mdct);
+        for(j=0;j<framesize/2;j++)
+          logmdct[j]=todB(mdct+j);
+
+        analysis("mdct",frameno+i,logmdct,framesize/2,1,0);
+        analysis("fft",frameno+i,fft,framesize/2,1,0);
+      }
+
+      for(i=0;i<2;i++){
+        float amp;
+        float *fft=work[i];
+        float *logmax=fft;
+        float *mdct=pcm[i];
+        float *logmdct=mdct+framesize/2;
+        float *mask=fft+framesize/2;
+
+        /* floor psychoacoustics */
+        _vp_compute_mask(&p_look,
+                         pg_look,
+                         i,
+                         fft,
+                         logmdct,
+                         mask,
+                         ampmax,
+                         local_ampmax[i],
+                         framesize/2);
+
+        analysis("mask",frameno+i,mask,framesize/2,1,0);
+
+        {
+          vorbis_block vb;
+          vorbis_dsp_state vd;
+          memset(&vd,0,sizeof(vd));
+          vd.vi=&vi;
+          vb.vd=&vd;
+          vb.pcmend=framesize;
+
+          /* floor quantization/application */
+          nonzero[i]=_floor_P[1]->forward(&vb,floor_look,
+                                          mdct,
+                                          logmdct,
+                                          mask,
+                                          logmax,
+                                          
+                                          flr[i]);
+        }
+
+        _vp_remove_floor(&p_look,
+                         pg_look,
+                         logmdct,
+                         mdct,
+                         flr[i],
+                         pcm[i],
+                         local_ampmax[i]);
+
+        for(j=0;j<framesize/2;j++)
+          if(fabs(pcm[i][j])>1500)
+            fprintf(stderr,"%ld ",frameno+i);
+        
+        analysis("res",frameno+i,pcm[i],framesize/2,1,0);
+        analysis("codedflr",frameno+i,flr[i],framesize/2,1,1);
+      }
+
+      /* residue prequantization */
+      _vp_partition_prequant(&p_look,
+                             &vi,
+                             pcm,
+                             nonzero);
+        
+      for(i=0;i<2;i++)
+        analysis("quant",frameno+i,pcm[i],framesize/2,1,0);
+
+      /* channel coupling / stereo quantization */
+
+      _vp_couple(&p_look,
+                 &mapping_info,
+                 pcm,
+                 nonzero);
+  
+      for(i=0;i<2;i++)
+        analysis("coupled",frameno+i,pcm[i],framesize/2,1,0);
+
+      /* decoupling */
+      for(i=mapping_info.coupling_steps-1;i>=0;i--){
+        float *pcmM=pcm[mapping_info.coupling_mag[i]];
+        float *pcmA=pcm[mapping_info.coupling_ang[i]];
+        
+        for(j=0;j<framesize/2;j++){
+          float mag=pcmM[j];
+          float ang=pcmA[j];
+          
+          if(mag>0)
+            if(ang>0){
+              pcmM[j]=mag;
+              pcmA[j]=mag-ang;
+            }else{
+              pcmA[j]=mag;
+              pcmM[j]=mag+ang;
+            }
+          else
+            if(ang>0){
+              pcmM[j]=mag;
+              pcmA[j]=mag+ang;
+            }else{
+              pcmA[j]=mag;
+              pcmM[j]=mag-ang;
+            }
+        }
+      }
+    
+      for(i=0;i<2;i++)
+        analysis("decoupled",frameno+i,pcm[i],framesize/2,1,0);
+
+      for(i=0;i<2;i++){
+        float amp;
+
+        for(j=0;j<framesize/2;j++)
+          pcm[i][j]*=flr[i][j];
+
+        analysis("final",frameno+i,pcm[i],framesize/2,1,1);
+
+        /* take it back to time */
+        mdct_backward(&m_look,pcm[i],pcm[i]);
+
+        for(j=0;j<framesize/2;j++)
+          out[i][j]+=pcm[i][j]*window[j];
+
+        analysis("out",frameno+i,out[i],framesize/2,0,0);
+
+
+      }
+           
+      /* write data.  Use the part of buffer we're about to shift out */
+      for(i=0;i<2;i++){
+        char  *ptr=buffer+i*2;
+        float *mono=out[i];
+        int flag=0;
+        for(j=0;j<framesize/2;j++){
+          int val=mono[j]*32767.;
+          /* might as well guard against clipping */
+          if(val>32767){
+            if(!flag)fprintf(stderr,"clipping in frame %ld ",frameno+i);
+            flag=1;
+            val=32767;
+          }
+          if(val<-32768){
+            if(!flag)fprintf(stderr,"clipping in frame %ld ",frameno+i);
+            flag=1;
+            val=-32768;
+          }
+          ptr[0]=val&0xff;
+          ptr[1]=(val>>8)&0xff;
+          ptr+=4;
+        }
+      }
+ 
+      fprintf(stderr,"*");
+      fwrite(buffer,1,framesize*2,stdout);
+      memmove(buffer,buffer2,framesize*2);
+
+      for(i=0;i<2;i++){
+        for(j=0,k=framesize/2;j<framesize/2;j++,k++)
+          out[i][j]=pcm[i][k]*window[k];
+      }
+      frameno+=2;
+    }else
+      eos=1;
+  }
+  fprintf(stderr,"average raw bits of entropy: %.03g/sample\n",acc/tot);
+  fprintf(stderr,"average nonzero samples: %.03g/%d\n",nonz/tot*framesize/2,
+          framesize/2);
+  fprintf(stderr,"Done\n\n");
+  return 0;
+}

+ 34 - 33
Engine/lib/libvorbis/lib/res0.c

@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: residue backend 0, 1 and 2 implementation
- last mod: $Id: res0.c 17556 2010-10-21 18:25:19Z tterribe $
+ last mod: $Id: res0.c 19441 2015-01-21 01:17:41Z xiphmont $
 
  ********************************************************************/
 
@@ -152,15 +152,6 @@ void res0_free_look(vorbis_look_residue *i){
   }
 }
 
-static int ilog(unsigned int v){
-  int ret=0;
-  while(v){
-    ret++;
-    v>>=1;
-  }
-  return(ret);
-}
-
 static int icount(unsigned int v){
   int ret=0;
   while(v){
@@ -186,7 +177,7 @@ void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
      bitmask of one indicates this partition class has bits to write
      this pass */
   for(j=0;j<info->partitions;j++){
-    if(ilog(info->secondstages[j])>3){
+    if(ov_ilog(info->secondstages[j])>3){
       /* yes, this is a minor hack due to not thinking ahead */
       oggpack_write(opb,info->secondstages[j],3);
       oggpack_write(opb,1,1);
@@ -284,7 +275,7 @@ vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
   look->partbooks=_ogg_calloc(look->parts,sizeof(*look->partbooks));
 
   for(j=0;j<look->parts;j++){
-    int stages=ilog(info->secondstages[j]);
+    int stages=ov_ilog(info->secondstages[j]);
     if(stages){
       if(stages>maxstage)maxstage=stages;
       look->partbooks[j]=_ogg_calloc(stages,sizeof(*look->partbooks[j]));
@@ -390,8 +381,13 @@ static int local_book_besterror(codebook *book,int *a){
   return(index);
 }
 
+#ifdef TRAIN_RES
 static int _encodepart(oggpack_buffer *opb,int *vec, int n,
                        codebook *book,long *acc){
+#else
+static int _encodepart(oggpack_buffer *opb,int *vec, int n,
+                       codebook *book){
+#endif
   int i,bits=0;
   int dim=book->dim;
   int step=n/dim;
@@ -534,12 +530,18 @@ static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,int **in,
 }
 
 static int _01forward(oggpack_buffer *opb,
-                      vorbis_block *vb,vorbis_look_residue *vl,
+                      vorbis_look_residue *vl,
                       int **in,int ch,
                       long **partword,
+#ifdef TRAIN_RES
                       int (*encode)(oggpack_buffer *,int *,int,
                                     codebook *,long *),
-                      int submap){
+                      int submap
+#else
+                      int (*encode)(oggpack_buffer *,int *,int,
+                                    codebook *)
+#endif
+){
   long i,j,k,s;
   vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
   vorbis_info_residue0 *info=look->info;
@@ -609,9 +611,8 @@ static int _01forward(oggpack_buffer *opb,
             codebook *statebook=look->partbooks[partword[j][i]][s];
             if(statebook){
               int ret;
-              long *accumulator=NULL;
-
 #ifdef TRAIN_RES
+              long *accumulator=NULL;
               accumulator=look->training_data[s][partword[j][i]];
               {
                 int l;
@@ -623,10 +624,12 @@ static int _01forward(oggpack_buffer *opb,
                     look->training_max[s][partword[j][i]]=samples[l];
                 }
               }
-#endif
-
               ret=encode(opb,in[j]+offset,samples_per_partition,
                          statebook,accumulator);
+#else
+              ret=encode(opb,in[j]+offset,samples_per_partition,
+                         statebook);
+#endif
 
               look->postbits+=ret;
               resbits[partword[j][i]]+=ret;
@@ -637,19 +640,6 @@ static int _01forward(oggpack_buffer *opb,
     }
   }
 
-  /*{
-    long total=0;
-    long totalbits=0;
-    fprintf(stderr,"%d :: ",vb->mode);
-    for(k=0;k<possible_partitions;k++){
-    fprintf(stderr,"%ld/%1.2g, ",resvals[k],(float)resbits[k]/resvals[k]);
-    total+=resvals[k];
-    totalbits+=resbits[k];
-    }
-
-    fprintf(stderr,":: %ld:%1.2g\n",total,(double)totalbits/total);
-    }*/
-
   return(0);
 }
 
@@ -729,12 +719,18 @@ int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
 int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
                  int **in,int *nonzero,int ch, long **partword, int submap){
   int i,used=0;
+  (void)vb;
   for(i=0;i<ch;i++)
     if(nonzero[i])
       in[used++]=in[i];
 
   if(used){
-    return _01forward(opb,vb,vl,in,used,partword,_encodepart,submap);
+#ifdef TRAIN_RES
+    return _01forward(opb,vl,in,used,partword,_encodepart,submap);
+#else
+    (void)submap;
+    return _01forward(opb,vl,in,used,partword,_encodepart);
+#endif
   }else{
     return(0);
   }
@@ -795,7 +791,12 @@ int res2_forward(oggpack_buffer *opb,
   }
 
   if(used){
-    return _01forward(opb,vb,vl,&work,1,partword,_encodepart,submap);
+#ifdef TRAIN_RES
+    return _01forward(opb,vl,&work,1,partword,_encodepart,submap);
+#else
+    (void)submap;
+    return _01forward(opb,vl,&work,1,partword,_encodepart);
+#endif
   }else{
     return(0);
   }

+ 67 - 60
Engine/lib/libvorbis/lib/sharedbook.c

@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: basic shared codebook operations
- last mod: $Id: sharedbook.c 17030 2010-03-25 06:52:55Z xiphmont $
+ last mod: $Id: sharedbook.c 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
@@ -26,13 +26,11 @@
 #include "scales.h"
 
 /**** pack/unpack helpers ******************************************/
-int _ilog(unsigned int v){
-  int ret=0;
-  while(v){
-    ret++;
-    v>>=1;
-  }
-  return(ret);
+
+int ov_ilog(ogg_uint32_t v){
+  int ret;
+  for(ret=0;v;ret++)v>>=1;
+  return ret;
 }
 
 /* 32 bit float (not IEEE; nonnormalized mantissa +
@@ -70,7 +68,7 @@ float _float32_unpack(long val){
 /* given a list of word lengths, generate a list of codewords.  Works
    for length ordered or unordered, always assigns the lowest valued
    codewords first.  Extended to handle unused entries (length 0) */
-ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
+ogg_uint32_t *_make_words(char *l,long n,long sparsecount){
   long i,j,count=0;
   ogg_uint32_t marker[33];
   ogg_uint32_t *r=_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
@@ -125,16 +123,15 @@ ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
       if(sparsecount==0)count++;
   }
 
-  /* sanity check the huffman tree; an underpopulated tree must be
-     rejected. The only exception is the one-node pseudo-nil tree,
-     which appears to be underpopulated because the tree doesn't
-     really exist; there's only one possible 'codeword' or zero bits,
-     but the above tree-gen code doesn't mark that. */
-  if(sparsecount != 1){
+  /* any underpopulated tree must be rejected. */
+  /* Single-entry codebooks are a retconned extension to the spec.
+     They have a single codeword '0' of length 1 that results in an
+     underpopulated tree.  Shield that case from the underformed tree check. */
+  if(!(count==1 && marker[2]==2)){
     for(i=1;i<33;i++)
       if(marker[i] & (0xffffffffUL>>(32-i))){
-	_ogg_free(r);
-	return(NULL);
+        _ogg_free(r);
+        return(NULL);
       }
   }
 
@@ -313,9 +310,10 @@ static int sort32a(const void *a,const void *b){
 int vorbis_book_init_decode(codebook *c,const static_codebook *s){
   int i,j,n=0,tabn;
   int *sortindex;
+
   memset(c,0,sizeof(*c));
 
-  /* count actually used entries */
+  /* count actually used entries and find max length */
   for(i=0;i<s->entries;i++)
     if(s->lengthlist[i]>0)
       n++;
@@ -325,7 +323,6 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
   c->dim=s->dim;
 
   if(n>0){
-
     /* two different remappings go on here.
 
     First, we collapse the likely sparse codebook down only to
@@ -361,7 +358,6 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
       c->codelist[sortindex[i]]=codes[i];
     _ogg_free(codes);
 
-
     c->valuelist=_book_unquantize(s,n,sortindex);
     c->dec_index=_ogg_malloc(n*sizeof(*c->dec_index));
 
@@ -370,51 +366,62 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
         c->dec_index[sortindex[n++]]=i;
 
     c->dec_codelengths=_ogg_malloc(n*sizeof(*c->dec_codelengths));
+    c->dec_maxlength=0;
     for(n=0,i=0;i<s->entries;i++)
-      if(s->lengthlist[i]>0)
+      if(s->lengthlist[i]>0){
         c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
+        if(s->lengthlist[i]>c->dec_maxlength)
+          c->dec_maxlength=s->lengthlist[i];
+      }
 
-    c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
-    if(c->dec_firsttablen<5)c->dec_firsttablen=5;
-    if(c->dec_firsttablen>8)c->dec_firsttablen=8;
-
-    tabn=1<<c->dec_firsttablen;
-    c->dec_firsttable=_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
-    c->dec_maxlength=0;
+    if(n==1 && c->dec_maxlength==1){
+      /* special case the 'single entry codebook' with a single bit
+       fastpath table (that always returns entry 0 )in order to use
+       unmodified decode paths. */
+      c->dec_firsttablen=1;
+      c->dec_firsttable=_ogg_calloc(2,sizeof(*c->dec_firsttable));
+      c->dec_firsttable[0]=c->dec_firsttable[1]=1;
 
-    for(i=0;i<n;i++){
-      if(c->dec_maxlength<c->dec_codelengths[i])
-        c->dec_maxlength=c->dec_codelengths[i];
-      if(c->dec_codelengths[i]<=c->dec_firsttablen){
-        ogg_uint32_t orig=bitreverse(c->codelist[i]);
-        for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
-          c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
+    }else{
+      c->dec_firsttablen=ov_ilog(c->used_entries)-4; /* this is magic */
+      if(c->dec_firsttablen<5)c->dec_firsttablen=5;
+      if(c->dec_firsttablen>8)c->dec_firsttablen=8;
+
+      tabn=1<<c->dec_firsttablen;
+      c->dec_firsttable=_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
+
+      for(i=0;i<n;i++){
+        if(c->dec_codelengths[i]<=c->dec_firsttablen){
+          ogg_uint32_t orig=bitreverse(c->codelist[i]);
+          for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
+            c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
+        }
       }
-    }
 
-    /* now fill in 'unused' entries in the firsttable with hi/lo search
-       hints for the non-direct-hits */
-    {
-      ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
-      long lo=0,hi=0;
-
-      for(i=0;i<tabn;i++){
-        ogg_uint32_t word=i<<(32-c->dec_firsttablen);
-        if(c->dec_firsttable[bitreverse(word)]==0){
-          while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
-          while(    hi<n && word>=(c->codelist[hi]&mask))hi++;
-
-          /* we only actually have 15 bits per hint to play with here.
-             In order to overflow gracefully (nothing breaks, efficiency
-             just drops), encode as the difference from the extremes. */
-          {
-            unsigned long loval=lo;
-            unsigned long hival=n-hi;
-
-            if(loval>0x7fff)loval=0x7fff;
-            if(hival>0x7fff)hival=0x7fff;
-            c->dec_firsttable[bitreverse(word)]=
-              0x80000000UL | (loval<<15) | hival;
+      /* now fill in 'unused' entries in the firsttable with hi/lo search
+         hints for the non-direct-hits */
+      {
+        ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
+        long lo=0,hi=0;
+
+        for(i=0;i<tabn;i++){
+          ogg_uint32_t word=i<<(32-c->dec_firsttablen);
+          if(c->dec_firsttable[bitreverse(word)]==0){
+            while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
+            while(    hi<n && word>=(c->codelist[hi]&mask))hi++;
+
+            /* we only actually have 15 bits per hint to play with here.
+               In order to overflow gracefully (nothing breaks, efficiency
+               just drops), encode as the difference from the extremes. */
+            {
+              unsigned long loval=lo;
+              unsigned long hival=n-hi;
+
+              if(loval>0x7fff)loval=0x7fff;
+              if(hival>0x7fff)hival=0x7fff;
+              c->dec_firsttable[bitreverse(word)]=
+                0x80000000UL | (loval<<15) | hival;
+            }
           }
         }
       }

+ 10 - 14
Engine/lib/libvorbis/lib/synthesis.c

@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: single-block PCM synthesis
- last mod: $Id: synthesis.c 17474 2010-09-30 03:41:41Z gmaxwell $
+ last mod: $Id: synthesis.c 19441 2015-01-21 01:17:41Z xiphmont $
 
  ********************************************************************/
 
@@ -145,6 +145,11 @@ long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
   oggpack_buffer       opb;
   int                  mode;
 
+  if(ci==NULL || ci->modes<=0){
+    /* codec setup not properly intialized */
+    return(OV_EFAULT);
+  }
+
   oggpack_readinit(&opb,op->packet,op->bytes);
 
   /* Check the packet type */
@@ -153,18 +158,9 @@ long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
     return(OV_ENOTAUDIO);
   }
 
-  {
-    int modebits=0;
-    int v=ci->modes;
-    while(v>1){
-      modebits++;
-      v>>=1;
-    }
-
-    /* read our mode and pre/post windowsize */
-    mode=oggpack_read(&opb,modebits);
-  }
-  if(mode==-1)return(OV_EBADPACKET);
+  /* read our mode and pre/post windowsize */
+  mode=oggpack_read(&opb,ov_ilog(ci->modes-1));
+  if(mode==-1 || !ci->mode_param[mode])return(OV_EBADPACKET);
   return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
 }
 

+ 54 - 0
Engine/lib/libvorbis/lib/tone.c

@@ -0,0 +1,54 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+void usage(){
+  fprintf(stderr,"tone <frequency_Hz>,[<amplitude>] [<frequency_Hz>,[<amplitude>]...]\n");
+  exit(1);
+}
+
+int main (int argc,char *argv[]){
+  int i,j;
+  double *f;
+  double *amp;
+  
+  if(argc<2)usage();
+
+  f=alloca(sizeof(*f)*(argc-1));
+  amp=alloca(sizeof(*amp)*(argc-1));
+
+  i=0;
+  while(argv[i+1]){
+    char *pos=strchr(argv[i+1],',');
+    
+    f[i]=atof(argv[i+1]);
+    if(pos)
+      amp[i]=atof(pos+1)*32767.f;
+    else
+      amp[i]=32767.f;
+
+    fprintf(stderr,"%g Hz, %g amp\n",f[i],amp[i]);
+
+    i++;
+  }
+
+  for(i=0;i<44100*10;i++){
+    float val=0;
+    int ival;
+    for(j=0;j<argc-1;j++)
+      val+=amp[j]*sin(i/44100.f*f[j]*2*M_PI);
+    ival=rint(val);
+
+    if(ival>32767.f)ival=32767.f;
+    if(ival<-32768.f)ival=-32768.f;
+
+    fprintf(stdout,"%c%c%c%c",
+            (char)(ival&0xff),
+            (char)((ival>>8)&0xff),
+            (char)(ival&0xff),
+            (char)((ival>>8)&0xff));
+  }
+  return(0);
+}
+

+ 16 - 7
Engine/lib/libvorbis/lib/vorbisenc.c

@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: simple programmatic interface for encoder mode setup
- last mod: $Id: vorbisenc.c 17028 2010-03-25 05:22:15Z xiphmont $
+ last mod: $Id: vorbisenc.c 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
@@ -903,8 +903,12 @@ int vorbis_encode_setup_vbr(vorbis_info *vi,
                             long  channels,
                             long  rate,
                             float quality){
-  codec_setup_info *ci=vi->codec_setup;
-  highlevel_encode_setup *hi=&ci->hi;
+  codec_setup_info *ci;
+  highlevel_encode_setup *hi;
+  if(rate<=0) return OV_EINVAL;
+
+  ci=vi->codec_setup;
+  hi=&ci->hi;
 
   quality+=.0000001;
   if(quality>=1.)quality=.9999;
@@ -948,9 +952,14 @@ int vorbis_encode_setup_managed(vorbis_info *vi,
                                 long nominal_bitrate,
                                 long min_bitrate){
 
-  codec_setup_info *ci=vi->codec_setup;
-  highlevel_encode_setup *hi=&ci->hi;
-  double tnominal=nominal_bitrate;
+  codec_setup_info *ci;
+  highlevel_encode_setup *hi;
+  double tnominal;
+  if(rate<=0) return OV_EINVAL;
+
+  ci=vi->codec_setup;
+  hi=&ci->hi;
+  tnominal=nominal_bitrate;
 
   if(nominal_bitrate<=0.){
     if(max_bitrate>0.){

+ 168 - 80
Engine/lib/libvorbis/lib/vorbisfile.c

@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.c 17573 2010-10-27 14:53:59Z xiphmont $
+ last mod: $Id: vorbisfile.c 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
@@ -80,11 +80,14 @@ static long _get_data(OggVorbis_File *vf){
 /* save a tiny smidge of verbosity to make the code more readable */
 static int _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
   if(vf->datasource){
-    if(!(vf->callbacks.seek_func)||
-       (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET) == -1)
-      return OV_EREAD;
-    vf->offset=offset;
-    ogg_sync_reset(&vf->oy);
+    /* only seek if the file position isn't already there */
+    if(vf->offset != offset){
+      if(!(vf->callbacks.seek_func)||
+         (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET) == -1)
+        return OV_EREAD;
+      vf->offset=offset;
+      ogg_sync_reset(&vf->oy);
+    }
   }else{
     /* shouldn't happen unless someone writes a broken callback */
     return OV_EFAULT;
@@ -138,14 +141,12 @@ static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
   }
 }
 
-/* find the latest page beginning before the current stream cursor
-   position. Much dirtier than the above as Ogg doesn't have any
-   backward search linkage.  no 'readp' as it will certainly have to
-   read. */
+/* find the latest page beginning before the passed in position. Much
+   dirtier than the above as Ogg doesn't have any backward search
+   linkage.  no 'readp' as it will certainly have to read. */
 /* returns offset or OV_EREAD, OV_FAULT */
-static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
-  ogg_int64_t begin=vf->offset;
-  ogg_int64_t end=begin;
+static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_int64_t begin,ogg_page *og){
+  ogg_int64_t end = begin;
   ogg_int64_t ret;
   ogg_int64_t offset=-1;
 
@@ -220,11 +221,10 @@ static int _lookup_page_serialno(ogg_page *og, long *serialno_list, int n){
    info of last page of the matching serial number instead of the very
    last page.  If no page of the specified serialno is seen, it will
    return the info of last page and alter *serialno.  */
-static ogg_int64_t _get_prev_page_serial(OggVorbis_File *vf,
+static ogg_int64_t _get_prev_page_serial(OggVorbis_File *vf, ogg_int64_t begin,
                                          long *serial_list, int serial_n,
                                          int *serialno, ogg_int64_t *granpos){
   ogg_page og;
-  ogg_int64_t begin=vf->offset;
   ogg_int64_t end=begin;
   ogg_int64_t ret;
 
@@ -438,9 +438,11 @@ static ogg_int64_t _initial_pcmoffset(OggVorbis_File *vf, vorbis_info *vi){
     while((result=ogg_stream_packetout(&vf->os,&op))){
       if(result>0){ /* ignore holes */
         long thisblock=vorbis_packet_blocksize(vi,&op);
-        if(lastblock!=-1)
-          accumulated+=(lastblock+thisblock)>>2;
-        lastblock=thisblock;
+        if(thisblock>=0){
+          if(lastblock!=-1)
+            accumulated+=(lastblock+thisblock)>>2;
+          lastblock=thisblock;
+        }
       }
     }
 
@@ -494,10 +496,10 @@ static int _bisect_forward_serialno(OggVorbis_File *vf,
        down to (or just started with) a single link.  Now we need to
        find the last vorbis page belonging to the first vorbis stream
        for this link. */
-
+    searched = end;
     while(endserial != serialno){
       endserial = serialno;
-      vf->offset=_get_prev_page_serial(vf,currentno_list,currentnos,&endserial,&endgran);
+      searched=_get_prev_page_serial(vf,searched,currentno_list,currentnos,&endserial,&endgran);
     }
 
     vf->links=m+1;
@@ -518,10 +520,15 @@ static int _bisect_forward_serialno(OggVorbis_File *vf,
 
   }else{
 
+    /* last page is not in the starting stream's serial number list,
+       so we have multiple links.  Find where the stream that begins
+       our bisection ends. */
+
     long *next_serialno_list=NULL;
     int next_serialnos=0;
     vorbis_info vi;
     vorbis_comment vc;
+    int testserial = serialno+1;
 
     /* the below guards against garbage seperating the last and
        first pages of two links. */
@@ -534,10 +541,8 @@ static int _bisect_forward_serialno(OggVorbis_File *vf,
         bisect=(searched+endsearched)/2;
       }
 
-      if(bisect != vf->offset){
-        ret=_seek_helper(vf,bisect);
-        if(ret)return(ret);
-      }
+      ret=_seek_helper(vf,bisect);
+      if(ret)return(ret);
 
       last=_get_next_page(vf,&og,-1);
       if(last==OV_EREAD)return(OV_EREAD);
@@ -550,28 +555,22 @@ static int _bisect_forward_serialno(OggVorbis_File *vf,
     }
 
     /* Bisection point found */
-
     /* for the time being, fetch end PCM offset the simple way */
-    {
-      int testserial = serialno+1;
-      vf->offset = next;
-      while(testserial != serialno){
-        testserial = serialno;
-        vf->offset=_get_prev_page_serial(vf,currentno_list,currentnos,&testserial,&searchgran);
-      }
+    searched = next;
+    while(testserial != serialno){
+      testserial = serialno;
+      searched = _get_prev_page_serial(vf,searched,currentno_list,currentnos,&testserial,&searchgran);
     }
 
-    if(vf->offset!=next){
-      ret=_seek_helper(vf,next);
-      if(ret)return(ret);
-    }
+    ret=_seek_helper(vf,next);
+    if(ret)return(ret);
 
     ret=_fetch_headers(vf,&vi,&vc,&next_serialno_list,&next_serialnos,NULL);
     if(ret)return(ret);
     serialno = vf->os.serialno;
     dataoffset = vf->offset;
 
-    /* this will consume a page, however the next bistection always
+    /* this will consume a page, however the next bisection always
        starts with a raw seek */
     pcmoffset = _initial_pcmoffset(vf,&vi);
 
@@ -638,11 +637,11 @@ static int _open_seekable2(OggVorbis_File *vf){
   /* Get the offset of the last page of the physical bitstream, or, if
      we're lucky the last vorbis page of this link as most OggVorbis
      files will contain a single logical bitstream */
-  end=_get_prev_page_serial(vf,vf->serialnos+2,vf->serialnos[1],&endserial,&endgran);
+  end=_get_prev_page_serial(vf,vf->end,vf->serialnos+2,vf->serialnos[1],&endserial,&endgran);
   if(end<0)return(end);
 
   /* now determine bitstream structure recursively */
-  if(_bisect_forward_serialno(vf,0,dataoffset,vf->offset,endgran,endserial,
+  if(_bisect_forward_serialno(vf,0,dataoffset,end,endgran,endserial,
                               vf->serialnos+2,vf->serialnos[1],0)<0)return(OV_EREAD);
 
   vf->offsets[0]=0;
@@ -1055,7 +1054,11 @@ int ov_halfrate_p(OggVorbis_File *vf){
 /* Only partially open the vorbis file; test for Vorbisness, and load
    the headers for the first chain.  Do not seek (although test for
    seekability).  Use ov_test_open to finish opening the file, else
-   ov_clear to close/free it. Same return codes as open. */
+   ov_clear to close/free it. Same return codes as open.
+
+   Note that vorbisfile does _not_ take ownership of the file if the
+   call fails; the calling applicaiton is responsible for closing the file
+   if this call returns an error. */
 
 int ov_test_callbacks(void *f,OggVorbis_File *vf,
     const char *initial,long ibytes,ov_callbacks callbacks)
@@ -1417,22 +1420,41 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
     if(pos>=total)break;
   }
 
-  /* search within the logical bitstream for the page with the highest
-     pcm_pos preceding (or equal to) pos.  There is a danger here;
-     missing pages or incorrect frame number information in the
-     bitstream could make our task impossible.  Account for that (it
-     would be an error condition) */
+  /* Search within the logical bitstream for the page with the highest
+     pcm_pos preceding pos.  If we're looking for a position on the
+     first page, bisection will halt without finding our position as
+     it's before the first explicit granulepos fencepost. That case is
+     handled separately below.
+
+     There is a danger here; missing pages or incorrect frame number
+     information in the bitstream could make our task impossible.
+     Account for that (it would be an error condition) */
+
+  /* new search algorithm originally by HB (Nicholas Vinen) */
 
-  /* new search algorithm by HB (Nicholas Vinen) */
   {
     ogg_int64_t end=vf->offsets[link+1];
-    ogg_int64_t begin=vf->offsets[link];
+    ogg_int64_t begin=vf->dataoffsets[link];
     ogg_int64_t begintime = vf->pcmlengths[link*2];
     ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
     ogg_int64_t target=pos-total+begintime;
-    ogg_int64_t best=begin;
+    ogg_int64_t best=-1;
+    int         got_page=0;
 
     ogg_page og;
+
+    /* if we have only one page, there will be no bisection.  Grab the page here */
+    if(begin==end){
+      result=_seek_helper(vf,begin);
+      if(result) goto seek_error;
+
+      result=_get_next_page(vf,&og,1);
+      if(result<0) goto seek_error;
+
+      got_page=1;
+    }
+
+    /* bisection loop */
     while(begin<end){
       ogg_int64_t bisect;
 
@@ -1447,51 +1469,80 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
           bisect=begin;
       }
 
-      if(bisect!=vf->offset){
-        result=_seek_helper(vf,bisect);
-        if(result) goto seek_error;
-      }
+      result=_seek_helper(vf,bisect);
+      if(result) goto seek_error;
 
+      /* read loop within the bisection loop */
       while(begin<end){
         result=_get_next_page(vf,&og,end-vf->offset);
         if(result==OV_EREAD) goto seek_error;
         if(result<0){
+          /* there is no next page! */
           if(bisect<=begin+1)
-            end=begin; /* found it */
+              /* No bisection left to perform.  We've either found the
+                 best candidate already or failed. Exit loop. */
+            end=begin;
           else{
+            /* We tried to load a fraction of the last page; back up a
+               bit and try to get the whole last page */
             if(bisect==0) goto seek_error;
             bisect-=CHUNKSIZE;
+
+            /* don't repeat/loop on a read we've already performed */
             if(bisect<=begin)bisect=begin+1;
+
+            /* seek and cntinue bisection */
             result=_seek_helper(vf,bisect);
             if(result) goto seek_error;
           }
         }else{
           ogg_int64_t granulepos;
+          got_page=1;
 
+          /* got a page. analyze it */
+          /* only consider pages from primary vorbis stream */
           if(ogg_page_serialno(&og)!=vf->serialnos[link])
             continue;
 
+          /* only consider pages with the granulepos set */
           granulepos=ogg_page_granulepos(&og);
           if(granulepos==-1)continue;
 
           if(granulepos<target){
+            /* this page is a successful candidate! Set state */
+
             best=result;  /* raw offset of packet with granulepos */
             begin=vf->offset; /* raw offset of next page */
             begintime=granulepos;
 
+            /* if we're before our target but within a short distance,
+               don't bisect; read forward */
             if(target-begintime>44100)break;
-            bisect=begin; /* *not* begin + 1 */
+
+            bisect=begin; /* *not* begin + 1 as above */
           }else{
-            if(bisect<=begin+1)
-              end=begin;  /* found it */
-            else{
-              if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
+
+            /* This is one of our pages, but the granpos is
+               post-target; it is not a bisection return
+               candidate. (The only way we'd use it is if it's the
+               first page in the stream; we handle that case later
+               outside the bisection) */
+            if(bisect<=begin+1){
+              /* No bisection left to perform.  We've either found the
+                 best candidate already or failed. Exit loop. */
+              end=begin;
+            }else{
+              if(end==vf->offset){
+                /* bisection read to the end; use the known page
+                   boundary (result) to update bisection, back up a
+                   little bit, and try again */
                 end=result;
-                bisect-=CHUNKSIZE; /* an endless loop otherwise. */
+                bisect-=CHUNKSIZE;
                 if(bisect<=begin)bisect=begin+1;
                 result=_seek_helper(vf,bisect);
                 if(result) goto seek_error;
               }else{
+                /* Normal bisection */
                 end=bisect;
                 endtime=granulepos;
                 break;
@@ -1502,9 +1553,46 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
       }
     }
 
-    /* found our page. seek to it, update pcm offset. Easier case than
-       raw_seek, don't keep packets preceding granulepos. */
-    {
+    /* Out of bisection: did it 'fail?' */
+    if(best == -1){
+
+      /* Check the 'looking for data in first page' special case;
+         bisection would 'fail' because our search target was before the
+         first PCM granule position fencepost. */
+
+      if(got_page &&
+         begin == vf->dataoffsets[link] &&
+         ogg_page_serialno(&og)==vf->serialnos[link]){
+
+        /* Yes, this is the beginning-of-stream case. We already have
+           our page, right at the beginning of PCM data.  Set state
+           and return. */
+
+        vf->pcm_offset=total;
+
+        if(link!=vf->current_link){
+          /* Different link; dump entire decode machine */
+          _decode_clear(vf);
+
+          vf->current_link=link;
+          vf->current_serialno=vf->serialnos[link];
+          vf->ready_state=STREAMSET;
+
+        }else{
+          vorbis_synthesis_restart(&vf->vd);
+        }
+
+        ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
+        ogg_stream_pagein(&vf->os,&og);
+
+      }else
+        goto seek_error;
+
+    }else{
+
+      /* Bisection found our page. seek to it, update pcm offset. Easier case than
+         raw_seek, don't keep packets preceding granulepos. */
+
       ogg_page og;
       ogg_packet op;
 
@@ -1534,23 +1622,23 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
       while(1){
         result=ogg_stream_packetpeek(&vf->os,&op);
         if(result==0){
-          /* !!! the packet finishing this page originated on a
-             preceding page. Keep fetching previous pages until we
-             get one with a granulepos or without the 'continued' flag
-             set.  Then just use raw_seek for simplicity. */
-
-          result=_seek_helper(vf,best);
-          if(result<0) goto seek_error;
-
-          while(1){
-            result=_get_prev_page(vf,&og);
+          /* No packet returned; we exited the bisection with 'best'
+             pointing to a page with a granule position, so the packet
+             finishing this page ('best') originated on a preceding
+             page. Keep fetching previous pages until we get one with
+             a granulepos or without the 'continued' flag set.  Then
+             just use raw_seek for simplicity. */
+          /* Do not rewind past the beginning of link data; if we do,
+             it's either a bug or a broken stream */
+          result=best;
+          while(result>vf->dataoffsets[link]){
+            result=_get_prev_page(vf,result,&og);
             if(result<0) goto seek_error;
             if(ogg_page_serialno(&og)==vf->current_serialno &&
                (ogg_page_granulepos(&og)>-1 ||
                 !ogg_page_continued(&og))){
               return ov_raw_seek(vf,result);
             }
-            vf->offset=result;
           }
         }
         if(result<0){
@@ -2054,14 +2142,14 @@ long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
   }
 }
 
-extern float *vorbis_window(vorbis_dsp_state *v,int W);
+extern const float *vorbis_window(vorbis_dsp_state *v,int W);
 
 static void _ov_splice(float **pcm,float **lappcm,
                        int n1, int n2,
                        int ch1, int ch2,
-                       float *w1, float *w2){
+                       const float *w1, const float *w2){
   int i,j;
-  float *w=w1;
+  const float *w=w1;
   int n=n1;
 
   if(n1>n2){
@@ -2169,7 +2257,7 @@ int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
   vorbis_info *vi1,*vi2;
   float **lappcm;
   float **pcm;
-  float *w1,*w2;
+  const float *w1,*w2;
   int n1,n2,i,ret,hs1,hs2;
 
   if(vf1==vf2)return(0); /* degenerate case */
@@ -2223,7 +2311,7 @@ static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
   vorbis_info *vi;
   float **lappcm;
   float **pcm;
-  float *w1,*w2;
+  const float *w1,*w2;
   int n1,n2,ch1,ch2,hs;
   int i,ret;
 
@@ -2284,7 +2372,7 @@ static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
   vorbis_info *vi;
   float **lappcm;
   float **pcm;
-  float *w1,*w2;
+  const float *w1,*w2;
   int n1,n2,ch1,ch2,hs;
   int i,ret;
 

+ 2 - 1
Engine/lib/libvorbis/lib/window.c

@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: window functions
- last mod: $Id: window.c 16227 2009-07-08 06:58:46Z xiphmont $
+ last mod: $Id: window.c 19028 2013-12-02 23:23:39Z tterribe $
 
  ********************************************************************/
 
@@ -19,6 +19,7 @@
 #include <math.h>
 #include "os.h"
 #include "misc.h"
+#include "window.h"
 
 static const float vwin64[32] = {
   0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,

+ 2 - 2
Engine/lib/libvorbis/lib/window.h

@@ -11,14 +11,14 @@
  ********************************************************************
 
  function: window functions
- last mod: $Id: window.h 13293 2007-07-24 00:09:47Z xiphmont $
+ last mod: $Id: window.h 19028 2013-12-02 23:23:39Z tterribe $
 
  ********************************************************************/
 
 #ifndef _V_WINDOW_
 #define _V_WINDOW_
 
-extern float *_vorbis_window_get(int n);
+extern const float *_vorbis_window_get(int n);
 extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
                           int lW,int W,int nW);
 

Some files were not shown because too many files changed in this diff