Logo Search packages:      
Sourcecode: iaxclient version File versions  Download package

nb_celp.h

Go to the documentation of this file.
/* Copyright (C) 2002 Jean-Marc Valin */
/**
    @file nb_celp.h
    @brief Narrowband CELP encoder/decoder
*/
/*
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:
   
   - Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
   
   - Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
   
   - Neither the name of the Xiph.org Foundation nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.
   
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#ifndef NB_CELP_H
#define NB_CELP_H

#include "modes.h"
#include <speex/speex_bits.h>
#include <speex/speex_callbacks.h>
#include "vbr.h"
#include "filters.h"

/**Structure representing the full state of the narrowband encoder*/
00046 typedef struct EncState {
00047    const SpeexMode *mode;       /**< Mode corresponding to the state */
00048    int    first;          /**< Is this the first frame? */
00049    int    frameSize;      /**< Size of frames */
00050    int    subframeSize;   /**< Size of sub-frames */
00051    int    nbSubframes;    /**< Number of sub-frames */
00052    int    windowSize;     /**< Analysis (LPC) window length */
00053    int    lpcSize;        /**< LPC order */
00054    int    min_pitch;      /**< Minimum pitch value allowed */
00055    int    max_pitch;      /**< Maximum pitch value allowed */

00057    int    safe_pitch;     /**< Don't use too large values for pitch (in case we lose a packet) */
00058    int    bounded_pitch;  /**< Next frame should not rely on previous frames for pitch */
00059    int    ol_pitch;       /**< Open-loop pitch */
00060    int    ol_voiced;      /**< Open-loop voiced/non-voiced decision */
   int   *pitch;

#ifdef EPIC_48K
   int    lbr_48k;
#endif

00067    spx_word16_t  gamma1;         /**< Perceptual filter: A(z/gamma1) */
00068    spx_word16_t  gamma2;         /**< Perceptual filter: A(z/gamma2) */
00069    float  lag_factor;     /**< Lag windowing Gaussian width */
00070    float  lpc_floor;      /**< Noise floor multiplier for A[0] in LPC analysis*/
00071    char  *stack;          /**< Pseudo-stack allocation for temporary memory */
00072    spx_sig_t *inBuf;          /**< Input buffer (original signal) */
00073    spx_sig_t *frame;          /**< Start of original frame */
00074    spx_sig_t *excBuf;         /**< Excitation buffer */
00075    spx_sig_t *exc;            /**< Start of excitation frame */
00076    spx_sig_t *swBuf;          /**< Weighted signal buffer */
00077    spx_sig_t *sw;             /**< Start of weighted signal frame */
00078    spx_sig_t *innov;          /**< Innovation for the frame */
00079    spx_word16_t *window;         /**< Temporary (Hanning) window */
00080    spx_word16_t *autocorr;       /**< auto-correlation */
00081    spx_word16_t *lagWindow;      /**< Window applied to auto-correlation */
00082    spx_coef_t *lpc;            /**< LPCs for current frame */
00083    spx_lsp_t *lsp;            /**< LSPs for current frame */
00084    spx_lsp_t *qlsp;           /**< Quantized LSPs for current frame */
00085    spx_lsp_t *old_lsp;        /**< LSPs for previous frame */
00086    spx_lsp_t *old_qlsp;       /**< Quantized LSPs for previous frame */
00087    spx_lsp_t *interp_lsp;     /**< Interpolated LSPs */
00088    spx_lsp_t *interp_qlsp;    /**< Interpolated quantized LSPs */
00089    spx_coef_t *interp_lpc;     /**< Interpolated LPCs */
00090    spx_coef_t *interp_qlpc;    /**< Interpolated quantized LPCs */
00091    spx_coef_t *bw_lpc1;        /**< LPCs after bandwidth expansion by gamma1 for perceptual weighting*/
00092    spx_coef_t *bw_lpc2;        /**< LPCs after bandwidth expansion by gamma2 for perceptual weighting*/
00093    spx_mem_t *mem_sp;         /**< Filter memory for signal synthesis */
00094    spx_mem_t *mem_sw;         /**< Filter memory for perceptually-weighted signal */
00095    spx_mem_t *mem_sw_whole;   /**< Filter memory for perceptually-weighted signal (whole frame)*/
00096    spx_mem_t *mem_exc;        /**< Filter memory for excitation (whole frame) */
00097    spx_word32_t *pi_gain;        /**< Gain of LPC filter at theta=pi (fe/2) */

00099    VBRState *vbr;         /**< State of the VBR data */
00100    float  vbr_quality;    /**< Quality setting for VBR encoding */
00101    float  relative_quality; /**< Relative quality that will be needed by VBR */
00102    int    vbr_enabled;    /**< 1 for enabling VBR, 0 otherwise */
00103    int    vad_enabled;    /**< 1 for enabling VAD, 0 otherwise */
00104    int    dtx_enabled;    /**< 1 for enabling DTX, 0 otherwise */
00105    int    dtx_count;      /**< Number of consecutive DTX frames */
00106    int    abr_enabled;    /**< ABR setting (in bps), 0 if off */
   float  abr_drift;
   float  abr_drift2;
   float  abr_count;
00110    int    complexity;     /**< Complexity setting (0-10 from least complex to most complex) */
   int    sampling_rate;
   int    plc_tuning;
   int    encode_submode;
00114    const SpeexSubmode * const *submodes; /**< Sub-mode data */
00115    int    submodeID;      /**< Activated sub-mode */
00116    int    submodeSelect;  /**< Mode chosen by the user (may differ from submodeID if VAD is on) */
} EncState;

