2008-07-29 23:34:34 -07:00
|
|
|
/********************************************************************
|
|
|
|
* *
|
|
|
|
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
|
|
|
|
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
|
|
|
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
|
|
|
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
|
|
|
* *
|
2009-07-30 22:24:16 -07:00
|
|
|
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 *
|
2008-07-29 23:34:34 -07:00
|
|
|
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
|
|
|
* *
|
|
|
|
********************************************************************
|
|
|
|
|
|
|
|
function: basic shared codebook operations
|
2010-06-21 12:19:14 -07:00
|
|
|
last mod: $Id: codebook.h 17030 2010-03-25 06:52:55Z xiphmont $
|
2008-07-29 23:34:34 -07:00
|
|
|
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
#ifndef _V_CODEBOOK_H_
|
|
|
|
#define _V_CODEBOOK_H_
|
|
|
|
|
|
|
|
#include <ogg/ogg.h>
|
|
|
|
|
|
|
|
/* This structure encapsulates huffman and VQ style encoding books; it
|
|
|
|
doesn't do anything specific to either.
|
|
|
|
|
|
|
|
valuelist/quantlist are nonNULL (and q_* significant) only if
|
|
|
|
there's entry->value mapping to be done.
|
|
|
|
|
|
|
|
If encode-side mapping must be done (and thus the entry needs to be
|
|
|
|
hunted), the auxiliary encode pointer will point to a decision
|
|
|
|
tree. This is true of both VQ and huffman, but is mostly useful
|
|
|
|
with VQ.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct static_codebook{
|
|
|
|
long dim; /* codebook dimensions (elements per vector) */
|
|
|
|
long entries; /* codebook entries */
|
|
|
|
long *lengthlist; /* codeword lengths in bits */
|
|
|
|
|
|
|
|
/* mapping ***************************************************************/
|
|
|
|
int maptype; /* 0=none
|
2009-07-30 22:24:16 -07:00
|
|
|
1=implicitly populated values from map column
|
2009-07-06 15:10:04 -07:00
|
|
|
2=listed arbitrary values */
|
2008-07-29 23:34:34 -07:00
|
|
|
|
|
|
|
/* The below does a linear, single monotonic sequence mapping. */
|
|
|
|
long q_min; /* packed 32 bit float; quant value 0 maps to minval */
|
|
|
|
long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
|
|
|
|
int q_quant; /* bits: 0 < quant <= 16 */
|
|
|
|
int q_sequencep; /* bitflag */
|
|
|
|
|
|
|
|
long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
|
2009-07-06 15:10:04 -07:00
|
|
|
map == 2: list of dim*entries quantized entry vals
|
|
|
|
*/
|
2008-07-29 23:34:34 -07:00
|
|
|
int allocedp;
|
|
|
|
} static_codebook;
|
|
|
|
|
|
|
|
typedef struct codebook{
|
|
|
|
long dim; /* codebook dimensions (elements per vector) */
|
|
|
|
long entries; /* codebook entries */
|
|
|
|
long used_entries; /* populated codebook entries */
|
|
|
|
const static_codebook *c;
|
|
|
|
|
|
|
|
/* for encode, the below are entry-ordered, fully populated */
|
|
|
|
/* for decode, the below are ordered by bitreversed codeword and only
|
|
|
|
used entries are populated */
|
2009-07-30 22:24:16 -07:00
|
|
|
float *valuelist; /* list of dim*entries actual entry values */
|
2008-07-29 23:34:34 -07:00
|
|
|
ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
|
|
|
|
|
|
|
|
int *dec_index; /* only used if sparseness collapsed */
|
|
|
|
char *dec_codelengths;
|
|
|
|
ogg_uint32_t *dec_firsttable;
|
|
|
|
int dec_firsttablen;
|
|
|
|
int dec_maxlength;
|
|
|
|
|
2010-06-21 12:19:14 -07:00
|
|
|
/* The current encoder uses only centered, integer-only lattice books. */
|
|
|
|
int quantvals;
|
|
|
|
int minval;
|
|
|
|
int delta;
|
2008-07-29 23:34:34 -07:00
|
|
|
} codebook;
|
|
|
|
|
|
|
|
extern void vorbis_staticbook_destroy(static_codebook *b);
|
|
|
|
extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
|
|
|
|
extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
|
|
|
|
extern void vorbis_book_clear(codebook *b);
|
|
|
|
|
|
|
|
extern float *_book_unquantize(const static_codebook *b,int n,int *map);
|
|
|
|
extern float *_book_logdist(const static_codebook *b,float *vals);
|
|
|
|
extern float _float32_unpack(long val);
|
|
|
|
extern long _float32_pack(float val);
|
|
|
|
extern int _best(codebook *book, float *a, int step);
|
|
|
|
extern int _ilog(unsigned int v);
|
|
|
|
extern long _book_maptype1_quantvals(const static_codebook *b);
|
|
|
|
|
|
|
|
extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
|
|
|
|
extern long vorbis_book_codeword(codebook *book,int entry);
|
|
|
|
extern long vorbis_book_codelen(codebook *book,int entry);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
|
2010-06-21 12:19:14 -07:00
|
|
|
extern static_codebook *vorbis_staticbook_unpack(oggpack_buffer *b);
|
2008-07-29 23:34:34 -07:00
|
|
|
|
|
|
|
extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
|
|
|
|
|
|
|
|
extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
|
2009-07-30 22:24:16 -07:00
|
|
|
extern long vorbis_book_decodevs_add(codebook *book, float *a,
|
2009-07-06 15:10:04 -07:00
|
|
|
oggpack_buffer *b,int n);
|
2009-07-30 22:24:16 -07:00
|
|
|
extern long vorbis_book_decodev_set(codebook *book, float *a,
|
2009-07-06 15:10:04 -07:00
|
|
|
oggpack_buffer *b,int n);
|
2009-07-30 22:24:16 -07:00
|
|
|
extern long vorbis_book_decodev_add(codebook *book, float *a,
|
2009-07-06 15:10:04 -07:00
|
|
|
oggpack_buffer *b,int n);
|
2008-07-29 23:34:34 -07:00
|
|
|
extern long vorbis_book_decodevv_add(codebook *book, float **a,
|
2009-07-30 22:24:16 -07:00
|
|
|
long off,int ch,
|
2009-07-06 15:10:04 -07:00
|
|
|
oggpack_buffer *b,int n);
|
2008-07-29 23:34:34 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|