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 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
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
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':
00113 break;
00114 case '?':
00115 printUsageAndExit();
00116 break;
00117 default:
00118 System.out.print("getopt() returned " + c + "\n");
00119 }
00120 }
00121
00122
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
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
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 }