Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

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