More shuffling of includes to ease codebook integration. This breaks
authorMonty <xiphmont@xiph.org>
Wed, 5 Jan 2000 03:11:12 +0000 (03:11 +0000)
committerMonty <xiphmont@xiph.org>
Wed, 5 Jan 2000 03:11:12 +0000 (03:11 +0000)
the VQ build, but I'll fix that right away.

Monty

svn path=/trunk/vorbis/; revision=223

26 files changed:
examples/Makefile.in
examples/chaining_example.c
examples/decoder_example.c
examples/encoder_example.c
include/vorbis/codebook.h [new file with mode: 0644]
include/vorbis/codec.h [moved from include/codec.h with 92% similarity]
include/vorbis/internal.h [new file with mode: 0644]
include/vorbis/modes.h [moved from include/modes.h with 96% similarity]
include/vorbis/vorbisfile.h [moved from include/vorbisfile.h with 97% similarity]
lib/Makefile.in
lib/analysis.c
lib/bitwise.h
lib/block.c
lib/envelope.c
lib/framing.c
lib/info.c
lib/lpc.h
lib/mdct.h
lib/psy.c
lib/smallft.h
lib/spectrum.c
lib/synthesis.c
lib/vorbisfile.c
vq/Makefile.in
vq/run.c
vq/vqsplit.c

index 5089814..76b67b4 100644 (file)
@@ -1,6 +1,6 @@
 # vorbis makefile configured for use with gcc on any platform
 
-# $Id: Makefile.in,v 1.1 1999/12/31 12:35:38 xiphmont Exp $
+# $Id: Makefile.in,v 1.2 2000/01/05 03:10:23 xiphmont Exp $
 
 ###############################################################################
 #                                                                             #
@@ -27,7 +27,7 @@ AR=@AR@
 RANLIB=@RANLIB@
 LIBS=@LIBS@ -lm
 
-HFILES =       ../include/codec.h ../include/vorbisfile.h
+HFILES =       ../include/vorbis/codec.h ../include/vorbis/vorbisfile.h
 OFILES =       encoder_example.o decoder_example.o chaining_example.o
 BINFILES =      encoder_example decoder_example chaining_example
 
index d15167a..582ed7f 100644 (file)
  ********************************************************************
 
  function: illustrate simple use of chained bitstream and vorbisfile.a
- last mod: $Id: chaining_example.c,v 1.2 1999/12/30 07:26:26 xiphmont Exp $
+ last mod: $Id: chaining_example.c,v 1.3 2000/01/05 03:10:24 xiphmont Exp $
 
  ********************************************************************/
 
