diff options
author | Roman Birg <roman@cyngn.com> | 2016-08-12 11:10:05 -0700 |
---|---|---|
committer | Roman Birg <roman@cyngn.com> | 2016-08-23 18:01:57 +0000 |
commit | b01d7927cca7387b17d6b338f0e9a0a286e32c69 (patch) | |
tree | 76a04d15c191ac8829ee2fb882f386bbf5464d9c /src | |
parent | c5812df023693994ac3628c0fdb48e64178d24ee (diff) | |
download | android_packages_apps_AudioFX-b01d7927cca7387b17d6b338f0e9a0a286e32c69.tar.gz android_packages_apps_AudioFX-b01d7927cca7387b17d6b338f0e9a0a286e32c69.tar.bz2 android_packages_apps_AudioFX-b01d7927cca7387b17d6b338f0e9a0a286e32c69.zip |
ModioFX: split backend implementations
Change-Id: Ib6f345000b25a17a5c7520ea47355f1d96936522
Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'src')
6 files changed, 29 insertions, 85 deletions
diff --git a/src/com/cyngn/audiofx/Constants.java b/src/com/cyngn/audiofx/Constants.java index b38b0cd..c1d5475 100644 --- a/src/com/cyngn/audiofx/Constants.java +++ b/src/com/cyngn/audiofx/Constants.java @@ -24,8 +24,14 @@ import java.util.List; public class Constants { + // current pref version, bump to rebuild prefs public static final int CURRENT_PREFS_INT_VERSION = 2; + // effect type identifiers + public static final int EFFECT_TYPE_ANDROID = 1; + public static final int EFFECT_TYPE_MAXXAUDIO = 2; + public static final int EFFECT_TYPE_DTS = 3; + // global settings public static final String AUDIOFX_GLOBAL_FILE = "global"; diff --git a/src/com/cyngn/audiofx/backends/AndroidEffects.java b/src/com/cyngn/audiofx/backends/AndroidEffects.java index 77af1c9..090eb73 100644 --- a/src/com/cyngn/audiofx/backends/AndroidEffects.java +++ b/src/com/cyngn/audiofx/backends/AndroidEffects.java @@ -8,7 +8,6 @@ import android.media.audiofx.Virtualizer; import android.util.Log; import com.cyngn.audiofx.Constants; -import com.cyngn.audiofx.activity.MasterConfigControl; /** * EffectSet which comprises standard Android effects @@ -170,7 +169,7 @@ class AndroidEffects extends EffectSetWithAndroidEq { @Override public int getBrand() { - return EffectsFactory.ANDROID; + return Constants.EFFECT_TYPE_ANDROID; } private void setParameterSafe(AudioEffect e, int p, short v) { diff --git a/src/com/cyngn/audiofx/backends/EffectsFactory.java b/src/com/cyngn/audiofx/backends/EffectsFactory.java deleted file mode 100644 index 6057255..0000000 --- a/src/com/cyngn/audiofx/backends/EffectsFactory.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.cyngn.audiofx.backends; - -import android.content.Context; -import android.media.AudioDeviceInfo; -import android.util.Log; - -import java.io.File; - -/** - * Creates an EffectSet appropriate for the current device - * - * Currently handles basic Android effects and MaxxAudio. Extend for DTS in the future. - */ -public class EffectsFactory { - - private static final String TAG = "AudioFx-EffectsFactory"; - - private static int sBrand = -1; // cached value to not hit io every time we need a new effect - - public static final int ANDROID = 1; - public static final int MAXXAUDIO = 2; - public static final int DTS = 3; - - public static EffectSet createEffectSet(Context context, int sessionId, - AudioDeviceInfo currentDevice) { - EffectSet effects = null; - int brand = getBrand(); - - // dts? - if (brand == DTS) { - try { - effects = new DtsEffects(context, sessionId, currentDevice); - } catch (Exception e) { - Log.e(TAG, "Unable to create DTS effects!", e); - effects = null; - } - return effects; - } else if (brand == MAXXAUDIO) { - // try MaxxAudio next, this will throw an exception if unavailable - try { - effects = new MaxxAudioEffects(sessionId, currentDevice); - } catch (Exception e) { - Log.e(TAG, "Unable to create MaxxAudio effects!", e); - effects = null; - } - return effects; - } - - // if this throws, we're screwed, don't bother to recover. these - // are the standard effects that every android device must have, - // and if they don't exist we have bigger problems. - return new AndroidEffects(sessionId, currentDevice); - } - - public static int getBrand() { - if (sBrand == -1) { - sBrand = getBrandInternal(); - } - return sBrand; - } - - private static int getBrandInternal() { - if (hasDts()) { - return DTS; - } else if (hasMaxxAudio()) { - return MAXXAUDIO; - } - return ANDROID; - } - - private static boolean hasDts() { - return new File("***REMOVED***").exists(); - } - - private static boolean hasMaxxAudio() { - return new File("***REMOVED***").exists(); - } -} diff --git a/src/com/cyngn/audiofx/backends/IEffectFactory.java b/src/com/cyngn/audiofx/backends/IEffectFactory.java new file mode 100644 index 0000000..8e629b8 --- /dev/null +++ b/src/com/cyngn/audiofx/backends/IEffectFactory.java @@ -0,0 +1,16 @@ +package com.cyngn.audiofx.backends; + +import android.content.Context; +import android.media.AudioDeviceInfo; + +interface IEffectFactory { + + /** + * Create a new EffectSet based on current stream parameters. + * @param context context to create the effect with + * @param sessionId session id to attach the effect to + * @param currentDevice current device that the effect should initially setup for + * @return an {@link EffectSet} + */ + EffectSet createEffectSet(Context context, int sessionId, AudioDeviceInfo currentDevice); +} diff --git a/src/com/cyngn/audiofx/service/DevicePreferenceManager.java b/src/com/cyngn/audiofx/service/DevicePreferenceManager.java index 11d4de5..928209e 100644 --- a/src/com/cyngn/audiofx/service/DevicePreferenceManager.java +++ b/src/com/cyngn/audiofx/service/DevicePreferenceManager.java @@ -118,7 +118,7 @@ class DevicePreferenceManager implements AudioOutputChangeListener.AudioOutputCh } return; } - EffectSet temp = EffectsFactory.createEffectSet(mContext, 0, null); + EffectSet temp = new EffectsFactory().createEffectSet(mContext, 0, null); final int numBands = temp.getNumEqualizerBands(); final int numPresets = temp.getNumEqualizerPresets(); @@ -168,8 +168,8 @@ class DevicePreferenceManager implements AudioOutputChangeListener.AudioOutputCh editor.putBoolean(AUDIOFX_GLOBAL_HAS_VIRTUALIZER, temp.hasVirtualizer()); editor.putBoolean(AUDIOFX_GLOBAL_HAS_BASSBOOST, temp.hasBassBoost()); - editor.putBoolean(AUDIOFX_GLOBAL_HAS_MAXXAUDIO, temp.getBrand() == EffectsFactory.MAXXAUDIO); - editor.putBoolean(AUDIOFX_GLOBAL_HAS_DTS, temp.getBrand() == EffectsFactory.DTS); + editor.putBoolean(AUDIOFX_GLOBAL_HAS_MAXXAUDIO, temp.getBrand() == Constants.EFFECT_TYPE_MAXXAUDIO); + editor.putBoolean(AUDIOFX_GLOBAL_HAS_DTS, temp.getBrand() == Constants.EFFECT_TYPE_DTS); editor.commit(); temp.release(); @@ -208,7 +208,7 @@ class DevicePreferenceManager implements AudioOutputChangeListener.AudioOutputCh final SharedPreferences globalPrefs = Constants.getGlobalPrefs(mContext); - // Nothing to see here for DTS + // Nothing to see here for EFFECT_TYPE_DTS if (globalPrefs.getBoolean(AUDIOFX_GLOBAL_HAS_DTS, false)) { return; } diff --git a/src/com/cyngn/audiofx/service/SessionManager.java b/src/com/cyngn/audiofx/service/SessionManager.java index 2a60cc2..c744686 100644 --- a/src/com/cyngn/audiofx/service/SessionManager.java +++ b/src/com/cyngn/audiofx/service/SessionManager.java @@ -309,7 +309,8 @@ class SessionManager implements AudioOutputChangeListener.AudioOutputChangedCall session = mAudioSessionsL.get(sessionId); if (session == null) { try { - session = EffectsFactory.createEffectSet(mContext, sessionId, mCurrentDevice); + session = new EffectsFactory() + .createEffectSet(mContext, sessionId, mCurrentDevice); } catch (Exception e) { Log.e(TAG, "couldn't create effects for session id: " + sessionId, e); break; |