Skip to content

Most visited

Recently visited

navigation
added in API level 9

Visualizer.OnDataCaptureListener

public static interface Visualizer.OnDataCaptureListener

android.media.audiofx.Visualizer.OnDataCaptureListener


The OnDataCaptureListener interface defines methods called by the Visualizer to periodically update the audio visualization capture. The client application can implement this interface and register the listener with the setDataCaptureListener(OnDataCaptureListener, int, boolean, boolean) method.

Summary

Public methods

abstract void onFftDataCapture(Visualizer visualizer, byte[] fft, int samplingRate)

Method called when a new frequency capture is available.

abstract void onWaveFormDataCapture(Visualizer visualizer, byte[] waveform, int samplingRate)

Method called when a new waveform capture is available.

Public methods

onFftDataCapture

added in API level 9
void onFftDataCapture (Visualizer visualizer, 
                byte[] fft, 
                int samplingRate)

Method called when a new frequency capture is available.

Data in the fft buffer is valid only within the scope of the callback. Applications which need access to the fft data after returning from the callback should make a copy of the data instead of holding a reference.

In order to obtain magnitude and phase values the following formulas can be used:

       for (int i = 0; i < fft.size(); i += 2) {
           float magnitude = (float)Math.hypot(fft[i], fft[i + 1]);
           float phase = (float)Math.atan2(fft[i + 1], fft[i]);
       }

Parameters
visualizer Visualizer: Visualizer object on which the listener is registered.

fft byte: array of bytes containing the frequency representation. The fft array only contains the first half of the actual FFT spectrum (frequencies up to Nyquist frequency), exploiting the symmetry of the spectrum. For each frequencies bin i:
  • the element at index 2*i in the array contains the real part of a complex number,
  • the element at index 2*i+1 contains the imaginary part of the complex number.

samplingRate int: sampling rate of the visualized audio.

onWaveFormDataCapture

added in API level 9
void onWaveFormDataCapture (Visualizer visualizer, 
                byte[] waveform, 
                int samplingRate)

Method called when a new waveform capture is available.

Data in the waveform buffer is valid only within the scope of the callback. Applications which need access to the waveform data after returning from the callback should make a copy of the data instead of holding a reference.

Parameters
visualizer Visualizer: Visualizer object on which the listener is registered.

waveform byte: array of bytes containing the waveform representation.

samplingRate int: sampling rate of the visualized audio.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)