-#include "codec.h"
-#include "vorbisfile.h"
+#include "vorbis/codec.h"
+#include "vorbis/vorbisfile.h"
 
 int main(){
   OggVorbis_File ov;
index cd41e72..413c409 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: simple example decoder
- last mod: $Id: decoder_example.c,v 1.2 1999/12/30 07:26:27 xiphmont Exp $
+ last mod: $Id: decoder_example.c,v 1.3 2000/01/05 03:10:25 xiphmont Exp $
 
  ********************************************************************/
 
@@ -24,7 +24,7 @@
 
 #include <stdio.h>
 #include <math.h>
-#include "codec.h"
+#include "vorbis/codec.h"
 
 int16_t convbuffer[4096]; /* take 8k out of the data segment, not the stack */
 int convsize=4096;
index 3a7a730..53b09f7 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: simple example encoder
- last mod: $Id: encoder_example.c,v 1.2 1999/12/30 07:26:28 xiphmont Exp $
+ last mod: $Id: encoder_example.c,v 1.3 2000/01/05 03:10:26 xiphmont Exp $
 
  ********************************************************************/
 
@@ -25,7 +25,7 @@
 #include <stdlib.h>
 #include <time.h>
 #include <math.h>
-#include "codec.h"
+#include "vorbis/codec.h"
 
 #define READ 1024
 signed char readbuffer[READ*4+44]; /* out of the data segment, not the stack */
diff --git a/include/vorbis/codebook.h b/include/vorbis/codebook.h
new file mode 100644 (file)
index 0000000..9132561
--- /dev/null
@@ -0,0 +1,80 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE.  *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
+ * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE.    *
+ * PLEASE READ THESE TERMS DISTRIBUTING.                            *
+ *                                                                  *
+ * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000             *
+ * by Monty <monty@xiph.org> and The XIPHOPHORUS Company            *
+ * http://www.xiph.org/                                             *
+ *                                                                  *
+ ********************************************************************
+
+ function: codebook types
+ last mod: $Id: codebook.h,v 1.1 2000/01/05 03:10:47 xiphmont Exp $
+
+ ********************************************************************/
+
+#ifndef _V_CODEBOOK_H_
+#define _V_CODEBOOK_H_
+
+/* This structure encapsulates huffman and VQ style encoding books; it
+   doesn't do anything specific to either.
+
+   valuelist/quantlist are nonNULL (and q_* significant) only if
+   there's entry->value mapping to be done.
+
+   If encode-side mapping must be done (and thus the entry needs to be
+   hunted), the auxiliary encode pointer will point to a decision
+   tree.  This is true of both VQ and huffman, but is mostly useful
+   with VQ.
+
+*/
+
+typedef struct codebook{
+  long dim;           /* codebook dimensions (elements per vector) */
+  long entries;       /* codebook entries */
+
+  /* mapping */
+  long   q_min;       /* packed 24 bit float; quant value 0 maps to minval */
+  long   q_delta;     /* packed 24 bit float; val 1 - val 0 == delta */
+  int    q_quant;     /* 0 < quant <= 16 */
+  int    q_sequencep; /* bitflag */
+
+  double *valuelist;  /* list of dim*entries actual entry values */
+  long   *quantlist;  /* list of dim*entries quantized entry values */
+
+  /* actual codewords/lengths */
+  long   *codelist;   /* list of bitstream codewords for each entry */
+  long   *lengthlist; /* codeword lengths in bits */
+
+  struct encode_aux *encode_tree;
+  struct decode_aux *decode_tree;
+
+} codebook;
+
+typedef struct encode_aux{
+  /* pre-calculated partitioning tree */
+  long   *ptr0;
+  long   *ptr1;
+
+  double *n;         /* decision hyperplanes: sum(x_i*n_i)[0<=i<dim]=c */ 
+  double *c;         /* decision hyperplanes: sum(x_i*n_i)[0<=i<dim]=c */ 
+  long   *p;         /* decision points (each is an entry) */
+  long   *q;         /* decision points (each is an entry) */
+  long   aux;        /* number of tree entries */
+  long   alloc;       
+} encode_aux;
+
+typedef struct decode_aux{
+  long   *ptr0;
+  long   *ptr1;
+} decode_aux;
+
+#endif
+
+
+
+
+
similarity index 92%
rename from include/codec.h
rename to include/vorbis/codec.h
index 51b724b..bb52120 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: libvorbis codec headers
- last mod: $Id: codec.h,v 1.4 2000/01/04 09:04:54 xiphmont Exp $
+ last mod: $Id: codec.h,v 1.1 2000/01/05 03:10:47 xiphmont Exp $
 
  ********************************************************************/
 
 #  define int16_t size16
 #endif
 
-/* lookup structures for various simple transforms *****************/
-
-typedef struct {
-  int n;
-  struct vorbis_info *vi;
-
-  double *maskthresh;
-  double *barknum;
-
-} psy_lookup;
-
-typedef struct {
-  int n;
-  int log2n;
-  
-  double *trig;
-  int    *bitrev;
-
-} mdct_lookup;
-
-typedef struct {
-  int n;
-  double *trigcache;
-  int *splitcache;
-} drft_lookup;
-
-typedef struct {
-  int winlen;
-  double *window;
-  mdct_lookup mdct;
-} envelope_lookup;
-
-typedef struct lpclook{
-  /* en/decode lookups */
-  int *linearmap;
-  double *barknorm;
-  drft_lookup fft;
-
-  int n;
-  int ln;
-  int m;
-
-} lpc_lookup;
-
-/* structures for various internal data abstractions ********************/
-
-typedef struct {
-  long endbyte;     
-  int  endbit;      
-
-  unsigned char *buffer;
-  unsigned char *ptr;
-  long storage;
-  
-} oggpack_buffer;
+#include "vorbis/codebook.h"
+#include "vorbis/internal.h"
 
 /* vobis_info contains all the setup information specific to the specific
    compression/decompression mode in progress (eg, psychoacoustic settings,
diff --git a/include/vorbis/internal.h b/include/vorbis/internal.h
new file mode 100644 (file)
index 0000000..b81874b
--- /dev/null
@@ -0,0 +1,84 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE.  *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
+ * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE.    *
+ * PLEASE READ THESE TERMS DISTRIBUTING.                            *
+ *                                                                  *
+ * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000             *
+ * by Monty <monty@xiph.org> and The XIPHOPHORUS Company            *
+ * http://www.xiph.org/                                             *
+ *                                                                  *
+ ********************************************************************
+
+ function: libvorbis codec internal types.  These structures are 
+           'visible', but generally uninteresting to the developer
+ last mod: $Id: internal.h,v 1.1 2000/01/05 03:10:47 xiphmont Exp $
+
+ ********************************************************************/
+
+#ifndef _vorbis_internal_h_
+#define _vorbis_internal_h_
+
+/* lookup structures for various simple transforms *****************/
+
+typedef struct {
+  int n;
+  struct vorbis_info *vi;
+
+  double *maskthresh;
+  double *barknum;
+
+} psy_lookup;
+
+typedef struct {
+  int n;
+  int log2n;
+  
+  double *trig;
+  int    *bitrev;
+
+} mdct_lookup;
+
+typedef struct {
+  int n;
+  double *trigcache;
+  int *splitcache;
+} drft_lookup;
+
+typedef struct {
+  int winlen;
+  double *window;
+  mdct_lookup mdct;
+} envelope_lookup;
+
+typedef struct lpclook{
+  /* en/decode lookups */
+  int *linearmap;
+  double *barknorm;
+  drft_lookup fft;
+
+  int n;
+  int ln;
+  int m;
+
+} lpc_lookup;
+
+/* structures for various internal data abstractions ********************/
+
+typedef struct {
+  long endbyte;     
+  int  endbit;      
+
+  unsigned char *buffer;
+  unsigned char *ptr;
+  long storage;
+  
+} oggpack_buffer;
+
+#endif
+
+
+
+
+
similarity index 96%
rename from include/modes.h
rename to include/vorbis/modes.h
index 2893574..62fc98c 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: predefined encoding modes
- last mod: $Id: modes.h,v 1.3 2000/01/04 09:04:55 xiphmont Exp $
+ last mod: $Id: modes.h,v 1.1 2000/01/05 03:10:47 xiphmont Exp $
 
  ********************************************************************/
 
@@ -20,7 +20,7 @@
 #define _V_MODES_H_
 
 #include <stdio.h>
-#include "codec.h"
+#include "vorbis/codec.h"
 
 /*
    0      1      2      3      4     5      6     7     8     9 
similarity index 97%
rename from include/vorbisfile.h
rename to include/vorbis/vorbisfile.h
index 27794e9..854e507 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.h,v 1.2 1999/12/30 07:26:30 xiphmont Exp $
+ last mod: $Id: vorbisfile.h,v 1.1 2000/01/05 03:10:47 xiphmont Exp $
 
  ********************************************************************/
 
index cf362f1..784714c 100644 (file)
@@ -1,6 +1,6 @@
 # vorbis makefile configured for use with gcc on any platform
 
-# $Id: Makefile.in,v 1.19 2000/01/04 09:04:56 xiphmont Exp $
+# $Id: Makefile.in,v 1.20 2000/01/05 03:10:52 xiphmont Exp $
 
 ###############################################################################
 #                                                                             #
@@ -27,7 +27,7 @@ AR=@AR@
 RANLIB=@RANLIB@
 LIBS=@LIBS@ -lm
 
-HFILES =       ../include/codec.h ../include/vorbisfile.h \
+HFILES =       ../include/vorbis/codec.h ../include/vorbis/vorbisfile.h \
                bitwise.h envelope.h lpc.h lsp.h \
                psy.h smallft.h window.h scales.h os.h mdct.h
 LFILES =       framing.o mdct.o smallft.o block.o envelope.o window.o\
index 79382c1..d7cff4a 100644 (file)
  ********************************************************************
 
  function: single-block PCM analysis
- last mod: $Id: analysis.c,v 1.19 2000/01/04 09:04:57 xiphmont Exp $
+ last mod: $Id: analysis.c,v 1.20 2000/01/05 03:10:53 xiphmont Exp $
 
  ********************************************************************/
 
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
+#include "vorbis/codec.h"
+
 #include "os.h"
-#include "codec.h"
 #include "lpc.h"
 #include "lsp.h"
 #include "envelope.h"
index 0e56e93..1cd5573 100644 (file)
  ********************************************************************
 
   function: packing variable sized words into an octet stream
-  last mod: $Id: bitwise.h,v 1.3 1999/12/30 07:26:34 xiphmont Exp $
+  last mod: $Id: bitwise.h,v 1.4 2000/01/05 03:10:54 xiphmont Exp $
 
  ********************************************************************/
 
 #ifndef _V_BITW_H_
 #define _V_BITW_H_
 
-#include "codec.h"
+#include "vorbis/codec.h"
 
 extern void _oggpack_writeinit(oggpack_buffer *b);
 extern void _oggpack_reset(oggpack_buffer *b);
index 67701a3..8070f75 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.20 2000/01/04 09:04:59 xiphmont Exp $
+ last mod: $Id: block.c,v 1.21 2000/01/05 03:10:55 xiphmont Exp $
 
  Handle windowing, overlap-add, etc of the PCM vectors.  This is made
  more amusing by Vorbis' current two allowed block sizes.
@@ -26,7 +26,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "codec.h"
+#include "vorbis/codec.h"
+
 #include "window.h"
 #include "envelope.h"
 #include "mdct.h"
index cbc0860..b5fa328 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: PCM data envelope analysis and manipulation
- last mod: $Id: envelope.c,v 1.12 1999/12/30 07:26:36 xiphmont Exp $
+ last mod: $Id: envelope.c,v 1.13 2000/01/05 03:10:56 xiphmont Exp $
 
  Preecho calculation.
 
@@ -22,9 +22,9 @@
 #include <string.h>
 #include <stdio.h>
 #include <math.h>
+#include "vorbis/codec.h"
 
 #include "os.h"
-#include "codec.h"
 #include "mdct.h"
 #include "envelope.h"
 #include "bitwise.h"
index 46c0a9e..2e8b828 100644 (file)
@@ -13,7 +13,7 @@
 
  function: code raw [Vorbis] packets into framed OggSquish stream and
            decode Ogg streams back into raw packets
- last mod: $Id: framing.c,v 1.12 1999/12/30 07:26:38 xiphmont Exp $
+ last mod: $Id: framing.c,v 1.13 2000/01/05 03:10:57 xiphmont Exp $
 
  note: The CRC code is directly derived from public domain code by
  Ross Williams (ross@guest.adelaide.edu.au).  See docs/framing.html
@@ -23,7 +23,7 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include "codec.h"
+#include "vorbis/codec.h"
 
 /* A complete description of Ogg framing exists in docs/framing.html */
 
index c4181e7..765f173 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: maintain the info structure, info <-> header packets
- last mod: $Id: info.c,v 1.13 2000/01/04 09:05:00 xiphmont Exp $
+ last mod: $Id: info.c,v 1.14 2000/01/05 03:10:58 xiphmont Exp $
 
  ********************************************************************/
 
@@ -22,7 +22,7 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include "modes.h"
+#include "vorbis/modes.h"
 #include "bitwise.h"
 
 static int ilog2(unsigned int v){
index 0625470..0858d92 100644 (file)
--- a/lib/lpc.h
+++ b/lib/lpc.h
  ********************************************************************
 
   function: LPC low level routines
-  last mod: $Id: lpc.h,v 1.6 1999/12/31 12:35:15 xiphmont Exp $
+  last mod: $Id: lpc.h,v 1.7 2000/01/05 03:10:59 xiphmont Exp $
 
  ********************************************************************/
 
 #ifndef _V_LPC_H_
 #define _V_LPC_H_
 
-#include "codec.h"
+#include "vorbis/codec.h"
 
 extern void lpc_init(lpc_lookup *l,int n, long mapped, long rate, int m);
 extern void lpc_clear(lpc_lookup *l);
index 80e210c..9acde51 100644 (file)
  ********************************************************************
 
  function: modified discrete cosine transform prototypes
- last mod: $Id: mdct.h,v 1.8 1999/12/30 07:26:45 xiphmont Exp $
+ last mod: $Id: mdct.h,v 1.9 2000/01/05 03:11:00 xiphmont Exp $
 
  ********************************************************************/
 
 #ifndef _OGG_mdct_H_
 #define _OGG_mdct_H_
 
-#include "codec.h"
+#include "vorbis/codec.h"
 
 extern void mdct_init(mdct_lookup *lookup,int n);
 extern void mdct_clear(mdct_lookup *l);
index 7de7302..31fa6e3 100644 (file)
--- a/lib/psy.c
+++ b/lib/psy.c
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: random psychoacoustics (not including preecho)
- last mod: $Id: psy.c,v 1.9 2000/01/04 09:05:02 xiphmont Exp $
+ last mod: $Id: psy.c,v 1.10 2000/01/05 03:11:01 xiphmont Exp $
 
  ********************************************************************/
 
@@ -20,7 +20,8 @@
 #include <math.h>
 #include <string.h>
 #include <stdio.h>
-#include "codec.h"
+#include "vorbis/codec.h"
+
 #include "psy.h"
 #include "lpc.h"
 #include "smallft.h"
index 2142f86..c72011f 100644 (file)
  ********************************************************************
 
  function: fft transform
- last mod: $Id: smallft.h,v 1.4 1999/12/30 07:26:50 xiphmont Exp $
+ last mod: $Id: smallft.h,v 1.5 2000/01/05 03:11:02 xiphmont Exp $
 
 ********************************************************************/
 
 #ifndef _V_SMFT_H_
 #define _V_SMFT_H_
 
-#include "codec.h"
+#include "vorbis/codec.h"
 
 extern void drft_forward(drft_lookup *l,double *data);
 extern void drft_backward(drft_lookup *l,double *data);
index 179ec4e..925c869 100644 (file)
  ********************************************************************
 
  function: spectrum envelope and residue code/decode
- last mod: $Id: spectrum.c,v 1.9 2000/01/04 09:05:03 xiphmont Exp $
+ last mod: $Id: spectrum.c,v 1.10 2000/01/05 03:11:03 xiphmont Exp $
 
  ********************************************************************/
 
 #include <stdio.h>
 #include <math.h>
+#include "vorbis/codec.h"
+
 #include "os.h"
-#include "codec.h"
 #include "bitwise.h"
 #include "spectrum.h"
 
index 5236b52..91b045f 100644 (file)
  ********************************************************************
 
  function: single-block PCM synthesis
- last mod: $Id: synthesis.c,v 1.10 1999/12/30 07:26:53 xiphmont Exp $
+ last mod: $Id: synthesis.c,v 1.11 2000/01/05 03:11:04 xiphmont Exp $
 
  ********************************************************************/
 
 #include <stdio.h>
-#include "codec.h"
+#include "vorbis/codec.h"
+
 #include "envelope.h"
 #include "mdct.h"
 #include "lpc.h"
index b756f7a..36a6a62 100644 (file)
  ********************************************************************
 
  function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.c,v 1.11 1999/12/30 07:26:54 xiphmont Exp $
+ last mod: $Id: vorbisfile.c,v 1.12 2000/01/05 03:11:05 xiphmont Exp $
 
  ********************************************************************/
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <math.h>
+#include "vorbis/codec.h"
+#include "vorbis/vorbisfile.h"
+
 #include "os.h"
-#include "codec.h"
-#include "vorbisfile.h"
 
 /* A 'chained bitstream' is a Vorbis bitstream that contains more than
    one logical bitstream arranged end to end (the only form of Ogg
index 2fc556f..49e6cc1 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Makefile.in,v 1.4 1999/12/30 07:26:58 xiphmont Exp $
+# $Id: Makefile.in,v 1.5 2000/01/05 03:11:10 xiphmont Exp $
 
 ###############################################################################
 #                                                                             #
@@ -14,7 +14,7 @@
 # (unless, of course, you know what you are doing :) ##########################
 
 @SET_MAKE@
-FLAGS=-I. @TYPESIZES@ @CFLAGS@
+FLAGS=-I. -I../include @TYPESIZES@ @CFLAGS@
 OPT=@OPT@ $(FLAGS)
 DEBUG=@DEBUG@ $(FLAGS)
 PROFILE=@PROFILE@ $(FLAGS)
@@ -25,7 +25,7 @@ AR=@AR@
 RANLIB=@RANLIB@
 LIBS=@LIBS@ -lm
 
-HFILES =       vqgen.h vqext.h
+HFILES =       ../include/vorbis/codebook.h vqgen.h vqext.h
 
 OFILES =       vqgen.o vqsplit.o 
 ALLOFILES =    $(OFILES) lspdata.o train.o build.o
index ee9e3f3..80a385c 100644 (file)
--- a/vq/run.c
+++ b/vq/run.c
@@ -1,3 +1,5 @@
+#define CODEBOOK _vq_book_lsp_256_32_44100_8
+#include "lsp_256_32_44100_8.vqh"
 /********************************************************************
  *                                                                  *
  * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE.  *
@@ -12,7 +14,7 @@
  ********************************************************************
 
  function: utility main for loading/testing/running finished codebooks
- last mod: $Id: run.c,v 1.2 1999/12/30 07:27:01 xiphmont Exp $
+ last mod: $Id: run.c,v 1.3 2000/01/05 03:11:11 xiphmont Exp $
 
  ********************************************************************/
 
@@ -84,6 +86,16 @@ void vqbook_unquantize(vqbook *b){
   }
 }
 
+double _ssqe(int el,double *a, double *b){
+  int i;
+  double acc=0.;
+  for(i=0;i<el;i++){
+    double val=(a[i]-b[i]);
+    acc+=val*val;
+  }
+  return acc;
+}
+
 
 /* command line:
    run outbase [-m] [-s <start>,<n>] datafile [-s <start>,<n>] [datafile...]
@@ -104,7 +116,7 @@ int main(int argc,char *argv[]){
   long i,j,k;
   int start=0,num=-1;
 
-  double mean=0.,meansquare=0.,mean_count=0.;
+  double mean=0.,br_mean=0.,mean_count=0.;
   
   argv++;
 
@@ -219,15 +231,25 @@ int main(int argc,char *argv[]){
            entry=vqenc_entry(b,base);
 
            /* accumulate metrics */
-           for(k=0;k<b->dim;k++){
-             double err=base[k]-b->valuelist[k+entry*b->dim];
-             mean+=fabs(err);
-             meansquare+=err*err;
-             mean_count++;
+           mean+=_ssqe(b->dim,base,b->valuelist+entry*b->dim);
+
+           /* brute force it as a sanity check of the decision
+               table... did that work better? */
+           {
+             double best=_ssqe(b->dim,base,b->valuelist);
+             int bestj=0;
+             for(j=0;j<b->entries;j++){
+               double this=_ssqe(b->dim,base,b->valuelist+j*b->dim);
+               if(this<best){
+                 best=this;
+                 bestj=j;
+               }
+             }
+
+             br_mean+=best;
            }
 
-           /* brute force it... did that work better? */
-
+           mean_count+=b->dim;
 
            /* paint the cell if -m */
            if(cells){
@@ -242,7 +264,7 @@ int main(int argc,char *argv[]){
 
 
          }
-          free(b);
+          free(p);
         }
       }
       fclose(in);
@@ -254,8 +276,9 @@ int main(int argc,char *argv[]){
   if(cells)fclose(cells);
 
   /* print accumulated error statistics */
-  fprintf(stderr,"results:\n\tmean squared error:%g\n\tmean error:%g\n\n",
-         sqrt(meansquare/mean_count),mean/mean_count);
+  fprintf(stderr,"results:\n\tsqrt(mean squared error) from decision tree:%g\n"
+         "\tsqrt(mean squared error) by brute force:%g\n\n",
+         sqrt(mean/mean_count),sqrt(br_mean/mean_count));
 
   return 0;
 }
index 3f3ab46..e08dbc9 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: build a VQ codebook and the encoding decision 'tree'
- last mod: $Id: vqsplit.c,v 1.7 1999/12/30 07:27:06 xiphmont Exp $
+ last mod: $Id: vqsplit.c,v 1.8 2000/01/05 03:11:12 xiphmont Exp $
 
  ********************************************************************/
 
@@ -121,7 +121,7 @@ void pq_in_out(vqgen *v,double *n,double *c,double *p,double *q){
   }
 }
 
