我正在尝试对使用 AudioTrack 生成的正弦波应用混响效果。我尝试了 presetReverb 并将其应用于音频会话 0,就像文档说的那样,因为执行 getAudioSessionId() 方法会带来错误,但这根本没有应用混响。所以我尝试了 EnvironmentalReverb 并尝试了 audiosession 0,还使用了 getAudioSessionId(),两者都没有创建混响。
这是我的代码:
t = new Thread()
{
public void run()
{
setPriority(Thread.MAX_PRIORITY);
int buffsize = AudioTrack.getMinBufferSize(sr, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sr, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, buffsize, AudioTrack.MODE_STREAM);
EnvironmentalReverb reverb = new EnvironmentalReverb(1,0);
audioTrack.attachAuxEffect(reverb.getId());
reverb.setDiffusion((short) 1000);
reverb.setReverbLevel((short) 1000);
reverb.setDecayTime(10000);
reverb.setReverbDelay(100);
reverb.setDensity((short) 1000);
audioTrack.setAuxEffectSendLevel(1.0f);
reverb.setEnabled(true);
short samples[] = new short[buffsize];
int amp = 32767;
double twopi = 2*Math.PI;
double fr = 262.f;
double ph = 0.0;
audioTrack.play();
while(isRunning)
{
fr = 262;
for(int i=0; i < buffsize; i++)
{
samples[i] = (short) (amp*Math.sin(ph));
ph += twopi*fr/sr;
}
audioTrack.write(samples, 0, buffsize);
}
audioTrack.stop();
audioTrack.release();
}
};
t.start();
我的清单中有修改音频设置的权限,为什么这不会产生混响效果?