new preecho was switching back to long blocks too soon
authorMonty <xiphmont@xiph.org>
Sat, 23 Mar 2002 03:17:35 +0000 (03:17 +0000)
committerMonty <xiphmont@xiph.org>
Sat, 23 Mar 2002 03:17:35 +0000 (03:17 +0000)
svn path=/trunk/vorbis/; revision=3179

examples/encoder_example.c
lib/analysis.c
lib/block.c
lib/envelope.c
lib/envelope.h
lib/mapping0.c
lib/modes/psych_44.h
lib/window.c

index 3fd78c4..998a3ed 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: simple example encoder
- last mod: $Id: encoder_example.c,v 1.37 2002/02/28 04:12:47 xiphmont Exp $
+ last mod: $Id: encoder_example.c,v 1.38 2002/03/23 03:17:33 xiphmont Exp $
 
  ********************************************************************/
 
@@ -97,7 +97,7 @@ int main(){
   /* (quality mode .4: 44kHz stereo coupled, roughly 128kbps VBR) */
   vorbis_info_init(&vi);
 
-  vorbis_encode_init_vbr(&vi,2,44100,.4); /* max compression */
+  vorbis_encode_init_vbr(&vi,2,44100,.3); /* max compression */
 
   /* add a comment */
   vorbis_comment_init(&vc);
index 518399f..6fb0705 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: single-block PCM analysis mode dispatch
- last mod: $Id: analysis.c,v 1.48 2002/01/22 08:06:06 xiphmont Exp $
+ last mod: $Id: analysis.c,v 1.49 2002/03/23 03:17:33 xiphmont Exp $
 
  ********************************************************************/
 
@@ -78,7 +78,7 @@ int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
 }
 
 /* there was no great place to put this.... */
-void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB){
+void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
   int j;
   FILE *of;
   char buffer[80];
@@ -96,7 +96,7 @@ void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB){
        if(bark)
          fprintf(of,"%g ",toBARK(22050.f*j/n));
        else
-         fprintf(of,"%g ",(double)j);
+         fprintf(of,"%g ",(double)(j+off)/44100.);
        
        if(dB){
          fprintf(of,"%g\n",todB(v+j));
@@ -115,3 +115,7 @@ void _analysis_output(char *base,int i,float *v,int n,int bark,int dB){
 #endif
 }
 
+
+
+
+
index a5f6215..ab495db 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.60 2002/03/17 19:50:47 xiphmont Exp $
+ last mod: $Id: block.c,v 1.61 2002/03/23 03:17:33 xiphmont Exp $
 
  Handle windowing, overlap-add, etc of the PCM vectors.  This is made
  more amusing by Vorbis' current two allowed block sizes.
@@ -502,15 +502,9 @@ int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
      regardless of actual settings in the stream */
 
   _vorbis_block_ripcord(vb);
-  if(v->W){
-    vb->lW=v->lW;
-    vb->W=v->W;
-    vb->nW=v->nW;
-  }else{
-    vb->lW=0;
-    vb->W=v->W;
-    vb->nW=0;
-  }
+  vb->lW=v->lW;
+  vb->W=v->W;
+  vb->nW=v->nW;
 
   if(v->W){
     if(!v->lW || !v->nW){
index 62f1fcf..9761616 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: PCM data envelope analysis 
- last mod: $Id: envelope.c,v 1.42 2002/03/17 19:50:47 xiphmont Exp $
+ last mod: $Id: envelope.c,v 1.43 2002/03/23 03:17:33 xiphmont Exp $
 
  ********************************************************************/
 
@@ -149,6 +149,7 @@ static int _ve_amp(envelope_lookup *ve,
     float val=.14*buf[0]+.14*buf[1]+.72*acc[j];
     buf[0]=buf[1];buf[1]=acc[j];
     acc[j]=val;
+    filters[j].markers[pos+1]=val;
   }
 
   /* look at local min/max */
@@ -162,6 +163,8 @@ static int _ve_amp(envelope_lookup *ve,
 }
 
 static int seq=0;
+static ogg_int64_t totalshift=-1024;
+
 long _ve_envelope_search(vorbis_dsp_state *v){
   vorbis_info *vi=v->vi;
   codec_setup_info *ci=vi->codec_setup;
@@ -175,18 +178,25 @@ long _ve_envelope_search(vorbis_dsp_state *v){
 
   /* make sure we have enough storage to match the PCM */
   if(last>ve->storage){
-    ve->storage=last;
+    ve->storage=last+VE_DIV;
     ve->mark=_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
   }
 
   for(j=first;j<last;j++){
     int ret=0;
     for(i=0;i<ve->ch;i++){
+      /* the mark delay is one searchstep because of min/max finder */
       float *pcm=v->pcm[i]+ve->searchstep*(j+1);
       ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
     }
-    /* the mark delay is one searchstep because of min/max finder */
-    ve->mark[j]=ret;
+
+    /* we assume a 'transient' occupies half a short block; this way,
+       it's contained in two short blocks, else the first block is
+       short and the second long, causing smearing */
+    ve->mark[j+VE_DIV/2]=0;
+    if(ret)
+      for(i=0;i<=VE_DIV/2;i++)
+       ve->mark[j+i]=ret;
   }
 
   ve->current=last*ve->searchstep;
@@ -206,16 +216,56 @@ long _ve_envelope_search(vorbis_dsp_state *v){
       if(ve->mark[j/ve->searchstep]){
        if(j>centerW){
 
-         ve->curmark=j;
+#if 0
+         if(j>ve->curmark){
+           float *marker=alloca(v->pcm_current*sizeof(*marker));
+           int l;
+           memset(marker,0,sizeof(*marker)*v->pcm_current);
+
+           fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
+                   seq,
+                   (totalshift+ve->cursor)/44100.,
+                   (totalshift+j)/44100.);
+
+           _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
+           _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
+
+           _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
+           _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
+           
+
+           for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[0].markers[l]*.01;
+           _analysis_output_always("delL0",seq,marker,v->pcm_current,0,0,totalshift);
+           for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[1].markers[l]*.01;
+           _analysis_output_always("delL1",seq,marker,v->pcm_current,0,0,totalshift);
+           for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[2].markers[l]*.01;
+           _analysis_output_always("delL2",seq,marker,v->pcm_current,0,0,totalshift);
+           for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[3].markers[l]*.01;
+           _analysis_output_always("delL3",seq,marker,v->pcm_current,0,0,totalshift);
+           for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[4].markers[l]*.01;
+           _analysis_output_always("delR0",seq,marker,v->pcm_current,0,0,totalshift);
+           for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[5].markers[l]*.01;
+           _analysis_output_always("delR1",seq,marker,v->pcm_current,0,0,totalshift);
+           for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[6].markers[l]*.01;
+           _analysis_output_always("delR2",seq,marker,v->pcm_current,0,0,totalshift);
+           for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[7].markers[l]*.01;
+           _analysis_output_always("delR3",seq,marker,v->pcm_current,0,0,totalshift);
+             
+           seq++;
+
+         }
+#endif
 
+         ve->curmark=j;
+         ve->cursor=j;
          if(j>=testW)return(1);
          return(0);
        }
       }
       j+=ve->searchstep;
-      ve->cursor=j;
     }
   }
+  ve->cursor=j;
  
   return(-1);
 }
@@ -247,16 +297,26 @@ int _ve_envelope_mark(vorbis_dsp_state *v){
 }
 
 void _ve_envelope_shift(envelope_lookup *e,long shift){
-  int smallsize=e->current/e->searchstep;
+  int smallsize=e->current/e->searchstep+VE_DIV/2; /* VE_DIV/2 is to
+                                                      match setting a
+                                                      mark on a region
+                                                      in
+                                                      envelope_search */
   int smallshift=shift/e->searchstep;
   int i;
 
   memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
+  
+  for(i=0;i<VE_BANDS*e->ch;i++)
+    memmove(e->filter[i].markers,
+           e->filter[i].markers+smallshift,
+           (1024-smallshift)*sizeof(*(*e->filter).markers));
 
   e->current-=shift;
   if(e->curmark>=0)
     e->curmark-=shift;
   e->cursor-=shift;
+  totalshift+=shift;
 }
 
 
index 175cd4e..20cf0ae 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: PCM data envelope analysis and manipulation
- last mod: $Id: envelope.h,v 1.19 2002/03/17 19:50:47 xiphmont Exp $
+ last mod: $Id: envelope.h,v 1.20 2002/03/23 03:17:34 xiphmont Exp $
 
  ********************************************************************/
 
@@ -29,6 +29,8 @@ typedef struct {
   int   ampptr;
   float delbuf[VE_CONV-1];
   float convbuf[2];
+  
+  float markers[1024];
 } envelope_filter_state;
 
 typedef struct {
index 22a97a7..884caae 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: channel mapping 0 implementation
- last mod: $Id: mapping0.c,v 1.45 2002/02/28 04:12:48 xiphmont Exp $
+ last mod: $Id: mapping0.c,v 1.46 2002/03/23 03:17:34 xiphmont Exp $
 
  ********************************************************************/
 
@@ -284,6 +284,8 @@ static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb)
 
 /* no time mapping implementation for now */
 static long seq=0;
+ogg_int64_t total=0;
+
 static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
   vorbis_dsp_state      *vd=vb->vd;
   vorbis_info           *vi=vd->vi;
@@ -331,13 +333,13 @@ static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
     float *logmask =work+n/2;*/
 
     scale_dB=todB(&scale);
-    _analysis_output("pcm",seq+i,pcm,n,0,0);
+    //_analysis_output_always("pcm",seq+i,pcm,n,0,0,total-n/2);
 
     /* window the PCM data */
     _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
     memcpy(fft,pcm,sizeof(*fft)*n);
     
-    /*_analysis_output("windowed",seq+i,pcm,n,0,0);*/
+    //_analysis_output_always("windowed",seq+i,pcm,n,0,0,total-n/2);
 
     /* transform the PCM data */
     /* only MDCT right now.... */
@@ -357,7 +359,7 @@ static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
     if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
     if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
 
-    _analysis_output("fft",seq+i,logfft,n/2,1,0);
+    //_analysis_output("fft",seq+i,logfft,n/2,1,0);
   }
 
   for(i=0;i<vi->channels;i++){
@@ -375,7 +377,7 @@ static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
 
     for(j=0;j<n/2;j++)
       logmdct[j]=todB(mdct+j);
-    _analysis_output("mdct",seq+i,logmdct,n/2,1,0);
+    //_analysis_output("mdct",seq+i,logmdct,n/2,1,0);
 
 
     /* perform psychoacoustics; do masking */
@@ -387,7 +389,7 @@ static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
                     local_ampmax[i],
                     bm->avgnoise);
 
-    _analysis_output("mask",seq+i,logmask,n/2,1,0);
+    //_analysis_output("mask",seq+i,logmask,n/2,1,0);
     /* perform floor encoding */
     nonzero[i]=look->floor_func[submap]->
       forward(vb,look->floor_look[submap],
@@ -410,7 +412,7 @@ static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
        fprintf(stderr,"%ld ",seq+i);
        }*/
 
-    _analysis_output("codedflr",seq+i,codedflr,n/2,1,1);
+    //_analysis_output("codedflr",seq+i,codedflr,n/2,1,1);
       
   }
 
@@ -488,10 +490,6 @@ static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
                          0);
     }
 
