public String HmmF0Generation(HTSUttModel um,HMMData htsData) throws Exception {
  int frame, uttFrame, lf0Frame;
  int hmmState, k, n, i;
  boolean nobound;
  HTSModel m;
  HTSPStream lf0Pst=null;
  boolean voiced[];
  CartTreeSet ms=htsData.getCartTreeSet();
  lf0Pst=new HTSPStream(ms.getLf0Stream(),um.getLf0Frame(),HMMData.FeatureType.LF0,200);
  uttFrame=lf0Frame=0;
  voiced=new boolean[um.getTotalFrame()];
  for (i=0; i < um.getNumUttModel(); i++) {
    m=um.getUttModel(i);
    for (hmmState=0; hmmState < ms.getNumStates(); hmmState++)     for (frame=0; frame < m.getDur(hmmState); frame++) {
      voiced[uttFrame]=m.getVoiced(hmmState);
      uttFrame++;
      if (m.getVoiced(hmmState))       lf0Frame++;
    }
  }
  uttFrame=0;
  lf0Frame=0;
  for (i=0; i < um.getNumUttModel(); i++) {
    m=um.getUttModel(i);
    for (hmmState=0; hmmState < ms.getNumStates(); hmmState++) {
      for (frame=0; frame < m.getDur(hmmState); frame++) {
        for (k=0; k < ms.getLf0Stream(); k++) {
          int lw=lf0Pst.getDWLeftBoundary(k);
          int rw=lf0Pst.getDWRightBoundary(k);
          nobound=true;
          for (n=lw; n <= rw; n++)           if ((uttFrame + n) <= 0 || um.getTotalFrame() <= (uttFrame + n))           nobound=false;
 else           nobound=(nobound && voiced[uttFrame + n]);
          if (voiced[uttFrame]) {
            lf0Pst.setMseq(lf0Frame,k,m.getLf0Mean(hmmState,k));
            if (nobound || k == 0)             lf0Pst.setIvseq(lf0Frame,k,HTSParameterGeneration.finv(m.getLf0Variance(hmmState,k)));
 else             lf0Pst.setIvseq(lf0Frame,k,0.0);
          }
        }
        if (voiced[uttFrame])         lf0Frame++;
        uttFrame++;
      }
    }
  }
  double f0s[]=new double[voiced.length];
  i=0;
  if (lf0Frame > 0) {
    Log.i(Mary.LOG,"Parameter generation for LF0: ");
    lf0Pst.mlpg(htsData,htsData.getUseGV());
    for (int t=0; t < voiced.length; t++) {
      if (voiced[t]) {
        f0s[t]=Math.exp(lf0Pst.getPar(i,0));
        i++;
      }
 else       f0s[t]=0.0;
    }
  }
  double totalDur;
  int totalFrames;
  String f0Values="";
  int t=0;
  for (i=0; i < um.getNumUttModel(); i++) {
    m=um.getUttModel(i);
    f0Values+=m.getPhoneName() + " " + m.getTotalDurMillisec()+ " ";
    totalDur=m.getTotalDur();
    totalFrames=0;
    if (checkModelVoiced(m,ms.getNumStates())) {
      for (int j=0; j < ms.getNumStates(); j++) {
        for (frame=0; frame < m.getDur(j); frame++) {
          totalFrames++;
          if (f0s[t] > 0.0)           f0Values+="(" + Integer.toString((int)((totalFrames / totalDur) * 100)) + ","+ Integer.toString((int)f0s[t])+ ")";
          t++;
        }
      }
    }
 else {
      t=t + m.getTotalDur();
      f0Values+="0";
    }
    f0Values+="\n";
  }
  return (f0Values);
}

