IT. Expert System.

Android Reference

Visualizer


android.media.audiofx

Class Visualizer



  • public class Visualizer
    extends Object
    The Visualizer class enables application to retrieve part of the currently playing audio for visualization purpose. It is not an audio recording interface and only returns partial and low quality audio content. However, to protect privacy of certain audio data (e.g voice mail) the use of the visualizer requires the permission android.permission.RECORD_AUDIO.

    The audio session ID passed to the constructor indicates which audio content should be visualized:

    • If the session is 0, the audio output mix is visualized
    • If the session is not 0, the audio from a particular MediaPlayer or AudioTrack using this audio session is visualized

    Two types of representation of audio content can be captured:

    • Waveform data: consecutive 8-bit (unsigned) mono samples by using the getWaveForm(byte[]) method
    • Frequency data: 8-bit magnitude FFT by using the getFft(byte[]) method

    The length of the capture can be retrieved or specified by calling respectively getCaptureSize() and setCaptureSize(int) methods. The capture size must be a power of 2 in the range returned by getCaptureSizeRange().

    In addition to the polling capture mode described above with getWaveForm(byte[]) and getFft(byte[]) methods, a callback mode is also available by installing a listener by use of the setDataCaptureListener(OnDataCaptureListener, int, boolean, boolean) method. The rate at which the listener capture method is called as well as the type of data returned is specified.

    Before capturing data, the Visualizer must be enabled by calling the setEnabled(boolean) method. When data capture is not needed any more, the Visualizer should be disabled.

    It is good practice to call the release() method when the Visualizer is not used anymore to free up native resources associated to the Visualizer instance.

    Creating a Visualizer on the output mix (audio session 0) requires permission android.Manifest.permission#MODIFY_AUDIO_SETTINGS

    • Field Summary

      Fields
      Modifier and Type Field and Description
      static int ALREADY_EXISTS
      Internal operation status.
      static int ERROR
      Unspecified error.
      static int ERROR_BAD_VALUE
      Operation failed due to bad parameter value.
      static int ERROR_DEAD_OBJECT
      Operation failed due to dead remote object.
      static int ERROR_INVALID_OPERATION
      Operation failed because it was requested in wrong state.
      static int ERROR_NO_INIT
      Operation failed due to bad object initialization.
      static int ERROR_NO_MEMORY
      Operation failed due to lack of memory.
      static int SCALING_MODE_AS_PLAYED
      Defines a capture mode where the playback volume will affect (scale) the range of the captured data.
      static int SCALING_MODE_NORMALIZED
      Defines a capture mode where amplification is applied based on the content of the captured data.
      static int STATE_ENABLED
      State of a Visualizer object that is active.
      static int STATE_INITIALIZED
      State of a Visualizer object that is ready to be used.
      static int STATE_UNINITIALIZED
      State of a Visualizer object that was not successfully initialized upon creation
      static int SUCCESS
      Successful operation.
    • Constructor Summary

      Constructors
      Constructor and Description
      Visualizer(int audioSession)
      Class constructor.
    • Field Detail

      • STATE_UNINITIALIZED

        public static final int STATE_UNINITIALIZED
        State of a Visualizer object that was not successfully initialized upon creation
        See Also:
        Constant Field Values
      • STATE_INITIALIZED

        public static final int STATE_INITIALIZED
        State of a Visualizer object that is ready to be used.
        See Also:
        Constant Field Values
      • STATE_ENABLED

        public static final int STATE_ENABLED
        State of a Visualizer object that is active.
        See Also:
        Constant Field Values
      • SCALING_MODE_NORMALIZED

        public static final int SCALING_MODE_NORMALIZED
        Defines a capture mode where amplification is applied based on the content of the captured data. This is the default Visualizer mode, and is suitable for music visualization.
        See Also:
        Constant Field Values
      • SCALING_MODE_AS_PLAYED

        public static final int SCALING_MODE_AS_PLAYED
        Defines a capture mode where the playback volume will affect (scale) the range of the captured data. A low playback volume will lead to low sample and fft values, and vice-versa.
        See Also:
        Constant Field Values
      • ALREADY_EXISTS

        public static final int ALREADY_EXISTS
        Internal operation status. Not returned by any method.
        See Also:
        Constant Field Values
      • ERROR_NO_INIT

        public static final int ERROR_NO_INIT
        Operation failed due to bad object initialization.
        See Also:
        Constant Field Values
      • ERROR_BAD_VALUE

        public static final int ERROR_BAD_VALUE
        Operation failed due to bad parameter value.
        See Also:
        Constant Field Values
      • ERROR_INVALID_OPERATION

        public static final int ERROR_INVALID_OPERATION
        Operation failed because it was requested in wrong state.
        See Also:
        Constant Field Values
      • ERROR_NO_MEMORY

        public static final int ERROR_NO_MEMORY
        Operation failed due to lack of memory.
        See Also:
        Constant Field Values
      • ERROR_DEAD_OBJECT

        public static final int ERROR_DEAD_OBJECT
        Operation failed due to dead remote object.
        See Also:
        Constant Field Values
    • Method Detail

      • release

        public void release()
        Releases the native Visualizer resources. It is a good practice to release the visualization engine when not in use.
      • finalize

        protected void finalize()
        Description copied from class: Object
        Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

        Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

        If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

        Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

        Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

        Overrides:
        finalize in class Object
      • getEnabled

        public boolean getEnabled()
        Get current activation state of the visualizer.
        Returns:
        true if the visualizer is active, false otherwise
      • getCaptureSizeRange

        public static int[] getCaptureSizeRange()
        Returns the capture size range.
        Returns:
        the mininum capture size is returned in first array element and the maximum in second array element.
      • getFft

        public int getFft(byte[] fft)
                   throws IllegalStateException
        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:
        SUCCESS in case of success, ERROR_NO_MEMORY, ERROR_INVALID_OPERATION or ERROR_DEAD_OBJECT in case of failure.
        Throws:
        IllegalStateException
      • setDataCaptureListener

        public int setDataCaptureListener(Visualizer.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:
        SUCCESS in case of success, ERROR_NO_INIT or ERROR_BAD_VALUE in case of failure.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 2634 / . Delta: 0.02903 с