How to decode MP3 in Android within app? - android

I'm currently working on an app that lets the user choose an MP3 audio file. The file is then processed by my app.
For this processing, the application would need to decode audio files to get the raw PCM output.
To decode MP3, I have two options:
Use the Android system to decode MP3 and get the PCM data.
Decode the MP3 myself on the phone, WITHOUT paying MP3 licensing fees.
My question is whether #1 is technically possible? And for #2, whether the MP3 license on the phone covers an app as well?

To my knowledge, there is no Android-provided way to decode MP3s.
I've used JLayer in the past, and can recommend it for MP3 processing. Using the NDK with a c++ library might be faster, but if you're looking to keep it Java, that's what I'd use. It's still faster than real-time, roughly 30 seconds to decode all frames in an average bitrate 3 minute MP3. That's with an Galaxy S(1GHz), so any newer phones are faster.
As far as licensing goes, I can't help you there. JLayer itself is LGPL, but the world of MP3 licensing is murkier than used motor oil. After a few days of searching for a concrete answer, I just gave up and did it. The world at large seems divided on who even holds the license in the first place.

the Android system can decode mp3 file now, see here it describes the media codec, container, and network protocol support provided by the Android platform.
The MedieCodec is a very powful framework to encode and decode media file.

Option 1 is definitely not possible (unless you want to target ICS+ devices and are willing to write native C code to decode MP3s with OpenSL). Geobits recommendation of jLayer is a good one. For the most part, dealing with jLayer is a breeze. Here's a good blog post that will help: http://mindtherobot.com/blog/624/android-audio-play-an-mp3-file-on-an-audiotrack/

Related

How to identify the start of a song in a big video file

I am looking for a way to tag the start and end of a song(s) in a video file.
I am targeting below video formats for now.
1) 3GPP (.3gp)
2) MPEG-4 (.mp4)
I referred to the article http://bigflake.com/mediacodec/ and Android Extract Decode Encode Mux Audio and was able to get an idea for extracting demuxed, encoded audio data, however i am not sure how to identify the start of a music (not normal audio) in this audio file.
Target OS is Marshmallow.
Please suggest if this is possible, the answer i am looking for may need audio signal processing, unless there is an easier way to do it.
A theoretical way would be to use Transloadit, a program that would turn a song into a waveform. Then create a program (I think Python would do decently well) that can identify the start of the waveform and load it into a library. Then, in that library, you place the songs and their charts together, and if a song plays, you can then also run Python, which would detect the location of the source of current music and find the chart there and get the corresponding song name.
This will take a lot of time.
Transloadit waveform generator
Using PIL (Python Image Library) to detect image on screen from StackOverflow - first answer will help you.
If you need help with the libraries, then just ask me.
I'm sorry, but I don't have any major Android knowledge cough cough none.
Sorry, but you might need to search up some tutorials or try to use Python.

encoding and decoding of audio files to send over the internet to decrease size. android

i am making an android app in which we transfer audio files over the internet . But as the file size is large we need to encode and decode mp3 and other formats which we are unable to find a way till now .Like whatsapp they decreasses the size by appreciable amount . Can u help me and tell us a better way to encode and decode in android
and i want to do similar things in php website . Please guide me .
As per my understanding of your question, CODEC is what exactly you need to use.
CODEC is actually a piece of code or a program that compresses data to enable faster transmission and decompresses received data.
Since your application will be dealing with the transfer of audio files, you can go for Audio codecs or if any other rich media you want, accordingly you can choose the suitable one.
And even for different audio formats to be supported and their conversion, FFmpeg is what you can refer, also to the formats and codecs.
To decide which codec to use and which not,refer here.
Hope it helps and you can further ask for assistance needed in any case.

Using Stagefright to stream small audio files in Android

