📄 vc1.m
字号:
out=lrest(ngm1_ref, ngm2_ref, 1, SHOW)
b=out(1);
a=out(2);
ngm3_ref=abs(a*ngm1_ref+b); % new ngm contour
x_ref=road(1,:);
tM2=length(x_ref);
tmp_gm=zeros(tM2,4);
% ---interpolate ngm3---
s_fram=1;
for k=1:length(vcidx21);
e_fram=s_fram+vcidx22(k)-vcidx21(k);
% smoothing the starting frame
kf=s_fram;
gm_x=[1 m_len/2 m_len+m_len];
%When using segmentation we don't want to start the gain contour of the segment at 0
if ~exist('seg','var')
ngm3_ref(kf)=0.13*ngm3_ref(kf+1);
gm_y=[0 ngm3_ref(kf) ngm3_ref(kf+1)];
else
gm_y=[ngm3_ref(kf) ngm3_ref(kf) ngm3_ref(kf+1)];
end
gm_z=m_len/4*[0 1 2 3]+m_len/8;
tmp=interp1(gm_x,gm_y,gm_z,'spline');
tmp_gm(kf,1:4)=tmp(:)';
for kf=s_fram+1:e_fram-1
gm_x=[-1*m_len/2 m_len/2 m_len+m_len];
gm_y=[ngm3_ref(kf-1) ngm3_ref(kf) ngm3_ref(kf+1)];
gm_z=m_len/4*[0 1 2 3]+m_len/8;
tmp=interp1(gm_x,gm_y,gm_z);
tmp_gm(kf,1:4)=tmp(:)';
end
% smoothing the ending frame
kf=e_fram;
gm_x=[-1*m_len/2 m_len/2 m_len];
%When using segmentation we don't want to end the gain contour of the segment at 0
if ~exist('seg','var')
ngm3_ref(kf)=0.13*ngm3_ref(kf-1);
gm_y=[ngm3_ref(kf-1) ngm3_ref(kf) 0];
else
gm_y=[ngm3_ref(kf-1) ngm3_ref(kf) ngm3_ref(kf)];
end
gm_z=m_len/4*[0 1 2 3]+m_len/8;
tmp=interp1(gm_x,gm_y,gm_z,'spline');
tmp_gm(kf,1:4)=tmp(:)';
s_fram=e_fram+1;
end %% for k=1:length(vcidx21)
ngm3( x_ref,1:4)=tmp_gm;
disp('The linear model is used to convert the gain contour.');
disp( [a b]);
disp('Normalized Standard Deviation=');
disp(std(ngm3_ref-ngm2_ref)/mean(ngm2_ref));
elseif ngm_method==3
ngm3_ref=ngm2_ref;
elseif ngm_method==4
ngm3_ref=ngm1_ref;
x_ref=road(1,:);
tM2=length(x_ref);
tmp_gm=zeros(tM2,4);
% ---interpolate ngm3---
s_fram=1;
for k=1:length(vcidx21);
e_fram=s_fram+vcidx22(k)-vcidx21(k);
% smoothing the starting frame
kf=s_fram;
ngm1_ref(kf)=0.13*ngm1_ref(kf+1);
gm_x=[1 m_len/2 m_len+m_len];
gm_y=[0 ngm1_ref(kf) ngm1_ref(kf+1)];
gm_z=m_len/4*[0 1 2 3]+m_len/8;
tmp=interp1(gm_x,gm_y,gm_z,'spline');
tmp_gm(kf,1:4)=tmp(:)';
for kf=s_fram+1:e_fram-1
gm_x=[-1*m_len/2 m_len/2 m_len+m_len];
gm_y=[ngm1_ref(kf-1) ngm1_ref(kf) ngm1_ref(kf+1)];
gm_z=m_len/4*[0 1 2 3]+m_len/8;
tmp=interp1(gm_x,gm_y,gm_z);
tmp_gm(kf,1:4)=tmp(:)';
end
% smoothing the ending frame
kf=e_fram;
ngm1_ref(kf)=0.13*ngm1_ref(kf-1);
gm_x=[-1*m_len/2 m_len/2 m_len];
gm_y=[ngm1_ref(kf-1) ngm1_ref(kf) 0];
gm_z=m_len/4*[0 1 2 3]+m_len/8;
tmp=interp1(gm_x,gm_y,gm_z,'spline');
tmp_gm(kf,1:4)=tmp(:)';
s_fram=e_fram+1;
end %% for k=1:length(vcidx21)
ngm3( x_ref,1:4)=tmp_gm;
end %% if ngm_method==1
clear ngm1_ref ngm2_ref tmp tmp_gm;
%-------------------------------------------------
%************ convert gm3 to match gm2 **********
% construct new gain contour
gm_x=1;
gm_y=0;
[nframe,dum]=size(cofa2);
for kf=1:nframe
spoint=m_len*(kf-1)+Order+1;
tmp_x=m_len/4*[0 1 2 3]+m_len/8+spoint;
gm_x=[gm_x tmp_x];
gm_y=[gm_y ngm3(kf,1:4)];
end
gm_x=[gm_x spoint+m_len-1];
gm_y=[gm_y 0];
gm3=interp1( gm_x,gm_y,gci3 );
gm3=gm3(:)';
ave=min(gm3);
gm3=filter(0.4,[1 -0.4 -0.2],gm3);
gm3=gm3+(ave-min(gm3));
gm3=abs(gm3);
% take care of the transition. In the case of segmantation it does not
if length(gm3)==length(gm1)
gm3(1)=gm1(1);
gm3(length(gm3))=gm1(length(gm1));
%else
% [y,cor23]=min(abs(gci2-gci3(1)));
% gm3(1)=gm2(cor23);
% [y,cor23]=min(abs(gci2-gci3(length(gci3))));
% gm3(length(gm3))=gm2(cor23);
end
if SHOW==1
plot(gci1,gm1,'y',gci3,gm3,'r',gci2,gm2,'g');
title('gain conversion (source: yellow ; converted: red ; target: green)');
pause(1);
end
clear gm_x gm_y gm_z tmp_x cor23 y;
%************ convert gpcf1 to match gpcf2 **********
gpcf3=zeros(M2,7);
gpcf_method=get(v_pp_glo,'Value');
if sr==1
ncof=7; % number of coefficients
elseif sr==2
ncof=5;
end
if gpcf_method==1
for kk=1:ncof
out=lrest(gpcf1_ref(:,kk), gpcf2_ref(:,kk), 0, SHOW);
b=out(1);
gpcf1_ref(:,kk)=gpcf1_ref(:,kk)+b;
err(kk)=out(3);
end
gpcf3( x_ref,:)=gpcf1_ref;
disp('The bias model is used to convert glottal source.');
disp(b)
disp('Normalized Standard Deviation=')
disp(err./mean(gpcf2_ref(:,1:ncof)));
elseif gpcf_method==2
disp('The linear model is used to convert the glottal source.');
for kk=1:ncof
out=lrest(gpcf1_ref(:,kk), gpcf2_ref(:,kk), 1, SHOW);
b=out(1);
a=out(2);
err(kk)=out(3);
gpcf1_ref(:,kk)=a*gpcf1_ref(:,kk)+b;
disp( [a b]);
end
disp('Normalized Standard Deviation=');
disp(err./mean(gpcf2_ref(:,1:ncof)));
gpcf3( x_ref,:)=gpcf1_ref;
elseif gpcf_method==3
gpcf3=gpcf2;
elseif gpcf_method==4
gpcf3( x_ref,:)=gpcf1_ref;
end
clear gpcf1_ref gpcf2_ref tmp ncof err;
%************ convert FF1 to match FF2 **********
ff_method=get(v_pp_ff,'Value');
if vt==1 & ff_method==4
cofa3(road(1,:),:)=cofa1(road(2,:),:);
end %% if vt==1
if vt==2
x_ref=road(1,:);
FF3=FF2;
if ff_method==1
nff=basic(1);
for kk=1:nff
out=lrest(FF1_ref(:,kk), FF2_ref(:,kk), 0, SHOW);
b=out(1);
err(kk)=out(3);
FF3_ref(:,kk)=FF1_ref(:,kk)+b;
end
FF3( x_ref,:)=FF3_ref;
disp('The bias model is used to convert the formant track.');
disp(b);
disp('Normalized Standard Deviation=');
disp(std(FF3_ref-FF2_ref)./mean(FF2_ref));
elseif ff_method==2
disp('The linear model is used to convert the formant track.');
nff=basic(1);
for kk=1:nff
out=lrest(FF1_ref(:,kk), FF2_ref(:,kk), 1, SHOW);
b=out(1);
a=out(2);
err(kk)=out(3);
FF3_ref(:,kk)=a*FF1_ref(:,kk)+b;
disp( [a b]);
end
disp('Normalized Standard Deviation=');
disp(err./mean(FF2_ref));
FF3( x_ref,:)=FF3_ref;
elseif ff_method==3
FF3=FF2;
FB3=FB2;
FF3_ref=FF2_ref;
elseif ff_method==4
FF3_ref=FF1_ref;
FB3=FB2;
FF3( x_ref,:)=FF3_ref;
FB3( x_ref,:)=FB1(road(2,:),:);
cofa3(road(1,:),:)=cofa1(road(2,:),:);
end
clear s_fram e_fram spoint epoint err;
%---------------------------------------%
% determine new formant bandwidth FB3 %
%---------------------------------------%
% change the formant bandwidth to compensate for the pole interaction problem
if ff_method<3
FB3=FB2;
for k=1:tM2
kf1=road(2,k);
kf2=road(1,k);
%[npoly,opoly,FB3(kf2,:)]=rt2lp(FF3(kf2,:),FF1(kf1,:),FB1(kf1,:) );
[npoly,opoly,FB3(kf2,:)]=rt2lp(FF3(kf2,:),FF2(kf2,:),FB2(kf2,:) );
end
end %%if ff_method<3
if SHOW==1
subplot(311); plot(FF1_ref);title('source formant track');
subplot(312); plot(FF3_ref);title('converted formant track');
subplot(313); plot(FF2_ref);title('target formant track');
pause(1);
subplot(111);
end
end %% if vt==2;
disp('Voice Conversion is completed. You may run the synthesizer.');
clear tmp apply FF1_ref FF2_ref FF3_ref x_ref gci_s gci_e kf1 kf2 out err;
%clear vcidx11 vcidx12 vcidx21 vcidx22;
%clear ngm1 gm1 gci1 gpcf1 FF1 FB1 road road1 cofa1 vctyp1 nidx1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -