Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

NNComposer.java

00001 /*
00002  *  Copyright 2006-2007 Columbia University.
00003  *
00004  *  This file is part of MEAPsoft.
00005  *
00006  *  MEAPsoft is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License version 2 as
00008  *  published by the Free Software Foundation.
00009  *
00010  *  MEAPsoft is distributed in the hope that it will be useful, but
00011  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with MEAPsoft; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00018  *  02110-1301 USA
00019  *
00020  *  See the file "COPYING" for the text of the license.
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         // initial chunk - pick it at random:
00092         //int randIdx = (int)Math.floor(featFile.chunks.size()*Math.random());
00093         // start with the first chunk
00094         FeatChunk currChunk = (FeatChunk)featFile.chunks.get(0);
00095         
00096         dist.setTarget(currChunk);
00097         
00098         // maintain a set of chunks sorted using dist from targetChunk
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             // turn currChunk into an EDL chunk 
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         // outFile now contains some chunks.
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 }

Generated on Tue Feb 6 19:02:27 2007 for MEAPsoft by doxygen1.2.18