public class

OpenSLVisualizer

extends Object
implements IVisualizer
java.lang.Object
   ↳ com.h6ah4i.android.media.opensl.audiofx.OpenSLVisualizer

Summary

[Expand]
Inherited Constants
From interface com.h6ah4i.android.media.audiofx.IVisualizer
Public Constructors
OpenSLVisualizer(OpenSLMediaPlayerContext context)
Public Methods
int getCaptureSize()
Returns current capture size.
int[] getCaptureSizeRange()
Returns the capture size range.
boolean getEnabled()
Get current activation state of the visualizer.
int getFft(byte[] fft)
Returns a frequency capture of currently playing audio content.
int getMaxCaptureRate()
Returns the maximum capture rate for the callback capture method.
int getMeasurementMode()
Returns the current measurement modes performed by this audio effect
int getMeasurementPeakRms(IVisualizer.MeasurementPeakRms measurement)
Retrieves the latest peak and RMS measurement.
int getSamplingRate()
Returns the sampling rate of the captured audio.
int getScalingMode()
Returns the current scaling mode on the captured visualization data.
int getWaveForm(byte[] waveform)
Returns a waveform capture of currently playing audio content.
void release()
Release associated resources.
static int[] sGetCaptureSizeRange()
static int sGetMaxCaptureRate()
int setCaptureSize(int size)
Sets the capture size, i.e.
int setDataCaptureListener(IVisualizer.OnDataCaptureListener listener, int rate, boolean waveform, boolean fft)
Registers an OnDataCaptureListener interface and specifies the rate at which the capture should be updated as well as the type of capture requested.
int setEnabled(boolean enabled)
Enable or disable the visualization engine.
int setMeasurementMode(int mode)
Sets the combination of measurement modes to be performed by this audio effect.
int setScalingMode(int mode)
Set the type of scaling applied on the captured visualization data.
Protected Methods
void finalize()
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.h6ah4i.android.media.IReleasable
From interface com.h6ah4i.android.media.audiofx.IVisualizer

Public Constructors

public OpenSLVisualizer (OpenSLMediaPlayerContext context)

Public Methods

public int getCaptureSize ()

Returns current capture size.

Returns
  • the capture size in bytes.
Throws
IllegalStateException

public int[] getCaptureSizeRange ()

Returns the capture size range.

Returns
  • the minimum capture size is returned in first array element and the maximum in second array element.
Throws
IllegalStateException

public boolean getEnabled ()

Get current activation state of the visualizer.

Returns
  • true if the visualizer is active, false otherwise

public int getFft (byte[] fft)

Returns a frequency capture of currently playing audio content.

This method must be called when the Visualizer is enabled.

The capture is an 8-bit magnitude FFT, the frequency range covered being 0 (DC) to half of the sampling rate returned by getSamplingRate(). The capture returns the real and imaginary parts of a number of frequency points equal to half of the capture size plus one.

Note: only the real part is returned for the first point (DC) and the last point (sampling frequency / 2).

The layout in the returned byte array is as follows:

  • n is the capture size returned by getCaptureSize()
  • Rfk, Ifk are respectively the real and imaginary parts of the kth frequency component
  • If Fs is the sampling frequency retuned by getSamplingRate() the kth frequency is: (k*Fs)/(n/2)
Index 0 1 2 3 4 5 ... n - 2 n - 1
Data Rf0 Rf(n/2) Rf1 If1 Rf2 If2 ... Rf(n-1)/2 If(n-1)/2

Parameters
fft array of bytes where the FFT should be returned
Returns
Throws
IllegalStateException

public int getMaxCaptureRate ()

Returns the maximum capture rate for the callback capture method. This is the maximum value for the rate parameter of the setDataCaptureListener(OnDataCaptureListener, int, boolean, boolean) method.

Returns
  • the maximum capture rate expressed in milliHertz
Throws
IllegalStateException

public int getMeasurementMode ()

Returns the current measurement modes performed by this audio effect

Returns
Throws
IllegalStateException

public int getMeasurementPeakRms (IVisualizer.MeasurementPeakRms measurement)

Retrieves the latest peak and RMS measurement. Sets the peak and RMS fields of the supplied IVisualizer.MeasurementPeakRms to the latest measured values.

Parameters
measurement a non-null MeasurementPeakRms instance to store the measurement values.
Returns

public int getSamplingRate ()

Returns the sampling rate of the captured audio.

Returns
  • the sampling rate in milliHertz.
Throws
IllegalStateException

public int getScalingMode ()

Returns the current scaling mode on the captured visualization data.

Returns
Throws
IllegalStateException

public int getWaveForm (byte[] waveform)

Returns a waveform capture of currently playing audio content. The capture consists in a number of consecutive 8-bit (unsigned) mono PCM samples equal to the capture size returned by getCaptureSize().

This method must be called when the Visualizer is enabled.

Parameters
waveform array of bytes where the waveform should be returned
Returns
Throws
IllegalStateException

public void release ()

Release associated resources.

public static int[] sGetCaptureSizeRange ()

public static int sGetMaxCaptureRate ()

public int setCaptureSize (int size)

Sets the capture size, i.e. the number of bytes returned by getWaveForm(byte[]) and getFft(byte[]) methods. The capture size must be a power of 2 in the range returned by getCaptureSizeRange(). This method must not be called when the Visualizer is enabled.

Parameters
size requested capture size
Returns
Throws
IllegalStateException

public int setDataCaptureListener (IVisualizer.OnDataCaptureListener listener, int rate, boolean waveform, boolean fft)

Registers an OnDataCaptureListener interface and specifies the rate at which the capture should be updated as well as the type of capture requested.

Call this method with a null listener to stop receiving the capture updates.

Parameters
listener OnDataCaptureListener registered
rate rate in milliHertz at which the capture should be updated
waveform true if a waveform capture is requested: the onWaveFormDataCapture() method will be called on the OnDataCaptureListener interface.
fft true if a frequency capture is requested: the onFftDataCapture() method will be called on the OnDataCaptureListener interface.
Returns

public int setEnabled (boolean enabled)

Enable or disable the visualization engine.

Parameters
enabled requested enable state
Returns
Throws
IllegalStateException

public int setMeasurementMode (int mode)

Sets the combination of measurement modes to be performed by this audio effect.

Parameters
mode a mask of the measurements to perform. The valid values are MEASUREMENT_MODE_NONE (to cancel any measurement) or MEASUREMENT_MODE_PEAK_RMS.
Returns
Throws
IllegalStateException

public int setScalingMode (int mode)

Set the type of scaling applied on the captured visualization data.

Returns
Throws
IllegalStateException

Protected Methods

protected void finalize ()

Throws
Throwable