Hello Guest

decoding MP3 in to OpenAL

  • 4 Replies
  • 16643 Views
*

Offline abcdef

  • ****
  • 336
decoding MP3 in to OpenAL
« on: September 15, 2012, 17:25:08 »
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

Code: [Select]
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

*

Offline abcdef

  • ****
  • 336
Re: decoding MP3 in to OpenAL
« Reply #1 on: September 16, 2012, 08:17:17 »
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.

*

Offline kappa

  • *****
  • 1319
Re: decoding MP3 in to OpenAL
« Reply #2 on: September 17, 2012, 09:00:10 »
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).

*

Offline abcdef

  • ****
  • 336
Re: decoding MP3 in to OpenAL
« Reply #3 on: September 17, 2012, 09:57:25 »
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.




Re: decoding MP3 in to OpenAL
« Reply #4 on: November 02, 2013, 22:21:39 »
I found it easy enough to convert the MP3 file to WAV using this site..

http://media.io/