android.media.audiofx.Equalizer Java Examples

The following examples show how to use android.media.audiofx.Equalizer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayService.java    From music_player with Open Software License 3.0 7 votes vote down vote up
private void initialAudioEffect(final int audioSessionId) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                loudnessEnhancer = new LoudnessEnhancer(audioSessionId);
                mBass = new BassBoost(0, audioSessionId);
                mVirtualizer = new Virtualizer(0, audioSessionId);
                mEqualizer = new Equalizer(0, audioSessionId);
                canceler = AcousticEchoCanceler.create(audioSessionId);
                control = AutomaticGainControl.create(audioSessionId);
                suppressor = NoiseSuppressor.create(audioSessionId);
                getPreference();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
}
 
Example #2
Source File: EqualizerFragment.java    From Bop with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    mEqualizer = new Equalizer(0, audioSesionId);
    bassBoost = new BassBoost(0, audioSesionId);
    bassBoost.setEnabled(true);
    BassBoost.Settings bassBoostSettingTemp = bassBoost.getProperties();
    BassBoost.Settings bassBoostSetting = new BassBoost.Settings(bassBoostSettingTemp.toString());
    bassBoostSetting.strength = (1000 / 19);
    bassBoost.setProperties(bassBoostSetting);

    presetReverb = new PresetReverb(0, audioSesionId);
    presetReverb.setPreset(PresetReverb.PRESET_NONE);
    presetReverb.setEnabled(true);
    Settings.equalizerModel = new EqualizerModel();
    mEqualizer.setEnabled(true);
    
    unbindSystemEqualizer(audioSesionId);
}
 
Example #3
Source File: MusicService.java    From YTPlayer with GNU General Public License v3.0 6 votes vote down vote up
static void setDefaultEqualizerValues() {
    try {
        boolean isSet = settingPref.getBoolean("equalizer_default",false);
        if (!isSet) {
            SharedPreferences.Editor editor = settingPref.edit();
            int sessionId = player.getAudioComponent().getAudioSessionId();

            mEqualizer = new Equalizer(1000,sessionId);
            short numberFrequencyBands = mEqualizer.getNumberOfBands();
            final short lowerEqualizerBandLevel = mEqualizer.getBandLevelRange()[0];
            final short upperEqualizerBandLevel = mEqualizer.getBandLevelRange()[1];

            editor.putInt("bandLength",numberFrequencyBands);
            editor.putInt("lowerBand",lowerEqualizerBandLevel);
            editor.putInt("higherBand",upperEqualizerBandLevel);
            editor.putBoolean("equalizer_default",true);
            editor.apply();

            mEqualizer.release();
        }
    }catch (Exception ignored){}
}
 
Example #4
Source File: ImmutablePreferenceStore.java    From Jockey with Apache License 2.0 6 votes vote down vote up
public ImmutablePreferenceStore(ReadOnlyPreferenceStore preferencesStore) {
    mShowFirstStart = preferencesStore.showFirstStart();
    mAllowLogging = preferencesStore.allowLogging();
    mUseMobileNetwork = preferencesStore.useMobileNetwork();
    mOpenNowPlayingOnNewQueue = preferencesStore.openNowPlayingOnNewQueue();
    mEnableNowPlayingGestures = preferencesStore.enableNowPlayingGestures();
    mDefaultPage = preferencesStore.getDefaultPage();
    mPrimaryColor = preferencesStore.getPrimaryColor();
    mAccentColor = preferencesStore.getAccentColor();
    mBaseColor = preferencesStore.getBaseColor();
    mIconColor = preferencesStore.getIconColor();
    mResumeOnHeadphonesConnect = preferencesStore.resumeOnHeadphonesConnect();
    mShuffled = preferencesStore.isShuffled();
    mPreviousSleepTimerDurationMillis = preferencesStore.getLastSleepTimerDuration();
    mRepeatMode = preferencesStore.getRepeatMode();
    mSlsEnabled = preferencesStore.isSlsBroadcastingEnabled();
    mEqualizerPresetId = preferencesStore.getEqualizerPresetId();
    mEqualizerEnabled = preferencesStore.getEqualizerEnabled();

    Equalizer.Settings eqSettings = preferencesStore.getEqualizerSettings();
    if (eqSettings != null) {
        mEqualizerSettings = eqSettings.toString();
    } else {
        mEqualizerSettings = null;
    }
}
 
