Can I set volume beyond AudioManager.getStreamMaxVolume? - android

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.

Related

How to add volume gain to MediaPlayer?

I made an Android app to record and play wildlife sounds. It also shows a waveform of the volume of the recording as it records, and when you load a song it also shows you the waveform. I did this reading the bytes[] of the WAVE file, translating to shorts[], and showing the graph. Works as expected.
The problem with wildlife sounds is that they are usually very quiet. Of course, the device volume at play time is at its max, but even at max the volume is usually still too low. So I implemented a gain control at recording time: it just multiplies the shorts[] from AudioRecord (taking care of clipping) while printing the waveform, and then saves them to the WAVE file. Again, it works as expected.
But now I am thinking that I am doing everything wrong: why to apply gain before saving? This may introduce clipping ruining the capture. Much better is to implement gain at play time.
But I do not know how to do this. I reproduce the sound with MediaPlayer, and although it has a setVolume(float,float) control, this does not actually increase the volume.
How can I send a stream with gain to MediaPlayer?
If this cannot be done, how can I add volume gain at play time? Maybe AudioTrack? Never used it...

Audiotrack setVolume - minimum value

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.

Increase volume of recording Android AudioRecord

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.

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.

Audio Sound Too Low in Android App

I recorded some audio files to use in my app, around 50, so I would like to not record all of them again. I recently used SoundPool to play the audio files on a real device instead of the emulator and you can barely hear them. On the emulator with my PC volume set to max and device to max, I can hear it fine. Should I try to record the files louder or is there another option?
I've found that when targeting mobile devices (and cheap/small laptop speakers for that matter), it is best to do two things to your audio:
Compression: I do not mean data compression, I mean dynamic contrast compression. This will remove some of the level differences between loud and soft parts of the recording, allowing it all to be heard better.
Normalization: When you normalize audio, you take the loudest part of the audio, and scale the entire audio clip up so that the loudest part is at the loudest that can be stored in the audio file.
You can do both of these easily with any audio editing software, such as Audacity.
Finally, you should also keep in mind the reproduceable frequencies on such small speakers.
Most of these speakers are built with speech in mind. Because of this, you will find that they tend to be the loudest in the 700Hz-2.5kHz range.
That is, if your sound effects are low in frequency (think bass), then it will be almost impossible to hear them on a phone's small speaker which cannot reproduce such low frequencies.
If you have more questions on the matter, please visit https://video.stackexchange.com/.
If it is the volume of the recorded files, you can change it using a normalizer like MP3Gain.

Categories

Resources