1 /* Copyright (C) 2002 Jean-Marc Valin */
4 @brief Sub-band CELP mode used for wideband encoding
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
11 - Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
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.
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.
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.
40 #include <speex/speex_bits.h>
43 /**Structure representing the full state of the sub-band encoder*/
44 typedef struct SBEncState {
45 const SpeexMode *mode; /**< Pointer to the mode (containing for vtable info) */
46 void *st_low; /**< State of the low-band (narrowband) encoder */
47 int full_frame_size; /**< Length of full-band frames*/
48 int frame_size; /**< Length of high-band frames*/
49 int subframeSize; /**< Length of high-band sub-frames*/
50 int nbSubframes; /**< Number of high-band sub-frames*/
51 int windowSize; /**< Length of high-band LPC window*/
52 int lpcSize; /**< Order of high-band LPC analysis */
53 int bufSize; /**< Buffer size */
54 int first; /**< First frame? */
55 float lag_factor; /**< Lag-windowing control parameter */
56 float lpc_floor; /**< Controls LPC analysis noise floor */
57 spx_word16_t gamma1; /**< Perceptual weighting coef 1 */
58 spx_word16_t gamma2; /**< Perceptual weighting coef 2 */
60 char *stack; /**< Temporary allocation stack */
61 spx_sig_t *x0d, *x1d; /**< QMF filter signals*/
62 spx_sig_t *high; /**< High-band signal (buffer) */
63 spx_sig_t *y0, *y1; /**< QMF synthesis signals */
64 spx_word16_t *h0_mem, *h1_mem;
65 spx_word32_t *g0_mem, *g1_mem; /**< QMF memories */
67 spx_sig_t *excBuf; /**< High-band excitation */
68 spx_sig_t *exc; /**< High-band excitation (for QMF only)*/
69 spx_sig_t *buf; /**< Temporary buffer */
70 spx_sig_t *res; /**< Zero-input response (ringing) */
71 spx_sig_t *sw; /**< Perceptually weighted signal */
72 spx_sig_t *target; /**< Weighted target signal (analysis by synthesis) */
73 spx_word16_t *window; /**< LPC analysis window */
74 spx_word16_t *lagWindow; /**< Auto-correlation window */
75 spx_word16_t *autocorr; /**< Auto-correlation (for LPC analysis) */
76 spx_coef_t *lpc; /**< LPC coefficients */
77 spx_lsp_t *lsp; /**< LSP coefficients */
78 spx_lsp_t *qlsp; /**< Quantized LSPs */
79 spx_lsp_t *old_lsp; /**< LSPs of previous frame */
80 spx_lsp_t *old_qlsp; /**< Quantized LSPs of previous frame */
81 spx_lsp_t *interp_lsp; /**< Interpolated LSPs for current sub-frame */
82 spx_lsp_t *interp_qlsp; /**< Interpolated quantized LSPs for current sub-frame */
83 spx_coef_t *interp_lpc; /**< Interpolated LPCs for current sub-frame */
84 spx_coef_t *interp_qlpc; /**< Interpolated quantized LPCs for current sub-frame */
85 spx_coef_t *bw_lpc1; /**< Bandwidth-expanded version of LPCs (#1) */
86 spx_coef_t *bw_lpc2; /**< Bandwidth-expanded version of LPCs (#2) */
88 spx_mem_t *mem_sp; /**< Synthesis signal memory */
90 spx_mem_t *mem_sw; /**< Perceptual signal memory */
91 spx_word32_t *pi_gain;
93 float vbr_quality; /**< Quality setting for VBR encoding */
94 int vbr_enabled; /**< 1 for enabling VBR, 0 otherwise */
95 int abr_enabled; /**< ABR setting (in bps), 0 if off */
99 int vad_enabled; /**< 1 for enabling VAD, 0 otherwise */
100 float relative_quality;
103 const SpeexSubmode * const *submodes;
112 /**Structure representing the full state of the sub-band decoder*/
113 typedef struct SBDecState {
114 const SpeexMode *mode; /**< Pointer to the mode (containing for vtable info) */
115 void *st_low; /**< State of the low-band (narrowband) encoder */
126 spx_sig_t *x0d, *x1d;
129 spx_word32_t *g0_mem, *g1_mem;
134 spx_lsp_t *interp_qlsp;
135 spx_coef_t *interp_qlpc;
138 spx_word32_t *pi_gain;
141 const SpeexSubmode * const *submodes;
146 /**Initializes encoder state*/
147 void *sb_encoder_init(const SpeexMode *m);
149 /**De-allocates encoder state resources*/
150 void sb_encoder_destroy(void *state);
152 /**Encodes one frame*/
153 int sb_encode(void *state, void *in, SpeexBits *bits);
156 /**Initializes decoder state*/
157 void *sb_decoder_init(const SpeexMode *m);
159 /**De-allocates decoder state resources*/
160 void sb_decoder_destroy(void *state);
162 /**Decodes one frame*/
163 int sb_decode(void *state, SpeexBits *bits, void *out);
165 int sb_encoder_ctl(void *state, int request, void *ptr);
167 int sb_decoder_ctl(void *state, int request, void *ptr);