the VQ build, but I'll fix that right away.
Monty
svn path=/trunk/vorbis/; revision=223
# 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 $
###############################################################################
# #
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
********************************************************************
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;
********************************************************************
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 $
********************************************************************/
#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;
********************************************************************
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 $
********************************************************************/
#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 */
--- /dev/null
+/********************************************************************
+ * *
+ * 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
+
+
+
+
+
********************************************************************
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,
--- /dev/null
+/********************************************************************
+ * *
+ * 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
+
+
+
+
+
********************************************************************
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 $
********************************************************************/
#define _V_MODES_H_
#include <stdio.h>
-#include "codec.h"
+#include "vorbis/codec.h"
/*
0 1 2 3 4 5 6 7 8 9
********************************************************************
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 $
********************************************************************/
# 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 $
###############################################################################
# #
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\
********************************************************************
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"
********************************************************************
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);
********************************************************************
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.
#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"
********************************************************************
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.
#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"
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
#include <stdlib.h>
#include <string.h>
-#include "codec.h"
+#include "vorbis/codec.h"
/* A complete description of Ogg framing exists in docs/framing.html */
********************************************************************
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 $
********************************************************************/
#include <stdlib.h>
#include <string.h>
-#include "modes.h"
+#include "vorbis/modes.h"
#include "bitwise.h"
static int ilog2(unsigned int v){
********************************************************************
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);
********************************************************************
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);
********************************************************************
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 $
********************************************************************/
#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"
********************************************************************
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);
********************************************************************
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"
********************************************************************
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"
********************************************************************
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
-# $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 $
###############################################################################
# #
# (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)
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
+#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. *
********************************************************************
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 $
********************************************************************/
}
}
+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...]
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++;
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){
}
- free(b);
+ free(p);
}
}
fclose(in);
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;
}
********************************************************************
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 $
********************************************************************/
}
}
-static void spinnit(void){
+static void spinnit(int n){
static int p=0;
static long lasttime=0;
long test;
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);
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);
/* 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,
/* 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++)
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];