[xiph-cvs] cvs commit: vorbis/vq 44c0_s4.vqs 44c1_s3.vqs 44c2_s2.vqs 44c3_s2.vqs 44c4_s1.vqs bookutil.c distribution.c latticehint.c residuesplit.c lsp12_0.vql lsp12_1.vql lsp30_0.vql lsp30_1.vql lsp9_0.vql lsp9_1.vql res_128c.vqs res_128k.vqs res_160c.vqs res_160k.vqs res_192c.vqs res_192k.vqs res_256k.vqs res_350c.vqs res_350k.vqs res_44_A.vqs res_44_B.vqs res_44_Y.vqs res_44_Z.vqs res_44c_A.vqs res_44c_B.vqs res_44c_C.vqs res_44c_E.vqs res_44c_X.vqs res_44c_Y.vqs res_44c_Z.vqs res_64c.vqs res_96Zc.vqs res_96c.vqs res_96k.vqs

Monty xiphmont at xiph.org
Wed Dec 12 01:46:00 PST 2001



xiphmont    01/12/12 01:45:58

  Modified:    examples chaining_example.c encoder_example.c
               include/vorbis codec.h vorbisfile.h
               lib      Makefile.am analysis.c backends.h block.c
                        codebook.c codec_internal.h envelope.c envelope.h
                        floor0.c floor1.c info.c lpc.c mapping0.c masking.h
                        psy.c psy.h registry.c res0.c sharedbook.c
                        vorbisenc.c vorbisfile.c
               lib/books Makefile.am
               lib/modes Makefile.am
               vq       bookutil.c distribution.c latticehint.c
                        residuesplit.c
  Added:       lib      bitrate.c bitrate.h registry-api.h
               lib/books/coupled _44c0_long.vqh _44c0_s0_p1_0.vqh
                        _44c0_s0_p2_0.vqh _44c0_s0_p3_0.vqh
                        _44c0_s0_p4_0.vqh _44c0_s0_p4_1.vqh
                        _44c0_s1_p5_0.vqh _44c0_s1_p6_0.vqh
                        _44c0_s2_p6_0.vqh _44c0_s2_p7_0.vqh
                        _44c0_s4_p7_0.vqh _44c0_s4_p7_1.vqh
                        _44c0_s4_p7_2.vqh _44c0_short.vqh _44c1_long.vqh
                        _44c1_s0_p1_0.vqh _44c1_s0_p2_0.vqh
                        _44c1_s0_p3_0.vqh _44c1_s0_p4_0.vqh
                        _44c1_s0_p4_1.vqh _44c1_s1_p5_0.vqh
                        _44c1_s2_p6_0.vqh _44c1_s3_p7_0.vqh
                        _44c1_s3_p7_1.vqh _44c1_s3_p7_2.vqh _44c1_short.vqh
                        _44c2_long.vqh _44c2_s0_p1_0.vqh _44c2_s0_p2_0.vqh
                        _44c2_s0_p3_0.vqh _44c2_s0_p4_0.vqh
                        _44c2_s0_p4_1.vqh _44c2_s1_p5_0.vqh
                        _44c2_s2_p6_0.vqh _44c2_s2_p7_0.vqh
                        _44c2_s2_p7_1.vqh _44c2_s2_p7_2.vqh _44c2_short.vqh
                        _44c3_long.vqh _44c3_s0_p1_0.vqh _44c3_s0_p2_0.vqh
                        _44c3_s0_p3_0.vqh _44c3_s0_p4_0.vqh
                        _44c3_s0_p4_1.vqh _44c3_s1_p5_0.vqh
                        _44c3_s2_p6_0.vqh _44c3_s2_p7_0.vqh
                        _44c3_s2_p7_1.vqh _44c3_s2_p7_2.vqh _44c3_short.vqh
                        _44c4_long.vqh _44c4_s0_p1_0.vqh _44c4_s0_p3_0.vqh
                        _44c4_s0_p5_0.vqh _44c4_s1_p2_0.vqh
                        _44c4_s1_p4_0.vqh _44c4_s1_p6_0.vqh
                        _44c4_s1_p7_0.vqh _44c4_s1_p7_1.vqh
                        _44c4_s1_p8_0.vqh _44c4_s1_p8_1.vqh
                        _44c4_s1_p9_0.vqh _44c4_s1_p9_1.vqh
                        _44c4_s1_p9_2.vqh _44c4_short.vqh
               lib/books/floor line_1024x31_0sub0.vqh
                        line_1024x31_0sub1.vqh line_1024x31_1sub0.vqh
                        line_1024x31_1sub1.vqh line_1024x31_2sub1.vqh
                        line_1024x31_2sub2.vqh line_1024x31_2sub3.vqh
                        line_1024x31_3sub1.vqh line_1024x31_3sub2.vqh
                        line_1024x31_3sub3.vqh line_1024x31_class0.vqh
                        line_1024x31_class1.vqh line_1024x31_class2.vqh
                        line_1024x31_class3.vqh line_128x19_0sub0.vqh
                        line_128x19_1sub1.vqh line_128x19_1sub2.vqh
                        line_128x19_1sub3.vqh line_128x19_2sub1.vqh
                        line_128x19_2sub2.vqh line_128x19_2sub3.vqh
                        line_128x19_class1.vqh line_128x19_class2.vqh
                        line_128x7_0sub0.vqh line_128x7_1sub1.vqh
                        line_128x7_1sub2.vqh line_128x7_1sub3.vqh
                        line_128x7_2sub1.vqh line_128x7_2sub2.vqh
                        line_128x7_2sub3.vqh line_128x7_class1.vqh
                        line_128x7_class2.vqh line_128x9_0sub0.vqh
                        line_128x9_1sub1.vqh line_128x9_1sub2.vqh
                        line_128x9_1sub3.vqh line_128x9_2sub1.vqh
                        line_128x9_2sub2.vqh line_128x9_2sub3.vqh
                        line_128x9_class1.vqh line_128x9_class2.vqh
               lib/modes floor_44.h psych_44.h residue_44.h
               vq       44c0_s4.vqs 44c1_s3.vqs 44c2_s2.vqs 44c3_s2.vqs
                        44c4_s1.vqs
  Removed:     lib      bitbuffer.c bitbuffer.h
               lib/books line_1024x31_0sub0.vqh line_1024x31_0sub1.vqh
                        line_1024x31_1sub0.vqh line_1024x31_1sub1.vqh
                        line_1024x31_2sub1.vqh line_1024x31_2sub2.vqh
                        line_1024x31_2sub3.vqh line_1024x31_3sub1.vqh
                        line_1024x31_3sub2.vqh line_1024x31_3sub3.vqh
                        line_1024x31_class0.vqh line_1024x31_class1.vqh
                        line_1024x31_class2.vqh line_1024x31_class3.vqh
                        line_128x19_0sub0.vqh line_128x19_1sub1.vqh
                        line_128x19_1sub2.vqh line_128x19_1sub3.vqh
                        line_128x19_2sub1.vqh line_128x19_2sub2.vqh
                        line_128x19_2sub3.vqh line_128x19_class1.vqh
                        line_128x19_class2.vqh line_128x7_0sub0.vqh
                        line_128x7_1sub1.vqh line_128x7_1sub2.vqh
                        line_128x7_1sub3.vqh line_128x7_2sub1.vqh
                        line_128x7_2sub2.vqh line_128x7_2sub3.vqh
                        line_128x7_class1.vqh line_128x7_class2.vqh
                        lsp12_0.vqh lsp12_1.vqh lsp30_0.vqh lsp30_1.vqh
                        lsp9_0.vqh lsp9_1.vqh res_22c_Z_1024aux.vqh
                        res_22c_Z_128aux.vqh res_32c_Z_1024aux.vqh
                        res_32c_Z_128aux.vqh res_44_A_1024aux.vqh
                        res_44_A_128aux.vqh res_44_B_1024aux.vqh
                        res_44_B_128aux.vqh res_44_Y_1024aux.vqh
                        res_44_Y_128aux.vqh res_44_Z_1024aux.vqh
                        res_44_Z_128aux.vqh res_44c_A_1024aux.vqh
                        res_44c_A_128aux.vqh res_44c_B_1024aux.vqh
                        res_44c_B_128aux.vqh res_44c_C_1024aux.vqh
                        res_44c_C_128aux.vqh res_44c_E_1024aux.vqh
                        res_44c_E_128aux.vqh res_44c_X_1024aux.vqh
                        res_44c_X_128aux.vqh res_44c_Y_1024aux.vqh
                        res_44c_Y_128aux.vqh res_44c_Z_1024aux.vqh
                        res_44c_Z_128aux.vqh res_Ac_1.vqh res_Ac_1024_1.vqh
                        res_Ac_1024_2.vqh res_Ac_1024_3.vqh
                        res_Ac_1024_4.vqh res_Ac_1024_5.vqh
                        res_Ac_1024_6.vqh res_Ac_1024_7.vqh
                        res_Ac_1024_7a.vqh res_Ac_1024_8.vqh
                        res_Ac_1024_8a.vqh res_Ac_1024_9.vqh
                        res_Ac_1024_9a.vqh res_Ac_1024_9b.vqh res_Ac_2.vqh
                        res_Ac_3.vqh res_Ac_4.vqh res_Ac_5.vqh res_Ac_6.vqh
                        res_Ac_7.vqh res_Ac_7a.vqh res_Ac_8.vqh
                        res_Ac_8a.vqh res_Ac_9.vqh res_Ac_9a.vqh
                        res_Ac_9b.vqh res_B_1.vqh res_B_2.vqh res_B_3.vqh
                        res_B_4.vqh res_B_5.vqh res_B_5a.vqh res_B_6.vqh
                        res_B_6a.vqh res_B_6b.vqh res_Bc_1.vqh res_Bc_2.vqh
                        res_Bc_3.vqh res_Bc_4.vqh res_Bc_5.vqh res_Bc_6.vqh
                        res_Bc_7.vqh res_Bc_7a.vqh res_Bc_8.vqh
                        res_Bc_8a.vqh res_Bc_9.vqh res_Bc_9a.vqh
                        res_Bc_9b.vqh res_Cc_1.vqh res_Cc_2.vqh
                        res_Cc_3.vqh res_Cc_4.vqh res_Cc_5.vqh res_Cc_6.vqh
                        res_Cc_7.vqh res_Cc_8.vqh res_Cc_8a.vqh
                        res_Cc_9.vqh res_Cc_9a.vqh res_Cc_9b.vqh
                        res_Ec_1.vqh res_Ec_2.vqh res_Ec_3.vqh res_Ec_4.vqh
                        res_Ec_5.vqh res_Ec_6.vqh res_Ec_7.vqh res_Ec_8.vqh
                        res_Ec_8a.vqh res_Ec_9.vqh res_Ec_9a.vqh
                        res_Ec_9b.vqh res_Xc_1.vqh res_Xc_2.vqh
                        res_Xc_3.vqh res_Xc_4.vqh res_Xc_5.vqh res_Xc_6.vqh
                        res_Xc_7.vqh res_Xc_8.vqh res_Xc_9.vqh
                        res_Xc_9a.vqh res_Xc_9b.vqh res_Z_1.vqh res_Z_2.vqh
                        res_Z_3.vqh res_Z_4.vqh res_Z_5.vqh res_Z_6.vqh
                        res_Z_6a.vqh res_Z_6b.vqh res_Zc_1.vqh
                        res_Zc_1024aux.vqh res_Zc_128aux.vqh res_Zc_2.vqh
                        res_Zc_3.vqh res_Zc_4.vqh res_Zc_5.vqh res_Zc_6.vqh
                        res_Zc_7.vqh res_Zc_8.vqh res_Zc_9.vqh
                        res_Zc_9a.vqh res_Zc_9b.vqh temp26040.vqh
               lib/modes maskadj_A.h maskadj_X.h maskadj_Z.h mode_22c_Z.h
                        mode_32c_Z.h mode_44_A.h mode_44_B.h mode_44_C.h
                        mode_44_X.h mode_44_Y.h mode_44_Z.h mode_44c_A.h
                        mode_44c_B.h mode_44c_C.h mode_44c_D.h mode_44c_E.h
                        mode_44c_X.h mode_44c_Y.h mode_44c_Z.h modes.h
               vq       lsp12_0.vql lsp12_1.vql lsp30_0.vql lsp30_1.vql
                        lsp9_0.vql lsp9_1.vql res_128c.vqs res_128k.vqs
                        res_160c.vqs res_160k.vqs res_192c.vqs res_192k.vqs
                        res_256k.vqs res_350c.vqs res_350k.vqs res_44_A.vqs
                        res_44_B.vqs res_44_Y.vqs res_44_Z.vqs
                        res_44c_A.vqs res_44c_B.vqs res_44c_C.vqs
                        res_44c_E.vqs res_44c_X.vqs res_44c_Y.vqs
                        res_44c_Z.vqs res_64c.vqs res_96Zc.vqs res_96c.vqs
                        res_96k.vqs
  Log:
  Initial branch merge toward rc3
  monty_branch_20011009 is officially dead

Revision  Changes    Path
1.14      +4 -3      vorbis/examples/chaining_example.c

Index: chaining_example.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/examples/chaining_example.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- chaining_example.c	2001/09/17 01:06:18	1.13
+++ chaining_example.c	2001/12/12 09:45:22	1.14
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: illustrate simple use of chained bitstream and vorbisfile.a
- last mod: $Id: chaining_example.c,v 1.13 2001/09/17 01:06:18 cwolf Exp $
+ last mod: $Id: chaining_example.c,v 1.14 2001/12/12 09:45:22 xiphmont Exp $
 
  ********************************************************************/
 
@@ -60,10 +60,11 @@
            ov_serialnumber(&ov,i));
     printf("\t\theader length: %ld bytes\n",(long)
            (ov.dataoffsets[i]-ov.offsets[i]));
-    printf("\t\tcompressed length: %ld bytes ",(long)(ov_raw_total(&ov,i)));
-    printf(" play time: %lds\n",(long)ov_time_total(&ov,i));
+    printf("\t\tcompressed length: %ld bytes\n",(long)(ov_raw_total(&ov,i)));
+    printf("\t\tplay time: %lds\n",(long)ov_time_total(&ov,i));
   }
 
   ov_clear(&ov);
   return 0;
 }
+

1.28      +24 -18    vorbis/examples/encoder_example.c

Index: encoder_example.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/examples/encoder_example.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- encoder_example.c	2001/09/19 01:17:00	1.27
+++ encoder_example.c	2001/12/12 09:45:22	1.28
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: simple example encoder
- last mod: $Id: encoder_example.c,v 1.27 2001/09/19 01:17:00 cwolf Exp $
+ last mod: $Id: encoder_example.c,v 1.28 2001/12/12 09:45:22 xiphmont Exp $
 
  ********************************************************************/
 
@@ -22,6 +22,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <math.h>
 #include <vorbis/vorbisenc.h>
@@ -85,6 +86,7 @@
     {
       founddata = 1;
       fread(readbuffer,1,6,stdin);
+      break;
     }
   }
 
@@ -93,8 +95,9 @@
   /* choose an encoding mode */
   /* (mode 0: 44kHz stereo uncoupled, roughly 128kbps VBR) */
   vorbis_info_init(&vi);
-  vorbis_encode_init(&vi,2,44100, -1, 128000, -1);
 
+  vorbis_encode_init_vbr(&vi,2,44100,.4);
+
   /* add a comment */
   vorbis_comment_init(&vc);
   vorbis_comment_add(&vc,"Track encoded by encoder_example.c");
@@ -173,25 +176,28 @@
        more involved (potentially parallel) processing.  Get a single
        block for encoding now */
     while(vorbis_analysis_blockout(&vd,&vb)==1){
-
-      /* analysis */
-      vorbis_analysis(&vb,&op);
-      
-      /* weld the packet into the bitstream */
-      ogg_stream_packetin(&os,&op);
 
-      /* write out pages (if any) */
-      while(!eos){
-	int result=ogg_stream_pageout(&os,&og);
-	if(result==0)break;
-	fwrite(og.header,1,og.header_len,stdout);
-	fwrite(og.body,1,og.body_len,stdout);
+      /* analysis, assume we want to use bitrate management */
+      vorbis_analysis(&vb,NULL);
+      vorbis_bitrate_addblock(&vb);
 
-	/* this could be set above, but for illustrative purposes, I do
-	   it here (to show that vorbis does know where the stream ends) */
+      while(vorbis_bitrate_flushpacket(&vd,&op)){
         
-	if(ogg_page_eos(&og))eos=1;
-
+	/* weld the packet into the bitstream */
+	ogg_stream_packetin(&os,&op);
+	
+	/* write out pages (if any) */
+	while(!eos){
+	  int result=ogg_stream_pageout(&os,&og);
+	  if(result==0)break;
+	  fwrite(og.header,1,og.header_len,stdout);
+	  fwrite(og.body,1,og.body_len,stdout);
+	  
+	  /* this could be set above, but for illustrative purposes, I do
+	     it here (to show that vorbis does know where the stream ends) */
+	  
+	  if(ogg_page_eos(&og))eos=1;
+	}
       }
     }
   }

1.39      +6 -1      vorbis/include/vorbis/codec.h

Index: codec.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/include/vorbis/codec.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- codec.h	2001/05/27 06:43:59	1.38
+++ codec.h	2001/12/12 09:45:23	1.39
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: libvorbis codec headers
- last mod: $Id: codec.h,v 1.38 2001/05/27 06:43:59 xiphmont Exp $
+ last mod: $Id: codec.h,v 1.39 2001/12/12 09:45:23 xiphmont Exp $
 
  ********************************************************************/
 
@@ -164,6 +164,7 @@
 
 extern void     vorbis_info_init(vorbis_info *vi);
 extern void     vorbis_info_clear(vorbis_info *vi);
+extern int      vorbis_info_blocksize(vorbis_info *vi,int zo);
 extern void     vorbis_comment_init(vorbis_comment *vc);
 extern void     vorbis_comment_add(vorbis_comment *vc, char *comment); 
 extern void     vorbis_comment_add_tag(vorbis_comment *vc, 
@@ -189,6 +190,10 @@
 extern int      vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
 extern int      vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
 extern int      vorbis_analysis(vorbis_block *vb,ogg_packet *op);
+
+extern int      vorbis_bitrate_addblock(vorbis_block *vb);
+extern int      vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
+					   ogg_packet *op);
 
 /* Vorbis PRIMITIVES: synthesis layer *******************************/
 extern int      vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,

1.15      +3 -1      vorbis/include/vorbis/vorbisfile.h

Index: vorbisfile.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/include/vorbis/vorbisfile.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- vorbisfile.h	2001/05/27 06:43:59	1.14
+++ vorbisfile.h	2001/12/12 09:45:23	1.15
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.h,v 1.14 2001/05/27 06:43:59 xiphmont Exp $
+ last mod: $Id: vorbisfile.h,v 1.15 2001/12/12 09:45:23 xiphmont Exp $
 
  ********************************************************************/
 
@@ -117,6 +117,8 @@
 extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
 extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
 
+extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,
+			  int *bitstream);
 extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
                     int bigendianp,int word,int sgned,int *bitstream);
 

1.13      +3 -3      vorbis/lib/Makefile.am

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/Makefile.am,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Makefile.am	2001/05/27 06:43:59	1.12
+++ Makefile.am	2001/12/12 09:45:24	1.13
@@ -12,17 +12,17 @@
                         lpc.c analysis.c synthesis.c psy.c info.c time0.c \
                         floor1.c floor0.c\
                         res0.c mapping0.c registry.c codebook.c sharedbook.c\
-			lookup.c bitbuffer.c\
+			lookup.c bitrate.c\
                         envelope.h lpc.h lsp.h codebook.h misc.h psy.h\
                         masking.h iir.h os.h mdct.h smallft.h\
                         registry.h scales.h window.h lookup.h lookup_data.h\
-			codec_internal.h backends.h bitbuffer.h
+			codec_internal.h backends.h bitrate.h 
 libvorbis_la_LDFLAGS = -version-info @V_LIB_CURRENT@:@V_LIB_REVISION@:@V_LIB_AGE@
 
 libvorbisfile_la_SOURCES = vorbisfile.c
 libvorbisfile_la_LDFLAGS = -version-info @VF_LIB_CURRENT@:@VF_LIB_REVISION@:@VF_LIB_AGE@
 
