Okay, I finally got into it. I re-read the documentation, played with the code, and suddenly everything worked. These are my findings in case this helps someone in the future.
In the case of PresetReverb
In the presetReverb documentation
PresetReverb is an auxiliary effect of the output mix, and should be created in the audio session 0 . For MediaPlayer or AudioTrack to be used in this effect, they must be explicit and the send level must be specified . Use the effect identifier returned by the getId () method to indicate this particular effect when attaching it to MediaPlayer or AudioTrack.
It says
PresetReverb pReverb = new PresetReverb(0,player.getAudioSessionId()); <== error
is not allowed. You can use the global audio 0 session to create a PresetReverb.
PresetReverb pReverb = new PresetReverb(1,0); <== correct
Now we can connect it using MediaPlayer or AudioTrack using
player.attachAuxEffect(pReverb.getId()); player.setAuxEffectSendLevel(1.0f);
My complete PresetReverb code
PresetReverb pReverb = new PresetReverb(1,0); player.attachAuxEffect(pReverb.getId()); pReverb.setPreset(PresetReverb.PRESET_LARGEROOM); pReverb.setEnabled(true); player.setAuxEffectSendLevel(1.0f);
Note: If you are looking for a good reverb or echo effect, it is better to use EnvironmentalReverb. I am somewhat disappointed with PresetReverb.
In the case of EnvironmentalReverb
From EnvironmentalReverb documentation
EnvironmentalReverb is an auxiliary effect of output mixing and must be created in an audio 0 session. In order for MediaPlayer or AudioTrack to be used in this effect, they must be explicit and the send level must be specified . Use the effect identifier returned by the getId () method to indicate this particular effect when attaching it to MediaPlayer or AudioTrack.
Just like PresetReverb, but when I wrote
Log.e("DEBUG","sessionId : " + player.getAudioSessionId()); <== printed "454" EnvironmentalReverb eReverb = new EnvironmentalReverb(0,player.getAudioSessionId()); //should be error as per documentation //player.attachAuxEffect(eReverb.getId()); <== Yes this one was commented
there was no mistake, and I get a good reverb and echo effect. So this seems like a bug in the documentation. Also, when we pass the session identifier to the player constructor (player.getAudioSessionId ()), it seems that there is no need to attach the player with an EnvironmentalReverb instance. Strange ..
For completeness, this work also worked as written in the documentation.
EnvironmentalReverb eReverb = new EnvironmentalReverb(0,0); player.attachAuxEffect(eReverb.getId()); <== No,not comment this one
For other children AudioEffect (Equalizer, BassBoost, Virtualizer)
These were not part of my question. But for everyone who sees this in the future.
NOTE: adding insert effects (equalizer, bass boost, virtualizer) to the global audio output using session 0 is deprecated.
see documentation
Regarding error (-22.0)
Well, to be honest, this is not an informative error message. I donβt know why the error Invalid license error occurs when we ruined the audio session. Anyway, when I corrected the audio session parameter, this error disappeared. That's all what I know.