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());
// create the array of final residual sizes
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 all the pitchmarks that are required
for (; (pmI < numberFrames) &&
(targetTimes[pmI] <= targetEnd); pmI++) {
Sample sample = unit.getNearestSample(uIndex);
// Get LPC coefficients by copying
lpcResult.setFrame(pmI, sample.getFrameData());
// Get residual by copying
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();
}
}