-    for(i=0;i<vi->channels;i++)
-      _analysis_output("quant",seq+i,quantized[i],n/2,1,0);
-
-  
     /* classify, by submap */
 
     for(i=0;i<info->submaps;i++){
@@ -564,6 +562,7 @@ static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
     seq+=vi->channels;
   } 
 
+  total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
   look->lastframe=vb->sequence;
   return(0);
 }
index 4ec1aea..77ea530 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: key psychoacoustic settings for 44.1/48kHz
- last mod: $Id: psych_44.h,v 1.8 2002/03/17 19:50:49 xiphmont Exp $
+ last mod: $Id: psych_44.h,v 1.9 2002/03/23 03:17:35 xiphmont Exp $
 
  ********************************************************************/
 
@@ -23,20 +23,20 @@ static vorbis_info_psy_global _psy_global_44[4]={
   {8,   /* lines per eighth octave */
    /*{990.f,990.f,990.f,990.f}, {-990.f,-990.f,-990.f,-990.f}, -90.f,
    {0.f,0.f,0.f,0.f}, {-0.f,-0.f,-0.f,-0.f}, -90.f,*/
-   {46.f,40.f,40.f,36.f}, {-990.f,-990.f,-990.f,-990.f}, -100.f,
+   {46.f,40.f,36.f,36.f}, {-990.f,-990.f,-990.f,-990.f}, -100.f,
    -6.f, 0,
   },
   {8,   /* lines per eighth octave */
    /*{990.f,990.f,990.f,990.f}, {-990.f,-990.f,-990.f,-990.f}, -90.f,*/
-   {40.f,36.f,32.f,30.f}, {-90.f,-90.f,-90.f,-90.f}, -100.f,
+   {40.f,36.f,30.f,30.f}, {-90.f,-90.f,-90.f,-90.f}, -100.f,
    -6.f, 0,
   },
   {8,   /* lines per eighth octave */
-   {40.f,36.f,32.f,30.f}, {-60.f,-40.f,-40.f,-40.f}, -100.f,
+   {40.f,36.f,30.f,30.f}, {-60.f,-40.f,-40.f,-40.f}, -100.f,
    -6.f, 0,
   },
   {8,   /* lines per eighth octave */
-   {40.f,36.f,32.f,30.f}, {-40.f,-36.f,-32.f,-30.f}, -100.f,
+   {40.f,34.f,30.f,30.f}, {-40.f,-36.f,-32.f,-30.f}, -100.f,
    -6.f, 0,
   },
 };
