equalizer.getNumberOfPresets() return 0 on certains devices - android

I'm trying to implements presets on an android equalizer, to do so I'm using getNumberOfPresets():
mEqualizer = new Equalizer(0, mMediaPlayer.getAudioSessionId());
mEqualizer.setEnabled(true);
short presetNumber = mEqualizer.getNumberOfPresets();
On my nexus 4 (4.2.2) I'm getting presetNumber=10 but using an other device running android 4.0.4 I get presetNumber=0. With this last value I am not able to use:
mEqualizer.usePreset(short);
How can I force the equalizer to use presets?
thx

All the audio effects are hardware-dependent and not guaranteed on all devices.
Because of this, you should always check if the device supports the AudioEffect.
You can query available effects using AudioEffect.queryEffects();
http://developer.android.com/reference/android/media/audiofx/AudioEffect.html#queryEffects()

Related

Android microphone constantly gives 32639 or -32640 on newer devices

I've implemented code similar to this. I have a noise alert go off in the Log, but it always gives 32639 or -32640 regardless of what kind of noise is going on outside.
short[] buffer = new short[minSize];
boolean thresholdMet = false;
int threshold = sliderThreshold.getProgress();
ar.read(buffer, 0, minSize);
//Iterate through each chunk of amplitude data
//Check if amplitude is greater than threshold
for (short s : buffer) {
if (Math.abs(s) > threshold) {
thresholdMet = true;
Log.w("NoiseThreshold", String.valueOf(s));
break;
}
}
I've tested it on three phones (none of which are rooted):
Samsung Galaxy S3(API 19)
HTC One M9(API 23)
Samsung Galaxy S7(API 24)
It works on the S3, but not the others. I've tried using Sensor Sense on the HTC and it doesn't work for the mic sensor. However, it used to work, and now seems to detect one sample every five seconds or so in the graph view.
Oddly enough, the microphone still works fine for phone calls and video recording on the malfunctioning phones.
You said it works on S3, which is API 19 and doesn't on those with API>=23. So, it's possible that you have a problem with runtime permissions introduced in API 23.
New behaviour (for "old apps" which use static permission model) is to return dummy data if runtime permission is not granted.
Check out this answer:
Request permission for microphone on Android M

Number of bands in Android Equalizer

My question is simple: what is the default number of the bands provided by the built-in android equalizer? Also, what is the guaranteed minimum number of bands?
As far as I researched, the answer appears to be 5, but it is not very well documented. However, testing it on my devices, which is currently available, I got the following result:
HTC Desire S running android 2.3.5: 5 bands
Sony Xperia Tipo running android 4.0.x: 5 bands
however, Nexus 4 running Android 4.3.1: 6 bands
The way I get theese numbers is the following:
MediaPlayer mp=new MediaPlayer(this);
/* some initialization */
Equalizer eq=new Equalizer(0, mp.getAudioSessionId());
short bands=eq.getNumberOfBands();
So, on some devices, I may be able to get more bands, but the minimum number is 5?
Also, is that a good approach that I render the UI part of the equalizer dynamically, depending on how much bands the current device has, and then let the user set his own preferences?
Thanks in advance!
I can't tell the number of bands of device. It is hardware dependent. Samsung galaxy have 13 equalizer bands and some devices have greater than it.
You can simply create any number of bands programamtically.
Equalizer eq=new Equalizer(0, mp.getAudioSessionId());
short bands=eq.getNumberOfBands();
LinearLayout parentViewToAllEqualizerSeekBars = findViewById...
for(int i=0;i<(int)bands.length;i++)
{
//create seekbar programmatically and set it min max and add to the view
Seekbar seek = new SeekBar(this);
seek.min(equalizerMinLevel....)
seek.max(equalizerMaxLevel..)
parentViewToAllEqualizerSeekBars .addView(seek);
}
Now it will work on all devices.Whether it has band less than 5 or greater than 13.
Note:
Also check whether equalizer!=null must
I do not think there is a default number of bands, and you should not build your application assuming there is a default/fixed number of bands.
Definitely you will have to render your UI equalizer dynamically, based on device number of bands.
Because of low reputation i have to tell it to you here
Maximum number of bands are 8, I have created 8 seekbar and only show seekbar ==numberOfBands
How to implement Equalizer in android

Gstreamer Android changing pipeline state issue