I have a lot of small .ogg sound files (average size of ~35-50KB) that I need to have played from my AWS S3, and then once played, they need to be cached on the device. There are approximately 200 sounds, and that is 1/10th of what the finished application will use.
I'm not sure the Stagefright library is my best bet, or if an entirely different approach is needed. Should I use Stagefright, or go with another option???
From your query, I feel that you could use SoundPool for your application. Please refer to this link SoundPool for more information.
A couple of examples can be found in MediaActionSound.java, SoundPoolTest.java and Soundclips.java.

Android Mixing Audio Input

I've read a lot of questions on stackoverflow and other pages about this topic, but didn't find a real up-to-date solution:
In an Android-App I've got two audio files (local file system), which are encoded in mp3, ogg or wav.
I just want to play them exactly synchronously, have seeking possibilities and control the volume of each single track. Using MediaPlayer this isn't possible because of the well known latency issues in Android.
So I think having two Audio-Player-Instances (of whatever library) will allways result in bad latencies, so it seems not to be the solution.
So in my opinion the only solution would be to mix together the audio inputs to a somewhat mixed input, which can be played by one Player. I read a lot about Androids AudioTrack and buffers and the OpenSL ES implementation, but allways ended with the notice: buffers only support PCM raw audio data. Ok, so I have to decode the mp3/ogg by myself?
My Question now is: Is there any library that can help me to a) do exactly what I want with a simple API or b) decode mp3/ogg to memory to use that data with AudioTrack or OpenSL?
If it's native or Java is unimportant, it just has to work.
The minimum API-Level is 15+ (Android 4.0.3, most current Version while creating this question).

For android media player mp3 vs. wav

I want to know if it is faster to load and play a small wav than a small mp3 file on android media player. The wavs are about 30 KB and the same files as mp3s are about 20 kb. The mp3s have the advantage to save resource space. The sound files have to be played with split second timing.
For such small sounds, you will get best results with SoundPool.
Even the weakest android devices have ample computing power to play an mp3, and probably have hardware acceleration for it as well. The real question is the setup overhead for playing a wav vs. playing an mp3, which should be fairly easy to measure programmatically.
I'm a little surprised you're getting such a poor compression ratio with mp3. Even lossless compression algorithms tend to get a 2:1 compression ratio with wav. Given that an android device probably isn't hooked up to audiophile-quality speakers, you should be able to get away with 64 kbit/s mono mp3 compression, or even lower. If you can get the file size under 4K, it'll fit in a single memory page, which is about as low as you can get for OS overhead.
If for whatever reason you're stuck with a 1.5:1 compression ratio, it's probably not worth the extra work.
Wav files use more space because they have a higher sample rate. Pretty much more points that the sound wave will trace out so in theory it would take more processing power to play a wav. Also wave is uncompressed meaning it has all of the information from the source it was taken from. When you take a cd and convert it to wav you more or less have a copy of the original. When you convert to mp3 it uses fewer reference points and detail is lost. Secondly, most mp3 encoders normalize the music which is a fancy way of saying it makes the quiet parts louder and the loud parts quieter. All this being said some people cant hear the difference and it mostly depends on what type of headphones/speakers you are listening on... ALLL that being said there shouldn't be a delay on either format the only difference should be the sample rate or "resolution" of the sound file
I have no technical "stuff" to back me up here, but since no one else has taken a crack at this, I will.
I know that mp3s have "better" compression than wavs, thus the file is smaller. This would imply, however, that it would take more cpu to "uncompress" the files. (This may be done on dedicated hardware so it could be a moot point.) Additionally, since the files will be inflated, it may be deceiving to see the mp3 file's smaller size and think it would be quicker to load and play.
Considering the wav file format's history, and that it serves as a 'lowest common denominator' when it comes to exchanging sound files between different programs (per Wikipedia), I would make an educated guess that it would be faster to load and play a small wav file. This is very dependent on Android's software implementation of audio libraries as well as the hardware so if anyone knows more, it would be great to hear their take.

Categories

Resources