be.hogent.tarsos.util
Class SignalPowerExtractor

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

public final class SignalPowerExtractor
extends java.lang.Object

An utility class to calculate and access the power of an audio file at any given time.

Author:
Joren Six

Nested Class Summary
static interface SignalPowerExtractor.WaveFormDataAggregator
           
 
Constructor Summary
SignalPowerExtractor(AudioFile file)
          Create a new power extractor.
 
Method Summary
static boolean isSilence(float[] buffer)
           
static boolean isSilence(float[] buffer, double silenceThreshold)
          Checks if the dBSPL level in the buffer falls below a certain threshold.
static double localEnergy(float[] buffer)
          Calculates the local (linear) energy of an audio buffer.
 double powerAt(double seconds, boolean relative)
          Returns the relative power [0.0;1.0] at the given time.
 void savePowerPlot(java.lang.String powerPlotFileName, double silenceThreshold)
          Creates a 'power plot' of the signal.
 void saveTextFile(java.lang.String textFileName, boolean relative)
          Creates a text file with relative power values for each sample.
static double soundPressureLevel(float[] buffer)
          Returns the dBSPL for a buffer.
 void waveFormPlot(SignalPowerExtractor.WaveFormDataAggregator aggregator)
          Creates a wave from plot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SignalPowerExtractor

public SignalPowerExtractor(AudioFile file)
Create a new power extractor.

Parameters:
file - The audio file to extract power from.
Method Detail

powerAt

public double powerAt(double seconds,
                      boolean relative)
Returns the relative power [0.0;1.0] at the given time.

Parameters:
seconds - The time to get the relative power for.
relative -
Returns:
A number between 0 and 1 inclusive that shows the relative power at the given time
Throws:
java.lang.IndexOutOfBoundsException - when the number of seconds is not between the start and end of the song.

waveFormPlot

public void waveFormPlot(SignalPowerExtractor.WaveFormDataAggregator aggregator)
Creates a wave from plot.

Parameters:
aggregator - The aggregator to save to.

saveTextFile

public void saveTextFile(java.lang.String textFileName,
                         boolean relative)
Creates a text file with relative power values for each sample.

Parameters:
textFileName - Where to save the text file?
relative - Compare the current power with the max extracted power, or not?

savePowerPlot

public void savePowerPlot(java.lang.String powerPlotFileName,
                          double silenceThreshold)
Creates a 'power plot' of the signal.

Parameters:
powerPlotFileName - Where to save the plot.
silenceThreshold - Draw a line at this threshold. Can be used to show where the signal is 'silent'.

localEnergy

public static double localEnergy(float[] buffer)
Calculates the local (linear) energy of an audio buffer.

Parameters:
buffer - The audio buffer.
Returns:
The local (linear) energy of an audio buffer.

soundPressureLevel

public static double soundPressureLevel(float[] buffer)
Returns the dBSPL for a buffer.

Parameters:
buffer - The buffer with audio information.
Returns:
The dBSPL level for the buffer.

isSilence

public static boolean isSilence(float[] buffer,
                                double silenceThreshold)
Checks if the dBSPL level in the buffer falls below a certain threshold.

Parameters:
buffer - The buffer with audio information.
silenceThreshold - The threshold in dBSPL
Returns:
True if the audio information in buffer corresponds with silence, false otherwise.

isSilence

public static boolean isSilence(float[] buffer)