⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.m

📁 实现fs1016w的CELP的低速率语音编解码功能的基于vc开发环境的原代码。
💻 M
📖 第 1 页 / 共 2 页
字号:
% MATLAB SIMULATION OF NSA FS-1016 CELP v3.2
% COPYRIGHT (C) 1995-99 ANDREAS SPANIAS AND TED PAINTER
%
% This Copyright applies only to this particular MATLAB implementation
% of the FS-1016 CELP coder.  The MATLAB software is intended only for educational
% purposes.  No other use is intended or authorized.  This is not a public
% domain program and distribution to individuals or networks is strictly
% prohibited.  Be aware that use of the standard in any form is goverened
% by rules of the US DoD.  Therefore patents and royalties may apply to
% authors, companies, or committees associated with this standard, FS-1016.  For
% questions regarding the MATLAB implementation please contact Andreas
% Spanias at (480) 965-1837.  For questions on rules,
% royalties, or patents associated with the standard, please contact the DoD.
%
% ALL DERIVATIVE WORKS MUST INCLUDE THIS COPYRIGHT NOTICE.
%
% ******************************************************************
% INIT
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 6-7-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Initializes all global and static data objects
%
% DESIGN NOTES
%
% MATLAB globals are used wherever static behavior is required within
% a function (static local variables).
%
% INTERNAL VARIABLES
%
% These "internal" variables are in scope for:
%
%   1. fs1016.m
%   2. celpexec.m
%   3. celpanal.m
%   4. celpsyn.m
%   5. init.m
%
%   SimType         -   Simulation type - analysis/synthesis or synthesis only
%   scale           -   Input speech scale factor
%   descale         -   Output speech scale factor
%   ll              -   Frame length, in samples
%   l               -   Subframe length, in samples
%   lp              -   Pitch analysis subframe length, in samples
%   nn              -   Number of subframes per frame
%   minv            -   Minimum allowed input/output speech sample value
%   maxv            -   Maximum allowed input/output speech sample value
%   sold            -   Input speech history buffer
%   sumdm           -   Output speech distortion measure accumulators
%   sumdm2          -   Spectral distortion measure accumulators
%   stream          -   CELP analysis output bitstream
%   v               -   Optimum excitation vector during analysis phase
%   ssub            -   Subframe analysis buffer (ll samples)
%   framedm2        -   Frame count for averaging spectral distortion measures
%   framedm         -   Subframe count for averaging speech distortion measures
%   sbits           -   Bit allocations, LSP quantization
%   pbits           -   Bit allocations, adaptive (pitch) codebook index and gain
%   pointer         -   CELP bitstream index
%   nseg            -   Cumulative subframe counter
%   cbindex         -   Stochastic codebook index
%   ncsize          -   Stochastic codebook size
%   gindex          -   Stochastic codebook gain index (into gain table)
%   cbgbits         -   Bit allocation, stochastic codebook gain
%   cbgtype         -   Quantization method, stochastic codebook gain
%   cbbits          -   Bit allocation, stochastic codebook index
%   sync            -   Sync bit, CELP analysis bitstream output
%   syndavg         -   Error tracking average
%
% GLOBAL VARIABLES BY FUNCTION
%
% CELP32.M
%   SimRunning      -   First or subsequent call flag
%   celppath        -   System path to celp simulation m-files
%
% CELPANAL.M
%   FrameCnt        -   Current frame number
%   SubFrameCnt     -   Current subframe number
%   no              -   LPC filter order
%   gamma2          -   Bandwidth expansion coefficient, codebook searches
%   bb              -   Adaptive codebook index and gain
%   hmatrix         -   Hamming matrix, used during hamming codeword generation
%   syndrometable   -   Hamming syndrome table  "        "                 "
%   hamw            -   Hamming window, one full frame in length
%   hamws           -   Hamming window, one full subframe in length
%   ahpf            -   H(Z) denominator, input speech highpass filter
%   bhpf            -   H(Z) numerator, input speech highpass filter
%   dhpf1           -   Filter memory, input highpass filter
%   bitprotect      -   Bitstream indicies of bits protected by the hamming code
%   codeword        -   Hamming (15,11) codeword, formed from protected bits
%   protect         -   Hamming bit protection enable/disable flag
%   paritybit       -   Extraneous paritybit used for codeword parity overall
%   bitperm         -   Bit stream permutation table
%   mask            -   Bit error mask, allows forced error immunity for specific bits
%   ber             -   Simulated bit error rate
%
% CELPSYN.M
%   vdecoded        -   Synthesis excitation vector and output speech vector
%   dps             -   Buffer used during pitch lag search
%   dss             -   LPC synthesis filter memory
%   npf             -   Non-postfiltered synthesis output
%   pf              -   Postfiltered synthesis output
%   hppf            -   Hihgpass filtered synthesis output
%   sumsnr          -   Non postfiltered speech snr averaging accumlator
%   framesnr        -   Non postfiltered speech snr frame counter
%   sumsnrp         -   Postfiltered speech snr averaging accumlator
%   framesnrp       -   Postfiltered speech snr frame counter
%   sumsnrh         -   Highpass filtered speech snr averaging accumlator
%   framesnrh       -   Hihgpass filtered speech snr frame counter
%   dhpf1o          -   FIR (all zero) highpass filter memory, output speech
%   dhpf2o          -   IIR (all pole) highpass filter memory, output speech
%   ahpfo           -   Highpass filter H(Z) numerator coefficients, output speech
%   bhpfo           -   Highpass filter H(Z) denominator coefficients, output speech
%   errors          -   Cumulative sum over all frames of number of bit errors
%   total           -   Total number of bits processed
%   plevel1         -   Number of full search pitch delays
%   plevel2         -   Number of delta search pitch delays
%   idb             -   Dimension of d1a and d1b
%   bitsum1         -   Bit allocation sum used during parameter decoding
%   bitsum2         -   Bit allocation sum used during parameter decoding
%   ip              -   Post filter estimate of input power
%   op              -   Post filter estimate of output power
%
% PCTOLSP2.M
%   lastfreq        -   Previous frame LSPs
%
% LSP34.M
%   lspQ            -   LSP quantization table
%
% INANALY.M
%   w               -   LSP subframe interpolation weights
%   lspold          -   Old frame portion of LSP superframe
%   oldlsp          -   Last subframe of previous frame LSPs
%
% CSUB.M
%   e0              -   Codebook search initial error and updated error
%   d1a             -   Memory 1/P(z)       (pitch)
%   d1b             -   Memory 1/P(z)       (pitch)
%   d2a             -   Memory 1/A(z)       (spectrum)
%   d2b             -   Memory 1/A(z)       (spectrum)
%   d3a             -   Memory A(z)         (spectrum)
%   d3b             -   Memory A(z)         (spectrum)
%   d4a             -   Memory 1/A(z/gamma) (spectrum)
%   d4b             -   Memory 1/A(z/gamma) (spectrum)
%   mxsw            -   Modified excitation control switch
%
% MEXCITE1.M MEXCITE2.M MEXCITE3.M
%   e1              -   Euclidean norm of the first error signal
%   e0save          -   Copy of first error signal
%   ccor            -   Crosscorrelation of the residual signals
%
% PSEARCH.M
%   idb             -   Dimension of d1a, d1b
%   no              -   Predictor order
%   nseg            -   Segment (subframe) counter, cumulative
%   pindex          -   Pitch gain index
%   tauptr          -   Pitch delay pointer
%   minptr          -   Minimum delay pointer
%   oldptr          -   Previous subframe pitch pointer for delta calcs
%   plevel1         -   Number of full search pitch delays
%   plevel2         -   Number of delta search pitch delays
%   pdelay          -   Adaptive codebook pitch delays
%   pstype          -   Pitch search type (hier, full, or intg)
%   submult         -   Pitch submultiple delay table
%   ptype           -   Pitch codebook index quantization type
%
% PGAIN.M
%   Ypg             -   Perceptual weighting filter output
%
% DELAY.M
%   dfrac           -   Quantized fractional delays (5)
%   twelfths        -   Fractional delays for hamming window
%   wsinc           -   Windowed sinc interpolation kernel
%   hwin            -   Hamming window for application to sinc interp. kernel
%   FirstDelay      -   First call flag
%   DelaySize       -   Length of interpolation interval, in samples (8)
%   DelayM1         -   Start of interpolation interval (-4)
%   DelayM2         -   End of interpolation interval (3)
%
% PENCODE.M
%   pitch2max5      -   LLoyd-Max pitch gain quantization table
%
% LDELAY.M
%   dfrac           -   Quantized fractional delays (5)
%   twelfths        -   Fractional delays for hamming window
%   lwsinc          -   Windowed sinc interpolation kernel
%   lhwin           -   Hamming window for application to sinc interp. kernel
%   FirstLdelay     -   First call flag
%   LdelaySize      -   Length of interpolation interval, in samples (8)
%   LdelayM1        -   Start of interpolation interval (-4)
%   LdelayM2        -   End of interpolation interval (3)
%
% CBSEARCH.M
%   StochCB         -   Ternary valued stochastic codebook
%
% CGAIN.M
%   Ycg             -   Output of perceptual weighting filter
%   y59save         -   2nd to last sample, Ycg
%   y60save         -   Last sample, Ycg
%   Engcg           -   Codeword energy
%
% GAINCODE.M
%   gainlog5        -   Stochastic codebook gain quantization table
%
% PACKTAU.M
%   pdencode        -   Pitch delay (tau) encoding table
%
% RANDOM.M
%   y               -   Internal accumulator
%   j               -   Internal index
%   k               -   Internal index
%
% INTSYNTH.M
%   wIS             -   LSP interpolation weights
%   lspoldIS        -   Previous frame LSPs
%
% DCODTAU.M
%   lptrDT          -   Tau delta decoding pointer
%   pddecode        -   Tau permutation table
%   pdtabi          -   Tau delay table index
%
% SMCBG.M
%   enableSMCBG     -   Smoothing enable/disable flag
%   oldcbgain       -   Vector of old stochastic codebook gains
%
% SMT.M
%   enableSMT       -   Smoothing enable/disable flag
%   oldtau          -   Vector of old pitch lags
%
% SMPG.M
%   enableSMPG      -     Smoothing enable/disable flag
%   oldpgain        -     Vector of old pitch gains
%
% POSTFILT.M
%   ipZ             -     Input power estimation filter memory
%   opZ             -     Output power estimation filter memory
%   dp1             -     Postfilter memory, output speech
%   dp2             -     Postfilter memory, output speech
%   dp3             -     Postfilter memory, output speech
%
% SETUP.M
%   infile          -   Filename and path, input speech
%   outfile         -   Filename and path, postfiltered speech
%   npffile         -   Filename and path, non postfiltered speech
%   hpffile         -   Filename and path, highpass filtered speech
%
% CONSTANTS
%   LFRAME          -   Analysis frame size
%   READ            -   Read flag to control diskio
%   WRITE           -   Write flag to control diskio
%   EOF             -   Status flag for diskio
%   TRUE            -   Logical state == 1
%   FALSE           -   Logical state == 0
%   MAXNO           -   Maximum LPC filter order
%   MAXLP           -   Maximum pitch prediction frame size
%   MAXNP           -   Maximum pitch prediction order
%   MMAX            -   Maximum delay pitch predictor
%   MAXL            -   Maximum codeword vector length (subframe analysis)
%   MAXM2           -   Maximum vector size for delay parameter
%   MAXPA           -   Maximum pitch analysis buffer length
%   MAXPD           -   Maximum number of pitch delays
%   MMIN            -   Minimum delay pitch predictor
%   NFRAC           -   Number of fractional delays
%   MAXNCSIZE       -   Maximum stochastic codebook size
%   MAXCODE         -   Maximum size of stochastic codebook, given shift and overlap
%   MAXTAP          -   Knuth random number generator internal limit
%   CBGAINHISTORY   -   History buffer size, stochastic codebook gain smoothing
%   CBGAINLIMIT     -   Threshold,             "             "              "
%   VARLIMIT        -   Variance limit,        "             "              "
%   SGAINLIMIT      -   Maximum gain,          "             "              "
%   SVARLIMIT       -   Maximum variance,      "             "              "
%   AVGLIMIT        -   Maximum average,       "             "              "
%   SYNDLIMIT       -   Error detection threshold,           "              "
%   TAUHISTORY      -   History buffer size, pitch delay smoothing
%   TAULIMIT        -   Pitch delay excursion limit, "         "
%   PGAINHISTORY    -   History buffer size, pitch codebook gain smoothing
%   PGAINLIMIT      -   Pitch delay codebook gain excursion limit, "    "
%   TC              -   Post filter time constant
%   CODELENGTH1     -   Hamming codeword overall length (in bits)
%   CODELENGTH2     -   Hamming codeword data length (in bits)
%   PARITYLENGTH    -   Hamming codeword error protection length (in bits)
%   OMEGA           -   Expansion coefficient for LPC filter pole bandwidth
%   STREAMBITS      -   Bits per frame of CELP analysis output
%   MIDTAP          -   Knuth random number generator internal pointer
%   SYNDRUN         -   Bit error rate averaging constant
%   ANALYSIS        -   Analysis-synthesis simulation control flag
%   SYNTHESIS       -   Synthesis only simulation control flag
%   ALPHA           -   Postfilter pole/zero bandwidth expansion parameter
%   BETA            -   Postfilter pole/zero bandwidth expansion parameter
%
% ******************************************************************

