doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
codebook.h
Go to the documentation of this file.
1 /********************************************************************
2  * *
3  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
7  * *
8  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
9  * by the XIPHOPHORUS Company http://www.xiph.org/ *
10  * *
11  ********************************************************************
12 
13  function: basic shared codebook operations
14  last mod: $Id: codebook.h,v 1.13 2002/06/28 22:19:35 xiphmont Exp $
15 
16  ********************************************************************/
17 
18 #ifndef _V_CODEBOOK_H_
19 #define _V_CODEBOOK_H_
20 
21 #include "../ogg/ogg.h"
22 
23 /* This structure encapsulates huffman and VQ style encoding books; it
24  doesn't do anything specific to either.
25 
26  valuelist/quantlist are nonNULL (and q_* significant) only if
27  there's entry->value mapping to be done.
28 
29  If encode-side mapping must be done (and thus the entry needs to be
30  hunted), the auxiliary encode pointer will point to a decision
31  tree. This is true of both VQ and huffman, but is mostly useful
32  with VQ.
33 
34 */
35 
36 typedef struct static_codebook{
37  long dim; /* codebook dimensions (elements per vector) */
38  long entries; /* codebook entries */
39  long *lengthlist; /* codeword lengths in bits */
40 
41  /* mapping ***************************************************************/
42  int maptype; /* 0=none
43  1=implicitly populated values from map column
44  2=listed arbitrary values */
45 
46  /* The below does a linear, single monotonic sequence mapping. */
47  long q_min; /* packed 32 bit float; quant value 0 maps to minval */
48  long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
49  int q_quant; /* bits: 0 < quant <= 16 */
50  int q_sequencep; /* bitflag */
51 
52  long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
53  map == 2: list of dim*entries quantized entry vals
54  */
55 
56  /* encode helpers ********************************************************/
60 
61  int allocedp;
63 
64 /* this structures an arbitrary trained book to quickly find the
65  nearest cell match */
66 typedef struct encode_aux_nearestmatch{
67  /* pre-calculated partitioning tree */
68  long *ptr0;
69  long *ptr1;
70 
71  long *p; /* decision points (each is an entry) */
72  long *q; /* decision points (each is an entry) */
73  long aux; /* number of tree entries */
74  long alloc;
76 
77 /* assumes a maptype of 1; encode side only, so that's OK */
78 typedef struct encode_aux_threshmatch{
79  float *quantthresh;
80  long *quantmap;
81  int quantvals;
82  int threshvals;
84 
85 typedef struct encode_aux_pigeonhole{
86  float min;
87  float del;
88 
90  int quantvals;
91  long *pigeonmap;
92 
93  long fittotal;
94  long *fitlist;
95  long *fitmap;
96  long *fitlength;
98 
99 typedef struct codebook{
100  long dim; /* codebook dimensions (elements per vector) */
101  long entries; /* codebook entries */
102  long used_entries; /* populated codebook entries */
104 
105  /* for encode, the below are entry-ordered, fully populated */
106  /* for decode, the below are ordered by bitreversed codeword and only
107  used entries are populated */
108  float *valuelist; /* list of dim*entries actual entry values */
109  ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
110 
111  int *dec_index; /* only used if sparseness collapsed */
116 
117 } codebook;
118 
121 extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
122 extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
123 extern void vorbis_book_clear(codebook *b);
124 
125 extern float *_book_unquantize(const static_codebook *b,int n,int *map);
126 extern float *_book_logdist(const static_codebook *b,float *vals);
127 extern float _float32_unpack(long val);
128 extern long _float32_pack(float val);
129 extern int _best(codebook *book, float *a, int step);
130 extern int _ilog(unsigned int v);
131 extern long _book_maptype1_quantvals(const static_codebook *b);
132 
133 extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
134 extern long vorbis_book_codeword(codebook *book,int entry);
135 extern long vorbis_book_codelen(codebook *book,int entry);
136 
137 
138 
141 
142 extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
143 extern int vorbis_book_errorv(codebook *book, float *a);
144 extern int vorbis_book_encodev(codebook *book, int best,float *a,
145  oggpack_buffer *b);
146 
147 extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
148 extern long vorbis_book_decodevs_add(codebook *book, float *a,
149  oggpack_buffer *b,int n);
150 extern long vorbis_book_decodev_set(codebook *book, float *a,
151  oggpack_buffer *b,int n);
152 extern long vorbis_book_decodev_add(codebook *book, float *a,
153  oggpack_buffer *b,int n);
154 extern long vorbis_book_decodevv_add(codebook *book, float **a,
155  long off,int ch,
156  oggpack_buffer *b,int n);
157 
158 
159 
160 #endif
int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b)
Definition: codebook.c:257
struct encode_aux_threshmatch encode_aux_threshmatch
long vorbis_book_codeword(codebook *book, int entry)
Definition: sharedbook.c:585
long vorbis_book_decodevs_add(codebook *book, float *a, oggpack_buffer *b, int n)
Definition: codebook.c:380
long dim
Definition: codebook.h:100
int * dec_index
Definition: codebook.h:111
u_int32_t ogg_uint32_t
Definition: os_types.h:139
long vorbis_book_decodevv_add(codebook *book, float **a, long off, int ch, oggpack_buffer *b, int n)
Definition: codebook.c:454
void vorbis_staticbook_destroy(static_codebook *b)
Definition: sharedbook.c:271
const static_codebook * c
Definition: codebook.h:103
const GLdouble * v
Definition: glext.h:2936
long vorbis_book_decode(codebook *book, oggpack_buffer *b)
Definition: codebook.c:370
GLenum GLsizei n
Definition: glext.h:3705
int vorbis_book_errorv(codebook *book, float *a)
Definition: codebook.c:277
long vorbis_book_codelen(codebook *book, int entry)
Definition: sharedbook.c:592
ogg_uint32_t * codelist
Definition: codebook.h:109
struct encode_aux_nearestmatch encode_aux_nearestmatch
struct encode_aux_pigeonhole encode_aux_pigeonhole
int vorbis_book_init_decode(codebook *dest, const static_codebook *source)
Definition: sharedbook.c:318
struct encode_aux_pigeonhole * pigeon_tree
Definition: codebook.h:59
ogg_uint32_t * dec_firsttable
Definition: codebook.h:113
GLsizei GLsizei GLcharARB * source
Definition: glext.h:3633
long used_entries
Definition: codebook.h:102
float * _book_unquantize(const static_codebook *b, int n, int *map)
Definition: sharedbook.c:183
void vorbis_book_clear(codebook *b)
Definition: sharedbook.c:278
const GLubyte * c
Definition: glext.h:4677
float _float32_unpack(long val)
Definition: sharedbook.c:62
int vorbis_book_besterror(codebook *book, float *a, int step, int addmul)
int vorbis_book_encodev(codebook *book, int best, float *a, oggpack_buffer *b)
Definition: codebook.c:286
long * quantlist
Definition: codebook.h:52
int _best(codebook *book, float *a, int step)
Definition: sharedbook.c:444
int vorbis_staticbook_unpack(oggpack_buffer *b, static_codebook *c)
Definition: codebook.c:149
long _float32_pack(float val)
Definition: sharedbook.c:47
int _ilog(unsigned int v)
Definition: sharedbook.c:29
GLubyte GLubyte GLubyte a
Definition: glext.h:4662
struct codebook codebook
GLubyte GLubyte b
Definition: glext.h:4662
long vorbis_book_decodev_add(codebook *book, float *a, oggpack_buffer *b, int n)
Definition: codebook.c:397
int vorbis_book_init_encode(codebook *dest, const static_codebook *source)
Definition: sharedbook.c:291
int dec_maxlength
Definition: codebook.h:115
float * _book_logdist(const static_codebook *b, float *vals)
long _book_maptype1_quantvals(const static_codebook *b)
Definition: sharedbook.c:150
int vorbis_staticbook_pack(const static_codebook *c, oggpack_buffer *b)
Definition: codebook.c:30
struct static_codebook static_codebook
struct encode_aux_threshmatch * thresh_tree
Definition: codebook.h:58
long vorbis_book_decodev_set(codebook *book, float *a, oggpack_buffer *b, int n)
Definition: codebook.c:440
float * valuelist
Definition: codebook.h:108
long * lengthlist
Definition: codebook.h:39
char * dec_codelengths
Definition: codebook.h:112
struct encode_aux_nearestmatch * nearest_tree
Definition: codebook.h:57
void vorbis_staticbook_clear(static_codebook *b)
Definition: sharedbook.c:248
long entries
Definition: codebook.h:101
int dec_firsttablen
Definition: codebook.h:114