be.hogent.tarsos.sampled.pitch
Class Annotation

java.lang.Object
  extended by be.hogent.tarsos.sampled.pitch.Annotation
All Implemented Interfaces:
java.lang.Comparable<Annotation>

public final class Annotation
extends java.lang.Object
implements java.lang.Comparable<Annotation>

An annotation has one time stamp, one pitch and an optional probability. Also the source of the annotation needs to be defined.

Author:
Joren Six

Constructor Summary
Annotation(double timeStamp, double pitchInHz, PitchDetectionMode annotationSource)
          Create a new annotation with the given data.
Annotation(double timeStamp, double pitchInHz, PitchDetectionMode annotationSource, double salience)
          Create a new annotation with the given data.
 
Method Summary
 int compareTo(Annotation o)
           
 boolean equals(java.lang.Object o)
           
 double getPitch(PitchUnit unit)
          Return the pitch in the requested unit.
 double getProbability()
          The probability for the annotation.
 PitchDetectionMode getSource()
           
 double getStart()
          Returns the starting time in seconds.
 int hashCode()
           
static Annotation parse(java.lang.String line)
          Parses an annotation as written by the toString() method.
static double percentAnnotated(java.util.List<Annotation> annotations, double audioLenght)
          Calculates a maximum possible number of annotations and compares it with the actual number of annotations.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Annotation

public Annotation(double timeStamp,
                  double pitchInHz,
                  PitchDetectionMode annotationSource,
                  double salience)
Create a new annotation with the given data.

Parameters:
timeStamp - The starting time (in seconds).
pitchInHz - The pitch in Hz.
annotationSource - The source of the annotation.
salience - A probability between zero and one (inclusive) defining the saliance of the pitch.

Annotation

public Annotation(double timeStamp,
                  double pitchInHz,
                  PitchDetectionMode annotationSource)
Create a new annotation with the given data. The default salience of 1.0 is used.

Parameters:
timeStamp - The starting time (in seconds).
pitchInHz - The pitch in Hz.
annotationSource - The source of the annotation.
Method Detail

getStart

public double getStart()
Returns the starting time in seconds.

Returns:
The starting time of the sample (in seconds).

getSource

public PitchDetectionMode getSource()

getProbability

public double getProbability()
The probability for the annotation. If the algorithm does not define a probability the default is 1.0.

Returns:
The probability or salience for the annotation (a value between 0 and 1).

getPitch

public double getPitch(PitchUnit unit)
Return the pitch in the requested unit. The conversion is cached automatically.

Parameters:
unit - The unit requested.
Returns:
The converted value.

compareTo

public int compareTo(Annotation o)
Specified by:
compareTo in interface java.lang.Comparable<Annotation>

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

parse

public static Annotation parse(java.lang.String line)
Parses an annotation as written by the toString() method.

Parameters:
line - The line to parse.
Returns:
A new annotation.

percentAnnotated

public static double percentAnnotated(java.util.List<Annotation> annotations,
                                      double audioLenght)
Calculates a maximum possible number of annotations and compares it with the actual number of annotations. The result is an indication how much of the audio is annotated and therefore possibly how 'pitched' the original audio is (or how easily it can be annotated using the chosen algorithm). E.g. ten actual annotations from YIN at a sample rate of 100HZ with an audio file of two seconds gives 10 /(2s x 100Hz) = 5%

Parameters:
annotations - A list of annotations for an audio file.
audioLenght - The length of the annotated audio.
Returns:
A percentage indicating how much of the audio is annotated