-libvorbisenc_la_SOURCES = vorbisenc.c
+libvorbisenc_la_SOURCES = vorbisenc.c registry-api.h
 libvorbisenc_la_LDFLAGS = -version-info @VE_LIB_CURRENT@:@VE_LIB_REVISION@:@VE_LIB_AGE@
 
 EXTRA_PROGRAMS = barkmel tone psytune

1.47      +13 -14    vorbis/lib/analysis.c

Index: analysis.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/analysis.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- analysis.c	2001/08/13 01:36:56	1.46
+++ analysis.c	2001/12/12 09:45:24	1.47
@@ -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.47 2001/12/12 09:45:24 xiphmont Exp $
 
  ********************************************************************/
 
@@ -28,7 +28,7 @@
 int analysis_noisy=1;
 
 /* decides between modes, dispatches to the appropriate mapping. */
-int vorbis_analysis(vorbis_block *vb,ogg_packet *op){
+int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
   vorbis_dsp_state     *vd=vb->vd;
   backend_lookup_state *b=vd->backend_state;
   vorbis_info          *vi=vd->vi;
@@ -45,9 +45,9 @@
   oggpack_reset(&vb->opb);
   /* Encode the packet type */
   oggpack_write(&vb->opb,0,1);
-
+  
   /* currently lazy.  Short block dispatches to 0, long to 1. */
-
+  
   if(vb->W &&ci->modes>1)mode=1;
   type=ci->map_type[ci->mode_param[mode]->mapping];
   vb->mode=mode;
@@ -64,16 +64,15 @@
 
   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 */
-  
+
+  if(op){
+    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);
 }
 

1.11      +2 -3      vorbis/lib/backends.h

Index: backends.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/backends.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- backends.h	2001/08/13 01:36:56	1.10
+++ backends.h	2001/12/12 09:45:24	1.11
@@ -12,7 +12,7 @@
 
  function: libvorbis backend and mapping structures; needed for 
            static mode headers
- last mod: $Id: backends.h,v 1.10 2001/08/13 01:36:56 xiphmont Exp $
+ last mod: $Id: backends.h,v 1.11 2001/12/12 09:45:24 xiphmont Exp $
 
  ********************************************************************/
 
@@ -130,7 +130,7 @@
   long **(*class)      (struct vorbis_block *,vorbis_look_residue *,
                         float **,int *,int);
   int  (*forward)      (struct vorbis_block *,vorbis_look_residue *,
-			float **,float **,int *,int,int,long **);
+			float **,float **,int *,int,int,long **,ogg_uint32_t *);
   int  (*inverse)      (struct vorbis_block *,vorbis_look_residue *,
                         float **,int *,int);
 } vorbis_func_residue;
@@ -152,7 +152,6 @@
   float  ampmax[64];       /* book amp threshholds*/
   int    subgrp[64];       /* book heuristic subgroup size */
   int    blimit[64];       /* subgroup position limits */
-  int    passlimit[32];     /* iteration limit per couple/quant pass */
 } vorbis_info_residue0;
 
 /* Mapping backend generic *****************************************/

1.51      +49 -24    vorbis/lib/block.c

Index: block.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/block.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- block.c	2001/10/02 00:14:30	1.50
+++ block.c	2001/12/12 09:45:24	1.51
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.50 2001/10/02 00:14:30 segher Exp $
+ last mod: $Id: block.c,v 1.51 2001/12/12 09:45:24 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;
@@ -94,9 +90,12 @@
   vb->localalloc=0;
   vb->localstore=NULL;
   if(v->analysisp){
+    vorbis_block_internal *vbi=
+      vb->internal=_ogg_calloc(1,sizeof(vorbis_block_internal));
     oggpack_writeinit(&vb->opb);
-    vb->internal=_ogg_calloc(1,sizeof(vorbis_block_internal));
-    ((vorbis_block_internal *)vb->internal)->ampmax=-9999;
+    vbi->ampmax=-9999;
+    vbi->packet_markers=_ogg_malloc(vorbis_bitrate_maxmarkers()*
+			       sizeof(*vbi->packet_markers));
   }
   
   return(0);
@@ -154,8 +153,14 @@
       oggpack_writeclear(&vb->opb);
   _vorbis_block_ripcord(vb);
   if(vb->localstore)_ogg_free(vb->localstore);
-  if(vb->internal)_ogg_free(vb->internal);
 
+  if(vb->internal){
+    vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
+    if(vbi->packet_markers)_ogg_free(vbi->packet_markers);
+
+    _ogg_free(vb->internal);
+  }
+
   memset(vb,0,sizeof(*vb));
   return(0);
 }
@@ -267,6 +272,9 @@
   /* Initialize the envelope state storage */
   b->ve=_ogg_calloc(1,sizeof(*b->ve));
   _ve_envelope_init(b->ve,vi);
+
+  vorbis_bitrate_init(vi,&b->bms);
+
   return(0);
 }
 
@@ -307,7 +315,7 @@
         _ogg_free(b->transform[1]);
       }
       if(b->psy_g_look)_vp_global_free(b->psy_g_look);
-      
+      vorbis_bitrate_clear(&b->bms);
     }
     
     if(v->pcm){
@@ -371,6 +379,7 @@
   return(v->pcmret);
 }
 
+static int seq=0;
 static void _preextrapolate_helper(vorbis_dsp_state *v){
   int i;
   int order=32;
@@ -381,21 +390,30 @@
 
   if(v->pcm_current-v->centerW>order*2){ /* safety */
     for(i=0;i<v->vi->channels;i++){
-      
       /* need to run the extrapolation in reverse! */
       for(j=0;j<v->pcm_current;j++)
         work[j]=v->pcm[i][v->pcm_current-j-1];
       
+      _analysis_output("preextrap",seq,v->pcm[i],v->pcm_current,0,0);
+      _analysis_output("workextrap",seq,work,v->pcm_current,0,0);
+
       /* prime as above */
       vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
+      _analysis_output("lpc",seq,lpc,order,0,0);
       
       /* run the predictor filter */
       vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
                          order,
                          work+v->pcm_current-v->centerW,
                          v->centerW);
+
+      _analysis_output("extrap",seq,work,v->pcm_current,0,0);
+
+
       for(j=0;j<v->pcm_current;j++)
         v->pcm[i][v->pcm_current-j-1]=work[j];
+
+      _analysis_output("postextrap",seq++,v->pcm[i],v->pcm_current,0,0);
     }
   }
 }
@@ -474,8 +492,9 @@
   codec_setup_info *ci=vi->codec_setup;
   backend_lookup_state *b=v->backend_state;
   vorbis_look_psy_global *g=b->psy_g_look;
-  vorbis_info_psy_global *gi=ci->psy_g_param;
+  vorbis_info_psy_global *gi=&ci->psy_g_param;
   long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
+  vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
 
   /* check to see if we're started... */
   if(!v->preextrapolate)return(0);
@@ -488,20 +507,11 @@
      which lets us compute the shape of the current block's window */
   
   if(ci->blocksizes[0]<ci->blocksizes[1]){
-    long largebound;
-    long bp;
-
-    if(v->W)
-      /* min boundary; nW large, next small */
-      largebound=v->centerW+ci->blocksizes[1]*3/4+ci->blocksizes[0]/4;
-    else
-      /* min boundary; nW large, next small */
-      largebound=v->centerW+ci->blocksizes[1]/2+ci->blocksizes[0]/2;
-
-    bp=_ve_envelope_search(v,largebound);
+    long bp=_ve_envelope_search(v);
     if(bp==-1)return(0); /* not enough data currently to search for a
                             full long block */
     v->nW=bp;
+    //v->nW=0;
 
   }else
     v->nW=0;
@@ -519,6 +529,8 @@
                                                the search is not run
                                                if we only use one
                                                block size */
+
+
   }
   
   /* fill in the block.  Note that for a short window, lW and nW are *short*
@@ -534,6 +546,19 @@
     vb->W=v->W;
     vb->nW=0;
   }
+
+  if(v->W){
+    if(!v->lW || !v->nW)
+      vbi->blocktype=BLOCKTYPE_TRANSITION;
+    else
+      vbi->blocktype=BLOCKTYPE_LONG;
+  }else{
+    if(_ve_envelope_mark(v))
+      vbi->blocktype=BLOCKTYPE_IMPULSE;
+    else
+      vbi->blocktype=BLOCKTYPE_PADDING;
+  }
+ 
   vb->vd=v;
   vb->sequence=v->sequence;
   vb->granulepos=v->granulepos;
@@ -721,8 +746,8 @@
       for(;i<sizeW;i++)
         pcm[i]=p[i];
 
-      _analysis_output("lapped",seq,pcm,sizeW,0,0);
-      _analysis_output("buffered",seq++,v->pcm[j],sizeW+beginW,0,0);
+      //_analysis_output("lapped",seq,pcm,sizeW,0,0);
+      //_analysis_output("buffered",seq++,v->pcm[j],sizeW+beginW,0,0);
     
     }
 

1.31      +2 -2      vorbis/lib/codebook.c

Index: codebook.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/codebook.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- codebook.c	2001/10/02 00:14:30	1.30
+++ codebook.c	2001/12/12 09:45:24	1.31
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c,v 1.30 2001/10/02 00:14:30 segher Exp $
+ last mod: $Id: codebook.c,v 1.31 2001/12/12 09:45:24 xiphmont Exp $
 
  ********************************************************************/
 
@@ -418,7 +418,7 @@
 
 long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
                               oggpack_buffer *b,int n){
-  long i,j,k,entry;
+  long i,j,entry;
   int chptr=0;
 
   for(i=offset/ch;i<(offset+n)/ch;){

1.10      +18 -3     vorbis/lib/codec_internal.h

Index: codec_internal.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/codec_internal.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- codec_internal.h	2001/08/13 01:36:56	1.9
+++ codec_internal.h	2001/12/12 09:45:24	1.10
@@ -10,7 +10,7 @@
  ********************************************************************
 
  function: libvorbis codec headers
- last mod: $Id: codec_internal.h,v 1.9 2001/08/13 01:36:56 xiphmont Exp $
+ last mod: $Id: codec_internal.h,v 1.10 2001/12/12 09:45:24 xiphmont Exp $
 
  ********************************************************************/
 
@@ -20,9 +20,17 @@
 #include "envelope.h"
 #include "codebook.h"
 
+#define BLOCKTYPE_IMPULSE    0
+#define BLOCKTYPE_PADDING    1
+#define BLOCKTYPE_TRANSITION 0 
+#define BLOCKTYPE_LONG       1
+
 typedef struct vorbis_block_internal{
   float  **pcmdelay;  /* this is a pointer into local storage */ 
   float  ampmax;
+  int    blocktype;
+
+  ogg_uint32_t *packet_markers;
 } vorbis_block_internal;
 
 typedef void vorbis_look_time;
@@ -45,6 +53,7 @@
 typedef void vorbis_info_mapping;
 
 #include "psy.h"
+#include "bitrate.h"
 
 typedef struct backend_lookup_state {
   /* local lookup storage */
@@ -65,7 +74,9 @@
   unsigned char *header;
   unsigned char *header1;
   unsigned char *header2;
-  
+
+  bitrate_manager_state bms;
+
 } backend_lookup_state;
 
 /* vorbis_info contains all the setup information specific to the
@@ -104,9 +115,13 @@
   int                     residue_type[64];
   vorbis_info_residue    *residue_param[64];
   static_codebook        *book_param[256];
+
   vorbis_info_psy        *psy_param[64]; /* encode only */
-  vorbis_info_psy_global *psy_g_param;
+  vorbis_info_psy_global psy_g_param;
+  bitrate_manager_info   bi;
 
+  int    passlimit[32];     /* iteration limit per couple/quant pass */
+  int    coupling_passes;
 } codec_setup_info;
 
 extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);

1.39      +81 -31    vorbis/lib/envelope.c

Index: envelope.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/envelope.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- envelope.c	2001/10/02 00:14:30	1.38
+++ envelope.c	2001/12/12 09:45:24	1.39
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: PCM data envelope analysis and manipulation
- last mod: $Id: envelope.c,v 1.38 2001/10/02 00:14:30 segher Exp $
+ last mod: $Id: envelope.c,v 1.39 2001/12/12 09:45:24 xiphmont Exp $
 
  Preecho calculation.
 
@@ -82,11 +82,10 @@
 
 void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
   codec_setup_info *ci=vi->codec_setup;
-  vorbis_info_psy_global *gi=ci->psy_g_param;
+  vorbis_info_psy_global *gi=&ci->psy_g_param;
   int ch=vi->channels;
-  int window=gi->envelopesa;
+  int window=e->winlength=ci->blocksizes[0]/2; /* not random */
   int i;
-  e->winlength=window;
   e->minenergy=fromdB(gi->preecho_minenergy);
   e->iir=_ogg_calloc(ch*4,sizeof(*e->iir));
   e->filtered=_ogg_calloc(ch*4,sizeof(*e->filtered));
@@ -148,10 +147,10 @@
   return(B-A);
 }
 
-long _ve_envelope_search(vorbis_dsp_state *v,long searchpoint){
+long _ve_envelope_search(vorbis_dsp_state *v){
   vorbis_info *vi=v->vi;
   codec_setup_info *ci=vi->codec_setup;
-  vorbis_info_psy_global *gi=ci->psy_g_param;
+  vorbis_info_psy_global *gi=&ci->psy_g_param;
   envelope_lookup *ve=((backend_lookup_state *)(v->backend_state))->ve;
   long i,j,k;
 
@@ -192,45 +191,96 @@
 
   ve->current=v->pcm_current;
 
-  /* Now search through our cached highpass data for breaking points */
-  /* starting point */
-  if(v->W)
-    j=v->centerW+ci->blocksizes[1]/4-ci->blocksizes[0]/4;
-  else
-    j=v->centerW;
-
-  if(j<ve->lastmark)j=ve->lastmark;
-  
-  while(j+ve->winlength<=v->pcm_current){
-    if(j>=searchpoint)return(1);
-
-    ve->lastmark=j;
-    for(i=0;i<ve->ch;i++){
-      for(k=0;k<4;k++){
-	float *filtered=ve->filtered[i*4+k]+j;
-	float m=_ve_deltai(ve,filtered-ve->winlength,filtered);
+  {
+    int flag=-1;
+    long centerW=v->centerW;
+    long beginW=centerW-ci->blocksizes[v->W]/4;
+    //long endW=centerW+ci->blocksizes[v->W]/4+ci->blocksizes[0]/4;
+    long testW=centerW+ci->blocksizes[v->W]/4+ci->blocksizes[1]/2+ci->blocksizes[0]/4;
+    if(v->W)
+      beginW-=ci->blocksizes[v->lW]/4;
+    else
+      beginW-=ci->blocksizes[0]/4;
+
+    if(ve->mark>=centerW && ve->mark<testW)return(0);
+    if(ve->mark>=testW)return(1);
+
+    if(v->W)
+      j=ve->cursor;
+    else
+      j=centerW-ci->blocksizes[0]/4;
+    
+    while(j+ve->winlength*3/2<=v->pcm_current){
+      if(j>=testW)return(1);
+      ve->cursor=j;
+
+      for(i=0;i<ve->ch;i++){
+	for(k=0;k<4;k++){
+	  float *filtered=ve->filtered[i*4+k]+j;
+	  float *filtered2=ve->filtered[i*4+k]+j+ve->winlength/2;
+	  float m=_ve_deltai(ve,filtered-ve->winlength,filtered);
+	  float mm=_ve_deltai(ve,filtered2-ve->winlength,filtered2);
+	  
+	  if(m>gi->preecho_thresh[k] || m<gi->postecho_thresh[k]){
+	    if(j<=centerW){
+	      ve->prevmark=ve->mark=j;
+	    }else{
+	      /* if a quarter-short-block advance is an even stronger
+		 reading, set *that* as the impulse point. */
+	      if((m>0. && mm>m) || (m<0. && mm<m))
+		flag=j+ve->winlength/2;
+	      else
+		if(flag<0)flag=j;
+	    }
+	  }
+	}
+      }
       
-	if(m>gi->preecho_thresh[k])return(0);
-	if(m<gi->postecho_thresh[k])return(0);
-
+      if(flag>=0){
+ 	ve->prevmark=ve->mark;
+	ve->mark=flag;
+	if(flag>=testW)return(1);
+	return(0);
       }
+      
+      j+=ve->winlength/2;
     }
-
-    j+=min(ci->blocksizes[0],ve->winlength)/2;
-   
   }
-  if(j>=searchpoint)return(1);
  
   return(-1);
 }
 
+int _ve_envelope_mark(vorbis_dsp_state *v){
+  envelope_lookup *ve=((backend_lookup_state *)(v->backend_state))->ve;
+  vorbis_info *vi=v->vi;
+  codec_setup_info *ci=vi->codec_setup;
+  long centerW=v->centerW;
+  long beginW=centerW-ci->blocksizes[v->W]/4;
+  long endW=centerW+ci->blocksizes[v->W]/4;
+  if(v->W){
+    beginW-=ci->blocksizes[v->lW]/4;
+    endW+=ci->blocksizes[v->nW]/4;
+  }else{
+    beginW-=ci->blocksizes[0]/4;
+    endW+=ci->blocksizes[0]/4;
+  }
+
+  if(ve->prevmark>=beginW && ve->prevmark<endW)return(1);
+  if(ve->mark>=beginW && ve->mark<endW)return(1);
+  return(0);
+}
+
 void _ve_envelope_shift(envelope_lookup *e,long shift){
   int i;
   for(i=0;i<e->ch*4;i++)
     memmove(e->filtered[i],e->filtered[i]+shift,(e->current-shift)*
             sizeof(*e->filtered[i]));
   e->current-=shift;
-  e->lastmark-=shift;
+  if(e->prevmark>=0)
+    e->prevmark-=shift;
+  if(e->mark>=0)
+    e->mark-=shift;
+  e->cursor-=shift;
 }
 
 

1.17      +6 -3      vorbis/lib/envelope.h

Index: envelope.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/envelope.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- envelope.h	2001/02/26 03:50:41	1.16
+++ envelope.h	2001/12/12 09:45:25	1.17
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: PCM data envelope analysis and manipulation
- last mod: $Id: envelope.h,v 1.16 2001/02/26 03:50:41 xiphmont Exp $
+ last mod: $Id: envelope.h,v 1.17 2001/12/12 09:45:25 xiphmont Exp $
 
  ********************************************************************/
 
@@ -32,13 +32,16 @@
 
   long storage;
   long current;
-  long lastmark;
+  long mark;
+  long prevmark;
+  long cursor;
 } envelope_lookup;
 
 extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
 extern void _ve_envelope_clear(envelope_lookup *e);
-extern long _ve_envelope_search(vorbis_dsp_state *v,long searchpoint);
+extern long _ve_envelope_search(vorbis_dsp_state *v);
 extern void _ve_envelope_shift(envelope_lookup *e,long shift);
+extern int  _ve_envelope_mark(vorbis_dsp_state *v);
 
 
 #endif

1.47      +1 -2      vorbis/lib/floor0.c

Index: floor0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/floor0.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- floor0.c	2001/10/02 00:14:30	1.46
+++ floor0.c	2001/12/12 09:45:25	1.47
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: floor backend 0 implementation
- last mod: $Id: floor0.c,v 1.46 2001/10/02 00:14:30 segher Exp $
+ last mod: $Id: floor0.c,v 1.47 2001/12/12 09:45:25 xiphmont Exp $
 
  ********************************************************************/
 
@@ -266,7 +266,6 @@
   vorbis_look_floor0 *look=(vorbis_look_floor0 *)in;
   vorbis_info_floor0 *info=look->vi;
   float amp;
-  long bits=0;
   long val=0;
   static int seq=0;
 

1.18      +3 -3      vorbis/lib/floor1.c

Index: floor1.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/floor1.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- floor1.c	2001/11/13 06:04:31	1.17
+++ floor1.c	2001/12/12 09:45:25	1.18
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: floor backend 1 implementation
- last mod: $Id: floor1.c,v 1.17 2001/11/13 06:04:31 msmith Exp $
+ last mod: $Id: floor1.c,v 1.18 2001/12/12 09:45:25 xiphmont Exp $
 
  ********************************************************************/
 
@@ -618,6 +618,7 @@
     return B[pos];
   if(B[pos]<0)
     return A[pos];
+
   return (A[pos]+B[pos])>>1;
 }
 
@@ -1025,7 +1026,6 @@
   vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
   vorbis_info_floor1 *info=look->vi;
   
-  codec_setup_info   *ci=vb->vd->vi->codec_setup;
   int i,j,k;
   codebook *books=((backend_lookup_state *)(vb->vd->backend_state))->
     fullbooks;   
@@ -1138,7 +1138,7 @@
         ly=hy;
       }
     }
