00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package com.meapsoft.composers;
00024
00025 import java.text.NumberFormat;
00026
00027 import com.meapsoft.ChunkDist;
00028 import com.meapsoft.EDLChunk;
00029 import com.meapsoft.EDLFile;
00030 import com.meapsoft.FeatChunk;
00031 import com.meapsoft.FeatFile;
00032 import com.meapsoft.MinHeap;
00033
00042 public class NNComposer extends SortComposer
00043 {
00044 public static String description = "NNComposer starts at the first chunk and proceeds through the sound file " +
00045 "from each chunk to its nearest neighbor, according to the features " +
00046 "in the input features file.";
00047
00048 public NNComposer(String featFN, String outFN)
00049 {
00050 super(featFN, outFN);
00051 }
00052
00053 public NNComposer(FeatFile featFN, EDLFile outFN)
00054 {
00055 super(featFN, outFN);
00056 }
00057
00058 public NNComposer(String featFN, String outFN, ChunkDist cd)
00059 {
00060 super(featFN, outFN, cd);
00061 }
00062
00063 public NNComposer(FeatFile featFN, EDLFile outFN, ChunkDist cd)
00064 {
00065 super(featFN, outFN, cd);
00066 }
00067
00068 public void printUsageAndExit()
00069 {
00070 System.out.println("Usage: NNComposer [-options] features.feat \n\n" +
00071 " where options include:\n" +
00072 " -o output_file the file to write the output to (defaults to sorted.edl)\n" +
00073 " -g debug mode (prints out chunk features on each line of output file)");
00074 printCommandLineOptions('i');
00075 printCommandLineOptions('d');
00076 printCommandLineOptions('c');
00077 System.out.println();
00078 System.exit(0);
00079 }
00080
00084 public NNComposer(String[] args)
00085 {
00086 super(args);
00087 }
00088
00089 public EDLFile compose()
00090 {
00091
00092
00093
00094 FeatChunk currChunk = (FeatChunk)featFile.chunks.get(0);
00095
00096 dist.setTarget(currChunk);
00097
00098
00099 MinHeap chunks = new MinHeap(dist);
00100 chunks.addAll(featFile.chunks);
00101
00102 NumberFormat fmt = NumberFormat.getInstance();
00103 fmt.setMaximumFractionDigits(3);
00104
00105 double currTime = 0;
00106 while(chunks.size() > 0)
00107 {
00108 dist.setTarget(currChunk);
00109 chunks.rebuildHeap();
00110
00111 currChunk = (FeatChunk)chunks.deleteMin();
00112
00113
00114 EDLChunk nc = new EDLChunk(currChunk, currTime);
00115
00116 if(debug)
00117 {
00118 nc.comment = " # feats = ";
00119 double[] feat = currChunk.getFeatures(featdim);
00120 for(int x = 0; x < feat.length-1; x++)
00121 nc.comment += fmt.format(feat[x]) + ", ";
00122 nc.comment += fmt.format(feat[feat.length-1]);
00123 }
00124
00125 outFile.chunks.add(nc);
00126
00127 currTime += currChunk.length;
00128
00129 progress.setValue(progress.getValue()+1);
00130 }
00131
00132
00133 outFile.haveReadFile = true;
00134
00135 return outFile;
00136 }
00137
00138 public static void main(String[] args)
00139 {
00140 NNComposer m = new NNComposer(args);
00141 long startTime = System.currentTimeMillis();
00142
00143 m.run();
00144
00145 System.out.println("Done. Took " +
00146 ((System.currentTimeMillis() - startTime)/1000.0)
00147 + "s");
00148 System.exit(0);
00149 }
00150 }