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;
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
00047
00048 int maxChunkLen = Integer.MAX_VALUE;
00049
00050
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
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
00083 lastOnset = nextOnset;
00084 recording = true;
00085 }
00086 else if(nextOnset - lastOnset < minChunkLen)
00087 {
00088
00089 }
00090 else
00091 {
00092
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
00111 recording = false;
00112
00113 outFile.chunks.add(new FeatChunk(sourceFileName,
00114 stft.fr2Seconds(lastOnset),
00115 stft.fr2Seconds(maxChunkLen)));
00116 }
00117 }
00118 }