Vorbisfile API addition for game and mod coders;
[platform/upstream/libvorbis.git] / lib / mapping0.c
index 00d52d1..e38ca5f 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.58 2003/08/18 05:34:01 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,
@@ -176,7 +243,7 @@ static int mapping0_forward(vorbis_block *vb){
   vorbis_dsp_state      *vd=vb->vd;
   vorbis_info           *vi=vd->vi;
   codec_setup_info      *ci=vi->codec_setup;
-  backend_lookup_state  *b=vb->vd->backend_state;
+  private_state         *b=vb->vd->backend_state;
   vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
   int                    n=vb->pcmend;
   int i,j,k;
@@ -444,15 +511,18 @@ static int mapping0_forward(vorbis_block *vb){
     float **mag_memo;
     int **mag_sort;
 
-    mag_memo=_vp_quantize_couple_memo(vb,
-                                     psy_look,
-                                     info,
-                                     gmdct);    
-
-    mag_sort=_vp_quantize_couple_sort(vb,
-                                     psy_look,
-                                     info,
-                                     mag_memo);    
+    if(info->coupling_steps){
+      mag_memo=_vp_quantize_couple_memo(vb,
+                                       &ci->psy_g_param,
+                                       psy_look,
+                                       info,
+                                       gmdct);    
+      
+      mag_sort=_vp_quantize_couple_sort(vb,
+                                       psy_look,
+                                       info,
+                                       mag_memo);    
+    }
 
     memset(sortindex,0,sizeof(*sortindex)*vi->channels);
     if(psy_look->vi->normal_channel_p){
@@ -491,75 +561,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 +574,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,10 +606,8 @@ static int mapping0_forward(vorbis_block *vb){
                   mag_memo,
                   mag_sort,
                   ilogmaskch,
-                  nonzero);
-      }else{
-       for(i=0;i<vi->channels;i++)
-         memcpy(vb->pcm[i]+n/2,vb->pcm[i],n/2*sizeof(**vb->pcm));
+                  nonzero,
+                  ci->psy_g_param.sliding_lowpass[vb->W][k]);
       }
       
       /* classify and encode by submap */
@@ -645,8 +652,9 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
   vorbis_dsp_state     *vd=vb->vd;
   vorbis_info          *vi=vd->vi;
   codec_setup_info     *ci=vi->codec_setup;
-  backend_lookup_state *b=vd->backend_state;
+  private_state        *b=vd->backend_state;
   vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
+  int hs=ci->halfrate_flag; 
 
   int                   i,j;
   long                  n=vb->pcmend=ci->blocksizes[vb->W];
@@ -740,17 +748,6 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
     mdct_backward(b->transform[vb->W][0],pcm,pcm);
   }
 
-  /* window the data */
-  for(i=0;i<vi->channels;i++){
-    float *pcm=vb->pcm[i];
-    if(nonzero[i])
-      _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
-    else
-      for(j=0;j<n;j++)
-       pcm[j]=0.f;
-
-  }
-
   /* all done! */
   return(0);
 }