android environmentreverb不执行任何操作 [英] android environmentalreverb doesn't do anything

查看:291
本文介绍了android environmentreverb不执行任何操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将混响效果应用于使用AudioTrack生成的正弦波.我像文档所述那样尝试了presetReverb并将其应用于audiosession 0,因为执行getAudioSessionId()方法带来了一个错误,但是根本没有应用混响.因此,我尝试了EnvironmentalReverb,并尝试了audiosession 0,还使用了getAudioSessionId(),这两个方法均未创建混响.

I'm trying to apply a reverb effect to a sine wave that I'm generating using AudioTrack. I tried presetReverb and applied it to audiosession 0 like the docs said, since doing the getAudioSessionId() method brought an error, but that didn't apply a reverb at all. So I tried EnvironmentalReverb and tried audiosession 0, and also using getAudioSessionId(), both of which didn't create a reverb.

这是我的代码:

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();

我在清单中具有修改音频设置"权限,那么为什么不创建混响效果?

I have the modify audio settings permission in my manifest, so why doesn't this create the reverb effect?

推荐答案

两件事:一,确保在写入"或播放"之前设置效果(并附加).第二,如果希望PresetReverb起作用,则需要执行此操作,然后将其附加到AudioTrack(或MediaPlayer):

Two things: One, make sure you set up your effects (and attaching) BEFORE your "write" or "play". Two, if you want PresetReverb to work, you need to do this and then attach it to your AudioTrack (or MediaPlayer):

PresetReverb reverb = new PresetReverb(1, 0);

请在此过程中查看示例代码,并在底部查看我的回复:

See the example code mid-way through this and my response at the bottom: Android MediaPlayer with AudioEffect : Getting Error (-22,0)

这篇关于android environmentreverb不执行任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