Search in sources :

Example 61 with AudioEffect

use of android.media.audiofx.AudioEffect in project android_frameworks_base by DirtyUnicorns.

the class MediaAudioEffectTest method test5_0setEnabledLowerPriority.

//-----------------------------------------------------------------
// 5 priority and listeners
//----------------------------------
//Test case 5.0: test control passed to higher priority client
@LargeTest
public void test5_0setEnabledLowerPriority() throws Exception {
    boolean result = false;
    String msg = "test5_0setEnabledLowerPriority()";
    AudioEffect effect1 = null;
    AudioEffect effect2 = null;
    try {
        effect1 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, AudioEffect.EFFECT_TYPE_NULL, 0, 0);
        effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, AudioEffect.EFFECT_TYPE_NULL, 1, 0);
        assertNotNull(msg + ": could not create AudioEffect", effect1);
        assertNotNull(msg + ": could not create AudioEffect", effect2);
        assertTrue(msg + ": Effect2 does not have control", effect2.hasControl());
        assertFalse(msg + ": Effect1 has control", effect1.hasControl());
        assertTrue(msg + ": Effect1 can enable", effect1.setEnabled(true) == AudioEffect.ERROR_INVALID_OPERATION);
        assertFalse(msg + ": Effect1 has enabled", effect2.getEnabled());
        result = true;
    } catch (IllegalArgumentException e) {
        msg = msg.concat(": Effect not found");
        result = false;
    } catch (UnsupportedOperationException e) {
        msg = msg.concat(": Effect library not loaded");
        result = false;
    } finally {
        if (effect1 != null) {
            effect1.release();
        }
        if (effect2 != null) {
            effect2.release();
        }
    }
    assertTrue(msg, result);
}
Also used : AudioEffect(android.media.audiofx.AudioEffect) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 62 with AudioEffect

use of android.media.audiofx.AudioEffect in project android_frameworks_base by DirtyUnicorns.

the class MediaAudioEffectTest method test3_1SetParameterIntInt.

//Test case 3.1: test setParameter(int, int)
@LargeTest
public void test3_1SetParameterIntInt() throws Exception {
    boolean result = false;
    String msg = "test3_1SetParameterIntInt()";
    AudioEffect effect = null;
    try {
        effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, AudioEffect.EFFECT_TYPE_NULL, 0, 0);
        assertNotNull(msg + ": could not create AudioEffect", effect);
        if (effect.setParameter(EnvironmentalReverb.PARAM_DECAY_TIME, 0) == AudioEffect.SUCCESS) {
            result = true;
        }
    } catch (IllegalArgumentException e) {
        msg = msg.concat(": Bad parameter value");
        loge(msg, "Bad parameter value");
    } catch (UnsupportedOperationException e) {
        msg = msg.concat(": setParameter() rejected");
        loge(msg, "setParameter() rejected");
    } catch (IllegalStateException e) {
        msg = msg.concat("setParameter() called in wrong state");
        loge(msg, "setParameter() called in wrong state");
    } finally {
        if (effect != null) {
            effect.release();
        }
    }
    assertTrue(msg, result);
}
Also used : AudioEffect(android.media.audiofx.AudioEffect) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 63 with AudioEffect

use of android.media.audiofx.AudioEffect in project android_frameworks_base by DirtyUnicorns.

the class MediaAudioEffectTest method test4_4GetParameterIntArrayIntArray.

//Test case 4.4: test getParameter(int[], int[])
@LargeTest
public void test4_4GetParameterIntArrayIntArray() throws Exception {
    boolean result = false;
    String msg = "test4_4GetParameterIntArrayIntArray()";
    AudioEffect effect = null;
    try {
        effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, AudioEffect.EFFECT_TYPE_NULL, 0, 0);
        assertNotNull(msg + ": could not create AudioEffect", effect);
        int[] param = new int[1];
        int[] value = new int[1];
        param[0] = EnvironmentalReverb.PARAM_DECAY_TIME;
        if (!AudioEffect.isError(effect.getParameter(param, value))) {
            result = true;
        }
    } catch (IllegalArgumentException e) {
        msg = msg.concat(": Bad parameter value");
        loge(msg, "Bad parameter value");
    } catch (UnsupportedOperationException e) {
        msg = msg.concat(": getParameter() rejected");
        loge(msg, "getParameter() rejected");
    } catch (IllegalStateException e) {
        msg = msg.concat("getParameter() called in wrong state");
        loge(msg, "getParameter() called in wrong state");
    } finally {
        if (effect != null) {
            effect.release();
        }
    }
    assertTrue(msg, result);
}
Also used : AudioEffect(android.media.audiofx.AudioEffect) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 64 with AudioEffect

use of android.media.audiofx.AudioEffect in project android_frameworks_base by DirtyUnicorns.