I am working at a player based on gstreamer tutorials. For this I created a pipeline using:
pipeline = gst_pipeline_new("audio-player");
//adding also 3 gstreamer elements
appsrc = gst_element_factory_make("appsrc", "source");
decoder = gst_element_factory_make("faad", "aac-decoder");
sink = gst_element_factory_make("autoaudiosink", "audio-output");
//adding and linking the elements to the pipeline
gst_bin_add_many (GST_BIN (pipeline), appsrc, decoder, sink, NULL);
gst_element_link_many(appsrc, decoder,sink, NULL);
//for appsrc was added a callback function need_data_cb
g_signal_connect(appsrc, "need-data", (GCallback)need_data_cb, data);
//state of pipeline is set to playing
gst_element_set_state(pipeline, GST_STATE_PLAYING);
In need_data_cb function I have a buffer that I want to be played:
g_signal_emit_by_name(appsrc, "push-buffer", buffer, &ret);
My poblem is this: I have the same code in Linux and in Android. In Linux buffer is played well each time it enters the callback function need_data_cb. In Android it plays the buffer just the first time it enters in need_data_cb and after that no sound. Why it happens this when I have same code in both versions. If I add in need_data_cb Android version to change pipeline states to pause and play before adding buffer to appsrc, it plays each time buffer but with some interruptions between each call.
//the first 2 lines added in Android version to play each time buffer
gst_element_set_state(pipeline, GST_STATE_PAUSED);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
g_signal_emit_by_name(appsrc, "push-buffer", buffer, &ret);
The question is why on Linux works fine without these lines and on Android not?
On Linux I installed gstreamer 0.10 version, and on Android I used the libs from gstreamer sdk tutorials. Do you have any hint for my problem?
Thanks,
Radu
The problem was due to the emulator. On device everything was ok. Do not use emulators try debugging directly on device!!!

How to get CamcorderProfile.videoBitRate for an Android device?

My app uses HLS to stream video from a server, but when I request the HLS stream from the server I need to pass it the max video bitrate the device can handle. In the Android API guides it says that "a device's available video recording profiles can be used as a proxy for media playback capabilities," but when I try to retrieve the videoBitRate for the devices back-facing camera it always comes back as 12Mb/s regardless of the device (Galaxy Nexus, Galaxy Tab Plus 7", Galaxy Tab 8.9), despite the fact that they have 3 different GPUs (PowerVR SGX540, Mali-400 MP, Tegra 250 T20). Here's my code, am I doing something wrong?
CamcorderProfile camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
targetVideoBitRate = camcorderProfile.videoBitRate;
If I try this on the Galaxy Tab Plus:
boolean hasProfile = CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_HIGH);
it returns True, despite the fact that QUALITY_HIGH is for 1080p recording and the specs say it can only record at 720p.
It looks like I've found the answer to my own question.
I didn't read the documentation closely enough, QUALITY_HIGH is not equivalent to 1080p it is simply a way of specifying the highest quality profile the device supports. Therefore, by definition, CamcorderProfile.hasProfile( CamcorderProfile.QUALITY_HIGH ) is always true. I should have written something like this:
public enum mVideoQuality {
FullHD, HD, SD
}
mVideoQuality mMaxVideoQuality;
int mTargetVideoBitRate;
private void initVideoQuality {
if ( CamcorderProfile.hasProfile( CamcorderProfile.QUALITY_1080P ) ) {
mMaxVideoQuality = mVideoQuality.FullHD;
} else if ( CamcorderProfile.hasProfile( CamcorderProfile.QUALITY_720P ) ) {
mMaxVideoQuality = mVideoQuality.HD;
} else {
mMaxVideoQuality = mVideoQuality.SD;
}
CamcorderProfile cProfile = CamcorderProfile.get( CamcorderProfile.QUALITY_HIGH );
mTargetVideoBitRate = cProfile.videoBitRate;
}
Most of my devices are still reporting support for 1080p encoding, which I'm skeptical of, however I ran this code on a Sony Experia Tipo ( my low end test device ) and it reported a max encode quality of 480p with a videoBitRate of 720Kb/s.
As I said, I'm not sure if every device can be trusted, but I have seen a range of video bitrates from 720Kb/s to 17Mb/s and Profile qualities from 480p - 1080p. Hopefully other people will find this information to be useful.

Android Visualizer FFT / waveform affected by device volume?

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

Categories

Resources