Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

SpectralStability.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.featextractors;
00024 
00025 import com.meapsoft.STFT;
00026 
00033 public class SpectralStability extends FeatureExtractor 
00034 {
00035         public double[] features(STFT stft, long startFrame, int length) 
00036         {
00037                 int numBands = stft.getRows();
00038                 double[] currFrame;
00039                 double[] prevFrame = null;
00040                 double lastEnergy = 0.0;
00041                 double[] deltaSum = {0.0};
00042 
00043                 //we'll sum the deltas in each bin from frame to frame
00044                 //we'll return that total delta, maybe it'll act as an
00045                 //indicator of the stability of the chunk...
00046                 
00047                 for (int frame = 0; frame < length; frame++)
00048                 {               
00049                         currFrame = stft.getFrame(startFrame+frame);
00050                         
00051                         for (int bin = 0; bin < numBands; bin++)
00052                         {
00053                                 double delta = 0.0;
00054                                 //skip first frame!
00055                                 if (prevFrame != null)
00056                                          delta = Math.abs(prevFrame[bin] - currFrame[bin]);
00057                                 
00058                                 //if (bin == 5 && prevFrame != null)
00059                                         //System.out.println("delta: " + delta);
00060                                 
00061                                 //this is a threshold of some sort...
00062                                 if (delta < 5.0)
00063                                         delta = 0.0;
00064                                         
00065                                 deltaSum[0] += delta;
00066                         }
00067                         
00068                         prevFrame = currFrame;
00069                 }
00070                 
00071                 //normalize for frame length
00072                 deltaSum[0] /= length;
00073                 
00074                 return deltaSum;
00075         }
00076   
00077         public String description()
00078         {
00079                 return "Tracks the stability of the spectral energy within each chunk of sound. " 
00080             + "More spectrally stable chunks are more likely to be pitched material.";
00081         }
00082 }

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