# set directory to the CD_Diss Folder
# Please change here the folder!
setwd("C:/Users/bauer/Desktop/CD_Diss/")


setwd("UnivariateOnsetDetection/Functions")


file.sources = list.files(pattern="*.R")
sapply(file.sources,source)

# load libraries
library(tuneR)
library(signal)



#####################################################################################################
### example Bello 93
# control object 1
ctrl = onsetDetectionControl(window.size=2048, hop.size=1024, window.fun="hann",
                           odf="AEnerg", thresh.time.left=0.2,
                           thresh.time.right=0.01, thresh.fun="quantile",
                           onset.time.left=0.03,onset.time.right=0.01,
                           onset.time.min.dist=0.05,
                           smooth.alpha=0.7)
						   
path.wav = "../bello93.wav"
path.time = "../bello93.txt"
O=onsetDetection(path.wav, path.time, ctrl) 
  

O$fMeasure	# 0.5846154
			
#plot(O$orig.odf,type="o")
#points(O$thresh.odf,type="o",col=4)
#abline(v=O$est.onset.frames,col=2)

####################################################################################################
# control object 2
ctrl = onsetDetectionControl(norm.amplit = TRUE, window.size=2048,hop.size=1024, window.fun="hann",
                           odf="SFlux", thresh.time.left=0.2,
						   spec.filter = "yes", spec.log = "yes",
                           thresh.time.right=0.01, thresh.fun="mean",
                           onset.time.left=0.03,onset.time.right=0.01,
                           onset.time.min.dist=0.05,
                           smooth.alpha=0.8)
						   

O=onsetDetection(path.wav, path.time, ctrl) # 0.872
O$fMeasure #0.9101284

