ex

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nb_celp.h Source File

nb_celp.h

Go to the documentation of this file.
00001 /* Copyright (C) 2002-2006 Jean-Marc Valin */
00002 /**
00003     @file nb_celp.h
00004     @brief Narrowband CELP encoder/decoder
00005 */
00006 /*
00007    Redistribution and use in source and binary forms, with or without
00008    modification, are permitted provided that the following conditions
00009    are met:
00010    
00011    - Redistributions of source code must retain the above copyright
00012    notice, this list of conditions and the following disclaimer.
00013    
00014    - Redistributions in binary form must reproduce the above copyright
00015    notice, this list of conditions and the following disclaimer in the
00016    documentation and/or other materials provided with the distribution.
00017    
00018    - Neither the name of the Xiph.org Foundation nor the names of its
00019    contributors may be used to endorse or promote products derived from
00020    this software without specific prior written permission.
00021    
00022    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
00026    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef NB_CELP_H
00037 #define NB_CELP_H
00038 
00039 #include "modes.h"
00040 #include <speex/speex_bits.h>
00041 #include <speex/speex_callbacks.h>
00042 #include "vbr.h"
00043 #include "filters.h"
00044 
00045 #ifdef VORBIS_PSYCHO
00046 #include "vorbis_psy.h"
00047 #endif
00048 
00049 /**Structure representing the full state of the narrowband encoder*/
00050 typedef struct EncState {
00051    const SpeexMode *mode;        /**< Mode corresponding to the state */
00052    int    first;                 /**< Is this the first frame? */
00053    int    frameSize;             /**< Size of frames */
00054    int    subframeSize;          /**< Size of sub-frames */
00055    int    nbSubframes;           /**< Number of sub-frames */
00056    int    windowSize;            /**< Analysis (LPC) window length */
00057    int    lpcSize;               /**< LPC order */
00058    int    min_pitch;             /**< Minimum pitch value allowed */
00059    int    max_pitch;             /**< Maximum pitch value allowed */
00060 
00061    spx_word32_t cumul_gain;      /**< Product of previously used pitch gains (Q10) */
00062    int    bounded_pitch;         /**< Next frame should not rely on previous frames for pitch */
00063    int    ol_pitch;              /**< Open-loop pitch */
00064    int    ol_voiced;             /**< Open-loop voiced/non-voiced decision */
00065    int   *pitch;
00066 
00067 #ifdef EPIC_48K
00068    int    lbr_48k;
00069 #endif
00070 
00071 #ifdef VORBIS_PSYCHO
00072    VorbisPsy *psy;
00073    float *psy_window;
00074    float *curve;
00075    float *old_curve;
00076 #endif
00077 
00078    spx_word16_t  gamma1;         /**< Perceptual filter: A(z/gamma1) */
00079    spx_word16_t  gamma2;         /**< Perceptual filter: A(z/gamma2) */
00080    float  lag_factor;            /**< Lag windowing Gaussian width */
00081    spx_word16_t  lpc_floor;      /**< Noise floor multiplier for A[0] in LPC analysis*/
00082    char  *stack;                 /**< Pseudo-stack allocation for temporary memory */
00083    spx_word16_t *winBuf;         /**< Input buffer (original signal) */
00084    spx_word16_t *excBuf;         /**< Excitation buffer */
00085    spx_word16_t *exc;            /**< Start of excitation frame */
00086    spx_word16_t *swBuf;          /**< Weighted signal buffer */
00087    spx_word16_t *sw;             /**< Start of weighted signal frame */
00088    const spx_word16_t *window;   /**< Temporary (Hanning) window */
00089    spx_word16_t *lagWindow;      /**< Window applied to auto-correlation */
00090    spx_lsp_t *old_lsp;           /**< LSPs for previous frame */
00091    spx_lsp_t *old_qlsp;          /**< Quantized LSPs for previous frame */
00092    spx_mem_t *mem_sp;            /**< Filter memory for signal synthesis */
00093    spx_mem_t *mem_sw;            /**< Filter memory for perceptually-weighted signal */
00094    spx_mem_t *mem_sw_whole;      /**< Filter memory for perceptually-weighted signal (whole frame)*/
00095    spx_mem_t *mem_exc;           /**< Filter memory for excitation (whole frame) */
00096    spx_mem_t *mem_exc2;          /**< Filter memory for excitation (whole frame) */
00097    spx_mem_t mem_hp[2];          /**< High-pass filter memory */
00098    spx_word32_t *pi_gain;        /**< Gain of LPC filter at theta=pi (fe/2) */
00099    spx_word16_t *innov_rms_save; /**< If non-NULL, innovation RMS is copied here */
00100          
00101    VBRState *vbr;                /**< State of the VBR data */
00102    float  vbr_quality;           /**< Quality setting for VBR encoding */
00103    float  relative_quality;      /**< Relative quality that will be needed by VBR */
00104    spx_int32_t vbr_enabled;      /**< 1 for enabling VBR, 0 otherwise */
00105    spx_int32_t vbr_max;          /**< Max bit-rate allowed in VBR mode */
00106    int    vad_enabled;           /**< 1 for enabling VAD, 0 otherwise */
00107    int    dtx_enabled;           /**< 1 for enabling DTX, 0 otherwise */
00108    int    dtx_count;             /**< Number of consecutive DTX frames */
00109    spx_int32_t abr_enabled;      /**< ABR setting (in bps), 0 if off */
00110    float  abr_drift;
00111    float  abr_drift2;
00112    float  abr_count;
00113    int    complexity;            /**< Complexity setting (0-10 from least complex to most complex) */
00114    spx_int32_t sampling_rate;
00115    int    plc_tuning;
00116    int    encode_submode;
00117    const SpeexSubmode * const *submodes; /**< Sub-mode data */
00118    int    submodeID;             /**< Activated sub-mode */
00119    int    submodeSelect;         /**< Mode chosen by the user (may differ from submodeID if VAD is on) */
00120    int    isWideband;            /**< Is this used as part of the embedded wideband codec */
00121    int    highpass_enabled;        /**< Is the input filter enabled */
00122 } EncState;
00123 
00124 /**Structure representing the full state of the narrowband decoder*/
00125 typedef struct DecState {
00126    const SpeexMode *mode;       /**< Mode corresponding to the state */
00127    int    first;                /**< Is this the first frame? */
00128    int    count_lost;           /**< Was the last frame lost? */
00129    int    frameSize;            /**< Size of frames */
00130    int    subframeSize;         /**< Size of sub-frames */
00131    int    nbSubframes;          /**< Number of sub-frames */
00132    int    lpcSize;              /**< LPC order */
00133    int    min_pitch;            /**< Minimum pitch value allowed */
00134    int    max_pitch;            /**< Maximum pitch value allowed */
00135    spx_int32_t sampling_rate;
00136 
00137 #ifdef EPIC_48K
00138    int    lbr_48k;
00139 #endif
00140 
00141    spx_word16_t  last_ol_gain;  /**< Open-loop gain for previous frame */
00142 
00143    char  *stack;                /**< Pseudo-stack allocation for temporary memory */
00144    spx_word16_t *excBuf;        /**< Excitation buffer */
00145    spx_word16_t *exc;           /**< Start of excitation frame */
00146    spx_lsp_t *old_qlsp;         /**< Quantized LSPs for previous frame */
00147    spx_coef_t *interp_qlpc;     /**< Interpolated quantized LPCs */
00148    spx_mem_t *mem_sp;           /**< Filter memory for synthesis signal */
00149    spx_mem_t mem_hp[2];         /**< High-pass filter memory */
00150    spx_word32_t *pi_gain;       /**< Gain of LPC filter at theta=pi (fe/2) */
00151    spx_word16_t *innov_save;    /** If non-NULL, innovation is copied here */
00152    
00153    spx_word16_t level;
00154    spx_word16_t max_level;
00155    spx_word16_t min_level;
00156    
00157    /* This is used in packet loss concealment */
00158    int    last_pitch;           /**< Pitch of last correctly decoded frame */
00159    spx_word16_t  last_pitch_gain; /**< Pitch gain of last correctly decoded frame */
00160    spx_word16_t  pitch_gain_buf[3]; /**< Pitch gain of last decoded frames */
00161    int    pitch_gain_buf_idx;   /**< Tail of the buffer */
00162    spx_int32_t seed;            /** Seed used for random number generation */
00163    
00164    int    encode_submode;
00165    const SpeexSubmode * const *submodes; /**< Sub-mode data */
00166    int    submodeID;            /**< Activated sub-mode */
00167    int    lpc_enh_enabled;      /**< 1 when LPC enhancer is on, 0 otherwise */
00168    SpeexCallback speex_callbacks[SPEEX_MAX_CALLBACKS];
00169 
00170    SpeexCallback user_callback;
00171 
00172    /*Vocoder data*/
00173    spx_word16_t  voc_m1;
00174    spx_word32_t  voc_m2;
00175    float  voc_mean;
00176    int    voc_offset;
00177 
00178    int    dtx_enabled;
00179    int    isWideband;            /**< Is this used as part of the embedded wideband codec */
00180    int    highpass_enabled;        /**< Is the input filter enabled */
00181 } DecState;
00182 
00183 /** Initializes encoder state*/
00184 void *nb_encoder_init(const SpeexMode *m);
00185 
00186 /** De-allocates encoder state resources*/
00187 void nb_encoder_destroy(void *state);
00188 
00189 /** Encodes one frame*/
00190 int nb_encode(void *state, void *in, SpeexBits *bits);
00191 
00192 
00193 /** Initializes decoder state*/
00194 void *nb_decoder_init(const SpeexMode *m);
00195 
00196 /** De-allocates decoder state resources*/
00197 void nb_decoder_destroy(void *state);
00198 
00199 /** Decodes one frame*/
00200 int nb_decode(void *state, SpeexBits *bits, void *out);
00201 
00202 /** ioctl-like function for controlling a narrowband encoder */
00203 int nb_encoder_ctl(void *state, int request, void *ptr);
00204 
00205 /** ioctl-like function for controlling a narrowband decoder */
00206 int nb_decoder_ctl(void *state, int request, void *ptr);
00207 
00208 
00209 #endif