the class MediaAudioEffectTest method test5_2ControlStatusListener.

//Test case 5.2: test control status listener
@LargeTest
public void test5_2ControlStatusListener() throws Exception {
    boolean result = false;
    String msg = "test5_2ControlStatusListener()";
    mEffect = null;
    AudioEffect effect2 = null;
    try {
        mHasControl = true;
        createListenerLooper(true, false, false);
        synchronized (lock) {
            try {
                lock.wait(1000);
            } catch (Exception e) {
                Log.e(TAG, "Looper creation: wait was interrupted.");
            }
        }
        assertTrue(mInitialized);
        synchronized (lock) {
            try {
                effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, AudioEffect.EFFECT_TYPE_NULL, 1, 0);
                assertNotNull(msg + ": could not create AudioEffect", effect2);
                lock.wait(1000);
            } catch (Exception e) {
                Log.e(TAG, "Create second effect: wait was interrupted.");
            }
        }
        assertFalse(msg + ": effect control not lost by effect1", mHasControl);
        result = true;
    } catch (IllegalArgumentException e) {
        msg = msg.concat(": Equalizer not found");
        loge(msg, ": Equalizer not found");
    } catch (UnsupportedOperationException e) {
        msg = msg.concat(": Effect library not loaded");
        loge(msg, ": Effect library not loaded");
    } catch (Exception e) {
        loge(msg, "Could not create media player:" + e);
    } finally {
        terminateListenerLooper();
        if (effect2 != null) {
            effect2.release();
        }
    }
    assertTrue(msg, result);
}
Also used : AudioEffect(android.media.audiofx.AudioEffect) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 65 with AudioEffect

use of android.media.audiofx.AudioEffect in project android_frameworks_base by DirtyUnicorns.

the class MediaEnvReverbTest method test2_0AuxiliarySoundModification.

//-----------------------------------------------------------------
// 2 - Effect action
//----------------------------------
//Test case 2.0: test actual auxiliary reverb influence on sound
@LargeTest
public void test2_0AuxiliarySoundModification() throws Exception {
    boolean result = false;
    String msg = "test2_0AuxiliarySoundModification()";
    EnergyProbe probe = null;
    AudioEffect vc = null;
    MediaPlayer mp = null;
    AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
    int ringerMode = am.getRingerMode();
    am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
    getReverb(0);
    try {
        probe = new EnergyProbe(0);
        // creating a volume controller on output mix ensures that ro.audio.silent mutes
        // audio after the effects and not before
        vc = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, VOLUME_EFFECT_UUID, 0, 0);
        vc.setEnabled(true);
        mp = new MediaPlayer();
        mp.setDataSource(MediaNames.SINE_200_1000);
        mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mp.attachAuxEffect(mReverb.getId());
        mp.setAuxEffectSendLevel(1.0f);
        mReverb.setRoomLevel((short) 0);
        mReverb.setReverbLevel((short) 0);
        mReverb.setDecayTime(2000);
        mReverb.setEnabled(true);
        mp.prepare();
        mp.start();
        Thread.sleep(1000);
        mp.stop();
        Thread.sleep(300);
        // measure energy around 1kHz after media player was stopped for 300 ms
        int energy1000 = probe.capture(1000);
        assertTrue(msg + ": reverb has no effect", energy1000 > 0);
        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) {
        msg = msg.concat("get parameter() called in wrong state");
        loge(msg, "get parameter() called in wrong state");
    } catch (InterruptedException e) {
        loge(msg, "sleep() interrupted");
    } finally {
        releaseReverb();
        if (mp != null) {
            mp.release();
        }
        if (vc != null) {
            vc.release();
        }
        if (probe != null) {
            probe.release();
        }
        am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
        am.setRingerMode(ringerMode);
    }
    assertTrue(msg, result);
}
Also used : AudioManager(android.media.AudioManager) EnergyProbe(com.android.mediaframeworktest.functional.EnergyProbe) AudioEffect(android.media.audiofx.AudioEffect) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

AudioEffect (android.media.audiofx.AudioEffect)235 LargeTest (android.test.suitebuilder.annotation.LargeTest)234 MediaPlayer (android.media.MediaPlayer)54 AudioManager (android.media.AudioManager)42 EnergyProbe (com.android.mediaframeworktest.functional.EnergyProbe)24 AssetFileDescriptor (android.content.res.AssetFileDescriptor)12 AudioRecord (android.media.AudioRecord)12 AudioTrack (android.media.AudioTrack)6 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 ActionBar (android.support.v7.app.ActionBar)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 SeekBar (android.widget.SeekBar)1 TextView (android.widget.TextView)1 SystemBarTintManager (com.readystatesoftware.systembartint.SystemBarTintManager)1 SizableSeekBar (com.simplecity.amp_library.ui.views.SizableSeekBar)1