Android Equalizer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Equalizer class.

This code example shows how to use the following methods:release, getBandLevel, getBandLevelRange, getNumberOfBands, setBandLevel
    public void test1_0BandLevel() throws Exception { 
        boolean result = false;
        String msg = "test1_0BandLevel()";
        getEqualizer(0); 
        try { 
            short numBands = mEqualizer.getNumberOfBands();
            assertTrue(msg + ": not enough bands", numBands >= MIN_NUMBER_OF_BANDS);
 
            short[] levelRange = mEqualizer.getBandLevelRange();
            assertTrue(msg + ": min level too high", levelRange[0] <= MIN_BAND_LEVEL);
            assertTrue(msg + ": max level too low", levelRange[1] >= MAX_BAND_LEVEL);
 
            mEqualizer.setBandLevel((short)0, levelRange[1]);
            short level = mEqualizer.getBandLevel((short)0);
            // 10% margin on actual level compared to requested level 
            assertTrue(msg + ": setBandLevel failed",
                    ((float)level > (float)levelRange[1] * 0.9f) &&
                    ((float)level < (float)levelRange[1] * 1.1f));
            result = true;
        } catch (IllegalArgumentException e) {

9
CodeRank
This code example shows how to use the following methods:release, getCurrentPreset, getNumberOfPresets, getPresetName, usePreset
    public void test1_2Presets() throws Exception { 
        boolean result = false;
        String msg = "test1_2Presets()";
        getEqualizer(0); 
        try { 
            short numPresets = mEqualizer.getNumberOfPresets();
            assertTrue(msg + ": getNumberOfPresets failed", numPresets >= MIN_NUMBER_OF_PRESETS);
            mEqualizer.usePreset((short)(numPresets - 1));
            short preset = mEqualizer.getCurrentPreset();
            assertEquals(msg + ": usePreset failed", preset, (short)(numPresets - 1));
            String name = mEqualizer.getPresetName(preset);
            assertNotNull(msg + ": getPresetName failed", name);
            result = true;
        } catch (IllegalArgumentException e) {
            msg = msg.concat(": Bad parameter value");
            loge(msg, "Bad parameter value");
        } catch (UnsupportedOperationException e) {
            msg = msg.concat(": get parameter() rejected");
            loge(msg, "get parameter() rejected");
        } catch (IllegalStateException e) {

7
CodeRank
This code example shows how to use the following methods:setEnabled
	 * Create the equalizer and attach it to the given MediaPlayer's audio 
	 * session. 
	 */ 
	public CompatEq(MediaPlayer player)
	{ 
		Equalizer eq = new Equalizer(0, player.getAudioSessionId());
		eq.setEnabled(true);
		mEq = eq;
	} 
 
	/** 
	 * Call {@link Equalizer#getNumberOfBands()} 
	 */ 
	public short getNumberOfBands() 
	{ 
		return mEq.getNumberOfBands();
	} 
 
	/** 
	 * Call {@link Equalizer#setBandLevel(short, short)}. 
6
CodeRank
This code example shows how to use the following methods:release, getCurrentPreset, getNumberOfPresets, getPresetName, usePreset
    public void test1_2Presets() throws Exception { 
        boolean result = false;
        String msg = "test1_2Presets()";
        getEqualizer(0); 
        try { 
            short numPresets = mEqualizer.getNumberOfPresets();
            assertTrue(msg + ": getNumberOfPresets failed", numPresets >= MIN_NUMBER_OF_PRESETS);
            mEqualizer.usePreset((short)(numPresets - 1));
            short preset = mEqualizer.getCurrentPreset();
            assertEquals(msg + ": usePreset failed", preset, (short)(numPresets - 1));
            String name = mEqualizer.getPresetName(preset);
            assertNotNull(msg + ": getPresetName failed", name);
            result = true;
        } catch (IllegalArgumentException e) {
            msg = msg.concat(": Bad parameter value");
            loge(msg, "Bad parameter value");
        } catch (UnsupportedOperationException e) {
            msg = msg.concat(": get parameter() rejected");
            loge(msg, "get parameter() rejected");
        } catch (IllegalStateException e) {

6
CodeRank
This code example shows how to use the following methods:setBandLevel
            bar.setProgress(mEqualizer.getBandLevel(band));
 
            bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar seekBar, int progress,
                        boolean fromUser) {
                    mEqualizer.setBandLevel(band, (short) (progress + minEQLevel));
                } 
 
                public void onStartTrackingTouch(SeekBar seekBar) {}
                public void onStopTrackingTouch(SeekBar seekBar) {}
            }); 
 
            row.addView(minDbTextView);
            row.addView(bar);
            row.addView(maxDbTextView);
 
            mLinearLayout.addView(row);
        } 
    } 
 
6
CodeRank
This code example shows how to use the following methods:release
    protected void onPause() { 
        super.onPause(); 
 
        if (isFinishing() && mMediaPlayer != null) {
            mVisualizer.release();
            mEqualizer.release();
            mMediaPlayer.release();
            mMediaPlayer = null;
        } 
    } 
} 
 
/** 
 * A simple class that draws waveform data received from a 
 * {@link Visualizer.OnDataCaptureListener#onWaveFormDataCapture } 
 */ 
class VisualizerView extends View {
    private byte[] mBytes;
    private float[] mPoints;
    private Rect mRect = new Rect();
5
CodeRank
This code example shows how to use the following methods:setEnabled
        updateBars(); 
        return true; 
    } 
 
    private void setEqualizerEnabled(boolean enabled) {
        equalizer.setEnabled(enabled);
        updateBars(); 
    } 
 
    private void updateBars() { 
 
        for (Map.Entry<Short, SeekBar> entry : bars.entrySet()) {
            short band = entry.getKey();
            SeekBar bar = entry.getValue();
            bar.setEnabled(equalizer.getEnabled());
            short minEQLevel = equalizer.getBandLevelRange()[0];
            bar.setProgress(equalizer.getBandLevel(band) - minEQLevel);
        } 
    } 
 
6
CodeRank
This code example shows how to use the following methods:setEnabled, getBandLevelRange, getNumberOfBands
	 
	private short minimumBandGain;
	 
	public EqualizerHandler(MediaPlayer mediaPlayer) throws PlayerEqualizerException {
		try { 
			equalizer = new Equalizer(PRIORITY, mediaPlayer.getAudioSessionId());
			equalizer.setEnabled(true);
			init(); 
		} catch (Exception e) {
			throw new PlayerEqualizerException("Fail to construct new equalizer object", e);
		} 
	} 
	 
	public void init() { 
		setTotalBandSize(equalizer.getNumberOfBands());
		setMinimumBandGain(equalizer.getBandLevelRange()[0]);
		setMaximumBandGain(equalizer.getBandLevelRange()[1]);
	} 
	 
	public void setGain(short frequency, short gain) {

10
CodeRank
This code example shows how to use the following methods:release, getBandLevelRange, getNumberOfBands
		 
//		eqs = new ArrayList<SessionEqualizer>(); 
		 
		if (9 <= Build.VERSION.SDK_INT) {
			try { 
		        eq = new Equalizer(PRIORITY, 0);
				bands = eq.getNumberOfBands();
				 
				SpeakerBoost.log("Set up equalizer, have "+bands+" bands");
				 
				rangeLow = eq.getBandLevelRange()[0];
				rangeHigh = eq.getBandLevelRange()[1];
 
				SpeakerBoost.log("range "+rangeLow+ " "+rangeHigh);
				 
				if (!activeEqualizer) {
					eq.release();
					released = true;
				} 
				else { 

5
CodeRank
This code example shows how to use the following methods:release, getBandLevelRange, getNumberOfBands
		 
		eq = null;
		 
		if (9 <= Build.VERSION.SDK_INT) {
			try { 
		        eq = new Equalizer(activeEqualizer ? 87654323 : Integer.MIN_VALUE, 0);
				bands = eq.getNumberOfBands();
				 
				rangeLow = eq.getBandLevelRange()[0];
				rangeHigh = eq.getBandLevelRange()[1];
				 
				if (!activeEqualizer) {
					eq.release();
					released = true;
				} 
				else { 
					released = false;
				} 
			} 
			catch (UnsupportedOperationException e) {
5
CodeRank

Related Android Equalizer Questions & Answers:

See Code Examples for Android Equalizer Methods: