00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 #ifndef _V_CODEBOOK_H_
00019 #define _V_CODEBOOK_H_
00020 
00021 #include "ogg/ogg.h"
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 typedef struct static_codebook{
00037   long   dim;            
00038   long   entries;        
00039   long  *lengthlist;     
00040 
00041   
00042   int    maptype;        
00043 
00044 
00045 
00046   
00047   long     q_min;       
00048   long     q_delta;     
00049   int      q_quant;     
00050   int      q_sequencep; 
00051 
00052   long     *quantlist;  
00053 
00054 
00055 
00056   
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 
00065 
00066 typedef struct encode_aux_nearestmatch{
00067   
00068   long   *ptr0;
00069   long   *ptr1;
00070 
00071   long   *p;         
00072   long   *q;         
00073   long   aux;        
00074   long   alloc;       
00075 } encode_aux_nearestmatch;
00076 
00077 
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;           
00101   long entries;       
00102   long used_entries;  
00103   const static_codebook *c;
00104 
00105   
00106   
00107 
00108   float        *valuelist;    
00109   ogg_uint32_t *codelist;   
00110 
00111   int          *dec_index;  
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