public void processUtterance(Utterance utterance) throws ProcessException {
  float uIndex=0, m;
  int pmI=0, targetResidualPosition=0, nearestPM, unitPart, targetStart=0, targetEnd, residualSize, numberFrames;
  Relation unitRelation=utterance.getRelation(Relation.UNIT);
  boolean debug=false;
  SampleInfo sampleInfo;
  int addResidualMethod=ADD_RESIDUAL;
  String residualType=utterance.getString("residual_type");
  if (residualType != null) {
    if (residualType.equals("pulse")) {
      addResidualMethod=ADD_RESIDUAL_PULSE;
    }
 else     if (residualType.equals("windowed")) {
      addResidualMethod=ADD_RESIDUAL_WINDOWED;
    }
  }
  sampleInfo=(SampleInfo)utterance.getObject(SampleInfo.UTT_NAME);
  if (sampleInfo == null) {
    throw new IllegalStateException("UnitConcatenator: SampleInfo does not exist");
  }
  LPCResult lpcResult=(LPCResult)utterance.getObject("target_lpcres");
  lpcResult.setValues(sampleInfo.getNumberOfChannels(),sampleInfo.getSampleRate(),sampleInfo.getResidualFold(),sampleInfo.getCoeffMin(),sampleInfo.getCoeffRange());
  int[] targetTimes=lpcResult.getTimes();
  int[] residualSizes=lpcResult.getResidualSizes();
  int samplesSize=0;
  if (lpcResult.getNumberOfFrames() > 0) {
    samplesSize=targetTimes[lpcResult.getNumberOfFrames() - 1];
  }
  lpcResult.resizeResiduals(samplesSize);
  for (Item unitItem=unitRelation.getHead(); unitItem != null; unitItem=unitItem.getNext()) {
    FeatureSet featureSet=unitItem.getFeatures();
    String unitName=featureSet.getString("name");
    targetEnd=featureSet.getInt("target_end");
    Unit unit=(Unit)featureSet.getObject("unit");
    int unitSize=unit.getSize();
    uIndex=0;
    m=(float)unitSize / (float)(targetEnd - targetStart);
    numberFrames=lpcResult.getNumberOfFrames();
    for (; (pmI < numberFrames) && (targetTimes[pmI] <= targetEnd); pmI++) {
      Sample sample=unit.getNearestSample(uIndex);
      lpcResult.setFrame(pmI,sample.getFrameData());
      residualSize=lpcResult.getFrameShift(pmI);
      residualSizes[pmI]=residualSize;
      byte[] residualData=sample.getResidualData();
      if (addResidualMethod == ADD_RESIDUAL_PULSE) {
        lpcResult.copyResidualsPulse(residualData,targetResidualPosition,residualSize);
      }
 else {
        lpcResult.copyResiduals(residualData,targetResidualPosition,residualSize);
      }
      targetResidualPosition+=residualSize;
      uIndex+=((float)residualSize * m);
    }
    targetStart=targetEnd;
  }
  lpcResult.setNumberOfFrames(pmI);
  if (outputLPC) {
    lpcResult.dump();
  }
}

public void processUtterance ( Utterance utterance ) throws ProcessException { float uIndex = 0 , m ; int pmI = 0 , targetResidualPosition = 0 , nearestPM , unitPart , targetStart = 0 , targetEnd , residualSize , numberFrames ; Relation unitRelation = utterance . getRelation ( Relation . UNIT ) ; boolean debug = false ; SampleInfo sampleInfo ; int addResidualMethod = ADD_RESIDUAL ; String residualType = utterance . getString ( "residual_type" ) ; if ( residualType != null ) { if ( residualType . equals ( "pulse" ) ) { addResidualMethod = ADD_RESIDUAL_PULSE ; } else if ( residualType . equals ( "windowed" ) ) { addResidualMethod = ADD_RESIDUAL_WINDOWED ; } } sampleInfo = ( SampleInfo ) utterance . getObject ( SampleInfo . UTT_NAME ) ; if ( sampleInfo == null ) { throw new IllegalStateException ( "UnitConcatenator: SampleInfo does not exist" ) ; } LPCResult lpcResult = ( LPCResult ) utterance . getObject ( "target_lpcres" ) ; lpcResult . setValues ( sampleInfo . getNumberOfChannels ( ) , sampleInfo . getSampleRate ( ) , sampleInfo . getResidualFold ( ) , sampleInfo . getCoeffMin ( ) , sampleInfo . getCoeffRange ( ) ) ; int [ ] targetTimes = lpcResult . getTimes ( ) ; int [ ] residualSizes = lpcResult . getResidualSizes ( ) ; int samplesSize = 0 ; if ( lpcResult . getNumberOfFrames ( ) > 0 ) { samplesSize = targetTimes [ lpcResult . getNumberOfFrames ( ) - 1 ] ; } lpcResult . resizeResiduals ( samplesSize ) ; for ( Item unitItem = unitRelation . getHead ( ) ; unitItem != null ; unitItem = unitItem . getNext ( ) ) { FeatureSet featureSet = unitItem . getFeatures ( ) ; String unitName = featureSet . getString ( "name" ) ; targetEnd = featureSet . getInt ( "target_end" ) ; Unit unit = ( Unit ) featureSet . getObject ( "unit" ) ; int unitSize = unit . getSize ( ) ; uIndex = 0 ; m = ( float ) unitSize / ( float ) ( targetEnd - targetStart ) ; numberFrames = lpcResult . getNumberOfFrames ( ) ; for ( ; ( pmI < numberFrames ) && ( targetTimes [ pmI ] <= targetEnd ) ; pmI ++ ) { Sample sample = unit . getNearestSample ( uIndex ) ; lpcResult . setFrame ( pmI , sample . getFrameData ( ) ) ; residualSize = lpcResult . getFrameShift ( pmI ) ; residualSizes [ pmI ] = residualSize ; byte [ ] residualData = sample . getResidualData ( ) ; if ( addResidualMethod == ADD_RESIDUAL_PULSE ) { lpcResult . copyResidualsPulse ( residualData , targetResidualPosition , residualSize ) ; } else { lpcResult . copyResiduals ( residualData , targetResidualPosition , residualSize ) ; } targetResidualPosition += residualSize ; uIndex += ( ( float ) residualSize * m ) ; } targetStart = targetEnd ; } lpcResult . setNumberOfFrames ( pmI ) ; if ( outputLPC ) { lpcResult . dump ( ) ; } }
concatenate the units in the given utterance to the target_lpc result .
