[xiph-cvs] cvs commit: Tremor block.c codec_internal.h mapping0.c mdct.c synthesis.c

Monty xiphmont at xiph.org
Wed Oct 16 00:39:56 PDT 2002



xiphmont    02/10/16 03:39:56

  Modified:    .        block.c codec_internal.h mapping0.c mdct.c
                        synthesis.c
  Log:
  mdct comment change (correct the vorbis window function description)
  
  Roll a libvorbis fix into tremor (if audio stream has only one page
  and that page is a short page)
  
  Monty

Revision  Changes    Path
1.3       +53 -29    Tremor/block.c

Index: block.c
===================================================================
RCS file: /usr/local/cvsroot/Tremor/block.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- block.c	3 Sep 2002 03:15:19 -0000	1.2
+++ block.c	16 Oct 2002 07:39:56 -0000	1.3
@@ -146,10 +146,10 @@
 int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
   int i;
   codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
-  backend_lookup_state *b=NULL;
+  private_state *b=NULL;
 
   memset(v,0,sizeof(*v));
-  b=(backend_lookup_state *)(v->backend_state=_ogg_calloc(1,sizeof(*b)));
+  b=(private_state *)(v->backend_state=_ogg_calloc(1,sizeof(*b)));
 
   v->vi=vi;
   b->modebits=ilog(ci->modes);
@@ -197,6 +197,7 @@
   v->pcm_returned=-1;
   v->granulepos=-1;
   v->sequence=-1;
+  ((private_state *)(v->backend_state))->sample_count=-1;
 
   return(0);
 }
@@ -206,7 +207,7 @@
   if(v){
     vorbis_info *vi=v->vi;
     codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL);
-    backend_lookup_state *b=(backend_lookup_state *)v->backend_state;
+    private_state *b=(private_state *)v->backend_state;
 
     if(v->pcm){
       for(i=0;i<vi->channels;i++)
@@ -240,6 +241,7 @@
 int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
   vorbis_info *vi=v->vi;
   codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+  private_state *b=v->backend_state;
   int i,j;
 
   if(v->pcm_current>v->pcm_returned  && v->pcm_returned!=-1)return(OV_EINVAL);
@@ -248,8 +250,11 @@
   v->W=vb->W;
   v->nW=-1;
 
-  if(v->sequence+1 != vb->sequence)v->granulepos=-1; /* out of sequence;
-                                                     lose count */
+  if((v->sequence==-1)||
+     (v->sequence+1 != vb->sequence)){
+    v->granulepos=-1; /* out of sequence; lose count */
+    b->sample_count=-1;
+  }
 
   v->sequence=vb->sequence;
   
@@ -336,7 +341,7 @@
         ci->blocksizes[v->lW]/4+
         ci->blocksizes[v->W]/4;
     }
-
+    
     /* track the frame number... This is for convenience, but also
        making sure our last packet doesn't end with added padding.  If
        the last packet is partial, the number of samples we'll have to
@@ -347,36 +352,55 @@
        we don't have a starting point to judge where the last frame
        is.  For this reason, vorbisfile will always try to make sure
        it reads the last two marked pages in proper sequence */
-
-    if(v->granulepos==-1)
-      if(vb->granulepos==-1){
-	v->granulepos=0;
-      }else{
+    
+    if(b->sample_count==-1){
+      b->sample_count=0;
+    }else{
+      b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
+    }
+    
+    if(v->granulepos==-1){
+      if(vb->granulepos!=-1){ /* only set if we have a position to set to */
+	
         v->granulepos=vb->granulepos;
+	
+	/* is this a short page? */
+	if(b->sample_count>v->granulepos){
+	  /* corner case; if this is both the first and last audio page,
+	     then spec says the end is cut, not beginning */
+	  if(vb->eofflag){
+	    /* trim the end */
+	    /* no preceeding granulepos; assume we started at zero (we'd
+	       have to in a short single-page stream) */
+	    /* granulepos could be -1 due to a seek, but that would result
+	       in a long coun`t, not short count */
+	    
+	    v->pcm_current-=(b->sample_count-v->granulepos);
+	  }else{
+	    /* trim the beginning */
+	    v->pcm_returned+=(b->sample_count-v->granulepos);
+	    if(v->pcm_returned>v->pcm_current)
+	      v->pcm_returned=v->pcm_current;
+	  }
+	  
+	}
+	
       }
-    else{
+    }else{
       v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
       if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
-
+	
         if(v->granulepos>vb->granulepos){
           long extra=v->granulepos-vb->granulepos;
-
-	  if(vb->eofflag){
-	    /* partial last frame.  Strip the extra samples off */
-	    v->pcm_current-=extra;
-	  }else if(vb->sequence == 1){
-	    /* ^^^ argh, this can be 1 from seeking! */
-
-
-	    /* partial first frame.  Discard extra leading samples */
-	    v->pcm_returned+=extra;
-	    if(v->pcm_returned>v->pcm_current)
-	      v->pcm_returned=v->pcm_current;
-	    
-	  }
           
-	}/* else{ Shouldn't happen *unless* the bitstream is out of
-	    spec.  Either way, believe the bitstream } */
+	  if(extra)
+	    if(vb->eofflag){
+	      /* partial last frame.  Strip the extra samples off */
+	      v->pcm_current-=extra;
+	    } /* else {Shouldn't happen *unless* the bitstream is out of
+		 spec.  Either way, believe the bitstream } */
+	} /* else {Shouldn't happen *unless* the bitstream is out of
+	     spec.  Either way, believe the bitstream } */
         v->granulepos=vb->granulepos;
       }
     }

