I'm using AudioRecord and lame to record mic input to a mp3 sample for 12 seconds. The audio is recorder as expected but I realized the volume is too low.
Is there a way to increase the volume of the recording?
There is no gain settings in the audioRecord class to play with, so you cannot control the volume of the audio being recorded. The low volume of the audio is related to the hardware and varies from device to device. Here are a few options you can try.
1) try opening in the audio record in different modes and see whats works best .
check - http://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html
2) in audio record you get the raw PCM buffers. You can write a simple code/function to shift the bits (8/16 bits per channel) left or right to double or halve the gain. (Think of it as a very crude volume control)
3) try searching the net for more complex digital gain techniques for a smoother control.
There are many implementations. (There are proprietary techniques as well)
Check:
How to adjust microphone sensitivity while recording audio in android
you can also simply increase the volume of the device:
AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
int previousVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
am.setStreamVolume(AudioManager.STREAM_MUSIC, 10, 0);
{... do your things ... }
am.setStreamVolume(AudioManager.STREAM_MUSIC, previousVolume, 0);
In my case this was an easy fix and it worked with the rest of the application.
Related
I am using media recorder for recording call in android using VOICE_COMMUNICATION & MIC mode alternatively.
RECORD_SOURCE = MediaRecorder.AudioSource.VOICE_COMMUNICATION;
//RECORD_SOURCE = MediaRecorder.AudioSource.MIC;
iAudioRecorder = new AudioRecord(RECORD_SOURCE, NATIVE_SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, RECORD_BUF_UNIT);
I saw that MIC recorded audio data has gain much greater than VOICE_COMMUNICATION (about 2/3 times) for some devices. Also background music captured by VOICE_COMMUNICATION is not as good as MIC.
Why do audio quality (like gain, responsiveness) differs for this two recording modes?
According to the Android Developer Reference for MIC and VOICE_COMMUNICATION, some pre-processing like echo cancellation, noise suppression is applied on the audio captured using VOICE_COMMUNICATION which, in turn, causes some attenuation on the data. Moreover, on doing such pre-processing, audio signals with low amplitude becomes even more weak due to this attenuation. So we feel like background audio is sort of gone away for some devices when it is too low.
Another point was varied characteristics from device to device. From this link, it solely depends on device manufacturer and they are free to decide which pre-processing should work on which modes and how.
Is Microphone sensitivity and sound measure for loudspeaker adjustable in android? If it can be , how can i do that (with which classes and methods)?
And how can i stimulate a phone call and send message when a little sound comes to phone?
For API 16 you can use AutomaticGainControl, the AudioEffect and the AudioRecord to adjust gain, sampling and other pre-processing audio recording features.
I am currently working with AudioTrack. I am loading an mp3 file and playing it. However, depending on devices, the music plays either at half the rate or normal rate.
My code:
AudioTrack track= new AudioTrack( AudioManager.STREAM_MUSIC,
sampleRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
initBuffer,
AudioTrack.MODE_STREAM);
sampleRate is the sample rate return by AudioFormat and initBuffer the buffer size from AudioTrack.getMinBufferSize().
I have tried to change the sample rate but no difference. Buffer size also has no impact.
In fact, switching to CHANNEL_CONFIGURATION_STEREO does make the music play at normal rate on the devices that were slow, but it also makes the ones working fine playing at twice the normal speed. My problem is that I want all devices to play at the normal speed.
Any suggestions?
I have read this thread:Android AudioTrack slow playback, but it doesn't tell me how to find out which devices should play in mono or stereo.
Devices at normal speed: Urbano 4.2.2, Galaxy S4 4.3
Devices at half the speed, Galaxy S4 4.2.2, Experia Z 4.2.2
BTW, I cannot use MediaPlayer for playback. The AudioTrack is included in a custom player and I need to write audio data as I extract it. MediaPlayer won't do the trick.
Thanks.
I experienced it when trying to decode mono file using MediaCodec. On some devices,the codec would output stereo stream while mono on other. When setting up the audio track I used media format returned by MediaExtractor, which was mono. On devices where the codec would produce stereo stream, the audio track would be fed with twice as many samples. The solution is to listen for MediaFormatChanged event from MediaCodec and adjust the MediaFormat of the AudioTrack.
AudioTrack only allows PCM audio data, you cannot play mp3 wit AudioTrack directly, you have to convert your mp3 to PCM or use something else (e.g. MediaPlayer) than AudioTrack.
I finally solved my problem. Not the best fix but it works at least.
For those who are interested, I am reading the BufferInfo size and based on it, decide at which playback rate I should play. Basically when playback is slow the size is twice bigger than for normal speed playback. Just a guess, but the MediaCodec might duplicate data for stereo configuration.
This one is a little tricky but here is what you can do using adb and ALSA.
Android internally uses ALSA.
Your device should have ALSA, try :
root#user:/$ adb shell cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version 1.0.25.
Just take a look at Reading ALSA Device names.
Every device (subdivision of a card) has a capture and a playback component.
Like /proc/asound/card0/pcm1p and /proc/asound/card0/pcm1p where card is 0 device is 1
pcm1p is your playback and pcm1c is capture (for recording).
Access your device using adb:
root#user:/$ adb shell
shell#android:/$:
Identifying your device:
So you see /proc/asound/pcm will give you a long list.
shell#android:/$: cat /proc/asound/pcm
00-00: MultiMedia1 (*) : : playback 1 : capture 1
00-01: MultiMedia2 (*) : : playback 1 : capture 1
00-02: CS-Voice (*) : : playback 1 : capture 1
From the above I find 00-00: MultiMedia1 (*) as card0 and device0 is for Multimedia playback.
Getting Playback Parameter:
Play your loaded mp3 file using your standard music player Application.
While the song is playing.
Issue the following commands for card0, device0(p - playback), and subdevice0
shell#android:/$: cat /proc/asound/card0/pcm0p/sub0/hw_params
access: RW_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 1920
buffer_size: 3840
So try using the same values when you call AudioTrack track= new AudioTrack(...);
The above value will only be visible when the device is in open (Playing some audio).
If you issue this to a wrong device (like say pcm1p), you will see the following:
shell#android:/$: cat /proc/asound/card0/pcm1p/sub0/hw_params
closed
Note :
Step 1 doesn't require phone to be rooted, How to Setup ADB.
Alternatives:
Have you tried the AudioTrack APIs like getChannelConfiguration() or getChannelCount() from here - Just Asking.
Have you tried looking at the MP3 file properties, the metadata has information on the audio parameters.
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.
I am doing audio recording using MediaRecorder, but unfortunately when I playback the recorded audio, I have media with a very low volume. I don't hear anything (almost anything).
Is there any possibility to increase recording volume? Like setVolume() when we record?
I try to see in MediaRecorder API but i can't find setVolume or something like that..
Is there any work around?
Thanks.
Well after some r&d and googling i found is there is no specific volume for mic. when you are recording that takes media volume as mic volume.
So to set it, Goto
Settings->Sound->Volume->
and check Media volume.
If you wan to Record in the full Volume then keep Media Volume high and if you want to record in low Volume then keep Media Volume Small.
AIK there is no other sollution.
So please do it for your case.