| 1 |
/* Copyright (C) 2002-2006 Jean-Marc Valin */ |
| 2 |
/** |
| 3 |
@file sb_celp.h |
| 4 |
@brief Sub-band CELP mode used for wideband encoding |
| 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 SB_CELP_H |
| 37 |
#define SB_CELP_H |
| 38 |
|
| 39 |
#include "modes.h" |
| 40 |
#include "nb_celp.h" |
| 41 |
|
| 42 |
/**Structure representing the full state of the sub-band encoder*/ |
| 43 |
typedef struct SBEncState { |
| 44 |
const SpeexMode *mode; /**< Pointer to the mode (containing for vtable info) */ |
| 45 |
void *st_low; /**< State of the low-band (narrowband) encoder */ |
| 46 |
int full_frame_size; /**< Length of full-band frames*/ |
| 47 |
int frame_size; /**< Length of high-band frames*/ |
| 48 |
int subframeSize; /**< Length of high-band sub-frames*/ |
| 49 |
int nbSubframes; /**< Number of high-band sub-frames*/ |
| 50 |
int windowSize; /**< Length of high-band LPC window*/ |
| 51 |
int lpcSize; /**< Order of high-band LPC analysis */ |
| 52 |
int first; /**< First frame? */ |
| 53 |
spx_word16_t lpc_floor; /**< Controls LPC analysis noise floor */ |
| 54 |
spx_word16_t gamma1; /**< Perceptual weighting coef 1 */ |
| 55 |
spx_word16_t gamma2; /**< Perceptual weighting coef 2 */ |
| 56 |
|
| 57 |
char *stack; /**< Temporary allocation stack */ |
| 58 |
spx_word16_t *high; /**< High-band signal (buffer) */ |
| 59 |
spx_word16_t *h0_mem; |
| 60 |
|
| 61 |
const spx_word16_t *window; /**< LPC analysis window */ |
| 62 |
const spx_word16_t *lagWindow; /**< Auto-correlation window */ |
| 63 |
spx_lsp_t *old_lsp; /**< LSPs of previous frame */ |
| 64 |
spx_lsp_t *old_qlsp; /**< Quantized LSPs of previous frame */ |
| 65 |
spx_coef_t *interp_qlpc; /**< Interpolated quantized LPCs for current sub-frame */ |
| 66 |
|
| 67 |
spx_mem_t *mem_sp; /**< Synthesis signal memory */ |
| 68 |
spx_mem_t *mem_sp2; |
| 69 |
spx_mem_t *mem_sw; /**< Perceptual signal memory */ |
| 70 |
spx_word32_t *pi_gain; |
| 71 |
spx_word16_t *exc_rms; |
| 72 |
spx_word16_t *innov_rms_save; /**< If non-NULL, innovation is copied here */ |
| 73 |
|
| 74 |
#ifndef DISABLE_VBR |
| 75 |
float vbr_quality; /**< Quality setting for VBR encoding */ |
| 76 |
int vbr_enabled; /**< 1 for enabling VBR, 0 otherwise */ |
| 77 |
spx_int32_t vbr_max; /**< Max bit-rate allowed in VBR mode (total) */ |
| 78 |
spx_int32_t vbr_max_high; /**< Max bit-rate allowed in VBR mode for the high-band */ |
| 79 |
spx_int32_t abr_enabled; /**< ABR setting (in bps), 0 if off */ |
| 80 |
float abr_drift; |
| 81 |
float abr_drift2; |
| 82 |
float abr_count; |
| 83 |
int vad_enabled; /**< 1 for enabling VAD, 0 otherwise */ |
| 84 |
float relative_quality; |
| 85 |
#endif /* #ifndef DISABLE_VBR */ |
| 86 |
|
| 87 |
int encode_submode; |
| 88 |
const SpeexSubmode * const *submodes; |
| 89 |
int submodeID; |
| 90 |
int submodeSelect; |
| 91 |
int complexity; |
| 92 |
spx_int32_t sampling_rate; |
| 93 |
|
| 94 |
} SBEncState; |
| 95 |
|
| 96 |
|
| 97 |
/**Structure representing the full state of the sub-band decoder*/ |
| 98 |
typedef struct SBDecState { |
| 99 |
const SpeexMode *mode; /**< Pointer to the mode (containing for vtable info) */ |
| 100 |
void *st_low; /**< State of the low-band (narrowband) encoder */ |
| 101 |
int full_frame_size; |
| 102 |
int frame_size; |
| 103 |
int subframeSize; |
| 104 |
int nbSubframes; |
| 105 |
int lpcSize; |
| 106 |
int first; |
| 107 |
spx_int32_t sampling_rate; |
| 108 |
int lpc_enh_enabled; |
| 109 |
|
| 110 |
char *stack; |
| 111 |
spx_word16_t *g0_mem, *g1_mem; |
| 112 |
|
| 113 |
spx_word16_t *excBuf; |
| 114 |
spx_lsp_t *old_qlsp; |
| 115 |
spx_coef_t *interp_qlpc; |
| 116 |
|
| 117 |
spx_mem_t *mem_sp; |
| 118 |
spx_word32_t *pi_gain; |
| 119 |
spx_word16_t *exc_rms; |
| 120 |
spx_word16_t *innov_save; /** If non-NULL, innovation is copied here */ |
| 121 |
|
| 122 |
spx_word16_t last_ener; |
| 123 |
spx_uint32_t seed; |
| 124 |
|
| 125 |
int encode_submode; |
| 126 |
const SpeexSubmode * const *submodes; |
| 127 |
int submodeID; |
| 128 |
} SBDecState; |
| 129 |
|
| 130 |
|
| 131 |
/**Initializes encoder state*/ |
| 132 |
void *sb_encoder_init(const SpeexMode *m); |
| 133 |
|
| 134 |
/**De-allocates encoder state resources*/ |
| 135 |
void sb_encoder_destroy(void *state); |
| 136 |
|
| 137 |
/**Encodes one frame*/ |
| 138 |
int sb_encode(void *state, void *in, SpeexBits *bits); |
| 139 |
|
| 140 |
|
| 141 |
/**Initializes decoder state*/ |
| 142 |
void *sb_decoder_init(const SpeexMode *m); |
| 143 |
|
| 144 |
/**De-allocates decoder state resources*/ |
| 145 |
void sb_decoder_destroy(void *state); |
| 146 |
|
| 147 |
/**Decodes one frame*/ |
| 148 |
int sb_decode(void *state, SpeexBits *bits, void *out); |
| 149 |
|
| 150 |
int sb_encoder_ctl(void *state, int request, void *ptr); |
| 151 |
|
| 152 |
int sb_decoder_ctl(void *state, int request, void *ptr); |
| 153 |
|
| 154 |
#endif |