1

I have implemented a 5 band equalizer like this-

    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) {

            }
        });
    }

However I wanted to add a reset button to reset all the band levels for equalizer which I did like this-

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

I wanted to know if this is

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

is the correct way of resetting the equalizer.

And also sometimes i get a really high pitch sound by this method.

Naimish Srivastava
  • 373
  • 1
  • 3
  • 14

1 Answers1

0

There are 3 things to know.

1) Every equalizer band supports/controls a range of frequencies. Therefore when you call equalizer.getCenterFreq(short bandIndex) it gives you the center of the range of the frequencies that it supports/controls.

2) Resetting the equalizer: The equalizer will be using some preset by default. I assume by resetting you mean to assign some prior preset to the equalizer. That you can do using

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

3) You can get highest and lowest limit of every band also as follows:

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.

Normally the band level range is -1500 to +1500 (as in my test cases). So if you plan to reset all band to zero then you can go as this:

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

Hope it helps.

Shoaib Anwar
  • 1,555
  • 12
  • 26