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.featextractors;
00024
00025 import com.meapsoft.MEAPUtil;
00026 import com.meapsoft.STFT;
00027
00038 public class AvgChromaScalar extends AvgChroma {
00039
00040
00041 public AvgChromaScalar() {
00042 super();
00043 }
00044
00045 public AvgChromaScalar(int N, int outDim, double sampleRate) {
00046 super(N, outDim, sampleRate);
00047 }
00048
00049
00050 public double[] features(STFT stft, long startFrame, int length) {
00051 double[] chromaVal = new double[1];
00052
00053 double [] chromSpec;
00054
00055 chromSpec = super.features(stft, startFrame, length);
00056
00057
00058 double re = 0, im = 0;
00059 for (int bin = 0; bin < outDim; ++bin) {
00060 re = re + chromSpec[bin] * Math.cos(6.28318531*bin/outDim);
00061 im = im + chromSpec[bin] * Math.sin(6.28318531*bin/outDim);
00062 }
00063
00064 double meanchrom = outDim * (Math.atan2(im, re) / 6.28318531);
00065
00066
00067 if (meanchrom < 0)
00068 meanchrom += outDim;
00069
00070 chromaVal[0] = meanchrom;
00071
00072 return chromaVal;
00073 }
00074
00075 public String description()
00076 {
00077 return "Single value giving dominant semitone within the octave.";
00078 }
00079 }