Example #5
Source File: AudioEffectsImpl.java    From PainlessMusicPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void saveEqualizerSettings(@NonNull final Equalizer.Settings settings) {
    synchronized (SETTINGS_LOCK) {
        final EffectsProto.EqualizerSettings proto = mEqualizerSettings;
        proto.curPreset = settings.curPreset;
        proto.numBands = settings.numBands;

        final short[] bandLevels = settings.bandLevels;
        proto.bandValues = new int[bandLevels != null ? bandLevels.length : 0];
        if (bandLevels != null) {
            for (int i = 0; i < bandLevels.length; i++) {
                proto.bandValues[i] = bandLevels[i];
            }
        }
    }

    persistEqualizerSettingsAsync();
}
 
Example #6
Source File: AudioEffectsImpl.java    From PainlessMusicPlayer with Apache License 2.0 6 votes vote down vote up
private void restoreEqualizer() {
    mEqualizer = new Equalizer(Integer.MAX_VALUE, mSessionId);

    synchronized (SETTINGS_LOCK) {
        final EffectsProto.EqualizerSettings proto = mEqualizerSettings;
        if (proto.curPreset != 0
                || proto.numBands != 0
                || proto.bandValues.length != 0) {
            final Equalizer.Settings settings = new Equalizer.Settings();
            settings.curPreset = (short) proto.curPreset;
            settings.numBands = (short) proto.numBands;
            settings.bandLevels = new short[proto.bandValues.length];
            for (int i = 0; i < settings.bandLevels.length; i++) {
                settings.bandLevels[i] = (short) proto.bandValues[i];
            }

            try {
                mEqualizer.setProperties(settings);
            } catch (IllegalArgumentException e) {
                Log.wtf(TAG, "Failed restoring equalizer settings", e);
            }
        }
    }

    mEqualizer.setEnabled(true);
}
 
Example #7
Source File: MusicUtils.java    From Rey-MusicPlayer with Apache License 2.0 6 votes vote down vote up
public static boolean isEqualizerSupported() {
    int noOfBands = 0;
    int noOfPresents = 0;
    try {
        Equalizer equalizer = new Equalizer(0, 0);
        noOfBands = equalizer.getNumberOfBands();
        noOfPresents = equalizer.getNumberOfPresets();
        equalizer.release();
        equalizer = null;
    } catch (Exception e) {

    }

    return noOfBands > 0 && noOfPresents > 0 && !isHTC();

}
 
Example #8
Source File: StandardEqualizer.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private void workaroundCyanogenModSetProperties(IEqualizer.Settings settings) {
    // apply
    if (settings.curPreset != PRESET_UNDEFINED) {
        final Equalizer eq = getEqualizer();

        eq.usePreset(settings.curPreset);
        mWorkaroundCurPreset = settings.curPreset;
        for (short band = 0; band < settings.numBands; band++) {
            mWorkaroundBandLevels[band] = eq.getBandLevel(band);
        }
    } else {
        for (short band = 0; band < settings.numBands; band++) {
            workaroundCyanogenModSetBandLevel(band, settings.bandLevels[band]);
        }

        mWorkaroundCurPreset = settings.curPreset;
        System.arraycopy(settings.bandLevels, 0, mWorkaroundBandLevels, 0, mNumBands);
    }
}
 
Example #9
Source File: StandardEqualizer.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private void workaroundGalaxyS4SetProperties(IEqualizer.Settings settings) {
    final Equalizer eq = getEqualizer();

    if (settings.curPreset != PRESET_UNDEFINED) {
        // NOTE: if curPreset has valid preset no.,
        // bandLevels values are not used.
        settings = DefaultEqualizerPresets.getPreset(settings.curPreset);
    }

    // apply
    if (settings.curPreset != PRESET_UNDEFINED) {
        try {
            eq.usePreset(settings.curPreset);
        } catch (IllegalArgumentException e) {
            // HTC devices raises IllegalArgumentException
        }
    }
    for (short band = 0; band < settings.numBands; band++) {
        eq.setBandLevel(band, settings.bandLevels[band]);
    }

    mWorkaroundCurPreset = settings.curPreset;
    System.arraycopy(settings.bandLevels, 0, mWorkaroundBandLevels, 0,
            mNumBands);
}
 
Example #10
Source File: EqualizerVolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
private void updateEqualizerState(Equalizer eq) {
    if (null == eq) return;
    preset = eq.getCurrentPreset();
    for (short band = 0; band < levels.length; ++band) {
        levels[band] = eq.getBandLevel(band);
    }
}
 
