package com.gtr.echoing;
//import android.os.Build;
import android.media.audiofx.AudioEffect;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.BA.Permissions;
@ShortName("Echo")
@Author("GTR")
@Version(1.20f)
@Permissions(values={"android.permission.MODIFY_AUDIO_SETTINGS"})
public class Echo{
/**
* Preset. Parameter ID for
* {@link android.media.audiofx.PresetReverb.OnParameterChangeListener}
*/
public static final int PARAM_PRESET = 0;
/**
* No reverb or reflections
*/
public static final short PRESET_NONE = 0;
/**
* Reverb preset representing a small room less than five meters in length
*/
public static final short PRESET_SMALLROOM = 1;
/**
* Reverb preset representing a medium room with a length of ten meters or less
*/
public static final short PRESET_MEDIUMROOM = 2;
/**
* Reverb preset representing a large-sized room suitable for live performances
*/
public static final short PRESET_LARGEROOM = 3;
/**
* Reverb preset representing a medium-sized hall
*/
public static final short PRESET_MEDIUMHALL = 4;
/**
* Reverb preset representing a large-sized hall suitable for a full orchestra
*/
public static final short PRESET_LARGEHALL = 5;
/**
* Reverb preset representing a synthesis of the traditional plate reverb
*/
public static final short PRESET_PLATE = 6;
private static boolean IsAvailable = false;
private static boolean IsInit = false;
/* Check if required API is available even before compiling so as to avoid runtime errors
*
*/
static {
try {
Echovalid.CheckAvailable();
IsAvailable=true;
}catch (Throwable t) {
IsAvailable=false;
}
}
/**
* Checks whether the Echo is available and Initializes the object,
* only for all output and not for specific media players.
* For backwards compatibility, the library will not throw an exception
* on failure to initialize the Equalizer, but will return true or false
* and set the IsInitialized flag appropriately if it fails for any reason.
* check either of these before running the other methods as if the equalizer
* is not initialized, you will get a runtime error.
*
*/
@SuppressWarnings("finally")
public boolean Initialize() {
try {
Echovalid.Initialize();
IsInit=true;
} catch (Throwable t) {
IsInit = false;
}
finally
{ return IsInit;
}
}
/**
* Enables or disables the Audio effect engine.
*/
public static int Enable(boolean enable)throws Exception {
if (!IsInitialized()) {
throw new Exception("Echo should be initialized first");
}
return Echovalid.Enable(enable);
}
/**
* Gets the Enabled status of the Audio effect engine.
*/
public static boolean GetEnabled()throws Exception {
if (!IsInitialized()) {
throw new Exception("Echo should be initialized first");
}
return Echovalid.GetEnabled();
}
/**
* Checks if this AudioEffect object is controlling the effect engine
*/
public static boolean HasControl()throws Exception {
if (!IsInitialized()) {
throw new Exception("Echo should be initialized first");
}
return Echovalid.HasControl();
}
/**
* Releases the native AudioEffect resources.
* It is a good practice to release the effect engine when not
* in use as control can be returned to other
* applications or the native resources released.
*/
public static void Release()throws Exception {
if (!IsInitialized()) {
throw new Exception("Echo should be initialized first");
}
Echovalid.Release();
}
/**
* Returns the status of the Equalizer object, it must be available for
* the devices API level and initialized
*
*/
public static boolean IsInitialized(){
if (IsAvailable && Echovalid.IsInitialized()) {
return true;
} else {
return false;
}
}
/**
* Returns the availability of the Equalizer object, it must be available for
* the devices API level (9 or later)
*/
public boolean IsAvailable(){
return IsAvailable;
}
// Echo Start here
/**
* Enables a preset on the reverb.
* <p>The reverb PRESET_NONE disables any reverb from the current output but does not free the
* resources associated with the reverb. For an application to signal to the implementation
* to free the resources, it must call the release() method.
* @param preset this must be one of the the preset constants defined in this class.
* e.g. {@link #PRESET_SMALLROOM}
* @throws IllegalStateException
* @throws IllegalArgumentException
* @throws UnsupportedOperationException
*/
public void setPreset(short preset)throws Exception {
if (!IsInitialized()) {
throw new Exception("Echo should be initialized first");
}
Echovalid.setPreset(preset);
}
public void onParameterChange(AudioEffect effect, int status, byte[] param, byte[] value)throws Exception {
if (!IsInitialized()) {
throw new Exception("Echo should be initialized first");
}
Echovalid.onParameterChange(null, status, param, value);
{
}
}
}