Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

BlipComposer.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 gnu.getopt.Getopt;
00026 
00027 import java.io.IOException;
00028 import java.util.Iterator;
00029 import java.util.Vector;
00030 
00031 import com.meapsoft.EDLChunk;
00032 import com.meapsoft.EDLFile;
00033 import com.meapsoft.FeatChunk;
00034 import com.meapsoft.FeatFile;
00035 import com.meapsoft.ParserException;
00036 
00042 public class BlipComposer extends Composer
00043 {
00044         public static String description = "BlipComposer inserts a blip at the beginning of each chunk in the input " +
00045         "features file. Especially useful for understanding the output of the " +
00046         "segmenter.";
00047         
00048         String outFileName = "blipped.edl";
00049 
00050         FeatFile featFile;
00051         boolean debug = false;
00052         
00053     // path to blip wav file
00054     String blipWav = "data" + System.getProperty("file.separator") + "blip.wav"; 
00055 
00056         public BlipComposer(String featFN, String outFN)
00057         {
00058                 this(new FeatFile(featFN), new EDLFile(outFN));
00059         }
00060 
00061         public BlipComposer(FeatFile featFN, EDLFile outFN)
00062         {
00063                 if (featFN == null || outFN == null)
00064                         return;
00065                         
00066                 featFile = featFN;
00067                 outFile = outFN;
00068 
00069                 if(outFile == null)
00070                         outFile = new EDLFile("");
00071         }
00072 
00073         public void printUsageAndExit() 
00074         {
00075                 System.out.println("Usage: BlipComposer [-options] features.feat \n\n" + 
00076                            "  where options include:\n" + 
00077                            "    -o output_file  the file to write the output to (defaults to blipped.edl)\n" +
00078                "    -f blip_file    the audio file to insert at the beginning of each chunk (defaults to data/blip.wav)");
00079         printCommandLineOptions('c');
00080                 System.out.println();
00081                 System.exit(0);
00082         }
00083 
00084         public BlipComposer(String[] args) 
00085         {
00086                 if(args.length == 0)
00087                         printUsageAndExit();
00088 
00089                 Vector features = new Vector();
00090 
00091                 // Parse arguments
00092                 String argString = "o:c:f:g";
00093         parseCommands(args, argString);
00094 
00095                 Getopt opt = new Getopt("BlipComposer", args, argString);
00096                 opt.setOpterr(false);
00097         
00098                 int c = -1;
00099                 while ((c =opt.getopt()) != -1) 
00100                 {
00101                         switch(c) 
00102                         {
00103                         case 'o':
00104                                 outFileName = opt.getOptarg();
00105                                 break;
00106                         case 'g':
00107                                 debug = true;
00108                                 break;
00109                         case 'f':
00110                                 blipWav = opt.getOptarg();
00111                                 break;
00112             case 'c':  // already handled above
00113                 break;
00114                         case '?':
00115                                 printUsageAndExit();
00116                                 break;
00117                         default:
00118                                 System.out.print("getopt() returned " + c + "\n");
00119                         }
00120                 }
00121         
00122                 // parse arguments
00123                 int ind = opt.getOptind();
00124                 if(ind > args.length)
00125                         printUsageAndExit();
00126         
00127                 featFile = new FeatFile(args[args.length-1]);
00128                 outFile = new EDLFile(outFileName);
00129 
00130                 System.out.println("Composing " + outFileName + 
00131                                                    " from " +  args[args.length-1] + ".");
00132         }
00133 
00134         public void setup() throws IOException, ParserException
00135         {
00136                 super.setup();
00137 
00138                 if(!featFile.haveReadFile)
00139                         featFile.readFile();
00140 
00141                 if(featFile.chunks.size() == 0)
00142                         throw new ParserException(featFile.filename, "No chunks found");
00143 
00144         progress.setMaximum(featFile.chunks.size());
00145         }
00146     
00147         public EDLFile compose()
00148         {
00149                 Iterator c = featFile.chunks.iterator();
00150                 double currTime = 0;
00151         
00152                 while(c.hasNext())
00153                 {
00154                         FeatChunk ch = (FeatChunk)c.next();
00155 
00156                         EDLChunk nc = new EDLChunk(ch, currTime);
00157                         // hard-coded parameters of blip
00158                         EDLChunk blip = new EDLChunk(blipWav, 0, 0.1, currTime);
00159 
00160                         outFile.chunks.add(blip);
00161                         outFile.chunks.add(nc);
00162             
00163                         currTime += ch.length;
00164 
00165             progress.setValue(progress.getValue()+1);
00166                 }
00167 
00168                 // outFile now contains some chunks.
00169                 outFile.haveReadFile = true;
00170 
00171                 return outFile;
00172         } 
00173 
00174         public String description()
00175         {
00176                 return description;
00177         }
00178 
00179     public void setBlipWav(String bp)
00180     {
00181         blipWav = bp;
00182     }
00183         
00184         public static void main(String[] args) 
00185         {
00186                 BlipComposer m = new BlipComposer(args);
00187                 long startTime = System.currentTimeMillis();
00188                 m.run();
00189                 System.out.println("Done. Took " +
00190                                                    ((System.currentTimeMillis() - startTime)/1000.0)
00191                                                    + "s");
00192                 System.exit(0);
00193         }
00194 }

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