Audinaut-subsonic-app-android/app/src/main/java/net/nullsum/audinaut/audiofx/LoudnessEnhancerController....

78 lines
1.9 KiB
Java
Raw Normal View History

2016-12-18 18:41:30 +01:00
/*
This file is part of Subsonic.
Subsonic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Subsonic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2014 (C) Scott Jackson
*/
2017-01-09 08:01:12 +01:00
package net.nullsum.audinaut.audiofx;
2016-12-18 18:41:30 +01:00
import android.content.Context;
import android.media.audiofx.LoudnessEnhancer;
import android.util.Log;
public class LoudnessEnhancerController {
private static final String TAG = LoudnessEnhancerController.class.getSimpleName();
private final Context context;
private LoudnessEnhancer enhancer;
private boolean released = false;
private int audioSessionId = 0;
public LoudnessEnhancerController(Context context, int audioSessionId) {
this.context = context;
try {
this.audioSessionId = audioSessionId;
enhancer = new LoudnessEnhancer(audioSessionId);
} catch (Throwable x) {
Log.w(TAG, "Failed to create enhancer", x);
}
}
public boolean isAvailable() {
return enhancer != null;
}
public boolean isEnabled() {
try {
return isAvailable() && enhancer.getEnabled();
} catch(Exception e) {
return false;
}
}
public void enable() {
enhancer.setEnabled(true);
}
public void disable() {
enhancer.setEnabled(false);
}
public float getGain() {
return enhancer.getTargetGain();
}
public void setGain(int gain) {
enhancer.setTargetGain(gain);
}
public void release() {
if (isAvailable()) {
enhancer.release();
released = true;
}
}
}