Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

SegmentExtractor.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;
00024 
00025 import java.util.Vector;
00026 
00027 import javax.swing.BoundedRangeModel;
00028 import javax.swing.DefaultBoundedRangeModel;
00029 
00039 public class SegmentExtractor implements FrameListener, Runnable, OnsetListener 
00040 {
00041     Vector consumers = new Vector();
00042     STFT stft;
00043     long lastOnset = -1;
00044     int minChunkLen = 5;
00045 
00046     //int maxChunkLen = 85
00047     // no max length between onsets
00048     int maxChunkLen = Integer.MAX_VALUE; 
00049     
00050     // keep track of whether or not we have seen any onsets yet...
00051     boolean recording = false;
00052     
00053     FeatFile outFile;
00054     String sourceFileName;
00055 
00056     private BoundedRangeModel progress = null;
00057     
00058     public SegmentExtractor(STFT stft, String sfn, FeatFile of, BoundedRangeModel brm)
00059     {
00060         this.stft = stft;
00061         sourceFileName = sfn;
00062         outFile = of;
00063 
00064         //maxChunkLen = stft.getRows();
00065 
00066         progress = brm;
00067     }
00068     
00069     public void run() 
00070     {
00071         stft.start();
00072     }
00073     
00074 
00078     public void newOnset(long nextOnset, int zeroFrames) 
00079     {
00080         if(!recording) 
00081         {
00082             // Start recording at this onset, don't do anything else
00083             lastOnset = nextOnset;
00084             recording = true;
00085         } 
00086         else if(nextOnset - lastOnset < minChunkLen) 
00087         {
00088             // Ignore onsets that come too close together
00089         } 
00090         else 
00091         {
00092             // Got new onset, make a chunk from the last onset to this one
00093             outFile.chunks.add(new FeatChunk(sourceFileName, 
00094                                          stft.fr2Seconds(lastOnset), 
00095                                          stft.fr2Seconds(nextOnset-lastOnset)));
00096             lastOnset = nextOnset;
00097         }    
00098     }
00099 
00104     public void newFrame(STFT ignored, long frAddr) 
00105     {
00106         progress.setValue(progress.getValue()+1);
00107 
00108         if(recording && frAddr - lastOnset > maxChunkLen) 
00109         {
00110             // Reached max length of chunk from last onset, make chunk
00111             recording = false;
00112             
00113             outFile.chunks.add(new FeatChunk(sourceFileName, 
00114                                          stft.fr2Seconds(lastOnset), 
00115                                          stft.fr2Seconds(maxChunkLen)));
00116         }
00117     }
00118 }

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