function d = lpcsynth476(c) %(a,g)
% d = lpcsynth(a,g)   Resynthesize from LPC representation
%    Each row of a is an LPC fit to a h-point (non-overlapping) 
%    frame of data.  g gives the overall gains for each frame and 
%  Return d as the resulting LPC resynthesis.

% 2001-02-25 dpwe@ee.columbia.edu 
%$Header: /homes/dpwe/matlab/columbiafns/RCS/lpcsynth.m,v 1.1 2004/03/30 20:56:04 dpwe Exp $
%Modified by BRL4@cornell.edu; Dec2004

%    e is an excitation signal (if e is empty, white noise is used; 
%    if e is a scalar, a pulse train is used with that period).
% e = 50; %use noise or a period of about 75;
% mix = 0;
h = 128;
[nhops,p] = size(c);
npts = nhops*h;
d = zeros(1,p);

hop=1;
dlast=zeros(1,8);
%for each output point
for i=p:npts-1
    
    %check for new section
    if mod(i,h)==0
        hop = hop + 1;
    end
    
    %set input and gain
    %dtemp = (round(g(hop)*256)/256) * (mod(i,40)/16 + rand);%(round(g(hop)*2^16)/2^16)
    dtemp = (c(hop,1)/256) * (mod(i,40)/16 + rand);
    %sum over filter taps
    for j=2:p
        dtemp = dtemp - (c(hop,j)/256) * dlast(j-1);
    end
    %update the list of last 8 samples
    dlast = [dtemp, dlast(1:7)];
    
    %copy to array (in atmel this is not done, just play it)
    %and De-emphasis filter (must match pre-emphasis in lpcfit)
    d(i) =  dtemp + 0.9*dlast(2);
end