/**Structure representing the full state of the narrowband decoder*/
00120 typedef struct DecState {
00121    const SpeexMode *mode;       /**< Mode corresponding to the state */
00122    int    first;          /**< Is this the first frame? */
00123    int    count_lost;     /**< Was the last frame lost? */
00124    int    frameSize;      /**< Size of frames */
00125    int    subframeSize;   /**< Size of sub-frames */
00126    int    nbSubframes;    /**< Number of sub-frames */
00127    int    lpcSize;        /**< LPC order */
00128    int    min_pitch;      /**< Minimum pitch value allowed */
00129    int    max_pitch;      /**< Maximum pitch value allowed */
   int    sampling_rate;

#ifdef EPIC_48K
   int    lbr_48k;
#endif

00136    spx_word16_t  last_ol_gain;   /**< Open-loop gain for previous frame */

00138    char  *stack;          /**< Pseudo-stack allocation for temporary memory */
00139    spx_sig_t *inBuf;          /**< Input buffer (original signal) */
00140    spx_sig_t *frame;          /**< Start of original frame */
00141    spx_sig_t *excBuf;         /**< Excitation buffer */
00142    spx_sig_t *exc;            /**< Start of excitation frame */
00143    spx_sig_t *innov;          /**< Innovation for the frame */
00144    spx_lsp_t *qlsp;           /**< Quantized LSPs for current frame */
00145    spx_lsp_t *old_qlsp;       /**< Quantized LSPs for previous frame */
00146    spx_lsp_t *interp_qlsp;    /**< Interpolated quantized LSPs */
00147    spx_coef_t *interp_qlpc;    /**< Interpolated quantized LPCs */
00148    spx_mem_t *mem_sp;         /**< Filter memory for synthesis signal */
00149    spx_word32_t *pi_gain;        /**< Gain of LPC filter at theta=pi (fe/2) */
00150    int    last_pitch;     /**< Pitch of last correctly decoded frame */
00151    spx_word16_t  last_pitch_gain; /**< Pitch gain of last correctly decoded frame */
00152    spx_word16_t  pitch_gain_buf[3];  /**< Pitch gain of last decoded frames */
00153    int    pitch_gain_buf_idx; /**< Tail of the buffer */

   int    encode_submode;
00156    const SpeexSubmode * const *submodes; /**< Sub-mode data */
00157    int    submodeID;      /**< Activated sub-mode */
00158    int    lpc_enh_enabled; /**< 1 when LPC enhancer is on, 0 otherwise */
   CombFilterMem *comb_mem;
   SpeexCallback speex_callbacks[SPEEX_MAX_CALLBACKS];

   SpeexCallback user_callback;

   /*Vocoder data*/
   float  voc_m1;
   float  voc_m2;
   float  voc_mean;
   int    voc_offset;

   int    dtx_enabled;
} DecState;

/** Initializes encoder state*/
void *nb_encoder_init(const SpeexMode *m);

/** De-allocates encoder state resources*/
void nb_encoder_destroy(void *state);

/** Encodes one frame*/
int nb_encode(void *state, void *in, SpeexBits *bits);


/** Initializes decoder state*/
void *nb_decoder_init(const SpeexMode *m);

/** De-allocates decoder state resources*/
void nb_decoder_destroy(void *state);

/** Decodes one frame*/
int nb_decode(void *state, SpeexBits *bits, void *out);

/** ioctl-like function for controlling a narrowband encoder */
int nb_encoder_ctl(void *state, int request, void *ptr);

/** ioctl-like function for controlling a narrowband decoder */
int nb_decoder_ctl(void *state, int request, void *ptr);


#endif

Generated by  Doxygen 1.6.0   Back to index