Decoding Mp3 file in java - java

I am trying to design Shazam like app for Desktop in java.I took input from Microphone having format
sample rate=44100,sample size in bits=16,Channels=1,signed=true and bigendian=true. and perform FFT.Similarly for creating Database of MP3 songs i am decoding MP3 file in the same format as input from microphone.
and this process is giving me too much samples and that slows FFT process of mp3 files.
So my doubt is that how i can handle this problem.

Related

Exception in reading an MP3 file through AudioSystem.getAudioInputStream(file)

I am trying to read an MP3 file through class javax.sound.sampled.AudioSystem but I am getting an UnsupportedAudioFileException.
My code trying to read the audio file looks like:-
AudioInputStream audioInputStream =
AudioSystem.getAudioInputStream(file);
I am getting the following exception:-
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file
Does AudioSystem class not support mp3 format? If not then what formats does it supports? Or Am I doing some mistake here?
No it doesn't support MP3 (hence the UnsupportedAudioFileException). The supported files are quite basic (WAV and that sort of thing), so for any advanced codecs you'll need separate libraries.

How dos progressive videostream work exactly (MP4, flv etc.)

i wonder how progressive videostreambuffering works. Currently i try to create a media player for Android that is able to play progressive streamed video files. For that i use vitamio library. Its a very powerfull Android medialibrary. It also supports progressive straming and several videoformats. The only Problem with vitamio is that it dos not continue buffering when you Pause the playback. So you are not able to watch videos on slow networks.
So my current workaround to solve this is open a httpinputstream to the videofile i want to stream. Then i read the size of the videofile. Let's say it is 80MB. Then i create an empty dummyfile on my hdd with exactly this size (80MB). This file is currently filled up with zeros. Then i start to read the data from the httpinputstream and overwrite the dummyfile from . If i have 10MB downloaded i put this file into the videoplayer and start playback. In this moment the videofile on my hdd is still 80MB big but the readable and valid videodata are 10MB. During playback i continue downloading and filling up the dummy file until it is done.
Sometimes this works very good and sometimes not. The playback stops with several errors (frame not found and so on) although the play position is at 5% and the download has been 15%yet. It does not work very reliable and i cannot imagine that this is the common way of progressive streaming. So my question is: how does this technically work? What differs my method of progressive streaming from the common way?
thank you

Writing Wav Files of Unknown Length (Java)

I am trying to add a feature to some audio processing software I have written.
My software already captures sound from a microphone input, processes it in real time, and sends the result to a speaker output. (This is already a threaded application.) I've been using javax.sound.sampled.* and working with wav data (transforming it to and from numerical samples to do the processing.
I would like to add a feature to save both the raw input and the transformed output of a session with this software to wav files. But the signature for creating a new wav file (e.g., WavFile.newWavFile(...) seems to want to know in advance how many frames of data it is going to receive. Since these are live sessions of indeterminate time, I have no way of knowing this information before hand.
Am I missing something? Is there some way around this, other than a hack like saving files of data or samples, and then post-processing it?
Most audio file writers need to know the full file size before writing to an output stream. There's an open source project called Tritonus which is an implementation of the Java sound API that has an AudioOutputStream plugin you could try.

How to output elementary streams with android media recorder?

I want to output elementary video streams with media recorder in android for the purpose of streaming with live555. In essence, I want to get media recorder to output an MPEG-4 Video Elementary Stream file (an .m4e file) or an H.264 Video Elementary Stream file (an .264 file). Is it possible to do that with media recorder on android? Or is there any other way to get it work?
From the MediaRecorder APIs I see that you have to call the setOutputFormat() before calling prepare(), this limits you to select one of the available options - 3GP/MP4. Hence you can use your own parser to operate on the dump from the mediarecorder, which can give you elementary streams.
The answer is, as I understand, that it is not easy to do that with MediaRecorder while recording. You may do that without much difficulty, using ffmpeg once the video is recorded. The reason is that, MediaPlayer cannot record as elementary streams. Even if we record video only, it will be put in a container format such as 3GPP or MP4. Now, for tools like ffmpeg to work on these files, they need the 3GPP or MP4 header information must be present on the recorded file. But, MediaPlayer will write those headers to the file only after it finished recording.

Audio Files accurate seek to

Which Audio format should I use to get the best accurate seek to? (play the song from an offset)
I whant this to be accurate on the millisecond.
is that Possible?
I can say that the format of the audio file matters. I had this problem with long mp3 file. As the mp3 files aren't designed for such accurate seeking you can check this answer for more details
In my case the bitrate of the mp3 file was low, It was 96Kps. and the VBR data wasn't correct which caused the mp3 file to seek wrongly on android.
My intent was to make android and IOS app that seeks accurately through this file but I failed to find the correct format that is suitable for both.
For the IOS, I used MP3 Diags and applied custom transformations to remove and rebuild the VBR
For Android, I converted the file to m4a format and it worked perfectly. I used Audacity and installed the FFmpeg package to be able to export to m4a format.
This is the file sample that contains the problem I mentioned
The format doesn't matter, as long as it's compatible with Android's MediaPlayer class. It has a seekTo() method that is accrate to the millisecond.

Categories