Audiotrack setVolume - minimum value - android

I am writing a simple app for testing hearing and I am generating pure tones with Audiotrack. Because it is an app for testing hearing I am using VERY low volume levels to play these tones.
To set volume I use audiotrack's setVolume(float volumeValue) method, where volumeValue = 0-1.
I noticed the lowest volume I can get a device to play is about ~ 5.011872E-5. If I try to play sound with lower volume - e.g. 4.466836E-5, the sound is not played by the device. There is no error, just simply device does not play it.
Is it normal? Is there some kind of minimum limit level for Audiotrack volume value? Or maybe it's hardware connected issue - device cannot reproduce such quiet sounds?

You need to setVolume as two digit float value for example 0.02f.

Related

agora.io Android SDK: how to adjust microphone volume

I've integrated the Agora android SDK into my app. In the video chat channel, some of my testing android devices have very low microphone volume (eg, Pixel 2 / 2 XL), is there a way to always set the microphone volume to the highest?
Thanks in advance!
You can take a look at the following guide on how to control the volume: https://docs.agora.io/en/Video/volume_android?platform=Android.
In particular, to control the recording volume, you will need to do the following:
int volume = 200;
// Sets the volume of the recorded signal.
rtcEngine.adjustRecordingSignalVolume(volume);
400 is the highest possible value for the volume.

How to set type to my audio so it will be treated like a call?

I'm making VoIP app on Android, playing PCM audio like in Play PCM stream in Android
On my phone (LG V20, Android8) it works, but when I'm using volume buttons, it doesn't show Call volume and volume control doesn't work for my audio at all.
How to make my audio "Call audio" and be controlled by standard volume controls?
You have to take AudioFocus by calling "requestAudioFocus()": https://developer.android.com/reference/android/media/AudioManager#requestAudioFocus(android.media.AudioFocusRequest) and set VOICECALL Stream in the Constructor of the Request.
In the end, I was missing:
Permission - MODIFY_AUDIO_SETTINGS
Setting AudioManager mode to MODE_IN_COMMUNICATION
I'm surprised it wasn't in tutorials, maybe it was changed in later SDK.

Android API to set volume level

Which Android API can we use to set the volume level on my tablet for playing a tone when the headset is plugged in .
Currently I use the following API which does not seem to work when the headset is plugged in.
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 9, AudioManager.FLAG_SHOW_UI);
I made the following settings to route audio through the speaker when the headset is plugged in (this is the requirement of my app)
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);
When I play my desired tone after this setting the audio is routed through the speaker (even though headset is connected) but the volume is too high , which looks like the setStreamVolume API does not work since I have set it to only volume level 9 which is pretty low.
If I remove the headset and run my use-case then this API works fine, i.e the tone is played at a lower volume.
Is there any other API that can be used to set the volume for playing tones in Android when the headset is plugged in ?
Unless your app is a cellular call replacement, using MODE_IN_CALL actually optimizes cellular audio and starves STREAM_MUSIC on resource. If you are using STREAM_MUSIC audio with MODE_IN_CALL, depending on phone manufacturer/carrier extension of AudioPolicyManagerBase, you will see many odd behavior such as maybe the case you are seeing.
First, make sure you specify playing audio over STREAM_MUSIC. So that your volume control indeed is controlling the right stream.
Second, I would suggest use MODE_IN_COMMUNICATION instead of MODE_IN_CALL. Many manufacturer/carrier specific audio policy is specific to MODE_IN_CALL(cellular call) only.
Third, if it still happens, you should test your app on a different phone manufacturer/carrier to isolate the issue. Sometime it is a device specific flaw that you just can't fix. I have seen some cases like this myself.

How to change sampling rate for android's MediaPlayer

I am wondering if there is a way to change the sampling rate at which MediaPlayer plays data back. I'd like to tweak it and play data back at a slower rate than encoded. Thoughts?
This might not be doable with MediaPlayer, but for audio you can do it with SoundPool:
The playback rate can also be changed. A playback rate of 1.0 causes
the sound to play at its original frequency (resampled, if necessary,
to the hardware output frequency). A playback rate of 2.0 causes the
sound to play at twice its original frequency, and a playback rate of
0.5 causes it to play at half its original frequency. The playback rate range is 0.5 to 2.0.
You didn't mention this in your original question, but if you want to maintain pitch while changing the frequency, you'd need to provide a pitch-shift algorithm. Perhaps there's one in the android.media.audiofx package - there's a queryEffects() method that might return some type of pitch shifter.
For MediaPlayer, you might look at the attachAuxEffect method that would let you process the audio stream.

Can I set volume beyond AudioManager.getStreamMaxVolume?

I am making a birding app with playback to call birds. Many of the songs recorded are quite bad, some with very low volume. I know how to set max volume of music with
AudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
but this may not be enough for many songs; my Galaxy Note has quite bad speakers, and even with headphones max is low...
Would it be possible to add gain over this max for low volume songs, in order to be played at a decent volume?
This may sound like a silly question, but mplayer for Linux/Maemo has this option, called gain, that allowed me to play some songs higher than max in a Nokia N800.
Thanks!!
instead of using mediaplayer use audiotrack to play the filese. for the the work flow will be following
read from the files as byte or short array
to add a gain just multiply the sample by some fraction
(related question Android - how to add gain control when recording)
now write the samples to audiotrack
then play it.

Categories

Resources