add vorbis_encode_ctl entries to manipulate the bitrate management
authorMonty <xiphmont@xiph.org>
Sun, 30 Jun 2002 08:31:04 +0000 (08:31 +0000)
committerMonty <xiphmont@xiph.org>
Sun, 30 Jun 2002 08:31:04 +0000 (08:31 +0000)
engine.  Needed to allow old -b behavior (specifying a true VBR
quality mode via a bitrate mapping).

svn path=/trunk/vorbis/; revision=3451

12 files changed:
lib/analysis.c
lib/barkmel.c
lib/bitrate.c
lib/highlevel.h
lib/info.c
lib/mapping0.c
lib/masking.h
lib/modes/psych_44.h
lib/modes/setup_44.h
lib/psy.c
lib/psy.h
lib/vorbisenc.c

index 54aadd8..7b370fc 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: single-block PCM analysis mode dispatch
- last mod: $Id: analysis.c,v 1.52 2002/06/28 22:19:34 xiphmont Exp $
+ last mod: $Id: analysis.c,v 1.53 2002/06/30 08:31:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -76,24 +76,25 @@ void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB,ogg
     if(!of)perror("failed to open data dump file");
     
     for(j=0;j<n;j++){
-      if(dB && v[j]==0)
-       fprintf(of,"\n\n");
-      else{
-       if(v[j]>-900.){
-         if(bark)
-           fprintf(of,"%f ",toBARK(22050.f*j/n));
-         else
-           if(off!=0)
-             fprintf(of,"%f ",(double)(j+off)/44100.);
-           else
-           fprintf(of,"%f ",(double)j);
-         
-         if(dB){
-           fprintf(of,"%f\n",todB(v+j));
-         }else{
-           fprintf(of,"%f\n",v[j]);
-         }
-       }
+      if(bark){
+       float oc=toOC((22050.f*j/n)+.25)*.5;
+       if(oc<0)continue;
+       fprintf(of,"%f ",toOC((22050.f*j/n)+.25));
+      }else
+       if(off!=0)
+         fprintf(of,"%f ",(double)(j+off)/44100.);
+       else
+         fprintf(of,"%f ",(double)j);
+      
+      if(dB){
+       float val;
+       if(v[j]==0.)
+         val=-140.;
+       else
+         val=todB(v+j);
+       fprintf(of,"%f\n",val);
+      }else{
+       fprintf(of,"%f\n",v[j]);
       }
     }
     fclose(of);
index 24dc29c..08e3f5e 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: bark scale utility
- last mod: $Id: barkmel.c,v 1.10 2002/06/28 22:19:35 xiphmont Exp $
+ last mod: $Id: barkmel.c,v 1.11 2002/06/30 08:31:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -51,7 +51,14 @@ int main(){
 
 
   }
-
+  {
+    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);
 }
 
