double highBoundMult = highBound * 2;
Vector featChunks = new Vector(featFile.chunks);
//find chunks that fall in divisions or multiples of mode.
FeatChunk tempFeatChunk;
double tempFeatLen;
Vector modeChunks = new Vector();
Vector multModeChunks = new Vector();
Vector divModeChunks = new Vector();
Vector div2ModeChunks = new Vector();
for (int i=0; i < featChunks.size(); i++)
{
tempFeatChunk = (FeatChunk)featChunks.get(i);
tempFeatLen = Math.floor(tempFeatChunk.length * samplingRate);
if (lowBoundDiv2 < tempFeatLen && tempFeatLen < highBoundDiv2)
{
div2ModeChunks.add(featChunks.get(i));
//System.out.println(" found a div2 in chunk" + i);
}
else if (lowBoundDiv < tempFeatLen && tempFeatLen < highBoundDiv)
{
divModeChunks.add(featChunks.get(i));
//System.out.println(" found a div in chunk" + i);
}
else if (lowBoundMult < tempFeatLen && tempFeatLen < highBoundMult)
{
multModeChunks.add(featChunks.get(i));
//System.out.println(" found a mult in chunk" + i);
}
else if (lowBound < tempFeatLen && tempFeatLen < highBound)
{
modeChunks.add(featChunks.get(i));
//System.out.println(" found a mode in chunk" + i);
}
}
Vector outChunks = new Vector();
Random rand = new Random();
int index;
for (int i=0; i < newPieceLength; i++)
{
index = rand.nextInt(16);
if (0 <= index && index < 4)
{
if (div2ModeChunks.size() > 0)
{
outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
//System.out.println("Wrote 8 mode / 4 chunks");
}
}
else if (4 <= index && index < 6)
{
if (divModeChunks.size() > 0)
{
outChunks.add(divModeChunks.get(rand.nextInt(divModeChunks.size())));
outChunks.add(divModeChunks.get(rand.nextInt(divModeChunks.size())));
outChunks.add(divModeChunks.get(rand.nextInt(divModeChunks.size())));
outChunks.add(divModeChunks.get(rand.nextInt(divModeChunks.size())));
//System.out.println("Wrote 4 mode / 2 chunks");
}
}
else if (6 <= index && index < 14)
{
if (modeChunks.size() > 0)
{
outChunks.add(modeChunks.get(rand.nextInt(modeChunks.size())));
outChunks.add(modeChunks.get(rand.nextInt(modeChunks.size())));
//System.out.println("Wrote 2 mode chunks");
}
}
else if (14 <= index )
{
if (multModeChunks.size() > 0)
{
outChunks.add(multModeChunks.get(rand.nextInt(multModeChunks.size())));
//System.out.println("Wrote 1 mode * 2 chunk");
}
}
progress.setValue(progress.getValue()+1);
}
double currTime = 0;
while(outChunks.size() > 0)
{
FeatChunk match = (FeatChunk)outChunks.remove(0);
// turn match chunk into an EDL chunk
EDLChunk nc = new EDLChunk(match, currTime);
if(debug)
{
NumberFormat fmt = NumberFormat.getInstance();
fmt.setMaximumFractionDigits(3);
nc.comment = " # feats = ";
double[] feat = match.getFeatures();
for(int x = 0; x < feat.length-1; x++)
nc.comment += fmt.format(feat[x]) + ", ";
nc.comment += fmt.format(feat[feat.length-1]);
}