-    for(j=hx;j<n;j++)out[j]*=out[j-1]; /* be certain */    
+    for(j=hx;j<n;j++)out[j]*=ly; /* be certain */    
     return(1);
   }
   memset(out,0,sizeof(*out)*n);

1.49      +9 -2      vorbis/lib/info.c

Index: info.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/info.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- info.c	2001/10/20 04:57:57	1.48
+++ info.c	2001/12/12 09:45:25	1.49
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: maintain the info structure, info <-> header packets
- last mod: $Id: info.c,v 1.48 2001/10/20 04:57:57 msmith Exp $
+ last mod: $Id: info.c,v 1.49 2001/12/12 09:45:25 xiphmont Exp $
 
  ********************************************************************/
 
@@ -138,6 +138,13 @@
   memset(vc,0,sizeof(*vc));
 }
 
+/* blocksize 0 is guaranteed to be short, 1 is guarantted to be long.
+   They may be equal, but short will never ge greater than long */
+int vorbis_info_blocksize(vorbis_info *vi,int zo){
+  codec_setup_info *ci = vi->codec_setup;
+  return ci ? ci->blocksizes[zo] : -1;
+}
+
 /* used by synthesis, which has a full, alloced vi */
 void vorbis_info_init(vorbis_info *vi){
   memset(vi,0,sizeof(*vi));
@@ -409,7 +416,7 @@
 }
 
 static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
-  char temp[]="Xiphophorus libVorbis I 20010910";
+  char temp[]="Xiphophorus libVorbis I 20011212";
   int bytes = strlen(temp);
 
   /* preamble */  

1.33      +3 -3      vorbis/lib/lpc.c

Index: lpc.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/lpc.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- lpc.c	2001/10/02 00:14:31	1.32
+++ lpc.c	2001/12/12 09:45:25	1.33
@@ -11,7 +11,7 @@
  ********************************************************************
 
   function: LPC low level routines
-  last mod: $Id: lpc.c,v 1.32 2001/10/02 00:14:31 segher Exp $
+  last mod: $Id: lpc.c,v 1.33 2001/12/12 09:45:25 xiphmont Exp $
 
  ********************************************************************/
 
@@ -67,7 +67,7 @@
 
   j=m+1;
   while(j--){
-    float d=0;
+    double d=0; /* double needed for accumulator depth */
     for(i=j;i<n;i++)d+=data[i]*data[i-j];
     aut[j]=d;
   }
@@ -77,7 +77,7 @@
   error=aut[0];
   
   for(i=0;i<m;i++){
-    float r=-aut[i+1];
+    float r= -aut[i+1];
 
     if(error==0){
       memset(lpc,0,m*sizeof(*lpc));

1.38      +71 -51    vorbis/lib/mapping0.c

Index: mapping0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/mapping0.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- mapping0.c	2001/10/02 00:14:31	1.37
+++ mapping0.c	2001/12/12 09:45:25	1.38
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: channel mapping 0 implementation
- last mod: $Id: mapping0.c,v 1.37 2001/10/02 00:14:31 segher Exp $
+ last mod: $Id: mapping0.c,v 1.38 2001/12/12 09:45:25 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"
@@ -144,13 +143,13 @@
       int psynum=info->psy[0];
       look->psy_look[0]=_ogg_calloc(1,sizeof(*look->psy_look[0]));      
       _vp_psy_init(look->psy_look[0],ci->psy_param[psynum],
-		   ci->psy_g_param,
+		   &ci->psy_g_param,
                    ci->blocksizes[vm->blockflag]/2,vi->rate);
 
       psynum=info->psy[1];
       look->psy_look[1]=_ogg_calloc(1,sizeof(*look->psy_look[1]));      
       _vp_psy_init(look->psy_look[1],ci->psy_param[psynum],
-		   ci->psy_g_param,
+		   &ci->psy_g_param,
                    ci->blocksizes[vm->blockflag]/2,vi->rate);
     }else{
 
@@ -158,7 +157,7 @@
       look->psy_look[0]=_ogg_calloc(1,sizeof(*look->psy_look[0]));      
       look->psy_look[1]=look->psy_look[0];
       _vp_psy_init(look->psy_look[0],ci->psy_param[psynum],
-		   ci->psy_g_param,
+		   &ci->psy_g_param,
                    ci->blocksizes[vm->blockflag]/2,vi->rate);
 
     }
@@ -179,7 +178,8 @@
   return(ret);
 }
 
-static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,oggpack_buffer *opb){
+static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
+			  oggpack_buffer *opb){
   int i;
   vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
 
@@ -288,6 +288,7 @@
   vorbis_info           *vi=vd->vi;
   codec_setup_info      *ci=vi->codec_setup;
   backend_lookup_state  *b=vb->vd->backend_state;
+  bitrate_manager_state *bm=&b->bms;
   vorbis_look_mapping0  *look=(vorbis_look_mapping0 *)l;
   vorbis_info_mapping0  *info=look->map;
   vorbis_info_mode      *mode=look->mode;
@@ -301,7 +302,7 @@
 
   float global_ampmax=vbi->ampmax;
   float *local_ampmax=alloca(sizeof(*local_ampmax)*vi->channels);
-  int blocktype;
+  int blocktype=vbi->blocktype;
 
   /* we differentiate between short and long block types to help the
      masking engine; the window shapes also matter.
@@ -314,15 +315,17 @@
      long block (run of the mill long block)
   */
 
-  if(vb->W){
-    if(!vb->lW || !vb->nW)
-      blocktype=BLOCKTYPE_TRANSITION;
+  if(seq%10==0)fprintf(stderr,"%d",seq);
+  if(!vb->W){
+    if(blocktype==BLOCKTYPE_IMPULSE)
+      fprintf(stderr,"|");
     else
-      blocktype=BLOCKTYPE_LONG;
+      fprintf(stderr,".");
   }else{
-    /* right now we're missing the infrastructure to distingush the
-       two short types */
-    blocktype=BLOCKTYPE_IMPULSE;
+    if(blocktype==BLOCKTYPE_TRANSITION)
+      fprintf(stderr,"-");
+    else
+      fprintf(stderr,"_");
   }
 
   for(i=0;i<vi->channels;i++){
@@ -339,10 +342,14 @@
     float *logmax  =work;
     float *logmask =work+n/2;*/
 
+    _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];
     
+    //_analysis_output("windowed",seq+i,pcm,n,0,0);
+
     /* transform the PCM data */
     /* only MDCT right now.... */
     mdct_forward(b->transform[vb->W][0],pcm,pcm);
@@ -357,6 +364,8 @@
       temp=logfft[(j+1)>>1]=todB(&temp);
       if(temp>local_ampmax[i])local_ampmax[i]=temp;
     }
+
+    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);
@@ -378,7 +387,6 @@
     for(j=0;j<n/2;j++)
       logmdct[j]=todB(mdct+j);
     _analysis_output("mdct",seq+i,logmdct,n/2,1,0);
-    _analysis_output("lmdct",seq+i,mdct,n/2,0,0);
 
 
     /* perform psychoacoustics; do masking */
@@ -390,7 +398,8 @@
                      logmask,
                      global_ampmax,
                      local_ampmax[i],
-		     ci->blocksizes[vb->lW]/2);
+		     ci->blocksizes[vb->lW]/2,
+		     bm->avgnoise);
 
     _analysis_output("mask",seq+i,logmask,n/2,1,0);
     /* perform floor encoding */
@@ -404,7 +413,6 @@
               codedflr);
 
 
-    _analysis_output("mdct2",seq+i,mdct,n/2,1,1);
     _vp_remove_floor(look->psy_look[blocktype],
                      b->psy_g_look,
                      logmdct,
@@ -419,7 +427,7 @@
         fprintf(stderr,"%ld ",seq+i);
         }*/
 
-    _analysis_output("res",seq+i,res,n/2,1,0);
+    //_analysis_output("res",seq+i,res,n/2,1,0);
     _analysis_output("codedflr",seq+i,codedflr,n/2,1,1);
       
   }
@@ -428,9 +436,10 @@
 
   /* partition based prequantization and channel coupling */
   /* Steps in prequant and coupling:
-     
+
+     classify by |mag| across all pcm vectors 
+
      down-couple/down-quantize from perfect residue ->  quantized vector 
-     classify by this first quantized vector
      
      do{ 
         encode quantized vector; add encoded values to 'so-far' vector
@@ -455,6 +464,7 @@
     float  **sofar=alloca(sizeof(*sofar)*vi->channels);
 
     long  ***classifications=alloca(sizeof(*classifications)*info->submaps);
+    float ***qbundle=alloca(sizeof(*qbundle)*info->submaps);
     float ***pcmbundle=alloca(sizeof(*pcmbundle)*info->submaps);
     float ***sobundle=alloca(sizeof(*sobundle)*info->submaps);
     int    **zerobundle=alloca(sizeof(*zerobundle)*info->submaps);
@@ -462,15 +472,15 @@
     int      chcounter=0;
 
     /* play a little loose with this abstraction */
-    int   quant_passes=look->psy_look[blocktype]->vi->coupling_passes;
-    int   stopflag=0;
+    int   quant_passes=ci->coupling_passes;
 
     for(i=0;i<vi->channels;i++){
-      quantized[i]=pcm[i]+n/2;
-      sofar[i]=_vorbis_block_alloc(vb,n/2*sizeof(*sofar[i]));
+      quantized[i]=_vorbis_block_alloc(vb,n*sizeof(*sofar[i]));
+      sofar[i]=quantized[i]+n/2;
       memset(sofar[i],0,sizeof(*sofar[i])*n/2);
     }
 
+    qbundle[0]=alloca(sizeof(*qbundle[0])*vi->channels);
     pcmbundle[0]=alloca(sizeof(*pcmbundle[0])*vi->channels);
     sobundle[0]=alloca(sizeof(*sobundle[0])*vi->channels);
     zerobundle[0]=alloca(sizeof(*zerobundle[0])*vi->channels);
@@ -496,15 +506,15 @@
                           0);
     }
 
-    for(i=0;i<vi->channels;i++)
-      _analysis_output("quant",seq+i,quantized[i],n/2,1,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++){
       int ch_in_bundle=0;
-      pcmbundle[i]=pcmbundle[0]+chcounter;
+      qbundle[i]=qbundle[0]+chcounter;
       sobundle[i]=sobundle[0]+chcounter;
       zerobundle[i]=zerobundle[0]+chcounter;
 
@@ -514,7 +524,8 @@
             zerobundle[i][ch_in_bundle]=1;
           else
             zerobundle[i][ch_in_bundle]=0;
-	  pcmbundle[i][ch_in_bundle]=quantized[j];
+	  qbundle[i][ch_in_bundle]=quantized[j];
+	  pcmbundle[i][ch_in_bundle]=pcm[j];
           sobundle[i][ch_in_bundle++]=sofar[j];
         }
       }
@@ -524,39 +535,41 @@
       classifications[i]=look->residue_func[i]->
         class(vb,look->residue_look[i],pcmbundle[i],zerobundle[i],chbundle[i]);
     }
+
+    /* actual encoding loop; we pack all the iterations to collect
+       management data */
 
-    /* actual encoding loop */
-    for(i=0;!stopflag;){
+    for(i=0;i<quant_passes;){
 
       /* perform residue encoding of this pass's quantized residue
          vector, according residue mapping */
     
-      for(j=0;j<info->submaps;j++)
+      for(j=0;j<info->submaps;j++){
         look->residue_func[j]->
           forward(vb,look->residue_look[j],
-		  pcmbundle[j],sobundle[j],zerobundle[j],chbundle[j],
-		  i,classifications[j]);
+		  qbundle[j],sobundle[j],zerobundle[j],chbundle[j],
+		  i,classifications[j],vbi->packet_markers);
+	
+      }
       i++;
-      
-      /* bitrate management decision hook; the following if() is where
-         we tell progressive encoding to halt, right now it just
-         avoids falling off the edge */
-      if(i>=quant_passes /* || yadda yadda */)stopflag=1;
-
-      if(!stopflag){
+	
+      if(i<quant_passes){
         /* down-couple/down-quantize from perfect-'so-far' -> 
-	   new quantized vector */
+	 new quantized vector */
         if(info->coupling_steps==0){
           /* this assumes all or nothing coupling right now.  it should pass
              through any channels left uncoupled, but it doesn't do that now */
-	  for(i=0;i<vi->channels;i++){
-	    float *lpcm=pcm[i];
-	    float *lsof=sofar[i];
-	    float *lqua=quantized[i];
+	  int k;
+	  for(k=0;k<vi->channels;k++){
+	    float *lpcm=pcm[k];
+	    float *lsof=sofar[k];
+	    float *lqua=quantized[k];
             for(j=0;j<n/2;j++)
               lqua[j]=lpcm[j]-lsof[j];
           }
         }else{
+	  char buf[80];
+	  
           _vp_quantize_couple(look->psy_look[blocktype],
                               info,
                               pcm,
@@ -564,13 +577,17 @@
                               quantized,
                               nonzero,
                               i);
+	  
+	  //sprintf(buf,"quant%d",i);
+	  //for(j=0;j<vi->channels;j++)
+	  //_analysis_output(buf,seq+j,quantized[j],n/2,1,0);
+	  
         }
       }
-      /* steady as she goes */
     }
     seq+=vi->channels;
-  }
-  
+  } 
+
   look->lastframe=vb->sequence;
   return(0);
 }
@@ -676,8 +693,8 @@
   /* only MDCT right now.... */
   for(i=0;i<vi->channels;i++){
     float *pcm=vb->pcm[i];
-    _analysis_output("out",seq+i,pcm,n/2,1,1);
-    _analysis_output("lout",seq+i,pcm,n/2,0,0);
+    //_analysis_output("out",seq+i,pcm,n/2,1,1);
+    //_analysis_output("lout",seq+i,pcm,n/2,0,0);
     mdct_backward(b->transform[vb->W][0],pcm,pcm);
   }
 
@@ -690,12 +707,15 @@
     else
       for(j=0;j<n;j++)
         pcm[j]=0.f;
-    _analysis_output("final",seq++,pcm,n,0,0);
+
+    //_analysis_output("final",seq,pcm,n,0,0);
   }
             
   /* now apply the decoded post-window time information */
   /* NOT IMPLEMENTED */
 
+  fprintf(stderr,"seq %d\r",seq);
+    
   /* all done! */
   return(0);
 }

1.19      +1 -11     vorbis/lib/masking.h

Index: masking.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/masking.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- masking.h	2001/08/13 02:01:15	1.18
+++ masking.h	2001/12/12 09:45:25	1.19
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: masking curve data for psychoacoustics
- last mod: $Id: masking.h,v 1.18 2001/08/13 02:01:15 xiphmont Exp $
+ last mod: $Id: masking.h,v 1.19 2001/12/12 09:45:25 xiphmont Exp $
 
  ********************************************************************/
 
@@ -22,16 +22,6 @@
    15,   15,   15,    15,    11,    10,     8,    7,    7,    7,
     6,    2,    0,     0,    -3,    -5,    -6,   -6, -4.5f, 2.5f,
    10,   15,   15,    15,    15,    15,   15};
-
-static float ATH_Bark_dB_lineconservative[]={  
-   0,  15,  15,   15,   11,       10,   8,  7,  7, 7,
-   6,   2,   0,    0,   -2,       -5,  -6, -6, -4, 0,
-   2,   6,   5,    5,   15,       25,  35};
-
-static float ATH_Bark_dB_lineaggressive[]={  
-   0,  15,  15,   15,   11,       10,   8,  7,  7, 7,
-   6,   2,   0,    0,   -2,       -5,  -6, -6, -4, 4,
-  14,  20,  19,   17,   30,       60,  60};
 
 /* The below masking curves are straight from the R. Ehmer
    (J. Acoustical Society of America) papers ca 1958-59.  I modified

1.57      +209 -227  vorbis/lib/psy.c

Index: psy.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/psy.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- psy.c	2001/10/02 00:14:32	1.56
+++ psy.c	2001/12/12 09:45:25	1.57
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: psychoacoustics not including preecho
- last mod: $Id: psy.c,v 1.56 2001/10/02 00:14:32 segher Exp $
+ last mod: $Id: psy.c,v 1.57 2001/12/12 09:45:25 xiphmont Exp $
 
  ********************************************************************/
 
@@ -35,22 +35,10 @@
    masking has a strong harmonic dependency */
 
 vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
-  int i,j;
   codec_setup_info *ci=vi->codec_setup;
-  vorbis_info_psy_global *gi=ci->psy_g_param;
+  vorbis_info_psy_global *gi=&ci->psy_g_param;
   vorbis_look_psy_global *look=_ogg_calloc(1,sizeof(*look));
 
-  int shiftoc=rint(log(gi->eighth_octave_lines*8)/log(2))-1;
-  look->decaylines=toOC(96000.f)*(1<<(shiftoc+1))+.5f; /* max sample
-							  rate of
-							  192000kHz
-							  for now */
-  look->decay=_ogg_calloc(vi->channels,sizeof(*look->decay));
-  for(i=0;i<vi->channels;i++){
-    look->decay[i]=_ogg_calloc(look->decaylines,sizeof(*look->decay[i]));
-    for(j=0;j<look->decaylines;j++)
-      look->decay[i][j]=-9999.;
-  }
   look->channels=vi->channels;
 
   look->ampmax=-9999.;