Example #11
Source File: JockeyPreferencesCompat.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private static void updateFromJockey1_2(Context context, SharedPreferences prefs) {
    boolean showFirstStart = prefs.getBoolean("prefShowFirstStart", true);
    boolean allowLogging = prefs.getBoolean("prefAllowLogging", false);
    String firstPage = prefs.getString("prefDefaultPage", Integer.toString(SONGS));
    String primaryColor = prefs.getString("prefColorPrimary", Integer.toString(CYAN));
    String baseTheme = prefs.getString("prefBaseTheme", Integer.toString(LIGHT));
    boolean useMobileData = prefs.getBoolean("prefUseMobileData", true);
    boolean openNowPlaying = prefs.getBoolean("prefSwitchToNowPlaying", true);
    boolean enableGestures = prefs.getBoolean("prefEnableNowPlayingGestures", true);
    int eqPreset = prefs.getInt("equalizerPresetId", -1);
    boolean eqEnabled = prefs.getBoolean("prefUseEqualizer", false);
    String eqSettings = prefs.getString("prefEqualizerSettings", null);
    int repeat = prefs.getInt("prefRepeat", 0);
    boolean shuffle = prefs.getBoolean("prefShuffle", false);

    prefs.edit().clear().apply();
    PreferenceStore preferenceStore = new SharedPreferenceStore(context);

    preferenceStore.setShowFirstStart(showFirstStart);
    preferenceStore.setAllowLogging(allowLogging);
    preferenceStore.setDefaultPage(convertStartPage1_2(firstPage));
    preferenceStore.setPrimaryColor(convertPrimaryColor1_2(primaryColor));
    preferenceStore.setBaseColor(convertBaseTheme1_2(baseTheme));
    preferenceStore.setUseMobileNetwork(useMobileData);
    preferenceStore.setOpenNowPlayingOnNewQueue(openNowPlaying);
    preferenceStore.setEnableNowPlayingGestures(enableGestures);
    preferenceStore.setEqualizerPresetId(eqPreset);
    preferenceStore.setEqualizerEnabled(eqEnabled);

    try {
        if (eqSettings != null) {
            preferenceStore.setEqualizerSettings(new Equalizer.Settings(eqSettings));
        }
    } catch (IllegalArgumentException ignored) {}

    preferenceStore.setRepeatMode(repeat);
    preferenceStore.setShuffle(shuffle);
}
 
Example #12
Source File: RemoteEqualizer.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private static Band[] getEqualizerBands(Equalizer equalizer) {
    Band[] bands = new Band[equalizer.getNumberOfBands()];

    for (short i = 0; i < bands.length; i++) {
        int[] range = equalizer.getBandFreqRange(i);
        int centerFrequency = equalizer.getCenterFreq(i);
        int lowFrequency = range[0];
        int highFrequency = range[1];

        bands[i] = new Band(lowFrequency, highFrequency, centerFrequency);
    }

    return bands;
}
 
Example #13
Source File: RemoteEqualizer.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private static Preset[] getEqualizerPresets(Equalizer equalizer) {
    Preset[] presets = new Preset[equalizer.getNumberOfPresets()];

    for (short i = 0; i < presets.length; i++) {
        presets[i] = new Preset(equalizer.getPresetName(i));
    }

    return presets;
}
 
Example #14
Source File: EqualizerVolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
private void release(AudioEffect effect) {
    if (null != effect) {
        effect.setControlStatusListener(null);
        effect.setEnableStatusListener(null);
        if (effect instanceof Equalizer) {
            ((Equalizer) effect).setParameterListener(null);
        } else if (effect instanceof BassBoost) {
            ((BassBoost) effect).setParameterListener(null);
        } else if (effect instanceof Virtualizer) {
            ((Virtualizer) effect).setParameterListener(null);
        }
        effect.release();
    }
}
 
Example #15
Source File: RemoteEqualizer.java    From Jockey with Apache License 2.0 5 votes vote down vote up
public RemoteEqualizer(Band[] bands, Preset[] presets, Equalizer.Settings settings,
                       short[] bandLevelRange) {
    mBands = bands;
    mPresets = presets;

    mMinBandLevel = bandLevelRange[0];
    mMaxBandLevel = bandLevelRange[1];

    setProperties(settings);
}
 
Example #16
Source File: RemoteEqualizer.java    From Jockey with Apache License 2.0 5 votes vote down vote up
public Equalizer.Settings getProperties() {
    Equalizer.Settings settings = new Equalizer.Settings();

    settings.bandLevels = intArrayToShortArray(mBandLevels);
    settings.curPreset = (short) mCurPreset;
    settings.numBands = (short) getNumberOfBands();

    return settings;
}
 
