[xiph-cvs] cvs commit: vorbis/lib bitrate.c bitrate.h analysis.c block.c mapping0.c psy.c codec_internal.h psy.h

Monty xiphmont at xiph.org
Fri Nov 16 00:17:16 PST 2001



xiphmont    01/11/16 00:17:15

  Modified:    lib      Tag: branch_monty_20011009 analysis.c block.c
                        mapping0.c psy.c codec_internal.h psy.h
  Added:       lib      Tag: branch_monty_20011009 bitrate.c bitrate.h
  Log:
  Incremental commit of take-two higher latency but more stable
  bitrate management

Revision  Changes    Path
No                   revision

No                   revision

1.46.4.1  +8 -13     vorbis/lib/analysis.c

Index: analysis.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/analysis.c,v
retrieving revision 1.46
retrieving revision 1.46.4.1
diff -u -r1.46 -r1.46.4.1
--- analysis.c	2001/08/13 01:36:56	1.46
+++ analysis.c	2001/11/16 08:17:04	1.46.4.1
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: single-block PCM analysis mode dispatch
- last mod: $Id: analysis.c,v 1.46 2001/08/13 01:36:56 xiphmont Exp $
+ last mod: $Id: analysis.c,v 1.46.4.1 2001/11/16 08:17:04 xiphmont Exp $
 
  ********************************************************************/
 
@@ -27,8 +27,12 @@
 
 int analysis_noisy=1;
 
+int vorbis_analysis_packetout(vorbis_block *vb,ogg_packet *op){
+  return(vorbis_bitrate_flushpacket(&(vb->bms),op));
+}
+
 /* decides between modes, dispatches to the appropriate mapping. */
-int vorbis_analysis(vorbis_block *vb,ogg_packet *op){
+int vorbis_analysis(vorbis_block *vb){
   vorbis_dsp_state     *vd=vb->vd;
   backend_lookup_state *b=vd->backend_state;
   vorbis_info          *vi=vd->vi;
@@ -64,17 +68,8 @@
 
   if((ret=_mapping_P[type]->forward(vb,b->mode[mode])))
     return(ret);
-  
-  /* set up the packet wrapper */
-  
-  op->packet=oggpack_get_buffer(&vb->opb);
-  op->bytes=oggpack_bytes(&vb->opb);
-  op->b_o_s=0;
-  op->e_o_s=vb->eofflag;
-  op->granulepos=vb->granulepos;
-  op->packetno=vb->sequence; /* for sake of completeness */
-  
-  return(0);
+
+  return(vorbis_bitrate_addblock(vb));
 }
 
 /* there was no great place to put this.... */

1.50.2.5  +3 -28     vorbis/lib/block.c

Index: block.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/block.c,v
retrieving revision 1.50.2.4
retrieving revision 1.50.2.5
diff -u -r1.50.2.4 -r1.50.2.5
--- block.c	2001/10/20 03:00:09	1.50.2.4
+++ block.c	2001/11/16 08:17:05	1.50.2.5
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.50.2.4 2001/10/20 03:00:09 xiphmont Exp $
+ last mod: $Id: block.c,v 1.50.2.5 2001/11/16 08:17:05 xiphmont Exp $
 
  Handle windowing, overlap-add, etc of the PCM vectors.  This is made
  more amusing by Vorbis' current two allowed block sizes.
@@ -26,14 +26,10 @@
 #include "codec_internal.h"
 
 #include "window.h"
-#include "envelope.h"
 #include "mdct.h"
 #include "lpc.h"
 #include "registry.h"
-#include "codebook.h"
 #include "misc.h"
-#include "os.h"
-#include "psy.h"
 
 static int ilog2(unsigned int v){
   int ret=0;
@@ -268,25 +264,7 @@
   b->ve=_ogg_calloc(1,sizeof(*b->ve));
   _ve_envelope_init(b->ve,vi);
 
-  /* compute bitrate tracking setup, allocate circular packet size queue */
-  {
-    codec_setup_info *ci=vi->codec_setup;
-    /* first find the max possible needed queue size */
-    long maxpackets=(ci->bitrate_queue_time*vi->rate+(ci->blocksizes[0]-1))/ci->blocksizes[0]+1;
-    long bins=BITTRACK_DIVISOR*ci->passlimit[ci->coupling_passes-1];
-    if(ci->bitrate_queue_avgmin<=0. && 
-       ci->bitrate_queue_avgmax<=0.)bins=0;
-
-    b->bitrate_queue_size=maxpackets;
-    b->bitrate_bins=bins;
-    b->bitrate_queue_actual=_ogg_malloc(maxpackets*sizeof(*b->bitrate_queue_actual));
-    if(bins){
-      b->bitrate_queue_binned=_ogg_malloc(maxpackets*bins*
-					  sizeof(*b->bitrate_queue_binned));
-      b->bitrate_queue_binacc=_ogg_malloc(bins*sizeof(*b->bitrate_queue_binacc));
-    }
-    b->bitrate_avgfloat=ci->bitrate_avgfloat_initial;
-  }
+  vorbis_bitrate_init(vi,&b->bms);
 
   return(0);
 }
@@ -328,10 +306,7 @@
         _ogg_free(b->transform[1]);
       }
       if(b->psy_g_look)_vp_global_free(b->psy_g_look);
