1
/* Copyright (C) 2002-2006 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 first; /**< First frame? */
54
spx_word16_t lpc_floor; /**< Controls LPC analysis noise floor */
55
spx_word16_t gamma1; /**< Perceptual weighting coef 1 */
56
spx_word16_t gamma2; /**< Perceptual weighting coef 2 */
58
char *stack; /**< Temporary allocation stack */
59
spx_word16_t *high; /**< High-band signal (buffer) */
60
spx_word16_t *h0_mem, *h1_mem;
62
const spx_word16_t *window; /**< LPC analysis window */
63
const spx_word16_t *lagWindow; /**< Auto-correlation window */
64
spx_lsp_t *old_lsp; /**< LSPs of previous frame */
65
spx_lsp_t *old_qlsp; /**< Quantized LSPs of previous frame */
66
spx_coef_t *interp_qlpc; /**< Interpolated quantized LPCs for current sub-frame */
68
spx_mem_t *mem_sp; /**< Synthesis signal memory */
70
spx_mem_t *mem_sw; /**< Perceptual signal memory */
71
spx_word32_t *pi_gain;
72
spx_word16_t *exc_rms;
73
spx_word16_t *innov_rms_save; /**< If non-NULL, innovation is copied here */
76
float vbr_quality; /**< Quality setting for VBR encoding */
77
int vbr_enabled; /**< 1 for enabling VBR, 0 otherwise */
78
spx_int32_t vbr_max; /**< Max bit-rate allowed in VBR mode (total) */
79
spx_int32_t vbr_max_high; /**< Max bit-rate allowed in VBR mode for the high-band */
80
spx_int32_t abr_enabled; /**< ABR setting (in bps), 0 if off */
84
int vad_enabled; /**< 1 for enabling VAD, 0 otherwise */
85
float relative_quality;
86
#endif /* #ifndef DISABLE_VBR */
89
const SpeexSubmode * const *submodes;
93
spx_int32_t sampling_rate;
98
/**Structure representing the full state of the sub-band decoder*/
99
typedef struct SBDecState {
100
const SpeexMode *mode; /**< Pointer to the mode (containing for vtable info) */
101
void *st_low; /**< State of the low-band (narrowband) encoder */
108
spx_int32_t sampling_rate;
112
spx_word16_t *g0_mem, *g1_mem;
114
spx_word16_t *excBuf;
116
spx_coef_t *interp_qlpc;
119
spx_word32_t *pi_gain;
120
spx_word16_t *exc_rms;
121
spx_word16_t *innov_save; /** If non-NULL, innovation is copied here */
123
spx_word16_t last_ener;
127
const SpeexSubmode * const *submodes;
132
/**Initializes encoder state*/
133
void *sb_encoder_init(const SpeexMode *m);
135
/**De-allocates encoder state resources*/
136
void sb_encoder_destroy(void *state);
138
/**Encodes one frame*/
139
int sb_encode(void *state, void *in, SpeexBits *bits);
142
/**Initializes decoder state*/
143
void *sb_decoder_init(const SpeexMode *m);
145
/**De-allocates decoder state resources*/
146
void sb_decoder_destroy(void *state);
148
/**Decodes one frame*/
149
int sb_decode(void *state, SpeexBits *bits, void *out);
151
int sb_encoder_ctl(void *state, int request, void *ptr);
153
int sb_decoder_ctl(void *state, int request, void *ptr);