-static void spinnit(void){
+static void spinnit(int n){
   static int p=0;
   static long lasttime=0;
   long test;
@@ -132,19 +132,21 @@ static void spinnit(void){
   if(lasttime!=test){
     lasttime=test;
 
+    fprintf(stderr," %d ",n);
+
     p++;if(p>3)p=0;
     switch(p){
     case 0:
-      fprintf(stderr,"|\b");
+      fprintf(stderr,"|    \r");
       break;
     case 1:
-      fprintf(stderr,"/\b");
+      fprintf(stderr,"/    \r");
       break;
     case 2:
-      fprintf(stderr,"-\b");
+      fprintf(stderr,"-    \r");
       break;
     case 3:
-      fprintf(stderr,"\\\b");
+      fprintf(stderr,"\\    \r");
       break;
     }
     fflush(stderr);
@@ -185,7 +187,7 @@ int lp_split(vqgen *v,vqbook *b,
     long   firstentry=0;
     double firstmetric=_dist_sq(v,_now(v,entryindex[0]),ppt);
     
-    if(points*entries>64*1024)spinnit();
+    if(points*entries>64*1024)spinnit(entries);
 
     for(j=1;j<entries;j++){
       double thismetric=_dist_sq(v,_now(v,entryindex[j]),ppt);
@@ -204,13 +206,13 @@ int lp_split(vqgen *v,vqbook *b,
   /* more than one way to do this part.  For small sets, we can brute
      force it. */
 
-  if(entries<8 || points*entries*entries<128*1024*1024){
+  if(entries<8 || (double)points*entries*entries<128.*1024*1024){
     /* try every pair possibility */
     double best=0;
     double this;
     for(i=0;i<entries-1;i++){
       for(j=i+1;j<entries;j++){
-       spinnit();
+       spinnit(entries-i);
        pq_in_out(v,n,&c,_now(v,entryindex[i]),_now(v,entryindex[j]));
        vqsp_count(v,membership,
                   entryindex,entries, 
@@ -245,7 +247,7 @@ int lp_split(vqgen *v,vqbook *b,
     /* eventually, we want to select the closest entry and figure n/c
        from p/q (because storing n/c is too large */
     for(k=0;k<v->elements;k++){
-      spinnit();
+      spinnit(entries);
       
       p[k]=0.;
       for(j=0;j<entries;j++)
@@ -263,7 +265,7 @@ int lp_split(vqgen *v,vqbook *b,
       double ref_best=0.;
       double ref_j=-1;
       double this;
-      spinnit();
+      spinnit(entries-i);
       
       for(k=0;k<v->elements;k++)
        q[k]=2*p[k]-ppi[k];