index b7aa888..f8117b9 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: bitrate tracking and management
- last mod: $Id: bitrate.c,v 1.13 2002/06/28 22:19:35 xiphmont Exp $
+ last mod: $Id: bitrate.c,v 1.14 2002/06/30 08:31:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -293,7 +293,7 @@ int vorbis_bitrate_addblock(vorbis_block *vb){
        /* apply the average floater to new blocks */
        bin=rint(bm->avgfloat);
 
-       /*fprintf(stderr,"%d ",bin);*/
+       fprintf(stderr,"%d ",bin);
 
        
        while(bm->avg_centeracc>desired_center){
index 82929bc..aa129c2 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: highlevel encoder setup struct seperated out for vorbisenc clarity
- last mod: $Id: highlevel.h,v 1.2 2002/06/28 22:19:35 xiphmont Exp $
+ last mod: $Id: highlevel.h,v 1.3 2002/06/30 08:31:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -24,6 +24,7 @@ typedef struct highlevel_byblocktype {
   
 typedef struct highlevel_encode_setup {
   void *setup;
+  int   set_in_stone;
 
   double base_setting;
   double long_setting;
index 43343dd..04f8038 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: maintain the info structure, info <-> header packets
- last mod: $Id: info.c,v 1.54 2002/06/28 22:19:35 xiphmont Exp $
+ last mod: $Id: info.c,v 1.55 2002/06/30 08:31:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -415,7 +415,7 @@ static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
 }
 
 static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
-  char temp[]="Xiphophorus libVorbis I 20020623";
+  char temp[]="Xiphophorus libVorbis I 20020630";
   int bytes = strlen(temp);
 
   /* preamble */  
index 00d52d1..0492ae1 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: channel mapping 0 implementation
- last mod: $Id: mapping0.c,v 1.50 2002/06/28 22:19:35 xiphmont Exp $
+ last mod: $Id: mapping0.c,v 1.51 2002/06/30 08:31:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -160,6 +160,73 @@ static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb)
 #if 0
 static long seq=0;
 static ogg_int64_t total=0;
+static float FLOOR1_fromdB_LOOKUP[256]={
+  1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F, 
+  1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F, 
+  1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F, 
+  2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F, 
+  2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F, 
+  3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F, 
+  4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F, 
+  6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F, 
+  7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F, 
+  1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F, 
+  1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F, 
+  1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F, 
+  2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F, 
+  2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F, 
+  3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F, 
+  4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F, 
+  5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F, 
+  7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F, 
+  9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F, 
+  1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F, 
+  1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F, 
+  2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F, 
+  2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F, 
+  3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F, 
+  4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F, 
+  5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F, 
+  7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F, 
+  9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F, 
+  0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F, 
+  0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F, 
+  0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F, 
+  0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F, 
+  0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F, 
+  0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F, 
+  0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F, 
+  0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F, 
+  0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F, 
+  0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F, 
+  0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F, 
+  0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F, 
+  0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F, 
+  0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F, 
+  0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F, 
+  0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F, 
+  0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F, 
+  0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F, 
+  0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F, 
+  0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F, 
+  0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F, 
+  0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F, 
+  0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F, 
+  0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F, 
+  0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F, 
+  0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F, 
+  0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F, 
+  0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F, 
+  0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F, 
+  0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F, 
+  0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F, 
+  0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F, 
+  0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F, 
+  0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F, 
+  0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F, 
+  0.82788260F, 0.88168307F, 0.9389798F, 1.F, 
+};
+
 #endif 
 
 extern int *floor1_fit(vorbis_block *vb,vorbis_look_floor *look,
@@ -491,75 +558,8 @@ static int mapping0_forward(vorbis_block *vb){
                                 ilogmask);
 #if 0
        {
-         static float FLOOR1_fromdB_LOOKUP[256]={
-           1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F, 
-           1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F, 
-           1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F, 
-           2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F, 
-           2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F, 
-           3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F, 
-           4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F, 
-           6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F, 
-           7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F, 
-           1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F, 
-           1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F, 
-           1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F, 
-           2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F, 
-           2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F, 
-           3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F, 
-           4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F, 
-           5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F, 
-           7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F, 
-           9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F, 
-           1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F, 
-           1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F, 
-           2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F, 
-           2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F, 
-           3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F, 
-           4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F, 
-           5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F, 
-           7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F, 
-           9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F, 
-           0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F, 
-           0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F, 
-           0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F, 
-           0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F, 
-           0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F, 
-           0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F, 
-           0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F, 
-           0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F, 
-           0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F, 
-           0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F, 
-           0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F, 
-           0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F, 
-           0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F, 
-           0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F, 
-           0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F, 
-           0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F, 
-           0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F, 
-           0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F, 
-           0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F, 
-           0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F, 
-           0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F, 
-           0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F, 
-           0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F, 
-           0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F, 
-           0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F, 
-           0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F, 
-           0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F, 
-           0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F, 
-           0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F, 
-           0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F, 
-           0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F, 
-           0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F, 
-           0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F, 
-           0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F, 
-           0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F, 
-           0.82788260F, 0.88168307F, 0.9389798F, 1.F, 
-         };
-
          char buf[80];
-         sprintf(buf,"maskI%c%d",i?'L':'R',k);
+         sprintf(buf,"maskI%c%d",i?'R':'L',k);
          float work[n/2];
          for(j=0;j<n/2;j++)
            work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
@@ -571,13 +571,19 @@ static int mapping0_forward(vorbis_block *vb){
                         ilogmask,
                         res,
                         ci->psy_g_param.sliding_lowpass[vb->W][k]);
+
        _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
+
        
 #if 0
        {
          char buf[80];
-         sprintf(buf,"resI%d",k,i);
-         _analysis_output(buf,seq,res,n/2,1,1,0);
+         float work[n/2];
+         for(j=0;j<n/2;j++)
+           work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
+         sprintf(buf,"resI%c%d",i?'R':'L',k);
+         _analysis_output(buf,seq,work,n/2,1,1,0);
+
        }
 #endif
       }
@@ -597,7 +603,8 @@ static int mapping0_forward(vorbis_block *vb){
                   mag_memo,
                   mag_sort,
                   ilogmaskch,
-                  nonzero);
+                  nonzero,
+                  ci->psy_g_param.sliding_lowpass[vb->W][k]);
       }else{
        for(i=0;i<vi->channels;i++)
          memcpy(vb->pcm[i]+n/2,vb->pcm[i],n/2*sizeof(**vb->pcm));
index 0fc56b2..a79c2ac 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: masking curve data for psychoacoustics
- last mod: $Id: masking.h,v 1.22 2002/06/28 22:19:36 xiphmont Exp $
+ last mod: $Id: masking.h,v 1.23 2002/06/30 08:31:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -517,8 +517,8 @@ static float tonemasks[P_BANDS][6][EHMER_MAX]={
    {-999, -999, -999, -999, -999, -999, -999, -999, 
     -999, -103,  -96,  -90,  -86,  -78,  -70,  -51, 
     -42,  -47,  -48,  -55,  -54,  -54,  -53,  -42, 
-    -35,  -28,  -33,  -38,  -36,  -43,  -41,  -43
-    -46,  -60,  -68,  -78,  -82,  -89,  -94,  -99, 
+    -35,  -28,  -33,  -38,  -37,  -44,  -47,  -49
+    -54,  -63,  -68,  -78,  -82,  -89,  -94,  -99, 
     -104, -109, -114, -999, -999, -999, -999, -999, 
     -999, -999, -999, -999, -999, -999, -999, -999}}, 
   /* 2828 Hz */
@@ -538,22 +538,22 @@ static float tonemasks[P_BANDS][6][EHMER_MAX]={
     -999, -999, -999, -999, -999, -999, -999, -999}, 
    {-999, -999, -999, -999, -999, -999, -999, -999, 
     -999, -999, -999, -999, -112,  -93,  -81,  -68, 
-    -62,  -60,  -60,  -57,  -58,  -68,  -77,  -82, 
+    -62,  -60,  -60,  -57,  -63,  -70,  -77,  -82, 
     -90,  -93,  -98, -104, -109, -113, -999, -999, 
     -999, -999, -999, -999, -999, -999, -999, -999, 
     -999, -999, -999, -999, -999, -999, -999, -999, 
     -999, -999, -999, -999, -999, -999, -999, -999}, 
    {-999, -999, -999, -999, -999, -999, -999, -999, 
     -999, -999, -999, -113, -100,  -93,  -84,  -63, 
-    -58,  -48,  -53,  -54,  -52,  -44,  -47,  -56
-    -66,  -72,  -76,  -71,  -80,  -75,  -90,  -95, 
+    -58,  -48,  -53,  -54,  -52,  -52,  -57,  -64
+    -66,  -76,  -83,  -81,  -85,  -85,  -90,  -95, 
     -98, -101, -103, -106, -108, -111, -999, -999, 
     -999, -999, -999, -999, -999, -999, -999, -999, 
     -999, -999, -999, -999, -999, -999, -999, -999}, 
    {-999, -999, -999, -999, -999, -999, -999, -999, 
     -999, -999, -999, -105,  -95,  -86,  -74,  -53, 
     -50,  -38,  -43,  -49,  -43,  -42,  -39,  -39, 
-    -46,  -49,  -49,  -46,  -58,  -61,  -74,  -81, 
+    -46,  -52,  -57,  -56,  -72,  -69,  -74,  -81, 
     -87,  -92,  -94,  -97,  -99, -102, -105, -108, 
     -999, -999, -999, -999, -999, -999, -999, -999, 
     -999, -999, -999, -999, -999, -999, -999, -999}, 
index c9cb1ea..48fe369 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: key psychoacoustic settings for 44.1/48kHz
- last mod: $Id: psych_44.h,v 1.18 2002/06/29 11:18:31 xiphmont Exp $
+ last mod: $Id: psych_44.h,v 1.19 2002/06/30 08:31:03 xiphmont Exp $
 
  ********************************************************************/
 
@@ -108,7 +108,7 @@ static compandblock _psy_compand_44[6]={
 static vp_adjblock _vp_tonemask_adj_longblock[11]={
   /* adjust for mode zero */
   /* 63     125     250     500     1     2     4     8    16 */
-  {{-15,-15,-15,-15,-15,-12,-10,-8, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 0 */
+  {{-15,-15,-15,-15,-15,-12,-10,-8, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 1 */
   {{-15,-15,-15,-15,-15,-12,-10,-8, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 1 */
   {{-15,-15,-15,-15,-15,-12,-10,-8, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
   {{-15,-15,-15,-15,-15,-12,-10,-8, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 3 */
@@ -123,7 +123,7 @@ static vp_adjblock _vp_tonemask_adj_longblock[11]={
 static vp_adjblock _vp_tonemask_adj_otherblock[11]={
   /* adjust for mode zero */
   /* 63     125     250     500       1     2     4     8    16 */
-  {{-20,-20,-20,-20,-20,-18,-16,-14,-10, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 0 */
+  {{-20,-20,-20,-20,-20,-18,-16,-14,-10, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 1 */
   {{-20,-20,-20,-20,-20,-18,-16,-14,-10, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 1 */
   {{-20,-20,-20,-20,-20,-18,-16,-14,-10, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
   {{-20,-20,-20,-20,-20,-18,-16,-14,-10, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 3 */
@@ -139,15 +139,27 @@ static vp_adjblock _vp_tonemask_adj_otherblock[11]={
 static noise3 _psy_noisebias_trans_low[2]={
   /*  63     125     250     500      1k       2k      4k      8k     16k*/
   /* 0 */
-  {{{-15,-15,-15,-15,-15,-12,-10, -8,  0,  2,  4,  4,  5,  5,  5,  8,  10},
-    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2,  0,  0,  0,  2,  4,  10},
-    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4,  -2}}},
+  {{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 12, 16, 16, 30},
+    {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2,  2,  2,  4,  8,  8, 15},
+    {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
   /* 1 */
-  {{{-15,-15,-15,-15,-15,-12,-10, -8,  0,  2,  4,  4,  5,  5,  5,  8,  10},
-    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2,  0,  0,  0,  2,  4,  10},
-    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4,  -2}}},
+  {{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 14, 20, 20, 30},
+    {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2,  2,  2,  4,  8,  8, 15},
+    {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
+};
+static noise3 _psy_noisebias_long_low[2]={
+    /*63     125     250     500      1k       2k      4k      8k     16k*/
+  /* 0 */
+  {{{-10,-10,-10,-10,-10, -4,  0,  0,  0,  6,  6,  6,  6, 10, 10, 10,  20},
+    {-20,-20,-20,-20,-20,-20,-10, -2,  0,  0,  0,  0,  0,  2,  4,  8,  15},
+    {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
+  /* 1 */
+  {{{-10,-10,-10,-10,-10, -4,  0,  0,  0,  6,  6,  6,  6, 10, 10, 10,  20},
+    {-20,-20,-20,-20,-20,-20,-10, -2,  0,  0,  0,  0,  0,  2,  4,  8,  15},
+    {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
 };
 
+
 static noise3 _psy_noisebias_trans[11]={
   /*  63     125     250     500      1k       2k      4k      8k     16k*/
   /* 0 */
@@ -156,7 +168,7 @@ static noise3 _psy_noisebias_trans[11]={
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4,  -2}}},
   /* 1 */
   {{{-15,-15,-15,-15,-15,-12,-10, -8,  0,  2,  4,  4,  5,  5,  5,  8,  10},
-    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2,  0,  2,  6},
+    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2,  0,  2,  8},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
   /* 2 */
   {{{-15,-15,-15,-15,-15,-12,-10, -8,  0,  2,  2,  2,  4,  4,  5,  6,  10},
@@ -164,11 +176,11 @@ static noise3 _psy_noisebias_trans[11]={
     {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
   /* 3 */
   {{{-15,-15,-15,-15,-15,-12,-10, -8,  0,  2,  2,  2,  4,  4,  4,  5,  8},
-    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -1,  1,  4},
+    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -1,  1,  6},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
   /* 4 */
   {{{-20,-20,-20,-20,-20,-18,-14, -8, -1,  1,  1,  1,  2,  3,  3,  4,  7},
-    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -1,  1,  4},
+    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -1,  1,  5},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
   /* 5 */
   {{{-24,-24,-24,-24,-20,-18,-14, -8, -1,  1,  1,  1,  2,  3,  3,  4,  7},
@@ -179,7 +191,7 @@ static noise3 _psy_noisebias_trans[11]={
     {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -4, -2,  2},
     {-34,-34,-34,-34,-30,-26,-24,-18,-17,-15,-15,-15,-15,-13,-13,-12, -8}}},
   /* 7 */
-  {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2,  0,  0,  0,  1,  2,  3,  7},
+  {{{-24,-24,-24,-24,-20,-18,-14, -8, -1,  1,  1,  1,  2,  3,  3,  4, 7},
     {-32,-32,-32,-32,-28,-24,-24,-18,-14,-12,-10, -8, -8, -8, -6, -4,  0},
     {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
   /* 8 */
@@ -188,7 +200,7 @@ static noise3 _psy_noisebias_trans[11]={
     {-36,-36,-36,-36,-34,-30,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
   /* 9 */
   {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2,  2},
-    {-40,-40,-40,-40,-35,-35,-35,-29,-23,-19,-17,-15,-15,-15,-13,-11, -7},
+    {-36,-36,-36,-36,-34,-32,-32,-28,-20,-16,-16,-16,-16,-14,-12,-10, -7},
     {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
   /* 10 */
   {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
@@ -196,18 +208,6 @@ static noise3 _psy_noisebias_trans[11]={
     {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
 };
 
-static noise3 _psy_noisebias_long_low[2]={
-    /*63     125     250     500      1k       2k      4k      8k     16k*/
-  /* 0 */
-  {{{-10,-10,-10,-10,-10,-10, -8, -8,  0,  2,  4,  4,  5,  5,  5,  8,  10},
-    {-20,-20,-20,-20,-20,-20,-20,-10, -6, -2,  0,  0,  0,  0,  2,  4,  10},
-    {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
-  /* 0 */
-  {{{-10,-10,-10,-10,-10,-10, -8, -8,  0,  2,  4,  4,  5,  5,  5,  8,  10},
-    {-20,-20,-20,-20,-20,-20,-20,-10, -6, -2,  0,  0,  0,  0,  2,  4,  10},
-    {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
-};
-
 static noise3 _psy_noisebias_long[11]={
     /*63     125     250     500      1k       2k      4k      8k     16k*/
   /* 0 */
@@ -216,7 +216,7 @@ static noise3 _psy_noisebias_long[11]={
     {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
   /* 1 */
   {{{-10,-10,-10,-10,-10,-10, -8, -8,  0,  2,  4,  4,  5,  5,  5,  8,  10},
-    {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2,  0,  2,  6},
+    {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2,  0,  2,  8},
     {-20,-20,-20,-20,-20,-20,-20,-14, -8, -8, -8, -8, -8, -6, -6, -6, -4}}},
   /* 2 */
   {{{-10,-10,-10,-10,-10,-10,-10, -8,  0,  2,  2,  2,  4,  4,  5,  6,  10},
@@ -224,11 +224,11 @@ static noise3 _psy_noisebias_long[11]={
     {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
   /* 3 */
   {{{-10,-10,-10,-10,-10,-10,-10, -8,  0,  2,  2,  2,  4,  4,  4,  5,  8},
-    {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -1,  1,  4},
+    {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -1,  1,  6},
     {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
   /* 4 */
   {{{-15,-15,-15,-15,-15,-15,-15,-10, -4,  1,  1,  1,  2,  3,  3,  4,  7},
-    {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -1,  1,  4},
+    {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -1,  1,  5},
     {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
   /* 5 */
   {{{-15,-15,-15,-15,-15,-15,-15,-10, -4,  1,  1,  1,  2,  3,  3,  4,  7},
@@ -239,7 +239,7 @@ static noise3 _psy_noisebias_long[11]={
     {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -4, -2,  2},
     {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12, -8}}},
   /* 7 */
-  {{{-15,-15,-15,-15,-15,-15,-15,-10, -4,  0,  0,  0,  0,  1,  2,  3,  7},
+  {{{-15,-15,-15,-15,-15,-15,-15,-10, -4,  1,  1,  1,  2,  3,  3,  4,  7},
     {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4,  0},
     {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
   /* 8 */
@@ -248,7 +248,7 @@ static noise3 _psy_noisebias_long[11]={
     {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
   /* 9 */
   {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2,  2},
-    {-30,-30,-30,-30,-30,-30,-30,-25,-21,-17,-15,-15,-15,-15,-13,-11, -7},
+    {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
     {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
   /* 10 */
   {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
@@ -259,44 +259,44 @@ static noise3 _psy_noisebias_long[11]={
 static noise3 _psy_noisebias_impulse[11]={
   /*  63     125     250     500      1k      2k      4k      8k     16k*/
   /* 0 */
-  {{{-16,-16,-16,-16,-16,-13,-10, -7, -4, -1,  2,  5,  8, 11, 14, 17, 20},
+  {{{-10,-10,-10,-10,-10,-4, 0,  0,  4,  8,  8,  8,  8, 14, 20, 20, 30},
     {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -2,  2,  2,  4,  4,  5,  8},
     {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
   /* 1 */
-  {{{-16,-16,-16,-16,-16,-13,-10, -7, -4, -1,  2,  2,  4,  8, 10, 12, 15},
+  {{{-12,-12,-12,-12,-12,-8,-6, -4,  0,  4,  4,  4,  4, 10, 12, 14, 20},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4,  0,  0,  0,  0,  0,  4},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
   /* 2 */
-  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  2,  2,  2,  2,  3,  3,  6, 10},
+  {{{-14,-14,-14,-14,-14,-10,-8, -6, -2,  2,  2,  2,  2,  8, 10, 10, 16},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4,  0,  0,  0,  0,  0,  4},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
   /* 3 */
-  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  2,  2,  2,  2,  2,  3,  4,  8},
+  {{{-14,-14,-14,-14,-14,-10,-8, -6, -2,  2,  2,  2,  2,  6, 8, 8, 14},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -1, -1, -1, -1,  0,  3},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
   /* 4 */
-  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  2,  2,  2,  2,  2,  3,  4,  8},
+  {{{-16,-16,-16,-16,-16,-12,-10, -6, -2,  0,  0,  0,  0,  4, 6, 6, 12},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -1, -1, -1, -1,  0,  3},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
   /* 5 */
-  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  2,  2,  2,  2,  2,  3,  4,  8},
+  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  0,  0,  0,  0,  4,  4,  6, 11},
     {-32,-32,-32,-32,-28,-24,-22,-16,-12, -8, -6, -3, -3, -3, -2, -1,  2},
     {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
   /* 6 */
-  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  2,  2,  2,  2,  2,  3,  4,  8},
+  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  0,  0,  0,  0,  4,  4,  6, 11},
     {-34,-34,-34,-34,-30,-30,-24,-20,-14,-10, -6, -6, -6, -6, -3, -2,  2},
     {-34,-34,-34,-34,-34,-30,-26,-20,-16,-15,-15,-15,-15,-15,-13,-12, -8}}},
   /* 7 */
-  {{{-24,-24,-24,-24,-22,-20,-14,-10, -8, -2,  0,  0,  0,  1,  2,  3,  7},
+  {{{-22,-22,-22,-22,-22,-20,-14,-10, -6,  0,  0,  0,  0,  4,  4,  6, 11},
     {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -6, -2},
     {-34,-34,-34,-34,-32,-32,-30,-24,-20,-19,-19,-19,-19,-19,-17,-16,-12}}},
   /* 8 */
-  {{{-24,-24,-24,-24,-22,-20,-14,-10, -8, -2,  0,  0,  0,  1,  2,  3,  7},
+  {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1,  3,  3,  5, 10},
     {-34,-34,-34,-34,-30,-30,-30,-24,-18,-14,-12,-10,-10,-10, -9, -8, -4},
     {-36,-36,-36,-36,-36,-34,-28,-24,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
   /* 9 */
   {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2,  2},
-    {-40,-40,-40,-40,-35,-35,-35,-29,-23,-19,-17,-15,-15,-15,-15,-15,-10},
+    {-36,-36,-36,-36,-34,-32,-32,-26,-20,-16,-16,-16,-16,-14,-12,-10, -7},
     {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
   /* 10 */
   {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
@@ -307,44 +307,44 @@ static noise3 _psy_noisebias_impulse[11]={
 static noise3 _psy_noisebias_padding[11]={
   /*  63     125     250     500      1k       2k      4k      8k     16k*/
   /* 0 */
-  {{{-16,-16,-16,-16,-16,-13,-10, -7, -4, -1,  2,  5,  8, 11, 14, 17, 20},
+  {{{-10,-10,-10,-10,-10,-4, 0,  0,  4, -8,  8,  8,  8, 14, 20, 20, 30},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2,  2,  3,  6,  6,  8, 10},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2,  0,  2}}},
   /* 1 */
-  {{{-16,-16,-16,-16,-16,-13,-10, -7, -4, -1,  2,  2,  4,  8, 10, 12, 15},
+  {{{-12,-12,-12,-12,-12,-8,-6, -4,  0,  4,  4,  4,  4, 10, 12, 14, 20},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4,  0,  0,  0,  2,  2,  4,  8},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2,  0}}},
   /* 2 */
-  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  2,  2,  2,  2,  5,  5,  8, 10},
+  {{{-14,-14,-14,-14,-14,-10,-8, -6, -2,  2,  2,  2,  2,  8, 10, 10, 16},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4,  0,  0,  0,  2,  2,  4,  8},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
   /* 3 */
-  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  2,  2,  2,  3,  3,  4,  6,  9},
-    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1,  0,  2,  6},
+  {{{-14,-14,-14,-14,-14,-10,-8, -6, -2,  2,  2,  2,  2,  6, 8, 8, 14},
+    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1,  0,  0,  2,  6},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
   /* 4 */
-  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  2,  2,  2,  3,  3,  4,  6,  9},
+  {{{-16,-16,-16,-16,-16,-12,-10, -6, -2,  0,  0,  0,  0,  4, 6, 6, 12},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1,  0,  2,  6},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
   /* 5 */
-  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  2,  2,  2,  3,  3,  4,  6,  9},
+  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  0,  0,  0,  0,  4,  6,  6, 12},
     {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2,  0,  4},
     {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
   /* 6 */
-  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  2,  2,  2,  3,  3,  4,  6,  9},
+  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  0,  0,  0,  0,  4,  6,  6, 12},
     {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1,  4},
     {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
   /* 7 */
-  {{{-24,-24,-24,-24,-24,-20,-18,-12, -8, -2,  1,  1,  2,  2,  3,  5,  8},
+  {{{-20,-20,-20,-20,-20,-18,-14,-10, -4,  0,  0,  0,  0,  4,  6,  6, 12},
     {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3,  1},
     {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
   /* 8 */
-  {{{-24,-24,-24,-24,-24,-20,-18,-12, -8, -2,  1,  1,  2,  2,  3,  5,  8},
+  {{{-22,-22,-22,-22,-22,-20,-14,-10, -4,  0,  0,  0,  0,  3,  5,  5, 11},
     {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
     {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
   /* 9 */
-  {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, -2,  0,  2},
-    {-40,-40,-40,-40,-35,-35,-35,-29,-21,-17,-15,-13,-13,-13,-12,-10, -7},
+  {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2,  0,  2,  6},
+    {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
     {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
   /* 10 */
   {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
@@ -405,62 +405,62 @@ static int _psy_ath_abs[11]={
 /* stereo mode by base quality level */
 static adj_stereo _psy_stereo_modes_44_low[2]={
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         0  */
-  {{  5,  5,  5,  5,  4,  4,  4,  3,  2,  2,  1,  0,  0,  0,  0},
+  {{  4,  4,  4,  4,  4,  4,  4,  3,  2,  2,  1,  0,  0,  0,  0},
    {  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  5,  4,  3},
    {  1,  2,  3,  4,  4,  4,  4,  4,  4,  5,  6,  7,  8,  8,  8},
-   { 10, 12, 14, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
+   { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         1  */
-  {{  5,  5,  5,  5,  4,  4,  4,  3,  2,  2,  1,  0,  0,  0,  0},
+  {{  4,  4,  4,  4,  4,  4,  4,  3,  2,  2,  1,  0,  0,  0,  0},
    {  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  5,  4,  3},
    {  1,  2,  3,  4,  4,  4,  4,  4,  4,  5,  6,  7,  8,  8,  8},
-   { 10, 12, 14, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
+   { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
 };
 
 static adj_stereo _psy_stereo_modes_44[11]={
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         0  */
-  {{  5,  5,  5,  5,  4,  4,  4,  3,  2,  2,  1,  0,  0,  0,  0},
+  {{  4,  4,  4,  4,  4,  4,  4,  3,  2,  2,  1,  0,  0,  0,  0},
    {  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  5,  4,  3},
    {  1,  2,  3,  4,  4,  4,  4,  4,  4,  5,  6,  7,  8,  8,  8},
-   { 10, 12, 14, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
+   { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         1  */
-  {{  4,  4,  4,  4,  4,  4,  3,  3,  2,  1,  0,  0,  0,  0,  0},
-   {  8,  8,  8,  8,  6,  6,  6,  5,  5,  5,  5,  5,  5,  4,  3},
+  {{  3,  3,  3,  3,  3,  3,  3,  3,  2,  1,  0,  0,  0,  0,  0},
+   {  8,  8,  8,  8,  6,  6,  5,  5,  5,  5,  5,  5,  5,  4,  3},
    {  1,  2,  3,  4,  4,  5,  6,  6,  6,  6,  6,  8,  8,  8,  8},
    { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         2  */
-  {{  4,  4,  4,  3,  3,  3,  2,  2,  2,  1,  0,  0,  0,  0,  0},
-   {  8,  8,  8,  7,  5,  5,  5,  5,  5,  5,  5,  4,  3,  2,  1},
-   {  4,  4,  4,  4,  5,  6,  6,  6,  6,  6,  6,  8,  8,  8,  8},
+  {{  3,  3,  3,  3,  3,  3,  2,  2,  2,  1,  0,  0,  0,  0,  0},
+   {  8,  8,  8,  6,  5,  5,  5,  5,  5,  5,  5,  4,  3,  2,  1},
+   {  3,  4,  4,  4,  5,  6,  6,  6,  6,  6,  6,  8,  8,  8,  8},
    { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         3  */
-  {{  3,  3,  3,  3,  3,  3,  2,  1,  1,  0,  0,  0,  0,  0,  0},
-   {  7,  6,  5,  4,  4,  4,  4,  4,  4,  4,  4,  4,  3,  2,  1},
-   {  6,  6,  6,  6,  6,  6,  6,  6,  8,  8, 10, 10, 10, 10, 10},
+  {{  2,  2,  2,  2,  2,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0},
+   {  5,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  3,  2,  1},
+   {  4,  4,  5,  6,  6,  6,  6,  6,  8,  8, 10, 10, 10, 10, 10},
    { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         4  */
-  {{  3,  3,  3,  2,  2,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0},
-   {  7,  6,  5,  4,  4,  4,  4,  4,  4,  4,  3,  3,  2,  1,  0},
-   {  6,  6,  6,  8,  8,  8, 10, 10, 10, 10, 10, 10, 10, 10, 10},
+  {{  2,  2,  2,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0},
+   {  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  3,  3,  2,  1,  0},
+   {  6,  6,  6,  8,  8,  8,  8,  8,  8,  8, 10, 10, 10, 10, 10},
    { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         5  */
-  {{  2,  2,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
-   {  5,  5,  5,  4,  4,  4,  4,  3,  3,  3,  3,  2,  1,  0,  0},
-   {  6,  6,  6,  8,  8,  8, 10, 10, 10, 10, 10, 10, 10, 10, 10},
+  {{  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
+   {  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  1,  1,  0,  0},
+   {  6,  6,  8,  8,  8,  8, 10, 10, 10, 10, 10, 10, 10, 10, 10},
    { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         6  */
-  {{  2,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
-   {  4,  4,  4,  3,  3,  3,  2,  2,  2,  2,  1,  1,  0,  0,  0},
+  {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
+   {  3,  3,  3,  2,  2,  2,  1,  1,  1,  1,  1,  0,  0,  0,  0},
    {  8,  8,  8,  8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
    { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         7  */
-  {{  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
-   {  4,  4,  3,  3,  2,  2,  1,  1,  1,  1,  1,  0,  0,  0,  0},
-   {  8,  8,  8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
+  {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
+   {  2,  2,  2,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0},
+   {  8,  8,  8,  8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
    { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         8  */
   {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
-   {  3,  3,  2,  2,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0},
-   {  8,  8,  8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
+   {  2,  2,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
+   {  8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
    { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
   /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14         9  */
   {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
@@ -477,21 +477,21 @@ static adj_stereo _psy_stereo_modes_44[11]={
 /* tone master attenuation by base quality mode and bitrate tweak */
 
 static att3 _psy_tone_masteratt_44_low[2]={
-  {{ 45,  20,   8}, -6, 1.25}, /* 0 */
-  {{ 45,  20,   8}, -6, 1.25}, /* 0 */
+  {{ 34,  20,   8}, -6, 1.25}, /* 0 */
+  {{ 34,  20,   8}, -6, 1.25}, /* 1 */
 };
 static att3 _psy_tone_masteratt_44[11]={
-  {{ 45,  20,   8}, -6, 1.25}, /* 0 */
-  {{ 40,  14,   4}, -4, 1.25}, /* 1 */
-  {{ 34,  10,  -2},  0,    0}, /* 2 */
-  {{ 28,  10,  -4},  0,    0}, /* 3 */
-  {{ 24,  10,  -4},  0,    0}, /* 4 */
+  {{ 30,  20,   8}, -6, 1.25}, /* 0 */
+  {{ 25,  14,   4}, -4, 1.25}, /* 1 */
+  {{ 20,  10,  -2},  0,    0}, /* 2 */
+  {{ 20,   9,  -4},  0,    0}, /* 3 */
+  {{ 20,   9,  -4},  0,    0}, /* 4 */
   {{ 20,   6,  -6},  0,    0}, /* 5 */
   {{ 20,   3, -10},  0,    0}, /* 6 */
   {{ 18,   1, -14},  0,    0}, /* 7 */
   {{ 18,   0, -16},  0,    0}, /* 8 */
-  {{ 16,  -2, -16},  0,    0}, /* 9 */
-  {{ 16,  -2, -16},  0,    0}, /* 10 */
+  {{ 18,  -2, -16},  0,    0}, /* 9 */
+  {{ 12,  -2, -20},  0,    0}, /* 10 */
 };
 
 /* lowpass by mode **************/
@@ -505,10 +505,10 @@ static double _psy_lowpass_44[11]={
 /* noise normalization **********/
 
 static int _noise_start_short_44[10]={
-  16,16,16,16,16,16,16,16,16,16
+  16,16,16,16,32,64,9999,9999,9999,9999
 };
 static int _noise_start_long_44[10]={
-  128,128,128,128,128,128,128,128,128,128
+  128,128,128,256,512,9999,9999,9999,9999,9999
 };
 static int _noise_part_short_44[10]={
   8,8,8,8,8,8,8,8,8,8
@@ -519,3 +519,11 @@ static int _noise_part_long_44[10]={
 static double _noise_thresh_44[10]={
   .2,.2,.3,.4,.5,.5,.5,.5,.5,.5,
 };
+
+
+static int _noise_start_short_44_low[2]={
+  32,32
+};
+static int _noise_start_long_44_low[2]={
+  256,256
+};
index 1179197..e856ba6 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: toplevel settings for 44.1/48kHz
- last mod: $Id: setup_44.h,v 1.4 2002/06/29 11:18:31 xiphmont Exp $
+ last mod: $Id: setup_44.h,v 1.5 2002/06/30 08:31:04 xiphmont Exp $
 
  ********************************************************************/
 
@@ -150,7 +150,7 @@ ve_setup_data_template ve_setup_44_stereo_low={
   _psy_compand_short_mapping,
   _psy_compand_long_mapping,
 
-  {_noise_start_short_44,_noise_start_long_44},
+  {_noise_start_short_44_low,_noise_start_long_44_low},
   {_noise_part_short_44,_noise_part_long_44},
   _noise_thresh_44,
 
index dc015e9..3fc23da 100644 (file)
--- a/lib/psy.c
+++ b/lib/psy.c
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: psychoacoustics not including preecho
- last mod: $Id: psy.c,v 1.69 2002/06/29 13:13:54 msmith Exp $
+ last mod: $Id: psy.c,v 1.70 2002/06/30 08:31:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -208,6 +208,32 @@ static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
 
       }
 
+      /* be equally paranoid about being valid up to next half ocatve */
+      if(i+1<P_BANDS){
+       int l=0;
+       k=i+1;
+       for(j=0;j<EHMER_MAX;j++){
+         int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
+         int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
+         
+         if(lo_bin<0)lo_bin=0;
+         if(lo_bin>n)lo_bin=n;
+         if(lo_bin<l)l=lo_bin;
+         if(hi_bin<0)hi_bin=0;
+         if(hi_bin>n)hi_bin=n;
+
+         for(;l<hi_bin && l<n;l++)
+           if(brute_buffer[l]>workc[k][m][j])
+             brute_buffer[l]=workc[k][m][j];
+       }
+
+       for(;l<n;l++)
+         if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
+           brute_buffer[l]=workc[k][m][EHMER_MAX-1];
+
+      }
+
+
       for(j=0;j<EHMER_MAX;j++){
        int bin=fromOC(j*.125+i*.5-2.)/binHz;
        if(bin<0){
@@ -285,7 +311,7 @@ void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
   }
 
   for(i=0;i<n;i++)
-    p->octave[i]=toOC((i*.5f+.25f)*rate/n)*(1<<(p->shiftoc+1))+.5f;
+    p->octave[i]=toOC(((i+.25f)*.5)*rate/n)*(1<<(p->shiftoc+1))+.5f;
 
   p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
                                  vi->tone_centerboost,vi->tone_decay);
@@ -396,6 +422,7 @@ static void seed_loop(vorbis_look_psy *p,
     
     if(max+6.f>flr[i]){
       oc=oc>>p->shiftoc;
+
       if(oc>=P_BANDS)oc=P_BANDS-1;
       if(oc<0)oc=0;
 
@@ -846,7 +873,6 @@ static void precomputed_couple_point(float premag,
   floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
 
   *mag=premag*floormag;
-
   *ang=0.f;
 }
 
@@ -936,6 +962,7 @@ void _vp_noise_normalize_sort(vorbis_look_psy *p,
   }
 }
 
+#include <stdio.h>
 void _vp_noise_normalize(vorbis_look_psy *p,
                         float *in,float *out,int *sortedindex){
   int flag=0,i,j=0,n=p->n;
@@ -943,6 +970,8 @@ void _vp_noise_normalize(vorbis_look_psy *p,
   int partition=vi->normal_partition;
   int start=vi->normal_start;
 
+  if(start>n)start=n;
+
   if(vi->normal_channel_p){
     for(;j<start;j++)
       out[j]=rint(in[j]);
@@ -989,7 +1018,8 @@ void _vp_couple(int blobno,
                float **mag_memo,
                int   **mag_sort,
                int   **ifloor,
-               int   *nonzero){
+               int   *nonzero,
+               int  sliding_lowpass){
 
   int i,j,k,n=p->n;
 
@@ -1017,10 +1047,11 @@ void _vp_couple(int blobno,
       float *qA=rA+n;
       int *floorM=ifloor[vi->coupling_mag[i]];
       int *floorA=ifloor[vi->coupling_ang[i]];
-      int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
       float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
       float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
       int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
+      int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
+      int pointlimit=limit;
 
       nonzero[vi->coupling_mag[i]]=1; 
       nonzero[vi->coupling_ang[i]]=1; 
@@ -1030,25 +1061,32 @@ void _vp_couple(int blobno,
 
        for(k=0;k<partition;k++){
          int l=k+j;
-         if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
-            (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
-           precomputed_couple_point(mag_memo[i][l],
-                                    floorM[l],floorA[l],
-                                    qM+l,qA+l);
-           if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
+
+         if(l<sliding_lowpass){
+           if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
+              (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
+             precomputed_couple_point(mag_memo[i][l],
+                                      floorM[l],floorA[l],
+                                      qM+l,qA+l);
+             if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
+           }else{
+             couple_lossless(rM[l],rA[l],qM+l,qA+l);
+           }
          }else{
-           couple_lossless(rM[l],rA[l],qM+l,qA+l);
+           qM[l]=0.;
+           qA[l]=0.;
          }
        }
        
-       if(p->vi->normal_point_p)
+       if(p->vi->normal_point_p){
          for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
            int l=mag_sort[i][j+k];
-           if(l>=limit && rint(qM[l])==0.f){
+           if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
              qM[l]=unitnorm(qM[l]);
              acc-=1.f;
            }
          } 
+       }
       }
     }
   }
index 69d8694..799d250 100644 (file)
--- a/lib/psy.h
+++ b/lib/psy.h
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: random psychoacoustics (not including preecho)
- last mod: $Id: psy.h,v 1.29 2002/06/28 22:19:37 xiphmont Exp $
+ last mod: $Id: psy.h,v 1.30 2002/06/30 08:31:01 xiphmont Exp $
 
  ********************************************************************/
 
@@ -156,7 +156,8 @@ extern void _vp_couple(int blobno,
                       float **mag_memo,
                       int   **mag_sort,
                       int   **ifloor,
-                      int   *nonzero);
+                      int   *nonzero,
+                      int   sliding_lowpass);
 
 extern void _vp_noise_normalize(vorbis_look_psy *p,
                                float *in,float *out,int *sortedindex);
index ac1aced..a3e3f2c 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: simple programmatic interface for encoder mode setup
- last mod: $Id: vorbisenc.c,v 1.42 2002/06/29 13:24:37 msmith Exp $
+ last mod: $Id: vorbisenc.c,v 1.43 2002/06/30 08:31:01 xiphmont Exp $
 
  ********************************************************************/
 
@@ -93,8 +93,8 @@ typedef struct {
   double  *rate_mapping;
   double  *quality_mapping;
   int      coupling_restriction;
-  long     bitrate_min_restriction;
-  long     bitrate_max_restriction;
+  long     samplerate_min_restriction;
+  long     samplerate_max_restriction;
 
 
   int     *blocksize_short;
@@ -583,8 +583,8 @@ static void get_setup_template(vorbis_info *vi,
   while(setup_list[i]){
     if(setup_list[i]->coupling_restriction==-1 ||
        setup_list[i]->coupling_restriction==ch){
-      if(srate>=setup_list[i]->bitrate_min_restriction &&
-        srate<=setup_list[i]->bitrate_max_restriction){
+      if(srate>=setup_list[i]->samplerate_min_restriction &&
+        srate<=setup_list[i]->samplerate_max_restriction){
        int mappings=setup_list[i]->mappings;
        double *map=(q_or_bitrate?
                     setup_list[i]->rate_mapping:
@@ -645,6 +645,7 @@ int vorbis_encode_setup_init(vorbis_info *vi){
   setup=(ve_setup_data_template *)hi->setup;
   if(setup==NULL)return(OV_EINVAL);
 
+  hi->set_in_stone=1;
   /* choose block sizes from configured sizes as well as paying
      attention to long_block_p and short_block_p.  If the configured
      short and long blocks are the same length, we set long_block_p
@@ -838,6 +839,8 @@ int vorbis_encode_setup_vbr(vorbis_info *vi,
   codec_setup_info *ci=vi->codec_setup;
   highlevel_encode_setup *hi=&ci->hi;
 
+  quality+=.00001;
+
   get_setup_template(vi,channels,rate,quality,0);
   if(!hi->setup)return OV_EIMPL;
   
@@ -899,17 +902,18 @@ int vorbis_encode_setup_managed(vorbis_info *vi,
   }
 
   /* initialize management with sane defaults */
-  ci->hi.managed=1;
-
-  ci->hi.bitrate_av_window=4.;
-  ci->hi.bitrate_av_window_center=.5;
-  ci->hi.bitrate_limit_window=2.;
-  ci->hi.bitrate_min=min_bitrate;
-  ci->hi.bitrate_max=max_bitrate;
-  ci->hi.bitrate_av_lo=tnominal;
-  ci->hi.bitrate_av_hi=tnominal;
+      /* initialize management with sane defaults */
+  hi->managed=1;
+  hi->bitrate_av_window=4.;
+  hi->bitrate_av_window_center=.5;
+  hi->bitrate_limit_window=2.;
+  hi->bitrate_min=min_bitrate;
+  hi->bitrate_max=max_bitrate;
+  hi->bitrate_av_lo=tnominal;
+  hi->bitrate_av_hi=tnominal;
 
   return(ret);
+
 }
 
 int vorbis_encode_init(vorbis_info *vi,
@@ -936,5 +940,99 @@ int vorbis_encode_init(vorbis_info *vi,
 }
 
 int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
-  return(OV_EIMPL);
+  if(vi){
+    codec_setup_info *ci=vi->codec_setup;
+    highlevel_encode_setup *hi=&ci->hi;
+    int setp=(number&0xf); /* a read request has a low nibble of 0 */
+
+    if(setp && hi->set_in_stone)return(OV_EINVAL);
+
+    switch(number){
+    case OV_ECTL_RATEMANAGE_GET:
+      {
+       
+       struct ovectl_ratemanage_arg *ai=
+         (struct ovectl_ratemanage_arg *)arg;
+       
+       ai->management_active=hi->managed;
+       ai->bitrate_av_window=hi->bitrate_av_window;
+       ai->bitrate_av_window_center=hi->bitrate_av_window_center;
+       ai->bitrate_hard_window=hi->bitrate_limit_window;
+       ai->bitrate_hard_min=hi->bitrate_min;
+       ai->bitrate_hard_max=hi->bitrate_max;
+       ai->bitrate_av_lo=hi->bitrate_av_lo;
+       ai->bitrate_av_hi=hi->bitrate_av_hi;
+       
+      }
+      return(0);
+    
+    case OV_ECTL_RATEMANAGE_SET:
+      {
+       struct ovectl_ratemanage_arg *ai=
+         (struct ovectl_ratemanage_arg *)arg;
+       if(ai==NULL){
+         hi->managed=0;
+       }else{
+         hi->managed=ai->management_active;
+         vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
+         vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
+       }
+      }
+      return 0;
+
+    case OV_ECTL_RATEMANAGE_AVG:
+      {
+       struct ovectl_ratemanage_arg *ai=
+         (struct ovectl_ratemanage_arg *)arg;
+       if(ai==NULL){
+         hi->bitrate_av_lo=0;
+         hi->bitrate_av_hi=0;
+         hi->bitrate_av_window=0;
+       }else{
+         hi->bitrate_av_window=ai->bitrate_av_window;
+         hi->bitrate_av_window_center=ai->bitrate_av_window_center;
+         hi->bitrate_av_lo=ai->bitrate_av_lo;
+         hi->bitrate_av_hi=ai->bitrate_av_hi;
+       }
+
+       if(hi->bitrate_av_window<.25)hi->bitrate_av_window=.25;
+       if(hi->bitrate_av_window>10.)hi->bitrate_av_window=10.;
+       if(hi->bitrate_av_window_center<0.)hi->bitrate_av_window=0.;
+       if(hi->bitrate_av_window_center>1.)hi->bitrate_av_window=1.;
+       
+       if( ( (hi->bitrate_av_lo<=0 && hi->bitrate_av_hi<=0)||
+             (hi->bitrate_av_window<=0) ) &&
+           ( (hi->bitrate_min<=0 && hi->bitrate_max<=0)||
+             (hi->bitrate_limit_window<=0) ))
+         hi->managed=0;
+      }
+      return(0);
+    case OV_ECTL_RATEMANAGE_HARD:
+      {
+       struct ovectl_ratemanage_arg *ai=
+         (struct ovectl_ratemanage_arg *)arg;
+       if(ai==NULL){
+         hi->bitrate_min=0;
+         hi->bitrate_max=0;
+         hi->bitrate_limit_window=0;
+       }else{
+         hi->bitrate_limit_window=ai->bitrate_hard_window;
+         hi->bitrate_min=ai->bitrate_hard_min;
+         hi->bitrate_max=ai->bitrate_hard_max;
+       }
+       if(hi->bitrate_limit_window<0.)hi->bitrate_limit_window=0.;
+       if(hi->bitrate_limit_window>10.)hi->bitrate_limit_window=10.;
+       
+       if( ( (hi->bitrate_av_lo<=0 && hi->bitrate_av_hi<=0)||
+             (hi->bitrate_av_window<=0) ) &&
+           ( (hi->bitrate_min<=0 && hi->bitrate_max<=0)||
+             (hi->bitrate_limit_window<=0) ))
+         hi->managed=0;
+      }
+      return(0);
+    }
+
+    return(OV_EIMPL);
+  }
+  return(OV_EINVAL);
 }