index 41dc7ec..45e7c24 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: window functions
- last mod: $Id: window.c,v 1.16 2002/01/22 11:59:00 xiphmont Exp $
+ last mod: $Id: window.c,v 1.17 2002/03/23 03:17:34 xiphmont Exp $
 
  ********************************************************************/
 
@@ -48,28 +48,32 @@ float *_vorbis_window(int type, int left){
 
 void _vorbis_apply_window(float *d,float *window[2],long *blocksizes,
                          int lW,int W,int nW){
+  lW=(W?lW:0);
+  nW=(W?nW:0);
 
-  long n=blocksizes[W];
-  long ln=blocksizes[lW];
-  long rn=blocksizes[nW];
-
-  long leftbegin=n/4-ln/4;
-  long leftend=leftbegin+ln/2;
-
-  long rightbegin=n/2+n/4-rn/4;
-  long rightend=rightbegin+rn/2;
-  
-  int i,p;
-
-  for(i=0;i<leftbegin;i++)
-    d[i]=0.f;
-
-  for(p=0;i<leftend;i++,p++)
-    d[i]*=window[lW][p];
-
-  for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
-    d[i]*=window[nW][p];
-
-  for(;i<n;i++)
-    d[i]=0.f;
+  {
+    long n=blocksizes[W];
+    long ln=blocksizes[lW];
+    long rn=blocksizes[nW];
+    
+    long leftbegin=n/4-ln/4;
+    long leftend=leftbegin+ln/2;
+    
+    long rightbegin=n/2+n/4-rn/4;
+    long rightend=rightbegin+rn/2;
+    
+    int i,p;
+    
+    for(i=0;i<leftbegin;i++)
+      d[i]=0.f;
+    
+    for(p=0;i<leftend;i++,p++)
+      d[i]*=window[lW][p];
+    
+    for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
+      d[i]*=window[nW][p];
+    
+    for(;i<n;i++)
+      d[i]=0.f;
+  }
 }