[xiph-commits] r12030 - in branches/vorbis-aotuv: . lib lib/modes

j at svn.xiph.org j at svn.xiph.org
Sun Nov 5 07:20:17 PST 2006


Author: j
Date: 2006-11-05 07:20:01 -0800 (Sun, 05 Nov 2006)
New Revision: 12030

Added:
   branches/vorbis-aotuv/aoTuV_README-1st.txt
Removed:
   branches/vorbis-aotuv/aoTuV_README.txt
Modified:
   branches/vorbis-aotuv/COPYING
   branches/vorbis-aotuv/aoTuV_technical.txt
   branches/vorbis-aotuv/lib/block.c
   branches/vorbis-aotuv/lib/codec_internal.h
   branches/vorbis-aotuv/lib/info.c
   branches/vorbis-aotuv/lib/mapping0.c
   branches/vorbis-aotuv/lib/modes/psych_11.h
   branches/vorbis-aotuv/lib/modes/psych_44.h
   branches/vorbis-aotuv/lib/modes/setup_32.h
   branches/vorbis-aotuv/lib/psy.c
   branches/vorbis-aotuv/lib/psy.h
   branches/vorbis-aotuv/lib/scales.h
   branches/vorbis-aotuv/lib/vorbisenc.c
Log:
- aoTuV Beta4.51
 # This is a bug fix release.  There is no encode quality-difference fundamentally. 

- aoTuV Beta4.5
 # Reexamination of a low bit rate region, the addition of the code accompanying it, and tuning. Influence has this change below quality3.  Probably, in the especially low bit rate, it will be effective. 



Modified: branches/vorbis-aotuv/COPYING
===================================================================
--- branches/vorbis-aotuv/COPYING	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/COPYING	2006-11-05 15:20:01 UTC (rev 12030)
@@ -1,4 +1,5 @@
-Copyright (c) 2002-2004 Xiph.org Foundation
+aoTuV - Copyright (c) 2003-2005 Aoyumi
+libvorbis - Copyright (c) 2002-2005 Xiph.org Foundation
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions

Added: branches/vorbis-aotuv/aoTuV_README-1st.txt
===================================================================
--- branches/vorbis-aotuv/aoTuV_README-1st.txt	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/aoTuV_README-1st.txt	2006-11-05 15:20:01 UTC (rev 12030)
@@ -0,0 +1,24 @@
+aoTuV beta4.51 release note
+
+"aoTuV" tunes up Xiph.Org's libvorbis uniquely. 
+A license is taken as "BSD-style license" as well as original libvorbis. 
+
+
+# NOTICE #
+
+  Manuke's patch is used for improvement in the speed of sort processing. 
+  When "#define OPT_SORT" of "lib/psy.h" is deleted, the conventional 
+  processing method is used.
+
+
+Thanks! Manuke.
+
+
+
+aoTuV based on <Xiph.Org libvorbis>
+
+Copyright (c) 2002-2005 Xiph.Org Foundation
+Copyright (c) 2003-2005 Aoyumi
+
+
+AUTHOR : aoyumi <aoyumi at inter7.jp>
\ No newline at end of file

Deleted: branches/vorbis-aotuv/aoTuV_README.txt
===================================================================
--- branches/vorbis-aotuv/aoTuV_README.txt	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/aoTuV_README.txt	2006-11-05 15:20:01 UTC (rev 12030)
@@ -1,24 +0,0 @@
-aoTuV beta4 release note
-
-"aoTuV" tunes up Xiph.Org's libvorbis uniquely. 
-A license is taken as "BSD-style license" as well as original libvorbis. 
-
-
-# NOTICE #
-
-  Manuke's patch is used for improvement in the speed of sort processing. 
-  When "#define OPT_SORT" of "lib/psy.h" is deleted, the conventional 
-  processing method is used.
-
-
-Thanks! Manuke.
-
-
-
-aoTuV based on <Xiph.Org libvorbis>
-
-Copyright (c) 2002-2004 Xiph.Org Foundation
-Copyright (c) 2003-2005 Aoyumi
-
-
-AUTHOR : aoyumi <aoyumi at inter7.jp>
\ No newline at end of file

Modified: branches/vorbis-aotuv/aoTuV_technical.txt
===================================================================
--- branches/vorbis-aotuv/aoTuV_technical.txt	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/aoTuV_technical.txt	2006-11-05 15:20:01 UTC (rev 12030)
@@ -1,6 +1,79 @@
-aoTuV beta4 technical information
+aoTuV beta4.51 technical information
 
 
+The differences from the aoTuV beta 4.5...
+
+
+  1.  The changed part of "scale.h" of Xiph.Org SVN was reflected in aoTuV. This will solve the problem of the compile by gcc4. 
+
+  2.  A part of portion added by beta4.5 had caused memory access violation. Depending on environment, a problem arises in qualiy-1/-2. This problem was corrected. 
+
+
+2005/11/17
+Aoyumi
+
+----------------------------------------------------------------------------
+
+aoTuV beta4.5 technical information
+
+
+The differences from the aoTuV beta 4...
+
+
+
+  1.  M4 code of beta3 was deleted. M5 is added as what is replaced with it. The advantage of this method is that the result stabilized more is obtained. Instead, the change width of the bit rate becomes large rather than before. [32/44.1/48kHz only] 
+
+@2.  New M4 was added. There is this for the same purpose as M1. However, it is tuned up only in the low bit rate region according to work and individual parameters. [32/44.1/48kHz only] 
+
+@3.  M2 code was extended. This decreases a specific noise problem.  [32/44.1/48kHz only] 
+
+...and I mainly tune up tone/noise masking and noise normalization parameters. 
+
+The above change is applied below quality3. 
+
+
+2005/11/05
+Aoyumi
+
+----------------------------------------------------------------------------
+
+aoTuV beta4a technical information
+
+
+The differences from the aoTuV beta 4...
+
+
+
+  1.  Adoption of new hypot (point stereo). This works in general better than
+  dipole/round hypot. And when residue is likely to decrease greatly at the
+  time of a reverse phase, added code is made to increase the ratio of lossless.
+
+  2.  Change of ATH curve. This is not a big change. 
+
+  3.  Residue used for threshold calculation of channel coupling is changed.
+  This one seems to be good selection. 
+
+  4.  HF reduction code of beta3 was deleted. Now, this is not required. 
+
+  5.  The energy deficit of M4 code of beta3 -- correction of a bug Now.
+
+  6.  The code for pulling downward floor of the frequency range which can
+  be easy to be heard was added (New M2). This works by the low bit rate and
+  has a comparatively good trade-off. 
+
+  7.  Change of threshold calculation of noise normalization. Moreover, it
+  takes phase information into consideration. 
+
+
+...and I mainly tune up tone/noise masking parameters. 
+
+
+
+2005/06/18
+Aoyumi
+
+----------------------------------------------------------------------------
+
 The differences from the aoTuV beta 3...
 
 

Modified: branches/vorbis-aotuv/lib/block.c
===================================================================
--- branches/vorbis-aotuv/lib/block.c	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/lib/block.c	2006-11-05 15:20:01 UTC (rev 12030)
@@ -290,6 +290,7 @@
   /* added by aoyumi */
   b->nblock = _ogg_calloc((128*vi->channels), sizeof(*b->nblock));
   b->tblock = _ogg_calloc((128*vi->channels), sizeof(*b->tblock));
+  b->lownoise_compand_level = _ogg_calloc(vi->channels, sizeof(*b->lownoise_compand_level));
   
   /* Initialize the envelope state storage */
   b->ve=_ogg_calloc(1,sizeof(*b->ve));
@@ -356,6 +357,7 @@
       /* added by aoyumi */
       if(b->nblock) _ogg_free(b->nblock);
       if(b->tblock) _ogg_free(b->tblock);
+      if(b->lownoise_compand_level) _ogg_free(b->lownoise_compand_level);
 
     }
     

Modified: branches/vorbis-aotuv/lib/codec_internal.h
===================================================================
--- branches/vorbis-aotuv/lib/codec_internal.h	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/lib/codec_internal.h	2006-11-05 15:20:01 UTC (rev 12030)
@@ -85,6 +85,7 @@
 
   /* encode only
     added by aoyumi */
