开发者

Android audio reverb Sample App

Is there any sample code for Audio reverb using PresetReverb class from 2.3 in Android ?


MediaPlayer mMed开发者_如何学编程iaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(this, Uri.parse("/sdcard/music/sample.mp3"));
PresetReverb mReverb = new PresetReverb(0,
mMediaPlayer.getAudioSessionId());
mReverb.setPreset(PresetReverb.PRESET_LARGEROOM);
mReverb.setEnabled(true);
mMediaPlayer.attachAuxEffect(mReverb.getId());
mMediaPlayer.setAuxEffectSendLevel(1.0f);
mMediaPlayer.prepare();
mMediaPlayermp.start();

I executed the source above, but no sound was heard.

When I added this sentence after the souce, I can hear the sound.

Thread.sleep(10000);
mp.stop();

However the sound is normal, not reverbed.

Additionally, this permission is set on Manifest.xml.

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

Is there something else I have to write except for those?


PresetReverb mReverb = new PresetReverb(0,mMediaPlayer.getAudioSessionId());//<<<<<<<<<<<<<
mReverb.setPreset(PresetReverb.PRESET_SMALLROOM);
mReverb.setEnabled(true);
mMediaPlayer.setAuxEffectSendLevel(1.0f);

Dont attach it to mediaplayer. it is already attached if u use getAudioSessionId(). (tested on >v4)

To disable, use effect.setEnabled(false);


Instantiate the PresetReverb. You need the audio session id on which PresetReverb to be attached. Then just set pressets for which reverb you are going to use.

PresetReverb reverb = new  PresetReverb(0, mediaPlayer.getAudioSessionId());
        reverb.setPreset( PresetReverb.PRESET_LARGEHALL);
        reverb.setPreset(PresetReverb.PRESET_LARGEROOM);

Also if you need the parameter listener then let your class implements PresetReverb.OnParameterChangeListener

and then override unimplemented method

@Override
    public void onParameterChange(PresetReverb effect, int status, int param,
            short value) {
        // TODO Auto-generated method stub

    }

at point where you need to apply the reverb, just use: reverb.setEnabled(true);


Using reverb, create a reverb on the output mix (audio session "0" ) (ref.http://developer.android.com/reference/android/media/audiofx/PresetReverb.html)

Reason

'Audio framework' has two connectMode:(EFFECT_INSERT, EFFECT_AUXILIARY), 'Auxiliary effects' must be created on session 0 (global output mix). (ref.http://developer.android.com/reference/android/media/audiofx/AudioEffect.html#EFFECT_AUXILIARY)

Imagine the REAL MIXING CONSOLE.

Sample

PresetReverb mReverb = new PresetReverb(0,0);//<<<<<<<<<<<<<
mReverb.setPreset(PresetReverb.PRESET_LARGEROOM);
mReverb.setEnabled(true);
mMediaPlayer.attachAuxEffect(mReverb.getId());
mMediaPlayer.setAuxEffectSendLevel(1.0f); 


One cent tip here,

Permission MODIFY_AUDIO_SETTINGS is required only if you create a reverb on the output mix (audio session 0)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