[xiph-cvs] cvs commit: vorbis/lib/modes mode_A.h

Monty xiphmont at xiph.org
Sun Jan 14 16:35:39 PST 2001



xiphmont    01/01/14 16:35:39

  Modified:    include/vorbis Tag: monty_branch_20001226 codec.h
               lib      Tag: monty_branch_20001226 block.c codec_internal.h
                        floor0.c mapping0.c psy.c psy.h res0.c
               lib/modes Tag: monty_branch_20001226 mode_A.h
  Log:
  Incremental update; implemented a global amplitude tracker.
  
  Monty

Revision  Changes    Path
No                   revision

No                   revision

1.33.2.2  +3 -2      vorbis/include/vorbis/codec.h

Index: codec.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/include/vorbis/codec.h,v
retrieving revision 1.33.2.1
retrieving revision 1.33.2.2
diff -u -r1.33.2.1 -r1.33.2.2
--- codec.h	2000/12/27 23:46:34	1.33.2.1
+++ codec.h	2001/01/15 00:35:35	1.33.2.2
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: libvorbis codec headers
- last mod: $Id: codec.h,v 1.33.2.1 2000/12/27 23:46:34 xiphmont Exp $
+ last mod: $Id: codec.h,v 1.33.2.2 2001/01/15 00:35:35 xiphmont Exp $
 
  ********************************************************************/
 
@@ -89,7 +89,6 @@
 typedef struct vorbis_block{
   /* necessary stream state for linking to the framing abstraction */
   float  **pcm;       /* this is a pointer into local storage */ 
-  float  **pcmdelay;  /* this is a pointer into local storage */ 
   oggpack_buffer opb;
   
   long  lW;
@@ -116,6 +115,8 @@
   long time_bits;
   long floor_bits;
   long res_bits;
+
+  void *internal;
 
 } vorbis_block;
 

No                   revision

No                   revision

1.42.2.3  +22 -7     vorbis/lib/block.c

Index: block.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/block.c,v
retrieving revision 1.42.2.2
retrieving revision 1.42.2.3
diff -u -r1.42.2.2 -r1.42.2.3
--- block.c	2001/01/09 19:13:14	1.42.2.2
+++ block.c	2001/01/15 00:35:36	1.42.2.3
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.42.2.2 2001/01/09 19:13:14 xiphmont Exp $
+ last mod: $Id: block.c,v 1.42.2.3 2001/01/15 00:35:36 xiphmont Exp $
 
  Handle windowing, overlap-add, etc of the PCM vectors.  This is made
  more amusing by Vorbis' current two allowed block sizes.
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <ogg/ogg.h>
 #include "vorbis/codec.h"
+#include "codec_internal.h"
 
 #include "window.h"
 #include "envelope.h"
@@ -33,6 +34,7 @@
 #include "codebook.h"
 #include "misc.h"
 #include "os.h"
+#include "psy.h"
 
 static int ilog2(unsigned int v){
   int ret=0;
@@ -92,9 +94,12 @@
   vb->vd=v;
   vb->localalloc=0;
   vb->localstore=NULL;
-  if(v->analysisp)
+  if(v->analysisp){
     oggpack_writeinit(&vb->opb);
-
+    vb->internal=_ogg_calloc(1,sizeof(vorbis_block_internal));
+    ((vorbis_block_internal *)vb->internal)->ampmax=-9999;
+  }
+  
   return(0);
 }
 
@@ -150,6 +155,7 @@
       oggpack_writeclear(&vb->opb);
   _vorbis_block_ripcord(vb);
   if(vb->localstore)_ogg_free(vb->localstore);
+  if(vb->internal)_ogg_free(vb->internal);
 
   memset(vb,0,sizeof(vorbis_block));
   return(0);
@@ -169,6 +175,7 @@
 
   v->vi=vi;
   b->modebits=ilog2(ci->modes);
+  b->ampmax=-9999;
 
   b->transform[0]=_ogg_calloc(VI_TRANSFORMB,sizeof(vorbis_look_transform *));
   b->transform[1]=_ogg_calloc(VI_TRANSFORMB,sizeof(vorbis_look_transform *));
