be.hogent.tarsos.util
Class AudioFile

java.lang.Object
  extended by be.hogent.tarsos.util.AudioFile

public final class AudioFile
extends java.lang.Object

Represents an audio file. Facilitates transcoding, handling of originalPath names and data sets.

Author:
Joren Six

Constructor Summary
AudioFile(java.lang.String filePath)
          Create and transcode an audio file.
 
Method Summary
static java.util.List<AudioFile> audioFiles(java.lang.String... folders)
          Returns a list of AudioFiles included in one or more folders.
 javax.sound.sampled.AudioFileFormat fileFormat()
           
 double getLengthIn(TimeUnit unit)
           
 long getLengthInMilliSeconds()
          Determines the length of the transcoded file (only audio data) in microseconds.
 double getMicrosecondsPositionOfFrame(long frame)
           
 long getSizeInBytes()
          Determines the size of the transcoded audio data in bytes.
 java.lang.String originalBasename()
           
 java.lang.String originalPath()
           
 void playCents(PitchDetectionMode detectionMode, double from, double to, PitchUnit unit)
          Detects pitch and plays plays the samples that are in the interval from, to in the given pitch unit.
 void playSelection(double from, double to)
           
 void playSelections(double[] selections)
          Play selections of the audio file.
 java.lang.String toString()
           
 java.lang.String transcodedBasename()
           
 java.lang.String transcodedDirectory()
           
 java.lang.String transcodedPath()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AudioFile

public AudioFile(java.lang.String filePath)
          throws be.hogent.tarsos.transcoder.ffmpeg.EncoderException
Create and transcode an audio file.

Parameters:
filePath - the originalPath for the audio file
Throws:
be.hogent.tarsos.transcoder.ffmpeg.EncoderException - If FFMPEG fails to transcode the audio an UnsupportedAudioFileException is generated.
Method Detail

transcodedPath

public java.lang.String transcodedPath()
Returns:
the path of the transcoded audio file.

transcodedDirectory

public java.lang.String transcodedDirectory()
Returns:
the directory where the transcoded audio file resides.

originalPath

public java.lang.String originalPath()
Returns:
the path of the original file

toString

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

originalBasename

public java.lang.String originalBasename()
Returns:
the name of the file (without extension)

transcodedBasename

public java.lang.String transcodedBasename()
Returns:
the name of the file (without extension)

audioFiles

public static java.util.List<AudioFile> audioFiles(java.lang.String... folders)
Returns a list of AudioFiles included in one or more folders. Searches recursively.

Parameters:
folders - The fo
Returns:
a list of AudioFiles

getLengthInMilliSeconds

public long getLengthInMilliSeconds()
Determines the length of the transcoded file (only audio data) in microseconds.

Returns:
The length of the file in microseconds. If the length could not be determined -1 is returned.

getLengthIn

public double getLengthIn(TimeUnit unit)

getMicrosecondsPositionOfFrame

public double getMicrosecondsPositionOfFrame(long frame)

getSizeInBytes

public long getSizeInBytes()
Determines the size of the transcoded audio data in bytes.

Returns:
The size of the audio data in bytes. If the length could not be determined -1 is returned.

fileFormat

public javax.sound.sampled.AudioFileFormat fileFormat()
Returns:
The file format info of the transcoded audio data.

playSelection

public void playSelection(double from,
                          double to)

playSelections

public void playSelections(double[] selections)
Play selections of the audio file.

Parameters:
selections - An interleaved array with in the form [from,to,from,to,from,to...]. The from and to values are given in seconds.

playCents

public void playCents(PitchDetectionMode detectionMode,
                      double from,
                      double to,
                      PitchUnit unit)
Detects pitch and plays plays the samples that are in the interval from, to in the given pitch unit. E.g. when you want to hear all the b's in a western piece you could select TARSOS_YIN as detection mode, form and to would be [190-210] and the unit would be relative cents.

Parameters:
detectionMode - The detection mode.
from - Interval start.
to - Interval stop.
unit - The pitch unit.