-      if(b->bitrate_queue_actual)_ogg_free(b->bitrate_queue_actual);
-      if(b->bitrate_queue_binned)_ogg_free(b->bitrate_queue_binned);
-      if(b->bitrate_queue_binacc)_ogg_free(b->bitrate_queue_binacc);
-      
+      vorbis_bitrate_clear(&b->bms);
     }
     
     if(v->pcm){

1.37.2.7  +76 -52    vorbis/lib/mapping0.c

Index: mapping0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/mapping0.c,v
retrieving revision 1.37.2.6
retrieving revision 1.37.2.7
diff -u -r1.37.2.6 -r1.37.2.7
--- mapping0.c	2001/10/22 09:09:29	1.37.2.6
+++ mapping0.c	2001/11/16 08:17:05	1.37.2.7
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: channel mapping 0 implementation
- last mod: $Id: mapping0.c,v 1.37.2.6 2001/10/22 09:09:29 xiphmont Exp $
+ last mod: $Id: mapping0.c,v 1.37.2.7 2001/11/16 08:17:05 xiphmont Exp $
 
  ********************************************************************/
 
@@ -23,7 +23,6 @@
 #include "vorbis/codec.h"
 #include "codec_internal.h"
 #include "codebook.h"
-#include "bitbuffer.h"
 #include "registry.h"
 #include "psy.h"
 #include "misc.h"
@@ -282,39 +281,6 @@
 #include "psy.h"
 #include "scales.h"
 
-static double floater_interpolate(backend_lookup_state *b,vorbis_info *vi,
-				  double desired_rate){
-  int bin=b->bitrate_avgfloat*BITTRACK_DIVISOR-1.;
-  double lobitrate;
-  double hibitrate;
-  
-  if(desired_rate<=0.)return(0.);
-  
-  lobitrate=(double)(bin==0?0.:
-		     b->bitrate_queue_binacc[bin-1])/b->bitrate_queue_sampleacc[0]*vi->rate;
-  while(lobitrate>desired_rate && bin>0){
-    bin--;
-    lobitrate=(double)(bin==0?0.:
-		       b->bitrate_queue_binacc[bin-1])/b->bitrate_queue_sampleacc[0]*vi->rate;
-  }
-
-  hibitrate=(bin>=b->bitrate_bins?b->bitrate_queue_binacc[b->bitrate_bins-1]:
-	     (double)b->bitrate_queue_binacc[bin])/b->bitrate_queue_sampleacc[0]*vi->rate;
-  while(hibitrate<desired_rate && bin<b->bitrate_bins){
-    bin++;
-    if(bin<b->bitrate_bins)
-      hibitrate=(double)b->bitrate_queue_binacc[bin]/b->bitrate_queue_sampleacc[0]*vi->rate;
-  }
-
-  /* interpolate */
-  if(bin==b->bitrate_bins){
-    return bin/(double)BITTRACK_DIVISOR;
-  }else{
-    double delta=(desired_rate-lobitrate)/(hibitrate-lobitrate);
-    return (bin+delta)/(double)BITTRACK_DIVISOR;
-  }
-}
-
 /* no time mapping implementation for now */
 static long seq=0;
 static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
@@ -425,7 +391,8 @@
                      logmask,
                      global_ampmax,
                      local_ampmax[i],
-		     ci->blocksizes[vb->lW]/2);
+		     ci->blocksizes[vb->lW]/2,
+		     b->bitrate_avgnoise);
 
     _analysis_output("mask",seq+i,logmask,n/2,1,0);
     /* perform floor encoding */
