在android中重置均衡器的带级别

时间:2017-07-21 18:56:23

标签: android android-mediaplayer android-seekbar android-music-player equalizer

我已经实现了这样的5频段均衡器 -

    final short lowerEqualizerBandLevel = MusicService.equalizer.getBandLevelRange()[0];
    final short upperEqualizerBandLevel = MusicService.equalizer.getBandLevelRange()[1];

    for (short i = 0; i < 5; i++) {
        final short equalizerBandIndex = i;
        seekBars[i] = (SeekBar) findViewById(seekBars[i]);
        seekBars[i].setMax(upperEqualizerBandLevel - lowerEqualizerBandLevel);
        levels[i] = (TextView) findViewById(levels[i]);
        levels[i].setText((MusicService.equalizer.getCenterFreq(equalizerBandIndex) / 1000) + "Hz");
        seekBars[i].setProgress((upperEqualizerBandLevel - lowerEqualizerBandLevel) / 2);
        seekBars[i].setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                MusicService.equalizer.setBandLevel(equalizerBandIndex, (short) (progress + lowerEqualizerBandLevel));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }

但是我想添加一个重置按钮来重置均衡器的所有波段电平,我这样做了 -

reset.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            for (short i = 0; i < 5; i++) {
                MusicService.equalizer.setBandLevel(i, (short) MusicService.equalizer.getCenterFreq(i));
                seekBars[i].setProgress((upperEqualizerBandLevel - lowerEqualizerBandLevel) / 2);
            }
        }
    });

我想知道这是不是

MusicService.equalizer.setBandLevel(i, (short) MusicService.equalizer.getCenterFreq(i));

是重置均衡器的正确方法。

有时我也会通过这种方法获得非常高的音高。

1 个答案:

答案 0 :(得分:0)

有三件事要知道。

1)每个均衡器频段都支持/控制一系列频率。因此,当您致电equalizer.getCenterFreq(short bandIndex)时,它会为您提供其支持/控制的频率范围的中心。

2)重置均衡器:均衡器默认使用一些preset。我假设通过重置你的意思是将一些先前的预设分配给均衡器。你可以用

short index = equalizer.getCurrentPreset();
//save this index and later assing this preset via equalizer.usePreset(index)

3)您可以按如下方式获得每个频段的最高和最低限制:

short[] range = equalizer.getBandLevelRange();
//where range[0] is lowest while range[1] is highest limit. And you can
//set band level to either of these higher or lower limits. As you require.

通常乐队等级范围是-1500到+1500(在我的测试案例中)。因此,如果您计划将所有频段重置为零,那么您可以这样:

equalizer.setBandLevel(1 /*short bandIndex*/, 0 /*short level*/);

希望它有所帮助。