Skip to content

OpenSL prefixed API classes

Haruki Hasegawa edited this page Dec 27, 2015 · 1 revision

OpenSL* prefixed API classes

The OpenSL* prefixed classes are wrapper of C++ Native API sets.

OpenSLMediaPlayerFactory

The OpenSLMediaPlayerFactory class is a factory class of all OpenSL* media player and audio effect classes.

OpenSLMediaPlayerContext

The OpenSLMediaPlayerContext class is a shared object among all OpenSL* objects.

OpenSLMediaPlayerContext.Parameters

Field name Usage Default
options Specify logical OR of OPTION_* constants 0
streamType Specify one of the AudioManager.STREAM_* constants AudioManager.STREAM_MUSIC
shortFadeDuration Specify duration of short fading in milli seconds 25
longFadeDuration Specify duration of long fading in milli seconds 1500
resamplerQuality Specify one of the RESAMPLER_QUALITY_* constants RESAMPLER_QUALITY_MIDDLE
hqEqualizerImplType Specify one of the HQ_EAUALIZER_IMPL_* constants HQ_EAUALIZER_IMPL_BASIC_PEAKING_FILTER

OPTION_* constants

Name Meaning
OPTION_USE_BASSBOOST Whether to use OpenSLBassBoost
OPTION_USE_VIRTUALIZER Whether to use OpenSLVirtualizer
OPTION_USE_EQUALIZER Whether to use OpenSEqualizer
OPTION_USE_ENVIRONMENAL_REVERB Whether to use OpenSLEnvironmentalReverb
OPTION_USE_PRESET_REVERB Whether to use OpenSLPresetReverb
OPTION_USE_VISUALIZER Whether to use OpenSLVisualizer
OPTION_USE_HQ_EQUALIZER Whether to use OpenSLEqualizer
OPTION_USE_PREAMP Whether to use OpenSLPreAmp
OPTION_USE_HQ_VISUALIZER Whether to use OpenSLHQVisualizer

RESAMPLER_QUALITY_* constants

Name Meaning
RESAMPLER_QUALITY_LOW Low quality (better than "cubic")
RESAMPLER_QUALITY_MIDDLE Middle quality (almost same as "sinc with revised coefficients")
RESAMPLER_QUALITY_HIGH High quality (better than "sinc with revised coefficients")

HQ_EAUALIZER_IMPL_* constants

Name Meaning
HQ_EAUALIZER_IMPL_BASIC_PEAKING_FILTER Basic implementation using cascaded peaking filters
HQ_EAUALIZER_IMPL_FLAT_GAIN_RESPOINSE Better gain response implementation using cascaded shelf filters

OpenSLMediaPlayer

Corresponding Android's class is android.media.MediaPlayer.

OpenSLMediaPlayer(OpenSLMediaPlayerContext context, int options) [constructor]

Specify logical OR of these values for the second argument.

Flag name Effects
OPTION_USE_FADE Enable fade in/out

setAudioStreamType()

This method is not supported. Please use OpenSLMediaPlayerContext.Parameters.streamType instead.

getAudioSessionId()

This method is not supported and always returns 0.

setAudioSessionId()

This method is not supported and throws IllegalStateException.

setAuxEffectSendLevel()

Send level is shared among all OpenSLMediaPlayer instances created from the same factory instance.

Notes

  • Instantiation of this class is limited to 4 instances per each factory object

OpenSLBassBoost

The OpenSLBassBoost class uses SLBassBoostItf internally. The OPTION_USE_BASSBOOST flag is required when creating OpenSLMediaPlayerContext object to instantiate this class.

Corresponding Android's class is android.media.audiofx.BassBoost.

Notes

  • This class may not work on some devices which has CyanogenMod's DSP Manager

Limitations

  • OnParameterChangeListener is not supported
  • OnControlStatusChangeListener is not supported
  • OnEnableStatusChangeListener is not supported

OpenSLVirtualizer

The OpenSLVirtualizer class uses SLVirtualizerItf internally. The OPTION_USE_VIRTUALIZER flag is required when creating OpenSLMediaPlayerContext object to instantiate this class.