public String HmmF0Generation ( HTSUttModel um , HMMData htsData ) throws Exception { int frame , uttFrame , lf0Frame ; int hmmState , k , n , i ; boolean nobound ; HTSModel m ; HTSPStream lf0Pst = null ; boolean voiced [ ] ; CartTreeSet ms = htsData . getCartTreeSet ( ) ; lf0Pst = new HTSPStream ( ms . getLf0Stream ( ) , um . getLf0Frame ( ) , HMMData . FeatureType . LF0 , 200 ) ; uttFrame = lf0Frame = 0 ; voiced = new boolean [ um . getTotalFrame ( ) ] ; for ( i = 0 ; i < um . getNumUttModel ( ) ; i ++ ) { m = um . getUttModel ( i ) ; for ( hmmState = 0 ; hmmState < ms . getNumStates ( ) ; hmmState ++ ) for ( frame = 0 ; frame < m . getDur ( hmmState ) ; frame ++ ) { voiced [ uttFrame ] = m . getVoiced ( hmmState ) ; uttFrame ++ ; if ( m . getVoiced ( hmmState ) ) lf0Frame ++ ; } } uttFrame = 0 ; lf0Frame = 0 ; for ( i = 0 ; i < um . getNumUttModel ( ) ; i ++ ) { m = um . getUttModel ( i ) ; for ( hmmState = 0 ; hmmState < ms . getNumStates ( ) ; hmmState ++ ) { for ( frame = 0 ; frame < m . getDur ( hmmState ) ; frame ++ ) { for ( k = 0 ; k < ms . getLf0Stream ( ) ; k ++ ) { int lw = lf0Pst . getDWLeftBoundary ( k ) ; int rw = lf0Pst . getDWRightBoundary ( k ) ; nobound = true ; for ( n = lw ; n <= rw ; n ++ ) if ( ( uttFrame + n ) <= 0 || um . getTotalFrame ( ) <= ( uttFrame + n ) ) nobound = false ; else nobound = ( nobound && voiced [ uttFrame + n ] ) ; if ( voiced [ uttFrame ] ) { lf0Pst . setMseq ( lf0Frame , k , m . getLf0Mean ( hmmState , k ) ) ; if ( nobound || k == 0 ) lf0Pst . setIvseq ( lf0Frame , k , HTSParameterGeneration . finv ( m . getLf0Variance ( hmmState , k ) ) ) ; else lf0Pst . setIvseq ( lf0Frame , k , 0.0 ) ; } } if ( voiced [ uttFrame ] ) lf0Frame ++ ; uttFrame ++ ; } } } double f0s [ ] = new double [ voiced . length ] ; i = 0 ; if ( lf0Frame > 0 ) { Log . i ( Mary . LOG , "Parameter generation for LF0: " ) ; lf0Pst . mlpg ( htsData , htsData . getUseGV ( ) ) ; for ( int t = 0 ; t < voiced . length ; t ++ ) { if ( voiced [ t ] ) { f0s [ t ] = Math . exp ( lf0Pst . getPar ( i , 0 ) ) ; i ++ ; } else f0s [ t ] = 0.0 ; } } double totalDur ; int totalFrames ; String f0Values = "" ; int t = 0 ; for ( i = 0 ; i < um . getNumUttModel ( ) ; i ++ ) { m = um . getUttModel ( i ) ; f0Values += m . getPhoneName ( ) + " " + m . getTotalDurMillisec ( ) + " " ; totalDur = m . getTotalDur ( ) ; totalFrames = 0 ; if ( checkModelVoiced ( m , ms . getNumStates ( ) ) ) { for ( int j = 0 ; j < ms . getNumStates ( ) ; j ++ ) { for ( frame = 0 ; frame < m . getDur ( j ) ; frame ++ ) { totalFrames ++ ; if ( f0s [ t ] > 0.0 ) f0Values += "(" + Integer . toString ( ( int ) ( ( totalFrames / totalDur ) * 100 ) ) + "," + Integer . toString ( ( int ) f0s [ t ] ) + ")" ; t ++ ; } } } else { t = t + m . getTotalDur ( ) ; f0Values += "0" ; } f0Values += "\n" ; } return ( f0Values ) ; }
generate f0 values for voiced frames out of hmms