@@ -529,16 +536,24 @@
   vb->sequence=v->sequence;
   vb->granulepos=v->granulepos;
   vb->pcmend=ci->blocksizes[v->W];
+
   
   /* copy the vectors; this uses the local storage in vb */
   {
+    vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
+
+    /* this tracks 'strongest peak' for later psychoacoustics */
+    if(vbi->ampmax>b->ampmax)b->ampmax=vbi->ampmax;
+    b->ampmax=_vp_ampmax_decay(b->ampmax,v);
+    vbi->ampmax=b->ampmax;
+
     vb->pcm=_vorbis_block_alloc(vb,sizeof(float *)*vi->channels);
-    vb->pcmdelay=_vorbis_block_alloc(vb,sizeof(float *)*vi->channels);
+    vbi->pcmdelay=_vorbis_block_alloc(vb,sizeof(float *)*vi->channels);
     for(i=0;i<vi->channels;i++){
-      vb->pcmdelay[i]=
+      vbi->pcmdelay[i]=
         _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(float));
-      memcpy(vb->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(float));
-      vb->pcm[i]=vb->pcmdelay[i]+beginW;
+      memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(float));
+      vb->pcm[i]=vbi->pcmdelay[i]+beginW;
       
       /* before we added the delay 
       vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(float));

1.3.2.2   +10 -1     vorbis/lib/codec_internal.h

Index: codec_internal.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/codec_internal.h,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -r1.3.2.1 -r1.3.2.2
--- codec_internal.h	2000/12/27 23:46:35	1.3.2.1
+++ codec_internal.h	2001/01/15 00:35:36	1.3.2.2
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: libvorbis codec headers
- last mod: $Id: codec_internal.h,v 1.3.2.1 2000/12/27 23:46:35 xiphmont Exp $
+ last mod: $Id: codec_internal.h,v 1.3.2.2 2001/01/15 00:35:36 xiphmont Exp $
 
  ********************************************************************/
 
@@ -24,6 +24,11 @@
 #include "psy.h"
 #include "bitbuffer.h"
 
+typedef struct vorbis_block_internal{
+  float  **pcmdelay;  /* this is a pointer into local storage */ 
+  float  ampmax;
+} vorbis_block_internal;
+
 typedef void vorbis_look_time;
 typedef void vorbis_look_mapping;
 typedef void vorbis_look_floor;
@@ -49,6 +54,8 @@
   unsigned char *header1;
   unsigned char *header2;
 
+  float ampmax;
+
 } backend_lookup_state;
 
 /* mode ************************************************************/
@@ -107,6 +114,8 @@
   float     preecho_thresh;
   float     postecho_thresh;
   float     preecho_minenergy;
+
+  float     ampmax_att_per_sec;
 
   /* delay caching... how many samples to keep around prior to our
      current block to aid in analysis? */

1.34.2.3  +3 -3      vorbis/lib/floor0.c

Index: floor0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/floor0.c,v
retrieving revision 1.34.2.2
retrieving revision 1.34.2.3
diff -u -r1.34.2.2 -r1.34.2.3
--- floor0.c	2001/01/09 19:13:14	1.34.2.2
+++ floor0.c	2001/01/15 00:35:36	1.34.2.3
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: floor backend 0 implementation
- last mod: $Id: floor0.c,v 1.34.2.2 2001/01/09 19:13:14 xiphmont Exp $
+ last mod: $Id: floor0.c,v 1.34.2.3 2001/01/15 00:35:36 xiphmont Exp $
 
  ********************************************************************/
 
@@ -335,7 +335,7 @@
       booknum=0;
 
     b=be->fullbooks+info->books[booknum];
-    bitbuf_write(vbb,booknum,_ilog(info->numbooks));
+    oggpack_write(&vb->opb,booknum,_ilog(info->numbooks));
 
 
 #ifdef TRAIN_LSP
@@ -360,7 +360,7 @@
 
     for(j=0;j<look->m;j+=b->dim){
       int entry=_f0_fit(b,flr,lspwork,j);
-      bits+=vorbis_book_encode(b,entry,)&vb->opb;
+      bits+=vorbis_book_encode(b,entry,&vb->opb);
 
 #ifdef TRAIN_LSP
       fprintf(ef,"%d,\n",entry);

1.22.2.3  +16 -14    vorbis/lib/mapping0.c

Index: mapping0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/mapping0.c,v
retrieving revision 1.22.2.2
retrieving revision 1.22.2.3
diff -u -r1.22.2.2 -r1.22.2.3
--- mapping0.c	2001/01/09 19:13:15	1.22.2.2
+++ mapping0.c	2001/01/15 00:35:36	1.22.2.3
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: channel mapping 0 implementation
- last mod: $Id: mapping0.c,v 1.22.2.2 2001/01/09 19:13:15 xiphmont Exp $
+ last mod: $Id: mapping0.c,v 1.22.2.3 2001/01/15 00:35:36 xiphmont Exp $
 
  ********************************************************************/
 
@@ -203,13 +203,14 @@
 /* no time mapping implementation for now */
 static long seq=0;
 static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
-  vorbis_dsp_state     *vd=vb->vd;
-  vorbis_info          *vi=vd->vi;
-  backend_lookup_state *b=vb->vd->backend_state;
-  vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l;
-  vorbis_info_mapping0 *info=look->map;
-  vorbis_info_mode     *mode=look->mode;
-  int                   n=vb->pcmend;
+  vorbis_dsp_state      *vd=vb->vd;
+  vorbis_info           *vi=vd->vi;
+  backend_lookup_state  *b=vb->vd->backend_state;
+  vorbis_look_mapping0  *look=(vorbis_look_mapping0 *)l;
+  vorbis_info_mapping0  *info=look->map;
+  vorbis_info_mode      *mode=look->mode;
+  vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
+  int                    n=vb->pcmend;
   int i,j;
   float *window=b->window[vb->W][vb->lW][vb->nW][mode->windowtype];
 
@@ -219,15 +220,13 @@
 
   float **floor=_vorbis_block_alloc(vb,vi->channels*sizeof(float *));
   float *additional=_vorbis_block_alloc(vb,n*sizeof(float));
+  float newmax=vbi->ampmax;
 
-  for(i=0;i<vi->channels;i++)
-    bitbuf_init(vbb_flr+i,vb);
-  bitbuf_init(&vbb_res,vb);
-  
   for(i=0;i<vi->channels;i++){
     float *pcm=vb->pcm[i];
     float scale=4.f/n;
     int submap=info->chmuxlist[i];
+    float ret;
 
     _analysis_output("pcm",seq,pcm,n,0,0);
 
@@ -262,8 +261,9 @@
     //_analysis_output("lmdct",seq,additional+n/2,n/2,0,0);
 
     /* perform psychoacoustics; do masking */
-    _vp_compute_mask(look->psy_look+submap,additional,additional+n/2,
-		     floor[i],NULL);
+    ret=_vp_compute_mask(look->psy_look+submap,additional,additional+n/2,
+			 floor[i],NULL,vbi->ampmax);
+    if(ret>newmax)newmax=ret;
 
     _analysis_output("prefloor",seq,floor[i],n/2,0,0);
     
@@ -295,6 +295,8 @@
     
   }
     
+  vbi->ampmax=newmax;
+
   /* perform residue encoding with residue mapping; this is
      multiplexed.  All the channels belonging to one submap are
      encoded (values interleaved), then the next submap, etc */

1.34.2.3  +21 -6     vorbis/lib/psy.c

Index: psy.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/psy.c,v
retrieving revision 1.34.2.2
retrieving revision 1.34.2.3
diff -u -r1.34.2.2 -r1.34.2.3
--- psy.c	2001/01/09 19:13:15	1.34.2.2
+++ psy.c	2001/01/15 00:35:36	1.34.2.3
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: psychoacoustics not including preecho
- last mod: $Id: psy.c,v 1.34.2.2 2001/01/09 19:13:15 xiphmont Exp $
+ last mod: $Id: psy.c,v 1.34.2.3 2001/01/15 00:35:36 xiphmont Exp $
 
  ********************************************************************/
 
@@ -20,6 +20,7 @@
 #include <math.h>
 #include <string.h>
 #include "vorbis/codec.h"
+#include "codec_internal.h"
 
 #include "masking.h"
 #include "psy.h"
@@ -421,7 +422,6 @@
                        float *seeds,
                        float *flr,
                        float att){
-  vorbis_info_psy *vi=p->vi;
   long n=p->n,i;
 
   long off=(p->eighth_octave_lines>>1)+p->firstoc;
@@ -493,7 +493,7 @@
 /* bleaugh, this is more complicated than it needs to be */
 static void max_seeds(vorbis_look_psy *p,float *minseed,float *maxseed,
                       float *flr){
-  long   n=p->total_octave_lines,i;
+  long   n=p->total_octave_lines;
   int    linesper=p->eighth_octave_lines;
   long   linpos=0;
   long   pos;
@@ -587,11 +587,12 @@
 
 }
 
-void _vp_compute_mask(vorbis_look_psy *p,
+float _vp_compute_mask(vorbis_look_psy *p,
                       float *fft, 
                       float *mdct, 
                       float *flr, 
-		      float *decay){
+		      float *decay,
+		      float prev_maxamp){
   int i,n=p->n;
   float specmax=NEGINF;
   static int seq=0;
@@ -605,6 +606,9 @@
     fft[i]=todB(fft[i]);
     if(fft[i]>specmax)specmax=fft[i];
   }
+  if(specmax<prev_maxamp)specmax=prev_maxamp;
+
+
   for(i=0;i<n;i++){
     mdct[i]=todB(mdct[i]);
   }
@@ -661,6 +665,8 @@
 
 
   seq++;
+
+  return(specmax);
 }
 
 
@@ -681,8 +687,17 @@
 
   memcpy(f,work,p->n*sizeof(float));
 }
