decoding MP3 in to OpenAL

Started by abcdef, September 15, 2012, 17:25:08

Previous topic - Next topic

abcdef

Hi

Does anyone have any experience in decoding MP3 files and using them in OpenAL?

I'm using JLayer to try this but with no JLayer documentation its quite tricky.

This is the simple code I have so far

File file = new File(args[0]);
            
            Bitstream bitstream = new Bitstream(file.toURI().toURL().openStream());
            AudioDevice audioDevice = FactoryRegistry.systemRegistry().createAudioDevice();
            Decoder decoder = new Decoder();
            audioDevice.open(decoder);
            
            boolean process = true;
            
            WaveFileObuffer wfo = new WaveFileObuffer (1,192,"/Users/me/test.wav");
            decoder.setOutputBuffer(wfo);
            while (process)
            {
                Header header = bitstream.readFrame();
                if (header == null)
                {
                    process = false;
                    break;
                }
                
                decoder.decodeFrame(header, bitstream);                
            }


Its not quite working at the moment, the output should be a file created in .wav format (I guess I can write my own ostream which can save an inputstream rather than a file). I realise this isn't a JLayer forum but wantred to see if there were any people using OpenAL out there who have used JLayer successfully

abcdef

I have persevered and now have a working prototype!!  :)

I had to write a few extra classes to change the file based conversion method to a streaming based conversion method. The JLayer code is quite difficult to understand, I took the source of the Convert method they had and then stripped away all the parts that aren't relevant.

kappa

Just curious, why use the MP3 format when you can just use the royalty free OGG format which practically as good and doesn't have the licensing issues. The JOrbis library that decodes OGG works pretty well and has tons of example code for use with OpenAL (projects like Slick2D, jMonkeyEngine and LibGDX, etc use it).

abcdef

I agree that using the OGG format would be better, the reason I was doing what I was doing was because its not my sounds that I am trying to integrate (I'm using third party content). If I was to use my own content then OGG would definitely be a good first choice.




jmguillemette

I found it easy enough to convert the MP3 file to WAV using this site..

http://media.io/