Main Page   Class Hierarchy   Compound List   File List   Compound Members  

IntraChunkShuffleComposer.java

00001 package com.meapsoft.composers;
00002 
00003 import gnu.getopt.Getopt;
00004 
00005 import java.io.IOException;
00006 import java.util.Iterator;
00007 import java.util.Vector;
00008 
00009 import com.meapsoft.EDLChunk;
00010 import com.meapsoft.EDLFile;
00011 import com.meapsoft.FeatChunk;
00012 import com.meapsoft.FeatFile;
00013 import com.meapsoft.ParserException;
00014 
00020 public class IntraChunkShuffleComposer extends Composer
00021 {
00022         public static String description = "Chops each chunk up into small pieces " +
00023                 "and rearranges them. This keeps the meta chunks intact but scrambles " +
00024                 "them on a local level.";
00025         
00026         String outFileName = "shuffle.edl";
00027 
00028         FeatFile featFile;
00029         boolean debug = false;
00030         
00031         int numSubChunks = 4;
00032         
00033         public IntraChunkShuffleComposer(String featFN, String outFN, int chunks)
00034         {
00035                 this(new FeatFile(featFN), new EDLFile(outFN), chunks);
00036         }
00037 
00038         public IntraChunkShuffleComposer(FeatFile featFN, EDLFile outFN, int chunks)
00039         {
00040                 if (featFN == null || outFN == null)
00041                         return;
00042                         
00043                 featFile = featFN;
00044                 outFile = outFN;
00045                 numSubChunks = chunks;
00046                 
00047                 if (numSubChunks <= 1)
00048                         numSubChunks = 2;
00049 
00050                 if(outFile == null)
00051                         outFile = new EDLFile("");
00052         }
00053 
00054         public void printUsageAndExit() 
00055         {
00056                 System.out.println("Usage: IntraChunkShuffleComposer [-options] features.feat \n\n" + 
00057                            "  where options include:\n" + 
00058                            "    -o output_file  the file to write the output to (defaults to shuffle.edl)\n" +
00059                            "    -n num_chunks   the number of subchunks to divide each chunk into\n" +
00060                            "    -g              debug mode (prints out chunk features on each line of output file)");
00061                 System.out.println();
00062                 System.exit(0);
00063         }
00064 
00065         public IntraChunkShuffleComposer(String[] args) 
00066         {
00067                 if(args.length == 0)
00068                         printUsageAndExit();
00069 
00070                 Vector features = new Vector();
00071 
00072                 // Parse arguments
00073                 String argString = "o:n:g";
00074 
00075                 Getopt opt = new Getopt("IntraChunkShuffleComposer", args, argString);
00076                 opt.setOpterr(false);
00077         
00078                 int c = -1;
00079                 while ((c =opt.getopt()) != -1) 
00080                 {
00081                         switch(c) 
00082                         {
00083                         case 'o':
00084                                 outFileName = opt.getOptarg();
00085                                 break;
00086                         case 'n':
00087                                 numSubChunks = new Integer(opt.getOptarg()).intValue();
00088                                 if (numSubChunks <= 1)
00089                                         numSubChunks = 2;
00090                         case 'g':
00091                                 debug = true;
00092                                 break;
00093                         case '?':
00094                                 printUsageAndExit();
00095                                 break;
00096                         default:
00097                                 System.out.print("getopt() returned " + c + "\n");
00098                         }
00099                 }
00100         
00101                 // parse arguments
00102                 int ind = opt.getOptind();
00103                 if(ind > args.length)
00104                         printUsageAndExit();
00105         
00106                 featFile = new FeatFile(args[args.length-1]);
00107                 outFile = new EDLFile(outFileName);
00108 
00109                 System.out.println("Composing " + outFileName + 
00110                                                    " from " +  args[args.length-1] + ".");
00111         }
00112 
00113         public void setup() throws IOException, ParserException
00114         {
00115                 super.setup();
00116 
00117                 if(!featFile.haveReadFile)
00118                         featFile.readFile();
00119 
00120                 if(featFile.chunks.size() == 0)
00121                         throw new ParserException(featFile.filename, "No chunks found");
00122         }
00123     
00124 
00125         public EDLFile compose()
00126         {
00127                 Iterator c = featFile.chunks.iterator();
00128                 double currTime = 0;
00129                 
00130                 //iterate through all the chunks that the segmenter found
00131                 while(c.hasNext())
00132                 {
00133                         //your current features chunk
00134                         FeatChunk ch = (FeatChunk)c.next();
00135                         double length = ch.length/numSubChunks;
00136                         double localStartTime = ch.startTime;
00137                         
00138                         for (int i = numSubChunks - 1; i >= 0; i--)
00139                         {
00140                                 //make a new EDL chunk from the current features chunk
00141                                 //EDLChunk original = new EDLChunk(ch, currTime);
00142                                 
00143                                 EDLChunk chunk = new EDLChunk(ch.srcFile, 
00144                                         localStartTime + (i * length), length, currTime);
00145                                 
00146                                 //EDLChunk blip = new EDLChunk("data" + 
00147                                 //      System.getProperty("file.separator") + "blip.wav", 
00148                                 //      0, 0.1, currTime);
00149                                 //write both chunks out to the new EDL file                     
00150                                 outFile.chunks.add(chunk);
00151             
00152                                 //Increment currTime by twice the length of the chunk
00153                                 //since we've added two chunks. 
00154                                 currTime += length;
00155                         }
00156                 }
00157 
00158                 // outFile now contains some chunks.
00159                 outFile.haveReadFile = true;
00160 
00161                 return outFile;
00162         } 
00163 
00164         public static void main(String[] args) 
00165         {
00166                 IntraChunkShuffleComposer m = new IntraChunkShuffleComposer(args);
00167                 long startTime = System.currentTimeMillis();
00168                 m.go();
00169                 System.out.println("Done. Took " +
00170                                                    ((System.currentTimeMillis() - startTime)/1000.0)
00171                                                    + "s");
00172                 System.exit(0);
00173         }
00174 }

Generated on Thu May 11 15:04:10 2006 for MEAPsoft by doxygen1.2.18