@@ -577,12 +544,16 @@
     {
       long maxbits_absolute=
         (vb->W?
-	 ci->bitrate_absolute_max_long/vi->rate*ci->blocksizes[1]/2:
-	 ci->bitrate_absolute_max_short/vi->rate*ci->blocksizes[0]/2);
+	 (ci->bitrate_absolute_max_long>0?
+	  ci->bitrate_absolute_max_long/vi->rate*ci->blocksizes[1]/2:-1):
+	 (ci->bitrate_absolute_max_short>0?
+	  ci->bitrate_absolute_max_short/vi->rate*ci->blocksizes[0]/2:-1));
       long minbits_absolute=
         (vb->W?
-	 ci->bitrate_absolute_min_long/vi->rate*ci->blocksizes[1]/2:
-	 ci->bitrate_absolute_min_short/vi->rate*ci->blocksizes[0]/2);
+	 (ci->bitrate_absolute_min_long>0?
+	  ci->bitrate_absolute_min_long/vi->rate*ci->blocksizes[1]/2:-1):
+	 (ci->bitrate_absolute_min_short>0?
+	  ci->bitrate_absolute_min_short/vi->rate*ci->blocksizes[0]/2:-1));
 
       long minbits_period=ci->bitrate_queue_hardmin/vi->rate*
         (b->bitrate_queue_sampleacc[0]+ci->blocksizes[vb->W]/2)-
@@ -592,6 +563,9 @@
                               b->bitrate_queue_sampleacc[0]);
       long maxbits_period=-1;
 
+      maxbits=-1;
+      minbits=-1;
+      
       /* pessimistic checkahead */
       for(i=0;i<8;i++){
         long ahead_samples=period_samples-b->bitrate_queue_sampleacc[i];
@@ -599,7 +573,7 @@
           long maxbits_local=ci->bitrate_queue_hardmax/vi->rate*
             (period_samples+ci->blocksizes[vb->W]/2)-
             b->bitrate_queue_bitacc[i]-
-	    ci->bitrate_queue_hardmin/vi->rate*ahead_samples;
+	    ci->bitrate_queue_hardmax/vi->rate*ahead_samples;
 
           if(maxbits_period==-1 || maxbits_local<maxbits_period)
             maxbits_period=maxbits_local;
@@ -607,19 +581,20 @@
         }
       }
 
+
+      fprintf(stderr,"maxbits_a %ld    maxbit_period %ld\n",maxbits_absolute,maxbits_period);
 
