blob: 945d00462bf7e5e41eead30a33a5eae983f10311 [file] [log] [blame]
Benny Prijonoeb30bf52006-03-04 20:43:52 +00001/* Copyright (C) 2002 Jean-Marc Valin */
2/**
3 @file modes.h
4 @brief Describes the different modes of the codec
5*/
6/*
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 - Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13
14 - Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17
18 - Neither the name of the Xiph.org Foundation nor the names of its
19 contributors may be used to endorse or promote products derived from
20 this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
26 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#ifndef MODES_H
37#define MODES_H
38
39#include <speex/speex.h>
40#include <speex/speex_bits.h>
41#include "misc.h"
42
43#define NB_SUBMODES 16
44#define NB_SUBMODE_BITS 4
45
46#define SB_SUBMODES 8
47#define SB_SUBMODE_BITS 3
48
49
50/** Quantizes LSPs */
51typedef void (*lsp_quant_func)(spx_lsp_t *, spx_lsp_t *, int, SpeexBits *);
52
53/** Decodes quantized LSPs */
54typedef void (*lsp_unquant_func)(spx_lsp_t *, int, SpeexBits *);
55
56
57/** Long-term predictor quantization */
58typedef int (*ltp_quant_func)(spx_sig_t *, spx_sig_t *, spx_coef_t *, spx_coef_t *,
59 spx_coef_t *, spx_sig_t *, const void *, int, int, spx_word16_t,
60 int, int, SpeexBits*, char *, spx_sig_t *, spx_word16_t *, int, int, int);
61
62/** Long-term un-quantize */
63typedef void (*ltp_unquant_func)(spx_sig_t *, int, int, spx_word16_t, const void *, int, int *,
64 spx_word16_t *, SpeexBits*, char*, int, int, spx_word16_t, int);
65
66
67/** Innovation quantization function */
68typedef void (*innovation_quant_func)(spx_sig_t *, spx_coef_t *, spx_coef_t *, spx_coef_t *, const void *, int, int,
69 spx_sig_t *, spx_word16_t *, SpeexBits *, char *, int, int);
70
71/** Innovation unquantization function */
72typedef void (*innovation_unquant_func)(spx_sig_t *, const void *, int, SpeexBits*, char *);
73
74/** Description of a Speex sub-mode (wither narrowband or wideband */
75typedef struct SpeexSubmode {
76 int lbr_pitch; /**< Set to -1 for "normal" modes, otherwise encode pitch using a global pitch and allowing a +- lbr_pitch variation (for low not-rates)*/
77 int forced_pitch_gain; /**< Use the same (forced) pitch gain for all sub-frames */
78 int have_subframe_gain; /**< Number of bits to use as sub-frame innovation gain */
79 int double_codebook; /**< Apply innovation quantization twice for higher quality (and higher bit-rate)*/
80 /*LSP functions*/
81 lsp_quant_func lsp_quant; /**< LSP quantization function */
82 lsp_unquant_func lsp_unquant; /**< LSP unquantization function */
83
84 /*Lont-term predictor functions*/
85 ltp_quant_func ltp_quant; /**< Long-term predictor (pitch) quantizer */
86 ltp_unquant_func ltp_unquant; /**< Long-term predictor (pitch) un-quantizer */
87 const void *ltp_params; /**< Pitch parameters (options) */
88
89 /*Quantization of innovation*/
90 innovation_quant_func innovation_quant; /**< Innovation quantization */
91 innovation_unquant_func innovation_unquant; /**< Innovation un-quantization */
92 const void *innovation_params; /**< Innovation quantization parameters*/
93
94 /*Synthesis filter enhancement*/
95 spx_word16_t lpc_enh_k1; /**< Enhancer constant */
96 spx_word16_t lpc_enh_k2; /**< Enhancer constant */
97 spx_word16_t lpc_enh_k3; /**< Enhancer constant */
98 spx_word16_t comb_gain; /**< Gain of enhancer comb filter */
99
100 int bits_per_frame; /**< Number of bits per frame after encoding*/
101} SpeexSubmode;
102
103/** Struct defining the encoding/decoding mode*/
104typedef struct SpeexNBMode {
105 int frameSize; /**< Size of frames used for encoding */
106 int subframeSize; /**< Size of sub-frames used for encoding */
107 int lpcSize; /**< Order of LPC filter */
108 int pitchStart; /**< Smallest pitch value allowed */
109 int pitchEnd; /**< Largest pitch value allowed */
110
111 spx_word16_t gamma1; /**< Perceptual filter parameter #1 */
112 spx_word16_t gamma2; /**< Perceptual filter parameter #2 */
113 float lag_factor; /**< Lag-windowing parameter */
114 spx_word16_t lpc_floor; /**< Noise floor for LPC analysis */
115
116#ifdef EPIC_48K
117 int lbr48k; /**< 1 for the special 4.8 kbps mode */
118#endif
119
120 const SpeexSubmode *submodes[NB_SUBMODES]; /**< Sub-mode data for the mode */
121 int defaultSubmode; /**< Default sub-mode to use when encoding */
122 int quality_map[11]; /**< Mode corresponding to each quality setting */
123} SpeexNBMode;
124
125
126/** Struct defining the encoding/decoding mode for SB-CELP (wideband) */
127typedef struct SpeexSBMode {
128 const SpeexMode *nb_mode; /**< Embedded narrowband mode */
129 int frameSize; /**< Size of frames used for encoding */
130 int subframeSize; /**< Size of sub-frames used for encoding */
131 int lpcSize; /**< Order of LPC filter */
132 int bufSize; /**< Signal buffer size in encoder */
133 spx_word16_t gamma1; /**< Perceptual filter parameter #1 */
134 spx_word16_t gamma2; /**< Perceptual filter parameter #1 */
135 float lag_factor; /**< Lag-windowing parameter */
136 spx_word16_t lpc_floor; /**< Noise floor for LPC analysis */
137 float folding_gain;
138
139 const SpeexSubmode *submodes[SB_SUBMODES]; /**< Sub-mode data for the mode */
140 int defaultSubmode; /**< Default sub-mode to use when encoding */
141 int low_quality_map[11]; /**< Mode corresponding to each quality setting */
142 int quality_map[11]; /**< Mode corresponding to each quality setting */
143 const float (*vbr_thresh)[11];
144 int nb_modes;
145} SpeexSBMode;
146
147int speex_encode_native(void *state, spx_word16_t *in, SpeexBits *bits);
148int speex_decode_native(void *state, SpeexBits *bits, spx_word16_t *out);
149
150int nb_mode_query(const void *mode, int request, void *ptr);
151int wb_mode_query(const void *mode, int request, void *ptr);
152
153#endif