use of android.media.audiofx.AudioEffect in project android_frameworks_base by DirtyUnicorns.
the class MediaAudioEffectTest method test6_0Command.
//-----------------------------------------------------------------
// 6 command method
//----------------------------------
//Test case 6.0: test command method
@LargeTest
public void test6_0Command() throws Exception {
boolean result = false;
String msg = "test6_0Command()";
AudioEffect effect = null;
try {
effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, AudioEffect.EFFECT_TYPE_NULL, 0, 0);
assertNotNull(msg + ": could not create AudioEffect", effect);
try {
byte[] cmd = new byte[0];
byte[] reply = new byte[4];
int status = effect.command(3, cmd, reply);
assertFalse(msg + ": command failed", AudioEffect.isError(status));
assertTrue(msg + ": effect not enabled", effect.getEnabled());
result = true;
} catch (IllegalStateException e) {
msg = msg.concat(": command in illegal state");
}
} 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 {
if (effect != null) {
effect.release();
}
}
assertTrue(msg, result);
}
use of android.media.audiofx.AudioEffect in project android_frameworks_base by AOSPA.
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);
}
use of android.media.audiofx.AudioEffect in project android_frameworks_base by AOSPA.
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);
}
use of android.media.audiofx.AudioEffect in project android_frameworks_base by AOSPA.
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);
}
use of android.media.audiofx.AudioEffect in project android_frameworks_base by AOSPA.
the class MediaAudioEffectTest method test5_3EnableStatusListener.
//Test case 5.3: test enable status listener
@LargeTest
public void test5_3EnableStatusListener() throws Exception {
boolean result = false;
String msg = "test5_3EnableStatusListener()";
mEffect = null;
AudioEffect effect2 = null;
try {
createListenerLooper(false, true, false);
synchronized (lock) {
try {
lock.wait(1000);
} catch (Exception e) {
Log.e(TAG, "Looper creation: wait was interrupted.");
}
}
assertTrue(mInitialized);
mEffect.setEnabled(true);
mIsEnabled = true;
effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, AudioEffect.EFFECT_TYPE_NULL, 1, 0);
assertNotNull(msg + ": could not create AudioEffect", effect2);
assertTrue(msg + ": effect not enabled", effect2.getEnabled());
synchronized (lock) {
try {
effect2.setEnabled(false);
lock.wait(1000);
} catch (Exception e) {
Log.e(TAG, "Create second effect: wait was interrupted.");
}
}
assertFalse(msg + ": enable status not updated", mIsEnabled);
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);
}
Aggregations