1 /*---------------------------------------------------------------------------*\ 2 3 FILE........: quantise.h 4 AUTHOR......: David Rowe 5 DATE CREATED: 31/5/92 6 7 Quantisation functions for the sinusoidal coder. 8 9 \*---------------------------------------------------------------------------*/ 10 11 /* 12 All rights reserved. 13 14 This program is free software; you can redistribute it and/or modify 15 it under the terms of the GNU Lesser General Public License version 2.1, as 16 published by the Free Software Foundation. This program is 17 distributed in the hope that it will be useful, but WITHOUT ANY 18 WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 20 License for more details. 21 22 You should have received a copy of the GNU Lesser General Public License 23 along with this program; if not, see <http://www.gnu.org/licenses/>. 24 */ 25 26 #ifndef __QUANTISE__ 27 #define __QUANTISE__ 28 29 #include "codec2_fft.h" 30 #include "comp.h" 31 32 #define WO_BITS 7 33 #define WO_LEVELS (1<<WO_BITS) 34 #define WO_DT_BITS 3 35 36 #define E_BITS 5 37 #define E_LEVELS (1<<E_BITS) 38 #define E_MIN_DB -10.0 39 #define E_MAX_DB 40.0 40 41 #define LSP_SCALAR_INDEXES 10 42 #define LSPD_SCALAR_INDEXES 10 43 #define LSP_PRED_VQ_INDEXES 3 44 45 #define WO_E_BITS 8 46 47 #define LPCPF_GAMMA 0.5 48 #define LPCPF_BETA 0.2 49 50 float lpc_model_amplitudes(float Sn[], float w[], MODEL *model, int order, 51 int lsp,float ak[]); 52 void aks_to_M2(codec2_fftr_cfg fftr_fwd_cfg, float ak[], int order, MODEL *model, 53 float E, float *snr, int dump, int sim_pf, 54 int pf, int bass_boost, float beta, float gamma, COMP Aw[]); 55 56 int encode_Wo(C2CONST *c2const, float Wo, int bits); 57 float decode_Wo(C2CONST *c2const, int index, int bits); 58 int encode_log_Wo(C2CONST *c2const, float Wo, int bits); 59 float decode_log_Wo(C2CONST *c2const, int index, int bits); 60 void encode_lsps_scalar(int indexes[], float lsp[], int order); 61 void decode_lsps_scalar(float lsp[], int indexes[], int order); 62 void encode_lspds_scalar(int indexes[], float lsp[], int order); 63 void decode_lspds_scalar(float lsp[], int indexes[], int order); 64 65 void encode_lsps_vq(int *indexes, float *x, float *xq, int order); 66 void decode_lsps_vq(int *indexes, float *xq, int order, int stages); 67 68 long quantise(const float * cb, float vec[], float w[], int k, int m, float *se); 69 void lspvq_quantise(float lsp[], float lsp_[], int order); 70 void lspjvm_quantise(float lsps[], float lsps_[], int order); 71 72 void quantise_WoE(C2CONST *c2const, MODEL *model, float *e, float xq[]); 73 int encode_WoE(MODEL *model, float e, float xq[]); 74 void decode_WoE(C2CONST *c2const, MODEL *model, float *e, float xq[], int n1); 75 76 int encode_energy(float e, int bits); 77 float decode_energy(int index, int bits); 78 79 void pack(unsigned char * bits, unsigned int *nbit, int index, unsigned int index_bits); 80 void pack_natural_or_gray(unsigned char * bits, unsigned int *nbit, int index, unsigned int index_bits, unsigned int gray); 81 int unpack(const unsigned char * bits, unsigned int *nbit, unsigned int index_bits); 82 int unpack_natural_or_gray(const unsigned char * bits, unsigned int *nbit, unsigned int index_bits, unsigned int gray); 83 84 int lsp_bits(int i); 85 int lspd_bits(int i); 86 int lsp_pred_vq_bits(int i); 87 88 void apply_lpc_correction(MODEL *model); 89 float speech_to_uq_lsps(float lsp[], 90 float ak[], 91 float Sn[], 92 float w[], 93 int m_pitch, 94 int order 95 ); 96 int check_lsp_order(float lsp[], int lpc_order); 97 void bw_expand_lsps(float lsp[], int order, float min_sep_low, float min_sep_high); 98 void bw_expand_lsps2(float lsp[], int order); 99 void locate_lsps_jnd_steps(float lsp[], int order); 100 float decode_amplitudes(MODEL *model, 101 float ak[], 102 int lsp_indexes[], 103 int energy_index, 104 float lsps[], 105 float *e); 106 107 #endif 108