ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 47:9e361da97763 1 /* Copyright (C) 2002-2006 Jean-Marc Valin */
TMBOY 47:9e361da97763 2 /**
TMBOY 47:9e361da97763 3 @file sb_celp.h
TMBOY 47:9e361da97763 4 @brief Sub-band CELP mode used for wideband encoding
TMBOY 47:9e361da97763 5 */
TMBOY 47:9e361da97763 6 /*
TMBOY 47:9e361da97763 7 Redistribution and use in source and binary forms, with or without
TMBOY 47:9e361da97763 8 modification, are permitted provided that the following conditions
TMBOY 47:9e361da97763 9 are met:
TMBOY 47:9e361da97763 10
TMBOY 47:9e361da97763 11 - Redistributions of source code must retain the above copyright
TMBOY 47:9e361da97763 12 notice, this list of conditions and the following disclaimer.
TMBOY 47:9e361da97763 13
TMBOY 47:9e361da97763 14 - Redistributions in binary form must reproduce the above copyright
TMBOY 47:9e361da97763 15 notice, this list of conditions and the following disclaimer in the
TMBOY 47:9e361da97763 16 documentation and/or other materials provided with the distribution.
TMBOY 47:9e361da97763 17
TMBOY 47:9e361da97763 18 - Neither the name of the Xiph.org Foundation nor the names of its
TMBOY 47:9e361da97763 19 contributors may be used to endorse or promote products derived from
TMBOY 47:9e361da97763 20 this software without specific prior written permission.
TMBOY 47:9e361da97763 21
TMBOY 47:9e361da97763 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
TMBOY 47:9e361da97763 23 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
TMBOY 47:9e361da97763 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
TMBOY 47:9e361da97763 25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
TMBOY 47:9e361da97763 26 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
TMBOY 47:9e361da97763 27 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
TMBOY 47:9e361da97763 28 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
TMBOY 47:9e361da97763 29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
TMBOY 47:9e361da97763 30 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
TMBOY 47:9e361da97763 31 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
TMBOY 47:9e361da97763 32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TMBOY 47:9e361da97763 33
TMBOY 47:9e361da97763 34 */
TMBOY 47:9e361da97763 35
TMBOY 47:9e361da97763 36 #ifndef SB_CELP_H
TMBOY 47:9e361da97763 37 #define SB_CELP_H
TMBOY 47:9e361da97763 38
TMBOY 47:9e361da97763 39 #include "modes.h"
TMBOY 47:9e361da97763 40 #include <speex/speex_bits.h>
TMBOY 47:9e361da97763 41 #include "nb_celp.h"
TMBOY 47:9e361da97763 42
TMBOY 47:9e361da97763 43 /**Structure representing the full state of the sub-band encoder*/
TMBOY 47:9e361da97763 44 typedef struct SBEncState {
TMBOY 47:9e361da97763 45 const SpeexMode *mode; /**< Pointer to the mode (containing for vtable info) */
TMBOY 47:9e361da97763 46 void *st_low; /**< State of the low-band (narrowband) encoder */
TMBOY 47:9e361da97763 47 int full_frame_size; /**< Length of full-band frames*/
TMBOY 47:9e361da97763 48 int frame_size; /**< Length of high-band frames*/
TMBOY 47:9e361da97763 49 int subframeSize; /**< Length of high-band sub-frames*/
TMBOY 47:9e361da97763 50 int nbSubframes; /**< Number of high-band sub-frames*/
TMBOY 47:9e361da97763 51 int windowSize; /**< Length of high-band LPC window*/
TMBOY 47:9e361da97763 52 int lpcSize; /**< Order of high-band LPC analysis */
TMBOY 47:9e361da97763 53 int bufSize; /**< Buffer size */
TMBOY 47:9e361da97763 54 int first; /**< First frame? */
TMBOY 47:9e361da97763 55 float lag_factor; /**< Lag-windowing control parameter */
TMBOY 47:9e361da97763 56 spx_word16_t lpc_floor; /**< Controls LPC analysis noise floor */
TMBOY 47:9e361da97763 57 spx_word16_t gamma1; /**< Perceptual weighting coef 1 */
TMBOY 47:9e361da97763 58 spx_word16_t gamma2; /**< Perceptual weighting coef 2 */
TMBOY 47:9e361da97763 59
TMBOY 47:9e361da97763 60 char *stack; /**< Temporary allocation stack */
TMBOY 47:9e361da97763 61 spx_word16_t *high; /**< High-band signal (buffer) */
TMBOY 47:9e361da97763 62 spx_word16_t *h0_mem, *h1_mem;
TMBOY 47:9e361da97763 63
TMBOY 47:9e361da97763 64 const spx_word16_t *window; /**< LPC analysis window */
TMBOY 47:9e361da97763 65 spx_word16_t *lagWindow; /**< Auto-correlation window */
TMBOY 47:9e361da97763 66 spx_lsp_t *old_lsp; /**< LSPs of previous frame */
TMBOY 47:9e361da97763 67 spx_lsp_t *old_qlsp; /**< Quantized LSPs of previous frame */
TMBOY 47:9e361da97763 68 spx_coef_t *interp_qlpc; /**< Interpolated quantized LPCs for current sub-frame */
TMBOY 47:9e361da97763 69
TMBOY 47:9e361da97763 70 spx_mem_t *mem_sp; /**< Synthesis signal memory */
TMBOY 47:9e361da97763 71 spx_mem_t *mem_sp2;
TMBOY 47:9e361da97763 72 spx_mem_t *mem_sw; /**< Perceptual signal memory */
TMBOY 47:9e361da97763 73 spx_word32_t *pi_gain;
TMBOY 47:9e361da97763 74 spx_word16_t *exc_rms;
TMBOY 47:9e361da97763 75 spx_word16_t *innov_rms_save; /**< If non-NULL, innovation is copied here */
TMBOY 47:9e361da97763 76
TMBOY 47:9e361da97763 77 float vbr_quality; /**< Quality setting for VBR encoding */
TMBOY 47:9e361da97763 78 int vbr_enabled; /**< 1 for enabling VBR, 0 otherwise */
TMBOY 47:9e361da97763 79 spx_int32_t vbr_max; /**< Max bit-rate allowed in VBR mode (total) */
TMBOY 47:9e361da97763 80 spx_int32_t vbr_max_high; /**< Max bit-rate allowed in VBR mode for the high-band */
TMBOY 47:9e361da97763 81 spx_int32_t abr_enabled; /**< ABR setting (in bps), 0 if off */
TMBOY 47:9e361da97763 82 float abr_drift;
TMBOY 47:9e361da97763 83 float abr_drift2;
TMBOY 47:9e361da97763 84 float abr_count;
TMBOY 47:9e361da97763 85 int vad_enabled; /**< 1 for enabling VAD, 0 otherwise */
TMBOY 47:9e361da97763 86 float relative_quality;
TMBOY 47:9e361da97763 87
TMBOY 47:9e361da97763 88 int encode_submode;
TMBOY 47:9e361da97763 89 const SpeexSubmode * const *submodes;
TMBOY 47:9e361da97763 90 int submodeID;
TMBOY 47:9e361da97763 91 int submodeSelect;
TMBOY 47:9e361da97763 92 int complexity;
TMBOY 47:9e361da97763 93 spx_int32_t sampling_rate;
TMBOY 47:9e361da97763 94
TMBOY 47:9e361da97763 95 } SBEncState;
TMBOY 47:9e361da97763 96
TMBOY 47:9e361da97763 97
TMBOY 47:9e361da97763 98 /**Structure representing the full state of the sub-band decoder*/
TMBOY 47:9e361da97763 99 typedef struct SBDecState {
TMBOY 47:9e361da97763 100 const SpeexMode *mode; /**< Pointer to the mode (containing for vtable info) */
TMBOY 47:9e361da97763 101 void *st_low; /**< State of the low-band (narrowband) encoder */
TMBOY 47:9e361da97763 102 int full_frame_size;
TMBOY 47:9e361da97763 103 int frame_size;
TMBOY 47:9e361da97763 104 int subframeSize;
TMBOY 47:9e361da97763 105 int nbSubframes;
TMBOY 47:9e361da97763 106 int lpcSize;
TMBOY 47:9e361da97763 107 int first;
TMBOY 47:9e361da97763 108 spx_int32_t sampling_rate;
TMBOY 47:9e361da97763 109 int lpc_enh_enabled;
TMBOY 47:9e361da97763 110
TMBOY 47:9e361da97763 111 char *stack;
TMBOY 47:9e361da97763 112 spx_word32_t *g0_mem, *g1_mem;
TMBOY 47:9e361da97763 113
TMBOY 47:9e361da97763 114 spx_word16_t *excBuf;
TMBOY 47:9e361da97763 115 spx_lsp_t *old_qlsp;
TMBOY 47:9e361da97763 116 spx_coef_t *interp_qlpc;
TMBOY 47:9e361da97763 117
TMBOY 47:9e361da97763 118 spx_mem_t *mem_sp;
TMBOY 47:9e361da97763 119 spx_word32_t *pi_gain;
TMBOY 47:9e361da97763 120 spx_word16_t *exc_rms;
TMBOY 47:9e361da97763 121 spx_word16_t *innov_save; /** If non-NULL, innovation is copied here */
TMBOY 47:9e361da97763 122
TMBOY 47:9e361da97763 123 spx_word16_t last_ener;
TMBOY 47:9e361da97763 124 spx_int32_t seed;
TMBOY 47:9e361da97763 125
TMBOY 47:9e361da97763 126 int encode_submode;
TMBOY 47:9e361da97763 127 const SpeexSubmode * const *submodes;
TMBOY 47:9e361da97763 128 int submodeID;
TMBOY 47:9e361da97763 129 } SBDecState;
TMBOY 47:9e361da97763 130
TMBOY 47:9e361da97763 131
TMBOY 47:9e361da97763 132 /**Initializes encoder state*/
TMBOY 47:9e361da97763 133 void *sb_encoder_init(const SpeexMode *m);
TMBOY 47:9e361da97763 134
TMBOY 47:9e361da97763 135 /**De-allocates encoder state resources*/
TMBOY 47:9e361da97763 136 void sb_encoder_destroy(void *state);
TMBOY 47:9e361da97763 137
TMBOY 47:9e361da97763 138 /**Encodes one frame*/
TMBOY 47:9e361da97763 139 int sb_encode(void *state, void *in, SpeexBits *bits);
TMBOY 47:9e361da97763 140
TMBOY 47:9e361da97763 141
TMBOY 47:9e361da97763 142 /**Initializes decoder state*/
TMBOY 47:9e361da97763 143 void *sb_decoder_init(const SpeexMode *m);
TMBOY 47:9e361da97763 144
TMBOY 47:9e361da97763 145 /**De-allocates decoder state resources*/
TMBOY 47:9e361da97763 146 void sb_decoder_destroy(void *state);
TMBOY 47:9e361da97763 147
TMBOY 47:9e361da97763 148 /**Decodes one frame*/
TMBOY 47:9e361da97763 149 int sb_decode(void *state, SpeexBits *bits, void *out);
TMBOY 47:9e361da97763 150
TMBOY 47:9e361da97763 151 int sb_encoder_ctl(void *state, int request, void *ptr);
TMBOY 47:9e361da97763 152
TMBOY 47:9e361da97763 153 int sb_decoder_ctl(void *state, int request, void *ptr);
TMBOY 47:9e361da97763 154
TMBOY 47:9e361da97763 155 #endif