Home > @d_opvt > private > diva_synthX.m

diva_synthX

PURPOSE ^

DIVA_SYNTH2 Synthesizes the sound

SYNOPSIS ^

function [data] = diva_synthX(data)

DESCRIPTION ^

 DIVA_SYNTH2   Synthesizes the sound
   This core function relies on a mex file to provide the output signal
   Input:
   data: The structure data must have the following fields
       Af,Ag0,AgP,F0, duration, dx

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [data] = diva_synthX(data)
0002 % DIVA_SYNTH2   Synthesizes the sound
0003 %   This core function relies on a mex file to provide the output signal
0004 %   Input:
0005 %   data: The structure data must have the following fields
0006 %       Af,Ag0,AgP,F0, duration, dx
0007 
0008 % Satrajit Ghosh, SpeechLab, Boston University. (c)2001
0009 % $Header: /mnt/localhd/cvsdir/MODELLING/NEWDIVA/@d_opvt/private/diva_synthX.m,v 1.1.1.1 2006/10/06 18:20:23 brumberg Exp $
0010 
0011 % $NoKeywords: $
0012 
0013 % Setup globals
0014 global RELEASE
0015 
0016 TYPE='Tf';         % 'Tf' synthesis from transfer function; 'Af' synthesis from area function
0017 Fs=data.fs;
0018 sigm=inline('(1-exp(-x))./(1+exp(-x))');
0019 if ~isfield(data,TYPE) & isfield(data,'X'),
0020     Nt=size(data.X,2); %data.dx=zeros(1,Nt);
0021     data.Tf=zeros(125,Nt); for i=1:Nt,   
0022         [F,B,A,Af,Tf,P1] = doAM(data.X(:,i));
0023         if i==1, data.Af=zeros([size(Af,2),Nt]); opt.P1=zeros([size(P1),Nt]); end 
0024         % computes uniform-sampling transfer function (Tf has a non-uniform sampling)
0025         incr=[0;0;2*(abs(diff(Tf(2:end)))<1)-1]; df=40*ones(size(Tf)); for n1=2:length(Tf), df(n1)=max(.5,min(40,df(n1-1)+incr(n1-1)*8)); end; f=cumsum(df);
0026         data.Tf(ceil(f/40),i)=Tf;
0027         data.Af(:,i) = Af(1,:)';
0028         opt.P1(:,:,i)=P1;
0029         data.dx(:,i)=Af(2,:)';
0030         %plot(i*ones(size(F)),F,'k.'); hold on; drawnow;
0031         %subplot(221); plot(P1(1,:),P1(2,:),'b',P1(3,:),P1(4,:),'r'); axis equal; subplot(222); plot(Af');
0032         %subplot(223); plot(i*ones(size(F)),F,'.'); hold on; subplot(224); plot(Tf); hold on; drawnow;
0033         %disp(round(sum(df)))
0034         %if ~isempty(Tf), data.Tf(:,i)=Tf(ceil((1:256)/256*length(Tf))); end;
0035         %data.dx=data.dx+mean(Af(2,:));
0036     end;
0037     if 1,
0038         % re-interpolation of Area function
0039         Na=size(data.Af,1);
0040         Nfact=16;
0041         data.Af=shiftdim(max(0,min(reshape(real(exp(-j*2*pi*(-63:64)'/128*linspace(-.5,Na-.5,Na*Nfact))'*exp(j*2*pi*(0:Na-1)'*(-63:64)/128)'*data.Af/128),[Nfact,Na,Nt]),[],1)));
0042         data.dx(:)=data.dx.^4;                              % modification on lip protrusion
0043         %data.dx=1.0*data.dx/Nt;                         % modification on vocal tract size
0044         
0045         data.Af=max(0,min(64,1.0*(data.Af.^1.0)-.1));   % corrects global alpha-beta values
0046         idx0=find(data.Af<.5); idx1=1+floor((idx0-1)/size(data.Af,1));
0047         data.Af(idx0)=data.Af(idx0)+4*max(0,data.P(idx1)'-.75).*(.5/(1-exp(-.5))*(exp(-data.Af(idx0))-exp(-.5)));   % allows for pressure opening of the mouth
0048         data.Af=max(0,data.Af)+.001; for i=2:Nt, data.Af(:,i)=data.Af(:,i-1).*exp(max(-2,min(1,log(data.Af(:,i))-log(data.Af(:,i-1))))); end; data.Af=max(0,data.Af-.001);  % smooths to avoid clicks
0049     end
0050     opt.Af=data.Af;
0051 end;
0052 
0053 switch(TYPE),
0054     case 'Af',
0055         % Determine the dimensionality of the area functions
0056         n = size(data.Af,2);
0057         
0058         % Initialize all parameters for vtsynth - [note the transpose]
0059         Ag0 = data.Ag0';
0060         AgP = data.AgP';
0061         F0  = data.F0';
0062         
0063         %TAF1 = [linspace(0,data.duration,n)' [0;2 * ones(n-1,1)] -1*ones(n,1)]';
0064         TAF1 = [F0(1,:)', [0;2 * ones(n-1,1)], -1*ones(n,1)]';
0065         TAF2 = data.Af;
0066         
0067         % call vtsynth to generate the signal
0068         if 1,
0069             if isfield(data,'fs'),
0070                 [sig] = vtsynth(size(data.Af,1),Ag0,AgP,F0,TAF1,TAF2,data.dx,data.fs);
0071             else,
0072                 [sig] = vtsynth(size(data.Af,1),Ag0,AgP,F0,TAF1,TAF2,data.dx);
0073             end;
0074         else,   % do it recursively, it might avoid clicks...
0075             N0=4;
0076             Na=size(data.Af,1);
0077             dt=data.duration/Nt; %step size in ms
0078             Np=round(dt*(Nt-1)*Fs/1000);
0079             sig=zeros(Np,1);
0080             idx=(1:Np);
0081             sF0=(Fs./F0(2,:));
0082             idxa=1+floor((0:Np-1)/Fs/dt*1000);
0083             idxb=[1,find(diff(idxa)),Np+1];
0084             d=ones(1,2); ph=0;
0085             for n1=1:length(idxb)-1,
0086                 tt=[0,1*sF0(n1+1)*N0/Fs*1000]; %N0*round(idxb(n1+1)-idxb(n1))/Fs*1000];
0087                 sigt=vtsynth(Na,[tt;Ag0(2:end,[1,n1+1])],[tt;AgP(2:end,[n1,n1+1])],[tt;F0(2:end,[n1,n1+1])],[tt;TAF1(2:end,[n1,n1+1])],TAF2(:,[n1,n1+1]),data.dx(:,[n1,n1+1]));
0088                 %sigt=vtsynth(Na,[tt;Ag0(2:end,n1+d)],[tt;AgP(2:end,n1+d)],[tt;F0(2:end,n1+d)],[tt;TAF1(2:end,n1+d)],TAF2(:,n1+d),data.dx(:,n1+d));
0089                 sig(idxb(n1):idxb(n1+1)-1)=sigt(end-ceil(sF0(n1+1))+1+mod(floor(ph*sF0(n1+1))+(1:idxb(n1+1)-idxb(n1))-1,ceil(sF0(n1+1))));
0090                 ph=mod(ph+(idxb(n1+1)-idxb(n1))/sF0(n1+1),1);
0091             end
0092             sig=sig/2;
0093         end
0094         %sig=sigm(.5*sig);
0095 
0096         AV=interp1(linspace(1,length(sig),n),min(data.Af)>0.1,1:length(sig))';
0097         sig = sig.*AV;
0098         
0099     case 'Tf',
0100         Tf=10.^(data.Tf/20)-1e-2;
0101         dt=data.duration/Nt; %step size in ms
0102         Np=round(dt*(Nt-1)*Fs/1000);
0103         WS=[20,1]; WS=WS/sum(abs(WS)); % glotal components
0104         
0105         % Generates source
0106         sfilt=hamming(round(Fs/1000*dt)+1); sfilt=sfilt/sum(sfilt);
0107         F0=repmat(data.F0(:,2)',[round(Fs/1000*dt),1]); F0=convn(F0(:),sfilt,'valid');
0108         Ag0=repmat(data.Ag0(:,2)',[round(Fs/1000*dt),1]); Ag0=convn(Ag0(:),sfilt,'valid');
0109         AgP=repmat(data.AgP(:,2)',[round(Fs/1000*dt),1]); AgP=convn(AgP(:),sfilt,'valid');
0110         phase=cumsum(F0/Fs);
0111         noise=.5*randn([Np,1])/10;
0112         Ag0=max(0.1,min(1,Ag0));
0113         sig0=AgP.*((1-Ag0).*(WS(1)*glotros(0,phase)+WS(2)*glotros(1,phase)) + (Ag0).*noise);
0114         
0115         % Vocal cavity filter
0116         Nf=127;
0117         %ffilt=real(fft(max(0,data.Tf))); ffilt=ffilt([end-(Nf-1)/2+1:end, 1:(Nf+1)/2],:);
0118         %ffilt=real(fft((max(0,[zeros(1,Nt);data.Tf;flipud(data.Tf)])))); ffilt=ffilt([end-(Nf-1)/2+1:end, 1:(Nf+1)/2],:);
0119         time=linspace(1,Nt,Np); timel=floor(time); timer=time-timel;
0120         ffilt=real(fft((max(0,[zeros(1,Nt);Tf;flipud(Tf)])))); ffilt=ffilt([end-(Nf-1)/2+1:end, 1:(Nf+1)/2],:);
0121         Sig=sample_window(sig0,Nf,Nf-1,'hanning','same');
0122         sig=(1-timer).*sum(Sig.*ffilt(:,max(1,min(Nt,timel))),1) + timer.*sum(Sig.*ffilt(:,max(1,min(Nt,timel+1))),1);
0123         
0124         sig=2*sig/100;
0125         %sig=sigm(.5*sig/1000);
0126 
0127 end
0128 
0129 data.sig=sig;
0130 data.Plot=opt;

Generated on Tue 27-Mar-2007 12:06:24 by m2html © 2003