codebook.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
  5. * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
  6. * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
  9. * by Monty <monty@xiph.org> and the XIPHOPHORUS Company *
  10. * http://www.xiph.org/ *
  11. * *
  12. ********************************************************************
  13. function: basic shared codebook operations
  14. last mod: $Id: codebook.h,v 1.1.2.2 2000/11/04 06:21:43 xiphmont Exp $
  15. ********************************************************************/
  16. #ifndef _V_CODEBOOK_H_
  17. #define _V_CODEBOOK_H_
  18. /* This structure encapsulates huffman and VQ style encoding books; it
  19. doesn't do anything specific to either.
  20. valuelist/quantlist are nonNULL (and q_* significant) only if
  21. there's entry->value mapping to be done.
  22. If encode-side mapping must be done (and thus the entry needs to be
  23. hunted), the auxiliary encode pointer will point to a decision
  24. tree. This is true of both VQ and huffman, but is mostly useful
  25. with VQ.
  26. */
  27. typedef struct static_codebook{
  28. long dim; /* codebook dimensions (elements per vector) */
  29. long entries; /* codebook entries */
  30. long *lengthlist; /* codeword lengths in bits */
  31. /* mapping ***************************************************************/
  32. int maptype; /* 0=none
  33. 1=implicitly populated values from map column
  34. 2=listed arbitrary values */
  35. /* The below does a linear, single monotonic sequence mapping. */
  36. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  37. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  38. int q_quant; /* bits: 0 < quant <= 16 */
  39. int q_sequencep; /* bitflag */
  40. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  41. map == 2: list of dim*entries quantized entry vals
  42. */
  43. /* encode helpers ********************************************************/
  44. struct encode_aux_nearestmatch *nearest_tree;
  45. struct encode_aux_threshmatch *thresh_tree;
  46. struct encode_aux_pigeonhole *pigeon_tree;
  47. int allocedp;
  48. } static_codebook;
  49. /* this structures an arbitrary trained book to quickly find the
  50. nearest cell match */
  51. typedef struct encode_aux_nearestmatch{
  52. /* pre-calculated partitioning tree */
  53. long *ptr0;
  54. long *ptr1;
  55. long *p; /* decision points (each is an entry) */
  56. long *q; /* decision points (each is an entry) */
  57. long aux; /* number of tree entries */
  58. long alloc;
  59. } encode_aux_nearestmatch;
  60. /* assumes a maptype of 1; encode side only, so that's OK */
  61. typedef struct encode_aux_threshmatch{
  62. float *quantthresh;
  63. long *quantmap;
  64. int quantvals;
  65. int threshvals;
  66. } encode_aux_threshmatch;
  67. typedef struct encode_aux_pigeonhole{
  68. float min;
  69. float del;
  70. int mapentries;
  71. int quantvals;
  72. long *pigeonmap;
  73. long fittotal;
  74. long *fitlist;
  75. long *fitmap;
  76. long *fitlength;
  77. } encode_aux_pigeonhole;
  78. typedef struct decode_aux{
  79. long *tab;
  80. int *tabl;
  81. int tabn;
  82. long *ptr0;
  83. long *ptr1;
  84. long aux; /* number of tree entries */
  85. } decode_aux;
  86. typedef struct codebook{
  87. long dim; /* codebook dimensions (elements per vector) */
  88. long entries; /* codebook entries */
  89. const static_codebook *c;
  90. float *valuelist; /* list of dim*entries actual entry values */
  91. long *codelist; /* list of bitstream codewords for each entry */
  92. struct decode_aux *decode_tree;
  93. } codebook;
  94. extern void vorbis_staticbook_clear(static_codebook *b);
  95. extern void vorbis_staticbook_destroy(static_codebook *b);
  96. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  97. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  98. extern void vorbis_book_clear(codebook *b);
  99. extern float *_book_unquantize(const static_codebook *b);
  100. extern float *_book_logdist(const static_codebook *b,float *vals);
  101. extern float _float32_unpack(long val);
  102. extern long _float32_pack(float val);
  103. extern int _best(codebook *book, float *a, int step);
  104. extern int _ilog(unsigned int v);
  105. extern long _book_maptype1_quantvals(const static_codebook *b);
  106. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  107. extern long vorbis_book_codeword(codebook *book,int entry);
  108. extern long vorbis_book_codelen(codebook *book,int entry);
  109. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  110. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  111. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  112. extern int vorbis_book_errorv(codebook *book, float *a);
  113. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  114. oggpack_buffer *b);
  115. extern int vorbis_book_encodevs(codebook *book, float *a, oggpack_buffer *b,
  116. int step,int stagetype);
  117. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  118. extern long vorbis_book_decodevs(codebook *book, float *a, oggpack_buffer *b,
  119. int step,int stagetype);
  120. extern long s_vorbis_book_decodevs(codebook *book, float *a, oggpack_buffer *b,
  121. int step,int stagetype);
  122. #endif