-      if(maxbits_absolute){
-	if(ci->bitrate_queue_hardmax>0.){
+      if(maxbits_absolute>=0.){
+	if(maxbits_period>=0.){
           maxbits=min(maxbits_period,maxbits_absolute);
         }else{
           maxbits=maxbits_absolute;
         }
       }else
-	maxbits=maxbits_period;
+	if(maxbits_period>=0)maxbits=maxbits_period;
       minbits=max(minbits_period,minbits_absolute);
 
-      if(maxbits<0)maxbits=0;
-      if(maxbits)minbits=min(minbits,maxbits);
+      if(maxbits>=0)minbits=min(minbits,maxbits);
     }
 
     /* actual encoding loop; if we have a desired stopping point, pack
@@ -663,7 +638,7 @@
           
           long current_bytes=oggpack_bits(&vb->opb)/8;
           
-	  if(maxbits && current_bytes>maxbits/8){
+	  if(maxbits>=0 && current_bytes>maxbits/8){
             /* maxbits trumps all... */
             stoppos=maxbits/8;
             stopflag=1;
@@ -715,8 +690,8 @@
      
     /* truncate the packet according to stoppos */
     if(!stoppos)stoppos=oggpack_bytes(&vb->opb);
-    if(minbits && stoppos*8<minbits)stoppos=(minbits+7)/8;
-    if(maxbits && stoppos*8>maxbits)stoppos=maxbits/8;
+    if(minbits>=0 && stoppos*8<minbits)stoppos=(minbits+7)/8;
+    if(maxbits>=0 && stoppos*8>maxbits)stoppos=maxbits/8;
     if(stoppos>oggpack_bytes(&vb->opb))stoppos=oggpack_bytes(&vb->opb);
     vb->opb.endbyte=stoppos;
     vb->opb.endbit=0;
@@ -772,6 +747,9 @@
           for(j=0;j<b->bitrate_bins;j++)
             b->bitrate_queue_binacc[j]-=
               b->bitrate_queue_binned[b->bitrate_queue_tail[0]*b->bitrate_bins+j];
+
+	  /* watch the running noise offset trigger */
+	  if(b->bitrate_noisetrigger_postpone)--b->bitrate_noisetrigger_postpone;
         }
 
         b->bitrate_queue_tail[i]++;
@@ -803,6 +781,7 @@
       
       b->bitrate_queue_head++;
       if(b->bitrate_queue_head>=b->bitrate_queue_size)b->bitrate_queue_head=0;
+
     }
       
     /* adjust the floater to offset bitrate above/below desired average */
@@ -812,14 +791,13 @@
     
     if(b->bitrate_bins>0 &&
        (b->bitrate_queue_sampleacc[0]>ci->bitrate_queue_time*vi->rate/8 ||
-	b->bitrate_queue_sampleacc[0]>8192)){
+	b->bitrate_queue_sampleacc[0]>8192 || b->bitrate_queue_head>16)){
+
       double upper=floater_interpolate(b,vi,ci->bitrate_queue_avgmax);
       double lower=floater_interpolate(b,vi,ci->bitrate_queue_avgmin);
       double new=ci->bitrate_avgfloat_initial;
       double slew;
       
-      fprintf(stderr,"\tupper:%g :: lower:%g\n",upper,lower);
-      
       if(upper>0. && upper<new)new=upper;
       if(lower<ci->bitrate_avgfloat_minimum)
         lower=ci->bitrate_avgfloat_minimum;
@@ -835,6 +813,52 @@
         
         b->bitrate_avgfloat=new;
       }
