⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vc2.m

📁 这是一个用于语音信号处理的工具箱
💻 M
📖 第 1 页 / 共 2 页
字号:
             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 bias model is used to convert the gain contour.');
     disp(b);
     disp('Normalized Standard Deviation=');
     disp(out(3)/mean(ngm2_ref));

  elseif ngm_method==2

     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=road1(1,:);
     tM2=length(x_ref);
     tmp_gm=zeros(tM2,4);

     % ---interpolate ngm3---
     s_fram=1;
     for k=1:length(vcidx11);
          e_fram=s_fram+vcidx12(k)-vcidx11(k);

          % smoothing the starting frame
          kf=s_fram;
             ngm3_ref(kf)=0.13*ngm3_ref(kf+1);
             gm_x=[1 m_len/2 m_len+m_len];
             gm_y=[0 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,'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;
             ngm3_ref(kf)=0.13*ngm3_ref(kf-1);
             gm_x=[-1*m_len/2 m_len/2 m_len];
             gm_y=[ngm3_ref(kf-1) ngm3_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;

     disp('The linear model is used to convert the gain contour.');
     disp( [a b]);

  elseif ngm_method==3

     ngm1_ref=ngm2_ref;

     x_ref=road1(1,:);
     tM2=length(x_ref);
     tmp_gm=zeros(tM2,4);

     % ---interpolate ngm3---
     s_fram=1;
     for k=1:length(vcidx11);
          e_fram=s_fram+vcidx12(k)-vcidx11(k);

          % smoothing the starting frame
          kf=s_fram;
             ngm3_ref(kf)=0.13*ngm3_ref(kf+1);
             gm_x=[1 m_len/2 m_len+m_len];
             gm_y=[0 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,'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;
             ngm3_ref(kf)=0.13*ngm3_ref(kf-1);
             gm_x=[-1*m_len/2 m_len/2 m_len];
             gm_y=[ngm3_ref(kf-1) ngm3_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;

  elseif ngm_method==4

      ngm3_ref=ngm1_ref;

  end  %% if ngm_method==1

  clear ngm1_ref ngm2_ref ngm3_ref tmp tmp_gm;


  %-------------------------------------------------
  %************ convert gm3 to match gm2  **********

  % construct new gain contour 

  gm_x=1;
  gm_y=0;
  [nframe,dum]=size(cofa1);
  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
  gm3(1)=gm1(1);
  gm3(length(gm3))=gm1(length(gm1));

  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;

  %************ convert gpcf1 to match gpcf2  **********
 
  gpcf3=zeros(M1,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 the 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( x_ref,:)=gpcf2_ref;

  elseif gpcf_method==4

     gpcf3=gpcf2;

  end

  clear gpcf1_ref gpcf2_ref tmp ncol err;

  %************ convert FF1 to match FF2  **********

  ff_method=get(v_pp_ff,'Value');

  if vt==1 & ff_method==3        
      cofa3(x_ref,:)=cofa2(y_ref,:);
  end  %% if vt==1

  if vt==2

      x_ref=road1(1,:);
      FF3=FF1;

      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,:)=FF1_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

         FB3=FB1;
         FF3( x_ref,:)=FF2_ref;
         FB3( x_ref,:)=FB2(y_ref,:);       
         cofa3(road1(1,:),:)=cofa2(y_ref,:);
         FF3_ref=FF2_ref;

      elseif ff_method==4

         FF3=FF1;
         FB3=FB1;
         FF3_ref=FF1_ref;

      end
     
      clear s_fram e_fram spoint epoint;

      %---------------------------------------%
      % determine new formant bandwidth FB1   %
      %---------------------------------------%

      % change the formant bandwidth to compensate for the pole interaction problem
      if ff_method<3
         FB3=FB1;
         for k=1:length(x_ref)
              kf=x_ref(k);
              [npoly,opoly,FB3(kf,:)]=rt2lp(FF3(kf,:),FF1(kf,:),FB1(kf,:) );
         end
      end %%if ff_method<3

      if SHOW==1         
            subplot(311); plot(FF1_ref);title('source spectrogram');
            subplot(312); plot(FF3_ref);title('converted spectrogram');
            subplot(313); plot(FF2_ref);title('target spectrogram');
            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 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 + -