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.lang.ref.WeakReference; 26948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentimport java.nio.ByteOrder; 27948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentimport java.nio.ByteBuffer; 28948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentimport java.util.UUID; 29948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 30948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent/** 311a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * AudioEffect is the base class for controlling audio effects provided by the android audio 321a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * framework. 331a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <p>Applications should not use the AudioEffect class directly but one of its derived classes to 341a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * control specific effects: 351a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <ul> 361a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li> {@link android.media.audiofx.Equalizer}</li> 371a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li> {@link android.media.audiofx.Virtualizer}</li> 381a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li> {@link android.media.audiofx.BassBoost}</li> 391a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li> {@link android.media.audiofx.PresetReverb}</li> 401a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li> {@link android.media.audiofx.EnvironmentalReverb}</li> 411a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * </ul> 4262f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * <p>To apply the audio effect to a specific AudioTrack or MediaPlayer instance, 431a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * the application must specify the audio session ID of that instance when creating the AudioEffect. 441a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * (see {@link android.media.MediaPlayer#getAudioSessionId()} for details on audio sessions). 4562f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * <p>NOTE: attaching insert effects (equalizer, bass boost, virtualizer) to the global audio output 4662f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * mix by use of session 0 is deprecated. 471a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <p>Creating an AudioEffect object will create the corresponding effect engine in the audio 481a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * framework if no instance of the same effect type exists in the specified audio session. 491a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * If one exists, this instance will be used. 501a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <p>The application creating the AudioEffect object (or a derived class) will either receive 511a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * control of the effect engine or not depending on the priority parameter. If priority is higher 521a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * than the priority used by the current effect engine owner, the control will be transfered to the 531a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * new object. Otherwise control will remain with the previous object. In this case, the new 541a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * application will be notified of changes in effect engine state or control ownership by the 551a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * appropiate listener. 56948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 571a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent 58df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurentpublic class AudioEffect { 59948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent static { 60948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent System.loadLibrary("audioeffect_jni"); 61948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent native_init(); 62948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 63948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 64948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private final static String TAG = "AudioEffect-JAVA"; 65948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 660f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent // effect type UUIDs are taken from hardware/libhardware/include/hardware/audio_effect.h 670f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 68948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 69df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * The following UUIDs define effect types corresponding to standard audio 70df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * effects whose implementation and interface conform to the OpenSL ES 71df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * specification. The definitions match the corresponding interface IDs in 72df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * OpenSLES_IID.h 73948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 74df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 7580569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * UUID for environmental reverberation effect 76df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 77df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_ENV_REVERB = UUID 78df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("c2e5d5f0-94bd-4763-9cac-4e234d06839e"); 79df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 8080569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * UUID for preset reverberation effect 81df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 82df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_PRESET_REVERB = UUID 83df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("47382d60-ddd8-11db-bf3a-0002a5d5c51b"); 84df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 85df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * UUID for equalizer effect 86df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 87df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_EQUALIZER = UUID 88df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("0bed4300-ddd6-11db-8f34-0002a5d5c51b"); 89df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 90df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * UUID for bass boost effect 91df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 92df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_BASS_BOOST = UUID 93df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("0634f220-ddd4-11db-a0fc-0002a5d5c51b"); 94df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 95df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * UUID for virtualizer effect 96df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 97df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_VIRTUALIZER = UUID 98df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("37cc2c00-dddd-11db-8577-0002a5d5c51b"); 99948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 100948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 10180569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * UUIDs for effect types not covered by OpenSL ES. 10280569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi */ 10380569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi /** 10480569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * UUID for Automatic Gain Control (AGC) 1050f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */ 1060f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent public static final UUID EFFECT_TYPE_AGC = UUID 1070f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent .fromString("0a8abfe0-654c-11e0-ba26-0002a5d5c51b"); 1080f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 1090f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent /** 11080569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * UUID for Acoustic Echo Canceler (AEC) 1110f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */ 1120f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent public static final UUID EFFECT_TYPE_AEC = UUID 1130f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent .fromString("7b491460-8d4d-11e0-bd61-0002a5d5c51b"); 1140f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 1150f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent /** 11680569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * UUID for Noise Suppressor (NS) 1170f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */ 1180f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent public static final UUID EFFECT_TYPE_NS = UUID 1190f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent .fromString("58b4b260-8e06-11e0-aa8e-0002a5d5c51b"); 1200f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 1210f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent /** 122d69e4e14226258fd103d0b9c1c5b4d8529e6a3ecJean-Michel Trivi * UUID for Loudness Enhancer 123d69e4e14226258fd103d0b9c1c5b4d8529e6a3ecJean-Michel Trivi */ 124d69e4e14226258fd103d0b9c1c5b4d8529e6a3ecJean-Michel Trivi public static final UUID EFFECT_TYPE_LOUDNESS_ENHANCER = UUID 125d69e4e14226258fd103d0b9c1c5b4d8529e6a3ecJean-Michel Trivi .fromString("fe3199be-aed0-413f-87bb-11260eb63cf1"); 126d69e4e14226258fd103d0b9c1c5b4d8529e6a3ecJean-Michel Trivi 127d69e4e14226258fd103d0b9c1c5b4d8529e6a3ecJean-Michel Trivi /** 128df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Null effect UUID. Used when the UUID for effect type of 1291a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 130df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 131df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final UUID EFFECT_TYPE_NULL = UUID 132df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent .fromString("ec7178ec-e5e1-4432-a3f4-4657e6795210"); 133df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 134df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 135df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * State of an AudioEffect object that was not successfully initialized upon 136df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * creation 1371a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 138948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 139948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public static final int STATE_UNINITIALIZED = 0; 140948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 141948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * State of an AudioEffect object that is ready to be used. 1421a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 143948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 144df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int STATE_INITIALIZED = 1; 145948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 146df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // to keep in sync with 1472a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent // frameworks/base/include/media/AudioEffect.h 148948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 1492a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent * Event id for engine control ownership change notification. 1501a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 151948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 1522a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent public static final int NATIVE_EVENT_CONTROL_STATUS = 0; 153948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 1542a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent * Event id for engine state change notification. 1551a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 156948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 1572a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent public static final int NATIVE_EVENT_ENABLED_STATUS = 1; 158948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 159948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Event id for engine parameter change notification. 1601a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 161948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 16217cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public static final int NATIVE_EVENT_PARAMETER_CHANGED = 2; 163948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 164df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 165df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Successful operation. 166df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 167df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int SUCCESS = 0; 168df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 169df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Unspecified error. 170df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 171df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR = -1; 172df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 173ed6eae420fd60dcb7d90f54c3116959b75bd6276Glenn Kasten * Internal operation status. Not returned by any method. 174df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 175df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ALREADY_EXISTS = -2; 176df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 177df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Operation failed due to bad object initialization. 178df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 179df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR_NO_INIT = -3; 180df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 181df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Operation failed due to bad parameter value. 182df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 183df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR_BAD_VALUE = -4; 184df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 185df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Operation failed because it was requested in wrong state. 186df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 187df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR_INVALID_OPERATION = -5; 188df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 189df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Operation failed due to lack of memory. 190df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 191df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR_NO_MEMORY = -6; 192df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 193df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Operation failed due to dead remote object. 194df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 195df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final int ERROR_DEAD_OBJECT = -7; 196df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 197df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 1981a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * The effect descriptor contains information on a particular effect implemented in the 1991a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * audio framework:<br> 200df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * <ul> 2011d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * <li>type: UUID identifying the effect type. May be one of: 2021d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * {@link AudioEffect#EFFECT_TYPE_AEC}, {@link AudioEffect#EFFECT_TYPE_AGC}, 2031d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * {@link AudioEffect#EFFECT_TYPE_BASS_BOOST}, {@link AudioEffect#EFFECT_TYPE_ENV_REVERB}, 2041d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * {@link AudioEffect#EFFECT_TYPE_EQUALIZER}, {@link AudioEffect#EFFECT_TYPE_NS}, 2051d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * {@link AudioEffect#EFFECT_TYPE_PRESET_REVERB}, {@link AudioEffect#EFFECT_TYPE_VIRTUALIZER}. 2061d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * </li> 2071a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li>uuid: UUID for this particular implementation</li> 2081d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * <li>connectMode: {@link #EFFECT_INSERT} or {@link #EFFECT_AUXILIARY}</li> 2091a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li>name: human readable effect name</li> 2101a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <li>implementor: human readable effect implementor name</li> 211df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * </ul> 2121a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * The method {@link #queryEffects()} returns an array of Descriptors to facilitate effects 2131a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * enumeration. 214df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 215df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static class Descriptor { 216df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 217df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public Descriptor() { 218df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent } 219df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 2201d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main /** 2211d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * @param type UUID identifying the effect type. May be one of: 2221d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * {@link AudioEffect#EFFECT_TYPE_AEC}, {@link AudioEffect#EFFECT_TYPE_AGC}, 2231d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * {@link AudioEffect#EFFECT_TYPE_BASS_BOOST}, {@link AudioEffect#EFFECT_TYPE_ENV_REVERB}, 2241d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * {@link AudioEffect#EFFECT_TYPE_EQUALIZER}, {@link AudioEffect#EFFECT_TYPE_NS}, 2251d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * {@link AudioEffect#EFFECT_TYPE_PRESET_REVERB}, 2261d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * {@link AudioEffect#EFFECT_TYPE_VIRTUALIZER}. 2271d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * @param uuid UUID for this particular implementation 2281d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * @param connectMode {@link #EFFECT_INSERT} or {@link #EFFECT_AUXILIARY} 2291d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * @param name human readable effect name 2301d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * @param implementor human readable effect implementor name 2311d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * 2321d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main */ 233df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public Descriptor(String type, String uuid, String connectMode, 234df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent String name, String implementor) { 2351a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent this.type = UUID.fromString(type); 2361a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent this.uuid = UUID.fromString(uuid); 2371a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent this.connectMode = connectMode; 2381a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent this.name = name; 2391a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent this.implementor = implementor; 240df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent } 241df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 2421a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 24380569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * Indicates the generic type of the effect (Equalizer, Bass boost ...). 24480569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * One of {@link AudioEffect#EFFECT_TYPE_AEC}, 24580569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * {@link AudioEffect#EFFECT_TYPE_AGC}, {@link AudioEffect#EFFECT_TYPE_BASS_BOOST}, 24680569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * {@link AudioEffect#EFFECT_TYPE_ENV_REVERB}, {@link AudioEffect#EFFECT_TYPE_EQUALIZER}, 24780569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * {@link AudioEffect#EFFECT_TYPE_NS}, {@link AudioEffect#EFFECT_TYPE_PRESET_REVERB} 24880569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * or {@link AudioEffect#EFFECT_TYPE_VIRTUALIZER}.<br> 24980569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * For reverberation, bass boost, EQ and virtualizer, the UUID 25080569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * corresponds to the OpenSL ES Interface ID. 2511a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 2521a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent public UUID type; 2531a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 2541a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Indicates the particular implementation of the effect in that type. Several effects 2551a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * can have the same type but this uuid is unique to a given implementation. 2561a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 2571a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent public UUID uuid; 2581a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 2591d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * Indicates if the effect is of insert category {@link #EFFECT_INSERT} or auxiliary 2601d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * category {@link #EFFECT_AUXILIARY}. 2611d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * Insert effects (typically an {@link Equalizer}) are applied 2621a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * to the entire audio source and usually not shared by several sources. Auxiliary effects 2631a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * (typically a reverberator) are applied to part of the signal (wet) and the effect output 2641a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * is added to the original signal (dry). 2651d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * Audio pre processing are applied to audio captured on a particular 2661d154187a99d5ad8dd33d47173cf6a4456276e76Scott Main * {@link android.media.AudioRecord}. 2671a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 2681a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent public String connectMode; 2691a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 2701a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Human readable effect name 2711a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 2721a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent public String name; 2731a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 2741a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Human readable effect implementor name 2751a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 2761a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent public String implementor; 277df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent }; 278df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 279df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 280df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Effect connection mode is insert. Specifying an audio session ID when creating the effect 281df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * will insert this effect after all players in the same audio session. 282df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 283df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final String EFFECT_INSERT = "Insert"; 284df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent /** 285df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Effect connection mode is auxiliary. 286df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * <p>Auxiliary effects must be created on session 0 (global output mix). In order for a 287df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * MediaPlayer or AudioTrack to be fed into this effect, they must be explicitely attached to 288df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * this effect and a send level must be specified. 289df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * <p>Use the effect ID returned by {@link #getId()} to designate this particular effect when 290df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * attaching it to the MediaPlayer or AudioTrack. 291df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent */ 292df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public static final String EFFECT_AUXILIARY = "Auxiliary"; 2930f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent /** 2940f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * Effect connection mode is pre processing. 2950f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * The audio pre processing effects are attached to an audio input (AudioRecord). 2960f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @hide 2970f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */ 2980f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent public static final String EFFECT_PRE_PROCESSING = "Pre Processing"; 299948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 300df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 301948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Member variables 302df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 303948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 304948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Indicates the state of the AudioEffect instance 305948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 30617cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private int mState = STATE_UNINITIALIZED; 307948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 308948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Lock to synchronize access to mState 309948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 31017cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private final Object mStateLock = new Object(); 311948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 312948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * System wide unique effect ID 313948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 31417cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private int mId; 315948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 316948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // accessed by native methods 317ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat private long mNativeAudioEffect; 318ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat private long mJniData; 319948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 320948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 321948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Effect descriptor 322948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 323948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private Descriptor mDescriptor; 324948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 325948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 326948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Listener for effect engine state change notifications. 327df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 328df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setEnableStatusListener(OnEnableStatusChangeListener) 329948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 33017cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private OnEnableStatusChangeListener mEnableStatusChangeListener = null; 331948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 332948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Listener for effect engine control ownership change notifications. 333df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 334df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setControlStatusListener(OnControlStatusChangeListener) 335948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 33617cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private OnControlStatusChangeListener mControlChangeStatusListener = null; 337948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 338948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Listener for effect engine control ownership change notifications. 339df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 340df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameterListener(OnParameterChangeListener) 341948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 34217cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent private OnParameterChangeListener mParameterChangeListener = null; 343948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 344948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Lock to protect listeners updates against event notifications 3451a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 346948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 34717cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public final Object mListenerLock = new Object(); 348948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 349948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Handler for events coming from the native code 3501a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 351948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 35217cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public NativeEventHandler mNativeEventHandler = null; 353948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 354df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 355948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Constructor, Finalize 356df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 357948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 358948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Class constructor. 359df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 360df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param type type of effect engine created. See {@link #EFFECT_TYPE_ENV_REVERB}, 361df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * {@link #EFFECT_TYPE_EQUALIZER} ... Types corresponding to 362df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * built-in effects are defined by AudioEffect class. Other types 363df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * can be specified provided they correspond an existing OpenSL 364df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * ES interface ID and the corresponsing effect is available on 365df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the platform. If an unspecified effect type is requested, the 366df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * constructor with throw the IllegalArgumentException. This 367df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * parameter can be set to {@link #EFFECT_TYPE_NULL} in which 368df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * case only the uuid will be used to select the effect. 369df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param uuid unique identifier of a particular effect implementation. 370df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Must be specified if the caller wants to use a particular 371df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * implementation of an effect type. This parameter can be set to 372df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * {@link #EFFECT_TYPE_NULL} in which case only the type will 373df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * be used to select the effect. 374df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param priority the priority level requested by the application for 375df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * controlling the effect engine. As the same effect engine can 376df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * be shared by several applications, this parameter indicates 377df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * how much the requesting application needs control of effect 378df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * parameters. The normal priority is 0, above normal is a 379df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * positive number, below normal a negative number. 38062f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * @param audioSession system wide unique audio session identifier. 38162f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * The effect will be attached to the MediaPlayer or AudioTrack in 38262f3617f2f4016ad2f59635d5156d64872989880Eric Laurent * the same audio session. 383948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 384948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws java.lang.IllegalArgumentException 385948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws java.lang.UnsupportedOperationException 386948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws java.lang.RuntimeException 3871a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 388948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 389948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 390948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public AudioEffect(UUID type, UUID uuid, int priority, int audioSession) 391df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalArgumentException, UnsupportedOperationException, 392df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent RuntimeException { 393948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int[] id = new int[1]; 394948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent Descriptor[] desc = new Descriptor[1]; 395948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // native initialization 396948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int initResult = native_setup(new WeakReference<AudioEffect>(this), 397df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent type.toString(), uuid.toString(), priority, audioSession, id, 398df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent desc); 399948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (initResult != SUCCESS && initResult != ALREADY_EXISTS) { 400df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent Log.e(TAG, "Error code " + initResult 401df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent + " when initializing AudioEffect."); 402948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent switch (initResult) { 403df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent case ERROR_BAD_VALUE: 404df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throw (new IllegalArgumentException("Effect type: " + type 405df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent + " not supported.")); 406df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent case ERROR_INVALID_OPERATION: 407df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throw (new UnsupportedOperationException( 408df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent "Effect library not loaded")); 409948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent default: 410df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throw (new RuntimeException( 411df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent "Cannot initialize effect engine for type: " + type 4125bb8f80fc4a72ad70d7d38cdc9f7988edce476e4Glenn Kasten + " Error: " + initResult)); 413948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 414948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 415948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mId = id[0]; 416948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mDescriptor = desc[0]; 417948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mStateLock) { 418948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mState = STATE_INITIALIZED; 419948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 420948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 421948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 422948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 423df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Releases the native AudioEffect resources. It is a good practice to 424df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * release the effect engine when not in use as control can be returned to 425df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * other applications or the native resources released. 426948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 427948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public void release() { 428948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mStateLock) { 429948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent native_release(); 430948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mState = STATE_UNINITIALIZED; 431948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 432948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 433948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 434948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent @Override 435948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent protected void finalize() { 436948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent native_finalize(); 437948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 438948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 439948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 440948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Get the effect descriptor. 441df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 4421a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @see android.media.audiofx.AudioEffect.Descriptor 443948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 444948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 445df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public Descriptor getDescriptor() throws IllegalStateException { 446948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("getDescriptor()"); 447948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return mDescriptor; 448948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 449948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 450df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 451948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Effects Enumeration 452df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 453948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 454948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 455948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Query all effects available on the platform. Returns an array of 4561a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * {@link android.media.audiofx.AudioEffect.Descriptor} objects 457948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 458948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 459948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 460948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 461948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent static public Descriptor[] queryEffects() { 462df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return (Descriptor[]) native_query_effects(); 463948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 464948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 4650f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent /** 46680569f7ff7db28ce98dde6e22bb4521ddbe5490aJean-Michel Trivi * Query all audio pre-processing effects applied to the AudioRecord with the supplied 4670f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * audio session ID. Returns an array of {@link android.media.audiofx.AudioEffect.Descriptor} 4680f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * objects. 4690f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @param audioSession system wide unique audio session identifier. 4700f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @throws IllegalStateException 4710f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @hide 4720f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */ 4730f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 4740f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent static public Descriptor[] queryPreProcessings(int audioSession) { 4750f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent return (Descriptor[]) native_query_pre_processing(audioSession); 4760f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 477855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent 478855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent /** 479855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent * Checks if the device implements the specified effect type. 480855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent * @param type the requested effect type. 481855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent * @return true if the device implements the specified effect type, false otherwise. 482855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent * @hide 483855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent */ 484855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent public static boolean isEffectTypeAvailable(UUID type) { 485855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent AudioEffect.Descriptor[] desc = AudioEffect.queryEffects(); 486de709869ae10263c4c325aaa72cdc6aada0ae8d5Jason Parks if (desc == null) { 487de709869ae10263c4c325aaa72cdc6aada0ae8d5Jason Parks return false; 488de709869ae10263c4c325aaa72cdc6aada0ae8d5Jason Parks } 489de709869ae10263c4c325aaa72cdc6aada0ae8d5Jason Parks 490855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent for (int i = 0; i < desc.length; i++) { 491855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent if (desc[i].type.equals(type)) { 492855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent return true; 493855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent } 494855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent } 495855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent return false; 496855255d89fe0a14abe796355bebb64031ec6ff47Eric Laurent } 4970f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 498df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 499948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Control methods 500df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 501948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 502948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 5031a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Enable or disable the effect. 5041a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Creating an audio effect does not automatically apply this effect on the audio source. It 5051a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * creates the resources necessary to process this effect but the audio signal is still bypassed 5061a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * through the effect engine. Calling this method will make that the effect is actually applied 5071a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * or not to the audio content being played in the corresponding audio session. 508df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 509df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param enabled the requested enable state 510df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @return {@link #SUCCESS} in case of success, {@link #ERROR_INVALID_OPERATION} 511df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * or {@link #ERROR_DEAD_OBJECT} in case of failure. 512948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 513948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 514df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public int setEnabled(boolean enabled) throws IllegalStateException { 515df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent checkState("setEnabled()"); 516df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return native_setEnabled(enabled); 517948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 518948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 519948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 520948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Set effect parameter. The setParameter method is provided in several 521df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * forms addressing most common parameter formats. This form is the most 522df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * generic one where the parameter and its value are both specified as an 523df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of bytes. The parameter and value type and length are therefore 524df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * totally free. For standard effect defined by OpenSL ES, the parameter 525df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * format and values must match the definitions in the corresponding OpenSL 526df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * ES interface. 527948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 528df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param param the identifier of the parameter to set 529df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param value the new value for the specified parameter 530df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @return {@link #SUCCESS} in case of success, {@link #ERROR_BAD_VALUE}, 531df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * {@link #ERROR_NO_MEMORY}, {@link #ERROR_INVALID_OPERATION} or 532df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * {@link #ERROR_DEAD_OBJECT} in case of failure 533948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 5341a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 535948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 536948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(byte[] param, byte[] value) 537df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 538948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("setParameter()"); 539948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return native_setParameter(param.length, param, value.length, value); 540948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 541948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 542948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 543948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Set effect parameter. The parameter and its value are integers. 544df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 545df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 5461a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 547948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 548df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public int setParameter(int param, int value) throws IllegalStateException { 549948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 550948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = intToByteArray(value); 551948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, v); 552948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 553948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 554948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 555df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Set effect parameter. The parameter is an integer and the value is a 556df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * short integer. 557df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 558df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 5591a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 560948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 561948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(int param, short value) 562df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 563948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 564948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = shortToByteArray(value); 565948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, v); 566948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 567948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 568948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 569df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Set effect parameter. The parameter is an integer and the value is an 570df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of bytes. 571df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 572df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 5731a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 574948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 575948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(int param, byte[] value) 576df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 577948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 578948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, value); 579948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 580948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 581948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 582df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Set effect parameter. The parameter is an array of 1 or 2 integers and 583df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is also an array of 1 or 2 integers 584df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 585df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 5861a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 587948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 588948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(int[] param, int[] value) 589df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 590948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2 || value.length > 2) { 591df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 592948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 593948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 594948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 595948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 596948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 597948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 598948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = intToByteArray(value[0]); 599948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (value.length > 1) { 600948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v2 = intToByteArray(value[1]); 601948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent v = concatArrays(v, v2); 602948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 603948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, v); 604948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 605948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 606948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 607df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Set effect parameter. The parameter is an array of 1 or 2 integers and 608df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is an array of 1 or 2 short integers 609df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 610df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 6111a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 612948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 613948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(int[] param, short[] value) 614df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 615948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2 || value.length > 2) { 616df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 617948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 618948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 619948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 620948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 621948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 622948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 623948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 624948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = shortToByteArray(value[0]); 625948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (value.length > 1) { 626948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v2 = shortToByteArray(value[1]); 627948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent v = concatArrays(v, v2); 628948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 629948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, v); 630948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 631948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 632948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 633df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Set effect parameter. The parameter is an array of 1 or 2 integers and 634df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is an array of bytes 635df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 636df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #setParameter(byte[], byte[]) 6371a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 638948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 639948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int setParameter(int[] param, byte[] value) 640df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 641948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2) { 642df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 643948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 644948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 645948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 646948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 647948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 648948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 649948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return setParameter(p, value); 650948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 651948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 652948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 653948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Get effect parameter. The getParameter method is provided in several 654df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * forms addressing most common parameter formats. This form is the most 655df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * generic one where the parameter and its value are both specified as an 656df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of bytes. The parameter and value type and length are therefore 657948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * totally free. 658df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 659df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param param the identifier of the parameter to set 660df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param value the new value for the specified parameter 661602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * @return the number of meaningful bytes in value array in case of success or 662602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * {@link #ERROR_BAD_VALUE}, {@link #ERROR_NO_MEMORY}, {@link #ERROR_INVALID_OPERATION} 663602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * or {@link #ERROR_DEAD_OBJECT} in case of failure. 664948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 6651a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 666948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 667948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(byte[] param, byte[] value) 668df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 669948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("getParameter()"); 670602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent return native_getParameter(param.length, param, value.length, value); 671948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 672948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 673948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 674df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an integer and the value is an 675df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of bytes. 676df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 677df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 6781a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 679948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 680948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int param, byte[] value) 681df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 682948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 683948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 684948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return getParameter(p, value); 685948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 686948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 687948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 688df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an integer and the value is an 689df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of 1 or 2 integers 690df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 691df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 692602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of success, returns the number of meaningful integers in value array. 6931a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 694948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 695948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int param, int[] value) 696df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 697948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (value.length > 2) { 698df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 699948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 700948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 701948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 702948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = new byte[value.length * 4]; 703948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 704948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int status = getParameter(p, v); 705948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 706602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 4 || status == 8) { 707602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[0] = byteArrayToInt(v); 708602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 8) { 709602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[1] = byteArrayToInt(v, 4); 710602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 711602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status /= 4; 712602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } else { 713602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status = ERROR; 714948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 715948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return status; 716948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 717948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 718948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 719df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an integer and the value is an 720df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * array of 1 or 2 short integers 721df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 722df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 723602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of success, returns the number of meaningful short integers in value array. 7241a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 725948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 726948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int param, short[] value) 727df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 728948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (value.length > 2) { 729df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 730948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 731948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param); 732948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 733948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = new byte[value.length * 2]; 734948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 735948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int status = getParameter(p, v); 736948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 737602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 2 || status == 4) { 738602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[0] = byteArrayToShort(v); 739602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 4) { 740602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[1] = byteArrayToShort(v, 2); 741602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 742602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status /= 2; 743602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } else { 744602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status = ERROR; 745948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 746948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return status; 747948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 748948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 749948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 750df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an array of 1 or 2 integers and 751df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is also an array of 1 or 2 integers 752df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 753df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 754602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of success, the returns the number of meaningful integers in value array. 7551a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 756948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 757948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int[] param, int[] value) 758df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 759948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2 || value.length > 2) { 760df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 761948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 762948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 763948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 764948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 765948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 766948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 767948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = new byte[value.length * 4]; 768948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 769948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int status = getParameter(p, v); 770948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 771602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 4 || status == 8) { 772602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[0] = byteArrayToInt(v); 773602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 8) { 774602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[1] = byteArrayToInt(v, 4); 775602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 776602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status /= 4; 777602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } else { 778602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status = ERROR; 779948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 780948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return status; 781948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 782948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 783948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 784df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an array of 1 or 2 integers and 785df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is an array of 1 or 2 short integers 786df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 787df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 788602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of success, returns the number of meaningful short integers in value array. 7891a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 790948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 791948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int[] param, short[] value) 792df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 793948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2 || value.length > 2) { 794df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 795948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 796948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 797948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 798948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 799948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 800948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 801948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] v = new byte[value.length * 2]; 802948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 803948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int status = getParameter(p, v); 804948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 805602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 2 || status == 4) { 806602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[0] = byteArrayToShort(v); 807602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (status == 4) { 808602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent value[1] = byteArrayToShort(v, 2); 809602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 810602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status /= 2; 811602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } else { 812602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent status = ERROR; 813948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 814948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return status; 815948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 816948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 817948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 818df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Get effect parameter. The parameter is an array of 1 or 2 integers and 819df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * the value is an array of bytes 820df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 821df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @see #getParameter(byte[], byte[]) 8221a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 823948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 824948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int getParameter(int[] param, byte[] value) 825df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 826948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 2) { 827df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return ERROR_BAD_VALUE; 828948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 829948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p = intToByteArray(param[0]); 830948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (param.length > 1) { 831948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] p2 = intToByteArray(param[1]); 832948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = concatArrays(p, p2); 833948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 834948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 835948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return getParameter(p, value); 836948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 837948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 838948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 839df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Send a command to the effect engine. This method is intended to send 840df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * proprietary commands to a particular effect implementation. 841602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of success, returns the number of meaningful bytes in reply array. 842602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * In case of failure, the returned value is negative and implementation specific. 8431a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 844948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 845948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public int command(int cmdCode, byte[] command, byte[] reply) 846df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throws IllegalStateException { 847948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("command()"); 848602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent return native_command(cmdCode, command.length, command, reply.length, reply); 849948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 850948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 851df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 852948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Getters 853df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 854948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 855948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 856df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Returns effect unique identifier. This system wide unique identifier can 857df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * be used to attach this effect to a MediaPlayer or an AudioTrack when the 858df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * effect is an auxiliary effect (Reverb) 859df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 860948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @return the effect identifier. 861948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 862948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 863df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public int getId() throws IllegalStateException { 864948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("getId()"); 865948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return mId; 866948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 867948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 868948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 8691a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * Returns effect enabled state 870df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 871948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @return true if the effect is enabled, false otherwise. 872948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 873948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 874df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public boolean getEnabled() throws IllegalStateException { 875df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent checkState("getEnabled()"); 876df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return native_getEnabled(); 877948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 878948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 879948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 880948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Checks if this AudioEffect object is controlling the effect engine. 881df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 882df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @return true if this instance has control of effect engine, false 883df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * otherwise. 884948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @throws IllegalStateException 885948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 886df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public boolean hasControl() throws IllegalStateException { 887948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent checkState("hasControl()"); 888948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return native_hasControl(); 889948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 890948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 891df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------------------------------------------------------------- 892948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Initialization / configuration 893df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 894948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 895948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Sets the listener AudioEffect notifies when the effect engine is enabled 896948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * or disabled. 897df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 898948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @param listener 899948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 900948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public void setEnableStatusListener(OnEnableStatusChangeListener listener) { 901948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 902948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mEnableStatusChangeListener = listener; 903948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 904948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if ((listener != null) && (mNativeEventHandler == null)) { 905948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent createNativeEventHandler(); 906948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 907948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 908948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 909948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 910df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Sets the listener AudioEffect notifies when the effect engine control is 911df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * taken or returned. 912df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 913948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @param listener 914948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 915948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public void setControlStatusListener(OnControlStatusChangeListener listener) { 916948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 917948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mControlChangeStatusListener = listener; 918948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 919948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if ((listener != null) && (mNativeEventHandler == null)) { 920948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent createNativeEventHandler(); 921948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 922948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 923948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 924948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 925948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Sets the listener AudioEffect notifies when a parameter is changed. 926df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * 927948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * @param listener 9281a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 929948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 930948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public void setParameterListener(OnParameterChangeListener listener) { 931948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 932948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mParameterChangeListener = listener; 933948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 934948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if ((listener != null) && (mNativeEventHandler == null)) { 935948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent createNativeEventHandler(); 936948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 937948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 938948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 939948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Convenience method for the creation of the native event handler 940948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // It is called only when a non-null event listener is set. 941948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // precondition: 942df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // mNativeEventHandler is null 943948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private void createNativeEventHandler() { 944948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent Looper looper; 945948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if ((looper = Looper.myLooper()) != null) { 946948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mNativeEventHandler = new NativeEventHandler(this, looper); 947948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } else if ((looper = Looper.getMainLooper()) != null) { 948948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mNativeEventHandler = new NativeEventHandler(this, looper); 949948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } else { 950948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mNativeEventHandler = null; 951948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 952948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 953948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 954df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // --------------------------------------------------------- 955948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Interface definitions 956df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 957948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 9582a6b80bc65c4782b5a7168b300e1dc5ec9f617eeEric Laurent * The OnEnableStatusChangeListener interface defines a method called by the AudioEffect 959df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * when a the enabled state of the effect engine was changed by the controlling application. 960948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 961df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public interface OnEnableStatusChangeListener { 962948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 963df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Called on the listener to notify it that the effect engine has been 964df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * enabled or disabled. 965df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param effect the effect on which the interface is registered. 966df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param enabled new effect state. 967948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 968948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent void onEnableStatusChange(AudioEffect effect, boolean enabled); 969948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 970948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 971948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 972df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * The OnControlStatusChangeListener interface defines a method called by the AudioEffect 973df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * when a the control of the effect engine is gained or lost by the application 974948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 975df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public interface OnControlStatusChangeListener { 976948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 977df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Called on the listener to notify it that the effect engine control 978df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * has been taken or returned. 979df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param effect the effect on which the interface is registered. 980df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param controlGranted true if the application has been granted control of the effect 981df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * engine, false otherwise. 982948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 983948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent void onControlStatusChange(AudioEffect effect, boolean controlGranted); 984948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 985948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 986948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 987df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * The OnParameterChangeListener interface defines a method called by the AudioEffect 988df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * when a parameter is changed in the effect engine by the controlling application. 9891a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 990948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 991df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent public interface OnParameterChangeListener { 992948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 993948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Called on the listener to notify it that a parameter value has changed. 994df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param effect the effect on which the interface is registered. 995df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param status status of the set parameter operation. 996df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param param ID of the modified parameter. 997df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * @param value the new parameter value. 998948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 999df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent void onParameterChange(AudioEffect effect, int status, byte[] param, 1000df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent byte[] value); 1001948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1002948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1003d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1004d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent // ------------------------------------------------------------------------- 1005d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent // Audio Effect Control panel intents 1006d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent // ------------------------------------------------------------------------- 1007d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1008d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 100992cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Intent to launch an audio effect control panel UI. 101092cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>The goal of this intent is to enable separate implementations of music/media player 101192cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * applications and audio effect control application or services. 101292cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * This will allow platform vendors to offer more advanced control options for standard effects 101392cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * or control for platform specific effects. 1014d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The intent carries a number of extras used by the player application to communicate 1015d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * necessary pieces of information to the control panel application. 1016d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The calling application must use the 1017d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * {@link android.app.Activity#startActivityForResult(Intent, int)} method to launch the 1018d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * control panel so that its package name is indicated and used by the control panel 1019d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * application to keep track of changes for this particular application. 102092cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>The {@link #EXTRA_AUDIO_SESSION} extra will indicate an audio session to which the 1021d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * audio effects should be applied. If no audio session is specified, either one of the 1022d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * follownig will happen: 102392cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>- If an audio session was previously opened by the calling application with 1024d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * {@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} intent, the effect changes will 1025d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * be applied to that session. 102692cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>- If no audio session is opened, the changes will be stored in the package specific 102792cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * storage area and applied whenever a new audio session is opened by this application. 102892cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>The {@link #EXTRA_CONTENT_TYPE} extra will help the control panel application 1029d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * customize both the UI layout and the default audio effect settings if none are already 1030d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * stored for the calling application. 1031d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1032d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 1033d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL = 1034d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent "android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL"; 1035d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1036d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 103792cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Intent to signal to the effect control application or service that a new audio session 103892cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * is opened and requires audio effects to be applied. 103992cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>This is different from {@link #ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL} in that no 104092cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * UI should be displayed in this case. Music player applications can broadcast this intent 104192cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * before starting playback to make sure that any audio effect settings previously selected 104292cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * by the user are applied. 1043d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The effect control application receiving this intent will look for previously stored 1044d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * settings for the calling application, create all required audio effects and apply the 1045d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * effect settings to the specified audio session. 1046d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The calling package name is indicated by the {@link #EXTRA_PACKAGE_NAME} extra and the 1047d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * audio session ID by the {@link #EXTRA_AUDIO_SESSION} extra. Both extras are mandatory. 1048d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>If no stored settings are found for the calling application, default settings for the 1049d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * content type indicated by {@link #EXTRA_CONTENT_TYPE} will be applied. The default settings 1050d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * for a given content type are platform specific. 1051d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1052d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1053d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION = 1054d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent "android.media.action.OPEN_AUDIO_EFFECT_CONTROL_SESSION"; 1055d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1056d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 105792cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Intent to signal to the effect control application or service that an audio session 1058d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * is closed and that effects should not be applied anymore. 105992cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>The effect control application receiving this intent will delete all effects on 106092cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * this session and store current settings in package specific storage. 1061d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The calling package name is indicated by the {@link #EXTRA_PACKAGE_NAME} extra and the 1062d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * audio session ID by the {@link #EXTRA_AUDIO_SESSION} extra. Both extras are mandatory. 1063d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>It is good practice for applications to broadcast this intent when music playback stops 1064d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * and/or when exiting to free system resources consumed by audio effect engines. 1065d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1066d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1067d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION = 1068d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent "android.media.action.CLOSE_AUDIO_EFFECT_CONTROL_SESSION"; 1069d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1070d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 107192cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Contains the ID of the audio session the effects should be applied to. 107292cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>This extra is for use with {@link #ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL}, 107392cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * {@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} and 107492cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * {@link #ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION} intents. 1075d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The extra value is of type int and is the audio session ID. 10761a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @see android.media.MediaPlayer#getAudioSessionId() for details on audio sessions. 1077d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1078d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String EXTRA_AUDIO_SESSION = "android.media.extra.AUDIO_SESSION"; 1079d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1080d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 108192cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Contains the package name of the calling application. 108292cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>This extra is for use with {@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} and 1083d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * {@link #ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION} intents. 1084d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <p>The extra value is a string containing the full package name. 1085d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1086d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String EXTRA_PACKAGE_NAME = "android.media.extra.PACKAGE_NAME"; 1087d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1088d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 108992cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Indicates which type of content is played by the application. 109092cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>This extra is for use with {@link #ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL} and 109192cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * {@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} intents. 109292cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * <p>This information is used by the effect control application to customize UI and select 109392cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * appropriate default effect settings. The content type is one of the following: 1094d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <ul> 1095d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <li>{@link #CONTENT_TYPE_MUSIC}</li> 1096d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <li>{@link #CONTENT_TYPE_MOVIE}</li> 1097d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <li>{@link #CONTENT_TYPE_GAME}</li> 1098d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * <li>{@link #CONTENT_TYPE_VOICE}</li> 1099d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * </ul> 1100d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * If omitted, the content type defaults to {@link #CONTENT_TYPE_MUSIC}. 1101d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1102d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final String EXTRA_CONTENT_TYPE = "android.media.extra.CONTENT_TYPE"; 1103d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1104d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 1105d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * Value for {@link #EXTRA_CONTENT_TYPE} when the type of content played is music 1106d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1107d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final int CONTENT_TYPE_MUSIC = 0; 1108d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 110992cf2d60851462d91a1eb4b9615ea93579dd4330Eric Laurent * Value for {@link #EXTRA_CONTENT_TYPE} when the type of content played is video or movie 1110d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1111d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final int CONTENT_TYPE_MOVIE = 1; 1112d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 1113d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * Value for {@link #EXTRA_CONTENT_TYPE} when the type of content played is game audio 1114d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1115d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final int CONTENT_TYPE_GAME = 2; 1116d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent /** 1117d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent * Value for {@link #EXTRA_CONTENT_TYPE} when the type of content played is voice audio 1118d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent */ 1119d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent public static final int CONTENT_TYPE_VOICE = 3; 1120d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1121d09af7d5518d0a5b3c8070784c13a1070f46f460Eric Laurent 1122df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // --------------------------------------------------------- 1123948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Inner classes 1124df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 1125948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /** 1126df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * Helper class to handle the forwarding of native events to the appropriate 1127df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent * listeners 1128948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 1129df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private class NativeEventHandler extends Handler { 1130948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private AudioEffect mAudioEffect; 1131948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1132948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public NativeEventHandler(AudioEffect ae, Looper looper) { 1133948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent super(looper); 1134948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent mAudioEffect = ae; 1135948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1136948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1137948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent @Override 1138948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public void handleMessage(Message msg) { 1139948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (mAudioEffect == null) { 1140948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 1141948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1142df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent switch (msg.what) { 1143948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case NATIVE_EVENT_ENABLED_STATUS: 1144948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent OnEnableStatusChangeListener enableStatusChangeListener = null; 1145948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 1146948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent enableStatusChangeListener = mAudioEffect.mEnableStatusChangeListener; 1147948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1148948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (enableStatusChangeListener != null) { 1149df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent enableStatusChangeListener.onEnableStatusChange( 1150df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent mAudioEffect, (boolean) (msg.arg1 != 0)); 1151948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1152948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 1153948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case NATIVE_EVENT_CONTROL_STATUS: 1154948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent OnControlStatusChangeListener controlStatusChangeListener = null; 1155948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 1156948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent controlStatusChangeListener = mAudioEffect.mControlChangeStatusListener; 1157948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1158948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (controlStatusChangeListener != null) { 1159df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent controlStatusChangeListener.onControlStatusChange( 1160df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent mAudioEffect, (boolean) (msg.arg1 != 0)); 1161948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1162948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 1163948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case NATIVE_EVENT_PARAMETER_CHANGED: 1164948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent OnParameterChangeListener parameterChangeListener = null; 1165948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mListenerLock) { 1166948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent parameterChangeListener = mAudioEffect.mParameterChangeListener; 1167948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1168948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (parameterChangeListener != null) { 1169df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // arg1 contains offset of parameter value from start of 1170df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // byte array 1171948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int vOffset = msg.arg1; 1172df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent byte[] p = (byte[]) msg.obj; 1173df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // See effect_param_t in EffectApi.h for psize and vsize 1174df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // fields offsets 1175948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int status = byteArrayToInt(p, 0); 1176948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int psize = byteArrayToInt(p, 4); 1177948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int vsize = byteArrayToInt(p, 8); 1178948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] param = new byte[psize]; 1179948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] value = new byte[vsize]; 1180948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent System.arraycopy(p, 12, param, 0, psize); 1181948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent System.arraycopy(p, vOffset, value, 0, vsize); 1182948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1183df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent parameterChangeListener.onParameterChange(mAudioEffect, 1184df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent status, param, value); 1185948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1186948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 1187948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1188df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent default: 1189948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent Log.e(TAG, "handleMessage() Unknown event type: " + msg.what); 1190948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 1191948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1192948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1193948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1194948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1195df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // --------------------------------------------------------- 1196948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Java methods called from the native side 1197df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 1198948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent @SuppressWarnings("unused") 1199df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private static void postEventFromNative(Object effect_ref, int what, 1200df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent int arg1, int arg2, Object obj) { 1201df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent AudioEffect effect = (AudioEffect) ((WeakReference) effect_ref).get(); 1202948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (effect == null) { 1203948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 1204948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1205948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (effect.mNativeEventHandler != null) { 1206df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent Message m = effect.mNativeEventHandler.obtainMessage(what, arg1, 1207df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent arg2, obj); 1208948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect.mNativeEventHandler.sendMessage(m); 1209948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1210948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1211948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1212948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1213df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // --------------------------------------------------------- 1214948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Native methods called from the Java side 1215df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // -------------------- 1216948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1217948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private static native final void native_init(); 1218948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1219df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final int native_setup(Object audioeffect_this, String type, 1220df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent String uuid, int priority, int audioSession, int[] id, Object[] desc); 1221948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1222948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private native final void native_finalize(); 1223948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1224948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private native final void native_release(); 1225948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1226df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final int native_setEnabled(boolean enabled); 1227948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1228df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final boolean native_getEnabled(); 1229948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1230948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private native final boolean native_hasControl(); 1231948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1232df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final int native_setParameter(int psize, byte[] param, 1233df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent int vsize, byte[] value); 1234948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1235df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final int native_getParameter(int psize, byte[] param, 1236602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent int vsize, byte[] value); 1237948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1238df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent private native final int native_command(int cmdCode, int cmdSize, 1239602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent byte[] cmdData, int repSize, byte[] repData); 1240948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1241948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent private static native Object[] native_query_effects(); 1242948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12430f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent private static native Object[] native_query_pre_processing(int audioSession); 12440f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 1245df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // --------------------------------------------------------- 1246948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Utility methods 1247df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent // ------------------ 1248948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12491a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12501a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12511a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 125217cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public void checkState(String methodName) throws IllegalStateException { 1253948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent synchronized (mStateLock) { 1254948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (mState != STATE_INITIALIZED) { 1255df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent throw (new IllegalStateException(methodName 1256df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent + " called on uninitialized AudioEffect.")); 1257948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1258948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1259948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1260948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12611a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12621a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12631a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 126417cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent public void checkStatus(int status) { 1265602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (isError(status)) { 1266602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent switch (status) { 1267602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent case AudioEffect.ERROR_BAD_VALUE: 1268602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent throw (new IllegalArgumentException( 1269602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent "AudioEffect: bad parameter value")); 1270602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent case AudioEffect.ERROR_INVALID_OPERATION: 1271602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent throw (new UnsupportedOperationException( 1272602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent "AudioEffect: invalid parameter operation")); 1273602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent default: 1274602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent throw (new RuntimeException("AudioEffect: set/get parameter error")); 1275602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 1276948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1277948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1278948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 12791a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12801a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12811a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 1282602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent public static boolean isError(int status) { 1283602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent return (status < 0); 1284602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 1285602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent 1286602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent /** 1287602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent * @hide 1288602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent */ 1289d2bebb3ab86177c0d27664af86b30b7dce2c9bcbJean-Michel Trivi public static int byteArrayToInt(byte[] valueBuf) { 1290948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return byteArrayToInt(valueBuf, 0); 1291948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1292948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1293df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 12941a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 12951a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 12961a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 1297d2bebb3ab86177c0d27664af86b30b7dce2c9bcbJean-Michel Trivi public static int byteArrayToInt(byte[] valueBuf, int offset) { 1298948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent ByteBuffer converter = ByteBuffer.wrap(valueBuf); 1299948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.order(ByteOrder.nativeOrder()); 1300948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return converter.getInt(offset); 1301948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1302948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1303948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 13041a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 13051a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 13061a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 1307d2bebb3ab86177c0d27664af86b30b7dce2c9bcbJean-Michel Trivi public static byte[] intToByteArray(int value) { 1308948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent ByteBuffer converter = ByteBuffer.allocate(4); 1309948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.order(ByteOrder.nativeOrder()); 1310948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.putInt(value); 1311948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return converter.array(); 1312948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1313948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 13141a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 13151a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 13161a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 1317d2bebb3ab86177c0d27664af86b30b7dce2c9bcbJean-Michel Trivi public static short byteArrayToShort(byte[] valueBuf) { 1318948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return byteArrayToShort(valueBuf, 0); 1319948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1320948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 13211a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 13221a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 13231a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 1324d2bebb3ab86177c0d27664af86b30b7dce2c9bcbJean-Michel Trivi public static short byteArrayToShort(byte[] valueBuf, int offset) { 1325948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent ByteBuffer converter = ByteBuffer.wrap(valueBuf); 1326948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.order(ByteOrder.nativeOrder()); 1327948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return converter.getShort(offset); 1328948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1329948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1330948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 13311a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 13321a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 13331a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 1334d2bebb3ab86177c0d27664af86b30b7dce2c9bcbJean-Michel Trivi public static byte[] shortToByteArray(short value) { 1335948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent ByteBuffer converter = ByteBuffer.allocate(2); 1336948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.order(ByteOrder.nativeOrder()); 1337df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent short sValue = (short) value; 1338948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent converter.putShort(sValue); 1339948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return converter.array(); 1340948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1341948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 13421a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent /** 13431a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * @hide 13441a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent */ 1345d2bebb3ab86177c0d27664af86b30b7dce2c9bcbJean-Michel Trivi public static byte[] concatArrays(byte[]... arrays) { 1346948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int len = 0; 1347948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent for (byte[] a : arrays) { 1348948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent len += a.length; 1349948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1350948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent byte[] b = new byte[len]; 1351948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 1352948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int offs = 0; 1353948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent for (byte[] a : arrays) { 1354948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent System.arraycopy(a, 0, b, offs, a.length); 1355948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent offs += a.length; 1356948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1357948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return b; 1358948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 1359948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 1360