+  float *lownoise_compand_level;
   float *nblock; /* lW logmdct buffer */  
   float *tblock; /* temporal masking buffer (impulse block) */
   int lW_blocktype; /* last window block type */

Modified: branches/vorbis-aotuv/lib/info.c
===================================================================
--- branches/vorbis-aotuv/lib/info.c	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/lib/info.c	2006-11-05 15:20:01 UTC (rev 12030)
@@ -416,7 +416,7 @@
 }
 
 static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
-  char temp[]="AO; aoTuV b4 [20050617] (based on Xiph.Org's libVorbis)";
+  char temp[]="AO; aoTuV b5 [20061024] (based on Xiph.Org's libVorbis)";
   int bytes = strlen(temp);
 
   /* preamble */  

Modified: branches/vorbis-aotuv/lib/mapping0.c
===================================================================
--- branches/vorbis-aotuv/lib/mapping0.c	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/lib/mapping0.c	2006-11-05 15:20:01 UTC (rev 12030)
@@ -246,6 +246,7 @@
   codec_setup_info      *ci=vi->codec_setup;
   private_state         *b=vb->vd->backend_state;
   vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
+  vorbis_info_floor1    *vif=ci->floor_param[vb->W];
   int                    n=vb->pcmend;
   int i,j,k;
 
@@ -388,6 +389,8 @@
       
       float *lastmdct = b->nblock+i*128;
       float *tempmdct = b->tblock+i*128;
+      
+      float *lowcomp = b->lownoise_compand_level+i;
 
       vb->mode=modenumber;
 
@@ -427,7 +430,15 @@
          us a tonality estimate (the larger the value in the
          'noise_depth' vector, the more tonal that area is) */
 
+      *lowcomp=
+      	lb_loudnoise_fix(psy_look,
+      			*lowcomp,
+      			logmdct,
+      			b->lW_modenumber,
+      			blocktype, modenumber);
+      
       _vp_noisemask(psy_look,
+      		*lowcomp,
 		    logmdct,
 		    noise); /* noise does not have by-frequency offset
                                bias applied yet */
@@ -477,6 +488,8 @@
 			   mdct,
 			   logmdct,
 			   lastmdct, tempmdct,
+			   *lowcomp,
+			   vif->n,
 			   blocktype, modenumber,
 			   vb->nW,
 			   b->lW_blocktype, b->lW_modenumber, b->lW_no);
@@ -524,6 +537,8 @@
 			   mdct,
 			   logmdct,
 			   lastmdct, tempmdct,
+			   *lowcomp,
+			   vif->n,
 			   blocktype, modenumber,
 			   vb->nW,
 			   b->lW_blocktype, b->lW_modenumber, b->lW_no);
@@ -551,6 +566,8 @@
 			   mdct,
 			   logmdct,
 			   lastmdct, tempmdct,
+			   *lowcomp,
+			   vif->n,
 			   blocktype, modenumber,
 			   vb->nW,
 			   b->lW_blocktype, b->lW_modenumber, b->lW_no);
@@ -717,8 +734,6 @@
 		   ilogmaskch,
 		   nonzero,
 		   ci->psy_g_param.sliding_lowpass[vb->W][k],
-		   blocktype, modenumber,
-		   b->lW_blocktype, b->lW_modenumber,
 		   gmdct, res_org);
       }
       

Modified: branches/vorbis-aotuv/lib/modes/psych_11.h
===================================================================
--- branches/vorbis-aotuv/lib/modes/psych_11.h	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/lib/modes/psych_11.h	2006-11-05 15:20:01 UTC (rev 12030)
@@ -27,10 +27,10 @@
 static vp_adjblock _vp_tonemask_adj_11[4]={
   /* adjust for mode zero */
   /* 63     125     250     500     1     2     4     8    16 */
-  {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 5, 5,99,99,99}}, /* -2 */
-  {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* -1 */
-  {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /*  0 */
-  {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 10 */
+  {{-16,-16,-16,-16,-16,-16,-10,-8,-4, 0, 0, 0, 5, 5,99,99,99}}, /* -2 */
+  {{-16,-16,-16,-16,-16,-16,-10,-8,-4, 0, 0, 0, 0, 0,99,99,99}}, /* -1 */
+  {{-20,-20,-20,-20,-20,-16,-10,-8,-4,-2, 0, 0, 0, 0,99,99,99}}, /*  0 */
+  {{-20,-20,-20,-20,-20,-16,-10,-8,-4,-2, 0, 0, 0, 0,99,99,99}}, /* 10 */
 };
 
 

Modified: branches/vorbis-aotuv/lib/modes/psych_44.h
===================================================================
--- branches/vorbis-aotuv/lib/modes/psych_44.h	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/lib/modes/psych_44.h	2006-11-05 15:20:01 UTC (rev 12030)
@@ -81,8 +81,8 @@
      0, 1, 2, 3, 4, 5, 6,  6,     /* 7dB */
      6, 6, 7, 7, 7, 7, 8,  8,     /* 15dB */
      9,10,11,12,13,14,15, 16,     /* 23dB */
-    17,18,19,20,21,22,23, 24,     /* 31dB */
-    25,26,27,28,29,30,31, 32,     /* 39dB */
+    17,17,18,19,20,21,22, 23,     /* 31dB */
+    23,24,25,26,27,28,29, 30,     /* 39dB */
   }},
   /* mode_Z nominal short */
   {{
@@ -119,9 +119,9 @@
 //    32,33,34,35,36,37,38, 39,     /* 39dB */
      0, 1, 2, 3, 4, 5, 6,  7,     /* 7dB */
      8, 9,10,11,12,12,13, 13,     /* 15dB */
-    13,14,14,15,15,16,16, 17,     /* 23dB */
-    17,18,19,20,21,22,23, 24,     /* 31dB */
-    25,26,27,28,29,30,31, 32,     /* 39dB */
+    13,14,14,15,15,16,16, 16,     /* 23dB */
+    17,17,18,19,20,21,22, 23,     /* 31dB */
+    23,24,25,26,27,28,29, 30,     /* 39dB */
   }},
   /* mode_Z nominal long */
   {{
@@ -152,19 +152,19 @@
    /* 63     125     250     500       1       2       4       8      16 */
 
 // {{ -3, -9,-12,-12,-10,-10,-10,-10,-10,-10,-10, -1,  0,  0,  1,  1,  1}}, /* -2(addition) */
-   {{-13,-13,-13,-13,-13,-13,-13,-13,-13,-13,-13,-12, -6, -1,  1,  0,  1}},
+   {{-14,-14,-14,-14,-14,-14,-14,-14,-13,-11,-11,-11,-10, -4, -2, -2,  1}},
 
 // {{ -3, -9,-12,-12,-11,-11,-11,-11,-11,-11,-10, -1, -1,  0,  0,  0,  0}}, /* -1 */
-   {{-15,-15,-15,-15,-15,-15,-15,-14,-13,-13,-13,-13, -8, -2,  0, -1,  0}},
+   {{-15,-15,-15,-15,-15,-15,-15,-15,-14,-13,-13,-13,-13, -6, -4, -5,  0}}, 
    
 /* {{-15,-15,-15,-15,-10, -8, -4, -2,  0,  0,  0, 10,  0,  0,  0,  0,  0}},    0 */
-   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -6, -4, -5,  0}}, /* 0 */
+   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -7, -5, -6,  0}}, /* 0 */
 
 /* {{-15,-15,-15,-15,-15,-12,-10, -8,  0,  0,  0,  5,  0,  0,  0,  0,  0}},    1 */
-   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -6, -4, -5,  0}}, /* 1 */
+   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -7, -5, -6,  0}}, /* 1 */
 
 /* {{-15,-15,-15,-15,-15,-12,-10, -8,  0,  0,  0,  0,  0,  0,  0,  0,  0}},    2 */
-   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -6, -4, -5,  0}}, /* 2 */
+   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -7, -5, -6,  0}}, /* 2 */
    
 /* {{-15,-15,-15,-15,-15,-12,-10, -8,  0,  0,  0,  0,  0,  0,  0,  0,  0}},    3 */
    {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -7, -5, -6,  0}}, /* 3 */
@@ -194,19 +194,19 @@
    /* 63     125     250     500       1       2       4       8      16 */
 
 // {{ -3, -9,-12,-12,-10,-10,-10,-10,-10,-10,-10, -1,  0,  0,  1,  1,  1}}, /* -2(addition) */
