📄 pitchvq.m
字号:
% 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 (602) 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.
%
% ******************************************************************
% PITCHVQ
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 7-8-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Pitch VQ (n-taps, where n = 0, ..., 3) "self-excited" or
% "vq" or "adaptive codebook"
%
% DESIGN NOTES
%
% Adaptive code book (pitch) synthesis routine:
%
% 1) For lags < frame size: gain-shape adaptive code book VQ
% 2) For lags => frame size this is equivalent to a pitch synthesis "filter"
%
% -[b(1)-1] -b(1) -[b(1)+1]
% H(z) = 1 / 1 + b(2) z + b(3) z + b(4) z
%
% NOTE: largest delay must not exceed the value IDIMB-IDIM
%
% REFERENCES
%
% 1. Singhal & Atal, Improving Performance of Multi-Pulse LPC Coders at
% Low Bit Rates, ICASSP, 1984.
%
% 2. Rose & Barnwell. The Self Excited Vocoder-An Alternate Approcch
% to Toll Quality at 4800 bps, ICASSP, 1986, pp. 453-456.
%
% 3. Kleijn, Krasinski and Ketchum, Improved Speech Quality and
% Efficient Vector Quantization in SELP, ICASSP, 1988.
%
% VARIABLES
%
% INPUTS
% rar - Input data segment
% buf - Data buffer
% idim - Dimension of rar
% idimb - Dimension of buf
% b - Pitch predictor coefficients, beta1, beta2, beta3
% For a one-tap predictor, beta1 = beta3 = 0.00
% b(1) = Pitch delay (m)
% b(2-4) = Pitch predictor coefficients
% type - Delay type used, long or short
%
% OUTPUTS
% rar - Output data segment
% buf - Data buffer
%
% INTERNALS
% imin - Lower index for filter memory update segment
% imax - Upper index for filter memory update segment
% frac - Fractional delay component
% k - Lower bound on filter update
% m - Integer delay component
% start - Lower bound on filter update
% buf2 - Delayed version of output signal
%
% CONSTANTS
% MAXLP - Maximum pitch prediction frame size
%
% ******************************************************************
function [ rar, buf ] = pitchvq( rar, idim, buf, idimb, b, type )
% DECLARE CONSTANTS
global MAXLP
% INIT LOCALS
k = idimb - idim;
start = k + 1;
m = fix( b(1) );
frac = b(1) - m;
buf2 = zeros( MAXLP, 1 );
% UPDATE FILTER MEMORY
buf( 1:k ) = buf( (1+idim):(k+idim) );
% UPDATE FILTER MEMORY WITH SELECTED PITCH MEMORY FROM DELAY M
% MUST USE TWO BLOCK MOVES TO ACCOUNT FOR OVERLAP DURING DELAYS (M)
% LESS THAN IDIM (60 SAMPLES), OTHERWISE BEGINNING SEGMENT
% DOESN'T GET REPEATED. SEE 'C' FOR LOOP FOR CLARIFICATION.
% IN ADDITION, MUST HANDLE TWO CASES FOR OVERLAP: CASE I, M<30
% MUST REPEAT STARTING PORTION MORE THAN ONCE.
% CASE II, M >= 30 REPEATS ONLY ONCE
if abs(frac) < 1.0e-4
if ( idimb-m ) >= k+1
if m < 30
buf( (k+1):(k+m) ) = buf( (k-m+1):k );
buf( (k+m+1):(k+m+m) ) = buf( (k+1):(k+m) );
buf( (k+m+m+1):idimb ) = buf( (k+m+1):(idimb-m) );
else
buf( (k+1):(k+m) ) = buf( (k-m+1):k );
buf( (k+m+1):idimb ) = buf( (k+1):(idimb-m) );
end
else
buf( (k+1):idimb ) = buf( (k+1-m):(idimb-m) );
end
end
% DO FRACTIONAL UPDATE IF FRACTIONAL PART ISN'T CLOSE ENOUGH TO 0
if abs(frac) > 1.0e-4
if strcmp( type, 'long' ) == 1
[ buf, buf2 ] = ldelay( buf, start, idim, frac, m );
else
[ buf, buf2 ] = delay( buf, start, idim, frac, m );
end
buf( (k+1):(k+idim) ) = buf2( 1:idim );
end
% RETURN RAR WITH SCALED MEMORY ADDED TO STOCHASTIC CONTRIBUTION
imin = k+1; imax = k+idim;
rar( 1:idim ) = rar( 1:idim ) + ( b(3) * buf( imin:imax ) );
buf( imin:imax ) = rar( 1:idim );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -