codebook.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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-2014 *
  9. * by the Xiph.Org Foundation http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: basic shared codebook operations
  13. last mod: $Id: codebook.h 19057 2014-01-22 12:32:31Z xiphmont $
  14. ********************************************************************/
  15. #ifndef _V_CODEBOOK_H_
  16. #define _V_CODEBOOK_H_
  17. #include <ogg/ogg.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. char *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. int allocedp;
  44. } static_codebook;
  45. typedef struct codebook{
  46. long dim; /* codebook dimensions (elements per vector) */
  47. long entries; /* codebook entries */
  48. long used_entries; /* populated codebook entries */
  49. const static_codebook *c;
  50. /* for encode, the below are entry-ordered, fully populated */
  51. /* for decode, the below are ordered by bitreversed codeword and only
  52. used entries are populated */
  53. float *valuelist; /* list of dim*entries actual entry values */
  54. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  55. int *dec_index; /* only used if sparseness collapsed */
  56. char *dec_codelengths;
  57. ogg_uint32_t *dec_firsttable;
  58. int dec_firsttablen;
  59. int dec_maxlength;
  60. /* The current encoder uses only centered, integer-only lattice books. */
  61. int quantvals;
  62. int minval;
  63. int delta;
  64. } codebook;
  65. extern void vorbis_staticbook_destroy(static_codebook *b);
  66. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  67. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  68. extern void vorbis_book_clear(codebook *b);
  69. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  70. extern float *_book_logdist(const static_codebook *b,float *vals);
  71. extern float _float32_unpack(long val);
  72. extern long _float32_pack(float val);
  73. extern int _best(codebook *book, float *a, int step);
  74. extern int _ilog(unsigned int v);
  75. extern long _book_maptype1_quantvals(const static_codebook *b);
  76. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  77. extern long vorbis_book_codeword(codebook *book,int entry);
  78. extern long vorbis_book_codelen(codebook *book,int entry);
  79. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  80. extern static_codebook *vorbis_staticbook_unpack(oggpack_buffer *b);
  81. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  82. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  83. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  84. oggpack_buffer *b,int n);
  85. extern long vorbis_book_decodev_set(codebook *book, float *a,
  86. oggpack_buffer *b,int n);
  87. extern long vorbis_book_decodev_add(codebook *book, float *a,
  88. oggpack_buffer *b,int n);
  89. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  90. long off,int ch,
  91. oggpack_buffer *b,int n);
  92. #endif