Android Visualizer FFT / waveform affected by device volume?
Asked Answered
R

2

8

I'm working on some music analysis using the Visualizer class on Android 2.3.1. I am finding that the FFT and waveform magnitudes are affected by the volume of the device. This means that if the user has the volume turned down I receive little or not FFT data.

I've tested this on a Motorola Xoom, Samsung Galaxy Tab and the emulator and it behaves this way.

I am using the code below:

mp = new MediaPlayer();
mp.setDataSource("/sdcard/sine1.wav");
mp.prepare();
mp.setLooping(true);
mp.start();
int audioSessionID = mp.getAudioSessionId();
v = new Visualizer(audioSessionID);
v.setEnabled(true);

Looking at the docs for the Visualizer class it seems that if we are passing in a valid audio session id then the visualizer should operate upon this audio session. It appears that the Visualizer is operating upon the output mix.

Has anyone else encountered this or found a way around it?

Thanks

Ratsbane answered 8/11, 2011 at 10:3 Comment(1)
G
10

I was also facing the same problem, but it is working when i am enabled the Eqaulizer and Visualizer for same seession id.I dont know the reason for it ,i checked it remove the equalizer from visualizer class in api demos it is working as you said.

 Equalizer mEqualizer = new Equalizer(0, SessionId);
 mEqualizer.setEnabled(true); // need to enable equalizer
 Visualizer mVisualizer = new Visualizer(SessionId);
Guria answered 26/11, 2011 at 10:6 Comment(7)
Sorry for my bad english.Hope that what you can understand i am saying .Guria
Hi, thanks for the suggestion however this didn't fix it for me.Ratsbane
hi,test with api demos ,there is an examples of visualizer and equalizer class.put comment line for equalizer class and observe it,waveform plays depend upon volume.Guria
Thanks sony - I tried the API demos and you are correct. I found the problem with my code. I wasn't calling mEqualizer.setEnabled(true);. Now I'm calling that, it's working at all volumes. Thanks for the help!Ratsbane
In case the above doesn't work, try to enable the Equalizer AFTER! constructing the Visualizer. At least that's been my experience. It wouldn't work otherwise ...Stivers
This does not work for me with an audioSession of 0. Enabling the equalizer before or after the visualizer doesn't seem to make a difference either.Happiness
Agreed with @BigMoney, this solution is not workingMotor
D
0

There are two options for the Visualizer scaling mode:

SCALING_MODE_AS_PLAYED and SCALING_MODE_NORMALIZED

If you want the Visualizer to be normalized, as in it's consistent no matter what the volume is, then use SCALING_MODE_NORMALIZED.

mVisualizer.scalingMode = Visualizer.SCALING_MODE_AS_PLAYED

Keep in mind though that this drastically changes the values being sent to the Visualizer, so other adjustments may be needed.

Dorweiler answered 15/7, 2020 at 7:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.