michael@0: /*********************************************************************** michael@0: Copyright (c) 2006-2011, Skype Limited. All rights reserved. michael@0: Redistribution and use in source and binary forms, with or without michael@0: modification, are permitted provided that the following conditions michael@0: are met: michael@0: - Redistributions of source code must retain the above copyright notice, michael@0: this list of conditions and the following disclaimer. michael@0: - Redistributions in binary form must reproduce the above copyright michael@0: notice, this list of conditions and the following disclaimer in the michael@0: documentation and/or other materials provided with the distribution. michael@0: - Neither the name of Internet Society, IETF or IETF Trust, nor the michael@0: names of specific contributors, may be used to endorse or promote michael@0: products derived from this software without specific prior written michael@0: permission. michael@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" michael@0: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE michael@0: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE michael@0: LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR michael@0: CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF michael@0: SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS michael@0: INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN michael@0: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE michael@0: POSSIBILITY OF SUCH DAMAGE. michael@0: ***********************************************************************/ michael@0: michael@0: #ifndef SILK_STRUCTS_H michael@0: #define SILK_STRUCTS_H michael@0: michael@0: #include "typedef.h" michael@0: #include "SigProc_FIX.h" michael@0: #include "define.h" michael@0: #include "entenc.h" michael@0: #include "entdec.h" michael@0: michael@0: #ifdef __cplusplus michael@0: extern "C" michael@0: { michael@0: #endif michael@0: michael@0: /************************************/ michael@0: /* Noise shaping quantization state */ michael@0: /************************************/ michael@0: typedef struct { michael@0: opus_int16 xq[ 2 * MAX_FRAME_LENGTH ]; /* Buffer for quantized output signal */ michael@0: opus_int32 sLTP_shp_Q14[ 2 * MAX_FRAME_LENGTH ]; michael@0: opus_int32 sLPC_Q14[ MAX_SUB_FRAME_LENGTH + NSQ_LPC_BUF_LENGTH ]; michael@0: opus_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ]; michael@0: opus_int32 sLF_AR_shp_Q14; michael@0: opus_int lagPrev; michael@0: opus_int sLTP_buf_idx; michael@0: opus_int sLTP_shp_buf_idx; michael@0: opus_int32 rand_seed; michael@0: opus_int32 prev_gain_Q16; michael@0: opus_int rewhite_flag; michael@0: } silk_nsq_state; michael@0: michael@0: /********************************/ michael@0: /* VAD state */ michael@0: /********************************/ michael@0: typedef struct { michael@0: opus_int32 AnaState[ 2 ]; /* Analysis filterbank state: 0-8 kHz */ michael@0: opus_int32 AnaState1[ 2 ]; /* Analysis filterbank state: 0-4 kHz */ michael@0: opus_int32 AnaState2[ 2 ]; /* Analysis filterbank state: 0-2 kHz */ michael@0: opus_int32 XnrgSubfr[ VAD_N_BANDS ]; /* Subframe energies */ michael@0: opus_int32 NrgRatioSmth_Q8[ VAD_N_BANDS ]; /* Smoothed energy level in each band */ michael@0: opus_int16 HPstate; /* State of differentiator in the lowest band */ michael@0: opus_int32 NL[ VAD_N_BANDS ]; /* Noise energy level in each band */ michael@0: opus_int32 inv_NL[ VAD_N_BANDS ]; /* Inverse noise energy level in each band */ michael@0: opus_int32 NoiseLevelBias[ VAD_N_BANDS ]; /* Noise level estimator bias/offset */ michael@0: opus_int32 counter; /* Frame counter used in the initial phase */ michael@0: } silk_VAD_state; michael@0: michael@0: /* Variable cut-off low-pass filter state */ michael@0: typedef struct { michael@0: opus_int32 In_LP_State[ 2 ]; /* Low pass filter state */ michael@0: opus_int32 transition_frame_no; /* Counter which is mapped to a cut-off frequency */ michael@0: opus_int mode; /* Operating mode, <0: switch down, >0: switch up; 0: do nothing */ michael@0: } silk_LP_state; michael@0: michael@0: /* Structure containing NLSF codebook */ michael@0: typedef struct { michael@0: const opus_int16 nVectors; michael@0: const opus_int16 order; michael@0: const opus_int16 quantStepSize_Q16; michael@0: const opus_int16 invQuantStepSize_Q6; michael@0: const opus_uint8 *CB1_NLSF_Q8; michael@0: const opus_uint8 *CB1_iCDF; michael@0: const opus_uint8 *pred_Q8; michael@0: const opus_uint8 *ec_sel; michael@0: const opus_uint8 *ec_iCDF; michael@0: const opus_uint8 *ec_Rates_Q5; michael@0: const opus_int16 *deltaMin_Q15; michael@0: } silk_NLSF_CB_struct; michael@0: michael@0: typedef struct { michael@0: opus_int16 pred_prev_Q13[ 2 ]; michael@0: opus_int16 sMid[ 2 ]; michael@0: opus_int16 sSide[ 2 ]; michael@0: opus_int32 mid_side_amp_Q0[ 4 ]; michael@0: opus_int16 smth_width_Q14; michael@0: opus_int16 width_prev_Q14; michael@0: opus_int16 silent_side_len; michael@0: opus_int8 predIx[ MAX_FRAMES_PER_PACKET ][ 2 ][ 3 ]; michael@0: opus_int8 mid_only_flags[ MAX_FRAMES_PER_PACKET ]; michael@0: } stereo_enc_state; michael@0: michael@0: typedef struct { michael@0: opus_int16 pred_prev_Q13[ 2 ]; michael@0: opus_int16 sMid[ 2 ]; michael@0: opus_int16 sSide[ 2 ]; michael@0: } stereo_dec_state; michael@0: michael@0: typedef struct { michael@0: opus_int8 GainsIndices[ MAX_NB_SUBFR ]; michael@0: opus_int8 LTPIndex[ MAX_NB_SUBFR ]; michael@0: opus_int8 NLSFIndices[ MAX_LPC_ORDER + 1 ]; michael@0: opus_int16 lagIndex; michael@0: opus_int8 contourIndex; michael@0: opus_int8 signalType; michael@0: opus_int8 quantOffsetType; michael@0: opus_int8 NLSFInterpCoef_Q2; michael@0: opus_int8 PERIndex; michael@0: opus_int8 LTP_scaleIndex; michael@0: opus_int8 Seed; michael@0: } SideInfoIndices; michael@0: michael@0: /********************************/ michael@0: /* Encoder state */ michael@0: /********************************/ michael@0: typedef struct { michael@0: opus_int32 In_HP_State[ 2 ]; /* High pass filter state */ michael@0: opus_int32 variable_HP_smth1_Q15; /* State of first smoother */ michael@0: opus_int32 variable_HP_smth2_Q15; /* State of second smoother */ michael@0: silk_LP_state sLP; /* Low pass filter state */ michael@0: silk_VAD_state sVAD; /* Voice activity detector state */ michael@0: silk_nsq_state sNSQ; /* Noise Shape Quantizer State */ michael@0: opus_int16 prev_NLSFq_Q15[ MAX_LPC_ORDER ]; /* Previously quantized NLSF vector */ michael@0: opus_int speech_activity_Q8; /* Speech activity */ michael@0: opus_int allow_bandwidth_switch; /* Flag indicating that switching of internal bandwidth is allowed */ michael@0: opus_int8 LBRRprevLastGainIndex; michael@0: opus_int8 prevSignalType; michael@0: opus_int prevLag; michael@0: opus_int pitch_LPC_win_length; michael@0: opus_int max_pitch_lag; /* Highest possible pitch lag (samples) */ michael@0: opus_int32 API_fs_Hz; /* API sampling frequency (Hz) */ michael@0: opus_int32 prev_API_fs_Hz; /* Previous API sampling frequency (Hz) */ michael@0: opus_int maxInternal_fs_Hz; /* Maximum internal sampling frequency (Hz) */ michael@0: opus_int minInternal_fs_Hz; /* Minimum internal sampling frequency (Hz) */ michael@0: opus_int desiredInternal_fs_Hz; /* Soft request for internal sampling frequency (Hz) */ michael@0: opus_int fs_kHz; /* Internal sampling frequency (kHz) */ michael@0: opus_int nb_subfr; /* Number of 5 ms subframes in a frame */ michael@0: opus_int frame_length; /* Frame length (samples) */ michael@0: opus_int subfr_length; /* Subframe length (samples) */ michael@0: opus_int ltp_mem_length; /* Length of LTP memory */ michael@0: opus_int la_pitch; /* Look-ahead for pitch analysis (samples) */ michael@0: opus_int la_shape; /* Look-ahead for noise shape analysis (samples) */ michael@0: opus_int shapeWinLength; /* Window length for noise shape analysis (samples) */ michael@0: opus_int32 TargetRate_bps; /* Target bitrate (bps) */ michael@0: opus_int PacketSize_ms; /* Number of milliseconds to put in each packet */ michael@0: opus_int PacketLoss_perc; /* Packet loss rate measured by farend */ michael@0: opus_int32 frameCounter; michael@0: opus_int Complexity; /* Complexity setting */ michael@0: opus_int nStatesDelayedDecision; /* Number of states in delayed decision quantization */ michael@0: opus_int useInterpolatedNLSFs; /* Flag for using NLSF interpolation */ michael@0: opus_int shapingLPCOrder; /* Filter order for noise shaping filters */ michael@0: opus_int predictLPCOrder; /* Filter order for prediction filters */ michael@0: opus_int pitchEstimationComplexity; /* Complexity level for pitch estimator */ michael@0: opus_int pitchEstimationLPCOrder; /* Whitening filter order for pitch estimator */ michael@0: opus_int32 pitchEstimationThreshold_Q16; /* Threshold for pitch estimator */ michael@0: opus_int LTPQuantLowComplexity; /* Flag for low complexity LTP quantization */ michael@0: opus_int mu_LTP_Q9; /* Rate-distortion tradeoff in LTP quantization */ michael@0: opus_int32 sum_log_gain_Q7; /* Cumulative max prediction gain */ michael@0: opus_int NLSF_MSVQ_Survivors; /* Number of survivors in NLSF MSVQ */ michael@0: opus_int first_frame_after_reset; /* Flag for deactivating NLSF interpolation, pitch prediction */ michael@0: opus_int controlled_since_last_payload; /* Flag for ensuring codec_control only runs once per packet */ michael@0: opus_int warping_Q16; /* Warping parameter for warped noise shaping */ michael@0: opus_int useCBR; /* Flag to enable constant bitrate */ michael@0: opus_int prefillFlag; /* Flag to indicate that only buffers are prefilled, no coding */ michael@0: const opus_uint8 *pitch_lag_low_bits_iCDF; /* Pointer to iCDF table for low bits of pitch lag index */ michael@0: const opus_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */ michael@0: const silk_NLSF_CB_struct *psNLSF_CB; /* Pointer to NLSF codebook */ michael@0: opus_int input_quality_bands_Q15[ VAD_N_BANDS ]; michael@0: opus_int input_tilt_Q15; michael@0: opus_int SNR_dB_Q7; /* Quality setting */ michael@0: michael@0: opus_int8 VAD_flags[ MAX_FRAMES_PER_PACKET ]; michael@0: opus_int8 LBRR_flag; michael@0: opus_int LBRR_flags[ MAX_FRAMES_PER_PACKET ]; michael@0: michael@0: SideInfoIndices indices; michael@0: opus_int8 pulses[ MAX_FRAME_LENGTH ]; michael@0: michael@0: int arch; michael@0: michael@0: /* Input/output buffering */ michael@0: opus_int16 inputBuf[ MAX_FRAME_LENGTH + 2 ]; /* Buffer containing input signal */ michael@0: opus_int inputBufIx; michael@0: opus_int nFramesPerPacket; michael@0: opus_int nFramesEncoded; /* Number of frames analyzed in current packet */ michael@0: michael@0: opus_int nChannelsAPI; michael@0: opus_int nChannelsInternal; michael@0: opus_int channelNb; michael@0: michael@0: /* Parameters For LTP scaling Control */ michael@0: opus_int frames_since_onset; michael@0: michael@0: /* Specifically for entropy coding */ michael@0: opus_int ec_prevSignalType; michael@0: opus_int16 ec_prevLagIndex; michael@0: michael@0: silk_resampler_state_struct resampler_state; michael@0: michael@0: /* DTX */ michael@0: opus_int useDTX; /* Flag to enable DTX */ michael@0: opus_int inDTX; /* Flag to signal DTX period */ michael@0: opus_int noSpeechCounter; /* Counts concecutive nonactive frames, used by DTX */ michael@0: michael@0: /* Inband Low Bitrate Redundancy (LBRR) data */ michael@0: opus_int useInBandFEC; /* Saves the API setting for query */ michael@0: opus_int LBRR_enabled; /* Depends on useInBandFRC, bitrate and packet loss rate */ michael@0: opus_int LBRR_GainIncreases; /* Gains increment for coding LBRR frames */ michael@0: SideInfoIndices indices_LBRR[ MAX_FRAMES_PER_PACKET ]; michael@0: opus_int8 pulses_LBRR[ MAX_FRAMES_PER_PACKET ][ MAX_FRAME_LENGTH ]; michael@0: } silk_encoder_state; michael@0: michael@0: michael@0: /* Struct for Packet Loss Concealment */ michael@0: typedef struct { michael@0: opus_int32 pitchL_Q8; /* Pitch lag to use for voiced concealment */ michael@0: opus_int16 LTPCoef_Q14[ LTP_ORDER ]; /* LTP coeficients to use for voiced concealment */ michael@0: opus_int16 prevLPC_Q12[ MAX_LPC_ORDER ]; michael@0: opus_int last_frame_lost; /* Was previous frame lost */ michael@0: opus_int32 rand_seed; /* Seed for unvoiced signal generation */ michael@0: opus_int16 randScale_Q14; /* Scaling of unvoiced random signal */ michael@0: opus_int32 conc_energy; michael@0: opus_int conc_energy_shift; michael@0: opus_int16 prevLTP_scale_Q14; michael@0: opus_int32 prevGain_Q16[ 2 ]; michael@0: opus_int fs_kHz; michael@0: opus_int nb_subfr; michael@0: opus_int subfr_length; michael@0: } silk_PLC_struct; michael@0: michael@0: /* Struct for CNG */ michael@0: typedef struct { michael@0: opus_int32 CNG_exc_buf_Q14[ MAX_FRAME_LENGTH ]; michael@0: opus_int16 CNG_smth_NLSF_Q15[ MAX_LPC_ORDER ]; michael@0: opus_int32 CNG_synth_state[ MAX_LPC_ORDER ]; michael@0: opus_int32 CNG_smth_Gain_Q16; michael@0: opus_int32 rand_seed; michael@0: opus_int fs_kHz; michael@0: } silk_CNG_struct; michael@0: michael@0: /********************************/ michael@0: /* Decoder state */ michael@0: /********************************/ michael@0: typedef struct { michael@0: opus_int32 prev_gain_Q16; michael@0: opus_int32 exc_Q14[ MAX_FRAME_LENGTH ]; michael@0: opus_int32 sLPC_Q14_buf[ MAX_LPC_ORDER ]; michael@0: opus_int16 outBuf[ MAX_FRAME_LENGTH + 2 * MAX_SUB_FRAME_LENGTH ]; /* Buffer for output signal */ michael@0: opus_int lagPrev; /* Previous Lag */ michael@0: opus_int8 LastGainIndex; /* Previous gain index */ michael@0: opus_int fs_kHz; /* Sampling frequency in kHz */ michael@0: opus_int32 fs_API_hz; /* API sample frequency (Hz) */ michael@0: opus_int nb_subfr; /* Number of 5 ms subframes in a frame */ michael@0: opus_int frame_length; /* Frame length (samples) */ michael@0: opus_int subfr_length; /* Subframe length (samples) */ michael@0: opus_int ltp_mem_length; /* Length of LTP memory */ michael@0: opus_int LPC_order; /* LPC order */ michael@0: opus_int16 prevNLSF_Q15[ MAX_LPC_ORDER ]; /* Used to interpolate LSFs */ michael@0: opus_int first_frame_after_reset; /* Flag for deactivating NLSF interpolation */ michael@0: const opus_uint8 *pitch_lag_low_bits_iCDF; /* Pointer to iCDF table for low bits of pitch lag index */ michael@0: const opus_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */ michael@0: michael@0: /* For buffering payload in case of more frames per packet */ michael@0: opus_int nFramesDecoded; michael@0: opus_int nFramesPerPacket; michael@0: michael@0: /* Specifically for entropy coding */ michael@0: opus_int ec_prevSignalType; michael@0: opus_int16 ec_prevLagIndex; michael@0: michael@0: opus_int VAD_flags[ MAX_FRAMES_PER_PACKET ]; michael@0: opus_int LBRR_flag; michael@0: opus_int LBRR_flags[ MAX_FRAMES_PER_PACKET ]; michael@0: michael@0: silk_resampler_state_struct resampler_state; michael@0: michael@0: const silk_NLSF_CB_struct *psNLSF_CB; /* Pointer to NLSF codebook */ michael@0: michael@0: /* Quantization indices */ michael@0: SideInfoIndices indices; michael@0: michael@0: /* CNG state */ michael@0: silk_CNG_struct sCNG; michael@0: michael@0: /* Stuff used for PLC */ michael@0: opus_int lossCnt; michael@0: opus_int prevSignalType; michael@0: michael@0: silk_PLC_struct sPLC; michael@0: michael@0: } silk_decoder_state; michael@0: michael@0: /************************/ michael@0: /* Decoder control */ michael@0: /************************/ michael@0: typedef struct { michael@0: /* Prediction and coding parameters */ michael@0: opus_int pitchL[ MAX_NB_SUBFR ]; michael@0: opus_int32 Gains_Q16[ MAX_NB_SUBFR ]; michael@0: /* Holds interpolated and final coefficients, 4-byte aligned */ michael@0: silk_DWORD_ALIGN opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ]; michael@0: opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ]; michael@0: opus_int LTP_scale_Q14; michael@0: } silk_decoder_control; michael@0: michael@0: michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: michael@0: #endif