Some cleanup of ov_crosslap function
authorMonty <xiphmont@xiph.org>
Sun, 2 Mar 2003 21:32:00 +0000 (21:32 +0000)
committerMonty <xiphmont@xiph.org>
Sun, 2 Mar 2003 21:32:00 +0000 (21:32 +0000)
svn path=/trunk/vorbis/; revision=4393

lib/block.c
lib/vorbisfile.c

index dfa7453..e239e2d 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.69 2003/03/02 11:45:17 xiphmont Exp $
+ last mod: $Id: block.c,v 1.70 2003/03/02 21:32:00 xiphmont Exp $
 
  Handle windowing, overlap-add, etc of the PCM vectors.  This is made
  more amusing by Vorbis' current two allowed block sizes.
@@ -938,19 +938,8 @@ int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
 
 }
 
-void vorbis_splice(float *d,float *s,
-                  vorbis_dsp_state *v,int W){
-  
-  vorbis_info *vi=v->vi;
-  codec_setup_info *ci=vi->codec_setup;
+float *vorbis_window(vorbis_dsp_state *v,int W){
   private_state *b=v->backend_state;
-  int n=ci->blocksizes[W]/2;
-
-  float *wd=b->window[W];
-  float *ws=b->window[W]+n;
-  int i;
-
-  for(i=0;i<n;i++)
-    d[i]=d[i]*(*wd++) + s[i]*(*--ws);
+  return b->window[W];
 }
        
index 808a850..846c4d4 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.c,v 1.65 2003/03/02 11:45:17 xiphmont Exp $
+ last mod: $Id: vorbisfile.c,v 1.66 2003/03/02 21:32:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -1623,8 +1623,24 @@ long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
   }
 }
 
-extern void vorbis_splice(float *d,float *s,
-                         vorbis_dsp_state *v,int W);
+extern float *vorbis_window(vorbis_dsp_state *v,int W);
+
+static void _vorbis_splice(float *d,float *s,
+                         vorbis_dsp_state *v,int W){
+  
+  vorbis_info *vi=v->vi;
+  int n=vorbis_info_blocksize(vi,0)/2;
+  float *w=vorbis_window(v,W);
+  int i;
+
+  for(i=0;i<n;i++){
+    float wd=w[i]*w[i];
+    float ws=1.-wd;
+    d[i]=d[i]*wd + s[i]*ws;
+  }
+}
+       
+
        
 /* this sets up crosslapping of a sample by using trailing data from
    sample 1 and lapping it into the windowing buffer of the second */
@@ -1720,26 +1736,20 @@ int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
       memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
     lapcount+=samples;
 
-    if(lapcount<lapsize){
-      fprintf(stderr,"GAR undersized lapping.\n");
-      exit(1);
-    }
+    if(lapcount<lapsize)return OV_EFAULT;
   }
 
   /* have a lapping buffer from vf1; now to splice it into the lapping
      buffer of vf2 */
 
   /* consolidate and expose the buffer. */
-  if(vorbis_synthesis_lapout(vd2,&pcm)<lapsize){
-    fprintf(stderr,"vf2 undersized lapping.\n");
-    exit(1);
-  }
+  if(vorbis_synthesis_lapout(vd2,&pcm)<lapsize)return OV_EFAULT;
 
   /* splice */
   for(j=0;j<vi1->channels;j++){
     float *s=lappcm[j];
     float *d=pcm[j];
-    vorbis_splice(d,s,winstate,0);
+    _vorbis_splice(d,s,winstate,0);
   }
 
   /* done */