[xiph-cvs] cvs commit: vorbis/lib block.c codec_internal.h mapping0.c mdct.h window.c window.h

Monty xiphmont at xiph.org
Tue Jan 22 03:59:02 PST 2002



xiphmont    02/01/22 03:59:01

  Modified:    lib      block.c codec_internal.h mapping0.c mdct.h window.c
                        window.h
  Log:
  add window function memory reduction

Revision  Changes    Path
1.58      +9 -35     vorbis/lib/block.c

Index: block.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/block.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- block.c	2002/01/22 08:06:06	1.57
+++ block.c	2002/01/22 11:59:00	1.58
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.57 2002/01/22 08:06:06 xiphmont Exp $
+ last mod: $Id: block.c,v 1.58 2002/01/22 11:59:00 xiphmont Exp $
 
  Handle windowing, overlap-add, etc of the PCM vectors.  This is made
  more amusing by Vorbis' current two allowed block sizes.
@@ -190,27 +190,9 @@
   mdct_init(b->transform[0][0],ci->blocksizes[0]);
   mdct_init(b->transform[1][0],ci->blocksizes[1]);
 
-  b->window[0][0][0]=_ogg_calloc(VI_WINDOWB,sizeof(*b->window[0][0][0]));
-  b->window[0][0][1]=b->window[0][0][0];
-  b->window[0][1][0]=b->window[0][0][0];
-  b->window[0][1][1]=b->window[0][0][0];
-  b->window[1][0][0]=_ogg_calloc(VI_WINDOWB,sizeof(*b->window[1][0][0]));
-  b->window[1][0][1]=_ogg_calloc(VI_WINDOWB,sizeof(*b->window[1][0][1]));
-  b->window[1][1][0]=_ogg_calloc(VI_WINDOWB,sizeof(*b->window[1][1][0]));
-  b->window[1][1][1]=_ogg_calloc(VI_WINDOWB,sizeof(*b->window[1][1][1]));
-
-  for(i=0;i<VI_WINDOWB;i++){
-    b->window[0][0][0][i]=
-      _vorbis_window(i,ci->blocksizes[0],ci->blocksizes[0]/2,ci->blocksizes[0]/2);
-    b->window[1][0][0][i]=
-      _vorbis_window(i,ci->blocksizes[1],ci->blocksizes[0]/2,ci->blocksizes[0]/2);
-    b->window[1][0][1][i]=
-      _vorbis_window(i,ci->blocksizes[1],ci->blocksizes[0]/2,ci->blocksizes[1]/2);
-    b->window[1][1][0][i]=
-      _vorbis_window(i,ci->blocksizes[1],ci->blocksizes[1]/2,ci->blocksizes[0]/2);
-    b->window[1][1][1][i]=
-      _vorbis_window(i,ci->blocksizes[1],ci->blocksizes[1]/2,ci->blocksizes[1]/2);
-  }
+  /* Vorbis I uses only window type 0 */
+  b->window[0]=_vorbis_window(0,ci->blocksizes[0]/2);
+  b->window[1]=_vorbis_window(0,ci->blocksizes[1]/2);
 
   if(encp){ /* encode/decode differ here */
     /* finish the codebooks */
@@ -284,26 +266,18 @@
 }
 
 void vorbis_dsp_clear(vorbis_dsp_state *v){
-  int i,j,k;
+  int i;
   if(v){
     vorbis_info *vi=v->vi;
     codec_setup_info *ci=(vi?vi->codec_setup:NULL);
     backend_lookup_state *b=v->backend_state;
 
     if(b){
-      if(b->window[0][0][0]){
-	for(i=0;i<VI_WINDOWB;i++)
-	  if(b->window[0][0][0][i])_ogg_free(b->window[0][0][0][i]);
-	_ogg_free(b->window[0][0][0]);
+      if(b->window[0])
+	_ogg_free(b->window[0]);
+      if(b->window[1])
+	_ogg_free(b->window[1]);
         
-	for(j=0;j<2;j++)
-	  for(k=0;k<2;k++){
-	    for(i=0;i<VI_WINDOWB;i++)
-	      if(b->window[1][j][k][i])_ogg_free(b->window[1][j][k][i]);
-	    _ogg_free(b->window[1][j][k]);
-	  }
-      }
-
       if(b->ve){
         _ve_envelope_clear(b->ve);
         _ogg_free(b->ve);

<p><p>1.14      +2 -2      vorbis/lib/codec_internal.h

Index: codec_internal.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/codec_internal.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- codec_internal.h	2002/01/22 08:06:06	1.13
+++ codec_internal.h	2002/01/22 11:59:00	1.14
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: libvorbis codec headers
- last mod: $Id: codec_internal.h,v 1.13 2002/01/22 08:06:06 xiphmont Exp $
+ last mod: $Id: codec_internal.h,v 1.14 2002/01/22 11:59:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -59,7 +59,7 @@
 typedef struct backend_lookup_state {
   /* local lookup storage */
   envelope_lookup        *ve; /* envelope lookup */    
-  float                 **window[2][2][2]; /* block, leadin, leadout, type */
+  float                  *window[2];
   vorbis_look_transform **transform[2];    /* block, type */
   vorbis_look_psy_global *psy_g_look;
 

<p><p>1.44      +6 -8      vorbis/lib/mapping0.c

Index: mapping0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/mapping0.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- mapping0.c	2001/12/20 01:00:27	1.43
+++ mapping0.c	2002/01/22 11:59:00	1.44
@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: channel mapping 0 implementation
- last mod: $Id: mapping0.c,v 1.43 2001/12/20 01:00:27 segher Exp $
+ last mod: $Id: mapping0.c,v 1.44 2002/01/22 11:59:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -23,6 +23,7 @@
 #include "vorbis/codec.h"
 #include "codec_internal.h"
 #include "codebook.h"
+#include "window.h"
 #include "registry.h"
 #include "psy.h"
 #include "misc.h"
@@ -295,7 +296,6 @@
   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];
   int   *nonzero=alloca(sizeof(*nonzero)*vi->channels);
 
   float *work=_vorbis_block_alloc(vb,n*sizeof(*work));
@@ -334,8 +334,8 @@
     _analysis_output("pcm",seq+i,pcm,n,0,0);
 
     /* window the PCM data */
-    for(j=0;j<n;j++)
-      fft[j]=pcm[j]*=window[j];
+    _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);*/
 
@@ -579,7 +579,6 @@
   int                   i,j;
   long                  n=vb->pcmend=ci->blocksizes[vb->W];
 
-  float *window=b->window[vb->W][vb->lW][vb->nW][mode->windowtype];
   float **pcmbundle=alloca(sizeof(*pcmbundle)*vi->channels);
   int    *zerobundle=alloca(sizeof(*zerobundle)*vi->channels);
 
@@ -676,8 +675,7 @@
   for(i=0;i<vi->channels;i++){
     float *pcm=vb->pcm[i];
     if(nonzero[i])
-      for(j=0;j<n;j++)
-	pcm[j]*=window[j];
+      _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
     else
       for(j=0;j<n;j++)
         pcm[j]=0.f;

<p><p>1.20      +6 -2      vorbis/lib/mdct.h

Index: mdct.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/mdct.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- mdct.h	2001/12/20 01:00:29	1.19
+++ mdct.h	2002/01/22 11:59:00	1.20
@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: modified discrete cosine transform prototypes
- last mod: $Id: mdct.h,v 1.19 2001/12/20 01:00:29 segher Exp $
+ last mod: $Id: mdct.h,v 1.20 2002/01/22 11:59:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -19,6 +19,10 @@
 #define _OGG_mdct_H_
 
 #include "vorbis/codec.h"
+
+
+
+
 
 /*#define MDCT_INTEGERIZED  <- be warned there could be some hurt left here*/
 #ifdef MDCT_INTEGERIZED

<p><p>1.16      +33 -20    vorbis/lib/window.c

Index: window.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/window.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- window.c	2001/12/20 01:00:30	1.15
+++ window.c	2002/01/22 11:59:00	1.16
@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: window functions
- last mod: $Id: window.c,v 1.15 2001/12/20 01:00:30 segher Exp $
+ last mod: $Id: window.c,v 1.16 2002/01/22 11:59:00 xiphmont Exp $
 
  ********************************************************************/
 
@@ -20,16 +20,14 @@
 #include "os.h"
 #include "misc.h"
 
-float *_vorbis_window(int type, int window,int left,int right){
-  float *ret=_ogg_calloc(window,sizeof(*ret));
+float *_vorbis_window(int type, int left){
+  float *ret=_ogg_calloc(left,sizeof(*ret));
+  int i;
 
   switch(type){
   case 0:
     /* The 'vorbis window' (window 0) is sin(sin(x)*sin(x)*2pi) */
     {
-      int leftbegin=window/4-left/2;
-      int rightbegin=window-window/4-right/2;
-      int i;
     
       for(i=0;i<left;i++){
         float x=(i+.5f)/left*M_PI/2.;
@@ -37,20 +35,8 @@
         x*=x;
         x*=M_PI/2.f;
         x=sin(x);
-	ret[i+leftbegin]=x;
+	ret[i]=x;
       }
-      
-      for(i=leftbegin+left;i<rightbegin;i++)
-	ret[i]=1.f;
-      
-      for(i=0;i<right;i++){
-	float x=(right-i-.5f)/right*M_PI/2.;
-	x=sin(x);
-	x*=x;
-	x*=M_PI/2.f;
-	x=sin(x);
-	ret[i+rightbegin]=x;
-      }
     }
     break;
   default:
@@ -60,3 +46,30 @@
   return(ret);
 }
 
+void _vorbis_apply_window(float *d,float *window[2],long *blocksizes,
+			  int lW,int W,int nW){
+
+  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;
+}

<p><p>1.10      +6 -3      vorbis/lib/window.h

Index: window.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/window.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- window.h	2001/12/20 01:00:30	1.9
+++ window.h	2002/01/22 11:59:00	1.10
@@ -5,19 +5,22 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: window functions
- last mod: $Id: window.h,v 1.9 2001/12/20 01:00:30 segher Exp $
+ last mod: $Id: window.h,v 1.10 2002/01/22 11:59:00 xiphmont Exp $
 
  ********************************************************************/
 
 #ifndef _V_WINDOW_
 #define _V_WINDOW_
 
-extern float *_vorbis_window(int type,int window,int left,int right);
+extern float *_vorbis_window(int type,int left);
+extern void _vorbis_apply_window(float *d,float *window[2],long *blocksizes,
+				 int lW,int W,int nW);
+
 
 #endif

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