I am using The Visualizer to draw a Visualization of a Sound File that I am Playing. The sound wave is displaying, however I would like to make it less detailed, as it has an effect on my frame-rate. There is very limited documentation for this. So I have attempted to do the following:
mVisualizer.setCaptureSize(2);
To set the capture rate to a very low value. However, it appears that the line is being drawn with the same amount of detail. I have read in the documentation that:
Sets the capture size, i.e. the number of bytes returned by getWaveForm(byte[]) and getFft(byte[]) methods.
Another issue that I have, is that I would like to detect sounds with a high energy level in the sound File that I am playing so I can visually represent them on the screen. For example: The screen flashes along with the baseline. Here is what I have so far:
public static void setupVisualizer() {
mVisualizer = new Visualizer(mpSong.getAudioSessionId());
mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
mVisualizer.setDataCaptureListener(
new Visualizer.OnDataCaptureListener() {
public void onWaveFormDataCapture(Visualizer visualizer,
byte[] bytes, int samplingRate) {
Game.updateVisualizer(bytes);
}
public void onFftDataCapture(Visualizer visualizer,
byte[] bytes, int samplingRate) {
}
}, Visualizer.getMaxCaptureRate() / 2, true, false);
}
Is it possible to detect certain sounds inside this listener? Or what are the alternatives? Sorry for my bad english. Thank you very much for your time friends.
Ok after several Hours of Testing and Researching I have found a solution. It may not be very accurate, but it is the only alternative I could come up with. I made a class called BeatDetector:
It takes a MediaPlayer Object as a parameter and then Calculates Three Different Frequencies Based on the EnergySum of the Byte Data. It is possible to Split the frequencies as many times as you like. I was considering Creating an Array of Frequencies, that each Have a Listener. I then used the Following to Draw a Rectangle:
This calculates the Height of the Rectangle by Calculating a percentage based on the Max Power and Maximum Height of a Bar. It is not very accurate, but it is the best thing I could come up with. Again, this can be done for as many frequencies as you like. Here are some Links that Helped me out:
https://android.googlesource.com/platform/cts/+/master/tests/tests/media/src/android/media/cts/VisualizerTest.java
https://www.codota.com/android/scenarios/518916b8da0af8330dfa9398/android.media.audiofx.Visualizer?tag=out_2013_05_05_07_19_34
Hope I can help anyone else with these issues.