-   {{-13,-13,-13,-13,-13,-13,-13,-13,-13,-13,-13,-12, -6, -1,  1,  0,  1}},
+   {{-14,-14,-14,-14,-14,-14,-14,-14,-13,-11,-11,-11, -7, -3, -2, -2,  1}},
 
 // {{ -3, -9,-12,-12,-11,-11,-11,-11,-11,-11,-10, -1, -1,  0,  0,  0,  0}}, /* -1 */
-   {{-15,-15,-15,-15,-15,-15,-15,-14,-13,-13,-13,-13, -8, -2,  0, -1,  0}},
+   {{-15,-15,-15,-15,-15,-15,-15,-15,-14,-13,-13,-13,-12, -5, -3, -4,  0}},
    
 /* {{-20,-20,-20,-20,-14,-12,-10, -8, -4,  0,  0, 10,  0,  0,  0,  0,  0}},    0 */
-   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -6, -4, -5,  0}}, /* 0 */
+   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -7, -5, -6,  0}}, /* 0 */
 
 /* {{-20,-20,-20,-20,-20,-18,-16,-14,-10,  0,  0,  5,  0,  0,  0,  0,  0}},    1 */
-   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -6, -4, -5,  0}}, /* 1 */
+   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -7, -5, -6,  0}}, /* 1 */
 
 /* {{-20,-20,-20,-20,-20,-18,-16,-14,-10,  0,  0,  0,  0,  0,  0,  0,  0}},    2 */
-   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -6, -4, -5,  0}}, /* 2 */
+   {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -7, -5, -6,  0}}, /* 2 */
 
 /* {{-20,-20,-20,-20,-20,-18,-16,-14,-10,  0,  0,  0,  0,  0,  0,  0,  0}},    3 */
    {{-16,-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-14, -7, -5, -6,  0}}, /* 3 */
