jAudioFeatureExtractor.jAudioTools
Class DSPMethods

java.lang.Object
  extended by jAudioFeatureExtractor.jAudioTools.DSPMethods

public class DSPMethods
extends java.lang.Object

A holder class for general static methods relating to processing signals in the form of samples stored as arrays of doubles.

Author:
Cory McKay

Constructor Summary
DSPMethods()
           
 
Method Summary
static double[][] applyGain(double[][] samples, double gain)
          Applies a gain to the given samples.
static double convertSampleToTime(int sample, float sampling_rate)
          Returns the time corresponding to the given sample indice with the given sampling rate.
static int convertTimeToSample(double time, float sampling_rate)
          Returns the sample corresponding to the given time with the given sampling rate.
static double[] getAutoCorrelation(double[] signal, int min_lag, int max_lag)
          Calculates the auto-correlation of the given signal.
static double[] getAutoCorrelationLabels(double sampling_rate, int min_lag, int max_lag)
          Returns the bin labels for each bin of an auto-correlation calculation that involved the given paremeters (most likely using the getAutoCorrelation method).
static double[][] getCopyOfSamples(double[][] original_samples)
          Returns a copy of the given array of samples.
static double[] getSamplesMixedDownIntoOneChannel(double[][] audio_samples)
          Returns the given set of samples as a set of samples mixed down into one channel.
static double[] normalizeSamples(double[] samples_to_normalize)
          Normalizes the given samples so that the absolute value of the highest sample amplitude is 1.
static double[][] normalizeSamples(double[][] samples_to_normalize)
          Normalizes the given samples dependantly so that the absolute value of the highest sample amplitude is 1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DSPMethods

public DSPMethods()
Method Detail

applyGain

public static double[][] applyGain(double[][] samples,
                                   double gain)
Applies a gain to the given samples. Note that a negative gain effectively applies a phase shift of pi. There is no guarantee that the returned samples will be between -1 and +1. The returned samples are copies, so changes to them will not affect the original samples.

Parameters:
samples - Audio samles to modify, usually with a minimum value of -1 and a maximum value of +1. The first indice corresponds to the channel and the second indice corresponds to the sample number.
gain - The gain to apply.
Returns:
The given audio samples after the application of the given gain.

getSamplesMixedDownIntoOneChannel

public static double[] getSamplesMixedDownIntoOneChannel(double[][] audio_samples)
Returns the given set of samples as a set of samples mixed down into one channel.

Parameters:
audio_samples - Audio samles to modify, with a minimum value of -1 and a maximum value of +1. The first indice corresponds to the channel and the second indice corresponds to the sample number.
Returns:
The given audio samples mixed down, with equal gain, into one channel.

normalizeSamples

public static double[] normalizeSamples(double[] samples_to_normalize)
Normalizes the given samples so that the absolute value of the highest sample amplitude is 1. Does nothing if also samples are 0.

Parameters:
samples_to_normalize - The samples to normalize.
Returns:
Returns a copy of the given samples after normalization.

normalizeSamples

public static double[][] normalizeSamples(double[][] samples_to_normalize)
Normalizes the given samples dependantly so that the absolute value of the highest sample amplitude is 1. Does nothing if all samples are 0.

Parameters:
samples_to_normalize - The samples to normalize. The first indice denotes channel and the second denotes sample number.
Returns:
Returns a copy of the given samples after normalization.

getCopyOfSamples

public static double[][] getCopyOfSamples(double[][] original_samples)
Returns a copy of the given array of samples.

Parameters:
original_samples - Audio samles to modify, usually with a minimum value of value of- 1 and a maximum value of +1. The first indice corresponds to the channel and the second indice corresponds to the sample number.
Returns:
A copy of the original_samples parameter.

convertTimeToSample

public static int convertTimeToSample(double time,
                                      float sampling_rate)
Returns the sample corresponding to the given time with the given sampling rate.

Parameters:
time - The time in seconds to convert to a sample indice.
sampling_rate - The sampling rate of the audio in question.
Returns:
The corresponding sample indice.

convertSampleToTime

public static double convertSampleToTime(int sample,
                                         float sampling_rate)
Returns the time corresponding to the given sample indice with the given sampling rate.

Parameters:
sample - The sample indice to convert to time.
sampling_rate - The sampling rate of the audio in question.
Returns:
The corresponding time in seconds.

getAutoCorrelation

public static double[] getAutoCorrelation(double[] signal,
                                          int min_lag,
                                          int max_lag)
Calculates the auto-correlation of the given signal. The auto-correlation is only calculated between the given lags.

The getAutoCorrelationLabels method can be called to find the labels in Hz for each of the returned bins.

Parameters:
signal - The digital signal to auto-correlate.
min_lag - The minimum lag in samples to look for in the auto-correlation.
max_lag - The maximum lag in samples to look for in the auto-correaltion.
Returns:
The auto-correlation for each lag from min_lag to max_lag. Entry 0 corresponds to min_lag, and the last entry corresponds to max_lag.

getAutoCorrelationLabels

public static double[] getAutoCorrelationLabels(double sampling_rate,
                                                int min_lag,
                                                int max_lag)
Returns the bin labels for each bin of an auto-correlation calculation that involved the given paremeters (most likely using the getAutoCorrelation method).

Parameters:
sampling_rate - The sampling rate that was used to encode the signal that was auto-correlated.
min_lag - The minimum lag in samples that was used in the auto-correlation.
max_lag - The maximum lag in samples that was used in the auto-correlation.
Returns:
The labels, in Hz, for the corresponding bins produced by the getAutoCorrelation method.