Android Audio代码分析6 - AudioEffect
在看AudioSessionId相关代码的时候了解到,共用一个AudioSessionId的AudioTrack和MediaPlayer会共用一个AudioEffect。
今天就来看看AudioEffect是个什么东东。
看这个类的目的,主要是为了搞清楚AudioEffect是个什么东东。
打算重点看看类的介绍及其构造函数上。
*****************************************源码*************************************************
public class AudioEffect {
static {
System.loadLibrary("audioeffect_jni");
native_init();
}
...
public AudioEffect(UUID type, UUID uuid, int priority, int audioSession)
throws IllegalArgumentException, UnsupportedOperationException,
RuntimeException {
int[] id = new int[1];
Descriptor[] desc = new Descriptor[1];
// native initialization
int initResult = native_setup(new WeakReference<AudioEffect>(this),
type.toString(), uuid.toString(), priority, audioSession, id,
desc);
if (initResult != SUCCESS && initResult != ALREADY_EXISTS) {
Log.e(TAG, "Error code " + initResult
+ " when initializing AudioEffect.");
switch (initResult) {
case ERROR_BAD_VALUE:
throw (new IllegalArgumentException("Effect type: " + type
+ " not supported."));
case ERROR_INVALID_OPERATION:
throw (new UnsupportedOperationException(
"Effect library not loaded"));
default:
throw (new RuntimeException(
"Cannot initialize effect engine for type: " + type
+ "Error: " + initResult));
}
}
mId = id[0];
mDescriptor = desc[0];
synchronized (mStateLock) {
mState = STATE_INITIALIZED;
}
}
...
} www.zzzyk.com
**********************************************************************************************
源码路径:
frameworks\base\media\java\android\media\audiofx\AudioEffect.java
###########################################说明################################################
先看看整个类的注释:
/**
* AudioEffect is the base class for controlling audio effects provided by the android audio
* framework.
* <p>Applications should not use the AudioEffect class directly but one of its derived classes to
* control specific effects:
* <ul>
* <li> {@link android.media.audiofx.Equalizer}</li>
* <li> {@link android.media.audiofx.Virtualizer}</li>
* <li> {@link android.media.audiofx.BassBoost}</li>
* <li> {@link android.media.audiofx.PresetReverb}</li>
* <li> {@link android.media.audiofx.EnvironmentalReverb}</li>
* </ul>
* <p>If the audio effect is to be applied to a specific AudioTrack or MediaPlayer instance,
* the application must specify the audio session ID of that instance when creating the AudioEffect.
* (see {@link android.media.MediaPlayer#getAudioSessionId()} for details on audio sessions).
* To apply an effect to the global audio output mix, session 0 must be specified when creating the
* AudioEffect.
* <p>Creating an effect on the output mix (audio session 0) requires permission
* {@link android.Manifest.permission#MODIFY_AUDIO_SETTINGS}
* <p>Creating an AudioEffect object will create the corresponding effect engine in the audio
* framework if no instance of the same effect type exists in the specified audio session.
* If one exists, this instance will be used.
* <p>The application creating the AudioEffect object (or a derived class) will either receive
* control of the effect engine or not depending on the priority parameter. If priority is higher
* than the priority used by the current effect engine owner, the control will be transfered to the
* new object. Otherwise control will remain with the previous object. In this case, the new
* application will be notified of changes in effect engine state or control ownership by the
* appropiate listener.
*/
大致意思如下:
AudioEffect是由android audio framework提供的控制audio effect的基类。
应用程序不应该直接创建AudioEffect的对象,而应该创建由其派生的,控制特定effect的类的对象。
可创建对象的派生类如下:
* <li> {@link android.media.audiofx.Equalizer}</li>
* <li> {@link android.media.audiofx.Virtualizer}</li>
* <li> {@link android.media.audiofx.BassBoost}</li>
* <li> {@link android.media.audiofx.PresetReverb}</li>
* <li> {@link android.media.audiofx.EnvironmentalReverb}</li>
* </ul>
如果一个audio effect被指定给一个特定的AudioTrack或者MediaPlayer,创建AudioEffect对象的时候必须指定一个AudioSessionId。
如果想创建一个对global audio outp
补充:移动开发 , Android ,