#!/bin/sh exec scala -cp ../../Tarsos/build/tarsos.jar -savecompiled "$0" "$@" !# import scala.collection.JavaConversions._ import be.hogent.tarsos.util._ import be.hogent.tarsos.util.histogram._ import be.hogent.tarsos.util.histogram.peaks._ import be.hogent.tarsos.sampled.pitch._ import be.hogent.tarsos.ui.pitch._ val makams = List("hicaz","huseyni","huzzam","kurdili_hicazar","nihavend","rast","saba","segah","ussak") val audio_pattern = Configuration.get(ConfKey.audio_file_name_pattern) //parse scala files, store KDE's in a hash map var theoreticKDEs = Map[java.lang.String,KernelDensityEstimate]() makams.foreach{ makam => val scalaFile = "/media/share/joren/datasets/Turkish_Makam/scala/" + makam + ".scl" val scalaObject = new ScalaFile(scalaFile); val kde = HistogramFactory.createPichClassKDE(scalaObject,35) kde.normalize theoreticKDEs = theoreticKDEs + (makam -> kde) } //print a confusion matrix Console.println("\n\nConfusion matrix\n\n") Console.println(";" + theoreticKDEs.toList.map{_._1}.mkString(";")) for ((thisMakam, thisKde) <- theoreticKDEs){ var resultList = List[Double]() for ((otherMakam, otherKde) <- theoreticKDEs){ val shift = thisKde.shiftForOptimalCorrelation(otherKde) val correlation = thisKde.correlation(otherKde,shift) resultList = correlation :: resultList } resultList = resultList.reverse Console.println(thisMakam + ";" + resultList.mkString(";")) } //print an sorted result (guess, correlation) for each file Console.println("\n\nResults\n\n") Console.println("Index;Answer; " + theoreticKDEs.toList.map{ r => "Guess;Correlation"}.mkString(";") + ";First;In first two; In first three" ) var index = 0; makams.foreach{ makam => val directory = "/media/share/joren/datasets/Turkish_Makam/" + makam val audioFiles = FileUtils.glob(directory,audio_pattern,true).toList audioFiles.foreach{ file => val audioFile = new AudioFile(file) val detectorYin = PitchDetectionMode.TARSOS_YIN.getPitchDetector(audioFile) val annotations = detectorYin.executePitchDetection() //only large files if(annotations.size > 3000) { val actualKDE = HistogramFactory.createPichClassKDE(annotations,15); val plotter = new SimplePlot() actualKDE.normalize plotter.addData(0,actualKDE) var resultList = List[Tuple2[java.lang.String,Double]]() for ((name, theoreticKDE) <- theoreticKDEs){ val shift = actualKDE.shiftForOptimalCorrelation(theoreticKDE) val currentCorrelation = actualKDE.correlation(theoreticKDE,shift) resultList = (name -> currentCorrelation) :: resultList } //order by correlation resultList = resultList.sortBy{_._2}.reverse val isFirst = if(resultList(0)._1 == makam) "1" else "0" val isInFirstTwo = if(resultList(0)._1 == makam || resultList(1)._1 == makam) "1" else "0" val isInFirstThree = if(resultList(0)._1 == makam || resultList(1)._1 == makam || resultList(2)._1 == makam) "1" else "0" index = index + 1 Console.println(index + ";" + makam + ";" + resultList.map{e => e._1 + ";" + e._2}.mkString(";") + ";" + isFirst + ";" + isInFirstTwo + ";" + isInFirstThree) } } }