Example #17
Source File: EqualizedExoPlayer.java    From Jockey with Apache License 2.0 5 votes vote down vote up
public void setEqualizerSettings(boolean enabled, Equalizer.Settings settings) {
    boolean invalidate = mEqualizerEnabled != enabled || mEqualizerEnabled;
    boolean wasSystem = isUsingSystemEqualizer();

    mEqualizerEnabled = enabled;
    mEqualizerSettings = settings;

    if (invalidate) {
        updateEqualizerPrefs(enabled, wasSystem);
    }
}
 
Example #18
Source File: EqualizerFragment.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private RemoteEqualizer generateEqualizerConfig() {
    // Obtain an instance of the system equalizer to discover available configuration options
    // for an equalizer including bands and presets. This equalizer is not used to control
    // audio settings and is released before this method ends
    Equalizer systemEqualizer = new Equalizer(0, 1);

    RemoteEqualizer eq = new RemoteEqualizer(systemEqualizer);
    Equalizer.Settings settings = mPrefStore.getEqualizerSettings();
    if (settings != null) {
        eq.setProperties(mPrefStore.getEqualizerSettings());
    }

    systemEqualizer.release();
    return eq;
}
 
Example #19
Source File: EqualizerController.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
private void init() {
	equalizer = new Equalizer(0, audioSessionId);
	bass = new BassBoost(0, audioSessionId);
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		loudnessAvailable = true;
		loudnessEnhancerController = new LoudnessEnhancerController(context, audioSessionId);
	}
}
 
Example #20
Source File: EqualizerController.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
public Equalizer getEqualizer() {
	if(released) {
		released = false;
		try {
			init();
		} catch (Throwable x) {
			equalizer = null;
			released = true;
			Log.w(TAG, "Failed to create equalizer.", x);
		}
	}
	return equalizer;
}
 
Example #21
Source File: StandardEqualizer.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
private IEqualizer.Settings workaroundCyanogenModGetPropertiesCompat() {
    final Equalizer eq = getEqualizer();
    IEqualizer.Settings settings = new IEqualizer.Settings();

    settings.curPreset = mWorkaroundCurPreset;
    settings.numBands = mNumBands;
    settings.bandLevels = new short[mNumBands];

    for (short band = 0; band < mNumBands; band++) {
        settings.bandLevels[band] = eq.getBandLevel(band);
    }

    return settings;
}
 
Example #22
Source File: EqualizerController.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
public void apply(Equalizer equalizer, BassBoost boost, LoudnessEnhancerController loudnessController) {
	for (short i = 0; i < bandLevels.length; i++) {
		equalizer.setBandLevel(i, bandLevels[i]);
	}
	equalizer.setEnabled(enabled);
	if(bass != 0) {
		boost.setEnabled(true);
		boost.setStrength(bass);
	}
	if(loudness != 0) {
		loudnessController.enable();
		loudnessController.setGain(loudness);
	}
}
 
Example #23
Source File: MainActivity.java    From NEON with Apache License 2.0 5 votes vote down vote up
private void updateEqualizer() {
    this.equalizer = new Equalizer(0, this.mediaPlayer.getAudioSessionId());
    this.equalizer.setEnabled(true);

    updateFrequencyBars(this.txtVsb_1, this.vsb_1, (short) 0);
    updateFrequencyBars(this.txtVsb_2, this.vsb_2, (short) 1);
    updateFrequencyBars(this.txtVsb_3, this.vsb_3, (short) 2);
    updateFrequencyBars(this.txtVsb_4, this.vsb_4, (short) 3);
    updateFrequencyBars(this.txtVsb_5, this.vsb_5, (short) 4);
}
 
Example #24
Source File: AudioEffectSettingsConverter.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * IEqualizer.Settings -&gt; Equalizer.Settings
 *
 * @param settings IEqualizer.Settings
 * @return Equalizer.Settings
 */
public static Equalizer.Settings convert(IEqualizer.Settings settings) {
    Equalizer.Settings settings2 = new Equalizer.Settings();

    settings2.curPreset = settings.curPreset;
    settings2.numBands = settings.numBands;
    settings2.bandLevels = settings.bandLevels;

    return settings2;
}
 
Example #25
Source File: AudioEffectSettingsConverter.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * Equalizer.Settings -&gt; IEqualizer.Settings
 *
 * @param settings Equalizer.Settings
 * @return IEqualizer.Settings
 */
public static IEqualizer.Settings convert(Equalizer.Settings settings) {
    IEqualizer.Settings settings2 = new IEqualizer.Settings();

    settings2.curPreset = settings.curPreset;
    settings2.numBands = settings.numBands;
    settings2.bandLevels = settings.bandLevels;

    return settings2;
}
 
