Search in sources :

Example 56 with AudioEffect

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

the class MediaPresetReverbTest 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.setPreset((short) PresetReverb.PRESET_PLATE);
        mReverb.setEnabled(true);
        mp.prepare();
        mp.start();
        Thread.sleep(1000);
        mp.stop();
        Thread.sleep(200);
        // measure energy around 1kHz after media player was stopped for 200 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)

Example 57 with AudioEffect

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

the class MediaVisualizerTest method test2_1ListenerCapture.

//Test case 2.1: test capture with listener
@LargeTest
public void test2_1ListenerCapture() throws Exception {
    boolean result = false;
    String msg = "test2_1ListenerCapture()";
    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);
    try {
        // 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);
        getVisualizer(mp.getAudioSessionId());
        createListenerLooper();
        synchronized (lock) {
            try {
                lock.wait(1000);
            } catch (Exception e) {
                Log.e(TAG, "Looper creation: wait was interrupted.");
            }
        }
        assertTrue(mInitialized);
        mVisualizer.setEnabled(true);
        // check capture on silence
        synchronized (lock) {
            try {
                mCaptureWaveform = true;
                lock.wait(1000);
                mCaptureWaveform = false;
            } catch (Exception e) {
                Log.e(TAG, "Capture waveform: wait was interrupted.");
            }
        }
        assertNotNull(msg + ": waveform capture failed", mWaveform);
        int energy = computeEnergy(mWaveform, true);
        assertEquals(msg + ": getWaveForm reports energy for silence", 0, energy);
        synchronized (lock) {
            try {
                mCaptureFft = true;
                lock.wait(1000);
                mCaptureFft = false;
            } catch (Exception e) {
                Log.e(TAG, "Capture FFT: wait was interrupted.");
            }
        }
        assertNotNull(msg + ": FFT capture failed", mFft);
        energy = computeEnergy(mFft, false);
        assertEquals(msg + ": getFft reports energy for silence", 0, energy);
        mp.prepare();
        mp.start();
        Thread.sleep(500);
        // check capture on sound
        synchronized (lock) {
            try {
                mCaptureWaveform = true;
                lock.wait(1000);
                mCaptureWaveform = false;
            } catch (Exception e) {
                Log.e(TAG, "Capture waveform: wait was interrupted.");
            }
        }
        assertNotNull(msg + ": waveform capture failed", mWaveform);
        energy = computeEnergy(mWaveform, true);
        assertTrue(msg + ": getWaveForm reads insufficient level", energy > 0);
        synchronized (lock) {
            try {
                mCaptureFft = true;
                lock.wait(1000);
                mCaptureFft = false;
            } catch (Exception e) {
                Log.e(TAG, "Capture FFT: wait was interrupted.");
            }
        }
        assertNotNull(msg + ": FFT capture failed", mFft);
        energy = computeEnergy(mFft, false);
        assertTrue(msg + ": getFft reads insufficient level", energy > 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 {
        terminateListenerLooper();
        releaseVisualizer();
        if (mp != null) {
            mp.release();
        }
        if (vc != null) {
            vc.release();
        }
        am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
        am.setRingerMode(ringerMode);
    }
    assertTrue(msg, result);
}
Also used : AudioManager(android.media.AudioManager) AudioEffect(android.media.audiofx.AudioEffect) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 58 with AudioEffect

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

the class MediaVisualizerTest method test2_0PollingCapture.

//-----------------------------------------------------------------
// 2 - check capture
//----------------------------------
//Test case 2.0: test capture in polling mode
@LargeTest
public void test2_0PollingCapture() throws Exception {
    boolean result = false;
    String msg = "test2_0PollingCapture()";
    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);
    try {
        // 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);
        getVisualizer(mp.getAudioSessionId());
        mVisualizer.setEnabled(true);
        // check capture on silence
        byte[] data = new byte[mVisualizer.getCaptureSize()];
        mVisualizer.getWaveForm(data);
        int energy = computeEnergy(data, true);
        assertEquals(msg + ": getWaveForm reports energy for silence", 0, energy);
        mVisualizer.getFft(data);
        energy = computeEnergy(data, false);
        assertEquals(msg + ": getFft reports energy for silence", 0, energy);
        mp.prepare();
        mp.start();
        Thread.sleep(500);
        // check capture on sound
        mVisualizer.getWaveForm(data);
        energy = computeEnergy(data, true);
        assertTrue(msg + ": getWaveForm reads insufficient level", energy > 0);
        mVisualizer.getFft(data);
        energy = computeEnergy(data, false);
        assertTrue(msg + ": getFft reads insufficient level", energy > 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 {
        releaseVisualizer();
        if (mp != null) {
            mp.release();
        }
        if (vc != null) {
            vc.release();
        }
        am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
        am.setRingerMode(ringerMode);
    }
    assertTrue(msg, result);
}
Also used : AudioManager(android.media.AudioManager) AudioEffect(android.media.audiofx.AudioEffect) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 59 with AudioEffect

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

the class MediaVisualizerTest method test2_2PollingCaptureVolumeScaling.

//Test case 2.2: test capture in polling mode with volume scaling
@LargeTest
public void test2_2PollingCaptureVolumeScaling() throws Exception {
    // test that when playing a sound, the energy measured with Visualizer in
    //   SCALING_MODE_AS_PLAYED mode decreases when lowering the volume
    boolean result = false;
    String msg = "test2_2PollingCaptureVolumeScaling()";
    AudioEffect vc = null;
    MediaPlayer mp = null;
    AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
    int ringerMode = am.getRingerMode();
    am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    final int volMax = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    am.setStreamVolume(AudioManager.STREAM_MUSIC, volMax, 0);
    try {
        // test setup not related to tested functionality:
        // 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);
        getVisualizer(mp.getAudioSessionId());
        // verify we successfully set the Visualizer in SCALING_MODE_AS_PLAYED mode
        mVisualizer.setScalingMode(Visualizer.SCALING_MODE_AS_PLAYED);
        assertTrue(msg + " get volume scaling doesn't return SCALING_MODE_AS_PLAYED", mVisualizer.getScalingMode() == Visualizer.SCALING_MODE_AS_PLAYED);
        mVisualizer.setEnabled(true);
        mp.prepare();
        mp.start();
        Thread.sleep(500);
        // check capture on sound with music volume at max
        byte[] data = new byte[mVisualizer.getCaptureSize()];
        mVisualizer.getWaveForm(data);
        int energyAtVolMax = computeEnergy(data, true);
        assertTrue(msg + ": getWaveForm reads insufficient level", energyAtVolMax > 0);
        log(msg, " engergy at max volume = " + energyAtVolMax);
        // check capture on sound with music volume lowered from max
        am.setStreamVolume(AudioManager.STREAM_MUSIC, (volMax * 2) / 3, 0);
        Thread.sleep(500);
        mVisualizer.getWaveForm(data);
        int energyAtLowerVol = computeEnergy(data, true);
        assertTrue(msg + ": getWaveForm at lower volume reads insufficient level", energyAtLowerVol > 0);
        log(msg, "energy at lower volume = " + energyAtLowerVol);
        assertTrue(msg + ": getWaveForm didn't report lower energy when volume decreases", energyAtVolMax > energyAtLowerVol);
        result = true;
    } catch (IllegalArgumentException e) {
        msg = msg.concat(": IllegalArgumentException");
        loge(msg, " hit exception " + e);
    } catch (UnsupportedOperationException e) {
        msg = msg.concat(": UnsupportedOperationException");
        loge(msg, " hit exception " + e);
    } catch (IllegalStateException e) {
        msg = msg.concat("IllegalStateException");
        loge(msg, " hit exception " + e);
    } catch (InterruptedException e) {
        loge(msg, " sleep() interrupted");
    } finally {
        releaseVisualizer();
        if (mp != null) {
            mp.release();
        }
        if (vc != null) {
            vc.release();
        }
        am.setRingerMode(ringerMode);
    }
    assertTrue(msg, result);
}
Also used : AudioManager(android.media.AudioManager) AudioEffect(android.media.audiofx.AudioEffect) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 60 with AudioEffect

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

the class MediaAudioEffectTest method test4_5GetParameterIntArrayShortArray.

//Test case 4.5: test getParameter(int[], short[])
@LargeTest
public void test4_5GetParameterIntArrayShortArray() throws Exception {
    boolean result = false;
    String msg = "test4_5GetParameterIntArrayShortArray()";
    AudioEffect effect = null;
    try {
        effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, AudioEffect.EFFECT_TYPE_NULL, 0, 0);
        assertNotNull(msg + ": could not create AudioEffect", effect);
        int[] param = new int[1];
        short[] value = new short[1];
        param[0] = Equalizer.PARAM_CURRENT_PRESET;
        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)

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