<p><p>1.3       +4 -2      Tremor/codec_internal.h

Index: codec_internal.h
===================================================================
RCS file: /usr/local/cvsroot/Tremor/codec_internal.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- codec_internal.h	3 Sep 2002 03:15:19 -0000	1.2
+++ codec_internal.h	16 Oct 2002 07:39:56 -0000	1.3
@@ -37,7 +37,7 @@
 typedef void vorbis_info_residue;
 typedef void vorbis_info_mapping;
 
-typedef struct backend_lookup_state {
+typedef struct private_state {
   /* local lookup storage */
   ogg_int32_t               *window[2];
 
@@ -45,7 +45,9 @@
   int                     modebits;
   vorbis_look_mapping   **mode;
 
-} backend_lookup_state;
+  ogg_int64_t sample_count;
+
+} private_state;
 
 /* codec_setup_info contains all the setup information specific to the
    specific compression/decompression mode in progress (eg,

<p><p>1.3       +1 -1      Tremor/mapping0.c

Index: mapping0.c
===================================================================
RCS file: /usr/local/cvsroot/Tremor/mapping0.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- mapping0.c	3 Sep 2002 03:15:19 -0000	1.2
+++ mapping0.c	16 Oct 2002 07:39:56 -0000	1.3
@@ -181,7 +181,7 @@
   vorbis_dsp_state     *vd=vb->vd;
   vorbis_info          *vi=vd->vi;
   codec_setup_info     *ci=(codec_setup_info *)vi->codec_setup;
-  backend_lookup_state *b=(backend_lookup_state *)vd->backend_state;
+  private_state        *b=(private_state *)vd->backend_state;
   vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l;
   vorbis_info_mapping0 *info=look->map;
 

<p><p>1.6       +2 -2      Tremor/mdct.c

Index: mdct.c
===================================================================
RCS file: /usr/local/cvsroot/Tremor/mdct.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- mdct.c	20 Sep 2002 00:10:31 -0000	1.5
+++ mdct.c	16 Oct 2002 07:39:56 -0000	1.6
@@ -13,7 +13,7 @@
 
  function: normalized modified discrete cosine transform
            power of two length transform only [64 <= n ]
- last mod: $Id: mdct.c,v 1.5 2002/09/20 00:10:31 xiphmont Exp $
+ last mod: $Id: mdct.c,v 1.6 2002/10/16 07:39:56 xiphmont Exp $
 
  Original algorithm adapted long ago from _The use of multirate filter
  banks for coding of high quality digital audio_, by T. Sporer,
@@ -27,7 +27,7 @@
 
  This module DOES NOT INCLUDE code to generate/apply the window
  function.  Everybody has their own weird favorite including me... I
- happen to like the properties of y=sin(2PI*sin^2(x)), but others may
+ happen to like the properties of y=sin(.5PI*sin^2(x)), but others may
  vehemently disagree.
 
  ********************************************************************/

<p><p>1.3       +2 -2      Tremor/synthesis.c

Index: synthesis.c
===================================================================
RCS file: /usr/local/cvsroot/Tremor/synthesis.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- synthesis.c	3 Sep 2002 03:15:19 -0000	1.2
+++ synthesis.c	16 Oct 2002 07:39:56 -0000	1.3
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: single-block PCM synthesis
- last mod: $Id: synthesis.c,v 1.2 2002/09/03 03:15:19 xiphmont Exp $
+ last mod: $Id: synthesis.c,v 1.3 2002/10/16 07:39:56 xiphmont Exp $
 
  ********************************************************************/
 
@@ -26,7 +26,7 @@
 
 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
   vorbis_dsp_state     *vd=vb->vd;
-  backend_lookup_state *b=(backend_lookup_state *)vd->backend_state;
+  private_state        *b=(private_state *)vd->backend_state;
   vorbis_info          *vi=vd->vi;
   codec_setup_info     *ci=(codec_setup_info *)vi->codec_setup;
   oggpack_buffer       *opb=&vb->opb;

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