Corresponding Android's class is android.media.audiofx.Virtualizer.

Notes

  • This class may not work on some devices which has CyanogenMod's DSP Manager

Limitations

  • OnParameterChangeListener is not supported
  • OnControlStatusChangeListener is not supported
  • OnEnableStatusChangeListener is not supported

OpenSLEqualizer

The OpenSLEqualizer class is a 5 bands graphic equalizer and it uses SLEqualizerItf internally. The OPTION_USE_EQUALIZER flag is required when creating OpenSLMediaPlayerContext object to instantiate this class.

Corresponding Android's class is android.media.audiofx.Equalizer.

Notes

  • This class may not work on some devices which has CyanogenMod's DSP Manager

Limitations

  • OnParameterChangeListener is not supported
  • OnControlStatusChangeListener is not supported
  • OnEnableStatusChangeListener is not supported

OpenSLVisualizer

The OpenSLVisualizer class enables to capture mixed out audio signal. This class does NOT use SLVisualizationtItf internally. The OPTION_USE_VISUALIZER flag is required when creating OpenSLMediaPlayerContext object to instantiate this class.

Corresponding Android's class is android.media.audiofx.Visualizer.

OpenSLEnvironmentalReverb

The OpenSLEnvironmentalReverb class is a configurable reverb and it uses SLEnvironmentalReverbItf internally. The OPTION_USE_ENVIRONMENAL_REVERB flag is required when creating OpenSLMediaPlayerContext object to instantiate this class.

Corresponding Android's class is android.media.audiofx.EnvironmentalReverb.

Limitations

  • OnParameterChangeListener is not supported
  • OnControlStatusChangeListener is not supported
  • OnEnableStatusChangeListener is not supported

OpenSLPresetReverb

The OpenSLEnvironmentalReverb class is a reverb which has simple interface and it uses SLPresetReverbItf internally. The OPTION_USE_PRESET_REVERB flag is required when creating OpenSLMediaPlayerContext object to instantiate this class.

Corresponding Android's class is android.media.audiofx.PresetReverb.

Limitations

  • OnParameterChangeListener is not supported
  • OnControlStatusChangeListener is not supported
  • OnEnableStatusChangeListener is not supported

OpenSLHQEqualizer

The OpenSLHQEqualizer class is 10 bands graphic equalizer class. This class implements IEqualizer as same as the OpenSLEqualizer class. The OPTION_USE_HQ_EQUALIZER flag is required when creating OpenSLMediaPlayerContext object to instantiate this class.

Limitations

  • OnParameterChangeListener is not supported
  • OnControlStatusChangeListener is not supported
  • OnEnableStatusChangeListener is not supported

OpenSLPreAmp

The OpenSLPreAmp class is preamplifier of mixed out audio. This class can be used to avoid clipping when using OpenSLHQEqualizer. The OPTION_USE_PREAMP flag is required when creating OpenSLMediaPlayerContext object to instantiate this class.

OpenSLHQVisualizer

The OpenSLHQVisualizer class is advanced class. This class implements IHQVisualizer, so it's different from OpenSLVisualizer class. The OPTION_USE_HQ_VISUALIZER flag is required when creating OpenSLMediaPlayerContext object to instantiate this class.

Comparsion with OpenSLVisualizer / StandardVisualizer

OpenSLHQVisualizer OpenSLVisualizer / StandardVisualizer
Super interface IHQVisualizer IVisualizer
Wave form capture format float, stereo byte (unsigned 8 bit), monaural
FFT capture format float, stereo byte (signed 8 bit), monaural
Min. capture data size 128 frames 128 frames
Max. capture data size 32768 frames 1024 frames
Min. capture data rate 0.1 Hz 0.1 Hz
Max. capture data rate 60 Hz 20 Hz
getWaveform() method not supported supported
getFft() method not supported supported
getMeasurementPeakRms() method not supported supported (getMeasurementPeakRmsCompat())
setScalingMode() method not supported supported (setScalingModeCompat())
Callback context from native capturing thread from Handler's thread (main thread)
System volume setting not affected affected