% DECLARE ALL GLOBAL CONSTANTS
global EOF READ WRITE LFRAME TRUE FALSE MAXNO MAXLP MAXNP MMAX
global MAXL MAXM2 MAXPA MAXPD MMIN NFRAC MAXNCSIZE MAXCODE MAXTAP
global ANALYSIS SYNTHESIS CBGAINHISTORY CBGAINLIMIT VARLIMIT
global SGAINLIMIT SVARLIMIT AVGLIMIT SYNDLIMIT TAUHISTORY TAULIMIT
global PGAINHISTORY PGAINLIMIT TC
global ted ts thalt
ted = 0;  ts=0; thalt = 0;

% DEFINE GLOBAL CONSTANTS
TRUE           = 1;
FALSE          = 0;
READ           = 0;
WRITE          = 1;
EOF            = -99;
LFRAME         = 240;
MAXNCSIZE      = 512;
MAXNO          = 10;
MAXLP          = 60;
MAXNP          = 3;
MMAX           = 147;
MAXL           = 60;
MAXM2          = 20;
MAXPD          = 256;
MMIN           = 20;
MAXPA          = MAXLP + MMAX + 2 + MAXM2;
NFRAC          = 5;
MAXCODE        = ( 2 * MAXNCSIZE ) + MAXL;
MAXTAP         = 5;
CBGAINHISTORY  = 4;
CBGAINLIMIT    = 300;
VARLIMIT       = 30000;
SGAINLIMIT     = 9.0;
SVARLIMIT      = 10.0;
AVGLIMIT       = 6.0;
SYNDLIMIT      = 0.04;
TAUHISTORY     = 4;
TAULIMIT       = 15;
PGAINHISTORY   = 4;
PGAINLIMIT     = 0.9;
TC             = 0.01;

% DEFINE LOCAL CONSTANTS
CODELENGTH1    = 15;
CODELENGTH2    = 11;
PARITYLENGTH   = CODELENGTH1 - CODELENGTH2;
OMEGA          = 0.994127;
STREAMBITS     = 144;
MIDTAP         = 2;
SYNDRUN        = 100;
ANALYSIS       = 1;
SYNTHESIS      = 2;
ALPHA          = 0.8;
BETA           = 0.5;

% GLOBAL VARIABLES ARE DECLARED ADJACENT TO THEIR DEFINITIONS

% SAVE THE CURRENT DIRECTORY FOR LATER RECALL
celppath = cd;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -