examples/sfexamples/oggvorbiscodec/src/libvorbis/lib/codebook.h

00001 /********************************************************************
00002  *                                                                  *
00003  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
00004  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
00005  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
00006  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
00007  *                                                                  *
00008  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
00009  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
00010  *                                                                  *
00011  ********************************************************************
00012 
00013  function: basic shared codebook operations
00014  last mod: $Id: codebook.h 7187 2004-07-20 07:24:27Z xiphmont $
00015 
00016  ********************************************************************/
00017 
00018 #ifndef _V_CODEBOOK_H_
00019 #define _V_CODEBOOK_H_
00020 
00021 #include "ogg/ogg.h"
00022 
00023 /* This structure encapsulates huffman and VQ style encoding books; it
00024    doesn't do anything specific to either.
00025 
00026    valuelist/quantlist are nonNULL (and q_* significant) only if
00027    there's entry->value mapping to be done.
00028 
00029    If encode-side mapping must be done (and thus the entry needs to be
00030    hunted), the auxiliary encode pointer will point to a decision
00031    tree.  This is true of both VQ and huffman, but is mostly useful
00032    with VQ.
00033 
00034 */
00035 
00036 typedef struct static_codebook{
00037   long   dim;            /* codebook dimensions (elements per vector) */
00038   long   entries;        /* codebook entries */
00039   long  *lengthlist;     /* codeword lengths in bits */
00040 
00041   /* mapping ***************************************************************/
00042   int    maptype;        /* 0=none
00043                             1=implicitly populated values from map column 
00044                             2=listed arbitrary values */
00045 
00046   /* The below does a linear, single monotonic sequence mapping. */
00047   long     q_min;       /* packed 32 bit float; quant value 0 maps to minval */
00048   long     q_delta;     /* packed 32 bit float; val 1 - val 0 == delta */
00049   int      q_quant;     /* bits: 0 < quant <= 16 */
00050   int      q_sequencep; /* bitflag */
00051 
00052   long     *quantlist;  /* map == 1: (int)(entries^(1/dim)) element column map
00053                            map == 2: list of dim*entries quantized entry vals
00054                         */
00055 
00056   /* encode helpers ********************************************************/
00057   struct encode_aux_nearestmatch *nearest_tree;
00058   struct encode_aux_threshmatch  *thresh_tree;
00059   struct encode_aux_pigeonhole  *pigeon_tree;
00060 
00061   int allocedp;
00062 } static_codebook;
00063 
00064 /* this structures an arbitrary trained book to quickly find the
00065    nearest cell match */
00066 typedef struct encode_aux_nearestmatch{
00067   /* pre-calculated partitioning tree */
00068   long   *ptr0;
00069   long   *ptr1;
00070 
00071   long   *p;         /* decision points (each is an entry) */
00072   long   *q;         /* decision points (each is an entry) */
00073   long   aux;        /* number of tree entries */
00074   long   alloc;       
00075 } encode_aux_nearestmatch;
00076 
00077 /* assumes a maptype of 1; encode side only, so that's OK */
00078 typedef struct encode_aux_threshmatch{
00079   float *quantthresh;
00080   long   *quantmap;
00081   int     quantvals; 
00082   int     threshvals; 
00083 } encode_aux_threshmatch;
00084 
00085 typedef struct encode_aux_pigeonhole{
00086   float min;
00087   float del;
00088 
00089   int  mapentries;
00090   int  quantvals;
00091   long *pigeonmap;
00092 
00093   long fittotal;
00094   long *fitlist;
00095   long *fitmap;
00096   long *fitlength;
00097 } encode_aux_pigeonhole;
00098 
00099 typedef struct codebook{
00100   long dim;           /* codebook dimensions (elements per vector) */
00101   long entries;       /* codebook entries */
00102   long used_entries;  /* populated codebook entries */
00103   const static_codebook *c;
00104 
00105   /* for encode, the below are entry-ordered, fully populated */
00106   /* for decode, the below are ordered by bitreversed codeword and only
00107      used entries are populated */
00108   float        *valuelist;  /* list of dim*entries actual entry values */  
00109   ogg_uint32_t *codelist;   /* list of bitstream codewords for each entry */
00110 
00111   int          *dec_index;  /* only used if sparseness collapsed */
00112   char         *dec_codelengths;
00113   ogg_uint32_t *dec_firsttable;
00114   int           dec_firsttablen;
00115   int           dec_maxlength;
00116 
00117 } codebook;
00118 
00119 extern void vorbis_staticbook_clear(static_codebook *b);
00120 extern void vorbis_staticbook_destroy(static_codebook *b);
00121 extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
00122 extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
00123 extern void vorbis_book_clear(codebook *b);
00124 
00125 extern float *_book_unquantize(const static_codebook *b,int n,int *map);
00126 extern float *_book_logdist(const static_codebook *b,float *vals);
00127 extern float _float32_unpack(long val);
00128 extern long   _float32_pack(float val);
00129 extern int  _best(codebook *book, float *a, int step);
00130 extern int _ilog(unsigned int v);
00131 extern long _book_maptype1_quantvals(const static_codebook *b);
00132 
00133 extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
00134 extern long vorbis_book_codeword(codebook *book,int entry);
00135 extern long vorbis_book_codelen(codebook *book,int entry);
00136 
00137 
00138 
00139 extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
00140 extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
00141 
00142 extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
00143 extern int vorbis_book_errorv(codebook *book, float *a);
00144 extern int vorbis_book_encodev(codebook *book, int best,float *a, 
00145                                oggpack_buffer *b);
00146 
00147 extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
00148 extern long vorbis_book_decodevs_add(codebook *book, float *a, 
00149                                      oggpack_buffer *b,int n);
00150 extern long vorbis_book_decodev_set(codebook *book, float *a, 
00151                                     oggpack_buffer *b,int n);
00152 extern long vorbis_book_decodev_add(codebook *book, float *a, 
00153                                     oggpack_buffer *b,int n);
00154 extern long vorbis_book_decodevv_add(codebook *book, float **a,
00155                                      long off,int ch, 
00156                                     oggpack_buffer *b,int n);
00157 
00158 
00159 
00160 #endif

Generated by  doxygen 1.6.2