/********************************************************************1* *2* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *3* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *4* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *5* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *6* *7* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015 *8* by the Xiph.Org Foundation https://xiph.org/ *9* *10********************************************************************1112function: basic shared codebook operations1314********************************************************************/1516#ifndef _V_CODEBOOK_H_17#define _V_CODEBOOK_H_1819#include <ogg/ogg.h>2021/* This structure encapsulates huffman and VQ style encoding books; it22doesn't do anything specific to either.2324valuelist/quantlist are nonNULL (and q_* significant) only if25there's entry->value mapping to be done.2627If encode-side mapping must be done (and thus the entry needs to be28hunted), the auxiliary encode pointer will point to a decision29tree. This is true of both VQ and huffman, but is mostly useful30with VQ.3132*/3334typedef struct static_codebook{35long dim; /* codebook dimensions (elements per vector) */36long entries; /* codebook entries */37char *lengthlist; /* codeword lengths in bits */3839/* mapping ***************************************************************/40int maptype; /* 0=none411=implicitly populated values from map column422=listed arbitrary values */4344/* The below does a linear, single monotonic sequence mapping. */45long q_min; /* packed 32 bit float; quant value 0 maps to minval */46long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */47int q_quant; /* bits: 0 < quant <= 16 */48int q_sequencep; /* bitflag */4950long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map51map == 2: list of dim*entries quantized entry vals52*/53int allocedp;54} static_codebook;5556typedef struct codebook{57long dim; /* codebook dimensions (elements per vector) */58long entries; /* codebook entries */59long used_entries; /* populated codebook entries */60const static_codebook *c;6162/* for encode, the below are entry-ordered, fully populated */63/* for decode, the below are ordered by bitreversed codeword and only64used entries are populated */65float *valuelist; /* list of dim*entries actual entry values */66ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */6768int *dec_index; /* only used if sparseness collapsed */69char *dec_codelengths;70ogg_uint32_t *dec_firsttable;71int dec_firsttablen;72int dec_maxlength;7374/* The current encoder uses only centered, integer-only lattice books. */75int quantvals;76int minval;77int delta;78} codebook;7980extern void vorbis_staticbook_destroy(static_codebook *b);81extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);82extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);83extern void vorbis_book_clear(codebook *b);8485extern float *_book_unquantize(const static_codebook *b,int n,int *map);86extern float *_book_logdist(const static_codebook *b,float *vals);87extern float _float32_unpack(long val);88extern long _float32_pack(float val);89extern int _best(codebook *book, float *a, int step);90extern long _book_maptype1_quantvals(const static_codebook *b);9192extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);93extern long vorbis_book_codeword(codebook *book,int entry);94extern long vorbis_book_codelen(codebook *book,int entry);95969798extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);99extern static_codebook *vorbis_staticbook_unpack(oggpack_buffer *b);100101extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);102103extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);104extern long vorbis_book_decodevs_add(codebook *book, float *a,105oggpack_buffer *b,int n);106extern long vorbis_book_decodev_set(codebook *book, float *a,107oggpack_buffer *b,int n);108extern long vorbis_book_decodev_add(codebook *book, float *a,109oggpack_buffer *b,int n);110extern long vorbis_book_decodevv_add(codebook *book, float **a,111long off,int ch,112oggpack_buffer *b,int n);113114115116#endif117118119