forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lpcBHdec.m
46 lines (30 loc) · 830 Bytes
/
lpcBHdec.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function E = lpcBHdec(P,H);
% E = lpcBHdec(P,H) Decode LPC residual encoded as pitch periods
% P is a vector pitch periods from lpcresenc. Reconstruct a
% stylized excitation vector E with a hop size H.
% 2001-03-19 [email protected]
if nargin < 2
H = 128;
end
nhops = length(P);
npts = H*nhops;
E = zeros(1,npts);
phs = 0; % Current phase as proportion of a cyle (new pulse at 1.0)
for hop = 1:nhops
pd = P(hop);
base = H*(hop-1);
if (pd == 0)
E(base+[1:H]) = randn(1,H);
else
pt = 0;
% Steps to next pulse
remsteps = round((1-phs) * pd);
while (pt + remsteps) < H
pt = pt + remsteps;
E(base+1+pt) = sqrt(pd); % so rms is 1
remsteps = pd;
end
% Store residual phase
phs = (H - pt)/pd;
end
end