How to add stereo,treble options in audio equalizer?

前提是你 提交于 2019-11-30 09:35:39
bonnyz

In order to change the bass, mid, treble there's no need to use the AudioTrack object (even because with this object you could only playback non-compressed PCM data).

You just need to adjust the proper frequency bands level using your Equalizer object. To get the number of available bands, just call:

myEqualizer.getNumberOfBands()

Considering the number of available bands, you can now set the level for each band using the following method:

myEqualizer.setBandLevel(band, level);

where:

band: frequency band that will have the new gain. The numbering of the bands starts from 0 and ends at (number of bands - 1).

level: new gain in millibels that will be set to the given band. getBandLevelRange() will define the maximum and minimum values.

The meaning of each bands, from left to right, is summarized in the following image:

UPDATE

To implement a trivial balance effect, just differentiate the left/right volume on your player (MediaPlayer, SoundPool,...):

mediaPlayer.setVolume(left, right)

To obtain a mono effect you can consider using a Virtualizer, which provides a stereo widening effect. You can set the strength of the virtualization effect using the method:

virtualizer.setStrength(1000); //range is [0..1000]

You need to read the documentation carefully in order to check if the current configuration of your virtualizer is really supported by the underlying system.


Anyway, this is not a real mono output and I think you won't be able to obtain a mono ouput on stereo speaker without using low level API such as AudioTrack (actually Poweramp relies on native JNI libraries for its audio pipeline). If you want to use an AudioTrack for playback you need to consider that it only supports PCM data (WAV) as input: this means you won't be able to play compressed audio file (like MP3, flac, ...) directly since you need to manually decode the compressed audio file first.

[Compressed File (MP3)] ===> decode() ===> [PCM data] ===> customEffect() ===> AudioTrack playback()

Thus, in order to play a compressed audio using and AudioTrack (and eventually create a custom effect) the following steps are required:

  1. decode the compressed file using a decoder (NO PUBLIC SYSTEM API available for this, you need to do it manually!!!).
  2. if necessary, transform uncompressed data in a PCM format which is compatible with AudioTrack
  3. (eventually) apply your transformation on the PCM data stream (e.g. you can merge both L/R channels and create a mono effect)
  4. play the PCM stream using an AudioTrack

I suggest you to skip this effect ;)


Regarding the bass-boost effect, you need to check if your current configuration is supported by the the running device (like the virtualizer). Take a look here for more info on this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!