-
 
+float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
+  vorbis_info *vi=vd->vi;
+  codec_setup_info *ci=vi->codec_setup;
+  int n=ci->blocksizes[vd->W]/2;
+  float secs=(float)n/vi->rate;
+
+  amp+=secs*ci->ampmax_att_per_sec;
+  if(amp<-9999)amp=-9999;
+  return(amp);
+}
 
 
 

1.16.2.3  +5 -3      vorbis/lib/psy.h

Index: psy.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/psy.h,v
retrieving revision 1.16.2.2
retrieving revision 1.16.2.3
diff -u -r1.16.2.2 -r1.16.2.3
--- psy.h	2001/01/09 19:13:15	1.16.2.2
+++ psy.h	2001/01/15 00:35:36	1.16.2.3
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: random psychoacoustics (not including preecho)
- last mod: $Id: psy.h,v 1.16.2.2 2001/01/09 19:13:15 xiphmont Exp $
+ last mod: $Id: psy.h,v 1.16.2.3 2001/01/15 00:35:36 xiphmont Exp $
 
  ********************************************************************/
 
@@ -89,12 +89,14 @@
 extern void   _vi_psy_free(vorbis_info_psy *i);
 extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
 
-extern void   _vp_compute_mask(vorbis_look_psy *p,
+extern float  _vp_compute_mask(vorbis_look_psy *p,
                                float *fft, 
                                float *mdct, 
                                float *floor,
-			       float *decay);
+			       float *decay,
+			       float prev_maxamp);
 extern void _vp_apply_floor(vorbis_look_psy *p,float *f,float *flr);
+extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
 
 #endif
 

1.23.2.2  +4 -4      vorbis/lib/res0.c

Index: res0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/res0.c,v
retrieving revision 1.23.2.1
retrieving revision 1.23.2.2
diff -u -r1.23.2.1 -r1.23.2.2
--- res0.c	2001/01/09 19:13:15	1.23.2.1
+++ res0.c	2001/01/15 00:35:36	1.23.2.2
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: residue backend 0 implementation
- last mod: $Id: res0.c,v 1.23.2.1 2001/01/09 19:13:15 xiphmont Exp $
+ last mod: $Id: res0.c,v 1.23.2.2 2001/01/15 00:35:36 xiphmont Exp $
 
  ********************************************************************/
 
@@ -210,7 +210,7 @@
   return(i);
 }
 