@@ -59,14 +47,17 @@
 }
 
 void _vp_global_free(vorbis_look_psy_global *look){
-  int i;
-  if(look->decay){
-    for(i=0;i<look->channels;i++)
-      _ogg_free(look->decay[i]);
-    _ogg_free(look->decay);
+  if(look){
+    memset(look,0,sizeof(*look));
+    _ogg_free(look);
+  }
+}
+
+void _vi_gpsy_free(vorbis_info_psy_global *i){
+  if(i){
+    memset(i,0,sizeof(*i));
+    _ogg_free(i);
   }
-  memset(look,0,sizeof(*look));
-  _ogg_free(look);
 }
 
 void _vi_psy_free(vorbis_info_psy *i){
@@ -310,9 +301,6 @@
   memcpy(p->tonecurves[16][8]+2,tone_8000_80dB_SL,sizeof(*p->tonecurves[16][8])*EHMER_MAX);
   memcpy(p->tonecurves[16][10]+2,tone_8000_100dB_SL,sizeof(*p->tonecurves[16][10])*EHMER_MAX);
 
-  /* value limit the tonal masking curves; the peakatt not only
-     optionally specifies maximum dynamic depth, but also [always]
-     limits the masking curves to a minimum depth */
   for(i=0;i<P_BANDS;i+=2)
     for(j=4;j<P_LEVELS;j+=2)
       for(k=2;k<EHMER_MAX+2;k++)
@@ -330,34 +318,174 @@
 
   /* set up the final curves */
   for(i=0;i<P_BANDS;i++)
-    setup_curve(p->tonecurves[i],i,vi->toneatt->block[i]);
+    setup_curve(p->tonecurves[i],i,vi->toneatt.block[i]);
+
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_63Hz",i,p->tonecurves[0][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_88Hz",i,p->tonecurves[1][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_125Hz",i,p->tonecurves[2][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_170Hz",i,p->tonecurves[3][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_250Hz",i,p->tonecurves[4][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_350Hz",i,p->tonecurves[5][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_500Hz",i,p->tonecurves[6][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_700Hz",i,p->tonecurves[7][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_1kHz",i,p->tonecurves[8][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_1.4Hz",i,p->tonecurves[9][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_2kHz",i,p->tonecurves[10][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_2.4kHz",i,p->tonecurves[11][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+     _analysis_output("curve_4kHz",i,p->tonecurves[12][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_5.6kHz",i,p->tonecurves[13][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_8kHz",i,p->tonecurves[14][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_11.5kHz",i,p->tonecurves[15][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("curve_16kHz",i,p->tonecurves[16][i]+2,EHMER_MAX,0,0);
 
   if(vi->curvelimitp){
     /* value limit the tonal masking curves; the peakatt not only
-       optionally specifies maximum dynamic depth, but also [always]
+       optionally specifies maximum dynamic depth, but also
        limits the masking curves to a minimum depth  */
     for(i=0;i<P_BANDS;i++)
       for(j=0;j<P_LEVELS;j++){
         for(k=2;k<EHMER_OFFSET+2+vi->curvelimitp;k++)
-	  if(p->tonecurves[i][j][k]> vi->peakatt->block[i][j])
-	    p->tonecurves[i][j][k]=  vi->peakatt->block[i][j];
+	  if(p->tonecurves[i][j][k]> vi->peakatt.block[i][j])
+	    p->tonecurves[i][j][k]=  vi->peakatt.block[i][j];
           else
             break;
       }
   }
+
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_63Hz",i,p->tonecurves[0][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_88Hz",i,p->tonecurves[1][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_125Hz",i,p->tonecurves[2][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_170Hz",i,p->tonecurves[3][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_250Hz",i,p->tonecurves[4][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_350Hz",i,p->tonecurves[5][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_500Hz",i,p->tonecurves[6][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_700Hz",i,p->tonecurves[7][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_1kHz",i,p->tonecurves[8][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_1.4Hz",i,p->tonecurves[9][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_2kHz",i,p->tonecurves[10][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_2.4kHz",i,p->tonecurves[11][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_4kHz",i,p->tonecurves[12][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_5.6kHz",i,p->tonecurves[13][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_8kHz",i,p->tonecurves[14][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_11.5kHz",i,p->tonecurves[15][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("licurve_16kHz",i,p->tonecurves[16][i]+2,EHMER_MAX,0,0);
 
-  if(vi->tone_guard) /* we limit depth only optionally */
+  if(vi->peakattp) /* we limit maximum depth only optionally */
     for(i=0;i<P_BANDS;i++)
       for(j=0;j<P_LEVELS;j++)
-	if(p->tonecurves[i][j][EHMER_OFFSET+2]< vi->peakatt->block[i][j])
-	  p->tonecurves[i][j][EHMER_OFFSET+2]=  vi->peakatt->block[i][j];
+	if(p->tonecurves[i][j][EHMER_OFFSET+2]< vi->peakatt.block[i][j])
+	  p->tonecurves[i][j][EHMER_OFFSET+2]=  vi->peakatt.block[i][j];
 
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_63Hz",i,p->tonecurves[0][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_88Hz",i,p->tonecurves[1][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_125Hz",i,p->tonecurves[2][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_170Hz",i,p->tonecurves[3][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_250Hz",i,p->tonecurves[4][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_350Hz",i,p->tonecurves[5][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_500Hz",i,p->tonecurves[6][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_700Hz",i,p->tonecurves[7][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_1kHz",i,p->tonecurves[8][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_1.4Hz",i,p->tonecurves[9][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_2kHz",i,p->tonecurves[10][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_2.4kHz",i,p->tonecurves[11][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_4kHz",i,p->tonecurves[12][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_5.6kHz",i,p->tonecurves[13][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_8kHz",i,p->tonecurves[14][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_11.5kHz",i,p->tonecurves[15][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("pcurve_16kHz",i,p->tonecurves[16][i]+2,EHMER_MAX,0,0);
+
   /* but guarding is mandatory */
   for(i=0;i<P_BANDS;i++)
     for(j=0;j<P_LEVELS;j++)
       if(p->tonecurves[i][j][EHMER_OFFSET+2]< vi->tone_guard)
           p->tonecurves[i][j][EHMER_OFFSET+2]=  vi->tone_guard;
 
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_63Hz",i,p->tonecurves[0][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_88Hz",i,p->tonecurves[1][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_125Hz",i,p->tonecurves[2][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_170Hz",i,p->tonecurves[3][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_250Hz",i,p->tonecurves[4][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_350Hz",i,p->tonecurves[5][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_500Hz",i,p->tonecurves[6][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_700Hz",i,p->tonecurves[7][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_1kHz",i,p->tonecurves[8][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_1.4Hz",i,p->tonecurves[9][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_2kHz",i,p->tonecurves[10][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_2.4kHz",i,p->tonecurves[11][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_4kHz",i,p->tonecurves[12][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_5.6kHz",i,p->tonecurves[13][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_8kHz",i,p->tonecurves[14][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_11.5kHz",i,p->tonecurves[15][i]+2,EHMER_MAX,0,0);
+  for(i=0;i<P_LEVELS;i++)
+    _analysis_output("fcurve_16kHz",i,p->tonecurves[16][i]+2,EHMER_MAX,0,0);
+
   /* set up rolling noise median */
   for(i=0;i<n;i++){
     float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
@@ -376,41 +504,6 @@
   analysis_noisy=1;
   _analysis_output("noiseoff",0,p->noiseoffset,n,1,0);
   _analysis_output("noisethresh",0,p->noisethresh,n,1,0);
-
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_63Hz",i,p->tonecurves[0][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_88Hz",i,p->tonecurves[1][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_125Hz",i,p->tonecurves[2][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_170Hz",i,p->tonecurves[3][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_250Hz",i,p->tonecurves[4][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_350Hz",i,p->tonecurves[5][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_500Hz",i,p->tonecurves[6][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_700Hz",i,p->tonecurves[7][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_1kHz",i,p->tonecurves[8][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_1.4Hz",i,p->tonecurves[9][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_2kHz",i,p->tonecurves[10][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_2.4kHz",i,p->tonecurves[11][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_4kHz",i,p->tonecurves[12][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_5.6kHz",i,p->tonecurves[13][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_8kHz",i,p->tonecurves[14][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_11.5kHz",i,p->tonecurves[15][i]+2,EHMER_MAX,0,0);
-  for(i=0;i<P_LEVELS;i++)
-    _analysis_output("curve_16kHz",i,p->tonecurves[16][i]+2,EHMER_MAX,0,0);
   analysis_noisy=1;
 
 }
@@ -713,14 +806,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;
 
@@ -736,7 +830,6 @@
 
     for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
 
-    _analysis_output("medianmdct",seq,work,n,1,0);
     bark_noise_hybridmp(n,p->bark,work,logmask,0.,
                         p->vi->noisewindowfixed);
 
@@ -744,21 +837,18 @@
 
     /* work[i] holds the median line (.5), logmask holds the upper
        envelope line (1.) */
+    _analysis_output("noisemedian",seq,work,n,1,0);
 
-    _analysis_output("median",seq,work,n,1,0);
-
-    _analysis_output("medianenvelope",seq,logmask,n,1,0);
     for(i=0;i<n;i++)logmask[i]+=work[i];
-    _analysis_output("envelope",seq,logmask,n,1,0);
+    _analysis_output("noiseenvelope",seq,logmask,n,1,0);
     for(i=0;i<n;i++)logmask[i]-=work[i];
 
     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;
     }
-
     _analysis_output("noise",seq,logmask,n,1,0);
 
   }else{
@@ -777,7 +867,7 @@
     }
   }
 
-  /* tone/peak masking */
+  /* tone masking */
   seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
   max_seeds(p,g,channel,seed,logmask);
 
@@ -798,7 +888,7 @@
 float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
   vorbis_info *vi=vd->vi;
   codec_setup_info *ci=vi->codec_setup;
-  vorbis_info_psy_global *gi=ci->psy_g_param;
+  vorbis_info_psy_global *gi=&ci->psy_g_param;
 
   int n=ci->blocksizes[vd->W]/2;
   float secs=(float)n/vi->rate;
@@ -810,140 +900,25 @@
 
 static void couple_lossless(float A, float B, 
                             float granule,float igranule,
-			    float *mag, float *ang){
+			    float *mag, float *ang,
+			    int flip_p){
 
-  A=rint(A*igranule)*granule;
-  B=rint(B*igranule)*granule;
-  
   if(fabs(A)>fabs(B)){
+    A=rint(A*igranule)*granule; /* must be done *after* the comparison */
+    B=rint(B*igranule)*granule;
+  
     *mag=A; *ang=(A>0.f?A-B:B-A);
   }else{
+    A=rint(A*igranule)*granule;
+    B=rint(B*igranule)*granule;
+  
     *mag=B; *ang=(B>0.f?A-B:B-A);
   }
-
-  if(*ang>fabs(*mag)*1.9999f)*ang=-fabs(*mag)*2.f;
- 
-}
 
-static void couple_8phase(float A, float B, float fA, float fB, 
-			 float granule,float igranule,
-			 float fmag, float *mag, float *ang){
-
-  float origmag=FAST_HYPOT(A*fA,B*fB),corr;
-
-  if(fmag!=0.f){
-    float phase=rint((A-B)/fmag);
-    
-    if(fabs(A)>fabs(B)){
-      *mag=A;phase=(A>0?phase:-phase);
-    }else{
-      *mag=B;phase=(B>0?phase:-phase);
-    }
-    
-    switch((int)phase){
-    case 0:
-      corr=origmag/FAST_HYPOT(fmag*fA,fmag*fB);
-      *mag=rint(*mag*corr*igranule)*granule; 
-      *ang=0.f;
-      break;
-    case 1:
-      *mag=rint(*mag*igranule)*granule; 
-      *ang=fabs(*mag);
-      break;
-    case -1:
-      *mag=rint(*mag*igranule)*granule; 
-      *ang= -fabs(*mag);
-      break;
-    case -2:
-      corr=origmag/FAST_HYPOT(fmag*fA,fmag*fB);
-      *mag=rint(*mag*corr*igranule)*granule; 
-      *ang= -2.f*fabs(*mag);
-      break;
-    case 2:
-      corr=origmag/FAST_HYPOT(fmag*fA,fmag*fB);
-      *mag= -rint(*mag*corr*igranule)*granule; 
-      *ang= -2.f*fabs(*mag);
-      break;
-    }
-  }else{
-    *mag=0.f;
-    *ang=0.f;
-  }    
-}
-
-static void couple_6phase(float A, float B, float fA, float fB, 
-			 float granule,float igranule,
-			 float fmag, float *mag, float *ang){
-
-  float origmag=FAST_HYPOT(A*fA,B*fB),corr;
-
-  if(fmag!=0.f){
-    float phase=rint((A-B)/fmag);
-    
-    if(fabs(A)>fabs(B)){
-      *mag=A;phase=(A>0?phase:-phase);
-    }else{
-      *mag=B;phase=(B>0?phase:-phase);
-    }
-    
-    switch((int)phase){
-    case 0:
-      corr=origmag/FAST_HYPOT(fmag*fA,fmag*fB);
-      *mag=rint(*mag*corr*igranule)*granule; 
-      *ang=0.f;
-      break;
-    case 1:case 2:
-      *mag=rint(*mag*igranule)*granule; 
-      *ang= fabs(*mag);
-      break;
-    case -1:case -2:
-      *mag=rint(*mag*igranule)*granule; 
-      *ang= -fabs(*mag);
-      break;
-    default:
-      *mag=0.f;
-      *ang=0.f;
-
-    }
-  }else{
-    *mag=0.f;
-    *ang=0.f;
-  }    
-}
-
-static void couple_4phase(float A, float B, float fA, float fB, 
-			 float granule,float igranule,
-			 float fmag, float *mag, float *ang){
-
-  float origmag=FAST_HYPOT(A*fA,B*fB),corr;
-
-  if(fmag!=0.f){
-    float phase=rint((A-B)*.5/fmag);
-    
-    if(fabs(A)>fabs(B)){
-      *mag=A;phase=(A>0?phase:-phase);
-    }else{
-      *mag=B;phase=(B>0?phase:-phase);
-    }
-    
-    corr=origmag/FAST_HYPOT(fmag*fA,fmag*fB);
-    *mag=rint(*mag*corr*igranule)*granule; 
-    switch((int)phase){
-    case 0:
-      *ang=0.f;
-      break;
-    case -1:
-      *ang=-2.f*fabs(*mag);
-      break;
-    default:
-      *mag=-*mag;
-      *ang=-2.f*fabs(*mag);
-      break;
-    }
-  }else{
-    *mag=0.f;
-    *ang=0.f;
-  }    
+  if(flip_p && *ang>fabs(*mag)*1.9999f){
+    *ang= -fabs(*mag)*2.f;
+    *mag= -*mag;
+  }
 }
 
 static void couple_point(float A, float B, float fA, float fB, 
@@ -994,7 +969,7 @@
   for(i=0;i<vi->coupling_steps;i++){
     float granulem=info->couple_pass[passno].granulem;
     float igranulem=info->couple_pass[passno].igranulem;
-    
+
     /* make sure coupling a zero and a nonzero channel results in two
        nonzero channels. */
     if(nonzero[vi->coupling_mag[i]] ||
@@ -1014,7 +989,9 @@
 
       for(j=0,k=0;j<n;k++){
         vp_couple *part=info->couple_pass[passno].couple_pass+k;
-
+	float rqlimit=part->outofphase_requant_limit;
+	float flip_p=part->outofphase_redundant_flip_p;
+    
         for(;j<part->limit && j<p->n;j++){
           /* partition by partition; k is our by-location partition
              class counter */
@@ -1023,23 +1000,28 @@
           if(fmag<part->amppost_point){
             couple_point(pcmM[j],pcmA[j],floorM[j],floorA[j],
                          granulem,igranulem,fmag,&mag,&ang);
+
           }else{
-	    if(fmag<part->amppost_6phase){
-	      couple_6phase(pcmM[j],pcmA[j],floorM[j],floorA[j],
-			   granulem,igranulem,fmag,&mag,&ang);
-	    }else{ 
-	      if(fmag<part->amppost_8phase){
-		couple_8phase(pcmM[j],pcmA[j],floorM[j],floorA[j],
-			      granulem,igranulem,fmag,&mag,&ang);
-	      }else{
-		couple_lossless(pcmM[j],pcmA[j],
-				granulem,igranulem,&mag,&ang);
-	      }
-	    }
+	    couple_lossless(pcmM[j],pcmA[j],
+			    granulem,igranulem,&mag,&ang,flip_p);
+	  }
+
+	  /* executive decision time: when requantizing and recoupling
+	     residue in order to progressively encode at finer
+	     resolution, an out of phase component that originally
+	     quntized to 2*mag can flip flop magnitude/angle if it
+	     requantizes to not-quite out of phase.  If that happens,
+	     we opt not to fill in additional resolution (in order to
+	     simplify the iterative codebook design and
+	     efficiency). */
+	 
+	  if(ang<-rqlimit || ang>rqlimit){
+	    qM[j]=0.f;
+	    qA[j]=0.f;
+	  }else{ 
+	    qM[j]=mag-sofarM[j];
+	    qA[j]=ang-sofarA[j];
           }
-	  
-	  qM[j]=mag-sofarM[j];
-	  qA[j]=ang-sofarA[j];
         }
       }
     }

1.25      +11 -20    vorbis/lib/psy.h

Index: psy.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/psy.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- psy.h	2001/09/11 05:06:57	1.24
+++ psy.h	2001/12/12 09:45:25	1.25
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: random psychoacoustics (not including preecho)
- last mod: $Id: psy.h,v 1.24 2001/09/11 05:06:57 xiphmont Exp $
+ last mod: $Id: psy.h,v 1.25 2001/12/12 09:45:25 xiphmont Exp $
 
  ********************************************************************/
 
@@ -21,12 +21,6 @@
 
 #include "backends.h"
 
-#define BLOCKTYPE_IMPULSE    0
-#define BLOCKTYPE_PADDING    1
-#define BLOCKTYPE_TRANSITION 0 
-#define BLOCKTYPE_LONG       1
-
-
 #ifndef EHMER_MAX
 #define EHMER_MAX 56
 #endif
@@ -38,9 +32,10 @@
 
 typedef struct vp_couple{
   int limit;        /* sample post */
+
+  int outofphase_redundant_flip_p;
+  float outofphase_requant_limit;
 
-  float amppost_8phase;
-  float amppost_6phase;
   float amppost_point;
   
 } vp_couple;
@@ -58,7 +53,7 @@
 
 #define NOISE_COMPAND_LEVELS 40
 typedef struct vorbis_info_psy{
-  float  *ath;
+  float  ath[27];
 
   float  ath_adjatt;
   float  ath_maxatt;
@@ -66,11 +61,11 @@
   float tone_masteratt;
   float tone_guard;
   float tone_abs_limit;
-  vp_attenblock *toneatt;
+  vp_attenblock toneatt;
 
   int peakattp;
   int curvelimitp;
-  vp_attenblock *peakatt;
+  vp_attenblock peakatt;
 
   int noisemaskp;
   float noisemaxsupp;
@@ -80,21 +75,18 @@
   int   noisewindowhimin;
   int   noisewindowfixed;
   float noiseoff[P_BANDS];
-  float *noisecompand;
+  float noisecompand[NOISE_COMPAND_LEVELS];
 
   float max_curve_dB;
 
-  int coupling_passes;
-  vp_couple_pass *couple_pass;
+  vp_couple_pass couple_pass[8];
 
 } vorbis_info_psy;
 
 typedef struct{
-  float     decaydBpms;
   int       eighth_octave_lines;
 
   /* for block long/short tuning; encode only */
-  int       envelopesa;
   float     preecho_thresh[4];
   float     postecho_thresh[4];
   float     preecho_minenergy;
@@ -108,8 +100,6 @@
 
 typedef struct {
   float   ampmax;
-  float **decay;
-  int     decaylines;
   int     channels;
 
   vorbis_info_psy_global *gi;
@@ -159,7 +149,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,

1.12      +9 -1      vorbis/lib/registry.c

Index: registry.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/registry.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- registry.c	2001/10/18 17:35:36	1.11
+++ registry.c	2001/12/12 09:45:25	1.12
@@ -11,13 +11,14 @@
  ********************************************************************
 
  function: registry for time, floor, res backends and channel mappings
- last mod: $Id: registry.c,v 1.11 2001/10/18 17:35:36 cwolf Exp $
+ last mod: $Id: registry.c,v 1.12 2001/12/12 09:45:25 xiphmont Exp $
 
  ********************************************************************/
 
 #include "vorbis/codec.h"
 #include "codec_internal.h"
 #include "registry.h"
+#include "registry-api.h"
 #include "misc.h"
 
 
@@ -50,3 +51,10 @@
 vorbis_func_mapping   *_mapping_P[]={
   &mapping0_exportbundle,
 };
+
+/* make Windows happy; can't access the registry directly outside of
+   libvorbis, and vorbisenc needs a few functions */
+void residue_free_info(vorbis_info_residue *r,int type){
+  _residue_P[type]->free_info(r);
+}
+

1.38      +87 -60    vorbis/lib/res0.c

Index: res0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/res0.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- res0.c	2001/10/02 00:14:32	1.37
+++ res0.c	2001/12/12 09:45:25	1.38
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: residue backend 0, 1 and 2 implementation
- last mod: $Id: res0.c,v 1.37 2001/10/02 00:14:32 segher Exp $
+ last mod: $Id: res0.c,v 1.38 2001/12/12 09:45:25 xiphmont Exp $
 
  ********************************************************************/
 
@@ -49,6 +49,8 @@
   long      phrasebits;
   long      frames;
 
+  int       qoffsets[BITTRACK_DIVISOR+1];
+
 } vorbis_look_residue0;
 
 vorbis_info_residue *res0_copy_info(vorbis_info_residue *vr){
@@ -191,7 +193,7 @@
   return(NULL);
 }
 
-vorbis_look_residue *res0_look (vorbis_dsp_state *vd,vorbis_info_mode *vm,
+vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
                           vorbis_info_residue *vr){
   vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
   vorbis_look_residue0 *look=_ogg_calloc(1,sizeof(*look));
@@ -236,6 +238,17 @@
     }
   }
 
+  {
+    int samples_per_partition=info->grouping;
+    int n=info->end-info->begin,i;
+    int partvals=n/samples_per_partition;
+
+    for(i=0;i<BITTRACK_DIVISOR;i++)
+      look->qoffsets[i]=partvals*(i+1)/BITTRACK_DIVISOR;
+
+    look->qoffsets[i]=9999999;
+  }
+
   return(look);
 }
 
@@ -316,26 +329,13 @@
   int i,bits=0;
   int dim=book->dim;
   int step=n/dim;
-#ifdef TRAIN_RESENT      
-  char buf[80];
-  FILE *f;
-  sprintf(buf,"res0_b%d.vqd",book-look->fullbooks);
-  f=fopen(buf,"a");
-#endif
 
   for(i=0;i<step;i++){
     int entry=vorbis_book_besterror(book,vec+i,step,0);
 
-#ifdef TRAIN_RESENT      
-    fprintf(f,"%d\n",entry);
-#endif
-
     bits+=vorbis_book_encode(book,entry,opb);
   }
 
-#ifdef TRAIN_RESENT      
-  fclose(f);
-#endif
   return(bits);
 }
  
@@ -344,26 +344,13 @@
   int i,bits=0;
   int dim=book->dim;
   int step=n/dim;
-#ifdef TRAIN_RESENT      
-  char buf[80];
-  FILE *f;
-  sprintf(buf,"res0_b%d.vqd",book-look->fullbooks);
-  f=fopen(buf,"a");
-#endif
 
   for(i=0;i<step;i++){
     int entry=vorbis_book_besterror(book,vec+i*dim,1,0);
 
-#ifdef TRAIN_RESENT      
-    fprintf(f,"%d\n",entry);
-#endif
-
     bits+=vorbis_book_encode(book,entry,opb);
   }
 
-#ifdef TRAIN_RESENT      
-  fclose(f);
-#endif
   return(bits);
 }
 
@@ -408,7 +395,7 @@
     char buffer[80];
   
     for(i=0;i<ch;i++){
-      sprintf(buffer,"resaux_%d.vqd",vb->mode);
+      sprintf(buffer,"resaux_%s.vqd",(vb->mode?"long":"short"));
       of=fopen(buffer,"a");
       for(j=0;j<partvals;j++)
         fprintf(of,"%ld, ",partword[i][j]);
@@ -438,6 +425,11 @@
   int partvals=n/samples_per_partition;
   long **partword=_vorbis_block_alloc(vb,sizeof(*partword));
   float *work=alloca(sizeof(*work)*samples_per_partition);
+
+#ifdef TRAIN_RES
+  FILE *of;
+  char buffer[80];
+#endif
   
   partword[0]=_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
   memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
@@ -451,23 +443,22 @@
         l++;
       }
     }
+
     partword[0][i]=
       classify(work,samples_per_partition,look,possible_partitions,i);
+
+
   }  
 
 #ifdef TRAIN_RES
-  {
-    FILE *of;
-    char buffer[80];
-  
-    sprintf(buffer,"resaux_%d.vqd",vb->mode);
-    of=fopen(buffer,"a");
-    for(i=0;i<partvals;i++)
-      fprintf(of,"%ld, ",partword[0][i]);
-    fprintf(of,"\n");
-    fclose(of);
-  }
+  sprintf(buffer,"resaux_%s.vqd",(vb->mode?"long":"short"));
+  of=fopen(buffer,"a");
+  for(i=0;i<partvals;i++)
+    fprintf(of,"%ld, ",partword[0][i]);
+  fprintf(of,"\n");
+  fclose(of);
 #endif
+
   look->frames++;
 
   return(partword);
@@ -477,11 +468,17 @@
                       float **in,int ch,
                       int pass,long **partword,
                       int (*encode)(oggpack_buffer *,float *,int,
-				    codebook *,vorbis_look_residue0 *)){
+				    codebook *,vorbis_look_residue0 *),
+		      ogg_uint32_t *stats){
   long i,j,k,s;
   vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
   vorbis_info_residue0 *info=look->info;
 
+  vorbis_dsp_state      *vd=vb->vd;
+  vorbis_info           *vi=vd->vi;
+  codec_setup_info      *ci=vi->codec_setup;
+
+
   /* move all this setup out later */
   int samples_per_partition=info->grouping;
   int possible_partitions=info->partitions;
@@ -493,17 +490,22 @@
   long resvals[128];
 
 #ifdef TRAIN_RES
-  FILE *of;
+  FILE *of; 
   char buffer[80];
   int m;
   
   for(i=0;i<ch;i++){
-    sprintf(buffer,"residue_%d#%d.vqd",vb->mode,pass);
-    of=fopen(buffer,"a");
-    for(m=0;m<info->end;m++)
-      fprintf(of,"%.2f, ",in[i][m]);
-    fprintf(of,"\n");
-    fclose(of);
+    for(j=0;j<partvals;j++){
+      int class=partword[i][j];
+      float *ptr=in[i]+info->begin+j*samples_per_partition;
+      sprintf(buffer,"res_%s_part%d_it%d.vqd",(vb->mode?"long":"short"),
+	      class,pass);
+      of=fopen(buffer,"a");
+      for(k=0;k<samples_per_partition;k++)
+	fprintf(of,"%.3f, ",ptr[k]);
+      fprintf(of,"\n");
+      fclose(of);
+    }
   }
 #endif      
 
@@ -514,10 +516,14 @@
      words for a partition per channel until we've written all the
      residual words for that partition word.  Then write the next
      partition channel words... */
+
+  for(s=(pass==0?0:ci->passlimit[pass-1]);s<ci->passlimit[pass];s++){
+    int bin=0;
+    ogg_uint32_t *qptr=NULL;
+    if(stats)qptr=stats+s*BITTRACK_DIVISOR;
 
-  for(s=(pass==0?0:info->passlimit[pass-1]);s<info->passlimit[pass];s++){
     for(i=0;i<partvals;){
-      
+
       /* first we encode a partition codeword for each channel */
       if(s==0){
         for(j=0;j<ch;j++){
@@ -544,6 +550,9 @@
       for(k=0;k<partitions_per_word && i<partvals;k++,i++){
         long offset=i*samples_per_partition+info->begin;
         
+	if(qptr)while(i>=look->qoffsets[bin])
+	  qptr[bin++]=oggpack_bits(&vb->opb);
+
         for(j=0;j<ch;j++){
           if(s==0)resvals[partword[j][i]]+=samples_per_partition;
           if(info->secondstages[partword[j][i]]&(1<<s)){
@@ -557,6 +566,8 @@
           }
         }
       }
+      if(qptr)while(i>=look->qoffsets[bin])
+	qptr[bin++]=oggpack_bits(&vb->opb);
     }
   }
 
@@ -650,7 +661,7 @@
 
 int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
                  float **in,float **out,int *nonzero,int ch,
-		 int pass, long **partword){
+		 int pass, long **partword,ogg_uint32_t *stats){
   /* we encode only the nonzero parts of a bundle */
   int i,j,used=0,n=vb->pcmend/2;
   for(i=0;i<ch;i++)
@@ -661,7 +672,7 @@
     }
   if(used){
     int ret=_01forward(vb,vl,in,used,pass,partword,
-		      _interleaved_encodepart);
+		      _interleaved_encodepart,stats);
     used=0;
     for(i=0;i<ch;i++)
       if(nonzero[i]){
@@ -670,8 +681,12 @@
         used++;
       }
     return(ret);
-  }else
+  }else{
+    for(i=0;i<vorbis_bitrate_maxmarkers();i++)
+      stats[i]=oggpack_bits(&vb->opb);
+
     return(0);
+  }
 }
 
 int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
@@ -688,7 +703,7 @@
 
 int res1_forward(vorbis_block *vb,vorbis_look_residue *vl,
                  float **in,float **out,int *nonzero,int ch,
-		 int pass, long **partword){
+		 int pass, long **partword, ogg_uint32_t *stats){
   int i,j,used=0,n=vb->pcmend/2;
   for(i=0;i<ch;i++)
     if(nonzero[i]){
@@ -698,7 +713,7 @@
     }
 
   if(used){
-    int ret=_01forward(vb,vl,in,used,pass,partword,_encodepart);
+    int ret=_01forward(vb,vl,in,used,pass,partword,_encodepart,stats);
     used=0;
     for(i=0;i<ch;i++)
       if(nonzero[i]){
@@ -707,8 +722,12 @@
         used++;
       }
     return(ret);
-  }else
+  }else{
+    for(i=0;i<vorbis_bitrate_maxmarkers();i++)
+      stats[i]=oggpack_bits(&vb->opb);
+
     return(0);
+  }
 }
 
 long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
@@ -752,7 +771,7 @@
 
 int res2_forward(vorbis_block *vb,vorbis_look_residue *vl,
                  float **in,float **out,int *nonzero,int ch,
-		 int pass,long **partword){
+		 int pass,long **partword,ogg_uint32_t *stats){
   long i,j,k,n=vb->pcmend/2,used=0;
 
   /* don't duplicate the code; use a working vector hack for now and
@@ -767,18 +786,26 @@
   }
   
   if(used){
-    int ret=_01forward(vb,vl,&work,1,pass,partword,_encodepart);
+    int ret=_01forward(vb,vl,&work,1,pass,partword,_encodepart,stats);
     /* update the sofar vector */
     for(i=0;i<ch;i++){
       float *pcm=in[i];
       float *sofar=out[i];
       for(j=0,k=i;j<n;j++,k+=ch)
+#ifdef TRAIN_RES
+	sofar[j]+=pcm[j]; /* when training, our previous stage books 
+			    might be dummies */
+#else
         sofar[j]+=pcm[j]-work[k];
+#endif
     }
-
     return(ret);
-  }else
+  }else{
+    for(i=0;i<vorbis_bitrate_maxmarkers();i++)
+      stats[i]=oggpack_bits(&vb->opb);
+
     return(0);
+  }
 }
 
 /* duplicate code here as speed is somewhat more important */

1.19      +1 -2      vorbis/lib/sharedbook.c

Index: sharedbook.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/sharedbook.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- sharedbook.c	2001/10/02 00:14:32	1.18
+++ sharedbook.c	2001/12/12 09:45:25	1.19
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: basic shared codebook operations
- last mod: $Id: sharedbook.c,v 1.18 2001/10/02 00:14:32 segher Exp $
+ last mod: $Id: sharedbook.c,v 1.19 2001/12/12 09:45:25 xiphmont Exp $
 
  ********************************************************************/
 
@@ -379,7 +379,6 @@
   return(acc);
 }
 
-#include <stdio.h>
 int _best(codebook *book, float *a, int step){
   encode_aux_nearestmatch *nt=book->c->nearest_tree;
   encode_aux_threshmatch *tt=book->c->thresh_tree;

1.19      +644 -120  vorbis/lib/vorbisenc.c

Index: vorbisenc.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/vorbisenc.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- vorbisenc.c	2001/10/18 17:39:34	1.18
+++ vorbisenc.c	2001/12/12 09:45:26	1.19
@@ -7,79 +7,577 @@
  *                                                                  *
  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
-
+ *                                                                  *
  ********************************************************************
 
  function: simple programmatic interface for encoder mode setup
- last mod: $Id: vorbisenc.c,v 1.18 2001/10/18 17:39:34 cwolf Exp $
+ last mod: $Id: vorbisenc.c,v 1.19 2001/12/12 09:45:26 xiphmont Exp $
 
  ********************************************************************/
 
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
+#include <stdarg.h>
 
 #include "vorbis/codec.h"
 #include "vorbis/vorbisenc.h"
 
 #include "codec_internal.h"
-#include "registry.h"
-#include "modes/modes.h"
+#include "registry-api.h"
 
 #include "os.h"
 #include "misc.h"
+
+/* careful with this; it's using static array sizing to make managing
+   all the modes a little less annoying.  If we use a residue backend
+   with > 10 partition types, or a different division of iteration,
+   this needs to be updated. */
+typedef struct {
+  vorbis_info_residue0 *res[2];
+  static_codebook *book_aux[2];
+  static_codebook *books_base[5][10][3];
+  static_codebook *books_stereo_backfill[5][10];
+  static_codebook *books_residue_backfill[5][10][2];
+} vorbis_residue_template;
+
+static double stereo_threshholds[]={0.0, 2.5, 4.5, 8.5, 16.5};
+
+typedef struct vp_adjblock{
+  int block[P_BANDS][P_LEVELS];
+} vp_adjblock;
+
+#include "modes/residue_44.h"
+#include "modes/psych_44.h"
+#include "modes/floor_44.h"
+
+/* a few static coder conventions */
+static vorbis_info_time0 _time_dummy={0};
+static vorbis_info_mode _mode_set_short={0,0,0,0};
+static vorbis_info_mode _mode_set_long={1,0,0,1};
+
+/* mapping conventions:
+   only one submap (this would change for efficient 5.1 support for example)*/
+/* Four psychoacoustic profiles are used, one for each blocktype */
+static vorbis_info_mapping0 _mapping_set_short={
+  1, {0,0}, {0}, {0}, {0}, {0,1}, 0,{0},{0}};
+static vorbis_info_mapping0 _mapping_set_long={
+  1, {0,0}, {0}, {1}, {1}, {2,3}, 0,{0},{0}};
+
+static int vorbis_encode_toplevel_init(vorbis_info *vi,int small,int large,int ch,long rate){
+  if(vi && vi->codec_setup){
+    codec_setup_info *ci=vi->codec_setup;
+
+    vi->version=0;
+    vi->channels=ch;
+    vi->rate=rate;
+    
+    ci->blocksizes[0]=small;
+    ci->blocksizes[1]=large;
+
+    /* time mapping hooks are unused in vorbis I */
+    ci->times=1;
+    ci->time_type[0]=0;
+    ci->time_param[0]=calloc(1,sizeof(_time_dummy));
+    memcpy(ci->time_param[0],&_time_dummy,sizeof(_time_dummy));
+
+    /* by convention, two modes: one for short, one for long blocks.
+       short block mode uses mapping sero, long block uses mapping 1 */
+    ci->modes=2;
+    ci->mode_param[0]=calloc(1,sizeof(_mode_set_short));
+    memcpy(ci->mode_param[0],&_mode_set_short,sizeof(_mode_set_short));
+    ci->mode_param[1]=calloc(1,sizeof(_mode_set_long));
+    memcpy(ci->mode_param[1],&_mode_set_long,sizeof(_mode_set_long));
+
+    /* by convention two mappings, both mapping type zero (polyphonic
+       PCM), first for short, second for long blocks */
+    ci->maps=2;
+    ci->map_type[0]=0;
+    ci->map_param[0]=calloc(1,sizeof(_mapping_set_short));
+    memcpy(ci->map_param[0],&_mapping_set_short,sizeof(_mapping_set_short));
+    ci->map_type[1]=0;
+    ci->map_param[1]=calloc(1,sizeof(_mapping_set_long));
+    memcpy(ci->map_param[1],&_mapping_set_long,sizeof(_mapping_set_long));
+
+    return(0);
+  }
+  return(OV_EINVAL);
+}
+
+static int vorbis_encode_floor_init(vorbis_info *vi,double q,int block,
+				    static_codebook    ***books, 
+				    vorbis_info_floor1 *in, 
+				    ...){
+  int x[11],i,k,iq=rint(q*10);
+  vorbis_info_floor1 *f=calloc(1,sizeof(*f));
+  codec_setup_info *ci=vi->codec_setup;
+  va_list ap;
+
+  va_start(ap,in);
+  for(i=0;i<11;i++)
+    x[i]=va_arg(ap,int);
+  va_end(ap);
+
+  memcpy(f,in+x[iq],sizeof(*f));
+  /* fill in the lowpass field, even if it's temporary */
+  f->n=ci->blocksizes[block]>>1;
+
+  /* books */
+  {
+    int partitions=f->partitions;
+    int maxclass=-1;
+    int maxbook=-1;
+    for(i=0;i<partitions;i++)
+      if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
+    for(i=0;i<=maxclass;i++){
+      if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
+      f->class_book[i]+=ci->books;
+      for(k=0;k<(1<<f->class_subs[i]);k++){
+	if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
+	if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
+      }
+    }
+
+    for(i=0;i<=maxbook;i++)
+      ci->book_param[ci->books++]=books[x[iq]][i];
+  }
+
+  /* for now, we're only using floor 1 */
+  ci->floor_type[ci->floors]=1;
+  ci->floor_param[ci->floors]=f;
+  ci->floors++;
+
+  return(0);
+}
+
+static int vorbis_encode_global_psych_init(vorbis_info *vi,double q,
+					   vorbis_info_psy_global *in, ...){
+  int i,iq=q*10;
+  double x[11],dq;
+  codec_setup_info *ci=vi->codec_setup;
+  vorbis_info_psy_global *g=&ci->psy_g_param;
+  va_list ap;
+  
+  va_start(ap,in);
+  for(i=0;i<11;i++)
+    x[i]=va_arg(ap,double);
+  va_end(ap);
+
+  if(iq==10){
+    iq=9;
+    dq=1.;
+  }else{
+    dq=q*10.-iq;
+  }
+
+  memcpy(g,in+(int)x[iq],sizeof(*g));
+
+  dq=x[iq]*(1.-dq)+x[iq+1]*dq;
+  iq=(int)dq;
+  dq-=iq;
+  if(dq==0 && iq>0){
+    iq--;
+    dq=1.;
+  }
+
+  /* interpolate the trigger threshholds */
+  for(i=0;i<4;i++){
+    g->preecho_thresh[i]=in[iq].preecho_thresh[i]*(1.-dq)+in[iq+1].preecho_thresh[i]*dq;
+    g->postecho_thresh[i]=in[iq].postecho_thresh[i]*(1.-dq)+in[iq+1].postecho_thresh[i]*dq;
+  }
+  g->ampmax_att_per_sec=in[iq].ampmax_att_per_sec*(1.-dq)+in[iq+1].ampmax_att_per_sec*dq;
+  return(0);
+}
+
+static int vorbis_encode_psyset_init(vorbis_info *vi,double q,int block,
+					   vorbis_info_psy *in){
+  int iq=q*10;
+  double dq;
+  codec_setup_info *ci=vi->codec_setup;
+  vorbis_info_psy *p=ci->psy_param[block];
+
+  if(iq==10){
+    iq=9;
+    dq=1.;
+  }else{
+    dq=q*10.-iq;
+  }
+
+  if(block>=ci->psys)
+    ci->psys=block+1;
+  if(!p){
+    p=calloc(1,sizeof(*p));
+    ci->psy_param[block]=p;
+  }
+
+  memcpy(p,in+(int)(q*10.),sizeof(*p));
+  
+  p->ath_adjatt=in[iq].ath_adjatt*(1.-dq)+in[iq+1].ath_adjatt*dq;
+  p->ath_maxatt=in[iq].ath_maxatt*(1.-dq)+in[iq+1].ath_maxatt*dq;
+
+  p->tone_masteratt=in[iq].tone_masteratt*(1.-dq)+in[iq+1].tone_masteratt*dq;
+  p->tone_guard=in[iq].tone_guard*(1.-dq)+in[iq+1].tone_guard*dq;
+  p->tone_abs_limit=in[iq].tone_abs_limit*(1.-dq)+in[iq+1].tone_abs_limit*dq;
+
+  p->noisemaxsupp=in[iq].noisemaxsupp*(1.-dq)+in[iq+1].noisemaxsupp*dq;
+
+  return(0);
+}
+
+static int vorbis_encode_compand_init(vorbis_info *vi,double q,int block,
+					   float in[][NOISE_COMPAND_LEVELS], ...){
+  int i,iq=q*10;
+  double x[11],dq;
+  codec_setup_info *ci=vi->codec_setup;
+  vorbis_info_psy *p=ci->psy_param[block];
+  va_list ap;
+  
+  va_start(ap,in);
+  for(i=0;i<11;i++)
+    x[i]=va_arg(ap,double);
+  va_end(ap);
+
+  if(iq==10){
+    iq=9;
+    dq=1.;
+  }else{
+    dq=q*10.-iq;
+  }
+
+  dq=x[iq]*(1.-dq)+x[iq+1]*dq;
+  iq=(int)dq;
+  dq-=iq;
+  if(dq==0 && iq>0){
+    iq--;
+    dq=1.;
+  }
+
+  /* interpolate the compander settings */
+  for(i=0;i<NOISE_COMPAND_LEVELS;i++)
+    p->noisecompand[i]=in[iq][i]*(1.-dq)+in[iq+1][i]*dq;
+  return(0);
+}
+
+static int vorbis_encode_tonemask_init(vorbis_info *vi,double q,int block,
+				       vp_adjblock *in){
+  int i,j,iq=q*5.;
+  double dq;
+  codec_setup_info *ci=vi->codec_setup;
+  vorbis_info_psy *p=ci->psy_param[block];
+
+  if(iq==5){
+    iq=5;
+    dq=1.;
+  }else{
+    dq=q*5.-iq;
+  }
+
+  for(i=0;i<P_BANDS;i++)
+    for(j=0;j<P_LEVELS;j++)
+      p->toneatt.block[i][j]=(j<4?4:j)*-10.+
+	in[iq].block[i][j]*(1.-dq)+in[iq+1].block[i][j]*dq;
+  return(0);
+}
+
+static int vorbis_encode_peak_init(vorbis_info *vi,double q,int block,
+				   vp_adjblock *in){
+  int i,j,iq=q*5.;
+  double dq;
+  codec_setup_info *ci=vi->codec_setup;
+  vorbis_info_psy *p=ci->psy_param[block];
+
+  if(iq==5){
+    iq=5;
+    dq=1.;
+  }else{
+    dq=q*5.-iq;
+  }
+
+  for(i=0;i<P_BANDS;i++)
+    for(j=0;j<P_LEVELS;j++)
+      p->peakatt.block[i][j]=(j<4?4:j)*-10.+
+	in[iq].block[i][j]*(1.-dq)+in[iq+1].block[i][j]*dq;
+  return(0);
+}
+
+static int vorbis_encode_noisebias_init(vorbis_info *vi,double q,int block,
+					int in[][17],int guard[33]){
+  int i,iq=q*10;
+  double dq;
+  codec_setup_info *ci=vi->codec_setup;
+  vorbis_info_psy *p=ci->psy_param[block];
+
+  if(iq==10){
+    iq=9;
+    dq=1.;
+  }else{
+    dq=q*10.-iq;
+  }
+
+  p->noisewindowlomin=guard[iq*3];
+  p->noisewindowhimin=guard[iq*3+1];
+  p->noisewindowfixed=guard[iq*3+2];
 
-/* deepcopy all but the codebooks; in this usage, they're static
-   (don't copy as they could be big) */
-static void codec_setup_partialcopy(codec_setup_info *ci,
-				 codec_setup_info *cs){
-  int i;
+  for(i=0;i<P_BANDS;i++)
+    p->noiseoff[i]=in[iq][i]*(1.-dq)+in[iq+1][i]*dq;
+  return(0);
+}
 
-  memcpy(ci,cs,sizeof(*ci)); /* to get the flat numbers */
+static int vorbis_encode_ath_init(vorbis_info *vi,double q,int block,
+				  float in[][27], ...){
+  int i,iq=q*10;
+  double x[11],dq;
+  codec_setup_info *ci=vi->codec_setup;
+  vorbis_info_psy *p=ci->psy_param[block];
+  va_list ap;
+  
+  va_start(ap,in);
+  for(i=0;i<11;i++)
+    x[i]=va_arg(ap,double);
+  va_end(ap);
+
+  if(iq==10){
+    iq=9;
+    dq=1.;
+  }else{
+    dq=q*10.-iq;
+  }
 
-  /* codebooks */
-  for(i=0;i<ci->books;i++){
-    ci->book_param[i]=cs->book_param[i];
+  dq=x[iq]*(1.-dq)+x[iq+1]*dq;
+  iq=(int)dq;
+  dq-=iq;
+  if(dq==0 && iq>0){
+    iq--;
+    dq=1.;
   }
+
+  for(i=0;i<27;i++)
+    p->ath[i]=in[iq][i]*(1.-dq)+in[iq+1][i]*dq;
+  return(0);
+}
 
-  /* time backend settings */
-  for(i=0;i<ci->times;i++){
-    ci->time_param[i]=_time_P[ci->time_type[i]]->
-      copy_info(cs->time_param[i]);
+static int vorbis_encode_residue_init(vorbis_info *vi,double q,int block,
+				      int coupled_p,
+				      int stereo_backfill_p,
+				      int residue_backfill_p,
+				      vorbis_residue_template *in, ...){
+
+  int i,iq=q*10;
+  int a[11];
+  double c[11];
+  int n;
+  int partition_position;
+  int res_position;
+  int iterations=1;
+  int amplitude_select;
+
+  codec_setup_info *ci=vi->codec_setup;
+  vorbis_info_residue0 *r;
+  vorbis_info_psy *psy=ci->psy_param[block*2];
+  va_list ap;
+  
+  va_start(ap,in);
+  for(i=0;i<11;i++)
+    a[i]=va_arg(ap,int);
+  for(i=0;i<11;i++)
+    c[i]=va_arg(ap,double);
+  va_end(ap);
+  
+  /* may be re-called due to ctl */
+  if(ci->residue_param[block])
+    /* free preexisting instance */
+    residue_free_info(ci->residue_param[block],ci->residue_type[block]);
+
+  r=ci->residue_param[block]=malloc(sizeof(*r));
+  memcpy(r,in[iq].res[block],sizeof(*r));
+  if(ci->residues<=block)ci->residues=block+1;
+
+  if(block){
+    r->grouping=32;
+  }else{
+    r->grouping=16;
   }
 
-  /* floor backend settings */
-  for(i=0;i<ci->floors;i++){
-    ci->floor_param[i]=_floor_P[ci->floor_type[i]]->
-      copy_info(cs->floor_param[i]);
+  /* for uncoupled, we use type 1, else type 2 */
+  if(coupled_p){
+    ci->residue_type[block]=2;
+  }else{
+    ci->residue_type[block]=1;
   }
 
-  /* residue backend settings */
-  for(i=0;i<ci->residues;i++){
-    ci->residue_param[i]=_residue_P[ci->residue_type[i]]->
-      copy_info(cs->residue_param[i]);
+  switch(ci->residue_type[block]){
+  case 1:
+    n=r->end=ci->blocksizes[block?1:0]>>1; /* to be adjusted by lowpass later */
+    partition_position=rint((double)c[iq]*1000/(vi->rate/2)*n/r->grouping);
+    res_position=partition_position*r->grouping;
+    break;
+  case 2:
+    n=r->end=(ci->blocksizes[block?1:0]>>1)*vi->channels; /* to be adjusted by lowpass later */
+    partition_position=rint((double)c[iq]*1000/(vi->rate/2)*n/r->grouping);
+    res_position=partition_position*r->grouping/vi->channels;
+    break;
   }
+
+  for(i=0;i<r->partitions;i++)
+    if(r->blimit[i]<0)r->blimit[i]=partition_position;
+  
+  if(coupled_p){
+    int k;
+    vorbis_info_mapping0 *map=ci->map_param[block];
+
+    map->coupling_steps=1;
+    map->coupling_mag[0]=0;
+    map->coupling_ang[0]=1;
+
+    psy->couple_pass[0].granulem=1.;
+    psy->couple_pass[0].igranulem=1.;
+
+    psy->couple_pass[0].couple_pass[0].limit=res_position;
+    psy->couple_pass[0].couple_pass[0].outofphase_redundant_flip_p=1;
+    psy->couple_pass[0].couple_pass[0].outofphase_requant_limit=9e10;
+    psy->couple_pass[0].couple_pass[0].amppost_point=0;
+    psy->couple_pass[0].couple_pass[1].limit=9999;
+    psy->couple_pass[0].couple_pass[1].outofphase_redundant_flip_p=1;
+    psy->couple_pass[0].couple_pass[1].outofphase_requant_limit=9e10;
+    psy->couple_pass[0].couple_pass[1].amppost_point=stereo_threshholds[a[iq]];
+    amplitude_select=a[iq];
+
+    for(i=0;i<r->partitions;i++)
+      for(k=0;k<3;k++)
+	if(in[iq].books_base[a[iq]][i][k])
+	  r->secondstages[i]|=(1<<k);
+      
+    ci->passlimit[0]=3;
+    
+    if(stereo_backfill_p && a[iq]){
+      memcpy(psy->couple_pass+iterations,psy->couple_pass+iterations-1,
+	     sizeof(*psy->couple_pass));
+      amplitude_select=a[iq]-1;
+      psy->couple_pass[1].couple_pass[1].amppost_point=stereo_threshholds[a[iq]-1];
+      ci->passlimit[1]=4;
+      for(i=0;i<r->partitions;i++)
+	if(in[iq].books_stereo_backfill[a[iq]-1][i])
+	  r->secondstages[i]|=8;
+      iterations++;
+    }
+
+    if(residue_backfill_p){
+      memcpy(psy->couple_pass+iterations,psy->couple_pass+iterations-1,
+	     sizeof(*psy->couple_pass));
+      psy->couple_pass[iterations].granulem=.333333333;
+      psy->couple_pass[iterations].igranulem=3.;
+      for(i=0;i<r->partitions;i++)
+	if(in[iq].books_residue_backfill[amplitude_select][i][0])
+	  r->secondstages[i]|=(1<<(iterations+2));
+      ci->passlimit[iterations]=ci->passlimit[iterations-1]+1;
+      iterations++;
+
+      memcpy(psy->couple_pass+iterations,psy->couple_pass+iterations-1,
+	     sizeof(*psy->couple_pass));
+      psy->couple_pass[iterations].granulem=.1111111111;
+      psy->couple_pass[iterations].igranulem=9.;
+      for(i=0;i<r->partitions;i++)
+	if(in[iq].books_residue_backfill[amplitude_select][i][1])
+	  r->secondstages[i]|=(1<<(iterations+2));
+      ci->passlimit[iterations]=ci->passlimit[iterations-1]+1;
+      iterations++;
+    }
+    ci->coupling_passes=iterations;
 
-  /* map backend settings */
-  for(i=0;i<ci->maps;i++){
-    ci->map_param[i]=_mapping_P[ci->map_type[i]]->
-      copy_info(cs->map_param[i]);
+  }else{
+    ci->passlimit[0]=3;
+
+    if(residue_backfill_p){
+      for(i=0;i<r->partitions;i++){
+	if(in[iq].books_residue_backfill[amplitude_select][i][0])
+	  r->secondstages[i]|=8;
+	if(in[iq].books_residue_backfill[amplitude_select][i][1])
+	  r->secondstages[i]|=16;
+      }
+      ci->passlimit[1]=4;
+      ci->passlimit[2]=5;
+      ci->coupling_passes=3;
+    }else
+      ci->coupling_passes=1;
   }
+
+  memcpy(&ci->psy_param[block*2+1]->couple_pass,
+	 &ci->psy_param[block*2]->couple_pass,
+	 sizeof(psy->couple_pass[0]));
   
-  /* mode settings */
-  for(i=0;i<ci->modes;i++){
-    ci->mode_param[i]=_ogg_calloc(1,sizeof(*ci->mode_param[i]));
-    ci->mode_param[i]->blockflag=cs->mode_param[i]->blockflag;
-    ci->mode_param[i]->windowtype=cs->mode_param[i]->windowtype;
-    ci->mode_param[i]->transformtype=cs->mode_param[i]->transformtype;
-    ci->mode_param[i]->mapping=cs->mode_param[i]->mapping;
+  /* fill in all the books */
+  {
+    int booklist=0,k;
+    r->groupbook=ci->books;
+    ci->book_param[ci->books++]=in[iq].book_aux[block];
+    for(i=0;i<r->partitions;i++){
+      for(k=0;k<3;k++){
+	if(in[iq].books_base[a[iq]][i][k]){
+	  r->booklist[booklist++]=ci->books;
+	  ci->book_param[ci->books++]=in[iq].books_base[a[iq]][i][k];
+      }
+      if(coupled_p && stereo_backfill_p && a[iq] &&
+	 in[iq].books_stereo_backfill[a[iq]][i]){
+	  r->booklist[booklist++]=ci->books;
+	  ci->book_param[ci->books++]=in[iq].books_stereo_backfill[a[iq]][i];
+      }
+      if(residue_backfill_p)
+	for(k=0;k<2;k++){
+	  if(in[iq].books_residue_backfill[amplitude_select][i][k]){
+	    r->booklist[booklist++]=ci->books;
+	    ci->book_param[ci->books++]=in[iq].books_residue_backfill[amplitude_select][i][k];
+	  }
+	}
+      }
+    }
   }
+
+  return(0);
+}      
 
-  /* psy settings */
-  for(i=0;i<ci->psys;i++){
-    ci->psy_param[i]=_vi_psy_copy(cs->psy_param[i]);
+static int vorbis_encode_lowpass_init(vorbis_info *vi,double q,int block,...){
+  int i,iq=q*10;
+  double x[11],dq;
+  double freq;
+  codec_setup_info *ci=vi->codec_setup;
+  vorbis_info_floor1 *f=ci->floor_param[block];
+  vorbis_info_residue0 *r=ci->residue_param[block];
+  int blocksize=ci->blocksizes[block]>>1;
+  double nyq=vi->rate/2.;
+  va_list ap;
+  
+  va_start(ap,block);
+  for(i=0;i<11;i++)
+    x[i]=va_arg(ap,double);
+  va_end(ap);
+
+  if(iq==10){
+    iq=9;
+    dq=1.;
+  }else{
+    dq=q*10.-iq;
   }
+  
+  freq=(x[iq]*(1.-dq)+x[iq+1]*dq)*1000.;
 
+  /* lowpass needs to be set in the floor and the residue. */
+
+  /* in the floor, the granularity can be very fine; it doesn't alter
+     the encoding structure, only the samples used to fit the floor
+     approximation */
+  f->n=freq/nyq*blocksize;
+
+  /* in the residue, we're constrained, physically, by partition
+     boundaries.  We still lowpass 'wherever', but we have to round up
+     here to next boundary, or the vorbis spec will round it *down* to
+     previous boundary in encode/decode */
+  if(ci->residue_type[block]==2)
+    r->end=rint((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
+      r->grouping;
+  else
+    r->end=rint((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
+      r->grouping;
+  return(0);
 }
 
 /* encoders will need to use vorbis_info_init beforehand and call
@@ -91,18 +589,110 @@
                            
                            float base_quality /* 0. to 1. */
                            ){
+  int ret=0;
 
-  switch(channels){
-  case 2:
-    return(OV_EIMPL);
+  base_quality=.4;
 
+  if(rate>40000){
+    ret|=vorbis_encode_toplevel_init(vi,256,2048,channels,rate);
+    ret|=vorbis_encode_floor_init(vi,base_quality,0,_floor_44_128_books,_floor_44_128,
+				  0,1,1,2,2,2,2,2,2,2,2);
+    ret|=vorbis_encode_floor_init(vi,base_quality,1,_floor_44_1024_books,_floor_44_1024,
+				  0,0,0,0,0,0,0,0,0,0,0);
+    
+    ret|=vorbis_encode_global_psych_init(vi,base_quality,_psy_global_44,
+					 0., 1., 1.5, 2., 2., 2., 2., 2., 2., 2., 2.);
+    
+    ret|=vorbis_encode_psyset_init(vi,base_quality,0,_psy_settings);
+    ret|=vorbis_encode_psyset_init(vi,base_quality,1,_psy_settings);
+    ret|=vorbis_encode_psyset_init(vi,base_quality,2,_psy_settings);
+    ret|=vorbis_encode_psyset_init(vi,base_quality,3,_psy_settings);
+
+    ret|=vorbis_encode_tonemask_init(vi,base_quality,0,_vp_tonemask_adj_otherblock);
+    ret|=vorbis_encode_tonemask_init(vi,base_quality,1,_vp_tonemask_adj_otherblock);
+    ret|=vorbis_encode_tonemask_init(vi,base_quality,2,_vp_tonemask_adj_otherblock);
+    ret|=vorbis_encode_tonemask_init(vi,base_quality,3,_vp_tonemask_adj_longblock);
+
+    ret|=vorbis_encode_compand_init(vi,base_quality,0,_psy_compand_44_short,
+				    1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.);
+    ret|=vorbis_encode_compand_init(vi,base_quality,1,_psy_compand_44_short,
+				    1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.);
+    ret|=vorbis_encode_compand_init(vi,base_quality,2,_psy_compand_44,
+				    1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.);
+    ret|=vorbis_encode_compand_init(vi,base_quality,3,_psy_compand_44,
+				    1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.);
+    
+    ret|=vorbis_encode_peak_init(vi,base_quality,0,_vp_peakguard);
+    ret|=vorbis_encode_peak_init(vi,base_quality,1,_vp_peakguard);
+    ret|=vorbis_encode_peak_init(vi,base_quality,2,_vp_peakguard);
+    ret|=vorbis_encode_peak_init(vi,base_quality,3,_vp_peakguard);
+    
+    ret|=vorbis_encode_noisebias_init(vi,base_quality,0,_psy_noisebias_impulse,
+				      _psy_noiseguards_short);
+    ret|=vorbis_encode_noisebias_init(vi,base_quality,1,_psy_noisebias_other,
+				      _psy_noiseguards_short);
+    ret|=vorbis_encode_noisebias_init(vi,base_quality,2,_psy_noisebias_other,
+				      _psy_noiseguards_long);
+    ret|=vorbis_encode_noisebias_init(vi,base_quality,3,_psy_noisebias_long,
+				      _psy_noiseguards_long);
+
+    ret|=vorbis_encode_ath_init(vi,base_quality,0,ATH_Bark_dB,
+				0., 0., 0., 0., .2, .5, 1., 1., 1.5, 2., 2.);
+    ret|=vorbis_encode_ath_init(vi,base_quality,1,ATH_Bark_dB,
+				0., 0., 0., 0., .2, .5, 1., 1., 1.5, 2., 2.);
+    ret|=vorbis_encode_ath_init(vi,base_quality,2,ATH_Bark_dB,
+				0., 0., 0., 0., .2, .5, 1., 1., 1.5, 2., 2.);
+    ret|=vorbis_encode_ath_init(vi,base_quality,3,ATH_Bark_dB,
+				0., 0., 0., 0., .2, .5, 1., 1., 1.5, 2., 2.);
+
+    if(ret){
+      vorbis_info_clear(vi);
+      return ret; 
+    }
 
-    break;
-  default:
+    switch(channels){
+    case 2:
+      /* setup specific to stereo coupling */
+
+      /* unmanaged, one iteration residue setup */
+      ret|=vorbis_encode_residue_init(vi,base_quality,0,
+				      1, /* coupled */
+				      0, /* no mid stereo backfill */
+				      0, /* no residue backfill */
+				      _residue_template_44_stereo,
+				      4,  3,  2,  2,   1,  0,  0,  0,  0,  0,  0,
+				      4., 6., 6., 6., 10., 6., 6., 6., 6., 6., 6.);
+      
+      ret|=vorbis_encode_residue_init(vi,base_quality,1,
+				      1, /* coupled */
+				      0, /* no mid stereo backfill */
+				      0, /* no residue backfill */
+				      _residue_template_44_stereo,
+				      4,  3,  2,   2,   1,  0,  0,  0,  0,  0,  0,
+				      6., 6., 6., 10., 10., 6., 6., 6., 6., 6., 6.);      
+
+      ret|=vorbis_encode_lowpass_init(vi,base_quality,0,
+				      15.1,15.8,16.5,17.9,20.5,
+				      999.,999.,999.,999.,999.,999.);
+      ret|=vorbis_encode_lowpass_init(vi,base_quality,1,
+				      15.1,15.8,16.5,17.9,20.5,
+				      999.,999.,999.,999.,999.,999.);
+      
+      return(ret);
+
+      break;
+    default:
+      return(OV_EIMPL);
+      
+      break;
+    }
+    return(0);
+  }else
     return(OV_EIMPL);
 
-    break;
-  }
+  if(ret)
+    vorbis_info_clear(vi);
+  return(ret);
 }
 
 
@@ -113,87 +703,21 @@
                        long max_bitrate,
                        long nominal_bitrate,
                        long min_bitrate){
-
-  long bpch;
-  int i,j;
-  codec_setup_info *ci=vi->codec_setup;
-  codec_setup_info *mode=NULL;
-  if(!ci)return(OV_EFAULT);
-
-  vi->version=0;
-  vi->channels=channels;
-  vi->rate=rate;
-  
-  vi->bitrate_upper=max_bitrate;
-  vi->bitrate_nominal=nominal_bitrate;
-  vi->bitrate_lower=min_bitrate;
-  vi->bitrate_window=2;
 
-  /* copy a mode into our allocated storage */
-  bpch=nominal_bitrate/channels;
+  /* it's temporary while I do the merge; relax */
+  return(vorbis_encode_init_vbr(vi,channels,rate, .4));
 
-#if 0
-  switch(channels){
-  case 2:
-/*	if(rate>40000){	*/
-
-    if(bpch<35000){
-      mode=&info_44c_Z;
-    }else if(bpch<45000){
-      mode=&info_44c_Y;
-    }else if(bpch<55000){
-      mode=&info_44c_X;
-    }else if(bpch<75000){
-      mode=&info_44c_A;
-    }else if(bpch<90000){
-      mode=&info_44c_B;
-    }else if(bpch<110000){
-      mode=&info_44c_C;
-    }else if(bpch<160000){
-      mode=&info_44c_D;
-    }else{
-      mode=&info_44c_E;
-    }
-/*	}	*/
+  return(OV_EIMPL);
+}
 
-    break;
-  default:
+int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
+  return(OV_EIMPL);
+}
+		       
 
-    if(bpch<40000){
-      mode=&info_44_Z;
-    }else if(bpch<50000){
-      mode=&info_44_Y;
-    }else if(bpch<70000){
-      mode=&info_44_X;
-    }else if(bpch<90000){
-      mode=&info_44_A;
-    }else if(bpch<120000){
-      mode=&info_44_B;
-    }else{
-      mode=&info_44_C;
-    }
-    break;
-  }
-#endif
 
-  mode=&info_44c_A;
 
-  /* now we have to deepcopy */
-  codec_setup_partialcopy(ci,mode);
 
-  /* adjust for sample rate */
-  /* we don't have any floor 0 modes anymore 
-  for(i=0;i<ci->floors;i++)
-    if(ci->floor_type[i]==0)
-    ((vorbis_info_floor0 *)(ci->floor_param[i]))->rate=rate; */
 
-  /* adjust for channels */
-  /* but all our mappings use submap zero now! */
 
-  return(0);
-}
 
-int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
-  return(OV_EIMPL);
-}
-		       

1.52      +115 -98   vorbis/lib/vorbisfile.c

Index: vorbisfile.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/vorbisfile.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- vorbisfile.c	2001/11/12 13:41:10	1.51
+++ vorbisfile.c	2001/12/12 09:45:26	1.52
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.c,v 1.51 2001/11/12 13:41:10 msmith Exp $
+ last mod: $Id: vorbisfile.c,v 1.52 2001/12/12 09:45:26 xiphmont Exp $
 
  ********************************************************************/
 
@@ -1125,7 +1125,6 @@
 int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
   int thisblock,lastblock=0;
   int ret=ov_pcm_seek_page(vf,pos);
-  codec_setup_info *ci=vf->vi->codec_setup;
   if(ret<0)return(ret);
 
   /* discard leading packets we don't need for the lapping of the
@@ -1140,7 +1139,8 @@
       thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
       if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
 
-      if(vf->pcm_offset+((thisblock+ci->blocksizes[1])>>2)>=pos)break;
+      if(vf->pcm_offset+((thisblock+
+			  vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
 
       ogg_stream_packetout(&vf->os,NULL);
       
@@ -1374,10 +1374,7 @@
 
             *section) set to the logical bitstream number */
 
-long ov_read(OggVorbis_File *vf,char *buffer,int length,
-		    int bigendianp,int word,int sgned,int *bitstream){
-  int i,j;
-  int host_endian = host_is_big_endian();
+long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int *bitstream){
 
   if(vf->ready_state<OPENED)return(OV_EINVAL);
 
@@ -1386,100 +1383,12 @@
       float **pcm;
       long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
       if(samples){
-	/* yay! proceed to pack data into the byte buffer */
-
-	long channels=ov_info(vf,-1)->channels;
-	long bytespersample=word * channels;
-	vorbis_fpu_control fpu;
-	if(samples>length/bytespersample)samples=length/bytespersample;
-	
-	/* a tight loop to pack each size */
-	{
-	  int val;
-	  if(word==1){
-	    int off=(sgned?0:128);
-	    vorbis_fpu_setround(&fpu);
-	    for(j=0;j<samples;j++)
-	      for(i=0;i<channels;i++){
-		val=vorbis_ftoi(pcm[i][j]*128.f);
-		if(val>127)val=127;
-		else if(val<-128)val=-128;
-		*buffer++=val+off;
-	      }
-	    vorbis_fpu_restore(fpu);
-	  }else{
-	    int off=(sgned?0:32768);
-
-	    if(host_endian==bigendianp){
-	      if(sgned){
-
-		vorbis_fpu_setround(&fpu);
-		for(i=0;i<channels;i++) { /* It's faster in this order */
-		  float *src=pcm[i];
-		  short *dest=((short *)buffer)+i;
-		  for(j=0;j<samples;j++) {
-		    val=vorbis_ftoi(src[j]*32768.f);
-		    if(val>32767)val=32767;
-		    else if(val<-32768)val=-32768;
-		    *dest=val;
-		    dest+=channels;
-		  }
-		}
-		vorbis_fpu_restore(fpu);
-
-	      }else{
-
-		vorbis_fpu_setround(&fpu);
-		for(i=0;i<channels;i++) {
-		  float *src=pcm[i];
-		  short *dest=((short *)buffer)+i;
-		  for(j=0;j<samples;j++) {
-		    val=vorbis_ftoi(src[j]*32768.f);
-		    if(val>32767)val=32767;
-		    else if(val<-32768)val=-32768;
-		    *dest=val+off;
-		    dest+=channels;
-		  }
-		}
-		vorbis_fpu_restore(fpu);
-
-	      }
-	    }else if(bigendianp){
-
-	      vorbis_fpu_setround(&fpu);
-	      for(j=0;j<samples;j++)
-		for(i=0;i<channels;i++){
-		  val=vorbis_ftoi(pcm[i][j]*32768.f);
-		  if(val>32767)val=32767;
-		  else if(val<-32768)val=-32768;
-		  val+=off;
-		  *buffer++=(val>>8);
-		  *buffer++=(val&0xff);
-		}
-	      vorbis_fpu_restore(fpu);
-
-	    }else{
-	      int val;
-	      vorbis_fpu_setround(&fpu);
-	      for(j=0;j<samples;j++)
-	 	for(i=0;i<channels;i++){
-		  val=vorbis_ftoi(pcm[i][j]*32768.f);
-		  if(val>32767)val=32767;
-		  else if(val<-32768)val=-32768;
-		  val+=off;
-		  *buffer++=(val&0xff);
-		  *buffer++=(val>>8);
-	  	}
-	      vorbis_fpu_restore(fpu);  
-
-	    }
-	  }
-	}
-	
+	if(pcm_channels)*pcm_channels=pcm;
         vorbis_synthesis_read(&vf->vd,samples);
         vf->pcm_offset+=samples;
         if(bitstream)*bitstream=vf->current_link;
-	return(samples*bytespersample);
+	return samples;
+
       }
     }
 
@@ -1490,6 +1399,114 @@
       if(ret<=0)return(ret);
     }
 
+  }
+}
+
+long ov_read(OggVorbis_File *vf,char *buffer,int length,
+		    int bigendianp,int word,int sgned,int *bitstream){
+  int i,j;
+  int host_endian = host_is_big_endian();
+
+  float **pcm;
+  long samples=ov_read_float(vf,&pcm,bitstream);
+  if(samples>0){
+  
+    /* yay! proceed to pack data into the byte buffer */
+    
+    long channels=ov_info(vf,-1)->channels;
+    long bytespersample=word * channels;
+    vorbis_fpu_control fpu;
+    if(samples>length/bytespersample)samples=length/bytespersample;
+    
+    /* a tight loop to pack each size */
+    {
+      int val;
+      if(word==1){
+	int off=(sgned?0:128);
+	vorbis_fpu_setround(&fpu);
+	for(j=0;j<samples;j++)
+	  for(i=0;i<channels;i++){
+	    val=vorbis_ftoi(pcm[i][j]*128.f);
+	    if(val>127)val=127;
+	    else if(val<-128)val=-128;
+	    *buffer++=val+off;
+	  }
+	vorbis_fpu_restore(fpu);
+      }else{
+	int off=(sgned?0:32768);
+	
+	if(host_endian==bigendianp){
+	  if(sgned){
+	    
+	    vorbis_fpu_setround(&fpu);
+	    for(i=0;i<channels;i++) { /* It's faster in this order */
+	      float *src=pcm[i];
+	      short *dest=((short *)buffer)+i;
+	      for(j=0;j<samples;j++) {
+		val=vorbis_ftoi(src[j]*32768.f);
+		if(val>32767)val=32767;
+		else if(val<-32768)val=-32768;
+		*dest=val;
+		dest+=channels;
+	      }
+	    }
+	    vorbis_fpu_restore(fpu);
+	    
+	  }else{
+	    
+	    vorbis_fpu_setround(&fpu);
+	    for(i=0;i<channels;i++) {
+	      float *src=pcm[i];
+	      short *dest=((short *)buffer)+i;
+	      for(j=0;j<samples;j++) {
+		val=vorbis_ftoi(src[j]*32768.f);
+		if(val>32767)val=32767;
+		else if(val<-32768)val=-32768;
+		*dest=val+off;
+		dest+=channels;
+	      }
+	    }
+	    vorbis_fpu_restore(fpu);
+	    
+	  }
+	}else if(bigendianp){
+	  
+	  vorbis_fpu_setround(&fpu);
+	  for(j=0;j<samples;j++)
+	    for(i=0;i<channels;i++){
+	      val=vorbis_ftoi(pcm[i][j]*32768.f);
+	      if(val>32767)val=32767;
+	      else if(val<-32768)val=-32768;
+	      val+=off;
+	      *buffer++=(val>>8);
+	      *buffer++=(val&0xff);
+	    }
+	  vorbis_fpu_restore(fpu);
+	  
+	}else{
+	  int val;
+	  vorbis_fpu_setround(&fpu);
+	  for(j=0;j<samples;j++)
+	    for(i=0;i<channels;i++){
+	      val=vorbis_ftoi(pcm[i][j]*32768.f);
+	      if(val>32767)val=32767;
+	      else if(val<-32768)val=-32768;
+	      val+=off;
+	      *buffer++=(val&0xff);
+	      *buffer++=(val>>8);
+	  	}
+	  vorbis_fpu_restore(fpu);  
+	  
+	}
+      }
+    }
+    
+    vorbis_synthesis_read(&vf->vd,samples);
+    vf->pcm_offset+=samples;
+    if(bitstream)*bitstream=vf->current_link;
+    return(samples*bytespersample);
+  }else{
+    return(samples);
   }
 }
 

1.2       +588 -0    vorbis/lib/bitrate.c

1.2       +96 -0     vorbis/lib/bitrate.h

1.2       +23 -0     vorbis/lib/registry-api.h

1.11      +1 -1      vorbis/lib/books/Makefile.am

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/books/Makefile.am,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Makefile.am	2001/08/13 11:38:35	1.10
+++ Makefile.am	2001/12/12 09:45:30	1.11
@@ -2,4 +2,4 @@
 
 AUTOMAKE_OPTIONS = foreign
 
-EXTRA_DIST =  line_1024x31_0sub0.vqh line_1024x31_0sub1.vqh line_1024x31_1sub0.vqh line_1024x31_1sub1.vqh line_1024x31_2sub1.vqh line_1024x31_2sub2.vqh line_1024x31_2sub3.vqh line_1024x31_3sub1.vqh line_1024x31_3sub2.vqh line_1024x31_3sub3.vqh line_1024x31_class0.vqh line_1024x31_class1.vqh line_1024x31_class2.vqh line_1024x31_class3.vqh line_128x19_0sub0.vqh line_128x19_1sub1.vqh line_128x19_1sub2.vqh line_128x19_1sub3.vqh line_128x19_2sub1.vqh line_128x19_2sub2.vqh line_128x19_2sub3.vqh line_128x19_class1.vqh line_128x19_class2.vqh line_128x7_0sub0.vqh line_128x7_1sub1.vqh line_128x7_1sub2.vqh line_128x7_1sub3.vqh line_128x7_2sub1.vqh line_128x7_2sub2.vqh line_128x7_2sub3.vqh line_128x7_class1.vqh line_128x7_class2.vqh lsp12_0.vqh lsp12_1.vqh lsp30_0.vqh lsp30_1.vqh lsp9_0.vqh lsp9_1.vqh res_22c_Z_1024aux.vqh res_22c_Z_128aux.vqh res_32c_Z_1024aux.vqh res_32c_Z_128aux.vqh res_44_A_1024aux.vqh res_44_A_128aux.vqh res_44_B_1024aux.vqh res_44_B_128aux.vqh res_44c_A_1024aux.vqh res_44c_A_128aux.vqh res_44c_B_
1024aux.vqh res_44c_B_128aux.vqh res_44c_C_1024aux.vqh res_44c_C_128aux.vqh res_44c_E_1024aux.vqh res_44c_E_128aux.vqh res_44c_X_1024aux.vqh res_44c_X_128aux.vqh res_44c_Y_1024aux.vqh res_44c_Y_128aux.vqh res_44c_Z_1024aux.vqh res_44c_Z_128aux.vqh res_44_Y_1024aux.vqh res_44_Y_128aux.vqh res_44_Z_1024aux.vqh res_44_Z_128aux.vqh res_Ac_1024_1.vqh res_Ac_1024_2.vqh res_Ac_1024_3.vqh res_Ac_1024_4.vqh res_Ac_1024_5.vqh res_Ac_1024_6.vqh res_Ac_1024_7a.vqh res_Ac_1024_7.vqh res_Ac_1024_8a.vqh res_Ac_1024_8.vqh res_Ac_1024_9a.vqh res_Ac_1024_9b.vqh res_Ac_1024_9.vqh res_Ac_1.vqh res_Ac_2.vqh res_Ac_3.vqh res_Ac_4.vqh res_Ac_5.vqh res_Ac_6.vqh res_Ac_7a.vqh res_Ac_7.vqh res_Ac_8a.vqh res_Ac_8.vqh res_Ac_9a.vqh res_Ac_9b.vqh res_Ac_9.vqh res_B_1.vqh res_B_2.vqh res_B_3.vqh res_B_4.vqh res_B_5a.vqh res_B_5.vqh res_B_6a.vqh res_B_6b.vqh res_B_6.vqh res_Bc_1.vqh res_Bc_2.vqh res_Bc_3.vqh res_Bc_4.vqh res_Bc_5.vqh res_Bc_6.vqh res_Bc_7a.vqh res_Bc_7.vqh res_Bc_8a.vqh res_Bc_8.vqh res_Bc_9a.vqh res_Bc_9b.vqh res_Bc_9.vq
h res_Cc_1.vqh res_Cc_2.vqh res_Cc_3.vqh res_Cc_4.vqh res_Cc_5.vqh res_Cc_6.vqh res_Cc_7.vqh res_Cc_8a.vqh res_Cc_8.vqh res_Cc_9a.vqh res_Cc_9b.vqh res_Cc_9.vqh res_Ec_1.vqh res_Ec_2.vqh res_Ec_3.vqh res_Ec_4.vqh res_Ec_5.vqh res_Ec_6.vqh res_Ec_7.vqh res_Ec_8a.vqh res_Ec_8.vqh res_Ec_9a.vqh res_Ec_9b.vqh res_Ec_9.vqh res_Xc_1.vqh res_Xc_2.vqh res_Xc_3.vqh res_Xc_4.vqh res_Xc_5.vqh res_Xc_6.vqh res_Xc_7.vqh res_Xc_8.vqh res_Xc_9a.vqh res_Xc_9b.vqh res_Xc_9.vqh res_Z_1.vqh res_Z_2.vqh res_Z_3.vqh res_Z_4.vqh res_Z_5.vqh res_Z_6a.vqh res_Z_6b.vqh res_Z_6.vqh res_Zc_1024aux.vqh res_Zc_128aux.vqh res_Zc_1.vqh res_Zc_2.vqh res_Zc_3.vqh res_Zc_4.vqh res_Zc_5.vqh res_Zc_6.vqh res_Zc_7.vqh res_Zc_8.vqh res_Zc_9a.vqh res_Zc_9b.vqh res_Zc_9.vqh temp26040.vqh
+

1.2       +40 -0     vorbis/lib/books/coupled/_44c0_long.vqh

1.2       +99 -0     vorbis/lib/books/coupled/_44c0_s0_p1_0.vqh

1.2       +70 -0     vorbis/lib/books/coupled/_44c0_s0_p2_0.vqh

1.2       +93 -0     vorbis/lib/books/coupled/_44c0_s0_p3_0.vqh

1.2       +86 -0     vorbis/lib/books/coupled/_44c0_s0_p4_0.vqh

1.2       +65 -0     vorbis/lib/books/coupled/_44c0_s0_p4_1.vqh

1.2       +63 -0     vorbis/lib/books/coupled/_44c0_s1_p5_0.vqh

1.2       +99 -0     vorbis/lib/books/coupled/_44c0_s1_p6_0.vqh

1.2       +70 -0     vorbis/lib/books/coupled/_44c0_s2_p6_0.vqh

1.2       +70 -0     vorbis/lib/books/coupled/_44c0_s2_p7_0.vqh

1.2       +65 -0     vorbis/lib/books/coupled/_44c0_s4_p7_0.vqh

1.2       +115 -0    vorbis/lib/books/coupled/_44c0_s4_p7_1.vqh

1.2       +63 -0     vorbis/lib/books/coupled/_44c0_s4_p7_2.vqh

1.2       +40 -0     vorbis/lib/books/coupled/_44c0_short.vqh

1.2       +40 -0     vorbis/lib/books/coupled/_44c1_long.vqh

1.2       +99 -0     vorbis/lib/books/coupled/_44c1_s0_p1_0.vqh

1.2       +70 -0     vorbis/lib/books/coupled/_44c1_s0_p2_0.vqh

1.2       +93 -0     vorbis/lib/books/coupled/_44c1_s0_p3_0.vqh

1.2       +86 -0     vorbis/lib/books/coupled/_44c1_s0_p4_0.vqh

1.2       +65 -0     vorbis/lib/books/coupled/_44c1_s0_p4_1.vqh

1.2       +63 -0     vorbis/lib/books/coupled/_44c1_s1_p5_0.vqh

1.2       +70 -0     vorbis/lib/books/coupled/_44c1_s2_p6_0.vqh

1.2       +65 -0     vorbis/lib/books/coupled/_44c1_s3_p7_0.vqh

1.2       +115 -0    vorbis/lib/books/coupled/_44c1_s3_p7_1.vqh

1.2       +63 -0     vorbis/lib/books/coupled/_44c1_s3_p7_2.vqh

1.2       +40 -0     vorbis/lib/books/coupled/_44c1_short.vqh

1.2       +40 -0     vorbis/lib/books/coupled/_44c2_long.vqh

1.2       +99 -0     vorbis/lib/books/coupled/_44c2_s0_p1_0.vqh

1.2       +70 -0     vorbis/lib/books/coupled/_44c2_s0_p2_0.vqh

1.2       +93 -0     vorbis/lib/books/coupled/_44c2_s0_p3_0.vqh

1.2       +86 -0     vorbis/lib/books/coupled/_44c2_s0_p4_0.vqh

1.2       +65 -0     vorbis/lib/books/coupled/_44c2_s0_p4_1.vqh

1.2       +63 -0     vorbis/lib/books/coupled/_44c2_s1_p5_0.vqh

1.2       +70 -0     vorbis/lib/books/coupled/_44c2_s2_p6_0.vqh

1.2       +65 -0     vorbis/lib/books/coupled/_44c2_s2_p7_0.vqh

1.2       +115 -0    vorbis/lib/books/coupled/_44c2_s2_p7_1.vqh

1.2       +63 -0     vorbis/lib/books/coupled/_44c2_s2_p7_2.vqh

1.2       +40 -0     vorbis/lib/books/coupled/_44c2_short.vqh

1.2       +40 -0     vorbis/lib/books/coupled/_44c3_long.vqh

1.2       +99 -0     vorbis/lib/books/coupled/_44c3_s0_p1_0.vqh

1.2       +70 -0     vorbis/lib/books/coupled/_44c3_s0_p2_0.vqh

1.2       +93 -0     vorbis/lib/books/coupled/_44c3_s0_p3_0.vqh

1.2       +86 -0     vorbis/lib/books/coupled/_44c3_s0_p4_0.vqh

1.2       +65 -0     vorbis/lib/books/coupled/_44c3_s0_p4_1.vqh

1.2       +63 -0     vorbis/lib/books/coupled/_44c3_s1_p5_0.vqh

1.2       +70 -0     vorbis/lib/books/coupled/_44c3_s2_p6_0.vqh

1.2       +65 -0     vorbis/lib/books/coupled/_44c3_s2_p7_0.vqh

1.2       +115 -0    vorbis/lib/books/coupled/_44c3_s2_p7_1.vqh

1.2       +63 -0     vorbis/lib/books/coupled/_44c3_s2_p7_2.vqh

1.2       +40 -0     vorbis/lib/books/coupled/_44c3_short.vqh

1.2       +43 -0     vorbis/lib/books/coupled/_44c4_long.vqh

1.2       +99 -0     vorbis/lib/books/coupled/_44c4_s0_p1_0.vqh

1.2       +70 -0     vorbis/lib/books/coupled/_44c4_s0_p3_0.vqh

1.2       +93 -0     vorbis/lib/books/coupled/_44c4_s0_p5_0.vqh

1.2       +63 -0     vorbis/lib/books/coupled/_44c4_s1_p2_0.vqh

1.2       +99 -0     vorbis/lib/books/coupled/_44c4_s1_p4_0.vqh

1.2       +70 -0     vorbis/lib/books/coupled/_44c4_s1_p6_0.vqh

1.2       +80 -0     vorbis/lib/books/coupled/_44c4_s1_p7_0.vqh

1.2       +61 -0     vorbis/lib/books/coupled/_44c4_s1_p7_1.vqh

1.2       +80 -0     vorbis/lib/books/coupled/_44c4_s1_p8_0.vqh

1.2       +80 -0     vorbis/lib/books/coupled/_44c4_s1_p8_1.vqh

1.2       +80 -0     vorbis/lib/books/coupled/_44c4_s1_p9_0.vqh

1.2       +80 -0     vorbis/lib/books/coupled/_44c4_s1_p9_1.vqh

1.2       +80 -0     vorbis/lib/books/coupled/_44c4_s1_p9_2.vqh

1.2       +43 -0     vorbis/lib/books/coupled/_44c4_short.vqh

1.2       +38 -0     vorbis/lib/books/floor/line_1024x31_0sub0.vqh

1.2       +44 -0     vorbis/lib/books/floor/line_1024x31_0sub1.vqh

1.2       +38 -0     vorbis/lib/books/floor/line_1024x31_1sub0.vqh

1.2       +44 -0     vorbis/lib/books/floor/line_1024x31_1sub1.vqh

1.2       +38 -0     vorbis/lib/books/floor/line_1024x31_2sub1.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_1024x31_2sub2.vqh

1.2       +44 -0     vorbis/lib/books/floor/line_1024x31_2sub3.vqh

1.2       +38 -0     vorbis/lib/books/floor/line_1024x31_3sub1.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_1024x31_3sub2.vqh

1.2       +44 -0     vorbis/lib/books/floor/line_1024x31_3sub3.vqh

1.2       +37 -0     vorbis/lib/books/floor/line_1024x31_class0.vqh

1.2       +37 -0     vorbis/lib/books/floor/line_1024x31_class1.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_1024x31_class2.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_1024x31_class3.vqh

1.2       +44 -0     vorbis/lib/books/floor/line_128x19_0sub0.vqh

1.2       +38 -0     vorbis/lib/books/floor/line_128x19_1sub1.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x19_1sub2.vqh

1.2       +44 -0     vorbis/lib/books/floor/line_128x19_1sub3.vqh

1.2       +38 -0     vorbis/lib/books/floor/line_128x19_2sub1.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x19_2sub2.vqh

1.2       +44 -0     vorbis/lib/books/floor/line_128x19_2sub3.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x19_class1.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x19_class2.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x7_0sub0.vqh

1.2       +37 -0     vorbis/lib/books/floor/line_128x7_1sub1.vqh

1.2       +38 -0     vorbis/lib/books/floor/line_128x7_1sub2.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x7_1sub3.vqh

1.2       +37 -0     vorbis/lib/books/floor/line_128x7_2sub1.vqh

1.2       +38 -0     vorbis/lib/books/floor/line_128x7_2sub2.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x7_2sub3.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x7_class1.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x7_class2.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x9_0sub0.vqh

1.2       +37 -0     vorbis/lib/books/floor/line_128x9_1sub1.vqh

1.2       +38 -0     vorbis/lib/books/floor/line_128x9_1sub2.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x9_1sub3.vqh

1.2       +37 -0     vorbis/lib/books/floor/line_128x9_2sub1.vqh

1.2       +38 -0     vorbis/lib/books/floor/line_128x9_2sub2.vqh

1.2       +40 -0     vorbis/lib/books/floor/line_128x9_2sub3.vqh

1.2       +52 -0     vorbis/lib/books/floor/line_128x9_class1.vqh

1.2       +52 -0     vorbis/lib/books/floor/line_128x9_class2.vqh

1.7       +1 -2      vorbis/lib/modes/Makefile.am

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/modes/Makefile.am,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Makefile.am	2001/08/13 11:38:34	1.6
+++ Makefile.am	2001/12/12 09:45:55	1.7
@@ -2,5 +2,4 @@
 
 AUTOMAKE_OPTIONS = foreign
 
-EXTRA_DIST = maskadj_A.h maskadj_X.h maskadj_Z.h mode_22c_Z.h mode_32c_Z.h mode_44_A.h mode_44_B.h mode_44c_A.h mode_44c_B.h mode_44c_C.h mode_44c_D.h mode_44c_E.h mode_44_C.h mode_44c_X.h mode_44c_Y.h mode_44c_Z.h mode_44_X.h mode_44_Y.h mode_44_Z.h modes.h
-
+EXTRA_DIST = floor_44.h psych_44.h residue_44.h

1.2       +184 -0    vorbis/lib/modes/floor_44.h

1.2       +668 -0    vorbis/lib/modes/psych_44.h

1.2       +349 -0    vorbis/lib/modes/residue_44.h

1.25      +8 -8      vorbis/vq/bookutil.c

Index: bookutil.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/vq/bookutil.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- bookutil.c	2001/05/27 06:44:07	1.24
+++ bookutil.c	2001/12/12 09:45:56	1.25
@@ -7,11 +7,11 @@
  *                                                                  *
  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
-
+ *                                                                  *
  ********************************************************************
 
  function: utility functions for loading .vqh and .vqd files
- last mod: $Id: bookutil.c,v 1.24 2001/05/27 06:44:07 xiphmont Exp $
+ last mod: $Id: bookutil.c,v 1.25 2001/12/12 09:45:56 xiphmont Exp $
 
  ********************************************************************/
 
@@ -191,7 +191,7 @@
   }
 
   /* find the codebook struct */
-  find_seek_to(in,"static static_codebook _");
+  find_seek_to(in,"static static_codebook ");
 
   /* get the major important values */
   line=get_line(in);
@@ -538,12 +538,12 @@
   "/********************************************************************\n"
   " *                                                                  *\n"
   " * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *\n"
-  " * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *\n"
-  " * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH    *\n"
-  " * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.        *\n"
+  " * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *\n"
+  " * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *\n"
+  " * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *\n"
   " *                                                                  *\n"
   " * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *\n"
-  " * by the XIPHOPHORUS Company, http://www.xiph.org/                 *\n"
+  " * by the XIPHOPHORUS Company http://www.xiph.org/                  *\n"
   " *                                                                  *\n"
   " ********************************************************************\n"
   "\n"
@@ -708,7 +708,7 @@
 
   /* tie it all together */
   
-  fprintf(out,"static static_codebook _vq_book_%s = {\n",name);
+  fprintf(out,"static static_codebook %s = {\n",name);
   
   fprintf(out,"\t%ld, %ld,\n",c->dim,c->entries);
   fprintf(out,"\t_vq_lengthlist_%s,\n",name);

1.8       +45 -38    vorbis/vq/distribution.c

Index: distribution.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/vq/distribution.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- distribution.c	2001/08/13 01:37:16	1.7
+++ distribution.c	2001/12/12 09:45:56	1.8
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: utility for finding the distribution in a data set
- last mod: $Id: distribution.c,v 1.7 2001/08/13 01:37:16 xiphmont Exp $
+ last mod: $Id: distribution.c,v 1.8 2001/12/12 09:45:56 xiphmont Exp $
 
  ********************************************************************/
 
@@ -163,8 +163,11 @@
     line=setup_line(in);
     while(line){      
       float code;
+      char buf[80];
       lines++;
-      if(!(lines&0xff))spinnit("getting min/max. lines so far...",lines);
+
+      sprintf(buf,"getting min/max (%.2f::%.2f). lines...",min,max);
+      if(!(lines&0xff))spinnit(buf,lines);
       
       while(!flag && sscanf(line,"%f",&code)==1){
         line=strchr(line,',');
@@ -193,48 +196,52 @@
     printf("\r                                                     \r");
     printf("Minimum scalar value: %f\n",min);
     printf("Maximum scalar value: %f\n",max);
-    
-    printf("\n counting hits into %ld bins...\n",bins+1);
-    countarray=calloc(bins+1,sizeof(long));
-    
-    rewind(in);
-    line=setup_line(in);
-    while(line){      
-      float code;
-      lines--;
-      if(!(lines&0xff))spinnit("counting distribution. lines so far...",lines);
+
+    if(argv[2]){
       
-      while(line && sscanf(line,"%f",&code)==1){
-	line=strchr(line,',');
-	if(line)line++;
-	
-	code-=min;
-	code/=(max-min);
-	code*=bins;
-	countarray[(int)rint(code)]++;
-	total++;
-      }
+      printf("\n counting hits into %ld bins...\n",bins+1);
+      countarray=calloc(bins+1,sizeof(long));
       
+      rewind(in);
       line=setup_line(in);
-    }
-
-    fclose(in);
+      while(line){      
+	float code;
+	lines--;
+	if(!(lines&0xff))spinnit("counting distribution. lines so far...",lines);
+	
+	while(line && sscanf(line,"%f",&code)==1){
+	  line=strchr(line,',');
+	  if(line)line++;
+	  
+	  code-=min;
+	  code/=(max-min);
+	  code*=bins;
+	  countarray[(int)rint(code)]++;
+	  total++;
+	}
+	
+	line=setup_line(in);
+      }
     
-    /* make a pretty graph */
-    {
-      long maxcount=0,i,j;
-      for(i=0;i<bins+1;i++)
-	if(countarray[i]>maxcount)maxcount=countarray[i];
-      
-      printf("\r                                                     \r");
-      printf("Total scalars: %ld\n",total);
-      for(i=0;i<bins+1;i++){
-	int stars=rint(50./maxcount*countarray[i]);
-	printf("%08f (%8ld) |",(max-min)/bins*i+min,countarray[i]);
-	for(j=0;j<stars;j++)printf("*");
-      printf("\n");
+      /* make a pretty graph */
+      {
+	long maxcount=0,i,j;
+	for(i=0;i<bins+1;i++)
+	  if(countarray[i]>maxcount)maxcount=countarray[i];
+	
+	printf("\r                                                     \r");
+	printf("Total scalars: %ld\n",total);
+	for(i=0;i<bins+1;i++){
+	  int stars=rint(50./maxcount*countarray[i]);
+	  printf("%08f (%8ld) |",(max-min)/bins*i+min,countarray[i]);
+	  for(j=0;j<stars;j++)printf("*");
+	  printf("\n");
+	}
       }
     }
+
+    fclose(in);
+
   }
   printf("\nDone.\n");
   exit(0);

1.11      +3 -1      vorbis/vq/latticehint.c

Index: latticehint.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/vq/latticehint.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- latticehint.c	2001/08/13 01:37:17	1.10
+++ latticehint.c	2001/12/12 09:45:56	1.11
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: utility main for building thresh/pigeonhole encode hints
- last mod: $Id: latticehint.c,v 1.10 2001/08/13 01:37:17 xiphmont Exp $
+ last mod: $Id: latticehint.c,v 1.11 2001/12/12 09:45:56 xiphmont Exp $
 
  ********************************************************************/
 
@@ -209,6 +209,7 @@
   }
 
   /* Do we want to gen a pigeonhole hint? */
+#if 0
   for(i=0;i<entries;i++)if(c->lengthlist[i]==0)break;
   if(c->q_sequencep || i<entries){
     long **tempstack;
@@ -420,6 +421,7 @@
       }
     }
   }
+#endif
 
   write_codebook(stdout,name,c); 
   fprintf(stderr,"\r                                                     "

1.12      +78 -40    vorbis/vq/residuesplit.c

Index: residuesplit.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/vq/residuesplit.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- residuesplit.c	2001/08/13 01:37:17	1.11
+++ residuesplit.c	2001/12/12 09:45:57	1.12
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: residue backend 0 partitioner/classifier
- last mod: $Id: residuesplit.c,v 1.11 2001/08/13 01:37:17 xiphmont Exp $
+ last mod: $Id: residuesplit.c,v 1.12 2001/12/12 09:45:57 xiphmont Exp $
 
  ********************************************************************/
 
@@ -64,7 +64,8 @@
 /* This is currently a bit specific to/hardwired for mapping 0; things
    will need to change in the future when we get real multichannel
    mappings */
-int quantaux(float *res,int n,float *ebound,float *mbound,int *subgrp,int parts, int subn){
+int quantaux(float *res,int n,float *ebound,float *mbound,int *subgrp,int parts, int subn, 
+	     int *class){
   long i,j,part=0;
   int aux;
 
@@ -82,18 +83,28 @@
          max<=mbound[j] &&
          part<subgrp[j])
         break;
-    aux=j;
+    class[part]=aux=j;
     
     fprintf(of,"%d, ",aux);
+  }    
+  fprintf(of,"\n");
+
+  return(0);
+}
+
+int quantwrite(float *res,int n,int subn, int *class,int offset){
+  long i,j,part=0;
+  int aux;
+
+  for(i=0;i<=n-subn;i+=subn,part++){
+    aux=class[part];
     
     for(j=0;j<subn;j++)
-      fprintf(or[aux],"%g, ",res[j+i]);
+      fprintf(or[aux+offset],"%g, ",res[j+i]);
     
-    fprintf(or[aux],"\n");
+    fprintf(or[aux+offset],"\n");
   }
 
-  fprintf(of,"\n");
-
   return(0);
 }
 
@@ -122,33 +133,45 @@
 static void usage(){
   fprintf(stderr,
           "usage:\n" 
-	  "residuesplit <res> <begin,n,group> <baseout> <ent,peak,sub> [<ent,peak,sub>]...\n"
+	  "residuesplit <res> [<res>] <begin,n,group> <baseout> <ent,peak,sub> [<ent,peak,sub>]...\n"
           "   where begin,n,group is first scalar, \n"
           "                          number of scalars of each in line,\n"
           "                          number of scalars in a group\n"
           "         ent is the maximum entropy value allowed for membership in a group\n"
           "         peak is the maximum amplitude value allowed for membership in a group\n"
-	  "         subn is the maximum subpartiton number allowed in the group\n"
-	           
-	  "eg: residuesplit mask.vqd floor.vqd 0,1024,16 res 0,.5,2 3,1.5,4 \n"
-	  "produces resaux.vqd and res_0...n.vqd\n\n");
+	  "         subn is the maximum subpartiton number allowed in the group\n\n");
   exit(1);
 }
 
 int main(int argc, char *argv[]){
   char *buffer;
   char *base;
-  int i,parts,begin,n,subn,*subgrp;
-  FILE *res;
+  int i,j,parts,begin,n,subn,*subgrp,*class;
+  FILE **res;
+  int resfiles=0;
   float *ebound,*mbound,*vec;
   long c=0;
   if(argc<5)usage();
+
+  /* count the res file names, open the files */
+  while(!strcmp(argv[resfiles+1]+strlen(argv[resfiles+1])-4,".vqd"))
+    resfiles++;
+  if(resfiles<1)usage();
+
+  res=alloca(sizeof(*res)*resfiles);
+  for(i=0;i<resfiles;i++){
+    res[i]=fopen(argv[i+1],"r");
+    if(!(res+i)){
+      fprintf(stderr,"Could not open file %s\n",argv[1+i]);
+      exit(1);
+    }
+  }
 
-  base=strdup(argv[3]);
+  base=strdup(argv[2+resfiles]);
   buffer=alloca(strlen(base)+20);
   {
-    char *pos=strchr(argv[2],',');
-    begin=atoi(argv[2]);
+    char *pos=strchr(argv[1+resfiles],',');
+    begin=atoi(argv[1+resfiles]);
     if(!pos)
       usage();
     else
@@ -165,19 +188,19 @@
   }
 
   /* how many parts?... */
-  parts=argc-3;
+  parts=argc-resfiles-2;
   
   ebound=_ogg_malloc(sizeof(float)*parts);
   mbound=_ogg_malloc(sizeof(float)*parts);
   subgrp=_ogg_malloc(sizeof(int)*parts);
   
   for(i=0;i<parts-1;i++){
-    char *pos=strchr(argv[4+i],',');
+    char *pos=strchr(argv[3+i+resfiles],',');
     subgrp[i]=0;
-    if(*argv[4+i]==',')
+    if(*argv[3+i+resfiles]==',')
       ebound[i]=1e50f;
     else
-      ebound[i]=atof(argv[4+i]);
+      ebound[i]=atof(argv[3+i+resfiles]);
 
     if(!pos){
       mbound[i]=1e50f;
@@ -198,42 +221,57 @@
   ebound[i]=1e50f;
   mbound[i]=1e50f;
   subgrp[i]=9999999;
-
-  res=fopen(argv[1],"r");
-  if(!res){
-    fprintf(stderr,"Could not open file %s\n",argv[1]);
-    exit(1);
-  }
 
-  or=alloca(parts*sizeof(FILE*));
+  or=alloca(parts*resfiles*sizeof(FILE*));
   sprintf(buffer,"%saux.vqd",base);
   of=fopen(buffer,"w");
   if(!of){
     fprintf(stderr,"Could not open file %s for writing\n",buffer);
     exit(1);
   }
-  for(i=0;i<parts;i++){
-    sprintf(buffer,"%s_%d.vqd",base,i);
-    or[i]=fopen(buffer,"w");
-    if(!or[i]){
-      fprintf(stderr,"Could not open file %s for writing\n",buffer);
-      exit(1);
+
+  for(j=0;j<resfiles;j++){
+    for(i=0;i<parts;i++){
+      sprintf(buffer,"%s_%d%c.vqd",base,i,j+65);
+      or[i+j*parts]=fopen(buffer,"w");
+      if(!or[i+j*parts]){
+	fprintf(stderr,"Could not open file %s for writing\n",buffer);
+	exit(1);
+      }
     }
   }
   
   vec=_ogg_malloc(sizeof(float)*n);
+  class=_ogg_malloc(sizeof(float)*n);
   /* get the input line by line and process it */
-  while(!feof(res)){
-    if(getline(res,vec,begin,n))
-      quantaux(vec,n,ebound,mbound,subgrp,parts,subn);
+  while(1){
+    if(getline(res[0],vec,begin,n)){
+      quantaux(vec,n,ebound,mbound,subgrp,parts,subn,class);
+      quantwrite(vec,n,subn,class,0);
+
+      for(i=1;i<resfiles;i++){
+	if(getline(res[i],vec,begin,n)){
+	  quantwrite(vec,n,subn,class,parts*i);
+	}else{
+	  fprintf(stderr,"Getline loss of sync (%d).\n\n",i);
+	  exit(1);
+	}
+      }
+    }else{
+      if(feof(res[0]))break;
+      fprintf(stderr,"Getline loss of sync (0).\n\n");
+      exit(1);
+    }
+    
     c++;
     if(!(c&0xf)){
-      spinnit("kB so far...",(int)(ftell(res)/1024));
+      spinnit("kB so far...",(int)(ftell(res[0])/1024));
     }
   }
-  fclose(res);
+  for(i=0;i<resfiles;i++)
+    fclose(res[i]);
   fclose(of);
-  for(i=0;i<parts;i++)
+  for(i=0;i<parts*resfiles;i++)
     fclose(or[i]);
   fprintf(stderr,"\rDone                         \n");
   return(0);

1.2       +62 -0     vorbis/vq/44c0_s4.vqs

1.2       +44 -0     vorbis/vq/44c1_s3.vqs

1.2       +33 -0     vorbis/vq/44c2_s2.vqs

1.2       +44 -0     vorbis/vq/44c3_s2.vqs

1.2       +36 -0     vorbis/vq/44c4_s1.vqs

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