+
+      {
+	long queueusage=b->bitrate_queue_head;
+	if(b->bitrate_queue_tail[0]>b->bitrate_queue_head)
+	  queueusage+=b->bitrate_queue_size;
+	queueusage-=b->bitrate_queue_tail[0];
+	
+	if(b->bitrate_avgfloat<ci->bitrate_avgfloat_noisetrigger_low)
+	  b->bitrate_noisetrigger_request+=1.f;
+	
+	if(b->bitrate_avgfloat>ci->bitrate_avgfloat_noisetrigger_high)
+	  b->bitrate_noisetrigger_request-=1.f;
+	
+	if(b->bitrate_noisetrigger_postpone==0){
+	  if(b->bitrate_noisetrigger_request<0.){
+	    b->bitrate_avgnoise-=1.f;
+	    if(b->bitrate_noisetrigger_request<10.)
+	    b->bitrate_avgnoise-=1.f;
+	    b->bitrate_noisetrigger_postpone=queueusage;
+	  }
+	  if(b->bitrate_noisetrigger_request>0.){
+	    b->bitrate_avgnoise+=1.f;
+	    if(b->bitrate_noisetrigger_request>10.)
+	      b->bitrate_avgnoise+=1.f;
+	    b->bitrate_noisetrigger_postpone=queueusage;
+	  }
+
+	  b->bitrate_noisetrigger_request=0.f;
+	  if(b->bitrate_avgnoise>0)
+	    b->bitrate_noisetrigger_request= -1.;
+	  if(b->bitrate_avgnoise<0)
+	    b->bitrate_noisetrigger_request= +1.;
+
+	  if(b->bitrate_avgnoise<ci->bitrate_avgfloat_noisetrigger_minoff)
+	    b->bitrate_avgnoise=ci->bitrate_avgfloat_noisetrigger_minoff;
+	  if(b->bitrate_avgnoise>ci->bitrate_avgfloat_noisetrigger_maxoff)
+	    b->bitrate_avgnoise=ci->bitrate_avgfloat_noisetrigger_maxoff;
+	}
+      }
+	      
+      fprintf(stderr,"\tupper:%g :: lower:%g (noise offset=%g, pending=%d, trigger=%d)\n",
+	      upper,lower,b->bitrate_avgnoise,b->bitrate_noisetrigger_request,
+	      b->bitrate_noisetrigger_postpone);
+      
+
+
     }
   } 
 

1.56.2.4  +11 -10    vorbis/lib/psy.c

Index: psy.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/psy.c,v
retrieving revision 1.56.2.3
retrieving revision 1.56.2.4
diff -u -r1.56.2.3 -r1.56.2.4
--- psy.c	2001/10/20 01:03:59	1.56.2.3
+++ psy.c	2001/11/16 08:17:05	1.56.2.4
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: psychoacoustics not including preecho
- last mod: $Id: psy.c,v 1.56.2.3 2001/10/20 01:03:59 xiphmont Exp $
+ last mod: $Id: psy.c,v 1.56.2.4 2001/11/16 08:17:05 xiphmont Exp $
 
  ********************************************************************/
 