Example #26
Source File: StandardEqualizer.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
void onParameterChange(
        android.media.audiofx.Equalizer effect,
        int status, int param1, int param2, int value) {
    IEqualizer.OnParameterChangeListener listener = null;

    listener = mUserOnParameterChangeListener;

    if (listener != null) {
        listener.onParameterChange(this, status, param1, param2, value);
    }
}
 
Example #27
Source File: StandardEqualizer.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
private void initializeForCompat() {
    final int MIN = 0;
    final int MAX = 1;

    final Equalizer eq = getEqualizer();

    mNumBands = eq.getNumberOfBands();
    mNumPresets = eq.getNumberOfPresets();

    short[] levelRange = eq.getBandLevelRange();

    mBandLevelMin = levelRange[0];
    mBandLevelMax = levelRange[1];

    mBandFreqRange = new int[mNumBands][2];
    mBandCenterFreq = new int[mNumBands];
    for (short band = 0; band < mNumBands; band++) {
        int center = eq.getCenterFreq(band);
        int[] range = eq.getBandFreqRange(band);
        mBandFreqRange[band][MIN] = range[MIN];
        mBandFreqRange[band][MAX] = range[MAX];
        mBandCenterFreq[band] = center;
    }

    // correct center freq. & band freq. range
    int[] correctedCenterFreq = new int[mNumBands];
    int[][] correctedBandFreqRange = new int[mNumBands][2];

    if (EqualizerBandInfoCorrector.correct(
            mNumBands, mBandCenterFreq, mBandFreqRange,
            correctedCenterFreq, correctedBandFreqRange)) {
        mCorrectedCenterFreq = correctedCenterFreq;
        mCorrectedBandFreqRange = correctedBandFreqRange;
    }

    initializePresetWorkarounds();
}
 
Example #28
Source File: StandardEqualizer.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
private void workaroundCyanogenModUsePreset(short preset) {
    if (preset != PRESET_UNDEFINED) {
        final Equalizer eq = getEqualizer();

        eq.usePreset(preset);

        for (short band = 0; band < mNumBands; band++) {
            mWorkaroundBandLevels[band] = eq.getBandLevel(band);
        }
        mWorkaroundCurPreset = preset;
    }
}
 
Example #29
Source File: EqualizerController.java    From Audinaut with GNU General Public License v3.0 5 votes vote down vote up
public Equalizer getEqualizer() {
    if (released) {
        released = false;
        try {
            init();
        } catch (Throwable x) {
            equalizer = null;
            released = true;
            Log.w(TAG, "Failed to create equalizer.", x);
        }
    }
    return equalizer;
}
 
Example #30
Source File: EqualizerFragment.java    From AndroidEqualizer with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Settings.isEditing = true;

    if (getArguments() != null && getArguments().containsKey(ARG_AUDIO_SESSIOIN_ID)){
        audioSesionId = getArguments().getInt(ARG_AUDIO_SESSIOIN_ID);
    }

    if (Settings.equalizerModel == null){
        Settings.equalizerModel = new EqualizerModel();
        Settings.equalizerModel.setReverbPreset(PresetReverb.PRESET_NONE);
        Settings.equalizerModel.setBassStrength((short) (1000 / 19));
    }

    mEqualizer = new Equalizer(0, audioSesionId);

    bassBoost = new BassBoost(0, audioSesionId);
    bassBoost.setEnabled(Settings.isEqualizerEnabled);
    BassBoost.Settings bassBoostSettingTemp = bassBoost.getProperties();
    BassBoost.Settings bassBoostSetting = new BassBoost.Settings(bassBoostSettingTemp.toString());
    bassBoostSetting.strength = Settings.equalizerModel.getBassStrength();
    bassBoost.setProperties(bassBoostSetting);

    presetReverb = new PresetReverb(0, audioSesionId);
    presetReverb.setPreset(Settings.equalizerModel.getReverbPreset());
    presetReverb.setEnabled(Settings.isEqualizerEnabled);

    mEqualizer.setEnabled(Settings.isEqualizerEnabled);

    if (Settings.presetPos == 0){
        for (short bandIdx = 0; bandIdx < mEqualizer.getNumberOfBands(); bandIdx++) {
            mEqualizer.setBandLevel(bandIdx, (short) Settings.seekbarpos[bandIdx]);
        }
    }
    else {
        mEqualizer.usePreset((short) Settings.presetPos);
    }
}