Main Page   Class Hierarchy   Compound List   File List   Compound Members  

AvgChromaScalar.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.featextractors;
00024 
00025 import com.meapsoft.MEAPUtil;
00026 import com.meapsoft.STFT;
00027 
00038 public class AvgChromaScalar extends AvgChroma {
00039 
00040         public static String description = "I am a generic FeatureExtractor";
00041 
00042   // Default constructor 
00043   public AvgChromaScalar() {
00044       //this(129, 12, 44100.0);
00045       //this(MEAPUtil.frameSize/2+1, 12, MEAPUtil.samplingRate);
00046       this(1025, 12, MEAPUtil.samplingRate);
00047   }
00048 
00049   public AvgChromaScalar(int N, int outDim, double sampleRate) {
00050       super(N, outDim, sampleRate);
00051   }
00052 
00053 
00054   public double[] features(STFT stft, long startFrame, int length) {
00055     double[] chromaVal = new double[1];
00056     
00057     double [] chromSpec;
00058 
00059     chromSpec = super.features(stft, startFrame, length);
00060 
00061     // calculate complex average chroma
00062     double re = 0, im = 0;
00063     for (int bin = 0; bin < outDim; ++bin) {
00064         re = re + chromSpec[bin] * Math.cos(6.28318531*bin/outDim);
00065         im = im + chromSpec[bin] * Math.sin(6.28318531*bin/outDim);
00066     }
00067 
00068     double meanchrom = outDim * (Math.atan2(im, re) / 6.28318531);   
00069     // atan2 returns -pi..pi
00070     // fold back to +ve octave
00071     if (meanchrom < 0) 
00072         meanchrom += outDim;
00073 
00074     chromaVal[0] = meanchrom;
00075 
00076     return chromaVal;
00077   }
00078 }

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