@@ -815,14 +815,15 @@
   
 
 void _vp_compute_mask(vorbis_look_psy *p,
-		       vorbis_look_psy_global *g,
-		       int channel,
-		       float *logfft, 
-		       float *logmdct, 
-		       float *logmask, 
-		       float global_specmax,
-		       float local_specmax,
-		       int lastsize){
+		      vorbis_look_psy_global *g,
+		      int channel,
+		      float *logfft, 
+		      float *logmdct, 
+		      float *logmask, 
+		      float global_specmax,
+		      float local_specmax,
+		      int lastsize,
+		      float bitrate_noise_offset){
   int i,n=p->n;
   static int seq=0;
 
@@ -849,7 +850,7 @@
     for(i=0;i<n;i++){
       int dB=logmask[i]+.5;
       if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
-      logmask[i]= work[i]+p->vi->noisecompand[dB]+p->noiseoffset[i];
+      logmask[i]= work[i]+p->vi->noisecompand[dB]+p->noiseoffset[i]+bitrate_noise_offset;
       if(logmask[i]>p->vi->noisemaxsupp)logmask[i]=p->vi->noisemaxsupp;
     }
 

1.9.4.5   +4 -36     vorbis/lib/codec_internal.h

Index: codec_internal.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/codec_internal.h,v
retrieving revision 1.9.4.4
retrieving revision 1.9.4.5
diff -u -r1.9.4.4 -r1.9.4.5
--- codec_internal.h	2001/10/20 03:00:09	1.9.4.4
+++ codec_internal.h	2001/11/16 08:17:06	1.9.4.5
@@ -10,7 +10,7 @@
  ********************************************************************
 
  function: libvorbis codec headers
- last mod: $Id: codec_internal.h,v 1.9.4.4 2001/10/20 03:00:09 xiphmont Exp $
+ last mod: $Id: codec_internal.h,v 1.9.4.5 2001/11/16 08:17:06 xiphmont Exp $
 
  ********************************************************************/
 
@@ -45,8 +45,8 @@
 typedef void vorbis_info_mapping;
 
 #include "psy.h"
+#inclide "bitrate.h"
 
-#define BITTRACK_DIVISOR 16
 typedef struct backend_lookup_state {
   /* local lookup storage */
   envelope_lookup        *ve; /* envelope lookup */    
@@ -67,21 +67,8 @@
   unsigned char *header1;
   unsigned char *header2;
 
-  /* encode side bitrate tracking */
-  ogg_uint32_t  *bitrate_queue_actual;
-  ogg_uint32_t  *bitrate_queue_binned;
-  int            bitrate_queue_size;
-  int            bitrate_queue_head;
-  int            bitrate_bins;
-
-  /* 0, -1, -4, -16, -n/16, -n/8, -n/4, -n/2 */
-  long    bitrate_queue_bitacc[8];
-  long    bitrate_queue_sampleacc[8];
-  long    bitrate_queue_tail[8]; 
-  long   *bitrate_queue_binacc;
+  bitrate_manager_state bms;
 
-  double bitrate_avgfloat;
-
 } backend_lookup_state;
 
 /* vorbis_info contains all the setup information specific to the
@@ -123,26 +110,7 @@
 
   vorbis_info_psy        *psy_param[64]; /* encode only */
   vorbis_info_psy_global *psy_g_param;
-
-  /* detailed bitrate management setup */
-  double bitrate_absolute_min_short;
-  double bitrate_absolute_min_long;
-  double bitrate_absolute_max_short;
-  double bitrate_absolute_max_long;
-
-  double bitrate_queue_time;
-  double bitrate_queue_hardmin;
-  double bitrate_queue_hardmax;
-  double bitrate_queue_avgmin;
-  double bitrate_queue_avgmax;
-
-  double bitrate_avgfloat_initial; /* set by mode */
-  double bitrate_avgfloat_minimum; /* set by mode */
-  double bitrate_avgfloat_downslew_max;
-  double bitrate_avgfloat_upslew_max;
-  double bitrate_avgfloat_downhyst;
-  double bitrate_avgfloat_uphyst;
-
+  bitrate_manager_info   *bi;
 
   int    passlimit[32];     /* iteration limit per couple/quant pass */
   int    coupling_passes;

1.24.2.4  +3 -2      vorbis/lib/psy.h

Index: psy.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/psy.h,v
retrieving revision 1.24.2.3
retrieving revision 1.24.2.4
diff -u -r1.24.2.3 -r1.24.2.4
--- psy.h	2001/10/20 01:03:59	1.24.2.3
+++ psy.h	2001/11/16 08:17:07	1.24.2.4
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: random psychoacoustics (not including preecho)
- last mod: $Id: psy.h,v 1.24.2.3 2001/10/20 01:03:59 xiphmont Exp $
+ last mod: $Id: psy.h,v 1.24.2.4 2001/11/16 08:17:07 xiphmont Exp $
 
  ********************************************************************/
 
@@ -159,7 +159,8 @@
                                float *mask, 
                                float global_specmax,
                                float local_specmax,
-			       int lastsize);
+			       int lastsize,
+			       float bitrate_noise_offset);
 
 extern void _vp_quantize_couple(vorbis_look_psy *p,
                          vorbis_info_mapping0 *vi,

No                   revision

No                   revision

1.1.2.1   +472 -0    vorbis/lib/Attic/bitrate.c

1.1.2.1   +100 -0    vorbis/lib/Attic/bitrate.h

--- >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