be.hogent.tarsos.dsp
Class ConstantQ

java.lang.Object
  extended by be.hogent.tarsos.dsp.ConstantQ
All Implemented Interfaces:
AudioProcessor

public class ConstantQ
extends java.lang.Object
implements AudioProcessor

Implementation of the Constant Q Transform.
References:

Judith C. Brown, Calculation of a constant Q spectral transform, J. Acoust. Soc. Am., 89(1): 425-434, 1991.

Judith C. Brown and Miller S. Puckette, An efficient algorithm for the calculation of a constant Q transform, J. Acoust. Soc. Am., Vol. 92, No. 5, November 1992

Benjamin Blankertz, The Constant Q Transform

Author:
Joren Six, Karl Helgason, P.J Leonard

Constructor Summary
ConstantQ(float sampleRate, float minFreq, float maxFreq, float binsPerOctave)
           
ConstantQ(float sampleRate, float minFreq, float maxFreq, float binsPerOctave, float threshold, float spread)
           
 
Method Summary
 void calculate(float[] inputBuffer)
          Take an input buffer with audio and calculate the constant Q coefficients.
 void calculateMagintudes(float[] inputBuffer)
          Take an input buffer with audio and calculate the constant Q magnitudes.
 float[] getCoefficients()
          Return the Constant Q coefficients calculated for the previous audio buffer.
 int getFFTlength()
           
 float[] getFreqencies()
           
 float[] getMagnitudes()
          Returns the Constant Q magnitudes calculated for the previous audio buffer.
 int getNumberOfOutputBands()
           
 boolean process(AudioEvent audioEvent)
          Process the audio event.
 void processingFinished()
          Notify the AudioProcessor that no more data is available and processing has finished.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConstantQ

public ConstantQ(float sampleRate,
                 float minFreq,
                 float maxFreq,
                 float binsPerOctave)

ConstantQ

public ConstantQ(float sampleRate,
                 float minFreq,
                 float maxFreq,
                 float binsPerOctave,
                 float threshold,
                 float spread)
Method Detail

calculate

public void calculate(float[] inputBuffer)
Take an input buffer with audio and calculate the constant Q coefficients.

Parameters:
inputBuffer - The input buffer with audio.

calculateMagintudes

public void calculateMagintudes(float[] inputBuffer)
Take an input buffer with audio and calculate the constant Q magnitudes.

Parameters:
inputBuffer - The input buffer with audio.

process

public boolean process(AudioEvent audioEvent)
Description copied from interface: AudioProcessor
Process the audio event. Do the actual signal processing on an (optionally) overlapping buffer.

Specified by:
process in interface AudioProcessor
Parameters:
audioEvent - The audio event that contains audio data.
Returns:
False if the chain needs to stop here, true otherwise. This can be used to implement e.g. a silence detector.

processingFinished

public void processingFinished()
Description copied from interface: AudioProcessor
Notify the AudioProcessor that no more data is available and processing has finished. Can be used to deallocate resources or cleanup.

Specified by:
processingFinished in interface AudioProcessor

getFreqencies

public float[] getFreqencies()
Returns:
The list of starting frequencies for each band. In Hertz.

getMagnitudes

public float[] getMagnitudes()
Returns the Constant Q magnitudes calculated for the previous audio buffer. Beware: the array is reused for performance reasons. If your need to cache your results, please copy the array.

Returns:
The output buffer with constant q magnitudes. If you for example are interested in coefficients between 256 and 1024 Hz (2^8 and 2^10 Hz) and you requested 12 bins per octave, you will need 12 bins/octave * 2 octaves = 24 places in the output buffer.

getCoefficients

public float[] getCoefficients()
Return the Constant Q coefficients calculated for the previous audio buffer. Beware: the array is reused for performance reasons. If your need to cache your results, please copy the array.

Returns:
The array with constant q coefficients. If you for example are interested in coefficients between 256 and 1024 Hz (2^8 and 2^10 Hz) and you requested 12 bins per octave, you will need 12 bins/octave * 2 octaves * 2 entries/bin = 48 places in the output buffer. The coefficient needs two entries in the output buffer since they are complex numbers.

getNumberOfOutputBands

public int getNumberOfOutputBands()
Returns:
The number of coefficients, output bands.

getFFTlength

public int getFFTlength()
Returns:
The required length the FFT.