org.hermit.android.instruments
Class AudioAnalyser

java.lang.Object
  extended by org.hermit.android.instruments.Instrument
      extended by org.hermit.android.instruments.AudioAnalyser

public class AudioAnalyser
extends Instrument

An Instrument which analyses an audio stream in various ways.

To use this class, your application must have permission RECORD_AUDIO.


Constructor Summary
AudioAnalyser(SurfaceRunner parent)
          Create a WindMeter instance.
 
Method Summary
 void appStart()
          The application is starting.
 void appStop()
          The application is closing down.
 void doUpdate(long now)
          Update the state of the instrument for the current frame.
 PowerGauge getPowerGauge(SurfaceRunner surface)
          Get a signal power gauge for this audio analyser.
 SpectrumGauge getSpectrumGauge(SurfaceRunner surface)
          Get a spectrum analyser gauge for this audio analyser.
 WaveformGauge getWaveformGauge(SurfaceRunner surface)
          Get a waveform gauge for this audio analyser.
 void measureStart()
          We are starting the main run; start measurements.
 void measureStop()
          We are stopping / pausing the run; stop measurements.
protected  void restoreState(Bundle icicle)
          Restore the game state from the given Bundle.
protected  void saveState(Bundle icicle)
          Save the state of the game in the provided Bundle.
 void setAverageLen(int len)
          Set the histogram averaging window for this instrument.
 void setBlockSize(int size)
          Set the input block size for this instrument.
 void setDecimation(int rate)
          Set the decimation rate for this instrument.
 void setSampleRate(int rate)
          Set the sample rate for this instrument.
 void setWindowFunc(org.hermit.dsp.Window.Function func)
          Set the spectrum analyser windowing function for this instrument.
 
Methods inherited from class org.hermit.android.instruments.Instrument
getSurface
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AudioAnalyser

public AudioAnalyser(SurfaceRunner parent)
Create a WindMeter instance.

Parameters:
parent - Parent surface.
Method Detail

setSampleRate

public void setSampleRate(int rate)
Set the sample rate for this instrument.

Parameters:
rate - The desired rate, in samples/sec.

setBlockSize

public void setBlockSize(int size)
Set the input block size for this instrument.

Parameters:
size - The desired block size, in samples. Typical values would be 256, 512, or 1024. Larger block sizes will mean more work to analyse the spectrum.

setWindowFunc

public void setWindowFunc(org.hermit.dsp.Window.Function func)
Set the spectrum analyser windowing function for this instrument.

Parameters:
func - The desired windowing function. Window.Function.BLACKMAN_HARRIS is a good option. Window.Function.RECTANGULAR turns off windowing.

setDecimation

public void setDecimation(int rate)
Set the decimation rate for this instrument.

Parameters:
rate - The desired decimation. Only 1 in rate blocks will actually be processed.

setAverageLen

public void setAverageLen(int len)
Set the histogram averaging window for this instrument.

Parameters:
len - The averaging interval. 1 means no averaging.

appStart

public void appStart()
The application is starting. Perform any initial set-up prior to starting the application. We may not have a screen size yet, so this is not a good place to allocate resources which depend on that.

Overrides:
appStart in class Instrument

measureStart

public void measureStart()
We are starting the main run; start measurements.

Overrides:
measureStart in class Instrument

measureStop

public void measureStop()
We are stopping / pausing the run; stop measurements.

Overrides:
measureStop in class Instrument

appStop

public void appStop()
The application is closing down. Clean up any resources.

Overrides:
appStop in class Instrument

getWaveformGauge

public WaveformGauge getWaveformGauge(SurfaceRunner surface)
Get a waveform gauge for this audio analyser.

Parameters:
surface - The surface in which the gauge will be displayed.
Returns:
A gauge which will display the audio waveform.

getSpectrumGauge

public SpectrumGauge getSpectrumGauge(SurfaceRunner surface)
Get a spectrum analyser gauge for this audio analyser.

Parameters:
surface - The surface in which the gauge will be displayed.
Returns:
A gauge which will display the audio waveform.

getPowerGauge

public PowerGauge getPowerGauge(SurfaceRunner surface)
Get a signal power gauge for this audio analyser.

Parameters:
surface - The surface in which the gauge will be displayed.
Returns:
A gauge which will display the signal power in a dB meter.

doUpdate

public final void doUpdate(long now)
Update the state of the instrument for the current frame. This method must be invoked from the doUpdate() method of the application's SurfaceRunner.

Since this is called frequently, we first check whether new audio data has actually arrived.

Overrides:
doUpdate in class Instrument
Parameters:
now - Nominal time of the current frame in ms.

saveState

protected void saveState(Bundle icicle)
Save the state of the game in the provided Bundle.

Overrides:
saveState in class Instrument
Parameters:
icicle - The Bundle in which we should save our state.

restoreState

protected void restoreState(Bundle icicle)
Restore the game state from the given Bundle.

Overrides:
restoreState in class Instrument
Parameters:
icicle - The Bundle containing the saved state.