# The function computeOnsetsClassif computes for each frame 0 or 1. 1 corresponds to a tone onset

# INPUT: 	n.onset.left: number of windows in the past for computing the lokal maximum
#			n.onset.right: number of windows in the future for computing the lokal maximum
#			onset.min.dist: minimal distance between two onset frames
#			prob.1: probablility for a tone onset (acording to the predistion of the model)
#			classif.threshold: classification threshold

# OUTPUT:	onset: (0,1)- vector. 1 corresponds to a tone onset in the respective frame

computeOnsetsClassif = function(n.onset.left, n.onset.right, onset.min.dist, prob.1,  classif.threshold){  
  n=length(prob.1)
  onsets=numeric(length(prob.1))
  last.onset=-1000
  
  
  for (i in 1:n){
    index=intersect(seq((i-n.onset.left),(i+ n.onset.right),1),1:n)
    if( ( prob.1[i] >= classif.threshold ) & ( prob.1[i] == max(prob.1[index])) 
        & ((i-last.onset) > onset.min.dist))  {
      onsets[i]=1 
      last.onset=i
    }
  }
  return(onsets)
}