@@ -238,14 +238,14 @@
   /*  63     125     250     500      1k       2k      4k      8k     16k*/
   /* -2(addition mode) */
   {{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 10, 12, 14, 20},
-    {-26,-26,-26,-26,-22,-16,-12, -6, -2,  1,  1,  1,  5,  7,  8,  8, 15},
+    {-26,-26,-26,-24,-22,-16,-12, -6, -2,  2,  2,  2,  6,  7,  8,  8, 13},
     {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
   /* -1 */
 /*{{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 10, 12, 14, 20},
     {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2,  2,  2,  3,  6,  6, 15},
     {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},*/
   {{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 10, 12, 14, 20},
-    {-30,-30,-30,-30,-26,-22,-18,-10, -4,  0,  0,  0,  2,  3,  5,  5, 13},
+    {-30,-30,-30,-30,-26,-22,-18,-10, -4,  0,  0,  0,  1,  2,  5,  5, 13},
     {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
   /* 0 */
 /*{{{-15,-15,-15,-15,-15,-12,-10, -8,  0,  2,  4,  4,  5,  5,  5,  8,  10},
@@ -266,7 +266,7 @@
     {-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,-10,-10,-10,-10, -8, -8, -8, -4}}}, */
   {{{-15,-15,-15,-15,-15,-12,-10, -8,  0,  2,  2,  2,  4,  4,  5,  6, 10},
-    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -2, -2, -1,  1,  3},
+    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -1,  1,  3},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
   /* 3 */
 /*{{{-15,-15,-15,-15,-15,-12,-10, -8,  0,  2,  2,  2,  4,  4,  4,  5,  8},
@@ -328,14 +328,14 @@
   /*  63     125     250     500      1k       2k      4k      8k     16k*/
   /* -2(addition mode) */
   {{{-10,-10,-10,-10,-10, -4,  0,  0,  2,  6,  6,  6,  6, 10, 10, 12, 20},
-    {-20,-20,-20,-20,-20,-20,-10, -2,  2,  2,  2,  2,  5,  6,  7,  7, 14},
+    {-20,-20,-20,-20,-20,-20,-10, -2,  2,  2,  2,  2,  3,  5,  8,  8, 13},
     {-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, 12, 20},
     {-20,-20,-20,-20,-20,-20,-10, -2,  0,  0,  0,  0,  0,  2,  4,  6, 15},
     {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},*/
   {{{-10,-10,-10,-10,-10, -4,  0,  0,  0,  6,  6,  6,  6, 10, 10, 12, 20},
-    {-20,-20,-20,-20,-20,-20,-11, -3,  0,  0,  0,  0,  0,  1,  3,  5, 13},
+    {-20,-20,-20,-20,-20,-20,-12, -4,  0,  0,  0,  0,  0,  1,  4,  4, 13},
     {-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,  2,  2,  2,  4,  4,  5,  5,  5,  8,  10},
@@ -356,7 +356,7 @@
     {-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,-10,-10,-10,-10, -8, -8, -8, -4}}},*/
   {{{-10,-10,-10,-10,-10,-10,-10, -8,  0,  2,  2,  2,  4,  4,  5,  6, 10},
-    {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -2, -2, -1,  1,  3},
+    {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -1,  1,  3},
     {-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},
@@ -409,14 +409,14 @@
   /*  63     125     250     500      1k      2k      4k      8k     16k*/
   /* -2(addition mode) */
   {{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 10, 12, 14, 20},
-    {-26,-26,-26,-26,-22,-16,-12, -6, -2,  1,  1,  1,  6,  7,  8,  8, 15},
+    {-26,-26,-26,-24,-22,-16,-12, -6, -2,  2,  2,  2,  6,  7,  8,  8, 13},
     {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
   /* -1 */
 /*{{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 10, 12, 14, 20},
     {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2,  2,  2,  3,  6,  6, 15},
     {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},*/
   {{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 10, 12, 14, 20},
-    {-30,-30,-30,-30,-26,-22,-18,-10, -4,  0,  0,  0,  2,  3,  5,  5, 13},
+    {-30,-30,-30,-30,-26,-22,-18,-10, -4,  0,  0,  0,  1,  2,  5,  5, 13},
     {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
   /* 0 */
 /*{{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  4,  8,  8,  8, 10, 12, 14, 20},
@@ -430,7 +430,7 @@
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2,  2},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},*/
   {{{-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, -4, -2, -2, -2,  0,  2},
+    {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, -2,  0,  2},
     {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
   /* 2 */
   {{{-14,-14,-14,-14,-14,-10, -8, -6, -2,  2,  2,  2,  2,  8, 10, 10, 16},
@@ -484,14 +484,14 @@
   /*  63     125     250     500      1k       2k      4k      8k     16k*/
   /* -2(addition mode) */
   {{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 10, 12, 14, 20},
-    {-26,-26,-26,-26,-22,-16,-12, -4, -2,  1,  1,  2,  7,  8,  8,  8, 15},
+    {-26,-26,-26,-24,-22,-16,-12, -6, -2,  2,  2,  2,  6,  7,  8,  8, 15},
     {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
   /* -1 */
 /*{{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 10, 12, 14, 20},
     {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2,  2,  2,  3,  6,  6, 15},
     {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},*/
   {{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 10, 12, 14, 20},
-    {-30,-30,-30,-30,-26,-20,-16, -8, -4,  0,  0,  1,  3,  6,  6,  8, 15},
+    {-30,-30,-30,-30,-26,-22,-18,-10, -4,  0,  0,  1,  2,  3,  6,  6, 15},
     {-30,-30,-30,-30,-30,-24,-20,-14,-10, -4, -4, -4, -4, -4, -2,  0,  2}}},
   /* 0 */
 /*{{{-10,-10,-10,-10,-10, -4,  0,  0,  4,  8,  8,  8,  8, 10, 12, 14, 20},
@@ -559,7 +559,7 @@
 };
 static int _psy_tone_0dB[13]={
 /*  90,90,95,95,95,95,105,105,105,105,105,105, */
-   90,90,90,95,95,95,95,105,105,105,105,105,105,
+   90,90,90,94,95,95,95,105,105,105,105,105,105,
 };
 static int _psy_noise_suppress[13]={
 /*  -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45, */
@@ -704,11 +704,13 @@
 
 /* tone master attenuation by base quality mode and bitrate tweak */
 static att3 _psy_tone_masteratt_44[13]={
-  {{ 37,  23,  11},  0,    0}, /* -2 */
-  {{ 35,  21,   9},  0,    0}, /* -1 */
+  {{ 38,  24,  12},  0,    0}, /* -2 */
+//  {{ 35,  21,   9},  0,    0}, /* -1 */
+  {{ 36,  22,  10},  0,    0}, /* -1 */
 //  {{ 30,  20,   8}, -2, 1.25}, /* 0 */
-  {{ 30,  20,   8},  0,    0}, /* 0 */
-  {{ 25,  14,   4},  0,    0}, /* 1 */
+  {{ 30,  21,   8},  0,    0}, /* 0 */
+//  {{ 25,  14,   4},  0,    0}, /* 1 */
+  {{ 25,  15,   4},  0,    0}, /* 1 */
   {{ 20,  10,  -2},  0,    0}, /* 2 */
 //  {{ 20,   9,  -4},  0,    0}, /* 3 */
   {{ 21,  10,  -3},  0,    0}, /* 3 */
@@ -733,12 +735,12 @@
 static int _noise_start_short_44[12]={
   /*  16,16,16,16,32,32,9999,9999,9999,9999 */
 //  32,16,16,16,32,9999,9999,9999,9999,9999,9999
-  32,32,16,16,32,64,9999,9999,9999,9999,9999,9999
+  16,32,16,16,32,64,9999,9999,9999,9999,9999,9999
 };
 static int _noise_start_long_44[12]={
   /*  128,128,128,256,512,512,9999,9999,9999,9999 */
 //  256,128,128,256,512,9999,9999,9999,9999,9999,9999
-  256,256,128,128,256,512,9999,9999,9999,9999,9999,9999
+  128,256,128,128,256,512,9999,9999,9999,9999,9999,9999
 };
 
 static int _noise_part_short_44[12]={
@@ -753,7 +755,7 @@
 static double _noise_thresh_44[12]={
   /*  .2,.2,.3,.4,.5,.5,9999.,9999.,9999.,9999., */
 //   .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
-   .2,.2,.2,.2,.4,.8,9999.,9999.,9999.,9999.,9999.,9999.,
+   .1462,.1886,.1887,.1975,.355,.8,9999.,9999.,9999.,9999.,9999.,9999.,
 };
 
 static double _noise_thresh_5only[2]={
@@ -762,8 +764,10 @@
 
 /* 32kHz only */
 static int _noise_start_short_32[12]={
-  40,40,20,20,40,80,9999,9999,9999,9999,9999,9999
+//  40,40,20,20,40,80,9999,9999,9999,9999,9999,9999
+  24,48,24,24,40,80,9999,9999,9999,9999,9999,9999
 };
 static int _noise_start_long_32[12]={
-  320,320,160,160,320,640,9999,9999,9999,9999,9999,9999
+//  320,320,160,160,320,640,9999,9999,9999,9999,9999,9999
+  160,320,160,160,320,640,9999,9999,9999,9999,9999,9999
 };

Modified: branches/vorbis-aotuv/lib/modes/setup_32.h
===================================================================
--- branches/vorbis-aotuv/lib/modes/setup_32.h	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/lib/modes/setup_32.h	2006-11-05 15:20:01 UTC (rev 12030)
@@ -17,7 +17,7 @@
 
 static double rate_mapping_32[13]={
 //  18000.,28000.,35000.,45000.,56000.,60000.,
-  14000.,20000.,28000.,35000.,45000.,56000.,60000.,
+  14000.,21000.,28000.,35000.,45000.,56000.,60000.,
   75000.,90000.,100000.,115000.,150000.,190000.,
 };
 
@@ -29,7 +29,7 @@
 
 static double _psy_lowpass_32[13]={
 //  12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
-  11.9,12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
+  12.,12.6,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
 };
 
 ve_setup_data_template ve_setup_32_stereo={

Modified: branches/vorbis-aotuv/lib/psy.c
===================================================================
--- branches/vorbis-aotuv/lib/psy.c	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/lib/psy.c	2006-11-05 15:20:01 UTC (rev 12030)
@@ -33,12 +33,14 @@
 
 /*
   rephase   = reverse phase limit (postpoint)
-  lowlong   = low quality long-block limit (postpoint)
                                                 0    1    2    3    4    5    6    7    8  */
 static double stereo_threshholds[]=           {0.0, 0.5, 1.0, 1.5, 2.5, 4.5, 8.5,16.5, 9e10};
-static double stereo_threshholds_rephase[]=   {0.0, 0.5, 0.5, 1.0, 1.5, 1.5, 1.5, 2.5, 9e10};
-static double stereo_threshholds_lowlong[]=   {0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 6.5,10.5, 9e10};
+static double stereo_threshholds_rephase[]=   {0.0, 0.5, 0.5, 1.0, 1.5, 1.5, 2.5, 2.5, 9e10};
 
+static double stereo_threshholds_low[]=       {0.0, 0.5, 0.5, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0};
+static double stereo_threshholds_high[]=      {0.0, 0.5, 0.5, 0.5, 1.0, 3.0, 5.5, 8.5, 0.0};
+
+
 static int m3n32[] = {21,13,10,4};
 static int m3n44[] = {15,9,7,3};
 static int m3n48[] = {14,8,6,3};
@@ -54,7 +56,9 @@
 15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
 };
 
+static float nnmid_th=0.2;
 
+
 vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
   codec_setup_info *ci=vi->codec_setup;
   vorbis_info_psy_global *gi=&ci->psy_g_param;
@@ -307,16 +311,53 @@
   p->rate=rate;
 
   /* AoTuV HF weighting etc. */
-  if(rate < 26000) p->m_val = 0;
-  else if(rate < 38000){   /* 32kHz */
-  	p->m_val = .94;
+  p->n25p=n/4;
+  p->n33p=n/3;
+  p->n75p=n*3/4;
+  if(rate < 26000){
+  	/* below 26kHz */
+  	p->m_val = 0;
+  	for(i=0; i<4; i++) p->m3n[i] = 0;
+  	p->tonecomp_endp=0; // dummy
+  	p->tonecomp_thres=.25;
+  	p->st_freqlimit=n;
+  	p->min_nn_lp=0;
+  }else if(rate < 38000){
+  	/* 32kHz */
+  	p->m_val = .93;
   	for(i=0; i<4; i++) p->m3n[i] = m3n32[i];
-  }else if(rate > 46000){  /* 48kHz */
+  	if(n==128)      { p->tonecomp_endp= 124; p->tonecomp_thres=.5;
+  	                 p->st_freqlimit=n; p->min_nn_lp=   0;}
+  	else if(n==256) { p->tonecomp_endp= 248; p->tonecomp_thres=.7;
+  	                 p->st_freqlimit=n; p->min_nn_lp=   0;}
+  	else if(n==1024){ p->tonecomp_endp= 992; p->tonecomp_thres=.5;
+  	                 p->st_freqlimit=n; p->min_nn_lp= 832;}
+  	else if(n==2048){ p->tonecomp_endp=1984; p->tonecomp_thres=.7;
+  	                 p->st_freqlimit=n; p->min_nn_lp=1664;}
+  }else if(rate > 46000){
+  	/* 48kHz */
   	p->m_val = 1.205;
   	for(i=0; i<4; i++) p->m3n[i] = m3n48[i];
-  }else{                   /* 44.1kHz */
+  	if(n==128)      { p->tonecomp_endp=  83; p->tonecomp_thres=.5;
+  	                 p->st_freqlimit=  89; p->min_nn_lp=   0;}
+  	else if(n==256) { p->tonecomp_endp= 166; p->tonecomp_thres=.7;
+  	                 p->st_freqlimit= 178; p->min_nn_lp=   0;}
+  	else if(n==1024){ p->tonecomp_endp= 664; p->tonecomp_thres=.5;
+  	                 p->st_freqlimit= 712; p->min_nn_lp= 576;}
+  	else if(n==2048){ p->tonecomp_endp=1328; p->tonecomp_thres=.7;
+  	                 p->st_freqlimit=1424; p->min_nn_lp=1152;}
+  }else{
+  	/* 44.1kHz */
   	p->m_val = 1.;
   	for(i=0; i<4; i++) p->m3n[i] = m3n44[i];
+  	if(n==128)      { p->tonecomp_endp=  90; p->tonecomp_thres=.5;
+  	                 p->st_freqlimit=  96; p->min_nn_lp=   0;}
+  	else if(n==256) { p->tonecomp_endp= 180; p->tonecomp_thres=.7;
+  	                 p->st_freqlimit= 192; p->min_nn_lp=   0;}
+  	else if(n==1024){ p->tonecomp_endp= 720; p->tonecomp_thres=.5;
+  	                 p->st_freqlimit= 768; p->min_nn_lp= 608;}
+  	else if(n==2048){ p->tonecomp_endp=1440; p->tonecomp_thres=.7;
+  	                 p->st_freqlimit=1536; p->min_nn_lp=1216;}
   }
 
   /* set up the lookups for a given blocksize and sample rate */
@@ -805,6 +846,7 @@
 }
 
 void _vp_noisemask(vorbis_look_psy *p,
+		   float noise_compand_level,
 		   float *logmdct, 
 		   float *logmask){
 
@@ -843,7 +885,19 @@
   }
 #endif
 
-  for(i=0;i<n;i++){
+  /* aoTuV M5 extension */
+  i=0;
+  if((p->vi->noisecompand_high[NOISE_COMPAND_LEVELS-1] > 1) && (noise_compand_level > 0)){
+  	int thter = p->n33p;
+  	for(;i<thter;i++){
+    	int dB=logmask[i]+.5;
+    	if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
+    	if(dB<0)dB=0;
+    	logmask[i]= work[i]+p->vi->noisecompand[dB]-
+    	  ((p->vi->noisecompand[dB]-p->vi->noisecompand_high[dB])*noise_compand_level);
+  	}
+  }
+  for(;i<n;i++){
     int dB=logmask[i]+.5;
     if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
     if(dB<0)dB=0;
@@ -885,33 +939,57 @@
 			float *mdct,
 			float *logmdct,
 			float *lastmdct, float *tempmdct,
+			float low_compand,
+			int end_block,
 			int blocktype, int modenumber,
 			int nW_modenumber,
 			int lW_blocktype, int lW_modenumber, int lW_no){
 
   int i,j,n=p->n;
-  int it_sw, *m3n, m3_count, nquarter=n/4; /* aoTuV for M3&M4 */
-  double ace=0; /* aoTuV for M4 */
+  int m2_sw=0,  padth; /* aoTuV for M2 */
+  int it_sw, *m3n, m3_count; /* aoTuV for M3 */
+  int m4_end, lp_pos, m4_start; /* aoTuV for M4 */
   float de, coeffi, cx; /* aoTuV for M1 */
+  float toneth; /* aoTuV for M2 */
   float noise_rate, noise_rate_low, noise_center, rate_mod; /* aoTuV for M3 */
+  float m4_thres; /* aoTuV for M4 */
   float toneatt=p->vi->tone_masteratt[offset_select];
 
   cx = p->m_val;
   m3n = p->m3n;
+  m4_start=p->vi->normal_start;
+  m4_end = p->tonecomp_endp;
+  m4_thres = p->tonecomp_thres;
+  lp_pos=9999;
   
+  end_block+=p->vi->normal_partition;
+  if(end_block>n)end_block=n;
+  
+  /* Collapse of low(mid) frequency is prevented. (for 32/44/48kHz q-2) */
+  if(low_compand<0 || toneatt<25.)low_compand=0;
+  else low_compand*=(toneatt-25.);
+  
+  /** @ M2 PRE **/
+  if(p->vi->normal_thresh<.48){
+  	if((cx > 0.5) && !modenumber && blocktype && (n==128)){
+    	if(p->vi->normal_thresh>.35) padth = 10+(int)(p->vi->flacint*100);
+    	else padth = 10;
+    	m2_sw=1;
+    }
+  }
+
+  /** @ M3 PRE **/
   m3_count = 3;
   if(toneatt < 3) m3_count = 2; // q6~
-  
-  /** @ M3 PRE **/
   if((n == 128) && !modenumber && !blocktype){
   	if(!lW_blocktype && !lW_modenumber){ /* last window "short" - type "impulse" */
   		if(lW_no < 8){
   			/* impulse - @impulse case1 */
-  			noise_rate = 0.8-(float)(lW_no-1)/17;
+  			noise_rate = 0.7-(float)(lW_no-1)/17;
   			noise_center = (float)(lW_no*m3_count);
   		}else{
   			/* impulse - @impulse case2 */
-  			noise_rate = 0.4;
+  			noise_rate = 0.3;
   			noise_center = 25;
   			if((lW_no*m3_count) < 24) noise_center = lW_no*m3_count;
   		}
@@ -919,13 +997,13 @@
   			for(i=0; i<128; i++) tempmdct[i] -= 5;
   		}
   	}else{ /* non_impulse - @Short(impulse) case */
-  		noise_rate = 0.9;
+  		noise_rate = 0.7;
   		noise_center = 0;
   		if(offset_select == 1){
   			for(i=0; i<128; i++) tempmdct[i] = lastmdct[i] - 5;
   		}
   	}
-  	noise_rate_low = noise_rate*0.6;
+  	noise_rate_low = 0;
   	it_sw = 1;
   }else{
   	it_sw = 0;
@@ -933,57 +1011,39 @@
   
   /** @ M3&M4 PRE **/
   if(cx < 0.5){
-  	it_sw = 0;     /* for M3 */
-  	nquarter = 0;  /* for M4 */
+  	it_sw = 0; /* for M3 */
+  	m4_end=end_block; /* for M4 */
+  }else if(p->vi->normal_thresh>1.){
+  	m4_start = 9999;
   }else{
-    /*  calculation of the correction value of noise masking (longblock).
-        the magic number should change with psych_44.h's "_psy_compand_44" values
-        and setup_44.h's "_psy_compand_long_mapping" value.     for M4  */
-  	if(modenumber && (p->vi->noisecompand[12] > 9.)){
-  		for(i=nquarter; i<n; i++) ace += logmdct[i];
-  		ace = (float)(n/ace*1000+13);
-  		if(ace < 0) ace = 0;
-  		else ace *= ace*((p->vi->noisecompand[12]-9.)/3.); /* range of q-1~q2.6... */
-  		if(ace > 6.) ace = 6;
-  	}else nquarter = 0;
+  	if(m4_end>end_block)lp_pos=m4_end;
+  	else lp_pos=end_block;
   }
-  
+
   for(i=0;i<n;i++){
     float val= noise[i]+p->noiseoffset[offset_select][i];
     float tval= tone[i]+toneatt;
-    float toneth;  /* aoTuV for M2 */
+    if(i<=m4_start)tval-=low_compand;
     if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
     
     /* AoTuV */
-    /** @ M4 MAIN **
-    When the energy of a high frequency is small, the noise level of a low frequency is lowered. 
-    This is the measure against complaints of a solo musical instrument. 
-    by Aoyumi @ 2004/09/18
-    */
-    if(i < nquarter){
-		if(logmdct[i] > -120) val -= (float)ace;
-	}
-    
-
     /** @ M2 MAIN **
-    floor is pulled below suitably. (long block only)
-    by Aoyumi @ 2005/06/14
+    floor is pulled below suitably. (padding block only) (#2)
+    by Aoyumi @ 2006/06/14
     */
-    if(modenumber && (p->vi->normal_thresh<.45)){
-    	toneth=toneatt-20; // q0=0, q1=-6, q2/q3=-10 (48/44.1/32kHz quality mode)
-    	if(toneth>0.5) toneth=0;
-    	if(val>(tval+toneth) && ((val-tval+toneth)>20) && val>-80){
-    		if((val-tval+toneth) > 30) val -= ((val-tval+toneth-30)/10+10);
-    		else val -= ((val-tval+toneth)-20);
+    if(m2_sw){
+    	// the conspicuous low level pre-echo of the padding block origin is reduced. 
+    	if((logmdct[i]-lastmdct[i]) > 20){
+    		if(i > m3n[3]) val -= (logmdct[i]-lastmdct[i]-20)/padth;
+    		else val -= (logmdct[i]-lastmdct[i]-20)/(padth+padth);
     	}
     }
     
-    
     /* AoTuV */
     /** @ M3 MAIN **
-    Dynamic impulse block noise control. (#3)
+    Dynamic impulse block noise control. (#4)
     48/44.1/32kHz only.
-    by Aoyumi @ 2004/08/30
+    by Aoyumi @ 2006/02/02
     */
     if(it_sw){
     	for(j=1; j<=temp_bfn[i]; j++){
@@ -991,31 +1051,58 @@
 			if( (tempmdct[i+j] < tempbuf) && (tempmdct[i+j] < (logmdct[i+j]-5)) )
 			 tempmdct[i+j] = logmdct[i+j] - 5;
 		}
-		
     	if(val > tval){
-    		if( logmdct[i] > (tempmdct[i]+noise_center) ){
+    		if( (val>lastmdct[i]) && (logmdct[i]>(tempmdct[i]+noise_center)) ){
+    			float valmask=0;
     			tempmdct[i] = logmdct[i];
-    			if(logmdct[i] < lastmdct[i]) rate_mod = noise_rate;
-    			else rate_mod = noise_rate_low;
-				
+    			
+    			if(logmdct[i]>lastmdct[i]){
+    				rate_mod = noise_rate;
+    			}else{
+    				rate_mod = noise_rate_low;
+				}
 				if(i > m3n[1]){
-						if((val-tval) > 30) val = val - ((val-tval-30)/10+30)*rate_mod;
-						else val = val - (val-tval)*rate_mod;
+						if((val-tval)>30) valmask=((val-tval-30)/10+30)*rate_mod;
+						else valmask=(val-tval)*rate_mod;
 				}else if(i > m3n[2]){
-						if((val-tval) > 20) val = val - ((val-tval-20)/10+20)*rate_mod;
-						else val = val - (val-tval)*rate_mod;
+						if((val-tval)>20) valmask=((val-tval-20)/10+20)*rate_mod;
+						else valmask=(val-tval)*rate_mod;
 				}else if(i > m3n[3]){
-						if((val-tval) > 10) val = val - ((val-tval-10)/10+10)*rate_mod*0.5;
-						else val = val - (val-tval)*rate_mod*0.5;
+						if((val-tval)>10) valmask=((val-tval-10)/10+10)*rate_mod*0.5;
+						else valmask=(val-tval)*rate_mod*0.5;
 				}else{
-					if((val-tval) > 10) val = val - ((val-tval-10)/10+10)*rate_mod*0.3;
-					else val = val - (val-tval)*rate_mod*0.3;
+					if((val-tval)>10) valmask=((val-tval-10)/10+10)*rate_mod*0.3;
+					else valmask=(val-tval)*rate_mod*0.3;
 				}
+				if((val-valmask)>lastmdct[i])val-=valmask;
+				else val=lastmdct[i];
 			}
    		}
    	}
    	
-    logmask[i]=max(val,tval);
+   	/* This affects calculation of a floor curve. */
+   	if(i>=lp_pos)logmdct[i]=-160;
+   	
+     /* AoTuV */
+	/** @ M4 MAIN **
+	The purpose of this portion is working Noise Normalization more correctly. 
+	(There is this in order to prevent extreme boost of floor)
+	  m4_start = start point
+	  m4_end   = end point
+	  m4_thres = threshold
+	by Aoyumi @ 2006/03/20
+	*/
+    //logmask[i]=max(val,tval);
+    if(val>tval){
+		logmask[i]=val;
+	}else if((i>m4_start) && (i<m4_end) && (logmdct[i]>-140)){
+		if(logmdct[i]>val){
+			if(logmdct[i]<tval)tval-=(tval-val)*m4_thres;
+		}else{
+			if(val<tval)tval-=(tval-val)*m4_thres;
+		}
+		logmask[i]=tval;
+	}else logmask[i]=tval;
 
     /* AoTuV */
     /** @ M1 **
@@ -1393,7 +1480,7 @@
 
 void _vp_noise_normalize(vorbis_look_psy *p,
 			 float *in,float *out,int *sortedindex){
-  int flag=0,i,j=0,n=p->n;
+  int i,j=0,n=p->n,min_energy;
   vorbis_info_psy *vi=p->vi;
   int partition=vi->normal_partition;
   int start=vi->normal_start;
@@ -1407,27 +1494,64 @@
     for(;j+partition<=n;j+=partition){
       float acc=0.;
       int k;
+      int energy_loss=0;
+      int nn_num=0;
+      int freqband_mid=j+16;
+      int freqband_flag=0;
       
-      for(i=j;i<j+partition;i++)
-	acc+=in[i]*in[i]*0.9;
+      for(i=j;i<j+partition;i++){
+        if(rint(in[i])==0.f){
+        	acc+=in[i]*in[i];
+        	energy_loss++;
+        }
+      }
+      /* When an energy loss is large, NN processing is carried out in the middle of partition. */
+      /*if(energy_loss==32 && fabs(in[freqband_mid])>nnmid_th){
+      	if(in[freqband_mid]*in[freqband_mid]<.25f){
+      		i=0;
+      		if(acc>=vi->normal_thresh){
+      			out[freqband_mid]=unitnorm(in[freqband_mid]);
+      			acc-=1.;
+      			freqband_flag=1;
+      			nn_num++;
+      		}
+      	}
+      }*/
       
+      /* NN main */
       for(i=0;i<partition;i++){
-	k=sortedindex[i+j-start];
-	
-	if(in[k]*in[k]>=.25f){ // or rint(in[k])!=0.f
-	  out[k]=rint(in[k]);
-	  acc-=in[k]*in[k]*0.9;
-	  flag=1;
-	}else{
-	  if(acc<vi->normal_thresh)break;
-	  out[k]=unitnorm(in[k]);
-	  acc-=1.;
-	}
+      	k=sortedindex[i+j-start];
+      	if(in[k]*in[k]>=.25f){ // or rint(in[k])!=0.f
+      		out[k]=rint(in[k]);
+      		//acc-=in[k]*in[k];
+      	}else{
+      		if(acc<vi->normal_thresh)break;
+      		if(freqband_flag && freqband_mid==k)continue;
+      		out[k]=unitnorm(in[k]);
+      		acc-=1.;
+      		nn_num++;
+      	}
       }
       
+      /* The minimum energy complement */
+      /*min_energy=32-energy_loss+nn_num;
+      if(min_energy<2 || (j<=p->min_nn_lp && min_energy==2)){
+      	k=sortedindex[i+j-start];
+      	if(freqband_flag && freqband_mid==k){
+      		i++;
+      		k=sortedindex[i+j-start];
+	    }
+	    if(!(fabs(in[k])<0.3)){
+	    	out[k]=unitnorm(in[k]);
+	    	i++;
+	    }
+	  }*/
+	  
+	  // The last process
       for(;i<partition;i++){
-	k=sortedindex[i+j-start];
-	out[k]=0.;
+      	k=sortedindex[i+j-start];
+      	if(freqband_flag && freqband_mid==k)continue;
+      	else out[k]=0.;
       }
     }
   }
@@ -1447,8 +1571,6 @@
 		int   **ifloor,
 		int   *nonzero,
 		int  sliding_lowpass,
-		int blocktype, int modenumber,
-		int lW_blocktype, int lW_modenumber,
 		float **mdct, float **res_org){
 
   int i,j,k,n=p->n;
@@ -1483,25 +1605,60 @@
       int *floorA=ifloor[vi->coupling_ang[i]];
       float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
       float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
-      float postpoint_bu;
+      float sth_low=stereo_threshholds_low[g->coupling_prepointamp[blobno]];
+      float sth_high=stereo_threshholds_high[g->coupling_postpointamp[blobno]];
+      float postpoint_backup;
+      float st_thresh;
       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;
-
+      int freqlimit=p->st_freqlimit;
+      unsigned char Mc_treshp[2048];
+      unsigned char Ac_treshp[2048];
+      int lof_st;
+      int hif_st;
+      int hif_stcopy;
+      int old_lof_st=0;
+      int old_hif_st=0;
+      int Afreq_num=0;
+      int Mfreq_num=0;
+      int stcont_start=0; // M6 start point
+      
       nonzero[vi->coupling_mag[i]]=1; 
       nonzero[vi->coupling_ang[i]]=1; 
        
-       if(p->m_val > 0.5){
-       	/* The threshold of a stereo is changed in specific conditions. */
-       	if(modenumber){
-       		if(p->vi->normal_thresh < .5)
-       		  postpoint=stereo_threshholds_lowlong[g->coupling_postpointamp[blobno]];
-       	}
-       }
-      postpoint_bu=postpoint;
-
-      for(j=0;j<p->n;j+=partition){
+      postpoint_backup=postpoint;
+      
+      /** @ M6 PRE **/
+      // lossless only?
+      if(!stereo_threshholds[g->coupling_postpointamp[blobno]])stcont_start=n;
+      else{
+      	// exception handling
+      	if((postpoint-sth_high)<prepoint)sth_high=postpoint-prepoint;
+      	// start point setup
+      	for(j=0;j<n;j++){
+      		stcont_start=j;
+      		if(p->noiseoffset[1][j]>=-2)break;
+      	}
+      	// start point correction & threshold setup 
+      	st_thresh=.1;
+      	if(p->m_val<.5){
+      		// low frequency limit
+      		if(stcont_start<limit)stcont_start=limit;
+      	}else if(p->vi->normal_thresh>1.)st_thresh=.5;
+      	for(j=0;j<=freqlimit;j++){ // or j<n
+      		if(fabs(rM[j])<st_thresh)Mc_treshp[j]=1;
+      		else Mc_treshp[j]=0;
+      		if(fabs(rA[j])<st_thresh)Ac_treshp[j]=1;
+      		else Ac_treshp[j]=0;
+      	}
+      }
+      
+      for(j=0;j<n;j+=partition){
 	float acc=0.f;
+	float rpacc;
+	int energy_loss=0;
+	int nn_num=0;
 
 	for(k=0;k<partition;k++){
 	  int l=k+j;
@@ -1509,11 +1666,101 @@
 	  float b=mdctA[l];
 	  float dummypoint;
 	  float hypot_reserve;
+	  float slow=0.f;
+	  float shigh=0.f;
+	  float slowM=0.f;
+	  float slowA=0.f;
+	  float shighM=0.f;
+	  float shighA=0.f;
+	  float rMs=fabs(rMo[l]);
+      float rAs=fabs(rAo[l]);
 
-	  postpoint=postpoint_bu;
+	  postpoint=postpoint_backup;
+	  
+	  /* AoTuV */
+	  /** @ M6 MAIN **
+	    The threshold of a stereo is changed dynamically. 
+	    by Aoyumi @ 2006/06/04
+	  */
+	  if(l>=stcont_start){
+	  	int m;
+	  	int lof_num;
+	  	int hif_num;
+	  	
+	  	// (It may be better to calculate this in advance) 
+	  	lof_st=l-(l/2)*.167;
+	  	hif_st=l+l*.167;
+	  
+	  	hif_stcopy=hif_st;
+	  	
+	  	// limit setting
+	  	if(hif_st>freqlimit)hif_st=freqlimit;
+	  	
+	  	if(old_lof_st || old_hif_st){
+	  		if(hif_st>l){
+	  			// hif_st, lof_st ...absolute value
+	  			// lof_num, hif_num ...relative value
+	  			
+	  			// low freq.(lower)
+	  			lof_num=lof_st-old_lof_st;
+	  			if(lof_num==0){
+	  				Afreq_num+=Ac_treshp[l-1];
+	  				Mfreq_num+=Mc_treshp[l-1];
+	  			}else if(lof_num==1){
+	  				Afreq_num+=Ac_treshp[l-1];
+	  				Mfreq_num+=Mc_treshp[l-1];
+	  				Afreq_num-=Ac_treshp[old_lof_st];
+	  				Mfreq_num-=Mc_treshp[old_lof_st];
+	  			}//else puts("err. low");
+	  			
+	  			// high freq.(higher)
+	  			hif_num=hif_st-old_hif_st;
+	  			if(hif_num==0){
+	  				Afreq_num-=Ac_treshp[l];
+	  				Mfreq_num-=Mc_treshp[l];
+	  			}else if(hif_num==1){
+	  				Afreq_num-=Ac_treshp[l];
+	  				Mfreq_num-=Mc_treshp[l];
+	  				Afreq_num+=Ac_treshp[hif_st];
+	  				Mfreq_num+=Mc_treshp[hif_st];
+	  			}else if(hif_num==2){
+	  				Afreq_num-=Ac_treshp[l];
+	  				Mfreq_num-=Mc_treshp[l];
+	  				Afreq_num+=Ac_treshp[hif_st];
+	  				Mfreq_num+=Mc_treshp[hif_st];
+	  				Afreq_num+=Ac_treshp[hif_st-1];
+	  				Mfreq_num+=Mc_treshp[hif_st-1];
+	  			}//else puts("err. high");
+	  		}
+	  	}else{
+	  		for(m=lof_st; m<=hif_st; m++){
+	  			if(m==l)continue;
+	  			if(Ac_treshp[m]) Afreq_num++;
+	  			if(Mc_treshp[m]) Mfreq_num++;
+			}
+	  	}
+	  	if(l>=limit){
+	  		shigh=sth_high/(hif_stcopy-lof_st);
+	  		shighA=shigh*Afreq_num;
+	  		shighM=shigh*Mfreq_num;
+	  		if((shighA+rAs)>(shighM+rMs))shigh=shighA;
+	  		else shigh=shighM;
+		}else{
+			slow=sth_low/(hif_stcopy-lof_st);
+			slowA=slow*Afreq_num;
+			slowM=slow*Mfreq_num;
+			if(p->noiseoffset[1][l]<-1){
+				slowA*=(p->noiseoffset[1][l]+2);
+				slowM*=(p->noiseoffset[1][l]+2);
+			}
+		}
+		old_lof_st=lof_st;
+	  	old_hif_st=hif_st;
+	  }
 
-	  /* The following prevents an extreme reduction of residue. (2ch stereo only) */
 	  if(l>=limit){
+	    postpoint-=shigh;
+	    /* The following prevents an extreme reduction of residue. (2ch stereo only) */
 	  	if( ((a>0.) && (b<0.)) || ((b>0.) && (a<0.)) ){
 	  		hypot_reserve = fabs(fabs(a)-fabs(b));
 	  		if(hypot_reserve < 0.001){ // 0~0.000999-
@@ -1525,8 +1772,8 @@
 	  }
 	  
 	  if(l<sliding_lowpass){
-	    if((l>=limit && fabs(rMo[l])<postpoint && fabs(rAo[l])<postpoint) ||
-	       (fabs(rMo[l])<prepoint && fabs(rAo[l])<prepoint)){
+	    if((l>=limit && rMs<postpoint && rAs<postpoint) ||
+	       (rMs<(prepoint-slowM) && rAs<(prepoint-slowA))){
 
 
 	      precomputed_couple_point(mag_memo[i][l],
@@ -1534,7 +1781,10 @@
 				       qM+l,qA+l);
 
 	      //if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
-	      if( (rint(qM[l])==0.f) && (l>=limit) )acc+=qM[l]*qM[l]*0.9;
+	      if(rint(qM[l])==0.f){
+	      	energy_loss++;
+	      	if(l>=limit)acc+=qM[l]*qM[l];
+	      }
 	    }else{
 	      couple_lossless(rM[l],rA[l],qM+l,qA+l);
 	    }
@@ -1543,24 +1793,106 @@
 	    qA[l]=0.;
 	  }
 	}
-	
+
 	if(p->vi->normal_point_p){
+	  int freqband_mid=j+16;
+	  int freqband_flag=0;
+	  int min_energy;
+	  
+	  rpacc=acc;
+	  /* When the energy loss of a partition is large, NN is performed in the middle of partition.
+	      for 48/44.1/32kHz */
+	  if(energy_loss==32 && fabs(qM[freqband_mid])>nnmid_th && acc>=p->vi->normal_thresh
+	   && freqband_mid<sliding_lowpass && freqband_mid>=pointlimit && rint(qM[freqband_mid])==0.f){
+	  	if( ((mdctM[freqband_mid]>0.) && (mdctA[freqband_mid]<0.)) ||
+	  	 ((mdctA[freqband_mid]>0.) && (mdctM[freqband_mid]<0.)) ){
+	  	 acc-=1.f;
+	  	 rpacc-=1.32;
+	  	}else{
+	  	 acc-=1.f;
+	  	 rpacc-=1.f;
+	  	}
+	  	qM[freqband_mid]=unitnorm(qM[freqband_mid]);
+	  	freqband_flag=1;
+	  	nn_num++;
+	  }
+	  /* NN main (point stereo) */
 	  for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
-	    int l=mag_sort[i][j+k];
-	    float a=mdctM[l];
-	    float b=mdctA[l];
+	    int l;
+	    l=mag_sort[i][j+k];
+	    if(freqband_mid==l && freqband_flag)continue;
 	    if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
-	      qM[l]=unitnorm(qM[l]);
-	      if( ((a>0.) && (b<0.)) || ((b>0.) && (a<0.)) ){
-	        acc-=1.46;
+	      if( ((mdctM[l]>0.) && (mdctA[l]<0.)) || ((mdctA[l]>0.) && (mdctM[l]<0.)) ){
+	        if(rpacc<p->vi->normal_thresh)continue;
+	        acc-=1.f;
+	        rpacc-=1.32;
 	      }else{
 	        acc-=1.f;
+	        rpacc-=1.f;
 	      }
+	      qM[l]=unitnorm(qM[l]);
+	      nn_num++;
 	    }
-	  } 
+	  }
+	  /* The minimum energy complement.
+	      for 48/44.1/32kHz */
+	  min_energy=32-energy_loss+nn_num;
+	  if(min_energy<2 || (j<=p->min_nn_lp && min_energy==2)){
+	  	int l;
+	  	float ab;
+	    for(;k<partition;k++){
+	    	l=mag_sort[i][j+k];
+	    	ab=fabs(qM[l]);
+	    	if(ab<0.04)break;
+	    	if( ((mdctM[l]>0.) && (mdctA[l]<0.)) || ((mdctA[l]>0.) && (mdctM[l]<0.))
+	    	 && ab<0.11)break; // 0.11
+	    	if(rint(qM[l])==0.f && l>=pointlimit){
+	    		qM[l]=unitnorm(qM[l]);
+	    		break;
+	    	}
+	    }
+	  }
 	}
       }
     }
   }
 }
 
+/*  aoTuV M5
+	noise_compand_level of low frequency is determined from the level of high frequency. 
+	by Aoyumi @ 2005/09/14
+	
+	return value
+	[normal compander] 0 <> 1.0 [high compander] 
+	-1 @ disable
+*/
+float lb_loudnoise_fix(vorbis_look_psy *p,
+		float noise_compand_level,
+		float *logmdct,
+		int lW_modenumber,
+		int blocktype, int modenumber){
+
+	int i, n=p->n, nq1=p->n25p, nq3=p->n75p;
+	double hi_th=0;
+	
+	if(p->m_val < 0.5)return(-1); /* 48/44.1/32kHz only */
+	if(p->vi->normal_thresh>.45)return(-1); /* under q3 */
+
+	/* select trans. block(short>>long case). */
+	if(!modenumber)return(-1);
+	if(blocktype || lW_modenumber)return(noise_compand_level);
+
+	/* calculation of a threshold. */
+	for(i=nq1; i<nq3; i++){
+		if(logmdct[i]>-130)hi_th += logmdct[i];
+		else hi_th += -130;
+	}
+	hi_th /= n;
+	
+	/* calculation of a high_compand_level */
+	if(hi_th > -40.) noise_compand_level=-1;
+	else if(hi_th < -50.) noise_compand_level=1.;
+	else noise_compand_level=1.-((hi_th+50)/10);
+
+	return(noise_compand_level);
+}

Modified: branches/vorbis-aotuv/lib/psy.h
===================================================================
--- branches/vorbis-aotuv/lib/psy.h	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/lib/psy.h	2006-11-05 15:20:01 UTC (rev 12030)
@@ -56,6 +56,9 @@
   int   noisewindowfixed;
   float noiseoff[P_NOISECURVES][P_BANDS];
   float noisecompand[NOISE_COMPAND_LEVELS];
+  float noisecompand_high[NOISE_COMPAND_LEVELS];
+  
+  float flacint;
 
   float max_curve_dB;
 
@@ -132,6 +135,7 @@
 			     int sliding_lowpass);
 
 extern void _vp_noisemask(vorbis_look_psy *p,
+			  float noise_compand_level,
 			  float *logmdct, 
 			  float *logmask);
 
@@ -186,6 +190,12 @@
 				      vorbis_info_mapping0 *vi,
 				      float **mags);
 
+extern float lb_loudnoise_fix(vorbis_look_psy *p,
+		float noise_compand_level,
+		float *logmdct,
+		int lW_modenumber,
+		int blocktype, int modenumber);
 
+
 #endif
 

Modified: branches/vorbis-aotuv/lib/scales.h
===================================================================
--- branches/vorbis-aotuv/lib/scales.h	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/lib/scales.h	2006-11-05 15:20:01 UTC (rev 12030)
@@ -26,20 +26,24 @@
 #ifdef VORBIS_IEEE_FLOAT32
 
 static float unitnorm(float x){
-  ogg_uint32_t *ix=(ogg_uint32_t *)&x;
-  *ix=(*ix&0x80000000UL)|(0x3f800000UL);
-  return(x);
+  union {
+    ogg_uint32_t i;
+    float f;
+  } ix;
+  ix.f = x;
+  ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
+  return ix.f;
 }
 
-static float FABS(float *x){
-  ogg_uint32_t *ix=(ogg_uint32_t *)x;
-  *ix&=0x7fffffffUL;
-  return(*x);
-}
-
 /* Segher was off (too high) by ~ .3 decibel.  Center the conversion correctly. */
 static float todB(const float *x){
-  return (float)((*(ogg_int32_t *)x)&0x7fffffff) * 7.17711438e-7f -764.6161886f;
+  union {
+    ogg_uint32_t i;
+    float f;
+  } ix;
+  ix.f = *x;
+  ix.i = ix.i&0x7fffffff;
+  return (float)(ix.i * 7.17711438e-7f -764.6161886f);
 }
 
 #define todB_nn(x) todB(x)
@@ -51,8 +55,6 @@
   return(1.f);
 }
 
-#define FABS(x) fabs(*(x))
-
 #define todB(x)   (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
 #define todB_nn(x)   (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
 

Modified: branches/vorbis-aotuv/lib/vorbisenc.c
===================================================================
--- branches/vorbis-aotuv/lib/vorbisenc.c	2006-11-05 15:08:48 UTC (rev 12029)
+++ branches/vorbis-aotuv/lib/vorbisenc.c	2006-11-05 15:20:01 UTC (rev 12030)
@@ -370,11 +370,16 @@
 
 static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
 				       compandblock *in, double *x){
-  int i,is=s;
-  double ds=s-is;
+  int i,is=s, ishcm, hcm_stop=5; // high compander limit
+  double ds=s-is, dshcm;
+  
   codec_setup_info *ci=vi->codec_setup;
   vorbis_info_psy *p=ci->psy_param[block];
+  
+   /* the place was borrowed...  */
+   p->flacint=ds;
 
+  /* interpolate the compander mapping */
   ds=x[is]*(1.-ds)+x[is+1]*ds;
   is=(int)ds;
   ds-=is;
@@ -383,9 +388,32 @@
     ds=1.;
   }
 
+  /* high compander setup */
+  ishcm = is;
+  dshcm = ds+.3;
+  if(dshcm > 1.0){
+  	 ishcm++;
+  	 dshcm=dshcm-1;
+  }
+  if(x[hcm_stop] < ((float)ishcm+dshcm)){
+  	ishcm = x[hcm_stop];
+  	dshcm = x[hcm_stop]-ishcm;
+  }
+  if(dshcm==0 && ishcm>0){ // the same
+    ishcm--;
+    dshcm=1.;
+  }
+  
   /* interpolate the compander settings */
   for(i=0;i<NOISE_COMPAND_LEVELS;i++)
     p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
+  /* interpolate the high compander settings */
+  if(s < (float)hcm_stop){
+  	for(i=0;i<NOISE_COMPAND_LEVELS;i++)
+  	  p->noisecompand_high[i]=in[ishcm].data[i]*(1.-dshcm)+in[ishcm+1].data[i]*dshcm;
+  }else{ // disable high compander
+  	for(i=0;i<NOISE_COMPAND_LEVELS;i++)p->noisecompand_high[i]=0;
+  }
   return;
 }
 



More information about the commits mailing list