Main Page   Class Hierarchy   Compound List   File List   Compound Members  

SegmentExtractor.java

00001 /*
00002  *  Copyright 2006 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 
00036 public class SegmentExtractor implements FrameListener, Runnable, OnsetListener 
00037 {
00038     Vector consumers = new Vector();
00039     STFT stft;
00040     OnsetDetector onsDetect;
00041     long lastOnset = -1;
00042     int minChunkLen = 20;
00043     //int maxChunkLen = 85
00044     // no max length between onsets
00045     int maxChunkLen = Integer.MAX_VALUE; 
00046     
00047     // keep track of whether or not we have seen any onsets yet...
00048     boolean recording = false;
00049     
00050     FeatFile outFile;
00051     String sourceFileName;
00052     
00053     public SegmentExtractor(STFT stft, OnsetDetector od, String sfn, FeatFile of)
00054     {
00055         this.stft = stft;
00056         onsDetect = od;
00057         sourceFileName = sfn;
00058         outFile = of;
00059 
00060         //maxChunkLen = stft.getRows();
00061     }
00062     
00063     public void run() 
00064     {
00065         stft.start();
00066     }
00067     
00071     public void newOnset(long nextOnset, int zeroFrames) 
00072     {
00073         if(!recording) 
00074         {
00075             // Start recording at this onset, don't do anything else
00076             lastOnset = nextOnset;
00077             recording = true;
00078         } 
00079         else if(nextOnset - lastOnset < minChunkLen) 
00080         {
00081             // Ignore onsets that come too close together
00082         } 
00083         else 
00084         {
00085             // Got new onset, make a chunk from the last onset to this one
00086             outFile.chunks.add(new FeatChunk(sourceFileName, 
00087                                          stft.fr2Seconds(lastOnset), 
00088                                          stft.fr2Seconds(nextOnset-lastOnset)));
00089             lastOnset = nextOnset;
00090         }    
00091     }
00092 
00097     public void newFrame(STFT ignored, long frAddr) 
00098     {
00099         if(recording && frAddr - lastOnset > maxChunkLen) 
00100         {
00101             // Reached max length of chunk from last onset, make chunk
00102             recording = false;
00103             
00104             outFile.chunks.add(new FeatChunk(sourceFileName, 
00105                                          stft.fr2Seconds(lastOnset), 
00106                                          stft.fr2Seconds(maxChunkLen)));
00107         }
00108     }
00109 }

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