Android均衡器与AudioTrack不正常工作

huangapple go评论81阅读模式
英文:

Android equalizer not working with AudioTrack

问题

以下是翻译好的内容:

我正在使用 Android 均衡器 API 创建高通滤波器。但是,即使我将每个频段都设置为 -1500,似乎也没有起作用。音频播放得很好,但没有均衡效果。以下是我的代码。

private void attachEq(int audioSessionId) {
    Equalizer eq = new Equalizer(100, audioSessionId);
    short[] freqRange = eq.getBandLevelRange();
    short minLvl = freqRange[0];
    short maxLvl = freqRange[1];

    eq.setBandLevel((short) 4, minLvl);
    eq.setBandLevel((short) 3, minLvl);
    eq.setBandLevel((short) 2, minLvl);
    eq.setBandLevel((short) 1, minLvl);
    eq.setBandLevel((short) 0, minLvl);
}

我通过以下方式获取音频会话 ID:

at.getAudioSessionId()

其中 at 是已初始化的 AudioTrack。正如我所说,AudioTrack 播放得很好,但是均衡器似乎没有任何效果。

编辑:我在调用 at.play() 之前还是之后设置频段级别?我是在 at.play() 之前设置的,但似乎没有起作用。

英文:

I am using android equalizer API to create a high pass filter. But even if I set every band to -1500 it does not seems to work. The audio is playing well but no eq effects. Here is my code.

    private void attachEq(int audioSessionId) {
    Equalizer eq = new Equalizer(100,audioSessionId);
    short[] freqRange = eq.getBandLevelRange();
    short minLvl = freqRange[0];
    short maxLvl = freqRange[1];

    eq.setBandLevel((short) 4,minLvl);
    eq.setBandLevel((short) 3,minLvl);
    eq.setBandLevel((short) 2,minLvl);
    eq.setBandLevel((short) 1,minLvl);
    eq.setBandLevel((short) 0,minLvl);
}

I am getting the audio session-id by

> at.getAudioSessionId()

where at is an already initialized AudioTrack. As I said AudioTrack is playing fine but eq doesn't seem to have any effect.

Edit: Do I have to set band levels before I call at.play() or after? I am doing it before at.play() and it doesn't seem to work.

答案1

得分: 2

我搞清楚了!我没有调用 eq.setEnabled(true)。现在它正常工作了!

英文:

I figured it out! I wasn't calling eq.setEnabled(true).
Now it works!

huangapple
  • 本文由 发表于 2020年8月25日 01:24:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/63565844.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定