Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /******************************************************************** |
michael@0 | 2 | * * |
michael@0 | 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * |
michael@0 | 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
michael@0 | 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
michael@0 | 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
michael@0 | 7 | * * |
michael@0 | 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2014 * |
michael@0 | 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * |
michael@0 | 10 | * * |
michael@0 | 11 | ******************************************************************** |
michael@0 | 12 | |
michael@0 | 13 | function: basic shared codebook operations |
michael@0 | 14 | last mod: $Id: codebook.h 19057 2014-01-22 12:32:31Z xiphmont $ |
michael@0 | 15 | |
michael@0 | 16 | ********************************************************************/ |
michael@0 | 17 | |
michael@0 | 18 | #ifndef _V_CODEBOOK_H_ |
michael@0 | 19 | #define _V_CODEBOOK_H_ |
michael@0 | 20 | |
michael@0 | 21 | #include <ogg/ogg.h> |
michael@0 | 22 | |
michael@0 | 23 | /* This structure encapsulates huffman and VQ style encoding books; it |
michael@0 | 24 | doesn't do anything specific to either. |
michael@0 | 25 | |
michael@0 | 26 | valuelist/quantlist are nonNULL (and q_* significant) only if |
michael@0 | 27 | there's entry->value mapping to be done. |
michael@0 | 28 | |
michael@0 | 29 | If encode-side mapping must be done (and thus the entry needs to be |
michael@0 | 30 | hunted), the auxiliary encode pointer will point to a decision |
michael@0 | 31 | tree. This is true of both VQ and huffman, but is mostly useful |
michael@0 | 32 | with VQ. |
michael@0 | 33 | |
michael@0 | 34 | */ |
michael@0 | 35 | |
michael@0 | 36 | typedef struct static_codebook{ |
michael@0 | 37 | long dim; /* codebook dimensions (elements per vector) */ |
michael@0 | 38 | long entries; /* codebook entries */ |
michael@0 | 39 | char *lengthlist; /* codeword lengths in bits */ |
michael@0 | 40 | |
michael@0 | 41 | /* mapping ***************************************************************/ |
michael@0 | 42 | int maptype; /* 0=none |
michael@0 | 43 | 1=implicitly populated values from map column |
michael@0 | 44 | 2=listed arbitrary values */ |
michael@0 | 45 | |
michael@0 | 46 | /* The below does a linear, single monotonic sequence mapping. */ |
michael@0 | 47 | long q_min; /* packed 32 bit float; quant value 0 maps to minval */ |
michael@0 | 48 | long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */ |
michael@0 | 49 | int q_quant; /* bits: 0 < quant <= 16 */ |
michael@0 | 50 | int q_sequencep; /* bitflag */ |
michael@0 | 51 | |
michael@0 | 52 | long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map |
michael@0 | 53 | map == 2: list of dim*entries quantized entry vals |
michael@0 | 54 | */ |
michael@0 | 55 | int allocedp; |
michael@0 | 56 | } static_codebook; |
michael@0 | 57 | |
michael@0 | 58 | typedef struct codebook{ |
michael@0 | 59 | long dim; /* codebook dimensions (elements per vector) */ |
michael@0 | 60 | long entries; /* codebook entries */ |
michael@0 | 61 | long used_entries; /* populated codebook entries */ |
michael@0 | 62 | const static_codebook *c; |
michael@0 | 63 | |
michael@0 | 64 | /* for encode, the below are entry-ordered, fully populated */ |
michael@0 | 65 | /* for decode, the below are ordered by bitreversed codeword and only |
michael@0 | 66 | used entries are populated */ |
michael@0 | 67 | float *valuelist; /* list of dim*entries actual entry values */ |
michael@0 | 68 | ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */ |
michael@0 | 69 | |
michael@0 | 70 | int *dec_index; /* only used if sparseness collapsed */ |
michael@0 | 71 | char *dec_codelengths; |
michael@0 | 72 | ogg_uint32_t *dec_firsttable; |
michael@0 | 73 | int dec_firsttablen; |
michael@0 | 74 | int dec_maxlength; |
michael@0 | 75 | |
michael@0 | 76 | /* The current encoder uses only centered, integer-only lattice books. */ |
michael@0 | 77 | int quantvals; |
michael@0 | 78 | int minval; |
michael@0 | 79 | int delta; |
michael@0 | 80 | } codebook; |
michael@0 | 81 | |
michael@0 | 82 | extern void vorbis_staticbook_destroy(static_codebook *b); |
michael@0 | 83 | extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source); |
michael@0 | 84 | extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source); |
michael@0 | 85 | extern void vorbis_book_clear(codebook *b); |
michael@0 | 86 | |
michael@0 | 87 | extern float *_book_unquantize(const static_codebook *b,int n,int *map); |
michael@0 | 88 | extern float *_book_logdist(const static_codebook *b,float *vals); |
michael@0 | 89 | extern float _float32_unpack(long val); |
michael@0 | 90 | extern long _float32_pack(float val); |
michael@0 | 91 | extern int _best(codebook *book, float *a, int step); |
michael@0 | 92 | extern int _ilog(unsigned int v); |
michael@0 | 93 | extern long _book_maptype1_quantvals(const static_codebook *b); |
michael@0 | 94 | |
michael@0 | 95 | extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul); |
michael@0 | 96 | extern long vorbis_book_codeword(codebook *book,int entry); |
michael@0 | 97 | extern long vorbis_book_codelen(codebook *book,int entry); |
michael@0 | 98 | |
michael@0 | 99 | |
michael@0 | 100 | |
michael@0 | 101 | extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b); |
michael@0 | 102 | extern static_codebook *vorbis_staticbook_unpack(oggpack_buffer *b); |
michael@0 | 103 | |
michael@0 | 104 | extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b); |
michael@0 | 105 | |
michael@0 | 106 | extern long vorbis_book_decode(codebook *book, oggpack_buffer *b); |
michael@0 | 107 | extern long vorbis_book_decodevs_add(codebook *book, float *a, |
michael@0 | 108 | oggpack_buffer *b,int n); |
michael@0 | 109 | extern long vorbis_book_decodev_set(codebook *book, float *a, |
michael@0 | 110 | oggpack_buffer *b,int n); |
michael@0 | 111 | extern long vorbis_book_decodev_add(codebook *book, float *a, |
michael@0 | 112 | oggpack_buffer *b,int n); |
michael@0 | 113 | extern long vorbis_book_decodevv_add(codebook *book, float **a, |
michael@0 | 114 | long off,int ch, |
michael@0 | 115 | oggpack_buffer *b,int n); |
michael@0 | 116 | |
michael@0 | 117 | |
michael@0 | 118 | |
michael@0 | 119 | #endif |