codebook.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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-2015 *
  9. * by the Xiph.Org Foundation http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: basic shared codebook operations
  13. ********************************************************************/
  14. #ifndef _V_CODEBOOK_H_
  15. #define _V_CODEBOOK_H_
  16. #include <ogg/ogg.h>
  17. /* This structure encapsulates huffman and VQ style encoding books; it
  18. doesn't do anything specific to either.
  19. valuelist/quantlist are nonNULL (and q_* significant) only if
  20. there's entry->value mapping to be done.
  21. If encode-side mapping must be done (and thus the entry needs to be
  22. hunted), the auxiliary encode pointer will point to a decision
  23. tree. This is true of both VQ and huffman, but is mostly useful
  24. with VQ.
  25. */
  26. typedef struct static_codebook{
  27. long dim; /* codebook dimensions (elements per vector) */
  28. long entries; /* codebook entries */
  29. char *lengthlist; /* codeword lengths in bits */
  30. /* mapping ***************************************************************/
  31. int maptype; /* 0=none
  32. 1=implicitly populated values from map column
  33. 2=listed arbitrary values */
  34. /* The below does a linear, single monotonic sequence mapping. */
  35. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  36. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  37. int q_quant; /* bits: 0 < quant <= 16 */
  38. int q_sequencep; /* bitflag */
  39. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  40. map == 2: list of dim*entries quantized entry vals
  41. */
  42. int allocedp;
  43. } static_codebook;
  44. typedef struct codebook{
  45. long dim; /* codebook dimensions (elements per vector) */
  46. long entries; /* codebook entries */
  47. long used_entries; /* populated codebook entries */
  48. const static_codebook *c;
  49. /* for encode, the below are entry-ordered, fully populated */
  50. /* for decode, the below are ordered by bitreversed codeword and only
  51. used entries are populated */
  52. float *valuelist; /* list of dim*entries actual entry values */
  53. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  54. int *dec_index; /* only used if sparseness collapsed */
  55. char *dec_codelengths;
  56. ogg_uint32_t *dec_firsttable;
  57. int dec_firsttablen;
  58. int dec_maxlength;
  59. /* The current encoder uses only centered, integer-only lattice books. */
  60. int quantvals;
  61. int minval;
  62. int delta;
  63. } codebook;
  64. extern void vorbis_staticbook_destroy(static_codebook *b);
  65. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  66. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  67. extern void vorbis_book_clear(codebook *b);
  68. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  69. extern float *_book_logdist(const static_codebook *b,float *vals);
  70. extern float _float32_unpack(long val);
  71. extern long _float32_pack(float val);
  72. extern int _best(codebook *book, float *a, int step);
  73. extern long _book_maptype1_quantvals(const static_codebook *b);
  74. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  75. extern long vorbis_book_codeword(codebook *book,int entry);
  76. extern long vorbis_book_codelen(codebook *book,int entry);
  77. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  78. extern static_codebook *vorbis_staticbook_unpack(oggpack_buffer *b);
  79. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  80. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  81. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  82. oggpack_buffer *b,int n);
  83. extern long vorbis_book_decodev_set(codebook *book, float *a,
  84. oggpack_buffer *b,int n);
  85. extern long vorbis_book_decodev_add(codebook *book, float *a,
  86. oggpack_buffer *b,int n);
  87. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  88. long off,int ch,
  89. oggpack_buffer *b,int n);
  90. #endif