1948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent/* 2948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Copyright (C) 2010 The Android Open Source Project 3948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 4948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Licensed under the Apache License, Version 2.0 (the "License"); 5948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * you may not use this file except in compliance with the License. 6948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * You may obtain a copy of the License at 7948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 8948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * http://www.apache.org/licenses/LICENSE-2.0 9948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 10948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Unless required by applicable law or agreed to in writing, software 11948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * distributed under the License is distributed on an "AS IS" BASIS, 12948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * See the License for the specific language governing permissions and 14948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * limitations under the License. 15948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 16948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 171a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurentpackage android.media.audiofx; 18948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 19d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurentimport android.annotation.SdkConstant; 20d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurentimport android.annotation.SdkConstant.SdkConstantType; 21948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentimport android.os.Handler; 22948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentimport android.os.Looper; 23948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentimport android.os.Message; 24d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurentimport android.util.Log; 25d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurentimport java.io.IOException; 26d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurentimport java.lang.ref.WeakReference; 27948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentimport java.nio.ByteOrder; 28948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentimport java.nio.ByteBuffer; 29948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentimport java.util.UUID; 30948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 31948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent/** 321a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * AudioEffect is the base class for controlling audio effects provided by the android audio 331a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * framework. 341a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <p>Applications should not use the AudioEffect class directly but one of its derived classes to 351a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * control specific effects: 361a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <ul> 371a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li> {@link android.media.audiofx.Equalizer}</li> 381a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li> {@link android.media.audiofx.Virtualizer}</li> 391a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li> {@link android.media.audiofx.BassBoost}</li> 401a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li> {@link android.media.audiofx.PresetReverb}</li> 411a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li> {@link android.media.audiofx.EnvironmentalReverb}</li> 421a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * </ul> 4362f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * <p>To apply the audio effect to a specific AudioTrack or MediaPlayer instance, 441a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * the application must specify the audio session ID of that instance when creating the AudioEffect. 451a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * (see {@link android.media.MediaPlayer#getAudioSessionId()} for details on audio sessions). 4662f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * <p>NOTE: attaching insert effects (equalizer, bass boost, virtualizer) to the global audio output 4762f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * mix by use of session 0 is deprecated. 481a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <p>Creating an AudioEffect object will create the corresponding effect engine in the audio 491a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * framework if no instance of the same effect type exists in the specified audio session. 501a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * If one exists, this instance will be used. 511a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <p>The application creating the AudioEffect object (or a derived class) will either receive 521a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * control of the effect engine or not depending on the priority parameter. If priority is higher 531a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * than the priority used by the current effect engine owner, the control will be transfered to the 541a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * new object. Otherwise control will remain with the previous object. In this case, the new 551a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * application will be notified of changes in effect engine state or control ownership by the 561a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * appropiate listener. 57948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 581a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent 59df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurentpublic class AudioEffect { 60948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent static { 61948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent System.loadLibrary("audioeffect_jni"); 62948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent native_init(); 63948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 64948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 65948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private final static String TAG = "AudioEffect-JAVA"; 66948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 670f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent // effect type UUIDs are taken from hardware/libhardware/include/hardware/audio_effect.h 680f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 69948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 70df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * The following UUIDs define effect types corresponding to standard audio 71df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * effects whose implementation and interface conform to the OpenSL ES 72df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * specification. The definitions match the corresponding interface IDs in 73df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * OpenSLES_IID.h 74948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 75948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 76df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 77df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * UUID for environmental reverb effect 781a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 79df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 80df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_ENV_REVERB = UUID 81df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("c2e5d5f0-94bd-4763-9cac-4e234d06839e"); 82df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 83df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * UUID for preset reverb effect 841a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 85df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 86df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_PRESET_REVERB = UUID 87df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("47382d60-ddd8-11db-bf3a-0002a5d5c51b"); 88df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 89df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * UUID for equalizer effect 901a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 91df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 92df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_EQUALIZER = UUID 93df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("0bed4300-ddd6-11db-8f34-0002a5d5c51b"); 94df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 95df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * UUID for bass boost effect 961a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 97df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 98df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_BASS_BOOST = UUID 99df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("0634f220-ddd4-11db-a0fc-0002a5d5c51b"); 100df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 101df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * UUID for virtualizer effect 1021a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 103df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 104df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_VIRTUALIZER = UUID 105df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("37cc2c00-dddd-11db-8577-0002a5d5c51b"); 106948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 107948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 1080f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * UUID for Automatic Gain Control (AGC) audio pre-processing 1090f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @hide 1100f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */ 1110f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent public static final UUID EFFECT_TYPE_AGC = UUID 1120f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent .fromString("0a8abfe0-654c-11e0-ba26-0002a5d5c51b"); 1130f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 1140f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent /** 1150f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * UUID for Acoustic Echo Canceler (AEC) audio pre-processing 1160f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @hide 1170f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */ 1180f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent public static final UUID EFFECT_TYPE_AEC = UUID 1190f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent .fromString("7b491460-8d4d-11e0-bd61-0002a5d5c51b"); 1200f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 1210f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent /** 1220f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * UUID for Noise Suppressor (NS) audio pre-processing 1230f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @hide 1240f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */ 1250f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent public static final UUID EFFECT_TYPE_NS = UUID 1260f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent .fromString("58b4b260-8e06-11e0-aa8e-0002a5d5c51b"); 1270f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 1280f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent /** 129df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Null effect UUID. Used when the UUID for effect type of 1301a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 131df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 132df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_NULL = UUID 133df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("ec7178ec-e5e1-4432-a3f4-4657e6795210"); 134df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 135df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 136df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * State of an AudioEffect object that was not successfully initialized upon 137df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * creation 1381a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 139948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 140948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public static final int STATE_UNINITIALIZED = 0; 141948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 142948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * State of an AudioEffect object that is ready to be used. 1431a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 144948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 145df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int STATE_INITIALIZED = 1; 146948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 147df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // to keep in sync with 1482a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent // frameworks/base/include/media/AudioEffect.h 149948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 1502a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent * Event id for engine control ownership change notification. 1511a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 152948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 1532a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent public static final int NATIVE_EVENT_CONTROL_STATUS = 0; 154948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 1552a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent * Event id for engine state change notification. 1561a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 157948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 1582a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent public static final int NATIVE_EVENT_ENABLED_STATUS = 1; 159948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 160948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Event id for engine parameter change notification. 1611a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 162948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 16317cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public static final int NATIVE_EVENT_PARAMETER_CHANGED = 2; 164948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 165df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 166df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Successful operation. 167df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 168df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int SUCCESS = 0; 169df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 170df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Unspecified error. 171df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 172df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR = -1; 173df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 174ed6eae420fd60dcb7d90f54c3116959b75bd6276Glenn Kasten * Internal operation status. Not returned by any method. 175df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 176df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ALREADY_EXISTS = -2; 177df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 178df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Operation failed due to bad object initialization. 179df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 180df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR_NO_INIT = -3; 181df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 182df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Operation failed due to bad parameter value. 183df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 184df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR_BAD_VALUE = -4; 185df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 186df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Operation failed because it was requested in wrong state. 187df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 188df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR_INVALID_OPERATION = -5; 189df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 190df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Operation failed due to lack of memory. 191df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 192df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR_NO_MEMORY = -6; 193df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 194df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Operation failed due to dead remote object. 195df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 196df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR_DEAD_OBJECT = -7; 197df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 198df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 1991a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * The effect descriptor contains information on a particular effect implemented in the 2001a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * audio framework:<br> 201df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * <ul> 2021a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li>type: UUID corresponding to the OpenSL ES interface implemented by this effect</li> 2031a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li>uuid: UUID for this particular implementation</li> 2040f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * <li>connectMode: {@link #EFFECT_INSERT}, {@link #EFFECT_AUXILIARY} or 2050f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * {at_link #EFFECT_PRE_PROCESSING}</li> 2061a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li>name: human readable effect name</li> 2071a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li>implementor: human readable effect implementor name</li> 208df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * </ul> 2091a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * The method {@link #queryEffects()} returns an array of Descriptors to facilitate effects 2101a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * enumeration. 211df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 212df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static class Descriptor { 213df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 214df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public Descriptor() { 215df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent } 216df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 217df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public Descriptor(String type, String uuid, String connectMode, 218df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent String name, String implementor) { 2191a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent this.type = UUID.fromString(type); 2201a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent this.uuid = UUID.fromString(uuid); 2211a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent this.connectMode = connectMode; 2221a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent this.name = name; 2231a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent this.implementor = implementor; 224df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent } 225df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 2261a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 2271a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Indicates the generic type of the effect (Equalizer, Bass boost ...). The UUID 2281a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * corresponds to the OpenSL ES Interface ID for this type of effect. 2291a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 2301a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent public UUID type; 2311a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 2321a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Indicates the particular implementation of the effect in that type. Several effects 2331a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * can have the same type but this uuid is unique to a given implementation. 2341a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 2351a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent public UUID uuid; 2361a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 2370f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * Indicates if the effect is of insert category {@link #EFFECT_INSERT}, auxiliary 2380f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * category {@link #EFFECT_AUXILIARY} or pre processing category 2390f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * {at_link #EFFECT_PRE_PROCESSING}. Insert effects (Typically an Equalizer) are applied 2401a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * to the entire audio source and usually not shared by several sources. Auxiliary effects 2411a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * (typically a reverberator) are applied to part of the signal (wet) and the effect output 2421a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * is added to the original signal (dry). 2430f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * Audio pre processing are applied to audio captured on a particular AudioRecord. 2441a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 2451a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent public String connectMode; 2461a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 2471a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Human readable effect name 2481a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 2491a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent public String name; 2501a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 2511a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Human readable effect implementor name 2521a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 2531a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent public String implementor; 254df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent }; 255df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 256df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 257df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Effect connection mode is insert. Specifying an audio session ID when creating the effect 258df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * will insert this effect after all players in the same audio session. 259df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 260df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final String EFFECT_INSERT = "Insert"; 261df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 262df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Effect connection mode is auxiliary. 263df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * <p>Auxiliary effects must be created on session 0 (global output mix). In order for a 264df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * MediaPlayer or AudioTrack to be fed into this effect, they must be explicitely attached to 265df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * this effect and a send level must be specified. 266df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * <p>Use the effect ID returned by {@link #getId()} to designate this particular effect when 267df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * attaching it to the MediaPlayer or AudioTrack. 268df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 269df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final String EFFECT_AUXILIARY = "Auxiliary"; 2700f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent /** 2710f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * Effect connection mode is pre processing. 2720f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * The audio pre processing effects are attached to an audio input (AudioRecord). 2730f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @hide 2740f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */ 2750f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent public static final String EFFECT_PRE_PROCESSING = "Pre Processing"; 276948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 277df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 278948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Member variables 279df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 280948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 281948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Indicates the state of the AudioEffect instance 282948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 28317cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private int mState = STATE_UNINITIALIZED; 284948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 285948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Lock to synchronize access to mState 286948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 28717cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private final Object mStateLock = new Object(); 288948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 289948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * System wide unique effect ID 290948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 29117cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private int mId; 292948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 293948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // accessed by native methods 294948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private int mNativeAudioEffect; 295948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private int mJniData; 296948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 297948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 298948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Effect descriptor 299948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 300948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private Descriptor mDescriptor; 301948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 302948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 303948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Listener for effect engine state change notifications. 304df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 305df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setEnableStatusListener(OnEnableStatusChangeListener) 306948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 30717cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private OnEnableStatusChangeListener mEnableStatusChangeListener = null; 308948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 309948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Listener for effect engine control ownership change notifications. 310df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 311df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setControlStatusListener(OnControlStatusChangeListener) 312948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 31317cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private OnControlStatusChangeListener mControlChangeStatusListener = null; 314948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 315948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Listener for effect engine control ownership change notifications. 316df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 317df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameterListener(OnParameterChangeListener) 318948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 31917cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private OnParameterChangeListener mParameterChangeListener = null; 320948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 321948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Lock to protect listeners updates against event notifications 3221a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 323948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 32417cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public final Object mListenerLock = new Object(); 325948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 326948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Handler for events coming from the native code 3271a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 328948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 32917cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public NativeEventHandler mNativeEventHandler = null; 330948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 331df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 332948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Constructor, Finalize 333df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 334948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 335948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Class constructor. 336df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 337df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param type type of effect engine created. See {@link #EFFECT_TYPE_ENV_REVERB}, 338df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * {@link #EFFECT_TYPE_EQUALIZER} ... Types corresponding to 339df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * built-in effects are defined by AudioEffect class. Other types 340df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * can be specified provided they correspond an existing OpenSL 341df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * ES interface ID and the corresponsing effect is available on 342df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the platform. If an unspecified effect type is requested, the 343df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * constructor with throw the IllegalArgumentException. This 344df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * parameter can be set to {@link #EFFECT_TYPE_NULL} in which 345df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * case only the uuid will be used to select the effect. 346df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param uuid unique identifier of a particular effect implementation. 347df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Must be specified if the caller wants to use a particular 348df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * implementation of an effect type. This parameter can be set to 349df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * {@link #EFFECT_TYPE_NULL} in which case only the type will 350df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * be used to select the effect. 351df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param priority the priority level requested by the application for 352df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * controlling the effect engine. As the same effect engine can 353df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * be shared by several applications, this parameter indicates 354df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * how much the requesting application needs control of effect 355df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * parameters. The normal priority is 0, above normal is a 356df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * positive number, below normal a negative number. 35762f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * @param audioSession system wide unique audio session identifier. 35862f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * The effect will be attached to the MediaPlayer or AudioTrack in 35962f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * the same audio session. 360948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 361948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws java.lang.IllegalArgumentException 362948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws java.lang.UnsupportedOperationException 363948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws java.lang.RuntimeException 3641a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 365948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 366948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 367948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public AudioEffect(UUID type, UUID uuid, int priority, int audioSession) 368df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalArgumentException, UnsupportedOperationException, 369df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent RuntimeException { 370948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int[] id = new int[1]; 371948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent Descriptor[] desc = new Descriptor[1]; 372948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // native initialization 373948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int initResult = native_setup(new WeakReference<AudioEffect>(this), 374df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent type.toString(), uuid.toString(), priority, audioSession, id, 375df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent desc); 376948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (initResult != SUCCESS && initResult != ALREADY_EXISTS) { 377df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent Log.e(TAG, "Error code " + initResult 378df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent + " when initializing AudioEffect."); 379948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent switch (initResult) { 380df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent case ERROR_BAD_VALUE: 381df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throw (new IllegalArgumentException("Effect type: " + type 382df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent + " not supported.")); 383df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent case ERROR_INVALID_OPERATION: 384df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throw (new UnsupportedOperationException( 385df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent "Effect library not loaded")); 386948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent default: 387df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throw (new RuntimeException( 388df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent "Cannot initialize effect engine for type: " + type 389df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent + "Error: " + initResult)); 390948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 391948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 392948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mId = id[0]; 393948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mDescriptor = desc[0]; 394948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mStateLock) { 395948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mState = STATE_INITIALIZED; 396948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 397948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 398948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 399948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 400df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Releases the native AudioEffect resources. It is a good practice to 401df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * release the effect engine when not in use as control can be returned to 402df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * other applications or the native resources released. 403948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 404948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public void release() { 405948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mStateLock) { 406948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent native_release(); 407948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mState = STATE_UNINITIALIZED; 408948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 409948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 410948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 411948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent @Override 412948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent protected void finalize() { 413948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent native_finalize(); 414948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 415948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 416948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 417948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Get the effect descriptor. 418df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 4191a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @see android.media.audiofx.AudioEffect.Descriptor 420948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 421948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 422df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public Descriptor getDescriptor() throws IllegalStateException { 423948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("getDescriptor()"); 424948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return mDescriptor; 425948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 426948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 427df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 428948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Effects Enumeration 429df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 430948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 431948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 432948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Query all effects available on the platform. Returns an array of 4331a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * {@link android.media.audiofx.AudioEffect.Descriptor} objects 434948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 435948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 436948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 437948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 438948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent static public Descriptor[] queryEffects() { 439df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return (Descriptor[]) native_query_effects(); 440948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 441948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 4420f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent /** 4430f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * Query all audio pre processing effects applied to the AudioRecord with the supplied 4440f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * audio session ID. Returns an array of {@link android.media.audiofx.AudioEffect.Descriptor} 4450f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * objects. 4460f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @param audioSession system wide unique audio session identifier. 4470f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @throws IllegalStateException 4480f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @hide 4490f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */ 4500f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 4510f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent static public Descriptor[] queryPreProcessings(int audioSession) { 4520f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent return (Descriptor[]) native_query_pre_processing(audioSession); 4530f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 4540f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 455df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 456948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Control methods 457df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 458948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 459948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 4601a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Enable or disable the effect. 4611a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Creating an audio effect does not automatically apply this effect on the audio source. It 4621a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * creates the resources necessary to process this effect but the audio signal is still bypassed 4631a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * through the effect engine. Calling this method will make that the effect is actually applied 4641a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * or not to the audio content being played in the corresponding audio session. 465df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 466df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param enabled the requested enable state 467df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @return {@link #SUCCESS} in case of success, {@link #ERROR_INVALID_OPERATION} 468df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * or {@link #ERROR_DEAD_OBJECT} in case of failure. 469948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 470948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 471df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public int setEnabled(boolean enabled) throws IllegalStateException { 472df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent checkState("setEnabled()"); 473df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return native_setEnabled(enabled); 474948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 475948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 476948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 477948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Set effect parameter. The setParameter method is provided in several 478df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * forms addressing most common parameter formats. This form is the most 479df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * generic one where the parameter and its value are both specified as an 480df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of bytes. The parameter and value type and length are therefore 481df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * totally free. For standard effect defined by OpenSL ES, the parameter 482df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * format and values must match the definitions in the corresponding OpenSL 483df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * ES interface. 484948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 485df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param param the identifier of the parameter to set 486df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param value the new value for the specified parameter 487df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @return {@link #SUCCESS} in case of success, {@link #ERROR_BAD_VALUE}, 488df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * {@link #ERROR_NO_MEMORY}, {@link #ERROR_INVALID_OPERATION} or 489df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * {@link #ERROR_DEAD_OBJECT} in case of failure 490948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 4911a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 492948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 493948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(byte[] param, byte[] value) 494df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 495948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("setParameter()"); 496948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return native_setParameter(param.length, param, value.length, value); 497948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 498948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 499948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 500948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Set effect parameter. The parameter and its value are integers. 501df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 502df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 5031a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 504948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 505df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public int setParameter(int param, int value) throws IllegalStateException { 506948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 507948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = intToByteArray(value); 508948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, v); 509948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 510948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 511948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 512df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Set effect parameter. The parameter is an integer and the value is a 513df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * short integer. 514df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 515df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 5161a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 517948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 518948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(int param, short value) 519df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 520948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 521948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = shortToByteArray(value); 522948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, v); 523948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 524948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 525948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 526df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Set effect parameter. The parameter is an integer and the value is an 527df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of bytes. 528df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 529df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 5301a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 531948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 532948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(int param, byte[] value) 533df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 534948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 535948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, value); 536948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 537948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 538948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 539df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Set effect parameter. The parameter is an array of 1 or 2 integers and 540df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is also an array of 1 or 2 integers 541df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 542df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 5431a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 544948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 545948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(int[] param, int[] value) 546df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 547948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2 || value.length > 2) { 548df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 549948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 550948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 551948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 552948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 553948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 554948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 555948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = intToByteArray(value[0]); 556948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (value.length > 1) { 557948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v2 = intToByteArray(value[1]); 558948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent v = concatArrays(v, v2); 559948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 560948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, v); 561948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 562948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 563948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 564df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Set effect parameter. The parameter is an array of 1 or 2 integers and 565df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is an array of 1 or 2 short integers 566df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 567df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 5681a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 569948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 570948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(int[] param, short[] value) 571df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 572948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2 || value.length > 2) { 573df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 574948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 575948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 576948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 577948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 578948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 579948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 580948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 581948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = shortToByteArray(value[0]); 582948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (value.length > 1) { 583948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v2 = shortToByteArray(value[1]); 584948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent v = concatArrays(v, v2); 585948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 586948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, v); 587948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 588948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 589948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 590df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Set effect parameter. The parameter is an array of 1 or 2 integers and 591df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is an array of bytes 592df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 593df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 5941a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 595948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 596948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(int[] param, byte[] value) 597df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 598948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2) { 599df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 600948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 601948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 602948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 603948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 604948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 605948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 606948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, value); 607948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 608948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 609948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 610948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Get effect parameter. The getParameter method is provided in several 611df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * forms addressing most common parameter formats. This form is the most 612df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * generic one where the parameter and its value are both specified as an 613df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of bytes. The parameter and value type and length are therefore 614948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * totally free. 615df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 616df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param param the identifier of the parameter to set 617df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param value the new value for the specified parameter 618602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * @return the number of meaningful bytes in value array in case of success or 619602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * {@link #ERROR_BAD_VALUE}, {@link #ERROR_NO_MEMORY}, {@link #ERROR_INVALID_OPERATION} 620602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * or {@link #ERROR_DEAD_OBJECT} in case of failure. 621948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 6221a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 623948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 624948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(byte[] param, byte[] value) 625df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 626948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("getParameter()"); 627602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent return native_getParameter(param.length, param, value.length, value); 628948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 629948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 630948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 631df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an integer and the value is an 632df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of bytes. 633df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 634df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 6351a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 636948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 637948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int param, byte[] value) 638df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 639948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 640948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 641948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return getParameter(p, value); 642948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 643948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 644948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 645df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an integer and the value is an 646df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of 1 or 2 integers 647df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 648df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 649602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of success, returns the number of meaningful integers in value array. 6501a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 651948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 652948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int param, int[] value) 653df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 654948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (value.length > 2) { 655df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 656948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 657948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 658948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 659948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = new byte[value.length * 4]; 660948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 661948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int status = getParameter(p, v); 662948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 663602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 4 || status == 8) { 664602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[0] = byteArrayToInt(v); 665602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 8) { 666602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[1] = byteArrayToInt(v, 4); 667602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 668602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status /= 4; 669602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } else { 670602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status = ERROR; 671948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 672948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return status; 673948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 674948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 675948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 676df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an integer and the value is an 677df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of 1 or 2 short integers 678df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 679df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 680602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of success, returns the number of meaningful short integers in value array. 6811a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 682948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 683948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int param, short[] value) 684df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 685948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (value.length > 2) { 686df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 687948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 688948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 689948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 690948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = new byte[value.length * 2]; 691948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 692948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int status = getParameter(p, v); 693948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 694602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 2 || status == 4) { 695602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[0] = byteArrayToShort(v); 696602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 4) { 697602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[1] = byteArrayToShort(v, 2); 698602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 699602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status /= 2; 700602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } else { 701602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status = ERROR; 702948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 703948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return status; 704948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 705948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 706948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 707df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an array of 1 or 2 integers and 708df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is also an array of 1 or 2 integers 709df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 710df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 711602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of success, the returns the number of meaningful integers in value array. 7121a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 713948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 714948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int[] param, int[] value) 715df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 716948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2 || value.length > 2) { 717df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 718948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 719948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 720948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 721948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 722948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 723948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 724948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = new byte[value.length * 4]; 725948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 726948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int status = getParameter(p, v); 727948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 728602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 4 || status == 8) { 729602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[0] = byteArrayToInt(v); 730602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 8) { 731602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[1] = byteArrayToInt(v, 4); 732602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 733602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status /= 4; 734602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } else { 735602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status = ERROR; 736948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 737948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return status; 738948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 739948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 740948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 741df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an array of 1 or 2 integers and 742df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is an array of 1 or 2 short integers 743df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 744df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 745602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of success, returns the number of meaningful short integers in value array. 7461a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 747948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 748948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int[] param, short[] value) 749df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 750948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2 || value.length > 2) { 751df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 752948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 753948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 754948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 755948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 756948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 757948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 758948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = new byte[value.length * 2]; 759948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 760948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int status = getParameter(p, v); 761948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 762602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 2 || status == 4) { 763602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[0] = byteArrayToShort(v); 764602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 4) { 765602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[1] = byteArrayToShort(v, 2); 766602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 767602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status /= 2; 768602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } else { 769602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status = ERROR; 770948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 771948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return status; 772948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 773948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 774948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 775df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an array of 1 or 2 integers and 776df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is an array of bytes 777df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 778df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 7791a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 780948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 781948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int[] param, byte[] value) 782df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 783948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2) { 784df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 785948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 786948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 787948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 788948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 789948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 790948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 791948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 792948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return getParameter(p, value); 793948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 794948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 795948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 796df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Send a command to the effect engine. This method is intended to send 797df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * proprietary commands to a particular effect implementation. 798602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of success, returns the number of meaningful bytes in reply array. 799602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of failure, the returned value is negative and implementation specific. 8001a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 801948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 802948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int command(int cmdCode, byte[] command, byte[] reply) 803df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 804948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("command()"); 805602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent return native_command(cmdCode, command.length, command, reply.length, reply); 806948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 807948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 808df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 809948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Getters 810df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 811948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 812948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 813df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Returns effect unique identifier. This system wide unique identifier can 814df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * be used to attach this effect to a MediaPlayer or an AudioTrack when the 815df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * effect is an auxiliary effect (Reverb) 816df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 817948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @return the effect identifier. 818948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 819948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 820df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public int getId() throws IllegalStateException { 821948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("getId()"); 822948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return mId; 823948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 824948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 825948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 8261a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Returns effect enabled state 827df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 828948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @return true if the effect is enabled, false otherwise. 829948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 830948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 831df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public boolean getEnabled() throws IllegalStateException { 832df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent checkState("getEnabled()"); 833df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return native_getEnabled(); 834948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 835948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 836948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 837948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Checks if this AudioEffect object is controlling the effect engine. 838df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 839df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @return true if this instance has control of effect engine, false 840df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * otherwise. 841948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 842948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 843df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public boolean hasControl() throws IllegalStateException { 844948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("hasControl()"); 845948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return native_hasControl(); 846948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 847948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 848df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 849948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Initialization / configuration 850df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 851948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 852948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Sets the listener AudioEffect notifies when the effect engine is enabled 853948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * or disabled. 854df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 855948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @param listener 856948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 857948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public void setEnableStatusListener(OnEnableStatusChangeListener listener) { 858948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 859948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mEnableStatusChangeListener = listener; 860948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 861948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if ((listener != null) && (mNativeEventHandler == null)) { 862948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent createNativeEventHandler(); 863948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 864948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 865948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 866948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 867df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Sets the listener AudioEffect notifies when the effect engine control is 868df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * taken or returned. 869df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 870948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @param listener 871948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 872948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public void setControlStatusListener(OnControlStatusChangeListener listener) { 873948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 874948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mControlChangeStatusListener = listener; 875948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 876948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if ((listener != null) && (mNativeEventHandler == null)) { 877948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent createNativeEventHandler(); 878948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 879948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 880948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 881948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 882948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Sets the listener AudioEffect notifies when a parameter is changed. 883df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 884948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @param listener 8851a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 886948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 887948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public void setParameterListener(OnParameterChangeListener listener) { 888948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 889948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mParameterChangeListener = listener; 890948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 891948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if ((listener != null) && (mNativeEventHandler == null)) { 892948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent createNativeEventHandler(); 893948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 894948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 895948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 896948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Convenience method for the creation of the native event handler 897948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // It is called only when a non-null event listener is set. 898948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // precondition: 899df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // mNativeEventHandler is null 900948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private void createNativeEventHandler() { 901948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent Looper looper; 902948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if ((looper = Looper.myLooper()) != null) { 903948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mNativeEventHandler = new NativeEventHandler(this, looper); 904948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } else if ((looper = Looper.getMainLooper()) != null) { 905948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mNativeEventHandler = new NativeEventHandler(this, looper); 906948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } else { 907948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mNativeEventHandler = null; 908948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 909948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 910948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 911df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // --------------------------------------------------------- 912948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Interface definitions 913df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 914948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 9152a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent * The OnEnableStatusChangeListener interface defines a method called by the AudioEffect 916df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * when a the enabled state of the effect engine was changed by the controlling application. 917948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 918df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public interface OnEnableStatusChangeListener { 919948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 920df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Called on the listener to notify it that the effect engine has been 921df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * enabled or disabled. 922df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param effect the effect on which the interface is registered. 923df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param enabled new effect state. 924948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 925948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent void onEnableStatusChange(AudioEffect effect, boolean enabled); 926948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 927948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 928948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 929df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * The OnControlStatusChangeListener interface defines a method called by the AudioEffect 930df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * when a the control of the effect engine is gained or lost by the application 931948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 932df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public interface OnControlStatusChangeListener { 933948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 934df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Called on the listener to notify it that the effect engine control 935df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * has been taken or returned. 936df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param effect the effect on which the interface is registered. 937df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param controlGranted true if the application has been granted control of the effect 938df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * engine, false otherwise. 939948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 940948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent void onControlStatusChange(AudioEffect effect, boolean controlGranted); 941948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 942948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 943948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 944df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * The OnParameterChangeListener interface defines a method called by the AudioEffect 945df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * when a parameter is changed in the effect engine by the controlling application. 9461a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 947948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 948df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public interface OnParameterChangeListener { 949948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 950948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Called on the listener to notify it that a parameter value has changed. 951df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param effect the effect on which the interface is registered. 952df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param status status of the set parameter operation. 953df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param param ID of the modified parameter. 954df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param value the new parameter value. 955948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 956df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent void onParameterChange(AudioEffect effect, int status, byte[] param, 957df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent byte[] value); 958948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 959948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 960d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 961d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent // ------------------------------------------------------------------------- 962d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent // Audio Effect Control panel intents 963d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent // ------------------------------------------------------------------------- 964d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 965d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 96692cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Intent to launch an audio effect control panel UI. 96792cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>The goal of this intent is to enable separate implementations of music/media player 96892cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * applications and audio effect control application or services. 96992cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * This will allow platform vendors to offer more advanced control options for standard effects 97092cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * or control for platform specific effects. 971d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The intent carries a number of extras used by the player application to communicate 972d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * necessary pieces of information to the control panel application. 973d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The calling application must use the 974d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * {@link android.app.Activity#startActivityForResult(Intent, int)} method to launch the 975d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * control panel so that its package name is indicated and used by the control panel 976d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * application to keep track of changes for this particular application. 97792cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>The {@link #EXTRA_AUDIO_SESSION} extra will indicate an audio session to which the 978d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * audio effects should be applied. If no audio session is specified, either one of the 979d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * follownig will happen: 98092cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>- If an audio session was previously opened by the calling application with 981d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * {@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} intent, the effect changes will 982d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * be applied to that session. 98392cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>- If no audio session is opened, the changes will be stored in the package specific 98492cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * storage area and applied whenever a new audio session is opened by this application. 98592cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>The {@link #EXTRA_CONTENT_TYPE} extra will help the control panel application 986d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * customize both the UI layout and the default audio effect settings if none are already 987d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * stored for the calling application. 988d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 989d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 990d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL = 991d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent "android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL"; 992d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 993d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 99492cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Intent to signal to the effect control application or service that a new audio session 99592cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * is opened and requires audio effects to be applied. 99692cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>This is different from {@link #ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL} in that no 99792cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * UI should be displayed in this case. Music player applications can broadcast this intent 99892cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * before starting playback to make sure that any audio effect settings previously selected 99992cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * by the user are applied. 1000d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The effect control application receiving this intent will look for previously stored 1001d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * settings for the calling application, create all required audio effects and apply the 1002d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * effect settings to the specified audio session. 1003d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The calling package name is indicated by the {@link #EXTRA_PACKAGE_NAME} extra and the 1004d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * audio session ID by the {@link #EXTRA_AUDIO_SESSION} extra. Both extras are mandatory. 1005d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>If no stored settings are found for the calling application, default settings for the 1006d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * content type indicated by {@link #EXTRA_CONTENT_TYPE} will be applied. The default settings 1007d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * for a given content type are platform specific. 1008d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1009d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1010d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION = 1011d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent "android.media.action.OPEN_AUDIO_EFFECT_CONTROL_SESSION"; 1012d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1013d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 101492cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Intent to signal to the effect control application or service that an audio session 1015d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * is closed and that effects should not be applied anymore. 101692cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>The effect control application receiving this intent will delete all effects on 101792cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * this session and store current settings in package specific storage. 1018d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The calling package name is indicated by the {@link #EXTRA_PACKAGE_NAME} extra and the 1019d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * audio session ID by the {@link #EXTRA_AUDIO_SESSION} extra. Both extras are mandatory. 1020d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>It is good practice for applications to broadcast this intent when music playback stops 1021d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * and/or when exiting to free system resources consumed by audio effect engines. 1022d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1023d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1024d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION = 1025d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent "android.media.action.CLOSE_AUDIO_EFFECT_CONTROL_SESSION"; 1026d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1027d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 102892cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Contains the ID of the audio session the effects should be applied to. 102992cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>This extra is for use with {@link #ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL}, 103092cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * {@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} and 103192cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * {@link #ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION} intents. 1032d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The extra value is of type int and is the audio session ID. 10331a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @see android.media.MediaPlayer#getAudioSessionId() for details on audio sessions. 1034d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1035d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String EXTRA_AUDIO_SESSION = "android.media.extra.AUDIO_SESSION"; 1036d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1037d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 103892cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Contains the package name of the calling application. 103992cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>This extra is for use with {@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} and 1040d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * {@link #ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION} intents. 1041d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The extra value is a string containing the full package name. 1042d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1043d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String EXTRA_PACKAGE_NAME = "android.media.extra.PACKAGE_NAME"; 1044d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1045d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 104692cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Indicates which type of content is played by the application. 104792cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>This extra is for use with {@link #ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL} and 104892cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * {@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} intents. 104992cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>This information is used by the effect control application to customize UI and select 105092cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * appropriate default effect settings. The content type is one of the following: 1051d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <ul> 1052d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <li>{@link #CONTENT_TYPE_MUSIC}</li> 1053d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <li>{@link #CONTENT_TYPE_MOVIE}</li> 1054d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <li>{@link #CONTENT_TYPE_GAME}</li> 1055d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <li>{@link #CONTENT_TYPE_VOICE}</li> 1056d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * </ul> 1057d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * If omitted, the content type defaults to {@link #CONTENT_TYPE_MUSIC}. 1058d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1059d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String EXTRA_CONTENT_TYPE = "android.media.extra.CONTENT_TYPE"; 1060d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1061d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 1062d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * Value for {@link #EXTRA_CONTENT_TYPE} when the type of content played is music 1063d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1064d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final int CONTENT_TYPE_MUSIC = 0; 1065d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 106692cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Value for {@link #EXTRA_CONTENT_TYPE} when the type of content played is video or movie 1067d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1068d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final int CONTENT_TYPE_MOVIE = 1; 1069d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 1070d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * Value for {@link #EXTRA_CONTENT_TYPE} when the type of content played is game audio 1071d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1072d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final int CONTENT_TYPE_GAME = 2; 1073d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 1074d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * Value for {@link #EXTRA_CONTENT_TYPE} when the type of content played is voice audio 1075d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1076d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final int CONTENT_TYPE_VOICE = 3; 1077d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1078d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1079df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // --------------------------------------------------------- 1080948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Inner classes 1081df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 1082948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 1083df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Helper class to handle the forwarding of native events to the appropriate 1084df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * listeners 1085948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 1086df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private class NativeEventHandler extends Handler { 1087948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private AudioEffect mAudioEffect; 1088948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1089948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public NativeEventHandler(AudioEffect ae, Looper looper) { 1090948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent super(looper); 1091948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mAudioEffect = ae; 1092948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1093948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1094948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent @Override 1095948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public void handleMessage(Message msg) { 1096948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (mAudioEffect == null) { 1097948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 1098948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1099df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent switch (msg.what) { 1100948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case NATIVE_EVENT_ENABLED_STATUS: 1101948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent OnEnableStatusChangeListener enableStatusChangeListener = null; 1102948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 1103948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent enableStatusChangeListener = mAudioEffect.mEnableStatusChangeListener; 1104948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1105948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (enableStatusChangeListener != null) { 1106df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent enableStatusChangeListener.onEnableStatusChange( 1107df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent mAudioEffect, (boolean) (msg.arg1 != 0)); 1108948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1109948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 1110948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case NATIVE_EVENT_CONTROL_STATUS: 1111948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent OnControlStatusChangeListener controlStatusChangeListener = null; 1112948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 1113948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent controlStatusChangeListener = mAudioEffect.mControlChangeStatusListener; 1114948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1115948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (controlStatusChangeListener != null) { 1116df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent controlStatusChangeListener.onControlStatusChange( 1117df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent mAudioEffect, (boolean) (msg.arg1 != 0)); 1118948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1119948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 1120948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case NATIVE_EVENT_PARAMETER_CHANGED: 1121948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent OnParameterChangeListener parameterChangeListener = null; 1122948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 1123948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent parameterChangeListener = mAudioEffect.mParameterChangeListener; 1124948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1125948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (parameterChangeListener != null) { 1126df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // arg1 contains offset of parameter value from start of 1127df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // byte array 1128948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int vOffset = msg.arg1; 1129df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent byte[] p = (byte[]) msg.obj; 1130df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // See effect_param_t in EffectApi.h for psize and vsize 1131df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // fields offsets 1132948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int status = byteArrayToInt(p, 0); 1133948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int psize = byteArrayToInt(p, 4); 1134948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int vsize = byteArrayToInt(p, 8); 1135948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] param = new byte[psize]; 1136948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] value = new byte[vsize]; 1137948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent System.arraycopy(p, 12, param, 0, psize); 1138948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent System.arraycopy(p, vOffset, value, 0, vsize); 1139948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1140df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent parameterChangeListener.onParameterChange(mAudioEffect, 1141df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent status, param, value); 1142948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1143948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 1144948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1145df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent default: 1146948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent Log.e(TAG, "handleMessage() Unknown event type: " + msg.what); 1147948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 1148948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1149948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1150948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1151948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1152df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // --------------------------------------------------------- 1153948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Java methods called from the native side 1154df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 1155948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent @SuppressWarnings("unused") 1156df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private static void postEventFromNative(Object effect_ref, int what, 1157df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent int arg1, int arg2, Object obj) { 1158df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent AudioEffect effect = (AudioEffect) ((WeakReference) effect_ref).get(); 1159948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (effect == null) { 1160948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 1161948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1162948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (effect.mNativeEventHandler != null) { 1163df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent Message m = effect.mNativeEventHandler.obtainMessage(what, arg1, 1164df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent arg2, obj); 1165948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect.mNativeEventHandler.sendMessage(m); 1166948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1167948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1168948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1169948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1170df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // --------------------------------------------------------- 1171948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Native methods called from the Java side 1172df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 1173948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1174948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private static native final void native_init(); 1175948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1176df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final int native_setup(Object audioeffect_this, String type, 1177df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent String uuid, int priority, int audioSession, int[] id, Object[] desc); 1178948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1179948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private native final void native_finalize(); 1180948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1181948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private native final void native_release(); 1182948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1183df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final int native_setEnabled(boolean enabled); 1184948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1185df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final boolean native_getEnabled(); 1186948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1187948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private native final boolean native_hasControl(); 1188948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1189df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final int native_setParameter(int psize, byte[] param, 1190df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent int vsize, byte[] value); 1191948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1192df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final int native_getParameter(int psize, byte[] param, 1193602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent int vsize, byte[] value); 1194948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1195df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final int native_command(int cmdCode, int cmdSize, 1196602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent byte[] cmdData, int repSize, byte[] repData); 1197948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1198948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private static native Object[] native_query_effects(); 1199948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12000f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent private static native Object[] native_query_pre_processing(int audioSession); 12010f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 1202df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // --------------------------------------------------------- 1203948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Utility methods 1204df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // ------------------ 1205948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12061a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12071a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12081a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 120917cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public void checkState(String methodName) throws IllegalStateException { 1210948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mStateLock) { 1211948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (mState != STATE_INITIALIZED) { 1212df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throw (new IllegalStateException(methodName 1213df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent + " called on uninitialized AudioEffect.")); 1214948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1215948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1216948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1217948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12181a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12191a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12201a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 122117cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public void checkStatus(int status) { 1222602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (isError(status)) { 1223602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent switch (status) { 1224602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent case AudioEffect.ERROR_BAD_VALUE: 1225602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent throw (new IllegalArgumentException( 1226602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent "AudioEffect: bad parameter value")); 1227602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent case AudioEffect.ERROR_INVALID_OPERATION: 1228602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent throw (new UnsupportedOperationException( 1229602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent "AudioEffect: invalid parameter operation")); 1230602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent default: 1231602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent throw (new RuntimeException("AudioEffect: set/get parameter error")); 1232602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 1233948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1234948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1235948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12361a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12371a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12381a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 1239602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent public static boolean isError(int status) { 1240602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent return (status < 0); 1241602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 1242602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent 1243602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent /** 1244602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * @hide 1245602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent */ 124617cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public int byteArrayToInt(byte[] valueBuf) { 1247948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return byteArrayToInt(valueBuf, 0); 1248948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1249948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1250df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 12511a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12521a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12531a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 125417cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public int byteArrayToInt(byte[] valueBuf, int offset) { 1255948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent ByteBuffer converter = ByteBuffer.wrap(valueBuf); 1256948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.order(ByteOrder.nativeOrder()); 1257948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return converter.getInt(offset); 1258948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1259948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1260948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12611a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12621a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12631a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 126417cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public byte[] intToByteArray(int value) { 1265948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent ByteBuffer converter = ByteBuffer.allocate(4); 1266948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.order(ByteOrder.nativeOrder()); 1267948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.putInt(value); 1268948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return converter.array(); 1269948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1270948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12711a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12721a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12731a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 127417cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public short byteArrayToShort(byte[] valueBuf) { 1275948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return byteArrayToShort(valueBuf, 0); 1276948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1277948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12781a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12791a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12801a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 128117cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public short byteArrayToShort(byte[] valueBuf, int offset) { 1282948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent ByteBuffer converter = ByteBuffer.wrap(valueBuf); 1283948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.order(ByteOrder.nativeOrder()); 1284948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return converter.getShort(offset); 1285948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1286948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1287948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12881a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12891a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12901a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 129117cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public byte[] shortToByteArray(short value) { 1292948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent ByteBuffer converter = ByteBuffer.allocate(2); 1293948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.order(ByteOrder.nativeOrder()); 1294df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent short sValue = (short) value; 1295948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.putShort(sValue); 1296948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return converter.array(); 1297948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1298948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12991a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 13001a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 13011a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 130217cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public byte[] concatArrays(byte[]... arrays) { 1303948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int len = 0; 1304948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent for (byte[] a : arrays) { 1305948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent len += a.length; 1306948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1307948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] b = new byte[len]; 1308948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1309948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int offs = 0; 1310948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent for (byte[] a : arrays) { 1311948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent System.arraycopy(a, 0, b, offs, a.length); 1312948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent offs += a.length; 1313948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1314948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return b; 1315948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1316948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 1317