-static int _encodepart(vorbis_bitbuffer *vbb,float *vec, int n,
+static int _encodepart(oggpack_buffer *opb,float *vec, int n,
                        int stages, codebook **books,int mode,int part){
   int i,j=0,bits=0;
   if(stages){
@@ -228,7 +228,7 @@
         fclose(f);
       }
 #endif
-      bits+=vorbis_book_encode(books[j],entry,vbb);
+      bits+=vorbis_book_encode(books[j],entry,opb);
     }
   }
   return(bits);
@@ -305,7 +305,7 @@
       long val=partword[j][l];
       for(k=1;k<partitions_per_word;k++)
         val= val*possible_partitions+partword[j][l+k];
-      phrasebits+=vorbis_book_encode(look->phrasebook,val,vbb);
+      phrasebits+=vorbis_book_encode(look->phrasebook,val,&vb->opb);
     }
     /* now we encode interleaved residual values for the partitions */
     for(k=0;k<partitions_per_word;k++,l++,i+=samples_per_partition)

No                   revision

No                   revision

1.7.2.3   +15 -11    vorbis/lib/modes/mode_A.h

Index: mode_A.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/modes/mode_A.h,v
retrieving revision 1.7.2.2
retrieving revision 1.7.2.3
diff -u -r1.7.2.2 -r1.7.2.3
--- mode_A.h	2001/01/09 19:13:23	1.7.2.2
+++ mode_A.h	2001/01/15 00:35:38	1.7.2.3
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: predefined encoding modes
- last mod: $Id: mode_A.h,v 1.7.2.2 2001/01/09 19:13:23 xiphmont Exp $
+ last mod: $Id: mode_A.h,v 1.7.2.3 2001/01/15 00:35:38 xiphmont Exp $
 
  ********************************************************************/
 
@@ -124,8 +124,8 @@
    .500f, /*2800*/
    .600f, /*4000*/
    .700f, /*5600*/
-   .800f, /*8000*/
-   .800f, /*11500*/
+   .850f, /*8000*/
+   .900f, /*11500*/
    .900f, /*16000*/
   },
  
@@ -176,8 +176,8 @@
    {-30.,-35.,-35.,-40.,-40.,-50.,-60.,-70.,-80.,-90.,-100.}, /*4000*/
    {-30.,-35.,-35.,-40.,-40.,-50.,-60.,-70.,-80.,-90.,-100.}, /*5600*/
    {-30.,-30.,-30.,-40.,-40.,-50.,-60.,-70.,-80.,-90.,-100.}, /*8000*/
-   {-30.,-30.,-30.,-35.,-40.,-40.,-60.,-70.,-80.,-90.,-100.}, /*11500*/
-   {-30.,-30.,-30.,-35.,-35.,-45.,-50.,-50.,-70.,-80.,-90.}, /*16000*/
+   {-30.,-30.,-30.,-35.,-40.,-45.,-60.,-70.,-80.,-90.,-100.}, /*11500*/
+   {-30.,-30.,-30.,-35.,-35.,-45.,-50.,-60.,-70.,-80.,-90.}, /*16000*/
   },
 
   1,/* peakattp */
@@ -201,7 +201,7 @@
   },
 
   1,/*noisemaskp */
-  -30.f,  /* suppress any noise curve over maxspec+n */
+  -0.f,  /* suppress any noise curve over maxspec+n */
   .5f,   /* low window */
   .5f,   /* high window */
   25,
@@ -218,11 +218,11 @@
    .400f, /*1400*/
    .400f, /*2000*/
    .400f, /*2800*/
-   .600f, /*4000*/
-   .750f, /*5600*/
-   .850f, /*8000*/
+   .700f, /*4000*/
+   .850f, /*5600*/
+   .900f, /*8000*/
    .900f, /*11500*/
-   .950f, /*16000*/
+   .900f, /*16000*/
   },
  
   95.f,  /* even decade + 5 is important; saves an rint() later in a
@@ -309,7 +309,11 @@
   /* psy */
   {&_psy_set_A0,&_psy_set_A},
   /* thresh sample period, preecho clamp trigger threshhold, range, minenergy */
-  256, 30.f, -30.f, -96.f
+  256, 30.f, -30.f, -96.f,
+
+  -10., 
+
+  0,
 };
 
 #define PREDEF_INFO_MAX 0

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list