protected float[] getAveragePCPData(SpectrumImpl spectrum) { PCP pcp1 = CoreElementsInitializer.initializePCPWithExecParamsData( PCP.BASIC_ALG, Configuration.REFERENCE_FREQUENCY, _initialExecParameters); if (spectrum instanceof ReassignedSpectrum) { pcp1.initReassignedSpectrum((ReassignedSpectrum) spectrum); } else { pcp1.initSpectrum(spectrum); } float[][] pcpUnwrapped = pcp1.getPCPUnwrapped(); return HelperArrays.average(pcpUnwrapped, 0, pcpUnwrapped.length); }
@Override public void operate() { File[] fileList = (new File(workingDir)).listFiles(new ExtensionFileFilter(Extensions.WAV_EXT)); float[] ratios1 = new float[fileList.length]; float[] cosines1 = new float[fileList.length]; float[] ratios2 = new float[fileList.length]; float[] cosines2 = new float[fileList.length]; float[] ratios3 = new float[fileList.length]; float[] cosines3 = new float[fileList.length]; int counter = 0; for (File aFile : fileList) { System.out.println(String.format("Processing file %s", aFile.getName())); AudioReader reader = new AudioReader(aFile.getPath(), _initialExecParameters.samplingRate); SpectrumImpl spectrum1 = CoreElementsInitializer.initializeSpectrumWithExecParamsData( SpectrogramType.FFT_BASED, reader.getSamples(), reader.getSampleRate(), _initialExecParameters); ReassignedSpectrum spectrum2 = (ReassignedSpectrum) CoreElementsInitializer.initializeSpectrumWithExecParamsData( SpectrogramType.STANDARD, reader.getSamples(), reader.getSampleRate(), _initialExecParameters); ReassignedSpectrum spectrum3 = (ReassignedSpectrum) CoreElementsInitializer.initializeSpectrumWithExecParamsData( SpectrogramType.HARMONIC, reader.getSamples(), reader.getSampleRate(), _initialExecParameters); float[] pcp1 = getPCPPart(getAveragePCPData(spectrum1)); float[] pcp2 = getPCPPart(getAveragePCPData(spectrum2)); float[] pcp3 = getPCPPart(getAveragePCPData(spectrum3)); float[] template = createTemplate(); float[] templateCosine = createTemplateCosineMeasure(); ratios1[counter] = getRatio(pcp1, template); ratios2[counter] = getRatio(pcp2, template); ratios3[counter] = getRatio(pcp3, template); cosines1[counter] = getCosineMeasure(pcp1, templateCosine); cosines2[counter] = getCosineMeasure(pcp2, templateCosine); cosines3[counter] = getCosineMeasure(pcp3, templateCosine); counter++; } float ratio1Mean = HelperArrays.calculateMean(ratios1); float ratio2Mean = HelperArrays.calculateMean(ratios2); float ratio3Mean = HelperArrays.calculateMean(ratios3); float cosine1Mean = HelperArrays.calculateMean(cosines1); float cosine2Mean = HelperArrays.calculateMean(cosines2); float cosine3Mean = HelperArrays.calculateMean(cosines3); System.out.println("ratio1 mean " + ratio1Mean); System.out.println("ratio2 mean " + ratio2Mean); System.out.println("ratio3 mean " + ratio3Mean); System.out.println("cosine1 mean " + cosine1Mean); System.out.println("cosine2 mean " + cosine2Mean); System.out.println("cosine3 mean " + cosine3Mean); System.out.println(ratio1Mean); System.out.println(ratio2Mean); System.out.println(ratio3Mean); System.out.println(cosine1Mean); System.out.println(cosine2Mean); System.out.println(cosine3Mean); }